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 calculateSumOfSquaresDifference(a, b, c): return a ** 2 + b ** 2 - c ** 2
simplelr_Prefill
[ { "content": "Question:\nCreate a function that takes three integers as input and returns the sum of the squares of the first two integers, and then subtracts the square of the third integer from the result. The function should be named `calculateSumOfSquaresDifference`.\nAnswer:\nLet's think step by step.\n", ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 900, "level": 1, "question": "Create a function that takes three integers as input and returns the sum of the squares of the first two integers, and then subtracts the square of the third integer from the result. The function should be named `calculateSumOfSquaresDifference`.", "s...
def count_one_bits(number: int) -> int: if type(number) is not int or number < 0: raise ValueError("Input must be a non-negative integer.") count = 0 while number: count += number & 1 number >>= 1 return count
simplelr_Algorithm
[ { "content": "Question:\n## Title: Count the Number of 1 Bits in an Integer\n\n### Description\nYou are to write a function that counts the number of `1` bits (also known as the Hamming weight or population count) in the binary representation of a given non-negative integer. The process should be efficient, usi...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 901, "level": 1, "question": "## Title: Count the Number of 1 Bits in an Integer\n\n### Description\nYou are to write a function that counts the number of `1` bits (also known as the Hamming weight or population count) in the binary representation of a given non-negative integer. Th...
def count_paths_with_sum(grid, target): m = len(grid) if m == 0: return 0 n = len(grid[0]) if n == 0: return 0 # Initialize DP table where each cell is a dictionary {sum: count} dp = [[{} for _ in range(n)] for _ in range(m)] dp[0][0][grid[0][0]] = 1 for i in range(m): ...
simplelr_Leetcode
[ { "content": "Question:\nYou are given a 2D integer array `grid` representing a grid of digits. A path in the grid is a sequence of digits from the top-left cell to the bottom-right cell, moving only rightward or downward at each step. The **total** of a path is the sum of the digits along the path. Find a path...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 902, "level": 1, "question": "You are given a 2D integer array `grid` representing a grid of digits. A path in the grid is a sequence of digits from the top-left cell to the bottom-right cell, moving only rightward or downward at each step. The **total** of a path is the sum of the ...
import re from collections import defaultdict def most_frequent_words(text): # Split the text into tokens based on whitespace tokens = text.split() # List to hold cleaned words words = [] for token in tokens: # Remove leading and trailing non-alphanumeric characters stripp...
simplelr_Taco
[ { "content": "Question:\nYou are given a string of text where different words are separated by spaces. Your task is to write a function that finds the most frequently occurring word in the text. If there are multiple words with the same highest frequency, return them in a sorted list.\n\nWrite a function `most_...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 903, "level": 1, "question": "You are given a string of text where different words are separated by spaces. Your task is to write a function that finds the most frequently occurring word in the text. If there are multiple words with the same highest frequency, return them in a sorte...
def findNthElement(n): return 1
simplelr_Taco
[ { "content": "Question:\nWrite a function that takes a positive integer `n` and returns the n-th number in the sequence defined as follows:\n- The first element is `1`.\n- For every `n ≥ 2`, the n-th element is the sum of the digits of the (n-1)-th element.\n\nFor example, if the sequence starts with `[1]`, the...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 904, "level": 1, "question": "Write a function that takes a positive integer `n` and returns the n-th number in the sequence defined as follows:\n- The first element is `1`.\n- For every `n ≥ 2`, the n-th element is the sum of the digits of the (n-1)-th element.\n\nFor example, if t...
import os def generate_summary_report(directory_path): total_files = 0 total_size = 0 extensions = {} for root, dirs, files in os.walk(directory_path): for file in files: file_path = os.path.join(root, file) file_size = os.path.getsize(file_path) ...
simplelr_Package
[ { "content": "Question:\nYou are tasked with writing a function named `generate_summary_report` that summarizes file statistics from a given directory. The summary should include the total count of files, their combined size, and a breakdown by file extension.\n\n### Requirements:\n1. **Function Name**: `genera...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 905, "level": 1, "question": "You are tasked with writing a function named `generate_summary_report` that summarizes file statistics from a given directory. The summary should include the total count of files, their combined size, and a breakdown by file extension.\n\n### Requiremen...
def generate_primes(limit): if limit < 2: return [] sieve = [True] * (limit + 1) sieve[0], sieve[1] = False, False for p in range(2, int(limit ** 0.5) + 1): if sieve[p]: for multiple in range(p * p, limit + 1, p): sieve[multiple] = False return [p for p, i...
simplelr_Filter
[ { "content": "Question:\nI want to create a Python function that generates a list of prime numbers up to a given limit. How can I do this efficiently?\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 906, "level": 1, "question": "I want to create a Python function that generates a list of prime numbers up to a given limit. How can I do this efficiently?", "split": "train" }
def total_cost(prices=None, quantities=None): if prices is None: prices = [] if quantities is None: quantities = [] max_length = max(len(prices), len(quantities)) total = 0.0 for i in range(max_length): price = prices[i] if i < len(prices) else 0 quantity = ...
simplelr_Prefill
[ { "content": "Question:\nCreate a function that calculates the total cost of items in a store, given the prices of individual items and the quantities of each item. The function should return the total cost as a floating-point number. If any of the prices or quantities are not provided, they should be treated a...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 907, "level": 1, "question": "Create a function that calculates the total cost of items in a store, given the prices of individual items and the quantities of each item. The function should return the total cost as a floating-point number. If any of the prices or quantities are not ...
def find_squares(n): return [i ** 2 for i in range(1, n + 1)]
simplelr_Prefill
[ { "content": "Question:\nWrite a python function to find the squares of numbers from 1 to n.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 908, "level": 1, "question": "Write a python function to find the squares of numbers from 1 to n.", "split": "train" }
def merge_contacts(contacts): merged = {} for contact in contacts: first, last, phone = contact key = (first, last) if key in merged: merged[key].add(phone) else: merged[key] = {phone} result = [] for key in merged: first, last = key ...
simplelr_Code_Contests
[ { "content": "Question:\nImagine you are given a list of contacts where each contact consists of a first name, last name, and phone number. Some contacts may have the same first name or the same last name but different phone numbers. Your goal is to merge contacts that have either the same first name or the sam...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 909, "level": 1, "question": "Imagine you are given a list of contacts where each contact consists of a first name, last name, and phone number. Some contacts may have the same first name or the same last name but different phone numbers. Your goal is to merge contacts that have eit...
def power(a, b): if b == 0: return 1 result = 1 if b > 0: for _ in range(b): result *= a else: positive_b = -b for _ in range(positive_b): result *= a result = 1 / result return result
simplelr_Prefill
[ { "content": "Question:\nCreate a function that takes two integer parameters `a` and `b`, and returns the result of raising `a` to the power of `b`. You are not allowed to use the built-in exponentiation operator (`**` or `pow()` function). Instead, you must implement the exponentiation yourself using a loop. A...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 910, "level": 1, "question": "Create a function that takes two integer parameters `a` and `b`, and returns the result of raising `a` to the power of `b`. You are not allowed to use the built-in exponentiation operator (`**` or `pow()` function). Instead, you must implement the expon...
from datetime import datetime def days_between(start_date_str, end_date_str, date_format): """ Calculate the number of days between two dates specified as strings. Args: start_date_str (str): The start date string. end_date_str (str): The end date string. date_format (str): The for...
simplelr_Filter
[ { "content": "Question:\nWrite a Python function that calculates the number of days between two dates in a given format. The function should take two strings representing the dates and the format of the dates as arguments. The format will be specified according to the `datetime` module's strftime and strptime d...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 911, "level": 1, "question": "Write a Python function that calculates the number of days between two dates in a given format. The function should take two strings representing the dates and the format of the dates as arguments. The format will be specified according to the `datetime...
from collections import Counter def kth_smallest_unique(nums, k): count = Counter(nums) unique = [num for num, cnt in count.items() if cnt == 1] unique.sort() if len(unique) < k: return -1 else: return unique[k-1]
simplelr_Leetcode
[ { "content": "Question:\nYou are given a **0-indexed** integer array `nums` containing `n` integers. Your task is to find the **k-th smallest unique** integer in the array. If the k-th smallest unique integer does not exist, return `-1`.\n\nFor example, given `nums = [4, 3, 1, 1, 2, 5, 4, 3]` and `k = 3`, the u...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 912, "level": 1, "question": "You are given a **0-indexed** integer array `nums` containing `n` integers. Your task is to find the **k-th smallest unique** integer in the array. If the k-th smallest unique integer does not exist, return `-1`.\n\nFor example, given `nums = [4, 3, 1, ...
def generate_primes(n: int) -> list[int]: if n <= 2: return [] sieve = [True] * n sieve[0], sieve[1] = False, False for current in range(2, int(n ** 0.5) + 1): if sieve[current]: for multiple in range(current * current, n, current): sieve[multiple] = False ...
simplelr_Algorithm
[ { "content": "Question:\n### Scenario\nAs a part of the application's data security feature, you have been tasked to create a function that efficiently generates a list of prime numbers. These prime numbers will be used for various cryptographic operations across the application.\n\n### Coding Task\nImplement a...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 913, "level": 1, "question": "### Scenario\nAs a part of the application's data security feature, you have been tasked to create a function that efficiently generates a list of prime numbers. These prime numbers will be used for various cryptographic operations across the applicatio...
def can_be_split_into_equal_sum_subsequences(sequence): total = sum(sequence) if total % 2 != 0: return False target = total // 2 possible_sums = 1 # Initially, only sum 0 is possible for num in sequence: possible_sums |= possible_sums << num # Mask to keep only sums up to t...
simplelr_Apps
[ { "content": "Question:\nIn a certain math game, players are given a sequence of numbers, and their goal is to check whether the sequence can be split into two sub-sequences such that the sum of the elements in both sub-sequences is equal.\n\nWrite a function `can_be_split_into_equal_sum_subsequences(sequence)`...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 914, "level": 1, "question": "In a certain math game, players are given a sequence of numbers, and their goal is to check whether the sequence can be split into two sub-sequences such that the sum of the elements in both sub-sequences is equal.\n\nWrite a function `can_be_split_into...
def two_sum(nums, target): seen = set() for num in nums: complement = target - num if complement in seen: return (complement, num) seen.add(num) return ()
simplelr_Taco
[ { "content": "Question:\nWrite a function that takes an unsorted list of integers and a target sum, and returns a tuple containing two distinct integers from the list that add up to the target sum. If no such pair exists, return an empty tuple.\n\nNote:\n\n- You may assume that there is at most one such pair.\n...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 915, "level": 1, "question": "Write a function that takes an unsorted list of integers and a target sum, and returns a tuple containing two distinct integers from the list that add up to the target sum. If no such pair exists, return an empty tuple.\n\nNote:\n\n- You may assume that...
def double_list(lst): if not lst: return [] result = [] for num in lst: if num == 0: return [] result.append(num * 2) return result
simplelr_Taco
[ { "content": "Question:\nWrite a function that takes a list of integers and returns a list with the values doubled. If the original list contains zero or is empty, return an empty list. Your function should handle lists of any length and content efficiently.\nAnswer:\nLet's think step by step.\n", "role": "...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 916, "level": 1, "question": "Write a function that takes a list of integers and returns a list with the values doubled. If the original list contains zero or is empty, return an empty list. Your function should handle lists of any length and content efficiently.", "split": "train...
def factorial(n): if n < 0: raise ValueError("Factorial is not defined for negative numbers") result = 1 for i in range(1, n + 1): result *= i return result # Test the function with examples: print(factorial(5)) # Expected output: 120 print(factorial(0)) # Expected output: 1 print(fac...
simplelr_Evol
[ { "content": "Question:\nConsider the following code that attempts to compute the factorial of a given non-negative integer n using recursion. Identify any mistakes in the code and correct them to ensure it operates as intended. Additionally, optimize the implementation for handling larger inputs.\n\nErroneous ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 917, "level": 1, "question": "Consider the following code that attempts to compute the factorial of a given non-negative integer n using recursion. Identify any mistakes in the code and correct them to ensure it operates as intended. Additionally, optimize the implementation for han...
def combine_sorted_arrays(arr1, arr2): result = [] i = j = 0 while i < len(arr1) and j < len(arr2): if arr1[i] < arr2[j]: result.append(arr1[i]) i += 1 else: result.append(arr2[j]) j += 1 result.extend(arr1[i:]) result.extend(arr2[j:]) ...
simplelr_Filter
[ { "content": "Question:\nI'm trying to write a function that combines two sorted arrays into one sorted array. I know I can use the `sort()` method, but I want to implement a custom solution that doesn't rely on built-in sorting methods. Here's my attempt so far:\n\n```python\ndef combine_sorted_arrays(arr1, ar...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 918, "level": 1, "question": "I'm trying to write a function that combines two sorted arrays into one sorted array. I know I can use the `sort()` method, but I want to implement a custom solution that doesn't rely on built-in sorting methods. Here's my attempt so far:\n\n```python\n...
def count_word_occurrences(strings): word_counts = {} for string in strings: for word in string.split(): if word in word_counts: word_counts[word] += 1 else: word_counts[word] = 1 return word_counts
simplelr_Prefill
[ { "content": "Question:\nWrite a function to calculate the total number of occurrences of words in a given list of strings. The function should return a dictionary where keys are the words and values are the counts of their occurrences.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 919, "level": 1, "question": "Write a function to calculate the total number of occurrences of words in a given list of strings. The function should return a dictionary where keys are the words and values are the counts of their occurrences.", "split": "train" }
def optimized_bubble_sort(arr): n = len(arr) for i in range(n - 1): swapped = False for j in range(n - i - 1): if arr[j] > arr[j + 1]: arr[j], arr[j + 1] = arr[j + 1], arr[j] swapped = True if not swapped: break return arr
simplelr_Data_Structure
[ { "content": "Question:\n**Context**: You have been tasked with optimizing a sorting function used in a small-scale application where the performance of sorting different sized datasets must be analyzed and improved where possible. \n\n#### Task:\nImplement an optimized version of Bubble Sort, called `optimized...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 920, "level": 1, "question": "**Context**: You have been tasked with optimizing a sorting function used in a small-scale application where the performance of sorting different sized datasets must be analyzed and improved where possible. \n\n#### Task:\nImplement an optimized version...
def is_increasing_no_duplicates(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:\nGiven a list of integers, implement a function that returns True if the list is in increasing order and there are no duplicates, and False otherwise.\n\nExample:\nInput: [1, 2, 3, 4, 5]\nOutput: True\nInput: [5, 4, 3, 2, 1]\nOutput: False\nInput: [1, 1, 2, 3, 4, 5]\nOutput: False\n\nHer...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 921, "level": 1, "question": "Given a list of integers, implement a function that returns True if the list is in increasing order and there are no duplicates, and False otherwise.\n\nExample:\nInput: [1, 2, 3, 4, 5]\nOutput: True\nInput: [5, 4, 3, 2, 1]\nOutput: False\nInput: [1, 1,...
from typing import List def search_rotated_sorted_array(array: List[int], target: int) -> int: low = 0 high = len(array) - 1 while low <= high: mid = (low + high) // 2 if array[mid] == target: return mid if array[low] <= array[mid]: # Left part is sorted ...
simplelr_Data_Structure
[ { "content": "Question:\n#### Scenario\nYou are developing a feature for a search engine that needs to find the position of a specific element in a rotated sorted array. The array was originally sorted in ascending order and then rotated at some unknown pivot. Your task is to write a function to find the index ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 922, "level": 1, "question": "#### Scenario\nYou are developing a feature for a search engine that needs to find the position of a specific element in a rotated sorted array. The array was originally sorted in ascending order and then rotated at some unknown pivot. Your task is to w...
import math def num_digits(n: int) -> int: if n == 0: return 1 n_abs = abs(n) log10_n = math.log10(n_abs) digits = math.floor(log10_n) + 1 return digits
simplelr_Data_Structure
[ { "content": "Question:\n#### Task\nYou are tasked with designing a function that computes the number of digits in a number, utilizing logarithmic properties to achieve this in constant time O(1).\n\n#### Objective\nImplement the function `num_digits(n)` that takes a single integer `n` and returns the number of...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 923, "level": 1, "question": "#### Task\nYou are tasked with designing a function that computes the number of digits in a number, utilizing logarithmic properties to achieve this in constant time O(1).\n\n#### Objective\nImplement the function `num_digits(n)` that takes a single int...
def int_to_string(n): if n == 0: return '0' is_negative = False if n < 0: is_negative = True n = -n digits = [] while n > 0: remainder = n % 10 digits.append(remainder) n = n // 10 digits.reverse() characters = [chr(ord('0') + d) for d in digit...
simplelr_Prefill
[ { "content": "Question:\nCreate a function that converts an integer to a string.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 924, "level": 1, "question": "Create a function that converts an integer to a string.", "split": "train" }
def countPairs(A, N, sum): seen = {} count = 0 for num in A: target = sum - num if target in seen: count += seen[target] if num in seen: seen[num] += 1 else: seen[num] = 1 return count
simplelr_Taco
[ { "content": "Question:\nDesign an algorithm to find the number of pairs of integers in an array that sum up to a given value. \n\nInput:\nThe task is to complete the function countPairs, which takes three arguments: an array of integers A[ ], its size N, and an integer sum. The function should return the count...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 925, "level": 1, "question": "Design an algorithm to find the number of pairs of integers in an array that sum up to a given value. \n\nInput:\nThe task is to complete the function countPairs, which takes three arguments: an array of integers A[ ], its size N, and an integer sum. Th...
def min_replacements_to_palindrome(s): count = 0 n = len(s) for i in range(n // 2): if s[i] != s[n - 1 - i]: count += 1 return count
simplelr_Apps
[ { "content": "Question:\n## Task\nYou are given a string of lowercase English letters. You need to count the minimal number of characters that need to be replaced to make the string a palindrome. A palindrome is a word, phrase, number, or other sequence of characters that reads the same forward and backward (ig...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 926, "level": 1, "question": "## Task\nYou are given a string of lowercase English letters. You need to count the minimal number of characters that need to be replaced to make the string a palindrome. A palindrome is a word, phrase, number, or other sequence of characters that reads...
def swap_adjacent_characters(s): if len(s) <= 1: return s lst = list(s) for i in range(0, len(lst) - 1, 2): lst[i], lst[i+1] = lst[i+1], lst[i] return ''.join(lst)
simplelr_Prefill
[ { "content": "Question:\nWrite a function to swap adjacent characters in a given string.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 927, "level": 1, "question": "Write a function to swap adjacent characters in a given string.", "split": "train" }
def sum_of_multiples(n, lst): if n == 0: return 0 sum_total = 0 for num in lst: if num % n == 0: sum_total += num return sum_total
simplelr_Prefill
[ { "content": "Question:\nCreate a function that takes two parameters: an integer `n` and a list of integers. The function should return the sum of all integers in the list that are multiples of `n`.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 928, "level": 1, "question": "Create a function that takes two parameters: an integer `n` and a list of integers. The function should return the sum of all integers in the list that are multiples of `n`.", "split": "train" }
def can_form_sum(matrix, S): mask = 1 # Initially, sum 0 is achievable for row in matrix: current_mask = 0 for num in row: if num > S: continue shifted = mask << num shifted_mask = shifted & ((1 << (S + 1)) - 1) current_mask |= shi...
simplelr_Apps
[ { "content": "Question:\nGiven a matrix of dimension m x n consisting of non-negative integers, determine if you can remove exactly one number from each row such that the resulting sum of the selected numbers from each row equals a target value S.\n\nExample 1:\nInput: matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 929, "level": 1, "question": "Given a matrix of dimension m x n consisting of non-negative integers, determine if you can remove exactly one number from each row such that the resulting sum of the selected numbers from each row equals a target value S.\n\nExample 1:\nInput: matrix =...
import heapq def enhanced_dijkstra(graph, source): # Initialize distances to infinity for all nodes distances = {node: float('inf') for node in graph} distances[source] = 0 # Distance to source is zero # Priority queue: (distance, node) heap = [] heapq.heappush(heap, (0, source)) while h...
simplelr_Algorithm
[ { "content": "Question:\n### Question: Implementing a Robust Dijkstra's Algorithm\n\n#### Context:\nYou've been asked to enhance the implementation of Dijkstra's algorithm to handle a variety of graphs and output the shortest paths from a source node to all other nodes. Your task is to consider edge cases such ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 930, "level": 1, "question": "### Question: Implementing a Robust Dijkstra's Algorithm\n\n#### Context:\nYou've been asked to enhance the implementation of Dijkstra's algorithm to handle a variety of graphs and output the shortest paths from a source node to all other nodes. Your ta...
from typing import List def pigeonhole_sort(arr: List[int]) -> List[int]: if not arr: return [] min_val = min(arr) max_val = max(arr) size = max_val - min_val + 1 pigeonholes = [0] * size for num in arr: pigeonholes[num - min_val] += 1 result = [] for i in...
simplelr_Data_Structure
[ { "content": "Question:\n### Pigeonhole Sort Implementation\n\nYou have been hired by a software development company that specializes in processing large volumes of integer data. One of the tasks at hand requires sorting lists of integers efficiently. However, the lists they deal with often have a relatively sm...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 931, "level": 1, "question": "### Pigeonhole Sort Implementation\n\nYou have been hired by a software development company that specializes in processing large volumes of integer data. One of the tasks at hand requires sorting lists of integers efficiently. However, the lists they de...
def reverse_words(s): words = s.split() reversed_words = [] for i in range(len(words) - 1, -1, -1): reversed_words.append(words[i]) return ' '.join(reversed_words) # Example Usage s = "the sky is blue" print(reverse_words(s)) # Output: "blue is sky the"
simplelr_Evol
[ { "content": "Question:\nWrite a function `reverse_words` that takes a string `s` as input and returns a string in which the words of `s` are reversed but their relative order remains the same. For example, given the input string \"hello world\", the output should be \"world hello\". You can assume that `s` con...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 932, "level": 1, "question": "Write a function `reverse_words` that takes a string `s` as input and returns a string in which the words of `s` are reversed but their relative order remains the same. For example, given the input string \"hello world\", the output should be \"world he...
import heapq from collections import defaultdict def get_skyline(buildings): events = [] for b in buildings: L, R, H = b events.append((L, 1, H)) # Start event events.append((R, 0, H)) # End event events.sort() # Sorts by x, then by type (0 comes before 1) heap = ...
simplelr_Algorithm
[ { "content": "Question:\n### Problem Statement\n\nYou are given a list of integers representing the heights of buildings along a street. Your task is to determine the \"skyline\" silhouette formed by these buildings when viewed from a distance. Specifically, you need to find the critical points where the height...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 933, "level": 1, "question": "### Problem Statement\n\nYou are given a list of integers representing the heights of buildings along a street. Your task is to determine the \"skyline\" silhouette formed by these buildings when viewed from a distance. Specifically, you need to find th...
def is_valid_ipv4_address(ip): parts = ip.split('.') if len(parts) != 4: return False for part in parts: if not part.isdigit(): return False if len(part) > 1 and part[0] == '0': return False num = int(part) if num < 0 or num > 255: ...
simplelr_Filter
[ { "content": "Question:\nCan you create a Python function that checks if a given string is a valid IPv4 address? The function should return `True` if the string is a valid IPv4 address, and `False` otherwise.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 934, "level": 1, "question": "Can you create a Python function that checks if a given string is a valid IPv4 address? The function should return `True` if the string is a valid IPv4 address, and `False` otherwise.", "split": "train" }
def max_rectangular_area(heights): stack = [-1] max_area = 0 n = len(heights) for i in range(n): while stack[-1] != -1 and heights[i] < heights[stack[-1]]: popped = stack.pop() width = i - stack[-1] - 1 area = heights[popped] * width if area > max_...
simplelr_Leetcode
[ { "content": "Question:\nYou are given an integer array `heights` representing the heights of buildings situated on a street. Your task is to determine the maximum area of a rectangular block that can be formed between these buildings, considering each building has a width of 1. The area of the block is given b...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 935, "level": 1, "question": "You are given an integer array `heights` representing the heights of buildings situated on a street. Your task is to determine the maximum area of a rectangular block that can be formed between these buildings, considering each building has a width of 1...
def is_divisible_by_all(number, divisors): if not divisors: return True for d in divisors: if d == 0: return False if number % d != 0: return False return True
simplelr_Prefill
[ { "content": "Question:\nWrite a function to check if a number is divisible by all the numbers in a list.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 936, "level": 1, "question": "Write a function to check if a number is divisible by all the numbers in a list.", "split": "train" }
def add_large_numbers(num1: str, num2: str) -> str: # Reverse the numbers to process from least significant digit num1_rev = num1[::-1] num2_rev = num2[::-1] max_len = max(len(num1_rev), len(num2_rev)) carry = 0 result = [] for i in range(max_len): # Get digits from each nu...
simplelr_Algorithm
[ { "content": "Question:\n### Analyzing Large Numbers\n\n#### Context\nHandling large numbers is a common task in programming, especially when dealing with operations that exceed the native integer limits of some languages. Such problems require you to manipulate numbers using strings or special libraries to ens...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 937, "level": 1, "question": "### Analyzing Large Numbers\n\n#### Context\nHandling large numbers is a common task in programming, especially when dealing with operations that exceed the native integer limits of some languages. Such problems require you to manipulate numbers using s...
from typing import List, Tuple def linear_search_optimized(array: List[int], query: int) -> Tuple[int, int]: first_occurrence = -1 count = 0 for index, num in enumerate(array): if num == query: if first_occurrence == -1: first_occurrence = index count += 1 ...
simplelr_Data_Structure
[ { "content": "Question:\nYou are given an array `array` containing `n` integers, and an integer `query`. Your task is to implement a function `linear_search_optimized` that finds the index of the `query` element in the `array`. If the element is not found, the function should return -1. \n\nHowever, to challeng...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 938, "level": 1, "question": "You are given an array `array` containing `n` integers, and an integer `query`. Your task is to implement a function `linear_search_optimized` that finds the index of the `query` element in the `array`. If the element is not found, the function should r...
def merge_intervals(intervals): if not intervals: return [] # Sort intervals based on the start time sorted_intervals = sorted(intervals, key=lambda x: x[0]) merged = [] for interval in sorted_intervals: # If merged is empty or current interval does not overlap with the las...
simplelr_Filter
[ { "content": "Question:\nGiven a list of intervals, merge all overlapping intervals to produce a new list of non-overlapping intervals.\n\nExample:\n\nInput: [[1, 2], [3, 5], [4, 7], [8, 10], [12, 16]]\nOutput: [[1, 2], [3, 7], [8, 10], [12, 16]]\n\nExplanation: Given [1, 2] and [3, 5] do not overlap, they are ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 939, "level": 1, "question": "Given a list of intervals, merge all overlapping intervals to produce a new list of non-overlapping intervals.\n\nExample:\n\nInput: [[1, 2], [3, 5], [4, 7], [8, 10], [12, 16]]\nOutput: [[1, 2], [3, 7], [8, 10], [12, 16]]\n\nExplanation: Given [1, 2] an...
def is_prime(n): if n < 2: print(0) return False sieve = [True] * (n + 1) sieve[0] = sieve[1] = False for current in range(2, int(n ** 0.5) + 1): if sieve[current]: for multiple in range(current * current, n + 1, current): sieve[multiple] = False c...
simplelr_Filter
[ { "content": "Question:\nCan you modify the given Python function `is_prime(n)` to check if a given number is a prime number and also print the total count of prime numbers less than the given number? The function should return `True` if the number is prime and `False` otherwise, and the count of prime numbers ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 940, "level": 1, "question": "Can you modify the given Python function `is_prime(n)` to check if a given number is a prime number and also print the total count of prime numbers less than the given number? The function should return `True` if the number is prime and `False` otherwis...
def subarray_sum(nums, target): prefix_counts = {0: 1} current_sum = 0 result = 0 for num in nums: current_sum += num if (current_sum - target) in prefix_counts: result += prefix_counts[current_sum - target] if current_sum in prefix_counts: prefix_counts[c...
simplelr_Leetcode
[ { "content": "Question:\nYou are given a **0-indexed** integer array `nums` of length `n` and an integer `target`. You need to determine the number of non-empty continuous subarrays whose sum is equal to `target`. A subarray is a contiguous part of an array. Implement a function `int subarraySum(int[] nums, int...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 941, "level": 1, "question": "You are given a **0-indexed** integer array `nums` of length `n` and an integer `target`. You need to determine the number of non-empty continuous subarrays whose sum is equal to `target`. A subarray is a contiguous part of an array. Implement a functio...
def evaluate_expressions(expressions: str) -> list: expr_list = [e.strip() for e in expressions.split(';') if e.strip()] results = [] for expr in expr_list: result = eval(expr) results.append(result) return results
simplelr_Evol
[ { "content": "Question:\nWrite a function that processes a provided string of mathematical expressions separated by semicolons and evaluates each expression. The string can contain basic arithmetic operations (+, -, *, /) and parentheses for grouping. Return a list of evaluated results for each expression in th...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 942, "level": 1, "question": "Write a function that processes a provided string of mathematical expressions separated by semicolons and evaluates each expression. The string can contain basic arithmetic operations (+, -, *, /) and parentheses for grouping. Return a list of evaluated...
def max_parentheses_depth(s: str) -> int: current_depth = 0 max_depth = 0 for char in s: if char == '(': current_depth += 1 if current_depth > max_depth: max_depth = current_depth elif char == ')': if current_depth > 0: curr...
simplelr_Algorithm
[ { "content": "Question:\n### Question: Counting Nested Parentheses Depth\n\nYou are tasked with developing a Python function that computes the maximum nesting depth of parentheses in a given string.\n\n#### Function Signature\n```python\ndef max_parentheses_depth(s: str) -> int:\n pass\n```\n\n#### Input:\n-...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 943, "level": 1, "question": "### Question: Counting Nested Parentheses Depth\n\nYou are tasked with developing a Python function that computes the maximum nesting depth of parentheses in a given string.\n\n#### Function Signature\n```python\ndef max_parentheses_depth(s: str) -> int...
def find_min_platforms(arrivals, departures): events = [] for t in arrivals: events.append((t, 1)) # 1 represents an arrival for t in departures: events.append((t, 0)) # 0 represents a departure # Sort the events by time, with departures before arrivals if times are equal events.s...
simplelr_Filter
[ { "content": "Question:\nWrite a Python function to find the minimum number of platforms required at a railway station given the arrival and departure times of trains.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 944, "level": 1, "question": "Write a Python function to find the minimum number of platforms required at a railway station given the arrival and departure times of trains.", "split": "train" }
def min_abs_difference(arr): total = sum(arr) n = len(arr) min_diff = float('inf') for mask in range(1, (1 << n)): if mask == (1 << n) - 1: continue sum_subset = 0 for i in range(n): if mask & (1 << i): sum_subset += arr[i] cur...
simplelr_Code_Contests
[ { "content": "Question:\nYou are given an array of integers and you need to divide this array into two non-empty parts such that the absolute difference between the sum of elements in the first part and the sum of elements in the second part is minimized. Let f(A) be this minimum possible absolute difference.\n...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 945, "level": 1, "question": "You are given an array of integers and you need to divide this array into two non-empty parts such that the absolute difference between the sum of elements in the first part and the sum of elements in the second part is minimized. Let f(A) be this minim...
def merge_sorted_lists(list1, list2): if not isinstance(list1, list) or not isinstance(list2, list): raise ValueError("Both inputs must be lists") i = j = 0 result = [] last_added = None # Merge the two sorted lists, ensuring no duplicates while i < len(list1) and j < len(list2...
simplelr_Evol
[ { "content": "Question:\nDevelop a Python function that combines two sorted input lists (list1 and list2) into a single sorted list while removing any duplicate elements. The function should handle both lists being empty and should raise an appropriate exception if the inputs are not lists. Additionally, ensure...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 946, "level": 1, "question": "Develop a Python function that combines two sorted input lists (list1 and list2) into a single sorted list while removing any duplicate elements. The function should handle both lists being empty and should raise an appropriate exception if the inputs a...
def factorial(n): if n == 0: return 1 else: return n * factorial(n - 1) print(factorial(5)) # Output: 120
simplelr_Filter
[ { "content": "Question:\nHere are some examples of code that utilizes recursion, with detailed explanations of how they work:\n\n**1. Factorial Calculation:**\n\n```python\ndef factorial(n):\n if n == 0:\n return 1\n else:\n return n * factorial(n - 1)\n\nprint(factorial(5))\nAnswer:\nLet's think step b...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 947, "level": 1, "question": "Here are some examples of code that utilizes recursion, with detailed explanations of how they work:\n\n**1. Factorial Calculation:**\n\n```python\ndef factorial(n):\n if n == 0:\n return 1\n else:\n return n * factorial(n - 1)\n\nprint(factoria...
def longest_increasing_subsequence(arr): if not arr: return 0 n = len(arr) dp = [1] * n for i in range(n): for j in range(i): if arr[j] < arr[i]: if dp[i] < dp[j] + 1: dp[i] = dp[j] + 1 return max(dp)
simplelr_Taco
[ { "content": "Question:\nGiven an array of unsorted integers, your goal is to find the longest subsequence that is strictly increasing and return its length. This subsequence does not need to be contiguous. For example, given the array `[10, 9, 2, 5, 3, 7, 101, 18]`, the longest increasing subsequence would be ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 948, "level": 1, "question": "Given an array of unsorted integers, your goal is to find the longest subsequence that is strictly increasing and return its length. This subsequence does not need to be contiguous. For example, given the array `[10, 9, 2, 5, 3, 7, 101, 18]`, the longes...
def pounds_to_usd(amount): return amount * 1.35
simplelr_Prefill
[ { "content": "Question:\nCreate a function that converts British pounds to US dollars using the current exchange rate. The function should take an amount in British pounds and return the equivalent amount in US dollars. Assume the current exchange rate is 1 pound = 1.35 USD.\nAnswer:\nLet's think step by step.\...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 949, "level": 1, "question": "Create a function that converts British pounds to US dollars using the current exchange rate. The function should take an amount in British pounds and return the equivalent amount in US dollars. Assume the current exchange rate is 1 pound = 1.35 USD.", ...
import re def count_words(s): s_lower = s.lower() words = re.findall(r"[a-z'-]+", s_lower) counts = {} for word in words: counts[word] = counts.get(word, 0) + 1 return counts
simplelr_Taco
[ { "content": "Question:\nA team of scientists discovered a new pattern in how certain words repeat in a given text. They want a script that counts how often each unique word appears, ignoring case and punctuation (. , ? ! _ ).\n\nCreate a function that receives a string input and outputs a dictionary where the ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 950, "level": 1, "question": "A team of scientists discovered a new pattern in how certain words repeat in a given text. They want a script that counts how often each unique word appears, ignoring case and punctuation (. , ? ! _ ).\n\nCreate a function that receives a string input a...
import heapq def dijkstra(adj_matrix, source): n = len(adj_matrix) INF = float('inf') distances = [INF] * n distances[source] = 0 visited = [False] * n priority_queue = [] heapq.heappush(priority_queue, (0, source)) while priority_queue: current_dist, u = heapq.heappop(prio...
simplelr_Filter
[ { "content": "Question:\nI am working on a problem where I need to find the shortest path in a weighted graph. The graph is represented as an adjacency matrix. Can you provide me with a Python code snippet using Dijkstra's algorithm to solve this problem?\nAnswer:\nLet's think step by step.\n", "role": "use...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 951, "level": 1, "question": "I am working on a problem where I need to find the shortest path in a weighted graph. The graph is represented as an adjacency matrix. Can you provide me with a Python code snippet using Dijkstra's algorithm to solve this problem?", "split": "train" }
def find_row(data, target): return next((i for i, row in enumerate(data) if target in row), None)
simplelr_Filter
[ { "content": "Question:\nI have a 2D list of data and I want to write a function that finds the row where a specific value appears.\n\nHere is my code:\n```\ndef find_row(data, target):\n for i, row in enumerate(data):\n if target in row:\n return i\n return None\n```\nHow do I modify th...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 952, "level": 1, "question": "I have a 2D list of data and I want to write a function that finds the row where a specific value appears.\n\nHere is my code:\n```\ndef find_row(data, target):\n for i, row in enumerate(data):\n if target in row:\n return i\n re...
import bisect def find_fraudulent_transactions(transactions, window): amount_dict = {} for idx, (ts, amt) in enumerate(transactions): if amt not in amount_dict: amount_dict[amt] = [] amount_dict[amt].append((ts, idx)) result = [] for amt, group in amount_dict.items(): ...
simplelr_Algorithm
[ { "content": "Question:\n### Scenario\nYou are developing a software that processes a large dataset of customer transactions to detect potentially fraudulent activities. For this task, you need to analyze sequences of transactions and identify patterns that are indicative of fraud. A known indicator of fraud is...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 953, "level": 1, "question": "### Scenario\nYou are developing a software that processes a large dataset of customer transactions to detect potentially fraudulent activities. For this task, you need to analyze sequences of transactions and identify patterns that are indicative of fr...
def print_right_angled_triangle(height): for i in range(1, height + 1): print('*' * i)
simplelr_Prefill
[ { "content": "Question:\nWrite a python function to print a right-angled triangle with stars. The height of the triangle should be user-defined.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 954, "level": 1, "question": "Write a python function to print a right-angled triangle with stars. The height of the triangle should be user-defined.", "split": "train" }
def h_index(citations): citations.sort(reverse=True) max_h = 0 for i in range(len(citations)): if citations[i] >= (i + 1): max_h = i + 1 else: break return max_h
simplelr_Leetcode
[ { "content": "Question:\nYou are given an array that represents the number of citations that researchers have. Each element of the array `citations` corresponds to a researcher's total number of citations. Your goal is to determine the researcher's h-index.\n\nThe h-index is defined as follows: A researcher has...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 955, "level": 1, "question": "You are given an array that represents the number of citations that researchers have. Each element of the array `citations` corresponds to a researcher's total number of citations. Your goal is to determine the researcher's h-index.\n\nThe h-index is de...
def longest_common_substring(str1, str2): m = len(str1) n = len(str2) dp = [[0] * (n + 1) for _ in range(m + 1)] max_length = 0 end = 0 for i in range(m): for j in range(n): if str1[i] == str2[j]: dp[i+1][j+1] = dp[i][j] + 1 if dp[i+1][j+1...
simplelr_Filter
[ { "content": "Question:\nWrite a Python function that takes two strings and returns the longest common substring. If there are multiple substrings of the same length, return any one of them. For example, given the strings \"abcde\" and \"abfce\", the function should return \"abc\" or \"abf\".\nAnswer:\nLet's th...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 956, "level": 1, "question": "Write a Python function that takes two strings and returns the longest common substring. If there are multiple substrings of the same length, return any one of them. For example, given the strings \"abcde\" and \"abfce\", the function should return \"ab...
def count_letters(s): counts = {} for char in s: if char.isalpha(): lower_char = char.lower() counts[lower_char] = counts.get(lower_char, 0) + 1 return counts
simplelr_Filter
[ { "content": "Question:\nCreate a Python function that takes a string as input and returns a dictionary with the count of each letter in the string. The function should be case-insensitive and should ignore any non-letter characters.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 957, "level": 1, "question": "Create a Python function that takes a string as input and returns a dictionary with the count of each letter in the string. The function should be case-insensitive and should ignore any non-letter characters.", "split": "train" }
def max_points(points): if not points: return 0 n = len(points) if n == 1: return points[0] prev_prev = points[0] prev = max(points[0], points[1]) for i in range(2, n): current = max(prev, prev_prev + points[i]) prev_prev, prev = prev, current return prev
simplelr_Leetcode
[ { "content": "Question:\nYou are given an integer array `points` of length `n` where `points[i]` represents the point value of the `i-th` game. You have been challenged to play these games sequentially while following specific rules to maximize your total score. The rules are:\n- If you choose to play a game at...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 958, "level": 1, "question": "You are given an integer array `points` of length `n` where `points[i]` represents the point value of the `i-th` game. You have been challenged to play these games sequentially while following specific rules to maximize your total score. The rules are:\...
def sum_values_for_keys(data, keys): total = 0 for key in keys: if key in data: total += data[key] return total
simplelr_Filter
[ { "content": "Question:\nDesign a Python function that accepts a dictionary with numeric values and a list of keys, and returns the sum of the values associated with the given keys. If a key is not found in the dictionary, it should be ignored. The function should be able to handle any numeric type (integers, f...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 959, "level": 1, "question": "Design a Python function that accepts a dictionary with numeric values and a list of keys, and returns the sum of the values associated with the given keys. If a key is not found in the dictionary, it should be ignored. The function should be able to ha...
def square_elements(lst): return [x ** 2 for x in lst]
simplelr_Filter
[ { "content": "Question:\nCreate a Python function that accepts a list of integers and returns a new list with each element squared. The function should be named `square_elements`, and it should handle any list of integers provided to it.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 960, "level": 1, "question": "Create a Python function that accepts a list of integers and returns a new list with each element squared. The function should be named `square_elements`, and it should handle any list of integers provided to it.", "split": "train" }
from itertools import permutations def find_anagrams(s): if len(s) == 0: return [] perms = permutations(s) unique_perms = set() for p in perms: unique_perms.add(''.join(p)) return sorted(unique_perms)
simplelr_Apps
[ { "content": "Question:\nImplement a function `find_anagrams` that takes a string `s` and returns a list of all unique anagrams that can be formed using the characters of `s`. The output list should be sorted in lexicographical order. You may assume that the input string contains only lowercase letters.\n\nFor ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 961, "level": 1, "question": "Implement a function `find_anagrams` that takes a string `s` and returns a list of all unique anagrams that can be formed using the characters of `s`. The output list should be sorted in lexicographical order. You may assume that the input string contai...
def longest_unique_substr(string: str) -> (int, str): if not string: return (0, "") left = 0 max_len = 0 start = 0 last_occurrence = {} for right in range(len(string)): char = string[right] if char in last_occurrence and last_occurrence[char] >= left: ...
simplelr_Data_Structure
[ { "content": "Question:\n### Find the Longest Substring without Repeating Characters\n\n**Objective**: Implement a function that finds and returns the length of the longest substring without repeating characters and the substring itself.\n\n**Function Signature**:\n```python\ndef longest_unique_substr(string: s...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 962, "level": 1, "question": "### Find the Longest Substring without Repeating Characters\n\n**Objective**: Implement a function that finds and returns the length of the longest substring without repeating characters and the substring itself.\n\n**Function Signature**:\n```python\nd...
def check_fake_book(titles, reviews): result = [] for title in titles: if title not in reviews or (title in reviews and not reviews[title]): result.append((title, "No reviews yet")) return result
simplelr_Filter
[ { "content": "Question:\nWrite a Python function `check_fake_book` that takes a list of strings representing book titles and a dictionary of book reviews. The function should return a list of tuples. Each tuple should contain the title of a book that has no reviews in the review dictionary and a default review ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 963, "level": 1, "question": "Write a Python function `check_fake_book` that takes a list of strings representing book titles and a dictionary of book reviews. The function should return a list of tuples. Each tuple should contain the title of a book that has no reviews in the revie...
def contains_peak(arr): n = len(arr) if n < 3: return False # Compute min_left: min of elements before each position min_left = [0] * n current_min = arr[0] for j in range(1, n): min_left[j] = current_min if arr[j] < current_min: current_min = arr[j] ...
simplelr_Leetcode
[ { "content": "Question:\nGiven an array of integers `arr` representing the heights of buildings, you are tasked with finding if there exist three buildings such that they form a \"peak\". A peak is defined as a sequence of three buildings where the height of the second building is strictly greater than the heig...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 964, "level": 1, "question": "Given an array of integers `arr` representing the heights of buildings, you are tasked with finding if there exist three buildings such that they form a \"peak\". A peak is defined as a sequence of three buildings where the height of the second building...
def are_anagrams(s1: str, s2: str) -> bool: if len(s1) != len(s2): return False count1 = [0] * 26 count2 = [0] * 26 for c in s1: index = ord(c) - ord('a') count1[index] += 1 for c in s2: index = ord(c) - ord('a') count2[index] += 1 return count1 == count2
simplelr_Algorithm
[ { "content": "Question:\n## Check if Two Strings Are Anagrams\n\n### Problem Statement\nTwo strings are considered anagrams if they can be rearranged to form each other by reordering their characters. Write a function to determine if two input strings are anagrams of each other.\n\n### Function Signature\n```py...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 965, "level": 1, "question": "## Check if Two Strings Are Anagrams\n\n### Problem Statement\nTwo strings are considered anagrams if they can be rearranged to form each other by reordering their characters. Write a function to determine if two input strings are anagrams of each other...
def is_string_rotation(s1: str, s2: str) -> bool: if len(s1) != len(s2): return False concatenated = s1 + s1 return s2 in concatenated
simplelr_Algorithm
[ { "content": "Question:\n### Problem Description\n\nYou have been given two non-empty strings `s1` and `s2`. The task is to determine whether the second string `s2` is a rotation of the first string `s1`.\n\nA string `s2` is a rotation of `s1` if and only if there exists a split of `s1` into two parts `x` and `...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 966, "level": 1, "question": "### Problem Description\n\nYou have been given two non-empty strings `s1` and `s2`. The task is to determine whether the second string `s2` is a rotation of the first string `s1`.\n\nA string `s2` is a rotation of `s1` if and only if there exists a spli...
def find_smallest_with_index(nums): if not nums: return None, None smallest_num = nums[0] smallest_index = 0 for index in range(1, len(nums)): if nums[index] < smallest_num: smallest_num = nums[index] smallest_index = index return smallest_num, smallest_index
simplelr_Filter
[ { "content": "Question:\nWrite a Python function to find the smallest number in a given list of integers. The function should also return the index of the smallest number in the list. If there are multiple occurrences of the smallest number, return the index of the first occurrence. Additionally, ensure your fu...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 967, "level": 1, "question": "Write a Python function to find the smallest number in a given list of integers. The function should also return the index of the smallest number in the list. If there are multiple occurrences of the smallest number, return the index of the first occurr...
import random import time def quicksort(arr, pivot_strategy='random'): if len(arr) <= 1: return arr if pivot_strategy == 'random': pivot = random.choice(arr) elif pivot_strategy == 'first': pivot = arr[0] elif pivot_strategy == 'last': pivot = arr[-1] elif pivot_stra...
simplelr_Filter
[ { "content": "Question:\nWhat is run time complexity of quick sort in Best, Average and Worst cases? Also, provide the QuickSort code in Python that demonstrates these cases.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 968, "level": 1, "question": "What is run time complexity of quick sort in Best, Average and Worst cases? Also, provide the QuickSort code in Python that demonstrates these cases.", "split": "train" }
def square_elements(numbers): return [num ** 2 for num in numbers]
simplelr_Filter
[ { "content": "Question:\nWrite a function in Python that takes a list of integers as input and returns a new list where each element is the square of the corresponding element in the input list. Ensure your function handles an empty list gracefully, returning an empty list in such a case.\nAnswer:\nLet's think ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 969, "level": 1, "question": "Write a function in Python that takes a list of integers as input and returns a new list where each element is the square of the corresponding element in the input list. Ensure your function handles an empty list gracefully, returning an empty list in s...
def fibonacci(n): if n <= 0: return 0 elif n == 1: return 1 else: a, b = 0, 1 for i in range(2, n + 1): next_fib = a + b a = b b = next_fib return b # Example test cases print(fibonacci(0)) # Expected output: 0 print(fibonacci(1))...
simplelr_Filter
[ { "content": "Question:\nCreate a Python function that calculates the value of the nth Fibonacci number using a loop. Ensure that your function is efficient and able to handle large numbers by using appropriate data types. Additionally, the function should accept an integer n as input and return the nth Fibonac...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 970, "level": 1, "question": "Create a Python function that calculates the value of the nth Fibonacci number using a loop. Ensure that your function is efficient and able to handle large numbers by using appropriate data types. Additionally, the function should accept an integer n a...
def reverse_words(s): return ' '.join(s.split()[::-1]) # Example usage: input_str = "Hello world this is Python" output_str = reverse_words(input_str) print(output_str) # Output: "Python is this world Hello"
simplelr_Filter
[ { "content": "Question:\nCraft a Python code snippet that reverses the order of words in a given string. The words are separated by spaces and there might be multiple spaces between words. How can I ensure that the reversed words are separated by a single space in the output?\nAnswer:\nLet's think step by step....
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 971, "level": 1, "question": "Craft a Python code snippet that reverses the order of words in a given string. The words are separated by spaces and there might be multiple spaces between words. How can I ensure that the reversed words are separated by a single space in the output?",...
def factorial(n): result = 1 for i in range(2, n + 1): result *= i return result
simplelr_Filter
[ { "content": "Question:\nI have a Python code snippet that calculates the factorial of a number using recursion. I want to modify this code to use iteration instead of recursion. How can I do this?\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 972, "level": 1, "question": "I have a Python code snippet that calculates the factorial of a number using recursion. I want to modify this code to use iteration instead of recursion. How can I do this?", "split": "train" }
def longest_substring_equal_ab(s): balance_map = {0: -1} # Stores the first occurrence index of each balance value current_balance = 0 max_length = 0 for i, char in enumerate(s): # Update the balance based on the current character current_balance += 1 if char == 'a' else -1 ...
simplelr_Filter
[ { "content": "Question:\nThis is the problem:\n\nYou are given a string containing only the characters 'a' and 'b'. You need to find the length of the longest substring that contains an equal number of 'a's and 'b's.\n\nExample:\n\nInput: \"aabbabb\"\nOutput: 4\n\nExplanation: The longest substring with an equa...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 973, "level": 1, "question": "This is the problem:\n\nYou are given a string containing only the characters 'a' and 'b'. You need to find the length of the longest substring that contains an equal number of 'a's and 'b's.\n\nExample:\n\nInput: \"aabbabb\"\nOutput: 4\n\nExplanation: ...
def double_values(arr): return [x * 2 for x in arr]
simplelr_Prefill
[ { "content": "Question:\nCreate a function that multiplies the values of an array by 2 and returns the converted array. Here's what the input and output should look like.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 974, "level": 1, "question": "Create a function that multiplies the values of an array by 2 and returns the converted array. Here's what the input and output should look like.", "split": "train" }
def gcd_and_lcm_sum(X, Y): a = abs(X) b = abs(Y) # Compute GCD using the Euclidean algorithm while b != 0: temp = b b = a % b a = temp gcd = a if gcd == 0: return 0 # Both X and Y are zero else: lcm = (abs(X) * abs(Y)) // gcd return ...
simplelr_Prefill
[ { "content": "Question:\nCreate a function that accepts two integers, say X and Y, and returns the sum of their greatest common divisor (GCD) and least common multiple (LCM). The function should be efficient in terms of time complexity.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 975, "level": 1, "question": "Create a function that accepts two integers, say X and Y, and returns the sum of their greatest common divisor (GCD) and least common multiple (LCM). The function should be efficient in terms of time complexity.", "split": "train" }
from typing import List def find_longest_common_prefix(strings: List[str]) -> str: if not strings: return "" min_length = min(len(s) for s in strings) prefix = [] for i in range(min_length): current_char = strings[0][i] for s in strings[1:]: if s[i] != current_char: ...
simplelr_Data_Structure
[ { "content": "Question:\nYou are tasked with writing a function to find the longest common prefix among an array of strings. Implement this function using a selected algorithmic approach, ensuring to handle edge cases effectively. The function should efficiently determine the longest shared starting sequence in...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 976, "level": 1, "question": "You are tasked with writing a function to find the longest common prefix among an array of strings. Implement this function using a selected algorithmic approach, ensuring to handle edge cases effectively. The function should efficiently determine the l...
def is_palindrome(s: str) -> bool: filtered = ''.join([c.lower() for c in s if c.isalnum()]) return filtered == filtered[::-1]
simplelr_Taco
[ { "content": "Question:\nYou are given a string consisting of alphabetical letters, digits, and other characters. You need to write a function to check if the string is a palindrome, considering only the letters and digits and ignoring case.\n\nA string is a palindrome when it reads the same backward as forward...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 977, "level": 1, "question": "You are given a string consisting of alphabetical letters, digits, and other characters. You need to write a function to check if the string is a palindrome, considering only the letters and digits and ignoring case.\n\nA string is a palindrome when it ...
def insertion_sort(nums): # Create a copy of the input list to avoid modifying the original sorted_nums = nums.copy() for i in range(1, len(sorted_nums)): key = sorted_nums[i] j = i - 1 while j >= 0 and sorted_nums[j] > key: sorted_nums[j + 1] = sorted_nums[j] ...
simplelr_Prefill
[ { "content": "Question:\nWrite a function to sort a list of integers in ascending order using the insertion sort algorithm. Insertion sort works by building a sorted array one item at a time. It takes each element from the input data, finds the location it belongs within the sorted list, and inserts it there. I...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 978, "level": 1, "question": "Write a function to sort a list of integers in ascending order using the insertion sort algorithm. Insertion sort works by building a sorted array one item at a time. It takes each element from the input data, finds the location it belongs within the so...
def merge_sorted_lists(list1: list[int], list2: list[int]) -> list[int]: result = [] i = j = 0 while i < len(list1) and j < len(list2): if list1[i] <= list2[j]: result.append(list1[i]) i += 1 else: result.append(list2[j]) j += 1 result += l...
simplelr_Algorithm
[ { "content": "Question:\n### Coding Problem: Merge Two Sorted Lists\nYou are given two sorted lists of integers. Your task is to write a function that merges these two lists into a single sorted list. Do not use the built-in sorting functions.\n\n### Function Signature\n```python\ndef merge_sorted_lists(list1: ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 979, "level": 1, "question": "### Coding Problem: Merge Two Sorted Lists\nYou are given two sorted lists of integers. Your task is to write a function that merges these two lists into a single sorted list. Do not use the built-in sorting functions.\n\n### Function Signature\n```pyth...
from typing import List def product_bundles(k: int, products: List[int]) -> List[List[int]]: if len(products) % k != 0: return [] return [products[i:i+k] for i in range(0, len(products), k)]
simplelr_Apps
[ { "content": "Question:\nYou are given a list of unique integers, and each integer represents the identifier of a unique product. You need to form bundles of these products such that each bundle has exactly `k` products. If it is not possible to form such bundles with the given list, return an empty list. Other...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 980, "level": 1, "question": "You are given a list of unique integers, and each integer represents the identifier of a unique product. You need to form bundles of these products such that each bundle has exactly `k` products. If it is not possible to form such bundles with the given...
def minSubstrings(S): if not S: return 0 count = 1 last = S[0] for c in S[1:]: if c > last: last = c else: count += 1 last = c return count
simplelr_Taco
[ { "content": "Question:\nGiven a string containing only digits, determine the minimum number of substrings such that each substring forms a valid increasing sequence.\n\nExample 1:\nInput:\nS = \"1234\"\nOutput:\n1\nExplanation:\nThe entire string \"1234\" is already an increasing sequence.\n\nExample 2:\nInput...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 981, "level": 1, "question": "Given a string containing only digits, determine the minimum number of substrings such that each substring forms a valid increasing sequence.\n\nExample 1:\nInput:\nS = \"1234\"\nOutput:\n1\nExplanation:\nThe entire string \"1234\" is already an increas...
def enhanced_selection_sort(arr: list) -> list: arr_copy = arr.copy() n = len(arr_copy) if n <= 1: return arr_copy for i in range(n): min_index = i for j in range(i + 1, n): if arr_copy[j] < arr_copy[min_index]: min_index = j if min_index != i:...
simplelr_Data_Structure
[ { "content": "Question:\n### Coding Challenge: Enhanced Selection Sort with Edge-Case Handling\n\n#### Context\nYou are tasked with implementing and optimizing the Selection Sort algorithm for different use cases. The algorithm must handle various edge cases and provide a sorted result in ascending order. \n\n#...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 982, "level": 1, "question": "### Coding Challenge: Enhanced Selection Sort with Edge-Case Handling\n\n#### Context\nYou are tasked with implementing and optimizing the Selection Sort algorithm for different use cases. The algorithm must handle various edge cases and provide a sorte...
def sum_of_first_n_odd_numbers(n): return n ** 2
simplelr_Prefill
[ { "content": "Question:\nCreate a function that takes an integer `n` and returns the sum of the first `n` positive odd numbers. The first `n` positive odd numbers are 1, 3, 5, ..., (2n - 1).\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 983, "level": 1, "question": "Create a function that takes an integer `n` and returns the sum of the first `n` positive odd numbers. The first `n` positive odd numbers are 1, 3, 5, ..., (2n - 1).", "split": "train" }
from collections import Counter def max_operations(arr, x): freq = Counter(arr) processed = set() operations = 0 for a in freq: if a in processed: continue b = x - a if b not in freq: continue if a == b: count = freq[a] // 2 ...
simplelr_Leetcode
[ { "content": "Question:\nYou are given an array of integers `arr` and an integer `x`. You are allowed to perform the following operation any number of times: choose any two indices `i` and `j` such that `arr[i] + arr[j] == x` (and `i != j`), then remove `arr[i]` and `arr[j]` from the array. Your task is to dete...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 984, "level": 1, "question": "You are given an array of integers `arr` and an integer `x`. You are allowed to perform the following operation any number of times: choose any two indices `i` and `j` such that `arr[i] + arr[j] == x` (and `i != j`), then remove `arr[i]` and `arr[j]` fr...
def largest_sum_subarray(arr): max_current = max_global = arr[0] for num in arr[1:]: max_current = max(num, max_current + num) if max_current > max_global: max_global = max_current return max_global
simplelr_Taco
[ { "content": "Question:\nYou are given a list of integers. Your task is to create a function ```largest_sum_subarray()``` that finds the contiguous subarray within a one-dimensional numerical array which has the largest sum and returns this sum.\n\n```python\nFor Python\nlargest_sum_subarray([1, 2, -1, 2, -3, 2...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 985, "level": 1, "question": "You are given a list of integers. Your task is to create a function ```largest_sum_subarray()``` that finds the contiguous subarray within a one-dimensional numerical array which has the largest sum and returns this sum.\n\n```python\nFor Python\nlarges...
def optimized_selection_sort(arr: list) -> list: arr_copy = arr.copy() n = len(arr_copy) for i in range(n): # Find the minimum element in the unsorted part of the array min_index = i for j in range(i + 1, n): if arr_copy[j] < arr_copy[min_index]: min_...
simplelr_Data_Structure
[ { "content": "Question:\n### Selection Sort Implementation and Reflection\n\nYou are assigned the task of improving and analyzing the Selection Sort algorithm provided below. Selection Sort is a simple sorting algorithm with a quadratic time complexity that sorts an array by repeatedly finding the minimum eleme...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 986, "level": 1, "question": "### Selection Sort Implementation and Reflection\n\nYou are assigned the task of improving and analyzing the Selection Sort algorithm provided below. Selection Sort is a simple sorting algorithm with a quadratic time complexity that sorts an array by re...
def filter_odd_keys_and_integer_values(d): return {k: v for k, v in d.items() if isinstance(k, int) and k % 2 == 1 and isinstance(v, int)}
simplelr_Filter
[ { "content": "Question:\nI'm trying to create a function that filters a dictionary to include only the items where the key is odd and the value is an integer. How can I achieve that?\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 987, "level": 1, "question": "I'm trying to create a function that filters a dictionary to include only the items where the key is odd and the value is an integer. How can I achieve that?", "split": "train" }
def average_temperature(temperatures): if not temperatures: return None return sum(temperatures) / len(temperatures)
simplelr_Filter
[ { "content": "Question:\nCan you help me create a Python function to calculate the average temperature over a list of days? Given a list of daily temperatures in Celsius, the function should return the average temperature. If the list is empty, it should return `None`.\nAnswer:\nLet's think step by step.\n", ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 988, "level": 1, "question": "Can you help me create a Python function to calculate the average temperature over a list of days? Given a list of daily temperatures in Celsius, the function should return the average temperature. If the list is empty, it should return `None`.", "spl...
def relative_sort(A: list[int], B: list[int]) -> list[int]: order_map = {v: i for i, v in enumerate(B)} X = [x for x in A if x in order_map] Y = [y for y in A if y not in order_map] X_sorted = sorted(X, key=lambda x: order_map[x]) Y_sorted = sorted(Y) return X_sorted + Y_sorted
simplelr_Algorithm
[ { "content": "Question:\n### Problem Statement - Sort a List Based on Another List\n\nGiven two lists, `A` and `B`, implement a function called `relative_sort` that sorts the elements of list `A` based on the ordering defined by list `B`. If an element in `A` does not appear in `B`, it should be placed at the e...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 989, "level": 1, "question": "### Problem Statement - Sort a List Based on Another List\n\nGiven two lists, `A` and `B`, implement a function called `relative_sort` that sorts the elements of list `A` based on the ordering defined by list `B`. If an element in `A` does not appear in...
def sort_string_lexicographically(s): return ''.join(sorted(s))
simplelr_Prefill
[ { "content": "Question:\nWrite a python function to sort a given string in lexicographical order. The function should take a string as input and return the sorted string.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 990, "level": 1, "question": "Write a python function to sort a given string in lexicographical order. The function should take a string as input and return the sorted string.", "split": "train" }
def manage_dbm_database(filename: str) -> None: import dbm with dbm.open(filename, 'c') as db: # Store key-value pairs as bytes db[b'name'] = b'Alice' db[b'age'] = b'30' db[b'city'] = b'New York' # Retrieve and print values print(f"name: {db[b'name'].decode()}")...
simplelr_Docs
[ { "content": "Question:\nGiven the `dbm` module and its capabilities as described in the documentation, you are to implement a Python function that interacts with a DBM database to achieve specific tasks. The function should use dictionary-like operations, handle context management, and demonstrate error handli...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 991, "level": 1, "question": "Given the `dbm` module and its capabilities as described in the documentation, you are to implement a Python function that interacts with a DBM database to achieve specific tasks. The function should use dictionary-like operations, handle context manage...
def extract_poem_lines(poem, n): result = [] for line in poem: stripped = line.strip() if stripped: result.append(stripped) if len(result) == n: break return result
simplelr_Code_Contests
[ { "content": "Question:\nYour favorite publication is planning a weekly feature where it prints the first few lines of the poems of various poets. They need a small utility that, given a poem's text, extracts and prints the first N lines of the poem without any empty lines or unnecessary spaces.\n\nTask: Create...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 992, "level": 1, "question": "Your favorite publication is planning a weekly feature where it prints the first few lines of the poems of various poets. They need a small utility that, given a poem's text, extracts and prints the first N lines of the poem without any empty lines or u...
def linear_search(array, target): """ This function performs a linear search to find the first occurrence of the target element in the given array. Parameters: array (list): The list of elements to search through. target: The element to be searched for. Returns: int: The index of t...
simplelr_Filter
[ { "content": "Question:\nWrite a code that implements a linear search algorithm to find the first occurrence of a specified element in an array. The array and the element to be searched for should be provided as input. If the element is found, the code should return the index of the element in the array. If the...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 993, "level": 1, "question": "Write a code that implements a linear search algorithm to find the first occurrence of a specified element in an array. The array and the element to be searched for should be provided as input. If the element is found, the code should return the index o...
def count_duos(words, k): from collections import defaultdict prefix_counts = defaultdict(int) for word in words: if len(word) >= k: prefix = word[:k] prefix_counts[prefix] += 1 total = 0 for count in prefix_counts.values(): if count >= 2: total +=...
simplelr_Leetcode
[ { "content": "Question:\nYou are given a list of strings `words` where each word consists of lowercase English letters. A **duo** in the list is a pair of words that share a common prefix of at least length `k`. Return _the number of unique duos in the list given the prefix length `k`_. If no such duo exists, r...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 994, "level": 1, "question": "You are given a list of strings `words` where each word consists of lowercase English letters. A **duo** in the list is a pair of words that share a common prefix of at least length `k`. Return _the number of unique duos in the list given the prefix len...
def maxEvents(events): # Sort events by their end day events.sort(key=lambda x: x[1]) last_day = -1 count = 0 for start, end in events: # Find the earliest possible day to attend this event day = max(start, last_day + 1) if day <= end: count += 1 last_...
simplelr_Leetcode
[ { "content": "Question:\nYou are given an array `events` where `events[i] = [startDayi, endDayi]` represents an event that starts at `startDayi` and ends at `endDayi`. You can attend an event `i` at any day between `startDayi` and `endDayi` (inclusive). Note that you can only attend one event per day. Find the ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 995, "level": 1, "question": "You are given an array `events` where `events[i] = [startDayi, endDayi]` represents an event that starts at `startDayi` and ends at `endDayi`. You can attend an event `i` at any day between `startDayi` and `endDayi` (inclusive). Note that you can only a...
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: low = mid + 1 else: high = mid - 1 return -1
simplelr_Prefill
[ { "content": "Question:\nWrite a function to binary search an array for a given element.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 996, "level": 1, "question": "Write a function to binary search an array for a given element.", "split": "train" }
def max_response_time_difference(response_times): if len(response_times) < 2: return 0 return max(response_times) - min(response_times)
simplelr_Codeforces
[ { "content": "Question:\nMonty wants to measure the effectiveness of his marketing campaign by analyzing customer response times. He has collected data where each entry represents the time (in minutes) a customer took to respond to his campaign. Monty wants to determine the maximum difference in response times ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 997, "level": 1, "question": "Monty wants to measure the effectiveness of his marketing campaign by analyzing customer response times. He has collected data where each entry represents the time (in minutes) a customer took to respond to his campaign. Monty wants to determine the max...
from typing import List def maximize_storage(bins: List[int], max_bins: int) -> int: # Check if max_bins is within the valid range if max_bins < 1 or max_bins > len(bins): raise ValueError("max_bins should be in the range of 1 to len(bins)") # Ensure all bin capacities are integers for cap...
simplelr_Algorithm
[ { "content": "Question:\n### Coding Assessment Question:\n\n#### Scenario:\nIn an effort to manage warehouse inventory efficiently, you need to implement a function that determines the maximum number of units that can be stored within a limited number of storage bins, given their varying sizes and unit capaciti...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 998, "level": 1, "question": "### Coding Assessment Question:\n\n#### Scenario:\nIn an effort to manage warehouse inventory efficiently, you need to implement a function that determines the maximum number of units that can be stored within a limited number of storage bins, given the...
def contains_lowercase(s): return any(c.islower() for c in s)
simplelr_Filter
[ { "content": "Question:\nWrite a Python function that checks if a string contains any lowercase letters from the alphabet. The function should return `True` if there is at least one lowercase letter, and `False` otherwise.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 999, "level": 1, "question": "Write a Python function that checks if a string contains any lowercase letters from the alphabet. The function should return `True` if there is at least one lowercase letter, and `False` otherwise.", "split": "train" }