target
stringlengths
29
3.65k
data_source
stringclasses
12 values
prompt
listlengths
1
1
ability
stringclasses
1 value
reward_model
dict
extra_info
dict
def sum_every_second(lst): return sum(lst[::2])
simplelr_Filter
[ { "content": "Question:\nDesign a Python function that computes the sum of every second element in a given list of integers. The function should be named `sum_every_second` and should take a single argument, a list of integers, and return the sum of every second element starting from the first element. The func...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 600, "level": 1, "question": "Design a Python function that computes the sum of every second element in a given list of integers. The function should be named `sum_every_second` and should take a single argument, a list of integers, and return the sum of every second element startin...
def sum_of_squares(lst): return sum(num ** 2 for num in lst)
simplelr_Prefill
[ { "content": "Question:\nCreate a function that takes a list of integers and returns the sum of all the squares of the numbers. The function should be efficient and handle large lists without causing a performance issue.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 601, "level": 1, "question": "Create a function that takes a list of integers and returns the sum of all the squares of the numbers. The function should be efficient and handle large lists without causing a performance issue.", "split": "train" }
def find_index_of_first_occurrence(lst, target): try: return lst.index(target) except ValueError: return -1
simplelr_Prefill
[ { "content": "Question:\nWrite a python function to find the index of the first occurrence of a target value in a list. If the target is not found, return -1.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 602, "level": 1, "question": "Write a python function to find the index of the first occurrence of a target value in a list. If the target is not found, return -1.", "split": "train" }
import math def check_perfect_square(n): if n < 0: return -1 s_root = math.isqrt(n) if s_root * s_root == n: return s_root else: return -1
simplelr_Filter
[ { "content": "Question:\nWrite a Python code snippet to check if a number is a perfect square and return the square root if it is, otherwise return -1.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 603, "level": 1, "question": "Write a Python code snippet to check if a number is a perfect square and return the square root if it is, otherwise return -1.", "split": "train" }
import math def is_prime(n): if n <= 1: return False if n <= 3: return True if n % 2 == 0: return False max_divisor = math.isqrt(n) for i in range(3, max_divisor + 1, 2): if n % i == 0: return False return True
simplelr_Filter
[ { "content": "Question:\nIn a recent programming competition, a problem was presented where the participants were required to write a function that determines whether a given integer \\( n \\) is a prime number. The function should return `True` if \\( n \\) is a prime number and `False` otherwise. A prime numb...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 604, "level": 1, "question": "In a recent programming competition, a problem was presented where the participants were required to write a function that determines whether a given integer \\( n \\) is a prime number. The function should return `True` if \\( n \\) is a prime number a...
def minPathSum(grid): m = len(grid) n = len(grid[0]) if m > 0 else 0 if m == 0 or n == 0: return 0 dp = [[0 for _ in range(n)] for _ in range(m)] dp[0][0] = grid[0][0] # Fill the first row for j in range(1, n): dp[0][j] = dp[0][j-1] + grid[0][j] # Fill...
simplelr_Leetcode
[ { "content": "Question:\nGiven a `2D` grid of size `m x n` filled with non-negative integers, a rat needs to find a path from the top-left corner to the bottom-right corner of the grid. The rat can move either down or right at any point in time. Implement a function `minPathSum(grid)` that returns the minimum s...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 605, "level": 1, "question": "Given a `2D` grid of size `m x n` filled with non-negative integers, a rat needs to find a path from the top-left corner to the bottom-right corner of the grid. The rat can move either down or right at any point in time. Implement a function `minPathSum...
from typing import List, Tuple def missing_ranges(arr: List[int], lo: int, hi: int) -> List[Tuple[int, int]]: result = [] if not arr: if lo <= hi: return [(lo, hi)] else: return [] current_start = lo for num in arr: if num > current_start: ...
simplelr_Data_Structure
[ { "content": "Question:\n### Question\n\nYou are given a sorted array of integers `arr`, and two integers `lo` and `hi` that define a range of interest. Your task is to write a function `missing_ranges(arr, lo, hi)` that returns a list of ranges (tuples) representing the missing numbers in the provided range `[...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 606, "level": 1, "question": "### Question\n\nYou are given a sorted array of integers `arr`, and two integers `lo` and `hi` that define a range of interest. Your task is to write a function `missing_ranges(arr, lo, hi)` that returns a list of ranges (tuples) representing the missin...
import re from collections import Counter def word_frequency(input_string): words = re.findall(r'[a-z]+', input_string.lower()) return dict(Counter(words))
simplelr_Taco
[ { "content": "Question:\nIn a given text, you need to implement a function that counts the frequency of each word. The function should ignore case sensitivity and punctuation. \n\nInput\n---\nA string of arbitrary length, consisting of words separated by spaces and punctuation marks (\".\", \",\", \";\", \":\",...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 607, "level": 1, "question": "In a given text, you need to implement a function that counts the frequency of each word. The function should ignore case sensitivity and punctuation. \n\nInput\n---\nA string of arbitrary length, consisting of words separated by spaces and punctuation ...
def remove_all_occurrences(lst, element): result = [] for item in lst: if item != element: result.append(item) return result
simplelr_Prefill
[ { "content": "Question:\nWrite a python function to remove all occurrences of a specific element from a list. Your function should take in a list and an element to be removed, and return the modified list without the specified element. The function should be able to handle any data type for the elements in the ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 608, "level": 1, "question": "Write a python function to remove all occurrences of a specific element from a list. Your function should take in a list and an element to be removed, and return the modified list without the specified element. The function should be able to handle any ...
def find_and_replace(text: str, find_word: str, replacement: str) -> str: return text.replace(find_word, replacement)
simplelr_Package
[ { "content": "Question:\nYou are developing a simple text editor that allows users to type and manipulate text. One of the features you need to implement is a function that can find and replace all occurrences of a specific word in a given text.\n\nWrite a Python function named `find_and_replace` that takes thr...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 609, "level": 1, "question": "You are developing a simple text editor that allows users to type and manipulate text. One of the features you need to implement is a function that can find and replace all occurrences of a specific word in a given text.\n\nWrite a Python function named...
def get_multiples(lst): new_lst = [] for num in lst: if num % 3 == 0 or num % 5 == 0: new_lst.append(num) return new_lst
simplelr_Filter
[ { "content": "Question:\nI have a Python list of integers and I want to create a new list with the multiples of 3 and the multiples of 5. \n\nHere is my attempt:\n```\ndef get_multiples(lst):\n new_lst = []\n for num in lst:\n if num % 3 == 0 and num % 5 == 0:\n new_lst.append(num)\n ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 610, "level": 1, "question": "I have a Python list of integers and I want to create a new list with the multiples of 3 and the multiples of 5. \n\nHere is my attempt:\n```\ndef get_multiples(lst):\n new_lst = []\n for num in lst:\n if num % 3 == 0 and num % 5 == 0:\n ...
from typing import List, Tuple def sort_products(products: List[Tuple[str, int]]) -> List[str]: sorted_products = sorted(products, key=lambda x: (-x[1], x[0])) return [name for name, score in sorted_products]
simplelr_Code_Contests
[ { "content": "Question:\nYou are working on a custom sorting feature for an e-commerce website where products need to be sorted based on a custom ranking attribute. Each product has a name and a custom score associated with it. Given the list of products and their scores, you need to sort the products in descen...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 611, "level": 1, "question": "You are working on a custom sorting feature for an e-commerce website where products need to be sorted based on a custom ranking attribute. Each product has a name and a custom score associated with it. Given the list of products and their scores, you n...
def process_items(items: list) -> int: sum_positive: int = 0 # Annotated assignment for num in items: if num > 0: sum_positive += num # Augmented assignment abs_items = [abs(num) for num in items] abs_sorted = sorted(abs_items) if not abs_sorted: return 0 ...
simplelr_Docs
[ { "content": "Question:\n**Objective:**\nDemonstrate understanding and application of various types of assignment statements, control flow mechanisms, and functions in Python.\n\n**Problem Statement:**\nWrite a Python function `process_items(items: list) -> int` that takes a list of integers called `items` and ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 612, "level": 1, "question": "**Objective:**\nDemonstrate understanding and application of various types of assignment statements, control flow mechanisms, and functions in Python.\n\n**Problem Statement:**\nWrite a Python function `process_items(items: list) -> int` that takes a li...
def is_palindrome(s): # Clean the string by keeping only alphanumeric characters and converting to lowercase cleaned = [c.lower() for c in s if c.isalnum()] cleaned_str = ''.join(cleaned) # Check if the cleaned string is equal to its reverse return cleaned_str == cleaned_str[::-1]
simplelr_Codeforces
[ { "content": "Question:\nYou are working on a project that involves analyzing sentences for palindrome properties. A sentence is a palindrome if it reads the same backward as forward when you ignore spaces, punctuation, and the case of the letters. Your task is to write a function that determines if a given sen...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 613, "level": 1, "question": "You are working on a project that involves analyzing sentences for palindrome properties. A sentence is a palindrome if it reads the same backward as forward when you ignore spaces, punctuation, and the case of the letters. Your task is to write a funct...
def isValid(s: str) -> str: stack = [] closing_to_opening = { ')': '(', ']': '[', '}': '{' } for char in s: if char in closing_to_opening.values(): stack.append(char) else: if not stack: return "NO" top = stack.p...
simplelr_Codeforces
[ { "content": "Question:\nJack is a computer science student who loves solving algorithms involving strings. Recently, he came across a fascinating problem and decided to tackle it with your help.\n\nGiven a string containing only the characters '(', ')', '{', '}', '[' and ']', determine if the input string is v...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 614, "level": 1, "question": "Jack is a computer science student who loves solving algorithms involving strings. Recently, he came across a fascinating problem and decided to tackle it with your help.\n\nGiven a string containing only the characters '(', ')', '{', '}', '[' and ']', ...
def print_reverse(lst): for item in reversed(lst): print(item)
simplelr_Prefill
[ { "content": "Question:\nCreate a function that prints the elements of a list in reverse order without modifying the original list.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 615, "level": 1, "question": "Create a function that prints the elements of a list in reverse order without modifying the original list.", "split": "train" }
def sum_of_digits(n): """ Calculate the sum of the digits of a given integer using recursion. Args: n (int): The integer whose digits are to be summed. Returns: int: The sum of the digits of the integer. If the input is 0, returns 0. Examples: >>> sum_of_digits(12345) ...
simplelr_Evol
[ { "content": "Question:\nDevelop a Python function that calculates the sum of the digits of a given integer learned through recursion. Your function should efficiently manage edge cases, such as negative numbers. For example, for the provided input `12345`, the function is expected to return `15` as the sum of ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 616, "level": 1, "question": "Develop a Python function that calculates the sum of the digits of a given integer learned through recursion. Your function should efficiently manage edge cases, such as negative numbers. For example, for the provided input `12345`, the function is expe...
def count_flips_to_convert(a: int, b: int) -> int: return bin(a ^ b).count('1')
simplelr_Data_Structure
[ { "content": "Question:\n**Scenario**:\nYou are developing a tool to analyze changes in binary data. One of the features is to determine the minimal number of bit flips required to change one binary number to another. This is crucial for assessing the complexity of certain transformation algorithms.\n\n**Proble...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 617, "level": 1, "question": "**Scenario**:\nYou are developing a tool to analyze changes in binary data. One of the features is to determine the minimal number of bit flips required to change one binary number to another. This is crucial for assessing the complexity of certain tran...
import heapq def min_cost_to_merge_files(arr): if len(arr) <= 1: return 0 heap = arr.copy() heapq.heapify(heap) total_cost = 0 while len(heap) > 1: a = heapq.heappop(heap) b = heapq.heappop(heap) sum_ab = a + b total_cost += sum_ab heapq.heappush(heap...
simplelr_Leetcode
[ { "content": "Question:\nYou are given an array of integers `arr` representing the sizes of files. You need to merge these files into one file. The cost of merging two files is equal to the sum of their sizes. Return the minimum cost to merge all the given files into one file.\n\nFor example, if `arr = [4, 6, 8...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 618, "level": 1, "question": "You are given an array of integers `arr` representing the sizes of files. You need to merge these files into one file. The cost of merging two files is equal to the sum of their sizes. Return the minimum cost to merge all the given files into one file.\...
def can_partition(arr): total = sum(arr) if total % 2 != 0: return False target = total // 2 possible_sums = {0} for num in arr: to_add = set() for s in possible_sums: new_sum = s + num if new_sum == target: return True ...
simplelr_Evol
[ { "content": "Question:\nWrite a function to determine if it's possible to partition an array of integers into two subsets such that the sum of elements in both subsets is equal. The function should return `true` if such a partition exists, otherwise, it should return `false`. \n\nYou are not allowed to use any...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 619, "level": 1, "question": "Write a function to determine if it's possible to partition an array of integers into two subsets such that the sum of elements in both subsets is equal. The function should return `true` if such a partition exists, otherwise, it should return `false`. ...
def characterReplacement(s: str, k: int) -> int: freq = {} max_freq = 0 max_length = 0 left = 0 for right in range(len(s)): char = s[right] if char in freq: freq[char] += 1 else: freq[char] = 1 # Update max_freq if freq[char] > max_freq...
simplelr_Leetcode
[ { "content": "Question:\nYou are given a string `s` and an integer `k`. You are allowed to choose one character of the string and change it to any other character a total of `k` times. Return the length of the longest substring containing the same letter you can get after performing the above operations.\n\nFor...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 620, "level": 1, "question": "You are given a string `s` and an integer `k`. You are allowed to choose one character of the string and change it to any other character a total of `k` times. Return the length of the longest substring containing the same letter you can get after perfo...
from collections import deque from typing import List def min_coins(coins: List[int], amount: int) -> int: if amount == 0: return 0 visited = [-1] * (amount + 1) visited[0] = 0 q = deque([0]) while q: current = q.popleft() for coin in coins: new_amt = c...
simplelr_Taco
[ { "content": "Question:\nA task is given which requires you to determine an optimal way to use a set of available coins to make up a specific amount of money. Write a function that computes the minimum number of coins needed to make up a given amount from a given set of coin denominations. If it is not possible...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 621, "level": 1, "question": "A task is given which requires you to determine an optimal way to use a set of available coins to make up a specific amount of money. Write a function that computes the minimum number of coins needed to make up a given amount from a given set of coin de...
def extended_gcd(a, b): old_r, r = a, b old_s, s = 1, 0 old_t, t = 0, 1 while r != 0: quotient = old_r // r # Update r, old_r, s, old_s, t, old_t old_r, r = r, old_r - quotient * r old_s, s = s, old_s - quotient * s old_t, t = t, old_t - quotient * t return ...
simplelr_Data_Structure
[ { "content": "Question:\n### Scenario\nYou are involved in a project involving cryptographic algorithms where you frequently need to compute modular inverses and solve linear congruences. One common requirement is to find integers `s` and `t` for given integers `a` and `b`, such that:\n\\[ a \\cdot s + b \\cdot...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 622, "level": 1, "question": "### Scenario\nYou are involved in a project involving cryptographic algorithms where you frequently need to compute modular inverses and solve linear congruences. One common requirement is to find integers `s` and `t` for given integers `a` and `b`, suc...
def calculate_factorial(n: int) -> int: """ This function calculates the factorial of a given non-negative integer using recursion. Args: n (int): The input number for which the factorial is calculated. Returns: int: The factorial of the input number. Raises: ...
simplelr_Algorithm
[ { "content": "Question:\n### **Calculate Factorial using Recursion**\n\n#### Background\nFactorial is a mathematical function that multiplies a given number by every number lower than it down to one. It's denoted as `n!` and is widely used in combinatorics, algebra, and other fields of mathematics. Using recurs...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 623, "level": 1, "question": "### **Calculate Factorial using Recursion**\n\n#### Background\nFactorial is a mathematical function that multiplies a given number by every number lower than it down to one. It's denoted as `n!` and is widely used in combinatorics, algebra, and other f...
def find_unique_element(arr): result = 0 for num in arr: result ^= num return result
simplelr_Prefill
[ { "content": "Question:\nWrite a python function to find the element that appears once in an array where all other elements appear exactly twice. The input array will always contain at least one element that appears only once. Assume all elements in the array are integers and may not be consecutive, any kind of...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 624, "level": 1, "question": "Write a python function to find the element that appears once in an array where all other elements appear exactly twice. The input array will always contain at least one element that appears only once. Assume all elements in the array are integers and m...
def remove_alphabets(s): return ''.join([c for c in s if c.isdigit()])
simplelr_Filter
[ { "content": "Question:\nSuppose you are presented with an alphanumeric string of variable length. Your task is to ingeniously devise a function that is capable of omitting all the alphabetic characters from this string, thereby yielding a sequence solely composed of numeric figures.\nAnswer:\nLet's think step ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 625, "level": 1, "question": "Suppose you are presented with an alphanumeric string of variable length. Your task is to ingeniously devise a function that is capable of omitting all the alphabetic characters from this string, thereby yielding a sequence solely composed of numeric fi...
def get_department_name(employee_id): department_code = employee_id[:3] department_mapping = { '101': 'Sales', '102': 'Engineering', '103': 'HR', '104': 'Finance', '105': 'IT Support', '106': 'Legal', '107': 'Marketing', '108': 'Research' } ...
simplelr_Apps
[ { "content": "Question:\nA company needs to manage their employee information. Your task is to help them by creating a function that retrieves the department name based on the employee ID. Each employee ID will follow the pattern \"DDD-XXXXX\", where \"DDD\" is the department code and \"XXXXX\" is a unique iden...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 626, "level": 1, "question": "A company needs to manage their employee information. Your task is to help them by creating a function that retrieves the department name based on the employee ID. Each employee ID will follow the pattern \"DDD-XXXXX\", where \"DDD\" is the department c...
from collections import defaultdict from typing import List, Tuple, Dict def process_transactions(transfers: List[Tuple[int, int, int]]) -> Dict[int, int]: balances = defaultdict(int) for sender, receiver, amount in transfers: balances[sender] -= amount balances[receiver] += amount return d...
simplelr_Taco
[ { "content": "Question:\nA digital bank offers an online platform where users can transfer money between their accounts. Every transfer is represented as a tuple (sender, receiver, amount), where `sender` and `receiver` are account IDs (integers) and `amount` is a positive integer representing the amount of mon...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 627, "level": 1, "question": "A digital bank offers an online platform where users can transfer money between their accounts. Every transfer is represented as a tuple (sender, receiver, amount), where `sender` and `receiver` are account IDs (integers) and `amount` is a positive inte...
def binary_search(arr, target): low = 0 high = len(arr) - 1 while low <= high: mid = (low + high) // 2 if arr[mid] == target: return mid elif arr[mid] > target: high = mid - 1 else: low = mid + 1 return -1
simplelr_Prefill
[ { "content": "Question:\nWrite a function to perform a simple binary search on a sorted array. Explain the logic behind each step of the implementation.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 628, "level": 1, "question": "Write a function to perform a simple binary search on a sorted array. Explain the logic behind each step of the implementation.", "split": "train" }
def even_numbers(numbers): """ This function takes a list of numbers and returns a new list containing only the even numbers. """ even_list = [] for number in numbers: if number % 2 == 0: even_list.append(number) return even_list
simplelr_Filter
[ { "content": "Question:\nThis is an assignment for my computer science class:\n\n**Assignment:**\n\nWrite a Python program that takes a list of numbers as input and returns a new list containing only the even numbers from the original list.\n\n**Example:**\n\nInput: [1, 2, 3, 4, 5, 6]\nOutput: [2, 4, 6]\n\n**He...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 629, "level": 1, "question": "This is an assignment for my computer science class:\n\n**Assignment:**\n\nWrite a Python program that takes a list of numbers as input and returns a new list containing only the even numbers from the original list.\n\n**Example:**\n\nInput: [1, 2, 3, 4...
def longest_allowed_substring(s, letters): letters_set = set(letters) max_len = 0 left = 0 for right in range(len(s)): if s[right] in letters_set: current_len = right - left + 1 if current_len > max_len: max_len = current_len else: left...
simplelr_Leetcode
[ { "content": "Question:\nYou are given a string `s` consisting of lowercase English letters and an array `letters` consisting of distinct characters representing a set of allowed letters. Your task is to find the longest substring of `s` that contains only characters from `letters`. Return the length of this lo...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 630, "level": 1, "question": "You are given a string `s` consisting of lowercase English letters and an array `letters` consisting of distinct characters representing a set of allowed letters. Your task is to find the longest substring of `s` that contains only characters from `lett...
import math from typing import List def bucket_sort(arr: List[float]) -> List[float]: if not arr: return [] n = len(arr) k = int(math.sqrt(n)) k = max(k, 1) # Ensure at least one bucket if n is very small buckets = [[] for _ in range(k)] for x in arr: bucket_inde...
simplelr_Data_Structure
[ { "content": "Question:\n### Bucket Sort Implementation Challenge\n\nGiven the initial setup of the Bucket Sort algorithm, your task is to complete and optimize the implementation of the `bucket_sort` function. The goal is to sorting a list of numeric values using the Bucket Sort approach, with some enhancement...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 631, "level": 1, "question": "### Bucket Sort Implementation Challenge\n\nGiven the initial setup of the Bucket Sort algorithm, your task is to complete and optimize the implementation of the `bucket_sort` function. The goal is to sorting a list of numeric values using the Bucket So...
def remove_element(array, element, remove_all=False): if remove_all: return [x for x in array if x != element] else: new_array = list(array) try: new_array.remove(element) except ValueError: pass return new_array
simplelr_Prefill
[ { "content": "Question:\nWrite a python function to remove a specific element from an array and return the modified array. The function should accept three parameters: the array, the element to be removed, and a boolean flag indicating whether to remove all occurrences of the element or only the first occurrenc...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 632, "level": 1, "question": "Write a python function to remove a specific element from an array and return the modified array. The function should accept three parameters: the array, the element to be removed, and a boolean flag indicating whether to remove all occurrences of the e...
def rotate_matrix(matrix): return [list(row[::-1]) for row in zip(*matrix)]
simplelr_Taco
[ { "content": "Question:\nWrite a function **\"rotate_matrix\"** that rotates a given NxN matrix 90 degrees clockwise.\n\nFor example:\n\n```\nInput:\n[\n [1, 2, 3],\n [4, 5, 6],\n [7, 8, 9]\n]\n\nOutput:\n[\n [7, 4, 1],\n [8, 5, 2],\n [9, 6, 3]\n]\n```\n\nThe function should work for any NxN matrix. Ensure the ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 633, "level": 1, "question": "Write a function **\"rotate_matrix\"** that rotates a given NxN matrix 90 degrees clockwise.\n\nFor example:\n\n```\nInput:\n[\n [1, 2, 3],\n [4, 5, 6],\n [7, 8, 9]\n]\n\nOutput:\n[\n [7, 4, 1],\n [8, 5, 2],\n [9, 6, 3]\n]\n```\n\nThe function should wo...
def digit_sum(n): total = 0 n = abs(n) while n > 0: total += n % 10 n = n // 10 return total
simplelr_Apps
[ { "content": "Question:\nWrite a function, `digitSum` / `digit-sum` / `digit_sum` / `DigitSum`, that takes an integer `n` as an argument and returns the sum of its digits. If the input number is negative, the function should still return the sum of the digits as if the number were positive.\n\nFor example, if t...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 634, "level": 1, "question": "Write a function, `digitSum` / `digit-sum` / `digit_sum` / `DigitSum`, that takes an integer `n` as an argument and returns the sum of its digits. If the input number is negative, the function should still return the sum of the digits as if the number w...
def clean_url(url: str, params_to_remove: list = []) -> str: # Split the URL into base, query, and fragment if '?' in url: base, rest = url.split('?', 1) # Split into query and fragment if present if '#' in rest: query_part, fragment = rest.split('#', 1) else: ...
simplelr_Data_Structure
[ { "content": "Question:\n#### Scenario\nYou are developing a URL management tool that needs to clean URLs by removing duplicate query string parameters and optionally any unwanted parameters provided by the user.\n\n#### Task\nWrite a function `clean_url(url: str, params_to_remove: list = []) -> str` that takes...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 635, "level": 1, "question": "#### Scenario\nYou are developing a URL management tool that needs to clean URLs by removing duplicate query string parameters and optionally any unwanted parameters provided by the user.\n\n#### Task\nWrite a function `clean_url(url: str, params_to_rem...
def time_addition(s, add): hours, minutes = map(int, s.split(':')) total = hours * 60 + minutes total += add total %= 1440 # Ensures total is within [0, 1439] new_h = total // 60 new_m = total % 60 return f"{new_h:02d}:{new_m:02d}"
simplelr_Apps
[ { "content": "Question:\nImplement a function that takes a string representing a specific time duration (in hours and minutes) and an integer representing the number of minutes to add to this time. The function should return the new time in the same format (hours and minutes). The input time will be in the form...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 636, "level": 1, "question": "Implement a function that takes a string representing a specific time duration (in hours and minutes) and an integer representing the number of minutes to add to this time. The function should return the new time in the same format (hours and minutes). ...
def reverse_string(s): return s[::-1]
simplelr_Prefill
[ { "content": "Question:\nCreate a function that reverses a string from the beginning to the end.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 637, "level": 1, "question": "Create a function that reverses a string from the beginning to the end.", "split": "train" }
def longest_distinct_substring(s): left = 0 max_len = 0 start = 0 char_map = {} for right in range(len(s)): current_char = s[right] if current_char in char_map and char_map[current_char] >= left: left = char_map[current_char] + 1 char_map[current_char] = right ...
simplelr_Leetcode
[ { "content": "Question:\nYou are given a string `s` that consists of lowercase English letters and digits. You need to find the **longest substring** of `s` that consists of distinct characters.\n\nFor example, given the string `\"abcabcbb\"`, the answer is `\"abc\"`, which has a length of 3. If there are multi...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 638, "level": 1, "question": "You are given a string `s` that consists of lowercase English letters and digits. You need to find the **longest substring** of `s` that consists of distinct characters.\n\nFor example, given the string `\"abcabcbb\"`, the answer is `\"abc\"`, which has...
def find_dominant_index(nums): if not nums: return -1 max_val = max(nums) count = nums.count(max_val) if count > 1: return -1 else: return nums.index(max_val)
simplelr_Leetcode
[ { "content": "Question:\nConsider an array of integers `nums`. A **dominant** number in this array is defined as a number that is strictly greater than every other number in the array. If such a dominant number exists, return the index of this number. If no such number exists, return `-1`. Note that the array m...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 639, "level": 1, "question": "Consider an array of integers `nums`. A **dominant** number in this array is defined as a number that is strictly greater than every other number in the array. If such a dominant number exists, return the index of this number. If no such number exists, ...
def product_except_self(nums): n = len(nums) if n == 0: return [] left_product = [1] * n for i in range(1, n): left_product[i] = left_product[i-1] * nums[i-1] right_product = [1] * n for i in range(n-2, -1, -1): right_product[i] = right_product[i+1] * nums[i+1] ...
simplelr_Apps
[ { "content": "Question:\nWrite a function that takes a list of integers as input and returns a list where each element is the product of all numbers in the input list except the one at that position. You are not allowed to use division in your solution.\n\n## Examples\n```\ninput: [1, 2, 3, 4]\noutput: [24, 12,...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 640, "level": 1, "question": "Write a function that takes a list of integers as input and returns a list where each element is the product of all numbers in the input list except the one at that position. You are not allowed to use division in your solution.\n\n## Examples\n```\ninp...
def maxDistinctElements(nums: list[int], k: int) -> int: unique_sorted = sorted(set(nums)) total = 0 count = 0 for num in unique_sorted: if total + num <= k: total += num count += 1 else: break return count
simplelr_Code_Contests
[ { "content": "Question:\nYou are given an integer array `nums` and an integer `k`. Your task is to find the maximum number of distinct elements that can be selected from the array such that the sum of all selected elements is less than or equal to `k`.\n\nWrite a function:\n\n```python\ndef maxDistinctElements(...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 641, "level": 1, "question": "You are given an integer array `nums` and an integer `k`. Your task is to find the maximum number of distinct elements that can be selected from the array such that the sum of all selected elements is less than or equal to `k`.\n\nWrite a function:\n\n`...
def find_two_sum_indices(arr, x): seen = {} for i, num in enumerate(arr): complement = x - num if complement in seen: return [seen[complement], i] seen[num] = i return []
simplelr_Leetcode
[ { "content": "Question:\nYou are given an array `arr` of unique positive integers and a target integer `x`. Your task is to find _two distinct indices_ such that the elements at these indices add up to `x`. If no such pair of indices exists, return an empty array. Return the indices as an array of the form `[in...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 642, "level": 1, "question": "You are given an array `arr` of unique positive integers and a target integer `x`. Your task is to find _two distinct indices_ such that the elements at these indices add up to `x`. If no such pair of indices exists, return an empty array. Return the in...
def bubble_sort(numbers): numbers = list(numbers) n = len(numbers) for i in range(n): swapped = False for j in range(0, n - i - 1): if numbers[j] > numbers[j+1]: numbers[j], numbers[j+1] = numbers[j+1], numbers[j] swapped = True if not swap...
simplelr_Filter
[ { "content": "Question:\nCould you provide an example of a simple algorithm, like sorting a list of numbers, in Python?\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 643, "level": 1, "question": "Could you provide an example of a simple algorithm, like sorting a list of numbers, in Python?", "split": "train" }
from collections import Counter from typing import List def unique_occurrences(arr: List[int]) -> bool: counts = Counter(arr) return len(counts.values()) == len(set(counts.values()))
simplelr_Algorithm
[ { "content": "Question:\n### Unique Occurrences in Array\n\nYou need to implement a function that checks whether the number of occurrences of each value in the input array is unique.\n\n#### Function Signature\n```python\ndef unique_occurrences(arr: List[int]) -> bool:\n pass\n```\n\n#### Objective\nWrite a ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 644, "level": 1, "question": "### Unique Occurrences in Array\n\nYou need to implement a function that checks whether the number of occurrences of each value in the input array is unique.\n\n#### Function Signature\n```python\ndef unique_occurrences(arr: List[int]) -> bool:\n pas...
def simulate_robot_movements(commands): x, y = 0, 0 direction = 0 # 0: North, 1: East, 2: South, 3: West direction_deltas = [ (0, 1), # North (1, 0), # East (0, -1), # South (-1, 0) # West ] direction_names = ['North', 'East', 'South', 'West'] for cmd...
simplelr_Apps
[ { "content": "Question:\n## Robot Movement Simulator\n\nYou are tasked with writing a function `simulate_robot_movements` to simulate the movements of a robot on a 2D grid. The robot starts at the origin point (0, 0) facing north. The function will take a string of commands and return the robot's final position...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 645, "level": 1, "question": "## Robot Movement Simulator\n\nYou are tasked with writing a function `simulate_robot_movements` to simulate the movements of a robot on a 2D grid. The robot starts at the origin point (0, 0) facing north. The function will take a string of commands and...
import seaborn as sns import matplotlib.pyplot as plt import numpy as np import pandas as pd def generate_comparative_visualizations(): # Data Preparation np.random.seed(123) # For reproducibility # Generate data for category A x1 = np.random.normal(0, 1, 100) y1 = np.random.normal(0, 1, 100) ...
simplelr_Docs
[ { "content": "Question:\n### Understanding and Using Seaborn Color Palettes\n\n**Problem Statement:**\nYou are provided with a set of visual data and are required to generate a comparative visualization using Seaborn. The task will assess your understanding of Seaborn’s color palettes and your ability to custom...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 646, "level": 1, "question": "### Understanding and Using Seaborn Color Palettes\n\n**Problem Statement:**\nYou are provided with a set of visual data and are required to generate a comparative visualization using Seaborn. The task will assess your understanding of Seaborn’s color p...
def sum_of_arithmetic_progression(n, a, d): """ Calculate the sum of the first n terms of an arithmetic progression. Parameters: n (int): The number of terms. a (int/float): The first term of the sequence. d (int/float): The common difference between terms. Returns: int/float: The sum ...
simplelr_Filter
[ { "content": "Question:\nHow can I create a Python function to calculate the sum of the first n terms of an arithmetic progression?\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 647, "level": 1, "question": "How can I create a Python function to calculate the sum of the first n terms of an arithmetic progression?", "split": "train" }
def filter_even_and_greater_than_ten(numbers): """ Filters a list of integers, returning a new list containing only the even integers greater than 10. Args: numbers (list): A list of integers to be filtered. Returns: list: A new list containing even integers greater than 10 from the in...
simplelr_Filter
[ { "content": "Question:\nCreate a Python function that takes a list of integers and returns a new list containing only the integers that are even and greater than 10. The function should be optimized for performance and should handle edge cases, such as an empty list or a list without qualifying integers. Ensur...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 648, "level": 1, "question": "Create a Python function that takes a list of integers and returns a new list containing only the integers that are even and greater than 10. The function should be optimized for performance and should handle edge cases, such as an empty list or a list ...
def roman_to_int(s): roman = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000} total = 0 for i in range(len(s) - 1): current = roman[s[i]] next_val = roman[s[i + 1]] if current < next_val: total -= current else: total += current tot...
simplelr_Apps
[ { "content": "Question:\nImplement a function that takes a string containing a valid Roman numeral and converts it to an integer. Roman numerals are typically written from largest to smallest, from left to right. However, some numerals are meant to be subtracted instead of added, such as IV (4) and IX (9). Your...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 649, "level": 1, "question": "Implement a function that takes a string containing a valid Roman numeral and converts it to an integer. Roman numerals are typically written from largest to smallest, from left to right. However, some numerals are meant to be subtracted instead of adde...
import numpy as np def sum_matrices(*args): if not args: return "No matrices provided" first_shape = args[0].shape for matrix in args: if matrix.shape != first_shape: raise ValueError("All matrices must have the same dimensions.") return np.sum(args, axis=0)
simplelr_Filter
[ { "content": "Question:\nCreate a Python function that can sum up an arbitrary number of matrices, where each matrix is represented as a 2D NumPy array. The function should handle the case where an arbitrary number of matrices are passed as arguments. If no matrices are passed, the function should return a mean...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 650, "level": 1, "question": "Create a Python function that can sum up an arbitrary number of matrices, where each matrix is represented as a 2D NumPy array. The function should handle the case where an arbitrary number of matrices are passed as arguments. If no matrices are passed,...
def fibonacci_up_to_max(max_value): if max_value < 0: return [] fib_list = [0, 1] if max_value == 0: return [0] elif max_value == 1: return [0, 1] a, b = 0, 1 while True: next_num = a + b if next_num > max_value: break fib_list.append(n...
simplelr_Filter
[ { "content": "Question:\nWrite a Python function that generates a list of Fibonacci numbers up to a specified maximum value. For example, if the input is 10, the output should be `[0, 1, 1, 2, 3, 5, 8]`.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 651, "level": 1, "question": "Write a Python function that generates a list of Fibonacci numbers up to a specified maximum value. For example, if the input is 10, the output should be `[0, 1, 1, 2, 3, 5, 8]`.", "split": "train" }
def atbash_cipher(message: str) -> str: translated = "" for char in message: if char.isalpha(): if char.isupper(): translated += chr(ord('Z') - (ord(char) - ord('A'))) else: translated += chr(ord('z') - (ord(char) - ord('a'))) else: ...
simplelr_Data_Structure
[ { "content": "Question:\n### Atbash Cipher Encoder\n\n**Context**:\nYou are tasked with creating a simple encryption tool based on the historical Atbash cipher technique. This tool will be used to encode short messages. \n\n**Task**:\nWrite a function called `atbash_cipher` that takes a single string `message` ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 652, "level": 1, "question": "### Atbash Cipher Encoder\n\n**Context**:\nYou are tasked with creating a simple encryption tool based on the historical Atbash cipher technique. This tool will be used to encode short messages. \n\n**Task**:\nWrite a function called `atbash_cipher` tha...
def find_single(nums): res = 0 for num in nums: res ^= num return res
simplelr_Apps
[ { "content": "Question:\nGiven an array of integers where every element appears twice except for one, which appears exactly once, find that single one.\n\nYour task is to write a function `find_single` that returns the integer that appears exactly once.\n\n## Example:\n\n```python\nfind_single([4, 1, 2, 1, 2]) ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 653, "level": 1, "question": "Given an array of integers where every element appears twice except for one, which appears exactly once, find that single one.\n\nYour task is to write a function `find_single` that returns the integer that appears exactly once.\n\n## Example:\n\n```pyt...
def next_maintenance(current_mileage: int, last_maintenance_date: str, vehicle_type: str) -> str: # Define the maintenance intervals for each vehicle type maintenance_intervals = { 'car': 10000, 'truck': 20000, 'motorcycle': 5000 } # Check if the vehicle type is valid if...
simplelr_Algorithm
[ { "content": "Question:\n**Scenario:**\nYou're working on a software project for a logistics company that needs to manage an extensive fleet of vehicles and track their maintenance schedules. The software should efficiently determine the next maintenance date based on the vehicle's current mileage and the vehic...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 654, "level": 1, "question": "**Scenario:**\nYou're working on a software project for a logistics company that needs to manage an extensive fleet of vehicles and track their maintenance schedules. The software should efficiently determine the next maintenance date based on the vehic...
def has_pair_with_difference(arr, k): if k == 0: return False elements = set(arr) for a in arr: if (a + k) in elements: return True return False
simplelr_Leetcode
[ { "content": "Question:\nGiven a sorted array of `n` distinct integers, write a function that finds if there exists a pair of elements with a given difference `k`. The function should return `True` if such a pair exists and `False` otherwise. Note that the array is sorted in ascending order and the pair element...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 655, "level": 1, "question": "Given a sorted array of `n` distinct integers, write a function that finds if there exists a pair of elements with a given difference `k`. The function should return `True` if such a pair exists and `False` otherwise. Note that the array is sorted in as...
def binary_search(nums, target): """ Performs a binary search on a sorted list to find the target element. Args: nums (list): The list of numbers to search. This list will be sorted before searching. target (int): The target number to be found. Returns: int: The index o...
simplelr_Filter
[ { "content": "Question:\nWrite the following Python code that implements a binary search algorithm to search for a specific element in a given list of numbers. The list must be sorted in ascending order before the search is performed. The program should output the index of the target if it is found in the list ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 656, "level": 1, "question": "Write the following Python code that implements a binary search algorithm to search for a specific element in a given list of numbers. The list must be sorted in ascending order before the search is performed. The program should output the index of the ...
def sum_of_evens(lst): return sum(num for num in lst if num % 2 == 0)
simplelr_Prefill
[ { "content": "Question:\nCreate a function that outputs the sum of all the even numbers in a given list. The function should be efficient and avoid unnecessary computations.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 657, "level": 1, "question": "Create a function that outputs the sum of all the even numbers in a given list. The function should be efficient and avoid unnecessary computations.", "split": "train" }
def remove_duplicates(lst): seen = set() unique = [] for num in lst: if num not in seen: seen.add(num) unique.append(num) return unique
simplelr_Filter
[ { "content": "Question:\nWrite a function to remove duplicates from a list of integers while maintaining the original order. The function should be efficient and handle large lists.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 658, "level": 1, "question": "Write a function to remove duplicates from a list of integers while maintaining the original order. The function should be efficient and handle large lists.", "split": "train" }
import pandas as pd import matplotlib.pyplot as plt def analyze_sales_data(filepath: str) -> tuple[pd.DataFrame, pd.DataFrame, pd.DataFrame]: # Read the CSV file into a DataFrame df = pd.read_csv(filepath) # Handle missing 'quantity' values by replacing NaNs with 0 df['quantity'] = df['quantity']....
simplelr_Docs
[ { "content": "Question:\n### Assessing Advanced Pandas Proficiency\n\nYou are tasked with analyzing a sales dataset to derive meaningful insights and visualizations. You are provided with a CSV file named `sales_data.csv` that contains the following columns:\n- `date`: The date of the sale (format: YYYY-MM-DD)....
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 659, "level": 1, "question": "### Assessing Advanced Pandas Proficiency\n\nYou are tasked with analyzing a sales dataset to derive meaningful insights and visualizations. You are provided with a CSV file named `sales_data.csv` that contains the following columns:\n- `date`: The date...
def insertion_sort(arr): n = len(arr) for i in range(1, n): key = arr[i] j = i - 1 while j >= 0 and arr[j] > key: arr[j + 1] = arr[j] j -= 1 arr[j + 1] = key return arr
simplelr_Prefill
[ { "content": "Question:\nWrite a function to sort an array of integers in ascending order using the insertion sort algorithm.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 660, "level": 1, "question": "Write a function to sort an array of integers in ascending order using the insertion sort algorithm.", "split": "train" }
def factorial(n): if n == 0: return 1 result = 1 for i in range(1, n + 1): result *= i return result print(factorial(5))
simplelr_Filter
[ { "content": "Question:\ndef factorial(n):\n if n == 0:\n return 1\n else:\n result = 1\n for i in range(1, n + 1):\n result *= i\n return result\n\nprint(factorial(5))\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 661, "level": 1, "question": "def factorial(n):\n if n == 0:\n return 1\n else:\n result = 1\n for i in range(1, n + 1):\n result *= i\n return result\n\nprint(factorial(5))", "split": "train" }
def count_special_elements(nums): if not nums: return 0 count = 1 max_so_far = nums[-1] for i in range(len(nums)-2, -1, -1): if nums[i] >= max_so_far: count += 1 max_so_far = nums[i] return count
simplelr_Leetcode
[ { "content": "Question:\nYou are given an integer array `nums`. An element `nums[i]` is called **special** if it is greater than or equal to all the elements to its right in the array. Return _the number of special elements in the array._\n\nFor example, given the array `nums = [16, 17, 4, 3, 5, 2]`, the specia...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 662, "level": 1, "question": "You are given an integer array `nums`. An element `nums[i]` is called **special** if it is greater than or equal to all the elements to its right in the array. Return _the number of special elements in the array._\n\nFor example, given the array `nums =...
def check_number(item): return ('Even positive number' if int(item) % 2 == 0 else 'Odd positive number') if (type(item) is int or (type(item) is float and item.is_integer())) and item > 0 else 'Not a positive number'
simplelr_Filter
[ { "content": "Question:\nProblem: Using a ternary form, implement a function which checks if the given item is a positive number. If it is, then further check if it is an even number and return 'Even positive number', if it's an odd number, return 'Odd positive number'. In case the given number isn't positive, ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 663, "level": 1, "question": "Problem: Using a ternary form, implement a function which checks if the given item is a positive number. If it is, then further check if it is an even number and return 'Even positive number', if it's an odd number, return 'Odd positive number'. In case...
def split_even_odd(numbers): evens = [] odds = [] for num in numbers: if num % 2 == 0: evens.append(num) else: odds.append(num) return (evens, odds)
simplelr_Filter
[ { "content": "Question:\nWrite a code to split a list of numbers into two lists: one containing the even numbers and the other containing the odd numbers.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 664, "level": 1, "question": "Write a code to split a list of numbers into two lists: one containing the even numbers and the other containing the odd numbers.", "split": "train" }
def reverse_string(string: str) -> str: letters = [c for c in string if c.isalpha()] reversed_letters = letters[::-1] result = list(string) index = 0 for i in range(len(result)): if result[i].isalpha(): result[i] = reversed_letters[index] index += 1 return ''.join...
simplelr_Evol
[ { "content": "Question:\nWrite a function that takes a string as input and returns the string reversed. However, all non-alphabetic characters should remain in their original positions. For example, the input string \"a,b$c\" should be transformed to \"c,b$a\" because only the alphabetic characters 'a', 'b', an...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 665, "level": 1, "question": "Write a function that takes a string as input and returns the string reversed. However, all non-alphabetic characters should remain in their original positions. For example, the input string \"a,b$c\" should be transformed to \"c,b$a\" because only the ...
def find_common_elements(list1, list2): set1 = set(list1) set2 = set(list2) common = set1.intersection(set2) return list(common)
simplelr_Filter
[ { "content": "Question:\nWrite a Python script to find the common elements between two lists. The common elements should be returned in a new list. The input lists can contain duplicate elements, but the output list should not have any duplicates.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 666, "level": 1, "question": "Write a Python script to find the common elements between two lists. The common elements should be returned in a new list. The input lists can contain duplicate elements, but the output list should not have any duplicates.", "split": "train" }
from typing import List def interpolation_search_custom(array: List[int], search_key: int) -> int: low = 0 high = len(array) - 1 while low <= high and array[low] <= search_key <= array[high]: if array[low] == array[high]: if array[low] == search_key: return low ...
simplelr_Data_Structure
[ { "content": "Question:\n### Coding Assessment\n\n#### Scenario:\n\nYou are tasked with implementing an efficient search function for an application that queries sorted datasets of uniformly distributed numerical values. The function should leverage the interpolation search algorithm to find the index of a give...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 667, "level": 1, "question": "### Coding Assessment\n\n#### Scenario:\n\nYou are tasked with implementing an efficient search function for an application that queries sorted datasets of uniformly distributed numerical values. The function should leverage the interpolation search alg...
def spiral_traversal(matrix): n = len(matrix) result = [] top = 0 bottom = n - 1 left = 0 right = n - 1 while top <= bottom and left <= right: # Traverse top row from left to right for i in range(left, right + 1): result.append(matrix[top][i]) top += 1 ...
simplelr_Taco
[ { "content": "Question:\nWrite a function that simulates a \"spiral walk\" through a square matrix of integers and returns the elements in the order they are encountered. The input to the function will be a 2D list (a list of lists), where each inner list represents a row of the matrix. The function should star...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 668, "level": 1, "question": "Write a function that simulates a \"spiral walk\" through a square matrix of integers and returns the elements in the order they are encountered. The input to the function will be a 2D list (a list of lists), where each inner list represents a row of th...
def can_form_palindrome(n: int) -> bool: s = str(n) freq = {} for c in s: if c in freq: freq[c] += 1 else: freq[c] = 1 odd_count = 0 for count in freq.values(): if count % 2 != 0: odd_count += 1 return odd_count <= 1
simplelr_Apps
[ { "content": "Question:\nGiven a positive integer `n`, determine if it is possible to re-arrange the digits of `n` to form a palindrome. A palindrome is a number that reads the same backward as forward. If it is possible to re-arrange the digits to form such a number, return `True`. Otherwise, return `False`.\n...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 669, "level": 1, "question": "Given a positive integer `n`, determine if it is possible to re-arrange the digits of `n` to form a palindrome. A palindrome is a number that reads the same backward as forward. If it is possible to re-arrange the digits to form such a number, return `T...
def exclude_current_element(lst): total = sum(lst) return [total - x for x in lst]
simplelr_Taco
[ { "content": "Question:\nGiven a list of integers, create a function that calculates and returns a new list where each element is the sum of all the elements in the original list except the one at the current index.\n\nExamples:\n\n input: output:\n [1, 2, 3, 4, 5] -> [14, 13, 12, 11, 10]\n ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 670, "level": 1, "question": "Given a list of integers, create a function that calculates and returns a new list where each element is the sum of all the elements in the original list except the one at the current index.\n\nExamples:\n\n input: output:\n [1, 2, 3,...
def search_matrix(matrix, target): m = len(matrix) if m == 0: return False n = len(matrix[0]) row, col = 0, n - 1 while row < m and col >= 0: current = matrix[row][col] if current == target: return True elif target > current: row += 1 e...
simplelr_Leetcode
[ { "content": "Question:\nGiven a **0-indexed** 2D integer array `matrix` of size `m x n` and an **integer** `target`, find whether `target` exists in `matrix`. This matrix has the following properties:\n * Integers in each row are sorted in ascending order from left to right.\n * Integers in each column are...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 671, "level": 1, "question": "Given a **0-indexed** 2D integer array `matrix` of size `m x n` and an **integer** `target`, find whether `target` exists in `matrix`. This matrix has the following properties:\n * Integers in each row are sorted in ascending order from left to right....
def has_alternating_bits(n): if n < 0: return False if n == 0: return True prev_bit = n & 1 n >>= 1 while n > 0: current_bit = n & 1 if current_bit == prev_bit: return False prev_bit = current_bit n >>= 1 return True
simplelr_Prefill
[ { "content": "Question:\nWrite a function to check if a given integer is a number with alternating bits using Python. The function should return `True` if the integer has alternating bits, otherwise `False`.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 672, "level": 1, "question": "Write a function to check if a given integer is a number with alternating bits using Python. The function should return `True` if the integer has alternating bits, otherwise `False`.", "split": "train" }
def min_operations_to_equal_candies(arr): total = sum(arr) n = len(arr) if total % n != 0: return -1 avg = total // n sum_so_far = 0 res = 0 for num in arr: sum_so_far += (num - avg) res += abs(sum_so_far) return res
simplelr_Leetcode
[ { "content": "Question:\n: Given an integer array `arr` of positive integers where `arr[i]` represents the number of candies the `i-th` child has. You are allowed to perform the following operation any number of times:\n- Choose any two adjacent children and give one candy from one child to the other.\nReturn _...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 673, "level": 1, "question": ": Given an integer array `arr` of positive integers where `arr[i]` represents the number of candies the `i-th` child has. You are allowed to perform the following operation any number of times:\n- Choose any two adjacent children and give one candy from...
def max_consecutive_sales(N, sales): max_current = sales[0] max_global = sales[0] for i in range(1, N): current = max(sales[i], max_current + sales[i]) max_current = current if current > max_global: max_global = current return max_global
simplelr_Code_Contests
[ { "content": "Question:\nAn e-commerce website records the number of items sold each day. The site admin wants to know the maximum number of items sold consecutively across any number of days. You need to write a function that takes an array of integers, where each integer represents the number of items sold on...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 674, "level": 1, "question": "An e-commerce website records the number of items sold each day. The site admin wants to know the maximum number of items sold consecutively across any number of days. You need to write a function that takes an array of integers, where each integer repr...
def first_non_repeating_char(s): char_count = {} for char in s: if char in char_count: char_count[char] += 1 else: char_count[char] = 1 for index, char in enumerate(s): if char_count[char] == 1: return index return -1
simplelr_Filter
[ { "content": "Question:\nHere's the problem: Design an algorithm to find the first non-repeating character in a given string and return its index. No repeating characters are allowed.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 675, "level": 1, "question": "Here's the problem: Design an algorithm to find the first non-repeating character in a given string and return its index. No repeating characters are allowed.", "split": "train" }
from collections import deque def shortestPath(grid, start, end): if start == end: return 0 s_r, s_c = start e_r, e_c = end if grid[s_r][s_c] == 1 or grid[e_r][e_c] == 1: return -1 rows = len(grid) cols = len(grid[0]) # Directions: up, down, left, right ...
simplelr_Codeforces
[ { "content": "Question:\n**Problem Statement**:\n\nYou are given a map of a city grid where some of the cells are obstacles, and others are passable. You need to find the shortest path from a given starting cell to a destination cell. The city grid is represented as a 2D array of integers, where `0` represents ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 676, "level": 1, "question": "**Problem Statement**:\n\nYou are given a map of a city grid where some of the cells are obstacles, and others are passable. You need to find the shortest path from a given starting cell to a destination cell. The city grid is represented as a 2D array ...
def find_uppercase_characters(s): return [char for char in s if char.isupper()]
simplelr_Prefill
[ { "content": "Question:\nWrite a function to find all uppercase characters in a string and return them.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 677, "level": 1, "question": "Write a function to find all uppercase characters in a string and return them.", "split": "train" }
def print_list_in_reverse(lst): for item in reversed(lst): print(item)
simplelr_Filter
[ { "content": "Question:\nWrite a python function that takes a list as an argument and prints all elements of the list in reverse order.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 678, "level": 1, "question": "Write a python function that takes a list as an argument and prints all elements of the list in reverse order.", "split": "train" }
def is_anagram(a, b): return sorted(a.replace(' ','').lower()) == sorted(b.replace(' ','').lower())
simplelr_Filter
[ { "content": "Question:\nCode Golf: Determine whether two strings are anagrams of each other in Python\n====================================================================\n\nHere is the desired functionality:\n\n* The function should be case insensitive.\n* The function should ignore any spaces.\n* The ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 679, "level": 1, "question": "Code Golf: Determine whether two strings are anagrams of each other in Python\n====================================================================\n\nHere is the desired functionality:\n\n* The function should be case insensitive.\n* The function s...
def find_highest_score(students): highest_name = students[0]['name'] highest_score = students[0]['score'] for student in students: if student['score'] > highest_score: highest_score = student['score'] highest_name = student['name'] return {'name': highest_name, 'score': h...
simplelr_Filter
[ { "content": "Question:\nYou've been tasked with writing a function `find_highest_score` to find the highest score in a list of students along with the student's name. The input will be a list of dictionaries, where each dictionary represents a student and contains two keys: 'name' and 'score'. The function sho...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 680, "level": 1, "question": "You've been tasked with writing a function `find_highest_score` to find the highest score in a list of students along with the student's name. The input will be a list of dictionaries, where each dictionary represents a student and contains two keys: 'n...
def string_lengths(lst): return [len(s) for s in lst]
simplelr_Filter
[ { "content": "Question:\nThis code defines a function that takes a list of strings as input and returns a list of the lengths of those strings.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 681, "level": 1, "question": "This code defines a function that takes a list of strings as input and returns a list of the lengths of those strings.", "split": "train" }
def convert_to_zigzag(s, n): if n == 1 or n == 0: return s rows = [''] * n current_row = 0 step = 1 # 1 indicates moving down, -1 indicates moving up for c in s: rows[current_row] += c if current_row == 0: step = 1 elif current_row == n - 1: ...
simplelr_Leetcode
[ { "content": "Question:\nYou are given a string `s` consisting of lowercase alphabets and an integer `n`. You need to transform the string into a \"zigzag\" pattern on a given number of rows. The pattern is created by writing the characters of the string in a zigzag manner and then reading line by line. Specifi...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 682, "level": 1, "question": "You are given a string `s` consisting of lowercase alphabets and an integer `n`. You need to transform the string into a \"zigzag\" pattern on a given number of rows. The pattern is created by writing the characters of the string in a zigzag manner and ...
def remove_duplicates(input_string: str) -> str: seen = set() result = [] for char in input_string: if char not in seen: result.append(char) seen.add(char) return ''.join(result)
simplelr_Data_Structure
[ { "content": "Question:\nYou have been given a string and your task is to remove any reoccurring characters, returning the new string that consists of only the first unique occurrence of each character.\n\nWrite a function `remove_duplicates` that implements this string filtering algorithm.\n\n### Function Sign...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 683, "level": 1, "question": "You have been given a string and your task is to remove any reoccurring characters, returning the new string that consists of only the first unique occurrence of each character.\n\nWrite a function `remove_duplicates` that implements this string filteri...
from typing import List, Tuple def calculate_max_distances(fleet: List[Tuple[float, float]]) -> List[float]: """ Calculate the maximum distance each vehicle in the fleet can travel based on its fuel efficiency and fuel capacity. Args: fleet (List[Tuple[float, float]]): A list of tuples where each ...
simplelr_Algorithm
[ { "content": "Question:\n**Context**: You are developing a software that manages a fleet of delivery vehicles for a logistics company. Each vehicle has a specific fuel efficiency and fuel capacity, and your task is to optimize the routes so that each vehicle can complete its deliveries without running out of fu...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 684, "level": 1, "question": "**Context**: You are developing a software that manages a fleet of delivery vehicles for a logistics company. Each vehicle has a specific fuel efficiency and fuel capacity, and your task is to optimize the routes so that each vehicle can complete its de...
def decode_string(s): stack = [] curr_str = '' curr_num = 0 for c in s: if c.isdigit(): curr_num = curr_num * 10 + int(c) elif c == '[': stack.append((curr_str, curr_num)) curr_str = '' curr_num = 0 elif c == ']': prev_s...
simplelr_Filter
[ { "content": "Question:\nGiven an encoded string whose format is [number: encoded_string], where number represents the frequency of the encoded_string that follows, your task is to decode it. For instance, \"3[a]2[bc]\" is decoded to \"aaabcbc\". \n\nNote: The string will only contain numbers, letters (lowercas...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 685, "level": 1, "question": "Given an encoded string whose format is [number: encoded_string], where number represents the frequency of the encoded_string that follows, your task is to decode it. For instance, \"3[a]2[bc]\" is decoded to \"aaabcbc\". \n\nNote: The string will only ...
def average(numbers): if not numbers: return 0.0 return sum(numbers) / len(numbers)
simplelr_Filter
[ { "content": "Question:\nCreate a function in Python that takes a list of integers and returns the average of the numbers in the list. The function should handle an empty list by returning 0.0.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 686, "level": 1, "question": "Create a function in Python that takes a list of integers and returns the average of the numbers in the list. The function should handle an empty list by returning 0.0.", "split": "train" }
from typing import List def calculate_median_age(ages: List[int]) -> float: if not ages: raise ValueError("Input list cannot be empty") sorted_ages = sorted(ages) n = len(sorted_ages) if n % 2 == 1: median = float(sorted_ages[n // 2]) else: mid1 = sorted_ages[n // ...
simplelr_Algorithm
[ { "content": "Question:\n### Problem Statement:\nYou are developing a module for demographic analysis and need to calculate the median age from a given list of ages. \n\n### Requirements:\nImplement a function `calculate_median_age(ages: List[int]) -> float` that calculates the median of a list of ages. The fun...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 687, "level": 1, "question": "### Problem Statement:\nYou are developing a module for demographic analysis and need to calculate the median age from a given list of ages. \n\n### Requirements:\nImplement a function `calculate_median_age(ages: List[int]) -> float` that calculates the...
def longestUniqueSubstring(s): char_map = {} left = 0 max_length = 0 for right in range(len(s)): char = s[right] if char in char_map: left = max(left, char_map[char] + 1) char_map[char] = right current_length = right - left + 1 if current_length > max_...
simplelr_Apps
[ { "content": "Question:\n# Introduction and Warm-up\n\n# Task\n\n**_Given_** a *string* that contains a mixture of lowercase and uppercase letters, **_identify_** the *longest substring* that contains unique characters and return the length of that substring. \n___\n\n# Notes \n\n* **_String_** length is *at le...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 688, "level": 1, "question": "# Introduction and Warm-up\n\n# Task\n\n**_Given_** a *string* that contains a mixture of lowercase and uppercase letters, **_identify_** the *longest substring* that contains unique characters and return the length of that substring. \n___\n\n# Notes \...
def area_of_triangle(base, height): """ Calculate the area of a triangle. Args: base: The base of the triangle. height: The height of the triangle. Returns: The area of the triangle. """ area = (base * height) / 2 return area
simplelr_Filter
[ { "content": "Question:\nThis is a code for calculating the area of a triangle:\n\n```python\ndef area_of_triangle(base, height):\n \"\"\"\n Calculate the area of a triangle.\n \n Args:\n base: The base of the triangle.\n\n height: The height of the triangle.\n\n Returns:\n The area of the t...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 689, "level": 1, "question": "This is a code for calculating the area of a triangle:\n\n```python\ndef area_of_triangle(base, height):\n \"\"\"\n Calculate the area of a triangle.\n \n Args:\n base: The base of the triangle.\n\n height: The height of the triangle.\n\n ...
def find_max_indices(arr): max_val = float('-inf') indices = None for i, row in enumerate(arr): for j, val in enumerate(row): if val > max_val: max_val = val indices = (i, j) return indices
simplelr_Filter
[ { "content": "Question:\nGiven a 2D array, find the indices of the maximum element in that array. \n\nFor example, given the following 2D array: \n[[1, 2, 3], [4, 5, 6], [7, 8, 9]] \n\nThe function should return (2, 2) since 9 is the maximum number in the array and its indices are (2, 2). \n\nHowever, if there ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 690, "level": 1, "question": "Given a 2D array, find the indices of the maximum element in that array. \n\nFor example, given the following 2D array: \n[[1, 2, 3], [4, 5, 6], [7, 8, 9]] \n\nThe function should return (2, 2) since 9 is the maximum number in the array and its indices ...
from heapq import heappop, heappush def shortest_path(graph, start, end): # Create a priority queue to hold all nodes to be processed queue = [(0, 0, start, [])] # Set to record visited nodes visited = set() while queue: # Pop the node with the lowest cost and edges from the queue...
simplelr_Filter
[ { "content": "Question:\nI am trying to generate a program that chooses the best path between two nodes in a weighted graph. The path with the lowest cost is preferred. The path with the least amount of edges is preferred in case of a tie. \n\nHere is the code I have so far:\n```python\nfrom heapq import heappo...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 691, "level": 1, "question": "I am trying to generate a program that chooses the best path between two nodes in a weighted graph. The path with the lowest cost is preferred. The path with the least amount of edges is preferred in case of a tie. \n\nHere is the code I have so far:\n`...
def longest_sequence(n, chapters): result = [] for chapter in chapters: current = 0 max_seq = 0 for char in chapter: if char == '1': current += 1 else: if current > max_seq: max_seq = current curr...
simplelr_Code_Contests
[ { "content": "Question:\n### Problem Statement\n\nSarah loves to read novels, but she often gets distracted and loses track of her place while reading. To help her focus, she has come up with a special reading system: each chapter of the novel is represented by a binary string of '0's and '1's. She starts readi...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 692, "level": 1, "question": "### Problem Statement\n\nSarah loves to read novels, but she often gets distracted and loses track of her place while reading. To help her focus, she has come up with a special reading system: each chapter of the novel is represented by a binary string ...
def edit_distance(str1: str, str2: str) -> int: len_str1 = len(str1) len_str2 = len(str2) # Create a 2D list with (len_str1 + 1) rows and (len_str2 + 1) columns initialized to 0 dp = [[0 for _ in range(len_str2 + 1)] for _ in range(len_str1 + 1)] # Initialize the base cases for i in ra...
simplelr_Algorithm
[ { "content": "Question:\n### Question\n\n#### Editing Distance Calculation Challenge\n\nYou are required to implement an algorithm that calculates the minimum edit distance (Levenshtein distance) between two strings. This metric represents the minimum number of single-character edits (insertions, deletions, or ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 693, "level": 1, "question": "### Question\n\n#### Editing Distance Calculation Challenge\n\nYou are required to implement an algorithm that calculates the minimum edit distance (Levenshtein distance) between two strings. This metric represents the minimum number of single-character...
def first_unique_character(s): char_count = {} # First pass to count each character for char in s: if char in char_count: char_count[char] += 1 else: char_count[char] = 1 # Second pass to find the first non-repeating character for char in s: if char_co...
simplelr_Taco
[ { "content": "Question:\nWrite a function that takes a string as input and returns the first character that does not repeat. If all characters repeat, the function should return an empty string.\n\nThe function should be case-sensitive, meaning 'a' and 'A' are considered different characters.\n\nExample inputs ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 694, "level": 1, "question": "Write a function that takes a string as input and returns the first character that does not repeat. If all characters repeat, the function should return an empty string.\n\nThe function should be case-sensitive, meaning 'a' and 'A' are considered differ...
from collections import deque from typing import List, Tuple def shortest_path(connections: List[Tuple[int, int]], start: int, end: int) -> int: if start == end: return 0 # Build the adjacency list graph = {} for a, b in connections: if a not in graph: graph[a] = [] ...
simplelr_Algorithm
[ { "content": "Question:\n### Coding Assessment Question\n\n#### Scenario\nYou have joined a tech startup as a software developer. Your current project involves analyzing networks of computers. One of the tasks is to determine the shortest path between two computers in a network, where the network is represented...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 695, "level": 1, "question": "### Coding Assessment Question\n\n#### Scenario\nYou have joined a tech startup as a software developer. Your current project involves analyzing networks of computers. One of the tasks is to determine the shortest path between two computers in a network...
def nextPermutation(nums): n = len(nums) i = n - 2 # Find the largest index 'i' such that nums[i] < nums[i+1] while i >= 0 and nums[i] >= nums[i+1]: i -= 1 if i == -1: # The array is in descending order; reverse to get the smallest permutation nums.reverse() els...
simplelr_Taco
[ { "content": "Question:\nGiven an array of integers nums, find the next permutation of nums in lexicographical order. If such an arrangement is not possible, rearrange nums to the lowest possible order (i.e., sorted in ascending order).\n\nThe replacement must be in-place and use only constant extra memory.\n\n...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 696, "level": 1, "question": "Given an array of integers nums, find the next permutation of nums in lexicographical order. If such an arrangement is not possible, rearrange nums to the lowest possible order (i.e., sorted in ascending order).\n\nThe replacement must be in-place and u...
def sum_even_numbers(numbers): """ This function takes a list of numbers and returns the sum of all even numbers in the list. """ total = 0 for number in numbers: if number % 2 == 0: total += number return total # Example usage: numbers = [1, 2, 3, 4, 5, 6] sum_of_evens = su...
simplelr_Filter
[ { "content": "Question:\nYou are a large language model, trained by Google.\n\nI need help writing a Python program that takes a list of numbers as input and returns the sum of all even numbers in the list.\n\n```python\ndef sum_even_numbers(numbers):\n \"\"\"\n This function takes a list of numbers and retur...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 697, "level": 1, "question": "You are a large language model, trained by Google.\n\nI need help writing a Python program that takes a list of numbers as input and returns the sum of all even numbers in the list.\n\n```python\ndef sum_even_numbers(numbers):\n \"\"\"\n This function...
def reverse_words(s: str) -> str: words = s.split() return ' '.join(reversed(words)) if words else ''
simplelr_Algorithm
[ { "content": "Question:\n### Reverse Words in a String\n\n**Problem Statement:**\n\nWrite a function `reverse_words` that takes in a string and returns a string with the words reversed. Words are defined as sequences of characters separated by spaces. You should consider the following points:\n\n1. If the input...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 698, "level": 1, "question": "### Reverse Words in a String\n\n**Problem Statement:**\n\nWrite a function `reverse_words` that takes in a string and returns a string with the words reversed. Words are defined as sequences of characters separated by spaces. You should consider the fo...
def unique_list(input_list): return list(dict.fromkeys(input_list)) # Example usage: my_list = [1, 2, 2, 3, 4, 4, 5] unique = unique_list(my_list) print(unique) # Output: [1, 2, 3, 4, 5]
simplelr_Filter
[ { "content": "Question:\nHow do I ensure that a list in Python is unique without losing the order of elements?\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 699, "level": 1, "question": "How do I ensure that a list in Python is unique without losing the order of elements?", "split": "train" }