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 are_anagrams(s1, s2): if len(s1) != len(s2): return False return sorted(s1) == sorted(s2)
simplelr_Apps
[ { "content": "Question:\nComplete the function to determine if a given string is an anagram of another string. Two strings are considered anagrams if they contain the same characters in the same frequencies. You can assume the input strings contain only lowercase alphabets.\n\n## Example\n```python\ninput strin...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8200, "level": 1, "question": "Complete the function to determine if a given string is an anagram of another string. Two strings are considered anagrams if they contain the same characters in the same frequencies. You can assume the input strings contain only lowercase alphabets.\n\...
import bisect def longest_book(books, X): result = {} for genre in books: page_list = books[genre] idx = bisect.bisect_right(page_list, X) if idx == 0: result[genre] = 0 else: result[genre] = page_list[idx - 1] return result
simplelr_Taco
[ { "content": "Question:\nPaul loves reading books, and he has a unique way of selecting them. Each book he reads fits a specific genre and has a finite number of pages. Paul has a bookshelf with books categorized by genre and each genre has a list of books sorted in ascending order by the number of pages.\n\nPa...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8201, "level": 1, "question": "Paul loves reading books, and he has a unique way of selecting them. Each book he reads fits a specific genre and has a finite number of pages. Paul has a bookshelf with books categorized by genre and each genre has a list of books sorted in ascending ...
import pandas as pd def process_sales_data(file1, file2): # Step 1: Load the datasets df1 = pd.read_csv(file1) df2 = pd.read_csv(file2) # Step 2: Merge the datasets on ProductID df_merged = pd.merge(df1, df2, on='ProductID') # Step 3: Handle missing values for column in df_merged....
simplelr_Docs
[ { "content": "Question:\n### Pandas Coding Assessment\n\n**Objective:**\n\nThe purpose of this task is to evaluate your ability to use the `pandas` library, specifically the `DataFrame` class. Your task involves constructing dataframes, performing transformations, handling missing data, and generating summary s...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8202, "level": 1, "question": "### Pandas Coding Assessment\n\n**Objective:**\n\nThe purpose of this task is to evaluate your ability to use the `pandas` library, specifically the `DataFrame` class. Your task involves constructing dataframes, performing transformations, handling mis...
def min_distance(string1, string2): m = len(string1) n = len(string2) # Create a DP table with (m+1) rows and (n+1) columns dp = [[0] * (n + 1) for _ in range(m + 1)] # Initialize the first row and column for i in range(m + 1): dp[i][0] = i for j in range(n + 1): dp...
simplelr_Leetcode
[ { "content": "Question:\nYou are given two strings, `string1` and `string2`, which consist of lowercase letters. You need to transform `string1` into `string2` by performing a sequence of allowed operations. In each operation, you can do one of the following:\n- Insert a new character into `string1`.\n- Delete ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8203, "level": 1, "question": "You are given two strings, `string1` and `string2`, which consist of lowercase letters. You need to transform `string1` into `string2` by performing a sequence of allowed operations. In each operation, you can do one of the following:\n- Insert a new c...
def find_maximum(lst): if not lst: return None return max(lst)
simplelr_Filter
[ { "content": "Question:\nWrite a Python function to find the maximum value in a list of integers. The function should be efficient in terms of both time and space complexity. Consider edge cases such as an empty list or a list with one element.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8204, "level": 1, "question": "Write a Python function to find the maximum value in a list of integers. The function should be efficient in terms of both time and space complexity. Consider edge cases such as an empty list or a list with one element.", "split": "train" }
def fibonacci_series(n): if n <= 0: return [] elif n == 1: return [0] fib_series = [0, 1] if n == 2: return fib_series for i in range(2, n): next_term = fib_series[i-1] + fib_series[i-2] fib_series.append(next_term) return fib_series
simplelr_Prefill
[ { "content": "Question:\nWrite a python function to print the Fibonacci series up to 'n' terms.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8205, "level": 1, "question": "Write a python function to print the Fibonacci series up to 'n' terms.", "split": "train" }
def convert_to_binary(n): if n < 0: return '-' + bin(-n)[2:] else: return bin(n)[2:]
simplelr_Filter
[ { "content": "Question:\nYou can build a simple decimal to binary converter. Create a function called `convert_to_binary` that takes a decimal number as an argument and returns the binary representation of that number as a string.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8206, "level": 1, "question": "You can build a simple decimal to binary converter. Create a function called `convert_to_binary` that takes a decimal number as an argument and returns the binary representation of that number as a string.", "split": "train" }
def find_pattern_occurrences(text: str, pattern: str) -> list[int]: m = len(pattern) n = len(text) if m == 0 or m > n: return [] base = 256 mod = 10**9 + 7 h = pow(base, m - 1, mod) pattern_hash = 0 for c in pattern: pattern_hash = (pattern_hash * base + ord(c))...
simplelr_Data_Structure
[ { "content": "Question:\nYou are given a large text and a smaller pattern string. Your task is to implement an efficient algorithm to find all the starting indices of occurrences of the pattern in the text using the Rabin-Karp algorithm.\n\n### Function Signature:\n```python\ndef find_pattern_occurrences(text: ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8207, "level": 1, "question": "You are given a large text and a smaller pattern string. Your task is to implement an efficient algorithm to find all the starting indices of occurrences of the pattern in the text using the Rabin-Karp algorithm.\n\n### Function Signature:\n```python\n...
def sum_of_prime_factors(n: int) -> int: if n < 2: raise ValueError("n must be >= 2") factors = set() # Handle the case for 2 separately if n % 2 == 0: factors.add(2) while n % 2 == 0: n = n // 2 # Now n must be odd, so check for odd factors starting from 3 i ...
simplelr_Algorithm
[ { "content": "Question:\n### Sum of Prime Factors\n\nDesign a function that calculates the sum of all unique prime factors of a given integer \\(n\\).\n\n### Function Signature\n`def sum_of_prime_factors(n: int) -> int:`\n\n### Input\n- An integer \\(n\\) where \\(n \\geq 2\\).\n\n### Output\n- Returns the sum ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8208, "level": 1, "question": "### Sum of Prime Factors\n\nDesign a function that calculates the sum of all unique prime factors of a given integer \\(n\\).\n\n### Function Signature\n`def sum_of_prime_factors(n: int) -> int:`\n\n### Input\n- An integer \\(n\\) where \\(n \\geq 2\\)...
from collections import Counter def first_non_repeating_char(s): if not s: return None count = Counter(s) for char in s: if count[char] == 1: return char return None
simplelr_Filter
[ { "content": "Question:\nWrite a Python function to find the first non-repeating character in a given string. If all characters repeat, return None. For example, the first non-repeating character in \"apple\" is \"p\", and the first non-repeating character in \"aabbcc\" is None.\nAnswer:\nLet's think step by st...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8209, "level": 1, "question": "Write a Python function to find the first non-repeating character in a given string. If all characters repeat, return None. For example, the first non-repeating character in \"apple\" is \"p\", and the first non-repeating character in \"aabbcc\" is Non...
from typing import Optional, List def limit(arr: List[int], min_lim: Optional[int] = None, max_lim: Optional[int] = None) -> List[int]: """ Filters the input array based on the specified minimum and/or maximum value. Parameters: arr (list of int): The input array of integers. min_lim (int, optiona...
simplelr_Data_Structure
[ { "content": "Question:\nYou are tasked with writing a function that filters an array such that only elements within a specified minimum and/or maximum value are included. The provided constraints should ensure an efficient algorithm with linear time complexity.\n\n### Function Definition:\n```python\ndef limit...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8210, "level": 1, "question": "You are tasked with writing a function that filters an array such that only elements within a specified minimum and/or maximum value are included. The provided constraints should ensure an efficient algorithm with linear time complexity.\n\n### Functio...
def find_largest_number(nums): if not nums: return None max_num = nums[0] for num in nums: if num > max_num: max_num = num return max_num
simplelr_Prefill
[ { "content": "Question:\nWrite a function to find the largest number in an array of integers. The function should be able to handle arrays with both positive and negative numbers.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8211, "level": 1, "question": "Write a function to find the largest number in an array of integers. The function should be able to handle arrays with both positive and negative numbers.", "split": "train" }
import pprint def custom_pretty_print(data, indent=2, width=100, depth=5, compact=True, sort_dicts=False, underscore_numbers=True): """ Pretty-prints the given data structure with specified formatting parameters. Args: data: The nested data structure to be printed. indent (int): The number...
simplelr_Docs
[ { "content": "Question:\n**Coding Assessment Question**\n\n### Custom Pretty-Print Function using `pprint`\n\n#### Objective:\nCreate a custom pretty-print function that formats complex nested data structures using specific formatting parameters. This function will demonstrate your understanding of the `pprint`...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8212, "level": 1, "question": "**Coding Assessment Question**\n\n### Custom Pretty-Print Function using `pprint`\n\n#### Objective:\nCreate a custom pretty-print function that formats complex nested data structures using specific formatting parameters. This function will demonstrate...
def next_alphabet_string(s: str) -> str: result = [] for c in s: new_ord = ord(c) - ord('a') new_ord = (new_ord + 1) % 26 new_char = chr(new_ord + ord('a')) result.append(new_char) return ''.join(result)
simplelr_Code_Contests
[ { "content": "Question:\nYou are given a string that contains only lowercase alphabets. Your task is to transform this string into a new string where each character is replaced by the next character in the English alphabet. The letter 'z' should wrap around to become 'a'.\n\nImplement a function `next_alphabet_...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8213, "level": 1, "question": "You are given a string that contains only lowercase alphabets. Your task is to transform this string into a new string where each character is replaced by the next character in the English alphabet. The letter 'z' should wrap around to become 'a'.\n\nI...
def restore_string(s, indices): n = len(s) original = [''] * n for i in range(n): pos = indices[i] original[pos] = s[i] return ''.join(original)
simplelr_Leetcode
[ { "content": "Question:\nYou are given a string `s` and an integer array `indices` of the same length. The string `s` has been shuffled such that the character at the `i`-th position in `s` was moved to `indices[i]`. Write a function to return the original string by restoring the characters to their respective ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8214, "level": 1, "question": "You are given a string `s` and an integer array `indices` of the same length. The string `s` has been shuffled such that the character at the `i`-th position in `s` was moved to `indices[i]`. Write a function to return the original string by restoring ...
def wiggle_sort(nums: list[int]) -> None: for i in range(len(nums) - 1): if i % 2 == 0: if nums[i] >= nums[i+1]: nums[i], nums[i+1] = nums[i+1], nums[i] else: if nums[i] <= nums[i+1]: nums[i], nums[i+1] = nums[i+1], nums[i]
simplelr_Data_Structure
[ { "content": "Question:\n### Question Title: Wiggle Sort Implementation\n\n### Description:\nGiven an unsorted array `nums`, your task is to reorder it such that `nums[0] < nums[1] > nums[2] < nums[3]....`. This pattern of alternating peaks and valleys must be maintained throughout the array. Your implementatio...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8215, "level": 1, "question": "### Question Title: Wiggle Sort Implementation\n\n### Description:\nGiven an unsorted array `nums`, your task is to reorder it such that `nums[0] < nums[1] > nums[2] < nums[3]....`. This pattern of alternating peaks and valleys must be maintained throu...
def remove_duplicates(nums): if not nums: return 0 write = 0 for i in range(1, len(nums)): if nums[i] != nums[write]: write += 1 nums[write] = nums[i] return write + 1
simplelr_Filter
[ { "content": "Question:\nGiven a sorted array of integers, write a function to remove the duplicates in place such that each element appears only once and returns the new length. The function should modify the input array in place with O(1) extra memory. For example, given the array [1, 1, 2], the function shou...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8216, "level": 1, "question": "Given a sorted array of integers, write a function to remove the duplicates in place such that each element appears only once and returns the new length. The function should modify the input array in place with O(1) extra memory. For example, given the...
def is_complete_binary_tree(lst): if not lst: return True # Find the last non-None element last_idx = -1 for i in range(len(lst)-1, -1, -1): if lst[i] is not None: last_idx = i break if last_idx == -1: return True # Determine the height of the tr...
simplelr_Leetcode
[ { "content": "Question:\nYou are given a binary tree represented as a list where elements are stored in level order traversal of the tree. Each element can either be an integer or `None` (indicating that there is no valid node at that position). Your task is to determine if this tree is a **Complete Binary Tree...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8217, "level": 1, "question": "You are given a binary tree represented as a list where elements are stored in level order traversal of the tree. Each element can either be an integer or `None` (indicating that there is no valid node at that position). Your task is to determine if th...
from functools import lru_cache @lru_cache(maxsize=None) def fibonacci(n): if n == 0: return 0 elif n == 1: return 1 else: return fibonacci(n - 1) + fibonacci(n - 2)
simplelr_Prefill
[ { "content": "Question:\nCreate a function that calculates the n-th Fibonacci number using memoization.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8218, "level": 1, "question": "Create a function that calculates the n-th Fibonacci number using memoization.", "split": "train" }
from typing import List def evaluate_expressions(expressions: List[str]) -> List[float]: results = [] for expr in expressions: result = eval(expr) results.append(float(result)) return results
simplelr_Evol
[ { "content": "Question:\nYou are given a list of strings, each representing a mathematical expression. Your task is to evaluate each expression and return a list with the results of each evaluated expression. The mathematical expressions will contain integers, the operators (+, -, *, /), and parentheses for alt...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8219, "level": 1, "question": "You are given a list of strings, each representing a mathematical expression. Your task is to evaluate each expression and return a list with the results of each evaluated expression. The mathematical expressions will contain integers, the operators (+...
def count_and_sum_positives(arr): count = 0 total_sum = 0 for num in arr: if num > 0: count += 1 total_sum += num return (count, total_sum)
simplelr_Filter
[ { "content": "Question:\nCreate a Python function which not only identifies the count of positive elements within the array of integers but also calculates the cumulative sum of these positive integers. Additionally, include an algorithm to optimize the search and computation process, favoring time complexity w...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8220, "level": 1, "question": "Create a Python function which not only identifies the count of positive elements within the array of integers but also calculates the cumulative sum of these positive integers. Additionally, include an algorithm to optimize the search and computation ...
def spiral_order(matrix): result = [] if not matrix: return result top = 0 bottom = len(matrix) - 1 left = 0 right = len(matrix[0]) - 1 while top <= bottom and left <= right: # Traverse top row for i in range(left, right + 1): result.append(matrix[top][i]...
simplelr_Prefill
[ { "content": "Question:\nWrite a function to print the elements of a matrix in spiral order. The function should take a 2D list of integers as input and return an array of integers representing the elements in spiral order.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8221, "level": 1, "question": "Write a function to print the elements of a matrix in spiral order. The function should take a 2D list of integers as input and return an array of integers representing the elements in spiral order.", "split": "train" }
import os def resolve_absolute_path(file_path: str) -> str: expanded_path = os.path.expanduser(file_path) absolute_path = os.path.abspath(expanded_path) return absolute_path
simplelr_Data_Structure
[ { "content": "Question:\nAbsolute Path Resolution\n\nYou are working on a utility script that requires consistently resolving file paths to their absolute equivalents. This is crucial in ensuring that all file operations are performed on correctly identified files regardless of the current working directory or ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8222, "level": 1, "question": "Absolute Path Resolution\n\nYou are working on a utility script that requires consistently resolving file paths to their absolute equivalents. This is crucial in ensuring that all file operations are performed on correctly identified files regardless o...
def remove_max_k_times(arr, k): result = [] for _ in range(k): if not arr: break max_val = max(arr) result.append(max_val) arr.remove(max_val) return result
simplelr_Filter
[ { "content": "Question:\nGiven an integer k and an array of integers, keep removing the maximum value from the array and adding it to a new array until k times. Write a code to simulate this process.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8223, "level": 1, "question": "Given an integer k and an array of integers, keep removing the maximum value from the array and adding it to a new array until k times. Write a code to simulate this process.", "split": "train" }
def find_minimum_value(lst): if not lst: return None min_value = lst[0] for num in lst[1:]: if num < min_value: min_value = num return min_value
simplelr_Prefill
[ { "content": "Question:\nCreate a function that provides the minimum value from a given list of integers. How can I solve this problem in Python?\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8224, "level": 1, "question": "Create a function that provides the minimum value from a given list of integers. How can I solve this problem in Python?", "split": "train" }
def sum_mul(n, m): if not (isinstance(n, int) and isinstance(m, int)) or n <= 0 or m <= 0: return "INVALID" q = (m - 1) // n return n * q * (q + 1) // 2
simplelr_Apps
[ { "content": "Question:\nWrite a function `sum_mul(n, m)` that will return the sum of all multiples of `n` below `m`. If `m` is not a positive integer or `n` is not a positive integer, return \"INVALID\".\n\nExamples:\n\n```\nsum_mul(2, 9) -> 20 (2 + 4 + 6 + 8)\nsum_mul(3, 10) -> 18 (3 + 6 + 9)\nsum_mu...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8225, "level": 1, "question": "Write a function `sum_mul(n, m)` that will return the sum of all multiples of `n` below `m`. If `m` is not a positive integer or `n` is not a positive integer, return \"INVALID\".\n\nExamples:\n\n```\nsum_mul(2, 9) -> 20 (2 + 4 + 6 + 8)\nsum_mul(3...
def is_rotated_sorted(nums): if len(nums) <= 1: return True count = 0 for i in range(len(nums) - 1): if nums[i] > nums[i + 1]: count += 1 if count > 1: return False if count == 0: return True else: return nums[-1] <= nums[0]
simplelr_Taco
[ { "content": "Question:\nGiven an array of integers, nums, return true if the array was originally sorted in an increasing order, and then possibly rotated. Otherwise, return false.\n\nTo clarify, a rotated array is formed by taking some prefix of the array and moving it to the end. For example, the array [3,4,...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8226, "level": 1, "question": "Given an array of integers, nums, return true if the array was originally sorted in an increasing order, and then possibly rotated. Otherwise, return false.\n\nTo clarify, a rotated array is formed by taking some prefix of the array and moving it to th...
def count_unique_substrings(s, k): n = len(s) if k == 0 or k > n: return 0 count = 0 freq = [0] * 26 left = 0 num_duplicates = 0 for right in range(n): c = s[right] idx = ord(c) - ord('a') if freq[idx] == 1: num_duplicates += 1 freq[id...
simplelr_Leetcode
[ { "content": "Question:\nGiven a string `s` consisting of lowercase English letters and an integer `k`, count the number of substrings of `s` of length `k` that contain no repeated characters. Return an integer representing the number of such substrings.\nAnswer:\nLet's think step by step.\n", "role": "user...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8227, "level": 1, "question": "Given a string `s` consisting of lowercase English letters and an integer `k`, count the number of substrings of `s` of length `k` that contain no repeated characters. Return an integer representing the number of such substrings.", "split": "train" }
def maxBuildingHeight(heights, k): return max(heights) + k
simplelr_Leetcode
[ { "content": "Question:\nYou are given an integer array `heights` representing the heights of buildings along a street, where `heights[i]` is the height of the ith building. You are allowed to increase the height of any building by 1 unit multiple times. However, the total number of increases cannot exceed `k` ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8228, "level": 1, "question": "You are given an integer array `heights` representing the heights of buildings along a street, where `heights[i]` is the height of the ith building. You are allowed to increase the height of any building by 1 unit multiple times. However, the total num...
def max_subarray_sum(arr): if not arr: return 0 # Handles empty array case, returns 0 current_max = global_max = arr[0] for num in arr[1:]: current_max = max(num, current_max + num) if current_max > global_max: global_max = current_max return global_ma...
simplelr_Prefill
[ { "content": "Question:\nCreate a function that takes an array of integers and returns the maximum possible sum of a sub-array. The array can contain both positive and negative integers.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8229, "level": 1, "question": "Create a function that takes an array of integers and returns the maximum possible sum of a sub-array. The array can contain both positive and negative integers.", "split": "train" }
def count_vowels(s): if not isinstance(s, str): return 0 vowels = {'a', 'e', 'i', 'o', 'u', 'y'} found_vowels = set() for c in s.lower(): if c in vowels: found_vowels.add(c) return len(found_vowels)
simplelr_Filter
[ { "content": "Question:\nI'll provide you with a string of text and I'd like you to respond with the number of vowels in that string. \n\nExample: if I said \"hello\", you'd say \"2\". \n\nI'd like to count each vowel (a, e, i, o, u) only once per character - so if a character is repeated (like \"aa\") it's sti...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8230, "level": 1, "question": "I'll provide you with a string of text and I'd like you to respond with the number of vowels in that string. \n\nExample: if I said \"hello\", you'd say \"2\". \n\nI'd like to count each vowel (a, e, i, o, u) only once per character - so if a character...
from typing import List, Union def second_largest_unique(numbers: List[int]) -> Union[int, None]: unique = list(set(numbers)) unique.sort(reverse=True) if len(unique) < 2: return None return unique[1]
simplelr_Taco
[ { "content": "Question:\nImplement a function that takes a list of integers and returns the second largest unique number in the list. If no such number exists, return `None`.\n\n**Function Signature:** `def second_largest_unique(numbers: List[int]) -> Union[int, None]`\n\n**Input:**\n- A list of integers which ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8231, "level": 1, "question": "Implement a function that takes a list of integers and returns the second largest unique number in the list. If no such number exists, return `None`.\n\n**Function Signature:** `def second_largest_unique(numbers: List[int]) -> Union[int, None]`\n\n**In...
def f(x, y): return x + y
simplelr_Filter
[ { "content": "Question:\nWe have the following function defined using lambda expression:\n \n ```python\nf = lambda x, y: x + y\n ```\n\nCan the following code snippet be rewritten without using lambda expressions?\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8232, "level": 1, "question": "We have the following function defined using lambda expression:\n \n ```python\nf = lambda x, y: x + y\n ```\n\nCan the following code snippet be rewritten without using lambda expressions?", "split": "train" }
def string_to_int_list(input_str): """ Converts a string of numbers separated by spaces into a list of integers. Args: input_str (str): The input string containing space-separated numbers. Returns: list: A list of integers. Example: >>> string_to_int_list("1 2 3 4") ...
simplelr_Filter
[ { "content": "Question:\nCan you provide a Python code snippet that demonstrates how to convert a string to a list of integers? Assuming the string contains numbers separated by spaces.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8233, "level": 1, "question": "Can you provide a Python code snippet that demonstrates how to convert a string to a list of integers? Assuming the string contains numbers separated by spaces.", "split": "train" }
def calculate_item_totals(orders: dict) -> dict: item_totals = {} for order in orders.values(): for item in order: item_id = item[0] quantity = item[1] item_totals[item_id] = item_totals.get(item_id, 0) + quantity return item_totals
simplelr_Codeforces
[ { "content": "Question:\nYou are tasked with developing a new software feature for an online shopping platform. The platform maintains a dataset of orders, where each order consists of a series of items bought by customers. Each item is represented by its item ID and the quantity purchased.\n\nYour task is to i...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8234, "level": 1, "question": "You are tasked with developing a new software feature for an online shopping platform. The platform maintains a dataset of orders, where each order consists of a series of items bought by customers. Each item is represented by its item ID and the quant...
def is_team_valid(team): s = set(team) # Check if both 1 and 2 are present if 1 in s and 2 in s: return False # Check if both 3 and 4 are present if 3 in s and 4 in s: return False # Check if 5 and 6 are either both present or both absent if (5 in s) != (6 in s): retu...
simplelr_Apps
[ { "content": "Question:\nA company is organizing a team-building event and wants to form teams that adhere to specific compatibility rules. There are eight employees numbered 1, 2, ..., 8 respectively.\n\nHere are the team formation rules:\n```\nEmployees 1 and 2 cannot be in the same team.\nEmployees 3 and 4 c...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8235, "level": 1, "question": "A company is organizing a team-building event and wants to form teams that adhere to specific compatibility rules. There are eight employees numbered 1, 2, ..., 8 respectively.\n\nHere are the team formation rules:\n```\nEmployees 1 and 2 cannot be in ...
def is_prime(n): # Basic cases if n <= 1: return False elif n <= 3: return True elif n % 2 == 0: return False # Write n-1 as d * 2^s d = n - 1 s = 0 while d % 2 == 0: d //= 2 s += 1 # Test for each base bases = [2, 3, 5, 7, 11, 13...
simplelr_Filter
[ { "content": "Question:\nHow can I create a Python function that checks if a given number is a prime number? And can you show me how to optimize it for large numbers?\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8236, "level": 1, "question": "How can I create a Python function that checks if a given number is a prime number? And can you show me how to optimize it for large numbers?", "split": "train" }
def minOperations(A, B): m = len(A) n = len(B) # Create a DP table with (m+1) rows and (n+1) columns dp = [[0] * (n + 1) for _ in range(m + 1)] # Initialize the base cases for i in range(m + 1): dp[i][0] = i # Deleting all characters from A's first i characters for j in ra...
simplelr_Taco
[ { "content": "Question:\nYou are given two strings, A and B, and your task is to transform string A into string B using a minimum number of operations. The operations allowed are:\n1. Insertion of a character.\n2. Deletion of a character.\n3. Substitution of a character.\n\nYour Task:\nYou need to complete the ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8237, "level": 1, "question": "You are given two strings, A and B, and your task is to transform string A into string B using a minimum number of operations. The operations allowed are:\n1. Insertion of a character.\n2. Deletion of a character.\n3. Substitution of a character.\n\nYo...
def find_max_min(lst): if not lst: return (None, None) max_val = min_val = lst[0] for num in lst[1:]: if num > max_val: max_val = num if num < min_val: min_val = num return (max_val, min_val)
simplelr_Prefill
[ { "content": "Question:\nCreate a function that returns the maximum and minimum elements in a list of integers. The function should have a time complexity of O(n), where n is the number of elements in the list. Additionally, describe the steps you took to ensure the function adheres to the time complexity.\nAns...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8238, "level": 1, "question": "Create a function that returns the maximum and minimum elements in a list of integers. The function should have a time complexity of O(n), where n is the number of elements in the list. Additionally, describe the steps you took to ensure the function a...
from typing import List def poly_derive(p: List[int]) -> List[int]: return [i * p[i] for i in range(1, len(p))]
simplelr_Taco
[ { "content": "Question:\n***Nova polynomial derive***\n\nThis kata is part of the same series on polynomial handling. ( [#1](http://www.codewars.com/kata/nova-polynomial-1-add-1) [#2](http://www.codewars.com/kata/570eb07e127ad107270005fe) [#3](http://www.codewars.com/kata/5714041e8807940ff3001140) [#4](http://w...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8239, "level": 1, "question": "***Nova polynomial derive***\n\nThis kata is part of the same series on polynomial handling. ( [#1](http://www.codewars.com/kata/nova-polynomial-1-add-1) [#2](http://www.codewars.com/kata/570eb07e127ad107270005fe) [#3](http://www.codewars.com/kata/5714...
def decode_alien_string(data: str) -> str: return ''.join([chr(int(p) + 64) for p in data.split()])
simplelr_Apps
[ { "content": "Question:\n## Alien Alphabet\n\n### Background\nOn a distant planet called Alpharion, the inhabitants use an alien alphabet that is completely different from any Earth language. To facilitate communication with Earth, they have agreed on an intergalactic encoding scheme. This encoding scheme, call...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8240, "level": 1, "question": "## Alien Alphabet\n\n### Background\nOn a distant planet called Alpharion, the inhabitants use an alien alphabet that is completely different from any Earth language. To facilitate communication with Earth, they have agreed on an intergalactic encoding...
def max_subarray_sum_modulo(arr, m): if not arr: return 0 current_sum = 0 max_result = 0 min_mod = m # Initialize with a value larger than any possible mod m for num in arr: current_sum = (current_sum + num) % m candidate = (current_sum - min_mod) % m current_m...
simplelr_Package
[ { "content": "Question:\nYou are required to write a function named `max_subarray_sum_modulo` that takes two arguments: a list of integers `arr` and an integer `m`. The function should find and return the maximum possible sum of a subarray of `arr`, such that the sum is taken modulo `m`.\n\nA subarray is a cont...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8241, "level": 1, "question": "You are required to write a function named `max_subarray_sum_modulo` that takes two arguments: a list of integers `arr` and an integer `m`. The function should find and return the maximum possible sum of a subarray of `arr`, such that the sum is taken ...
from typing import List def find_missing_numbers(arr: List[int], n: int) -> List[int]: missing = [] expected = 1 for num in arr: while num > expected: missing.append(expected) expected += 1 if num == expected: expected += 1 missing.extend(range(expect...
simplelr_Codeforces
[ { "content": "Question:\nGiven an integer array `arr` of size `n` which contains elements from 1 to `n` with some elements possibly missing. The array is sorted in an increasing order and each number in the range [1, n] appears at most once in the array.\n\nWrite a function that finds and returns all the missin...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8242, "level": 1, "question": "Given an integer array `arr` of size `n` which contains elements from 1 to `n` with some elements possibly missing. The array is sorted in an increasing order and each number in the range [1, n] appears at most once in the array.\n\nWrite a function th...
def reverse_string_in_place(s): s_list = list(s) s_list.reverse() return ''.join(s_list)
simplelr_Prefill
[ { "content": "Question:\nWrite a function to reverse a string in Python, in place. The function should take a single string argument and reverse the sequence of characters in the string without creating a new string.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8243, "level": 1, "question": "Write a function to reverse a string in Python, in place. The function should take a single string argument and reverse the sequence of characters in the string without creating a new string.", "split": "train" }
import math def checkSquare(num): s = math.isqrt(num) if s * s == num: return (s, True) else: return (s + 1, False)
simplelr_Taco
[ { "content": "Question:\nGiven a positive integer `num`, the task is to determine if `num` is a perfect square. If `num` is a perfect square, return its square root; otherwise, return the smallest integer greater than the square root of `num`.\n\nYour function `checkSquare` should take an integer `num` and retu...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8244, "level": 1, "question": "Given a positive integer `num`, the task is to determine if `num` is a perfect square. If `num` is a perfect square, return its square root; otherwise, return the smallest integer greater than the square root of `num`.\n\nYour function `checkSquare` sh...
def longest_even_odd_subarray(nums): max_even = 0 max_odd = 0 current_even = 0 current_odd = 0 for num in nums: if num % 2 == 0: current_even += 1 current_odd = 0 if current_even > max_even: max_even = current_even else: ...
simplelr_Taco
[ { "content": "Question:\n# Task\n\nGiven an integer array `nums` of size `n`, your task is to find out the length of the longest contiguous subarray containing only even numbers, and the length of the longest contiguous subarray containing only odd numbers. Return these lengths as a dictionary/object with the k...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8245, "level": 1, "question": "# Task\n\nGiven an integer array `nums` of size `n`, your task is to find out the length of the longest contiguous subarray containing only even numbers, and the length of the longest contiguous subarray containing only odd numbers. Return these length...
def unique_elements(input_list): seen = set() unique_list = [] for item in input_list: if item not in seen: unique_list.append(item) seen.add(item) return unique_list # Example usage and testing if __name__ == "__main__": # Test case 1: Empty list print(get_uniqu...
simplelr_Prefill
[ { "content": "Question:\nWrite a python function to return the unique elements from a given list, keeping the order of elements as they appear. Also, provide a piece of code to demonstrate its correctness.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8246, "level": 1, "question": "Write a python function to return the unique elements from a given list, keeping the order of elements as they appear. Also, provide a piece of code to demonstrate its correctness.", "split": "train" }
def remove_duplicates(lst): seen = set() result = [] for item in lst: if item not in seen: seen.add(item) result.append(item) return result
simplelr_Prefill
[ { "content": "Question:\nWrite a python function to remove all the duplicate values from a given list while maintaining their order.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8247, "level": 1, "question": "Write a python function to remove all the duplicate values from a given list while maintaining their order.", "split": "train" }
def manipulate_memory_view(byte_obj: bytes, indices: list, new_values: list) -> tuple: """ Manipulates a memoryview of a byte object and returns the modified object and its memory view. Parameters: byte_obj (bytes): A bytes-like object to be used as the buffer. indices (list): A list of indices in ...
simplelr_Docs
[ { "content": "Question:\n### Memory Management with MemoryView Objects\n\nYou are required to write a Python function that uses memoryview objects to interact with buffer protocols. Specifically, your task is to create a read-write memory view of a bytes-like object, manipulate it by modifying certain elements,...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8248, "level": 1, "question": "### Memory Management with MemoryView Objects\n\nYou are required to write a Python function that uses memoryview objects to interact with buffer protocols. Specifically, your task is to create a read-write memory view of a bytes-like object, manipulat...
def count_mines(grid): if not grid or not all(len(row) == len(grid[0]) for row in grid): raise ValueError("Grid must not be empty and must be rectangular.") rows = len(grid) cols = len(grid[0]) if rows > 0 else 0 result = [[0] * cols for _ in range(rows)] for r in range(rows): ...
simplelr_Package
[ { "content": "Question:\nYou need to implement a Python function that simulates a simplified version of the game Minesweeper. Given a 2D list representing the game field where:\n- `-1` represents a mine.\n- `0` represents an empty cell.\nthe function should generate a new 2D list of the same size where each emp...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8249, "level": 1, "question": "You need to implement a Python function that simulates a simplified version of the game Minesweeper. Given a 2D list representing the game field where:\n- `-1` represents a mine.\n- `0` represents an empty cell.\nthe function should generate a new 2D l...
def power(base, exponent): return base ** exponent
simplelr_Filter
[ { "content": "Question:\nHow can I create a Python function that dynamically calculates the nth power of a given number? The function should be able to take any number and raise it to any power specified by the user.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8250, "level": 1, "question": "How can I create a Python function that dynamically calculates the nth power of a given number? The function should be able to take any number and raise it to any power specified by the user.", "split": "train" }
def find_target_index(nums, target): low = 0 high = len(nums) - 1 while low <= high: mid = (low + high) // 2 if nums[mid] == target: return mid elif nums[mid] < target: low = mid + 1 else: high = mid - 1 return -1
simplelr_Filter
[ { "content": "Question:\nYou are given a sorted array of distinct integers and a target value. Your task is to write a function that finds the index of the target value in the array. If the target value is not present in the array, return -1.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8251, "level": 1, "question": "You are given a sorted array of distinct integers and a target value. Your task is to write a function that finds the index of the target value in the array. If the target value is not present in the array, return -1.", "split": "train" }
def can_form_by_repeating_substring(s): n = len(s) for d in range(1, (n // 2) + 1): if n % d == 0: times = n // d if s == s[:d] * times: return True return False
simplelr_Prefill
[ { "content": "Question:\nCreate a function that checks if a given string can be formed by repeating a substring of it. For example, \"abab\" can be formed by repeating the substring \"ab\".\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8252, "level": 1, "question": "Create a function that checks if a given string can be formed by repeating a substring of it. For example, \"abab\" can be formed by repeating the substring \"ab\".", "split": "train" }
def fibonacci_n_numbers(n): if n == 0: return [] elif n == 1: return [0] fib = [0, 1] a, b = 0, 1 for i in range(2, n): c = a + b fib.append(c) a, b = b, c return fib
simplelr_Filter
[ { "content": "Question:\nDevelop a function in Python that generates and returns a list of the first N Fibonacci numbers, where N is a given non-negative integer. The function should also be capable of handling large values for N (up to 10^5).\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8253, "level": 1, "question": "Develop a function in Python that generates and returns a list of the first N Fibonacci numbers, where N is a given non-negative integer. The function should also be capable of handling large values for N (up to 10^5).", "split": "train" }
def sum_of_squares(numbers): total = 0 for num in numbers: if num < 0: raise ValueError("List contains negative numbers") total += num ** 2 return total
simplelr_Prefill
[ { "content": "Question:\nCreate a function that takes a list of integers as input and returns the sum of the squares of those integers. If the list contains any negative numbers, then raise a ValueError.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8254, "level": 1, "question": "Create a function that takes a list of integers as input and returns the sum of the squares of those integers. If the list contains any negative numbers, then raise a ValueError.", "split": "train" }
def is_palindrome(s): # Preprocess the string: keep only alphanumeric characters and convert to lowercase cleaned = ''.join([char.lower() for char in s if char.isalnum()]) # Check if the cleaned string is a palindrome return cleaned == cleaned[::-1] # Example usage s = "A man, a plan, a canal, Panama!"...
simplelr_Filter
[ { "content": "Question:\nWrite a program in Python that can determine if a given string is a palindrome, ignoring spaces, punctuation, and case sensitivity. For example, \"A man, a plan, a canal, Panama!\" should be recognized as a palindrome.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8255, "level": 1, "question": "Write a program in Python that can determine if a given string is a palindrome, ignoring spaces, punctuation, and case sensitivity. For example, \"A man, a plan, a canal, Panama!\" should be recognized as a palindrome.", "split": "train" }
def min_difference_in_coins(coins): total = sum(coins) if total == 0: return 0 target = total // 2 dp = [False] * (target + 1) dp[0] = True for num in coins: for i in range(target, num - 1, -1): if dp[i - num]: dp[i] = True max_sum = 0 for i in...
simplelr_Leetcode
[ { "content": "Question:\nYou are given a list of `n` integers representing coins, where `coins[i]` is the value of the `i-th` coin. You need to split these coins into two sets `A` and `B` such that the absolute difference between the sum of coins in set `A` and the sum of coins in set `B` is minimized. Return _...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8256, "level": 1, "question": "You are given a list of `n` integers representing coins, where `coins[i]` is the value of the `i-th` coin. You need to split these coins into two sets `A` and `B` such that the absolute difference between the sum of coins in set `A` and the sum of coin...
def to_snake_case(s): if not s: return "" result = s[0].lower() for c in s[1:]: if c.isupper(): result += '_' + c.lower() else: result += c return result
simplelr_Apps
[ { "content": "Question:\nWrite a function to transform the input string from PascalCase to snake_case.\n\nThe function should take a single string as input and return a string. The function should be named `to_snake_case`, and it should convert all of the upper-case letters to lower-case letters and insert unde...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8257, "level": 1, "question": "Write a function to transform the input string from PascalCase to snake_case.\n\nThe function should take a single string as input and return a string. The function should be named `to_snake_case`, and it should convert all of the upper-case letters to...
def check_book_availability(book_list, requested_book): requested_lower = requested_book.lower() exact_matches = {book.lower() for book in book_list} if requested_lower in exact_matches: return f"The book '{requested_book}' is available." else: partial_matches = [book for book in bo...
simplelr_Package
[ { "content": "Question:\nYou are implementing a library management system and need to create a function `check_book_availability(book_list, requested_book)` that checks if a requested book is available in the library. The book titles are case insensitive, and the library should also suggest possible matches if ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8258, "level": 1, "question": "You are implementing a library management system and need to create a function `check_book_availability(book_list, requested_book)` that checks if a requested book is available in the library. The book titles are case insensitive, and the library shoul...
def find_subarray_with_target_sum(nums, target): prefix_sum = 0 hash_map = {0: -1} for i, num in enumerate(nums): prefix_sum += num s = prefix_sum - target if s in hash_map: start = hash_map[s] return nums[start + 1 : i + 1] if prefix_sum not in hash_m...
simplelr_Leetcode
[ { "content": "Question:\nYou are given an array of integers `nums` and an integer `target`. Your task is to find a contiguous subarray whose sum is exactly equal to the `target`. If there are multiple solutions, return the subarray that starts with the smallest index. If there is no such subarray, return an emp...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8259, "level": 1, "question": "You are given an array of integers `nums` and an integer `target`. Your task is to find a contiguous subarray whose sum is exactly equal to the `target`. If there are multiple solutions, return the subarray that starts with the smallest index. If there...
def is_valid_parentheses(s): stack = [] matching = {')': '(', '}': '{', ']': '['} for char in s: if char in matching.values(): stack.append(char) elif char in matching: if not stack: return False top = stack.pop() if top != matc...
simplelr_Prefill
[ { "content": "Question:\nWrite a function to valid a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8260, "level": 1, "question": "Write a function to valid a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.", "split": "train" }
def isPerfectSquare(num): if num < 1: return False low = 1 high = num while low <= high: mid = (low + high) // 2 square = mid * mid if square == num: return True elif square < num: low = mid + 1 else: high = mid - 1 ...
simplelr_Filter
[ { "content": "Question:\nThis is a code challenge I'm struggling with. I have to write a function called `isPerfectSquare(num)` which takes a positive integer `num` and returns True if it is a perfect square, False otherwise.\n\nHere's the catch:\n\n* **You cannot use any built-in functions for calculating squa...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8261, "level": 1, "question": "This is a code challenge I'm struggling with. I have to write a function called `isPerfectSquare(num)` which takes a positive integer `num` and returns True if it is a perfect square, False otherwise.\n\nHere's the catch:\n\n* **You cannot use any buil...
def double_and_square(num): return (num * 2) ** 2
simplelr_Prefill
[ { "content": "Question:\nWrite a python function to double a number and then square the result.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8262, "level": 1, "question": "Write a python function to double a number and then square the result.", "split": "train" }
def compare_lexicographically(a, b): return (a > b) - (a < b)
simplelr_Prefill
[ { "content": "Question:\nWrite a function to compare two strings lexicographically. That is, compare the first characters of both strings, then the second characters, and so on. Capital letters should be considered less than lowercase letters. Handle case where the strings may be of unequal lengths.\nAnswer:\nL...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8263, "level": 1, "question": "Write a function to compare two strings lexicographically. That is, compare the first characters of both strings, then the second characters, and so on. Capital letters should be considered less than lowercase letters. Handle case where the strings may...
def wordBreak(s: str, wordList: list[str]) -> bool: word_set = set(wordList) max_len = max(len(word) for word in wordList) if wordList else 0 n = len(s) dp = [False] * (n + 1) dp[0] = True # Empty string is segmentable for i in range(1, n + 1): # Check all possible word lengths up to m...
simplelr_Codeforces
[ { "content": "Question:\nGiven a string `s` and a list of words `wordList`, return `True` if `s` can be segmented into a space-separated sequence of one or more dictionary words from `wordList`.\n\nNote that the same word in the dictionary may be reused multiple times in the segmentation.\n\n### Input:\n- A str...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8264, "level": 1, "question": "Given a string `s` and a list of words `wordList`, return `True` if `s` can be segmented into a space-separated sequence of one or more dictionary words from `wordList`.\n\nNote that the same word in the dictionary may be reused multiple times in the s...
def intersect(a, b): # Remove duplicates from b and create a set of their lowercase versions unique_b_lower = {x.lower() for x in set(b)} # Collect elements from a whose lowercase is in unique_b_lower return [x for x in a if x.lower() in unique_b_lower]
simplelr_Filter
[ { "content": "Question:\nI have two arrays of different lengths, a and b with a being less than or equal to b in length. \n\nI want a function that checks if any of the elements of a are in b. This function should be able to compare elements regardless of case, and remove duplicates in b before doing the compar...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8265, "level": 1, "question": "I have two arrays of different lengths, a and b with a being less than or equal to b in length. \n\nI want a function that checks if any of the elements of a are in b. This function should be able to compare elements regardless of case, and remove dupl...
import json def merge_json(json1, json2): dict1 = json.loads(json1) dict2 = json.loads(json2) # Corrected: Parse json2 into a dictionary dict1.update(dict2) return json.dumps(dict1)
simplelr_Filter
[ { "content": "Question:\nGiven two JSON strings, you need to merge them into one. If they have the same key, then you should overwrite the value from the second JSON string to the first one. Furthermore, add a piece of erroneous code as a reference, which has to be fixed before the actual implementation. Rememb...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8266, "level": 1, "question": "Given two JSON strings, you need to merge them into one. If they have the same key, then you should overwrite the value from the second JSON string to the first one. Furthermore, add a piece of erroneous code as a reference, which has to be fixed befor...
from collections import deque def has_path(n, edges, start, end): # Build the adjacency list adj = [[] for _ in range(n)] for from_node, to_node in edges: adj[from_node].append(to_node) visited = set() queue = deque() queue.append(start) visited.add(start) while queue:...
simplelr_Leetcode
[ { "content": "Question:\nYou are given a directed graph with `n` nodes labeled from `0` to `n - 1` and `edges` where each `edges[i] = (from_i, to_i)` represents a directed edge from node `from_i` to node `to_i`. You are also given an integer `start` representing the starting node and an integer `end` representi...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8267, "level": 1, "question": "You are given a directed graph with `n` nodes labeled from `0` to `n - 1` and `edges` where each `edges[i] = (from_i, to_i)` represents a directed edge from node `from_i` to node `to_i`. You are also given an integer `start` representing the starting n...
def evaluate_expression(input_str): # Tokenize the input string tokens = [] current_number = '' for char in input_str: if char.isdigit(): current_number += char else: if current_number: tokens.append(current_number) current_number =...
simplelr_Leetcode
[ { "content": "Question:\nImplement a function that takes in a string `input_str` containing a mathematical expression consisting of non-negative integers and the operators \\( + \\) and \\( * \\). The function should calculate and return the result of the expression, ensuring multiplication has higher precedenc...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8268, "level": 1, "question": "Implement a function that takes in a string `input_str` containing a mathematical expression consisting of non-negative integers and the operators \\( + \\) and \\( * \\). The function should calculate and return the result of the expression, ensuring ...
def longest_streak(daily_steps: list[int], goal: int) -> int: max_streak = 0 current_streak = 0 for steps in daily_steps: if steps >= goal: current_streak += 1 if current_streak > max_streak: max_streak = current_streak else: current_streak...
simplelr_Algorithm
[ { "content": "Question:\n### Context\nYou're working on a module for a health and fitness application that tracks users' daily steps. The application needs to identify the longest streak of consecutive days where the user met their step goal.\n\n### Task\nWrite a function `longest_streak(daily_steps: list[int],...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8269, "level": 1, "question": "### Context\nYou're working on a module for a health and fitness application that tracks users' daily steps. The application needs to identify the longest streak of consecutive days where the user met their step goal.\n\n### Task\nWrite a function `lon...
def shortest_path(n, edges, src, dst): INF = float('inf') distance = [INF] * n distance[src] = 0 for _ in range(n - 1): updated = False for edge in edges: u, v, w = edge if distance[u] != INF and distance[v] > distance[u] + w: distance[v] = di...
simplelr_Leetcode
[ { "content": "Question:\nYou are given a **directed weighted graph** with `n` nodes labeled from `0` to `n-1` and a 2D integer array `edges` where `edges[i] = [fromi, toi, weighti]` represents a directed edge from node `fromi` to node `toi` with a given weight `weighti`. Determine the shortest path from a give...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8270, "level": 1, "question": "You are given a **directed weighted graph** with `n` nodes labeled from `0` to `n-1` and a 2D integer array `edges` where `edges[i] = [fromi, toi, weighti]` represents a directed edge from node `fromi` to node `toi` with a given weight `weighti`. Dete...
def find_max_and_index(a, b, c): """ This function finds the maximum number among three given numbers and returns both the maximum value and its position. Args: a (int/float): The first number. b (int/float): The second number. c (int/float): The third number. Returns: ...
simplelr_Filter
[ { "content": "Question:\nIn Python, what is the best way to create a function that finds the maximum number among three given numbers? Furthermore, modify the function to return the largest number's position/index among the three numbers, considering that the numbers may not be distinct. Make sure that your fun...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8271, "level": 1, "question": "In Python, what is the best way to create a function that finds the maximum number among three given numbers? Furthermore, modify the function to return the largest number's position/index among the three numbers, considering that the numbers may not b...
from collections import Counter def find_modes(array): if not array: return [] count = Counter(array) max_freq = max(count.values()) return [k for k, v in count.items() if v == max_freq]
simplelr_Data_Structure
[ { "content": "Question:\n**Context**: You are tasked with developing a function to find the most frequently occurring element(s) in a dataset. This function will be useful in various domains, such as determining the most common words in text analysis or the most frequent errors logged in system diagnostics.\n\n...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8272, "level": 1, "question": "**Context**: You are tasked with developing a function to find the most frequently occurring element(s) in a dataset. This function will be useful in various domains, such as determining the most common words in text analysis or the most frequent error...
def extract_chunks(file_path: str) -> list[tuple[str, int]]: with open(file_path, 'rb') as f: chunks = [] while True: # Read the 4-byte chunk ID id_bytes = f.read(4) if len(id_bytes) < 4: break # End of file chunk_id = id_bytes.decode(...
simplelr_Docs
[ { "content": "Question:\n### **Coding Assessment Question**\n\nYou are provided with a file containing multiple chunks in the EA IFF 85 format. Your task is to implement a function called `extract_chunks` that reads all chunk IDs and their sizes from the file and returns them in a list of tuples. Each tuple wil...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8273, "level": 1, "question": "### **Coding Assessment Question**\n\nYou are provided with a file containing multiple chunks in the EA IFF 85 format. Your task is to implement a function called `extract_chunks` that reads all chunk IDs and their sizes from the file and returns them ...
def evaluate_expression(s): tokens = [] current_num = '' for c in s: if c in '+-': tokens.append(int(current_num)) tokens.append(c) current_num = '' else: current_num += c tokens.append(int(current_num)) # Add the last number result =...
simplelr_Apps
[ { "content": "Question:\nGiven an input string that represents a mathematical expression, create a function that evaluates and returns the result of the expression. The expression will only contain non-negative integers, the operators + (addition) and - (subtraction), and will not include any parentheses.\n\nFo...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8274, "level": 1, "question": "Given an input string that represents a mathematical expression, create a function that evaluates and returns the result of the expression. The expression will only contain non-negative integers, the operators + (addition) and - (subtraction), and will...
def sum_nested_list(lst): total = 0 for element in lst: if isinstance(element, list): total += sum_nested_list(element) else: total += element return total
simplelr_Filter
[ { "content": "Question:\nWrite a Python function to calculate the sum of elements in a list, which could contain integers or nested lists. If an element is a nested list, the function should calculate the sum of its elements, including any further nested lists, and add that sum to the total. The function should...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8275, "level": 1, "question": "Write a Python function to calculate the sum of elements in a list, which could contain integers or nested lists. If an element is a nested list, the function should calculate the sum of its elements, including any further nested lists, and add that su...
def intersection(list1, list2): set2 = set(list2) seen = set() result = [] for num in list1: if num in set2 and num not in seen: result.append(num) seen.add(num) return result
simplelr_Prefill
[ { "content": "Question:\nCreate a function that takes in two list of integers as input and returns the intersection of these two lists as a list of integers. The intersection should contain only unique elements. For example, if list1 = [1, 2, 2, 3] and list2 = [2, 2, 3, 4], the function should return [2, 3].\nA...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8276, "level": 1, "question": "Create a function that takes in two list of integers as input and returns the intersection of these two lists as a list of integers. The intersection should contain only unique elements. For example, if list1 = [1, 2, 2, 3] and list2 = [2, 2, 3, 4], th...
def twoSum(arr, target): seen = {} for i, num in enumerate(arr): complement = target - num if complement in seen: return [seen[complement], i] seen[num] = i return []
simplelr_Taco
[ { "content": "Question:\nGiven an array arr of N integers and an integer target, return the indices of the two numbers such that they add up to target. \n\nExample 1:-\nInput:\n2\n4\n2 7 11 15\n9\n3\n3 2 4\n6\nOutput:\n0 1\n1 2\n\nYour task:\nYou need to complete the function twoSum() which takes an integer arr...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8277, "level": 1, "question": "Given an array arr of N integers and an integer target, return the indices of the two numbers such that they add up to target. \n\nExample 1:-\nInput:\n2\n4\n2 7 11 15\n9\n3\n3 2 4\n6\nOutput:\n0 1\n1 2\n\nYour task:\nYou need to complete the function ...
def is_balanced(s): stack = [] for char in s: if char == '(': stack.append(char) elif char == ')': if not stack: return False stack.pop() return len(stack) == 0
simplelr_Evol
[ { "content": "Question:\nWrite a function to determine if a given string contains balanced parentheses. A string with balanced parentheses has every opening parenthesis '(' matched with a closing parenthesis ')' in the correct order. \n\n### Input\n- A single input string consisting of characters 'a-z', 'A-Z', ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8278, "level": 1, "question": "Write a function to determine if a given string contains balanced parentheses. A string with balanced parentheses has every opening parenthesis '(' matched with a closing parenthesis ')' in the correct order. \n\n### Input\n- A single input string cons...
def insertion_sort_with_early_termination(arr, simulation=False): arr = list(arr) n = len(arr) for i in range(1, n): key = arr[i] j = i - 1 # Insert the key into the correct position while j >= 0 and arr[j] > key: arr[j + 1] = arr[j] j -=...
simplelr_Data_Structure
[ { "content": "Question:\n### Insertion Sort with Early Termination\n\n#### Objective\nIn this task, you are required to implement a function that performs an insertion sort with early termination. Early termination refers to stopping the sorting process as soon as the array is detected to be sorted. This enhanc...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8279, "level": 1, "question": "### Insertion Sort with Early Termination\n\n#### Objective\nIn this task, you are required to implement a function that performs an insertion sort with early termination. Early termination refers to stopping the sorting process as soon as the array is...
def can_transform(s1, s2): if len(s1) != len(s2): return False if s1 == s2: return True from collections import Counter if Counter(s1) != Counter(s2): return False for i in range(len(s1)): s = s1[:i] + s1[i+1:] for j in range(len(s2)): if s2[j] == ...
simplelr_Leetcode
[ { "content": "Question:\nYou are given two strings, `s1` and `s2`, both consisting of lowercase English letters. Your task is to determine if `s1` can be transformed into `s2` by moving at most one character from `s1` to any position within `s1`. The order of characters in `s1` can be changed, but you are only ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8280, "level": 1, "question": "You are given two strings, `s1` and `s2`, both consisting of lowercase English letters. Your task is to determine if `s1` can be transformed into `s2` by moving at most one character from `s1` to any position within `s1`. The order of characters in `s1...
import collections def findDuplicates(nums): count = collections.Counter(nums) duplicates = [num for num, cnt in count.items() if cnt > 1] return sorted(duplicates)
simplelr_Evol
[ { "content": "Question:\nDesign a function `findDuplicates` that, given a list of integers, returns a list of integers that appear more than once in the input list. The output list should be sorted in ascending order and must contain each duplicated integer only once. If there are no duplicates, return an empty...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8281, "level": 1, "question": "Design a function `findDuplicates` that, given a list of integers, returns a list of integers that appear more than once in the input list. The output list should be sorted in ascending order and must contain each duplicated integer only once. If there...
def are_permutations(s1, s2): if len(s1) != len(s2): return False return sorted(s1) == sorted(s2) # Test cases if __name__ == "__main__": test_cases = [ ("", "", True), # Both empty strings ("", "a", False), # Different lengths ("a", "A", Fals...
simplelr_Evol
[ { "content": "Question:\nWrite a Python function that takes two strings as input and returns True if one string is a permutation of the other, False otherwise. A permutation is a rearrangement of letters. The function must be case-sensitive and consider whitespace as valid characters. Implement this by verifyin...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8282, "level": 1, "question": "Write a Python function that takes two strings as input and returns True if one string is a permutation of the other, False otherwise. A permutation is a rearrangement of letters. The function must be case-sensitive and consider whitespace as valid cha...
def longest_word(s): words = s.split() if not words: return "" max_length = 0 longest_word = "" for word in words: if len(word) > max_length: max_length = len(word) longest_word = word return longest_word
simplelr_Filter
[ { "content": "Question:\nWrite a Python function that takes a string of characters as input and returns the longest word in the string. If there are multiple words of the same maximum length, it returns the first one encountered.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8283, "level": 1, "question": "Write a Python function that takes a string of characters as input and returns the longest word in the string. If there are multiple words of the same maximum length, it returns the first one encountered.", "split": "train" }
def trap(height): left = 0 right = len(height) - 1 left_max = right_max = 0 result = 0 while left <= right: if height[left] <= height[right]: if height[left] >= left_max: left_max = height[left] else: result += left_max - height[left] ...
simplelr_Leetcode
[ { "content": "Question:\nGiven `n` non-negative integers representing the heights of a series of vertical bars, where the width of each bar is 1, compute how much water it is able to trap after raining. * For example, given `heights = [0,1,0,2,1,0,1,3,2,1,2,1]`, the output should be `6`. Return _the total tr...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8284, "level": 1, "question": "Given `n` non-negative integers representing the heights of a series of vertical bars, where the width of each bar is 1, compute how much water it is able to trap after raining. * For example, given `heights = [0,1,0,2,1,0,1,3,2,1,2,1]`, the output ...
def linear_search(lst, target): for index, value in enumerate(lst): if value == target: return index return -1
simplelr_Prefill
[ { "content": "Question:\nWrite a python function to search for a given element in an unsorted list using linear search. If the element is found, return its index; otherwise, return -1.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8285, "level": 1, "question": "Write a python function to search for a given element in an unsorted list using linear search. If the element is found, return its index; otherwise, return -1.", "split": "train" }
def find_missing_number(sequence): total = (len(sequence) + 1) * (min(sequence) + max(sequence)) // 2 return total - sum(sequence)
simplelr_Taco
[ { "content": "Question:\nConsider a list of integers. Implement a function `find_missing_number` that takes a list of consecutive numbers with one missing number and returns the missing number in the sequence. The given list will contain all integers from a start number to an end number, missing only one intege...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8286, "level": 1, "question": "Consider a list of integers. Implement a function `find_missing_number` that takes a list of consecutive numbers with one missing number and returns the missing number in the sequence. The given list will contain all integers from a start number to an ...
def find_easiest_path(grid: list[list[int]]) -> int: if not grid: return 0 m = len(grid) n = len(grid[0]) if m > 0 else 0 if m == 1 and n == 1: return grid[0][0] # Process the first row for j in range(1, n): grid[0][j] += grid[0][j-1] # Process the first col...
simplelr_Algorithm
[ { "content": "Question:\n### Question: Pathfinding in a Weighted Grid\n\n**Context**:\nYou are developing a new game where players navigate through a dungeon represented as a 2D grid. Each cell in the grid has a certain weight that represents the difficulty to traverse that cell. Players need to find the easies...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8287, "level": 1, "question": "### Question: Pathfinding in a Weighted Grid\n\n**Context**:\nYou are developing a new game where players navigate through a dungeon represented as a 2D grid. Each cell in the grid has a certain weight that represents the difficulty to traverse that ce...
import builtins def transformed_open(path: str, transformations: list) -> str: try: with open(path, 'r') as file: content = file.read() except FileNotFoundError: return "" for transformation in transformations: func = None try: func = getattr(bui...
simplelr_Docs
[ { "content": "Question:\n#### Objective:\nTo assess your understanding of Python's built-in functions and your ability to handle potential naming conflicts by utilizing the `builtins` module effectively.\n\n#### Problem Statement:\nYou are tasked with creating a custom utility that reads a file and applies mult...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8288, "level": 1, "question": "#### Objective:\nTo assess your understanding of Python's built-in functions and your ability to handle potential naming conflicts by utilizing the `builtins` module effectively.\n\n#### Problem Statement:\nYou are tasked with creating a custom utility...
def isSubsequence(str): main_str = "codingassessment" i = j = 0 len_main = len(main_str) len_str = len(str) while i < len_str and j < len_main: if str[i] == main_str[j]: i += 1 j += 1 else: j += 1 return i == len_str
simplelr_Taco
[ { "content": "Question:\nGiven a string str, determine if it is a subsequence of the string \"codingassessment\". A sequence S1 is a subsequence of another sequence S2 if S1 can be derived from S2 by deleting some or no elements without changing the order of the remaining elements.\n\nExample 1:\nInput:\nstr = ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8289, "level": 1, "question": "Given a string str, determine if it is a subsequence of the string \"codingassessment\". A sequence S1 is a subsequence of another sequence S2 if S1 can be derived from S2 by deleting some or no elements without changing the order of the remaining elem...
def is_sorted(lst): if len(lst) <= 1: return True for i in range(len(lst) - 1): if lst[i] > lst[i + 1]: return False return True
simplelr_Filter
[ { "content": "Question:\nYou are tasked with writing a program that determines whether a given list of integers is already sorted in ascending order or not. If the list is sorted, the function should return True; otherwise, it should return False.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8290, "level": 1, "question": "You are tasked with writing a program that determines whether a given list of integers is already sorted in ascending order or not. If the list is sorted, the function should return True; otherwise, it should return False.", "split": "train" }
import time import sys def spinner(spin_interval: float) -> None: characters = ['|', '/', '-', '\\'] index = 0 while True: char = characters[index] sys.stdout.write(f'\r{char}') sys.stdout.flush() time.sleep(spin_interval) index = (index + 1) % 4
simplelr_Package
[ { "content": "Question:\n**Task: Implement a Function to Simulate a Loading Spinner**\n\nYou are assigned the task of creating a Python function named `spinner` that simulates a loading spinner in the console. The spinner should rotate indefinitely until stopped manually (e.g., by pressing `Control + C`).\n\nSp...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8291, "level": 1, "question": "**Task: Implement a Function to Simulate a Loading Spinner**\n\nYou are assigned the task of creating a Python function named `spinner` that simulates a loading spinner in the console. The spinner should rotate indefinitely until stopped manually (e.g....
def process_operations(operations: list) -> list: results = [] for op in operations: oper, operand1, operand2 = op if oper == "add": results.append(operand1 + operand2) elif oper == "sub": results.append(operand1 - operand2) elif oper == "mul": ...
simplelr_Algorithm
[ { "content": "Question:\n### Coding Assessment Question\n\n#### Context:\n\nYou are building a basic integer calculator that supports addition, subtraction, multiplication, and division operations. The calculator should read from a given list of operations. Each operation will be a tuple where:\n- the first ele...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8292, "level": 1, "question": "### Coding Assessment Question\n\n#### Context:\n\nYou are building a basic integer calculator that supports addition, subtraction, multiplication, and division operations. The calculator should read from a given list of operations. Each operation will...
from collections import Counter from typing import List def find_modes(arr: List[int]) -> List[int]: counts = Counter(arr) if not counts: return [] max_freq = max(counts.values()) modes = [k for k, v in counts.items() if v == max_freq] return modes
simplelr_Data_Structure
[ { "content": "Question:\nYou are given an array of integers and you need to implement a function `find_modes` that computes and returns a list of the most frequent element(s) in the array. The function should be efficient in terms of time complexity.\n\n### Function Signature\n```python\ndef find_modes(arr: Lis...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8293, "level": 1, "question": "You are given an array of integers and you need to implement a function `find_modes` that computes and returns a list of the most frequent element(s) in the array. The function should be efficient in terms of time complexity.\n\n### Function Signature\...
from typing import TypeVar T = TypeVar('T') def freq_dict(lst: list[T]) -> dict[T, int]: """Create a frequency dictionary from a list. Args: lst: A list of elements. Returns: A dictionary where keys are elements from the list and values are their frequencies. Example: >>> fr...
simplelr_Filter
[ { "content": "Question:\nI want to make a simple Python program that takes in a list and outputs a dictionary where the keys are the elements from the list and the values are the frequencies of the elements. \n\nFor example, if the input is `[1, 2, 2, 3, 3, 3]`, the output should be `{1: 1, 2: 2, 3: 3}`. \n\nI ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8294, "level": 1, "question": "I want to make a simple Python program that takes in a list and outputs a dictionary where the keys are the elements from the list and the values are the frequencies of the elements. \n\nFor example, if the input is `[1, 2, 2, 3, 3, 3]`, the output sho...
def sort_names_by_scores(names_scores): return sorted(names_scores, key=lambda x: (-x[1], x[0]))
simplelr_Filter
[ { "content": "Question:\nGiven a list of names and their corresponding scores, create a Python function that sorts the names in descending order based on their scores. If two names have the same score, they should be sorted alphabetically in ascending order. The function should return a list of tuples, where ea...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8295, "level": 1, "question": "Given a list of names and their corresponding scores, create a Python function that sorts the names in descending order based on their scores. If two names have the same score, they should be sorted alphabetically in ascending order. The function shoul...
def sum_even_or_min(nums): evens = [x for x in nums if x % 2 == 0] return sum(evens) if evens else min(nums)
simplelr_Prefill
[ { "content": "Question:\nCreate a function that takes a list of integers and returns the sum of all the even numbers in the list. If there are no even numbers, return the minimum integer in the list.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8296, "level": 1, "question": "Create a function that takes a list of integers and returns the sum of all the even numbers in the list. If there are no even numbers, return the minimum integer in the list.", "split": "train" }
def get_all_products_in_categories(categories): """ This function takes in a list of categories and returns a list of all products in those categories. Args: categories: A list of category names. Returns: A list of product names. """ product_categories = { "Electro...
simplelr_Filter
[ { "content": "Question:\nThis is the function\n\n```python\ndef get_all_products_in_categories(categories):\n \"\"\"\n This function takes in a list of categories and returns a list of \n all products in those categories.\n\n Args:\n categories: A list of category names.\n\n Returns:\n A list of prod...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8297, "level": 1, "question": "This is the function\n\n```python\ndef get_all_products_in_categories(categories):\n \"\"\"\n This function takes in a list of categories and returns a list of \n all products in those categories.\n\n Args:\n categories: A list of category names...
def find_scrambled_codes(codes): groups = {} for index, code in enumerate(codes): key = ''.join(sorted(code)) if key in groups: groups[key].append(index) else: groups[key] = [index] result = [] for key in groups: indices = groups[key] if le...
simplelr_Codeforces
[ { "content": "Question:\nRebellion forces have intercepted an encrypted message containing information about enemy fleet movements. The message consists of a sequence of strings, each representing a unique code. The challenge is to identify any codes that have been scrambled from a subset of letters of the orig...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8298, "level": 1, "question": "Rebellion forces have intercepted an encrypted message containing information about enemy fleet movements. The message consists of a sequence of strings, each representing a unique code. The challenge is to identify any codes that have been scrambled f...
def arrayPairSum(nums): nums.sort() return sum(nums[::2])
simplelr_Leetcode
[ { "content": "Question:\nYou are given an integer array `nums` consisting of `2n` elements where `n` is a positive integer. You need to arrange these elements into `n` pairs such that the sum of the minimum values of each pair is maximized. Return the maximized sum of the paired minimums.\n\nFor example, for th...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8299, "level": 1, "question": "You are given an integer array `nums` consisting of `2n` elements where `n` is a positive integer. You need to arrange these elements into `n` pairs such that the sum of the minimum values of each pair is maximized. Return the maximized sum of the pair...