target
stringlengths
29
3.65k
data_source
stringclasses
12 values
prompt
listlengths
1
1
ability
stringclasses
1 value
reward_model
dict
extra_info
dict
from typing import List def rotate_and_sum(matrix: List[List[int]]) -> int: return sum(num for row in matrix for num in row) if matrix else 0
simplelr_Algorithm
[ { "content": "Question:\n### Matrix Rotation and Sum Challenge\n\nYou are tasked with implementing a function to rotate a square matrix by 90 degrees clockwise and then calculate the sum of the elements of the rotated matrix.\n\n#### Task:\n\nImplement the following function:\n1. `rotate_and_sum(matrix: List[Li...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 300, "level": 1, "question": "### Matrix Rotation and Sum Challenge\n\nYou are tasked with implementing a function to rotate a square matrix by 90 degrees clockwise and then calculate the sum of the elements of the rotated matrix.\n\n#### Task:\n\nImplement the following function:\n...
from itertools import chain, combinations def generate_combinations(s): # Remove duplicate characters, maintaining their first occurrence order unique_chars = [] seen = set() for c in s: if c not in seen: unique_chars.append(c) seen.add(c) s = ''.join(unique_chars) ...
simplelr_Filter
[ { "content": "Question:\nGiven a string, write a function that generates all possible combinations of its characters. \n\nFor example, if the input string is \"abc\", the function should return all possible combinations of its characters, i.e., [\"a\", \"ab\", \"ac\", \"abc\", \"b\", \"bc\", \"c\"]. \n\nNote th...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 301, "level": 1, "question": "Given a string, write a function that generates all possible combinations of its characters. \n\nFor example, if the input string is \"abc\", the function should return all possible combinations of its characters, i.e., [\"a\", \"ab\", \"ac\", \"abc\", ...
def smallest_greater_than(num_list, threshold): filtered = [x for x in num_list if x > threshold] if not filtered: return None return min(filtered)
simplelr_Prefill
[ { "content": "Question:\nWrite a python function to find and return the smallest integer in the given list that is greater than a specified value.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 302, "level": 1, "question": "Write a python function to find and return the smallest integer in the given list that is greater than a specified value.", "split": "train" }
def sum_of_two_largest_numbers(arr): if len(arr) < 2: return 0 # Assuming the array has at least two elements as per problem constraints sorted_arr = sorted(arr, reverse=True) return sorted_arr[0] + sorted_arr[1]
simplelr_Prefill
[ { "content": "Question:\nCreate a function that returns the sum of the two largest numbers in a given array of integers.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 303, "level": 1, "question": "Create a function that returns the sum of the two largest numbers in a given array of integers.", "split": "train" }
def reverse_sequence(s): return ','.join(reversed(s.split(',')))
simplelr_Apps
[ { "content": "Question:\nYou are given a string containing a sequence of integers separated by commas (e.g., \"1,2,3,4,5\"). Your task is to implement a function that reverses the sequence of integers but does not reverse the integers themselves. The function should handle both positive and negative integers.\n...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 304, "level": 1, "question": "You are given a string containing a sequence of integers separated by commas (e.g., \"1,2,3,4,5\"). Your task is to implement a function that reverses the sequence of integers but does not reverse the integers themselves. The function should handle both...
def group_anagrams(strs): anagrams = {} for string in strs: key = "".join(sorted(string)) if key in anagrams: anagrams[key].append(string) else: anagrams[key] = [string] return list(anagrams.values())
simplelr_Filter
[ { "content": "Question:\n### Group Anagrams\n#### Problem Statement\nGiven a list of strings, group anagrams together.\n\n#### Examples\n\n* `[\"eat\", \"tea\", \"tan\", \"ate\", \"nat\", \"bat\"]` returns `[[\"eat\", \"tea\", \"ate\"], [\"tan\", \"nat\"], [\"bat\"]]`.\n* `[\"cat\", \"dog\", \"tac\", \"god\"]` ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 305, "level": 1, "question": "### Group Anagrams\n#### Problem Statement\nGiven a list of strings, group anagrams together.\n\n#### Examples\n\n* `[\"eat\", \"tea\", \"tan\", \"ate\", \"nat\", \"bat\"]` returns `[[\"eat\", \"tea\", \"ate\"], [\"tan\", \"nat\"], [\"bat\"]]`.\n* `[\"c...
import wave import struct def stereo_to_mono(input_wav: str, output_wav: str) -> None: """ Converts a stereo WAV file to a mono WAV file by averaging the left and right audio channels. :param input_wav: Path to the input stereo WAV file. :param output_wav: Path to output the mono WAV file. :return...
simplelr_Docs
[ { "content": "Question:\nYou are tasked with implementing a function to convert a stereo WAV file to mono. A mono WAV file has only one audio channel, while a stereo file has two. To achieve this, you need to average the left and right channel samples for each frame.\n\n### Function Signature\n```python\ndef st...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 306, "level": 1, "question": "You are tasked with implementing a function to convert a stereo WAV file to mono. A mono WAV file has only one audio channel, while a stereo file has two. To achieve this, you need to average the left and right channel samples for each frame.\n\n### Fun...
import wave def reverse_audio(input_file: str, output_file: str) -> None: with wave.open(input_file, 'rb') as input_wav: nchannels = input_wav.getnchannels() sampwidth = input_wav.getsampwidth() framerate = input_wav.getframerate() num_frames = input_wav.getnframes() data = ...
simplelr_Docs
[ { "content": "Question:\n### WAV File Processing Task\n\nYou are given two WAV files: an input file `input.wav` and an output file `output.wav`. Your task is to read the audio data from `input.wav`, apply a simple audio transformation, and write the transformed audio data to `output.wav`. The transformation to ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 307, "level": 1, "question": "### WAV File Processing Task\n\nYou are given two WAV files: an input file `input.wav` and an output file `output.wav`. Your task is to read the audio data from `input.wav`, apply a simple audio transformation, and write the transformed audio data to `o...
def third_largest(lst): if not lst: return [] unique = list(set(lst)) if len(unique) < 3: return max(unique) unique_sorted = sorted(unique, reverse=True) return unique_sorted[2]
simplelr_Prefill
[ { "content": "Question:\nCreate a function that takes a list of integers and return the third largest number in the list. If the list has less than 3 unique numbers, return the maximum number in the list. If the list is empty, return an empty list. Use Python to solve this problem.\nAnswer:\nLet's think step by...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 308, "level": 1, "question": "Create a function that takes a list of integers and return the third largest number in the list. If the list has less than 3 unique numbers, return the maximum number in the list. If the list is empty, return an empty list. Use Python to solve this prob...
from functools import lru_cache @lru_cache(None) def fib_recursive(n: int) -> int: """ Calculate the nth Fibonacci number recursively with memoization. The Fibonacci sequence is defined as: F(0) = 0, F(1) = 1 F(n) = F(n-1) + F(n-2) for n >= 2 Args: n: A non-negative integer represe...
simplelr_Algorithm
[ { "content": "Question:\n### Coding Assessment: Optimize Recursive Fibonacci Function\n\n#### Context\nThe Fibonacci sequence is used in various algorithmic problems and optimization tasks. A common implementation of the Fibonacci sequence uses recursion, which can be inefficient for larger input values due to ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 309, "level": 1, "question": "### Coding Assessment: Optimize Recursive Fibonacci Function\n\n#### Context\nThe Fibonacci sequence is used in various algorithmic problems and optimization tasks. A common implementation of the Fibonacci sequence uses recursion, which can be inefficie...
def total_memory_in_bytes(arr): return len(arr) * 4
simplelr_Filter
[ { "content": "Question:\nA 32-bit integer has 4 bytes. Suppose we are working with a computer system that allocates 4 bytes for each integer. Write a program that takes an array of integers as input and returns the total amount of memory (in bytes) that the array occupies in memory.\nAnswer:\nLet's think step b...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 310, "level": 1, "question": "A 32-bit integer has 4 bytes. Suppose we are working with a computer system that allocates 4 bytes for each integer. Write a program that takes an array of integers as input and returns the total amount of memory (in bytes) that the array occupies in me...
def is_palindrome(n): str_num = str(n) return str_num == str_num[::-1]
simplelr_Filter
[ { "content": "Question:\nWrite a python function to determine if a given integer is a palindrome. The function should return `True` if the integer is a palindrome, `False` otherwise.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 311, "level": 1, "question": "Write a python function to determine if a given integer is a palindrome. The function should return `True` if the integer is a palindrome, `False` otherwise.", "split": "train" }
def is_palindrome(s: str) -> bool: left = 0 right = len(s) - 1 while left < right: # Move left pointer to the next alnum character while left < right and not s[left].isalnum(): left += 1 # Move right pointer to the previous alnum character while left < right and n...
simplelr_Apps
[ { "content": "Question:\n## String Reversal and Palindrome Check\n\nYou are tasked with creating a function to check if a given string is a palindrome. A palindrome is a string that reads the same forwards and backwards, ignoring case, spaces, and punctuation.\n\nWrite a function `isPalindrome`/`IsPalindrome`/`...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 312, "level": 1, "question": "## String Reversal and Palindrome Check\n\nYou are tasked with creating a function to check if a given string is a palindrome. A palindrome is a string that reads the same forwards and backwards, ignoring case, spaces, and punctuation.\n\nWrite a functi...
def binary_search(arr, x): if not arr: return -1 mid = len(arr) // 2 if arr[mid] == x: return mid elif x > arr[mid]: result = binary_search(arr[mid + 1:], x) if result != -1: return mid + 1 + result else: return -1 else: return...
simplelr_Filter
[ { "content": "Question:\nHere is a recursive function in Python to find the value of a number in a sorted array using binary search:\n\n```python\ndef binary_search(arr, x):\n if not arr:\n return -1\n\n mid = len(arr) // 2\n if arr[mid] == x:\n return mid\n elif arr[mid] < x:\n ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 313, "level": 1, "question": "Here is a recursive function in Python to find the value of a number in a sorted array using binary search:\n\n```python\ndef binary_search(arr, x):\n if not arr:\n return -1\n\n mid = len(arr) // 2\n if arr[mid] == x:\n return mi...
from bs4 import BeautifulSoup def extract_text_from_html(file_path): try: # Open the HTML file with open(file_path, 'r', encoding='utf-8') as file: html_content = file.read() # Create a BeautifulSoup object and specify the parser soup = BeautifulSoup(html_conten...
simplelr_Filter
[ { "content": "Question:\nI have a large amount of HTML files that I need to process. Can you show me an example of how to read an HTML file and extract the text content using Python?\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 314, "level": 1, "question": "I have a large amount of HTML files that I need to process. Can you show me an example of how to read an HTML file and extract the text content using Python?", "split": "train" }
def difference(num1, num2): return num1 - num2
simplelr_Prefill
[ { "content": "Question:\nCreate a function that accepts two numbers as inputs and returns the difference between them.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 315, "level": 1, "question": "Create a function that accepts two numbers as inputs and returns the difference between them.", "split": "train" }
from typing import List def rotate_list(nums: List[int], k: int) -> List[int]: if not nums: return nums n = len(nums) effective_k = k % n return nums[-effective_k:] + nums[:-effective_k]
simplelr_Apps
[ { "content": "Question:\nYou have a list of integers and an integer `k`. Your task is to rotate the list to the right by `k` steps, where `k` is non-negative. The rotation means that the final elements of the array become the first elements of the array. \n\nWrite a function to perform this operation and return...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 316, "level": 1, "question": "You have a list of integers and an integer `k`. Your task is to rotate the list to the right by `k` steps, where `k` is non-negative. The rotation means that the final elements of the array become the first elements of the array. \n\nWrite a function to...
def find_smallest_missing(arr): n = len(arr) for i in range(n): while True: current = arr[i] if current < 1 or current > n: break if arr[current - 1] == current: break # Swap the current element with the element at index cur...
simplelr_Taco
[ { "content": "Question:\nGiven an array consisting of positive integers, your task is to determine the smallest positive integer that is not present in the array. The array may contain duplicates and is not necessarily sorted. The time complexity of your solution should be linear, and extra space complexity sho...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 317, "level": 1, "question": "Given an array consisting of positive integers, your task is to determine the smallest positive integer that is not present in the array. The array may contain duplicates and is not necessarily sorted. The time complexity of your solution should be line...
from typing import List import unicodedata def normalize_and_write_to_file(unicode_strings: List[str], file_path: str): with open(file_path, 'w', encoding='utf-8') as file: for u_str in unicode_strings: normalized_str = unicodedata.normalize('NFC', u_str) file.write(normalized_str +...
simplelr_Docs
[ { "content": "Question:\n## Coding Assessment Question\n\n### Title: Unicode Normalization and File Encoding Conversion\n\n### Objective:\nTo assess students' understanding of Unicode handling, normalization, and file operations in Python. The task requires implementing a function to normalize Unicode strings a...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 318, "level": 1, "question": "## Coding Assessment Question\n\n### Title: Unicode Normalization and File Encoding Conversion\n\n### Objective:\nTo assess students' understanding of Unicode handling, normalization, and file operations in Python. The task requires implementing a funct...
def find_row(input_array, target_string): for i, row in enumerate(input_array): if target_string in row: return i return -1
simplelr_Filter
[ { "content": "Question:\nI have an input that is a 2D array of binary strings and I need to return the row index of the first row that contains a specific binary string. If no such row exists, return -1.\n\nExample:\n```\n[\n [\"101\", \"110\", \"111\"],\n [\"000\", \"010\", \"101\"],\n [\"111\", \"101\", \"...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 319, "level": 1, "question": "I have an input that is a 2D array of binary strings and I need to return the row index of the first row that contains a specific binary string. If no such row exists, return -1.\n\nExample:\n```\n[\n [\"101\", \"110\", \"111\"],\n [\"000\", \"010\", ...
import zlib def compress_and_decompress(data1: bytes, data2: bytes) -> bytes: """ Compresses two binary data streams individually, concatenates them, then decompresses each to return the original concatenated data. Parameters: data1 (bytes): The first binary data stream. data2 (by...
simplelr_Docs
[ { "content": "Question:\nYou have been tasked to implement a function which takes two binary data streams and accurately compresses and decompresses them while maintaining their integrity. You will use Python's `zlib` module for this task. The function should demonstrate your understanding of:\n- Handling binar...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 320, "level": 1, "question": "You have been tasked to implement a function which takes two binary data streams and accurately compresses and decompresses them while maintaining their integrity. You will use Python's `zlib` module for this task. The function should demonstrate your u...
def compress_string(s): if not s: return "" result = [] current_char = s[0] count = 1 for char in s[1:]: if char == current_char: count += 1 else: if count == 1: result.append(current_char) else: result.appen...
simplelr_Taco
[ { "content": "Question:\nWrite a function **\"compress_string\"** that takes a string as input and returns a new string where consecutive duplicate characters are replaced with the character followed by the count of repetitions. If a character does not repeat, it should appear in the output string as it is.\n\n...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 321, "level": 1, "question": "Write a function **\"compress_string\"** that takes a string as input and returns a new string where consecutive duplicate characters are replaced with the character followed by the count of repetitions. If a character does not repeat, it should appear ...
def add_one_to_last_element(lst): if not lst: return [] new_list = lst.copy() new_list[-1] += 1 return new_list
simplelr_Prefill
[ { "content": "Question:\nWrite a function to add 1 to the last element of a list in Python. If the list is empty, the function should return an empty list.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 322, "level": 1, "question": "Write a function to add 1 to the last element of a list in Python. If the list is empty, the function should return an empty list.", "split": "train" }
def find_possible_sums(numbers: list[int]) -> set[int]: possible_sums = set() for num in numbers: temp = {num} for s in possible_sums: temp.add(s + num) possible_sums.update(temp) return possible_sums
simplelr_Algorithm
[ { "content": "Question:\n### Question: Find All Possible Sums in a List\n\nGiven a list of integers, find all possible unique sums that can be obtained by selecting one or more elements from the list.\n\n#### Function Signature\n```python\ndef find_possible_sums(numbers: list[int]) -> set[int]:\n pass\n```\n...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 323, "level": 1, "question": "### Question: Find All Possible Sums in a List\n\nGiven a list of integers, find all possible unique sums that can be obtained by selecting one or more elements from the list.\n\n#### Function Signature\n```python\ndef find_possible_sums(numbers: list[i...
def generate_employee_report(employees: list): position_data = {} for employee in employees: position = employee['Position'] salary = employee['Salary'] if position in position_data: position_data[position]['count'] += 1 position_data[position]['total'] += salary...
simplelr_Package
[ { "content": "Question:\nYou are tasked with creating a function that processes a list of dictionaries representing employee information. Each dictionary contains three keys: \"Name\", \"Position\", and \"Salary\". The goal is to perform two specific calculations and generate a formatted report based on the res...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 324, "level": 1, "question": "You are tasked with creating a function that processes a list of dictionaries representing employee information. Each dictionary contains three keys: \"Name\", \"Position\", and \"Salary\". The goal is to perform two specific calculations and generate a...
def find_substrings(s): substrings = [] n = len(s) for i in range(n + 1): substr = [] for j in range(i, n): substr.append(s[j]) substrings.append(''.join(substr)) return substrings input_string = "abc" print(find_substrings(input_string))
simplelr_Filter
[ { "content": "Question:\nYou have a string and you need to find all possible substrings of that string.\n\n2. Example:\n\n Input: \"abc\"\n Output: [\"\", \"a\", \"ab\", \"abc\", \"b\", \"bc\", \"c\"]\n\n3. Code (Python):\n\n ```python\n def find_substrings(s):\n substrings = []\n for i in r...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 325, "level": 1, "question": "You have a string and you need to find all possible substrings of that string.\n\n2. Example:\n\n Input: \"abc\"\n Output: [\"\", \"a\", \"ab\", \"abc\", \"b\", \"bc\", \"c\"]\n\n3. Code (Python):\n\n ```python\n def find_substrings(s):\n ...
def decodeString(s: str) -> str: stack = [] currentString = '' currentNumber = 0 for char in s: if char.isdigit(): currentNumber = currentNumber * 10 + int(char) elif char == '[': stack.append((currentString, currentNumber)) currentString = '' ...
simplelr_Leetcode
[ { "content": "Question:\nYou are tasked with developing a program that can decode a string with nested encoded patterns. The encoding rule is: `k[encoded_string]`, where the `encoded_string` inside the square brackets is being repeated exactly `k` times. You may assume that the input string is always valid; No ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 326, "level": 1, "question": "You are tasked with developing a program that can decode a string with nested encoded patterns. The encoding rule is: `k[encoded_string]`, where the `encoded_string` inside the square brackets is being repeated exactly `k` times. You may assume that the...
def is_rotation(s1, s2): if len(s1) != len(s2): return False if len(s1) == 0: return True return s2 in s1 + s1
simplelr_Filter
[ { "content": "Question:\nGiven two strings of equal length, write a function to check if one string is a rotation of the other. Your function should handle corner cases like empty strings and identical strings. Additionally, optimize your solution for time complexity.\nAnswer:\nLet's think step by step.\n", ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 327, "level": 1, "question": "Given two strings of equal length, write a function to check if one string is a rotation of the other. Your function should handle corner cases like empty strings and identical strings. Additionally, optimize your solution for time complexity.", "spli...
def length_of_shortest_word(sentence): words = sentence.split() lengths = [len(word) for word in words] return min(lengths)
simplelr_Apps
[ { "content": "Question:\nWrite a function that receives a string containing a sentence with words separated by spaces. The function should return the length of the shortest word in the sentence.\n\nExample:\nInput: \"The quick brown fox jumps over the lazy dog\"\nOutput: 3\nExplanation: The shortest words are \...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 328, "level": 1, "question": "Write a function that receives a string containing a sentence with words separated by spaces. The function should return the length of the shortest word in the sentence.\n\nExample:\nInput: \"The quick brown fox jumps over the lazy dog\"\nOutput: 3\nExp...
from typing import List def better_exchange_sort(arr: List[int]) -> List[int]: if not arr: return arr last_swap = len(arr) - 1 while True: swapped = False current_last_swap = 0 for j in range(last_swap): if arr[j] > arr[j + 1]: arr[j], arr[j + 1] ...
simplelr_Data_Structure
[ { "content": "Question:\nAs a junior data analyst, you are tasked with preparing a database for performance testing. Your dataset is a list of integer values that need to be sorted for easy readability.\n\n**Write a function `better_exchange_sort(arr)` that implements a more optimized exchange sort algorithm ap...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 329, "level": 1, "question": "As a junior data analyst, you are tasked with preparing a database for performance testing. Your dataset is a list of integer values that need to be sorted for easy readability.\n\n**Write a function `better_exchange_sort(arr)` that implements a more op...
def first_non_repeating_character(s): counts = {} for char in s: if char in counts: counts[char] += 1 else: counts[char] = 1 for char in s: if counts[char] == 1: return char return '_'
simplelr_Evol
[ { "content": "Question:\nWrite a function that takes a string as input and returns the first non-repeating character in the string. If there is no non-repeating character, return an underscore ('_'). Your solution should demonstrate efficient use of data structures to achieve optimal time complexity.\nAnswer:\n...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 330, "level": 1, "question": "Write a function that takes a string as input and returns the first non-repeating character in the string. If there is no non-repeating character, return an underscore ('_'). Your solution should demonstrate efficient use of data structures to achieve o...
def find_meeting_point(coordinates): if not coordinates: return (0, 0) x_coords = [coord[0] for coord in coordinates] y_coords = [coord[1] for coord in coordinates] x_coords.sort() y_coords.sort() mid_x = x_coords[len(x_coords) // 2] mid_y = y_coords[len(y_coords) // 2...
simplelr_Package
[ { "content": "Question:\n**Find Optimal Meeting Point on a Grid**\n\nYou are tasked with implementing a function to find the optimal meeting point on a grid for a group of people residing at different coordinates. The goal is to minimize the total travel distance for all individuals.\n\n### Problem Statement:\n...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 331, "level": 1, "question": "**Find Optimal Meeting Point on a Grid**\n\nYou are tasked with implementing a function to find the optimal meeting point on a grid for a group of people residing at different coordinates. The goal is to minimize the total travel distance for all indivi...
def product_except_self(nums): zero_count = nums.count(0) n = len(nums) if zero_count > 1: return [0] * n elif zero_count == 1: non_zero_product = 1 for num in nums: if num != 0: non_zero_product *= num result = [] for num in nums:...
simplelr_Filter
[ { "content": "Question:\nI have an array of integers and want to generate a new array where each element is the product of all numbers in the original array except for the number at that index.\n\nFor example, if the input is `[1, 2, 3, 4]`, the output should be `[24, 12, 8, 6]`.\n\nHere is the code I wrote:\n`...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 332, "level": 1, "question": "I have an array of integers and want to generate a new array where each element is the product of all numbers in the original array except for the number at that index.\n\nFor example, if the input is `[1, 2, 3, 4]`, the output should be `[24, 12, 8, 6]...
def max_subarray_sum(arr): if not arr: return 0 # Assuming the function should return 0 for an empty array max_ending_here = max_so_far = arr[0] for num in arr[1:]: max_ending_here = max(num, max_ending_here + num) max_so_far = max(max_so_far, max_ending_here) return max_so_far
simplelr_Prefill
[ { "content": "Question:\nCreate a function that takes an array of integers and returns the maximum sum of any contiguous subarray within this array. This subarray can contain a single element.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 333, "level": 1, "question": "Create a function that takes an array of integers and returns the maximum sum of any contiguous subarray within this array. This subarray can contain a single element.", "split": "train" }
import heapq def dijkstra_shortest_path(n, src, edges): # Initialize the distance array with infinity dist = [float('inf')] * n dist[src] = 0 # Build the adjacency list adj = [[] for _ in range(n)] for edge in edges: u, v, w = edge adj[u].append((v, w)) # Priority ...
simplelr_Algorithm
[ { "content": "Question:\n### Shortest Path in a Weighted Graph using Dijkstra's Algorithm\n\n#### Background:\nYou are tasked with writing a function to find the shortest path from a source node to all other nodes in a directed, weighted graph using Dijkstra's Algorithm. \n\n#### Task:\nImplement the function `...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 334, "level": 1, "question": "### Shortest Path in a Weighted Graph using Dijkstra's Algorithm\n\n#### Background:\nYou are tasked with writing a function to find the shortest path from a source node to all other nodes in a directed, weighted graph using Dijkstra's Algorithm. \n\n##...
import matplotlib.pyplot as plt def convert_and_plot_temperature(temperatures): # Convert Fahrenheit to Celsius celsius_temps = [(f - 32) * 5 / 9 for f in temperatures] # Create x values for plotting (indices) x = range(len(temperatures)) # Plot the Fahrenheit and Celsius temperatures ...
simplelr_Package
[ { "content": "Question:\nYou are tasked with creating a function, `convert_and_plot_temperature`, which will convert a list of temperatures from Fahrenheit to Celsius and then plot the original and converted temperatures using the `matplotlib` library. This problem is designed to help you understand basic list ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 335, "level": 1, "question": "You are tasked with creating a function, `convert_and_plot_temperature`, which will convert a list of temperatures from Fahrenheit to Celsius and then plot the original and converted temperatures using the `matplotlib` library. This problem is designed ...
def length_of_longest_substring(s: str) -> int: left = 0 max_len = 0 last_occurrence = {} for right in range(len(s)): char = s[right] if char in last_occurrence and last_occurrence[char] >= left: left = last_occurrence[char] + 1 last_occurrence[char] = right ...
simplelr_Apps
[ { "content": "Question:\nWrite a function that takes a string consisting of lowercase letters and returns the length of the longest substring with all unique characters.\n\nFor example:\n\n \"abcabcbb\" returns 3 (the longest substring is \"abc\")\n \"bbbbb\" returns 1 (the longest substring is \"b\")\n ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 336, "level": 1, "question": "Write a function that takes a string consisting of lowercase letters and returns the length of the longest substring with all unique characters.\n\nFor example:\n\n \"abcabcbb\" returns 3 (the longest substring is \"abc\")\n \"bbbbb\" returns 1 (t...
def create_dict(pair_list): new_dict = {} for pair in pair_list: new_dict[pair[0]] = pair[1] return new_dict
simplelr_Filter
[ { "content": "Question:\nHere's a problem I am struggling with:\n\nI am trying to create a method in Python that will create a dictionary from a list of lists where each sublist contains a key-value pair. In this case, the pair will always contain a string as the key and a list of one or more integers as the va...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 337, "level": 1, "question": "Here's a problem I am struggling with:\n\nI am trying to create a method in Python that will create a dictionary from a list of lists where each sublist contains a key-value pair. In this case, the pair will always contain a string as the key and a list...
def sum_array(arr): return sum(arr)
simplelr_Prefill
[ { "content": "Question:\nWrite a function to compute the sum of an array. The function should take an array of integers as input and return the sum of all the integers in the array. If the array is empty, the function should return 0.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 338, "level": 1, "question": "Write a function to compute the sum of an array. The function should take an array of integers as input and return the sum of all the integers in the array. If the array is empty, the function should return 0.", "split": "train" }
def find_unique_number(nums: list[int]) -> int: result = 0 for num in nums: result ^= num return result
simplelr_Algorithm
[ { "content": "Question:\n### Problem Statement\nYou are given a list of integers where each integer appears exactly twice, except for one integer which appears only once. Your task is to find the integer that appears only once. Implement a function `find_unique_number` that solves this problem efficiently.\n\n#...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 339, "level": 1, "question": "### Problem Statement\nYou are given a list of integers where each integer appears exactly twice, except for one integer which appears only once. Your task is to find the integer that appears only once. Implement a function `find_unique_number` that sol...
def sum_every_nth(start, end, n): total = 0 current = start while current <= end: total += current current += n return total
simplelr_Prefill
[ { "content": "Question:\nCreate a function that should output the sum of every nth number from a given start number to an end number, inclusive. For example, the sum of every 3rd number from 5 to 20 would be 54 (5 + 11 + 17 + 23). The function should return this sum.\nAnswer:\nLet's think step by step.\n", ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 340, "level": 1, "question": "Create a function that should output the sum of every nth number from a given start number to an end number, inclusive. For example, the sum of every 3rd number from 5 to 20 would be 54 (5 + 11 + 17 + 23). The function should return this sum.", "split...
import os def list_files(directory): try: # Using os.scandir() for better performance and to directly check if entry is a file with os.scandir(directory) as entries: files = [entry.name for entry in entries if entry.is_file()] return files except FileNotFoundError: ...
simplelr_Filter
[ { "content": "Question:\nCan you provide a Python example of how to list all files in a specific directory using the `os` module?\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 341, "level": 1, "question": "Can you provide a Python example of how to list all files in a specific directory using the `os` module?", "split": "train" }
from typing import List def generate_diamond(n: int) -> List[str]: center = n // 2 result = [] for i in range(n): distance = abs(i - center) stars_count = 1 + 2 * ((n // 2) - distance) row = ('*' * stars_count).center(n) result.append(row) return result
simplelr_Taco
[ { "content": "Question:\n## Task\n\nCreate a function to generate a series of strings representing a diamond shape, centered in a square grid. The size of the diamond is determined by an odd integer `n`, which is the length of one side of the grid.\n\nThe sides of the grid should be `n` characters long. The dia...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 342, "level": 1, "question": "## Task\n\nCreate a function to generate a series of strings representing a diamond shape, centered in a square grid. The size of the diamond is determined by an odd integer `n`, which is the length of one side of the grid.\n\nThe sides of the grid shou...
def calculate_overtime(hours): total = sum(hours) return max(0, total - 40)
simplelr_Taco
[ { "content": "Question:\nA company allows its employees to track and log how many hours they have worked throughout the week. The week is represented as an array of integers where each integer represents hours worked on a particular day: `[Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday]`. The co...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 343, "level": 1, "question": "A company allows its employees to track and log how many hours they have worked throughout the week. The week is represented as an array of integers where each integer represents hours worked on a particular day: `[Monday, Tuesday, Wednesday, Thursday, ...
def counting_sort(nums): if not nums: return [] min_val = min(nums) max_val = max(nums) range_val = max_val - min_val + 1 count = [0] * range_val for num in nums: idx = num - min_val count[idx] += 1 sorted_nums = [] for i in range(len(count)): ...
simplelr_Filter
[ { "content": "Question:\nWrite a function to sort a list of integers in O(n) time complexity.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 344, "level": 1, "question": "Write a function to sort a list of integers in O(n) time complexity.", "split": "train" }
def pigeonhole_sort(arr): if not arr: return [] min_val = min(arr) max_val = max(arr) range_size = max_val - min_val + 1 counts = [0] * range_size for num in arr: index = num - min_val counts[index] += 1 sorted_arr = [] for i in range(len(counts)): value =...
simplelr_Data_Structure
[ { "content": "Question:\n### Pigeonhole Sort Implementation\n\nYou are given an array of integers. Implement a function `pigeonhole_sort(arr)` that sorts the array using the Pigeonhole Sort algorithm. Ensure that your implementation includes checks to handle typical edge cases, and consider the constraints prov...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 345, "level": 1, "question": "### Pigeonhole Sort Implementation\n\nYou are given an array of integers. Implement a function `pigeonhole_sort(arr)` that sorts the array using the Pigeonhole Sort algorithm. Ensure that your implementation includes checks to handle typical edge cases,...
def remove_characters(s1, s2): exclude = set(s2) result = [] for char in s1: if char not in exclude: result.append(char) return ''.join(result)
simplelr_Filter
[ { "content": "Question:\nWrite a Python function that takes two strings as input and returns a new string with all characters from the second string removed from the first string.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 346, "level": 1, "question": "Write a Python function that takes two strings as input and returns a new string with all characters from the second string removed from the first string.", "split": "train" }
def group_by_first_char(strings): grouped = {} for s in strings: first_char = s[0] if first_char not in grouped: grouped[first_char] = [] grouped[first_char].append(s) return grouped
simplelr_Taco
[ { "content": "Question:\n> You are given a list of strings. Write a function that groups them by their first character and returns a dictionary where the keys are the first characters and the values are lists of strings that start with that character. The order of strings in the lists should be the same as thei...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 347, "level": 1, "question": "> You are given a list of strings. Write a function that groups them by their first character and returns a dictionary where the keys are the first characters and the values are lists of strings that start with that character. The order of strings in th...
import collections def shortest_path(grid): m = len(grid) if m == 0: return -1 n = len(grid[0]) # Check if start or end is blocked if grid[0][0] == -1 or grid[m-1][n-1] == -1: return -1 # If the grid is 1x1 if m == 1 and n == 1: return 0 visited = ...
simplelr_Taco
[ { "content": "Question:\nYou are given a rectangular grid of cells, each of which can be empty or contain an obstacle represented by -1. Your goal is to find the shortest path from the top-left cell (0,0) to the bottom-right cell (m-1, n-1) such that the path does not pass through obstacles. You can move to nei...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 348, "level": 1, "question": "You are given a rectangular grid of cells, each of which can be empty or contain an obstacle represented by -1. Your goal is to find the shortest path from the top-left cell (0,0) to the bottom-right cell (m-1, n-1) such that the path does not pass thro...
def add_numbers(num1, num2): return num1 + num2
simplelr_Filter
[ { "content": "Question:\nDefine a python function \"add_numbers( )\" that takes two numbers as input and returns their sum\n\n```python\n\ndef add_numbers():\n num1 = input(\"Enter first number: \")\n num2 = input(\"Enter second number: \")\n sum = int(num1) + int(num2)\n return sum\n```\n\n2. Expla...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 349, "level": 1, "question": "Define a python function \"add_numbers( )\" that takes two numbers as input and returns their sum\n\n```python\n\ndef add_numbers():\n num1 = input(\"Enter first number: \")\n num2 = input(\"Enter second number: \")\n sum = int(num1) + int(num2...
def factorial(n): if n == 0 or n == 1: return 1 else: return n * factorial(n - 1)
simplelr_Filter
[ { "content": "Question:\nWrite a Python code snippet to calculate the factorial of a number using recursion. Could you also provide a brief explanation of how recursion works in this context?\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 350, "level": 1, "question": "Write a Python code snippet to calculate the factorial of a number using recursion. Could you also provide a brief explanation of how recursion works in this context?", "split": "train" }
def longest_winning_streak(games): max_streak = 0 current = 0 for game in games: if game == 'W': current += 1 if current > max_streak: max_streak = current else: current = 0 return max_streak
simplelr_Apps
[ { "content": "Question:\n# Winning Streak\n\nYou are given a list representing a sequence of outcomes of games played by a team during a season. Each entry in the list is either 'W' for a win or 'L' for a loss. A winning streak is defined as a consecutive sequence of 'W' entries. Your task is to determine the l...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 351, "level": 1, "question": "# Winning Streak\n\nYou are given a list representing a sequence of outcomes of games played by a team during a season. Each entry in the list is either 'W' for a win or 'L' for a loss. A winning streak is defined as a consecutive sequence of 'W' entrie...
def to_title_case(s): return ' '.join(word.capitalize() for word in s.split())
simplelr_Filter
[ { "content": "Question:\nHow can I create a Python function that takes a string and returns a new string with all the words in title case?\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 352, "level": 1, "question": "How can I create a Python function that takes a string and returns a new string with all the words in title case?", "split": "train" }
def find_max(numbers): if not numbers: return None return max(numbers)
simplelr_Filter
[ { "content": "Question:\nI need to write a Python function that finds the maximum value in a list of integers. Can you provide an example of how to do this?\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 353, "level": 1, "question": "I need to write a Python function that finds the maximum value in a list of integers. Can you provide an example of how to do this?", "split": "train" }
def get_string_lengths(strings): """ Returns a new list containing the lengths of each string in the input list. Parameters: strings (list): A list of strings. Returns: list: A list of integers representing the lengths of each string. """ return [len(string) for string in strin...
simplelr_Filter
[ { "content": "Question:\nWrite a Python function that takes a list of strings and returns a new list containing the lengths of each string in the input list. Ensure that your function is well-documented and includes a brief description, parameters, and return type.\nAnswer:\nLet's think step by step.\n", "r...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 354, "level": 1, "question": "Write a Python function that takes a list of strings and returns a new list containing the lengths of each string in the input list. Ensure that your function is well-documented and includes a brief description, parameters, and return type.", "split":...
def rob(arr): if not arr: return 0 n = len(arr) if n == 1: return arr[0] if n == 2: return max(arr[0], arr[1]) prev2 = arr[0] prev1 = max(arr[0], arr[1]) for i in range(2, n): current = max(prev1, prev2 + arr[i]) prev2, prev1 = prev1, current retur...
simplelr_Leetcode
[ { "content": "Question:\nYou are given a list of non-negative integers `arr` representing the amount of money of each house in a row of houses. Each house has a certain amount of money stashed, and all houses are arranged in a straight line. The constraint is that you cannot rob two adjacent houses. Return the ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 355, "level": 1, "question": "You are given a list of non-negative integers `arr` representing the amount of money of each house in a row of houses. Each house has a certain amount of money stashed, and all houses are arranged in a straight line. The constraint is that you cannot ro...
def most_frequent_element(lst): if not lst: return None counts = {} first_occurrence = {} max_count = 0 result = None for index, num in enumerate(lst): if num not in counts: counts[num] = 1 first_occurrence[num] = index else: ...
simplelr_Filter
[ { "content": "Question:\nWrite a function in Python that finds the most frequent element in a list. If there are multiple elements with the same highest frequency, the function should return the one that appears first in the list. Additionally, ensure your solution is efficient in terms of time complexity. Prov...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 356, "level": 1, "question": "Write a function in Python that finds the most frequent element in a list. If there are multiple elements with the same highest frequency, the function should return the one that appears first in the list. Additionally, ensure your solution is efficient...
def maxSubsequenceSum(A, N): if N == 1: return A[0] prev_prev = A[0] prev = max(A[0], A[1]) for i in range(2, N): current = max(prev, prev_prev + A[i]) prev_prev, prev = prev, current return prev
simplelr_Taco
[ { "content": "Question:\nGiven an array A of N integers, return the maximum sum of a non-empty subsequence of A where no two elements are consecutive in the original array.\n\nExample 1:\nInput:\nA = [3, 2, 7, 10]\nOutput:\n13\nExplanation:\nThe subsequences with the highest sums are:\n(i) [3, 10] with sum 3 + ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 357, "level": 1, "question": "Given an array A of N integers, return the maximum sum of a non-empty subsequence of A where no two elements are consecutive in the original array.\n\nExample 1:\nInput:\nA = [3, 2, 7, 10]\nOutput:\n13\nExplanation:\nThe subsequences with the highest su...
import fnmatch def find_matching_strings(strings, pattern): """ Matches each string in the given list against the specified pattern. The pattern can contain wildcards: '?' matches any single character, and '*' matches any sequence of characters (including an empty sequence). The matching is case-se...
simplelr_Filter
[ { "content": "Question:\nGiven a list of strings, write a function in Python to find all strings in the list that match a given pattern. The pattern can contain wildcard characters, where '?' represents any single character and '*' represents any sequence of characters (including an empty sequence). The matchin...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 358, "level": 1, "question": "Given a list of strings, write a function in Python to find all strings in the list that match a given pattern. The pattern can contain wildcard characters, where '?' represents any single character and '*' represents any sequence of characters (includi...
def sum_of_squares(lst): return sum(num ** 2 for num in lst)
simplelr_Filter
[ { "content": "Question:\nWrite a Python function to calculate the sum of the squares of a list of integers. The function should be named `sum_of_squares` and should take a single parameter, which is a list of integers. It should return an integer representing the sum of the squares of the elements in the list. ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 359, "level": 1, "question": "Write a Python function to calculate the sum of the squares of a list of integers. The function should be named `sum_of_squares` and should take a single parameter, which is a list of integers. It should return an integer representing the sum of the squ...
import json def transform_json(json_data, key_mapping): """ Recursively transforms the keys of a nested JSON object based on a provided key mapping. Args: json_data (dict): The JSON data to be transformed. key_mapping (dict): A dictionary where keys are the original keys and values are...
simplelr_Filter
[ { "content": "Question:\nI have multiple JSON files which are similar in structure, but the keys change. For example, I have one file that looks like this:\n```json\n{\n \"name\": \"John Doe\",\n \"age\": 30,\n \"address\": {\n \"street\": \"123 Main St\",\n \"city\": \"New York\",\n \"state\": \"NY...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 360, "level": 1, "question": "I have multiple JSON files which are similar in structure, but the keys change. For example, I have one file that looks like this:\n```json\n{\n \"name\": \"John Doe\",\n \"age\": 30,\n \"address\": {\n \"street\": \"123 Main St\",\n \"city\": ...
import pandas as pd from typing import Tuple def highest_contributor(transactions: pd.DataFrame) -> Tuple[int, float]: # Group the transactions by user_id and sum the item_price for each user totals = transactions.groupby('user_id')['item_price'].sum() # Find the user with the highest total and their ...
simplelr_Algorithm
[ { "content": "Question:\n### Scenario\nYou are to ensure the financial integrity of transactions recorded for an e-commerce site. Each transaction log has attributes such as transaction identifier, user identifier, item price, and transaction date. The goal is to induce a hierarchy within these transactions bas...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 361, "level": 1, "question": "### Scenario\nYou are to ensure the financial integrity of transactions recorded for an e-commerce site. Each transaction log has attributes such as transaction identifier, user identifier, item price, and transaction date. The goal is to induce a hiera...
from typing import List def search_insert(array: List[int], val: int) -> int: low = 0 high = len(array) while low < high: mid = (low + high) // 2 if array[mid] < val: low = mid + 1 else: high = mid return low
simplelr_Data_Structure
[ { "content": "Question:\n### Scenario\n\nYou are working on an application that dynamically manages a leaderboard for an online game. The player scores are continuously updated, and the leaderboard must always remain in sorted order for efficient retrieval and display.\n\nIn this task, your primary job is to im...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 362, "level": 1, "question": "### Scenario\n\nYou are working on an application that dynamically manages a leaderboard for an online game. The player scores are continuously updated, and the leaderboard must always remain in sorted order for efficient retrieval and display.\n\nIn th...
def count_bubble_sort_swaps(arr): # Check if input is a list if not isinstance(arr, list): raise TypeError("Input must be a list") # Check if all elements are integers if not all(type(x) is int for x in arr): raise ValueError("All elements in the list must be integers") # Return 0 fo...
simplelr_Algorithm
[ { "content": "Question:\n### Context\nSorting algorithms are fundamental in computer science and software engineering. Various efficient algorithms like QuickSort, MergeSort, and HeapSort are commonly used to sort arrays or lists. One interesting aspect of sorting involves counting how many times elements are m...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 363, "level": 1, "question": "### Context\nSorting algorithms are fundamental in computer science and software engineering. Various efficient algorithms like QuickSort, MergeSort, and HeapSort are commonly used to sort arrays or lists. One interesting aspect of sorting involves coun...
def sort_and_dedupe_strings(strings): sorted_list = sorted(strings) unique_list = [] seen = set() for string in sorted_list: if string not in seen: unique_list.append(string) seen.add(string) return unique_list
simplelr_Filter
[ { "content": "Question:\nPlease write a code snippet in Python to sort a list of strings in ascending order and remove any duplicates. The original list should remain unchanged. The function should then return the new sorted, unique list.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 364, "level": 1, "question": "Please write a code snippet in Python to sort a list of strings in ascending order and remove any duplicates. The original list should remain unchanged. The function should then return the new sorted, unique list.", "split": "train" }
def extract_and_count(s): frequency_dict = {} for char in s: if char.isdigit() or char == '%': frequency_dict[char] = frequency_dict.get(char, 0) + 1 return frequency_dict
simplelr_Filter
[ { "content": "Question:\nCreate a Python function to extract digits and specific symbols (%) from a string, count the frequency of each symbol, and return the results in a dictionary. The function should ignore any other character that is not a digit or the specified symbol.\nAnswer:\nLet's think step by step.\...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 365, "level": 1, "question": "Create a Python function to extract digits and specific symbols (%) from a string, count the frequency of each symbol, and return the results in a dictionary. The function should ignore any other character that is not a digit or the specified symbol.", ...
def is_match(str_a: str, str_b: str) -> bool: n = len(str_a) m = len(str_b) # Create a DP table with (n+1) rows and (m+1) columns dp = [[False] * (m + 1) for _ in range(n + 1)] dp[0][0] = True for i in range(n + 1): for j in range(m + 1): if i == 0 and j == 0: ...
simplelr_Data_Structure
[ { "content": "Question:\n### Regular Expression Matching\n\n#### Problem Statement:\n\nImplement a function `bool is_match(const char *s, const char *p)` that determines if the input string `s` matches the pattern `p`. The pattern `p` may include:\n- `.` which matches any single character.\n- `*` which matches ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 366, "level": 1, "question": "### Regular Expression Matching\n\n#### Problem Statement:\n\nImplement a function `bool is_match(const char *s, const char *p)` that determines if the input string `s` matches the pattern `p`. The pattern `p` may include:\n- `.` which matches any singl...
def sort_pairs(pairs): return sorted(pairs, key=lambda x: (x[1], x[0])) # Example usage unsorted_list = [(5, 2), (3, 2), (1, 1), (4, 3)] sorted_list = sort_pairs(unsorted_list) print("Sorted List:", sorted_list)
simplelr_Filter
[ { "content": "Question:\nDevelop a software element that organizes a list of pairs (tuples) of integers in an ascending sequence based on the secondary constituent of each pair. Additionally, the function should be able to sort the pairs based on the primary constituent first when the elements in the pair are e...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 367, "level": 1, "question": "Develop a software element that organizes a list of pairs (tuples) of integers in an ascending sequence based on the secondary constituent of each pair. Additionally, the function should be able to sort the pairs based on the primary constituent first w...
def is_rotated(s1: str, s2: str) -> bool: if len(s1) != len(s2): return False if len(s1) == 0: return True return s2 in s1 + s1
simplelr_Data_Structure
[ { "content": "Question:\n### Scenario/Context\nYou are hired by a software company that develops a text editor with advanced search functionality. One of the features the company wants to implement is the ability to determine if one text snippet is a rotated version of another text snippet. This can be useful i...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 368, "level": 1, "question": "### Scenario/Context\nYou are hired by a software company that develops a text editor with advanced search functionality. One of the features the company wants to implement is the ability to determine if one text snippet is a rotated version of another ...
import re def is_valid_uuid(uuid): pattern = r'^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$' return bool(re.fullmatch(pattern, uuid))
simplelr_Prefill
[ { "content": "Question:\nCreate a function that checks if a given string is a valid UUID format. A UUID is a 36-character string in the format xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx. Here, x can be any hexadecimal digit (0-9, a-f, or A-F).\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 369, "level": 1, "question": "Create a function that checks if a given string is a valid UUID format. A UUID is a 36-character string in the format xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx. Here, x can be any hexadecimal digit (0-9, a-f, or A-F).", "split": "train" }
import re from collections import Counter from typing import List, Tuple def process_logs(logs: List[str]) -> Tuple[List[str], str]: error_logs = [] word_counts = [] pattern = r'^\[(.*?)\] \[(.*?)\] (.*)$' for log in logs: match = re.match(pattern, log) if match: level ...
simplelr_Taco
[ { "content": "Question:\nYou are tasked with developing a software tool that processes log messages generated by a system and identifies potential error cases. Each log message contains a timestamp, a log level, and a message.\n\nA log message is formatted as follows:\n```\n[YYYY-MM-DD HH:MM:SS] [LEVEL] Message...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 370, "level": 1, "question": "You are tasked with developing a software tool that processes log messages generated by a system and identifies potential error cases. Each log message contains a timestamp, a log level, and a message.\n\nA log message is formatted as follows:\n```\n[YY...
def sum_of_integers(lst): """ This function calculates the sum of integers in a given list. Args: lst (list): A list of integers. Returns: int: The sum of the integers in the list. Returns 0 if the list is empty. """ return sum(lst) # Test cases print(sum_of_integers([...
simplelr_Filter
[ { "content": "Question:\nWrite a function in Python that takes a list of integers as input and returns the sum of the integers. The function should also handle empty lists and return 0 in that case. Test the function with different lists of integers to ensure it works correctly.\nAnswer:\nLet's think step by st...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 371, "level": 1, "question": "Write a function in Python that takes a list of integers as input and returns the sum of the integers. The function should also handle empty lists and return 0 in that case. Test the function with different lists of integers to ensure it works correctly...
def map_titles_to_covers(books): book_dict = {} for title, url in books: book_dict[title] = url return book_dict
simplelr_Filter
[ { "content": "Question:\nPlease write a function in Python that takes a list of book titles and their cover images as URLs, and returns a dictionary where the keys are the book titles (as strings) and the values are the corresponding cover image URLs (as strings). If a title appears in the list more than once, ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 372, "level": 1, "question": "Please write a function in Python that takes a list of book titles and their cover images as URLs, and returns a dictionary where the keys are the book titles (as strings) and the values are the corresponding cover image URLs (as strings). If a title ap...
import math def sum_of_digits_in_factorial(n): fact = math.factorial(n) return sum(int(d) for d in str(fact))
simplelr_Prefill
[ { "content": "Question:\nWrite a python function to find the sum of the digits in the factorial of a given number `n`.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 373, "level": 1, "question": "Write a python function to find the sum of the digits in the factorial of a given number `n`.", "split": "train" }
from typing import List def find_median_sorted_arrays(nums1: List[int], nums2: List[int]) -> float: # Ensure that nums1 is the smaller array to minimize the binary search space if len(nums1) > len(nums2): nums1, nums2 = nums2, nums1 m = len(nums1) n = len(nums2) total = m + n low =...
simplelr_Algorithm
[ { "content": "Question:\n### Median of Two Sorted Arrays\n\n**Context**:\nIn data analysis and statistics, finding the median of a dataset is a common task. When the data is split between two separate, sorted arrays, it adds complexity to the operation, requiring efficient methods to find the median without com...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 374, "level": 1, "question": "### Median of Two Sorted Arrays\n\n**Context**:\nIn data analysis and statistics, finding the median of a dataset is a common task. When the data is split between two separate, sorted arrays, it adds complexity to the operation, requiring efficient meth...
def generate_missing_numbers(numbers): min_val = min(numbers) max_val = max(numbers) num_set = set(numbers) missing = [] for num in range(min_val, max_val + 1): if num not in num_set: missing.append(num) return missing
simplelr_Package
[ { "content": "Question:\nYour task is to write a Python function called `generate_missing_numbers` that finds all the missing numbers in a sequence of integers and returns them as a list. The function should work with a list of integers that may contain duplicates, and find the missing numbers in the range from...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 375, "level": 1, "question": "Your task is to write a Python function called `generate_missing_numbers` that finds all the missing numbers in a sequence of integers and returns them as a list. The function should work with a list of integers that may contain duplicates, and find the...
def character_frequency(s): counts = {} for char in s: counts[char] = counts.get(char, 0) + 1 return {char: count for char, count in counts.items() if count > 1}
simplelr_Filter
[ { "content": "Question:\nCreate a Python function that takes a string as input and returns a dictionary with the frequency of each character in the string. The dictionary should only include characters that appear more than once, and the characters should be case-sensitive. If no character repeats, return an em...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 376, "level": 1, "question": "Create a Python function that takes a string as input and returns a dictionary with the frequency of each character in the string. The dictionary should only include characters that appear more than once, and the characters should be case-sensitive. If ...
def sum_of_squares(n): total = 0 for i in range(1, n + 1, 2): total += i ** 2 return total
simplelr_Prefill
[ { "content": "Question:\nCreate a function that takes an integer as a parameter and returns the sum of the squares of all the odd numbers between 1 and the given integer (inclusive). The function should be named `sum_of_squares` and should not include any global variables or external dependencies.\nAnswer:\nLet...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 377, "level": 1, "question": "Create a function that takes an integer as a parameter and returns the sum of the squares of all the odd numbers between 1 and the given integer (inclusive). The function should be named `sum_of_squares` and should not include any global variables or ex...
def sum_two_numbers(a, b): """ This function calculates the sum of two numbers. Args: a (int or float): The first number to be added. b (int or float): The second number to be added. Returns: int or float: The sum of a and b. """ return a + b
simplelr_Prefill
[ { "content": "Question:\nWrite a python function to calculate the sum of two numbers and return the result. The function should be able to handle any two numbers provided as inputs.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 378, "level": 1, "question": "Write a python function to calculate the sum of two numbers and return the result. The function should be able to handle any two numbers provided as inputs.", "split": "train" }
from typing import List def polynomial_operations(polynomials: List[List[int]], operation: str) -> List[int]: if not polynomials: return [] max_len = max(len(p) for p in polynomials) result = [] if operation == "add": for i in range(max_len): total = 0 ...
simplelr_Algorithm
[ { "content": "Question:\n### Problem: Implementing a Simplified Polynomial Calculator\n\nYou are required to implement a function that takes a list of polynomials represented by their coefficients and performs operations such as addition and subtraction on them. Each polynomial is represented by a list where th...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 379, "level": 1, "question": "### Problem: Implementing a Simplified Polynomial Calculator\n\nYou are required to implement a function that takes a list of polynomials represented by their coefficients and performs operations such as addition and subtraction on them. Each polynomial...
def is_sum_zero(arr): return sum(arr) == 0
simplelr_Prefill
[ { "content": "Question:\nWrite a function to check if the sum of all elements in an array is零 (Case-sensitive: 返回True).\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 380, "level": 1, "question": "Write a function to check if the sum of all elements in an array is零 (Case-sensitive: 返回True).", "split": "train" }
import bisect from typing import List def longest_increasing_subsequence(arr: List[int]) -> int: tails = [] for num in arr: idx = bisect.bisect_left(tails, num) if idx == len(tails): tails.append(num) else: tails[idx] = num return len(tails)
simplelr_Algorithm
[ { "content": "Question:\n### Longest Increasing Subsequence\n\nYou are tasked with enhancing a data analysis tool to identify trends in numerical data. Specifically, you need to calculate the length of the longest increasing subsequence (LIS) within a given list of integers. This feature will help analyze the l...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 381, "level": 1, "question": "### Longest Increasing Subsequence\n\nYou are tasked with enhancing a data analysis tool to identify trends in numerical data. Specifically, you need to calculate the length of the longest increasing subsequence (LIS) within a given list of integers. Th...
def search_sorted_matrix(matrix, x): if not matrix or not matrix[0]: return False m = len(matrix) n = len(matrix[0]) i, j = 0, n - 1 while i < m and j >= 0: if matrix[i][j] == x: return True elif x < matrix[i][j]: j -= 1 else: i += ...
simplelr_Prefill
[ { "content": "Question:\nWrite a function to find a target integer `x` in a given 2D array `matrix`. The function should return `true` if the target is found, and `false` otherwise. The 2D array is sorted in a specific way: each row is sorted in ascending order, and each column is sorted in ascending order as w...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 382, "level": 1, "question": "Write a function to find a target integer `x` in a given 2D array `matrix`. The function should return `true` if the target is found, and `false` otherwise. The 2D array is sorted in a specific way: each row is sorted in ascending order, and each column...
def decodeString(s): stack = [] currentString = '' currentNum = 0 for c in s: if c.isdigit(): currentNum = currentNum * 10 + int(c) elif c == '[': stack.append((currentNum, currentString)) currentNum = 0 currentString = '' elif c ==...
simplelr_Leetcode
[ { "content": "Question:\nYou are given a string `s` representing an encoded string where repetitions of substrings are denoted by a positive integer followed by that substring, enclosed in square brackets. For example, the string \"3[a]2[bc]\" would be encoded as \"aaabcbc\". Write a function that decodes the s...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 383, "level": 1, "question": "You are given a string `s` representing an encoded string where repetitions of substrings are denoted by a positive integer followed by that substring, enclosed in square brackets. For example, the string \"3[a]2[bc]\" would be encoded as \"aaabcbc\". W...
def unique_elements_sorted_by_first_occurrence(arr): seen = set() unique_list = [] for num in arr: if num not in seen: seen.add(num) unique_list.append(num) return unique_list
simplelr_Leetcode
[ { "content": "Question:\nYou are given an array of integers `arr` where elements might appear more than once. Return an array of all the _unique elements_ in `arr` sorted in **ascending order** by their first occurrence in the original array. For example, given `arr = [4, 5, 6, 4, 1, 5, 1]`, the result should b...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 384, "level": 1, "question": "You are given an array of integers `arr` where elements might appear more than once. Return an array of all the _unique elements_ in `arr` sorted in **ascending order** by their first occurrence in the original array. For example, given `arr = [4, 5, 6,...
def count_primes(n): if n < 2: return 0 sieve = [True] * n sieve[0] = sieve[1] = False for i in range(2, int(n**0.5) + 1): if sieve[i]: for j in range(i*i, n, i): sieve[j] = False return sum(sieve) print(count_primes(10)) # Output: 4
simplelr_Filter
[ { "content": "Question:\ndef count_primes(n):\n if n < 2:\n return 0\n sieve = [True] * n\n sieve[0] = sieve[1] = False\n for i in range(2, int(n**0.5) + 1):\n if sieve[i]:\n for j in range(i*i, n, i):\n sieve[j] = False\n return sum(sieve)\n\nprint(count_p...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 385, "level": 1, "question": "def count_primes(n):\n if n < 2:\n return 0\n sieve = [True] * n\n sieve[0] = sieve[1] = False\n for i in range(2, int(n**0.5) + 1):\n if sieve[i]:\n for j in range(i*i, n, i):\n sieve[j] = False\n ...
def longest_substring_with_k_distinct_characters(S: str, K: int) -> int: if K == 0 or not S: return 0 counts = [0] * 26 left = 0 max_len = 0 distinct = 0 for right in range(len(S)): c = ord(S[right]) - ord('a') if counts[c] == 0: distinct += 1 ...
simplelr_Evol
[ { "content": "Question:\nDevise an algorithm for the following problem:\nYou are given a string S consisting of lowercase English letters, and an integer K. Your task is to determine the length of the longest substring of S that contains at most K distinct characters. Consider the case where the length of the s...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 386, "level": 1, "question": "Devise an algorithm for the following problem:\nYou are given a string S consisting of lowercase English letters, and an integer K. Your task is to determine the length of the longest substring of S that contains at most K distinct characters. Consider ...
import os def organize_files_by_directory(file_paths): dir_files = {} for path in file_paths: dir_part = os.path.dirname(path) file_name = os.path.basename(path) if file_name: # Ensure we only add non-empty file names if dir_part in dir_files: dir_files[dir_...
simplelr_Filter
[ { "content": "Question:\nI have a list of strings in Python where each string represents a file path, e.g., `['/data/ab/c.txt', '/data/bc/d.py', '/data/cd/e.sh']`. I want to create a Python function that takes this list of file paths and returns a dictionary where the keys are the unique directory paths (withou...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 387, "level": 1, "question": "I have a list of strings in Python where each string represents a file path, e.g., `['/data/ab/c.txt', '/data/bc/d.py', '/data/cd/e.sh']`. I want to create a Python function that takes this list of file paths and returns a dictionary where the keys are ...
def capitalize_words(s): return ' '.join(word.capitalize() for word in s.split())
simplelr_Prefill
[ { "content": "Question:\nWrite a python function to convert the first letter of each word in a given string to uppercase.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 388, "level": 1, "question": "Write a python function to convert the first letter of each word in a given string to uppercase.", "split": "train" }
def uniqueCharacters(n, s): seen = set() res = [] for c in s: seen.add(c) res.append(len(seen)) return res
simplelr_Taco
[ { "content": "Question:\nYou are given a string s of length n consisting only of lowercase English letters. For each index i, you have to determine the number of unique characters present in the substring of s starting from index 0 to index i (both inclusive).\n\nExample 1:\nInput:\nn = 5\ns = \"ababa\"\nOutput...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 389, "level": 1, "question": "You are given a string s of length n consisting only of lowercase English letters. For each index i, you have to determine the number of unique characters present in the substring of s starting from index 0 to index i (both inclusive).\n\nExample 1:\nIn...
def bubble_sort(lst): n = len(lst) for i in range(n): swapped = False for j in range(0, n - i - 1): if lst[j] > lst[j + 1]: lst[j], lst[j + 1] = lst[j + 1], lst[j] swapped = True if not swapped: break return lst
simplelr_Prefill
[ { "content": "Question:\nWrite a python function to implement a simple bubble sort algorithm on an unsorted list of integers and return the sorted list.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 390, "level": 1, "question": "Write a python function to implement a simple bubble sort algorithm on an unsorted list of integers and return the sorted list.", "split": "train" }
def remove_duplicates_sorted_array(nums: list[int]) -> int: if not nums: return 0 write_pointer = 0 for i in range(1, len(nums)): if nums[i] != nums[write_pointer]: write_pointer += 1 nums[write_pointer] = nums[i] return write_pointer + 1
simplelr_Package
[ { "content": "Question:\nYou are tasked with writing a function named `remove_duplicates_sorted_array(nums)` that removes duplicates from a sorted array in-place and returns the new length of the array. Each element should appear only once, and the relative order of the elements should be maintained.\n\nThe fun...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 391, "level": 1, "question": "You are tasked with writing a function named `remove_duplicates_sorted_array(nums)` that removes duplicates from a sorted array in-place and returns the new length of the array. Each element should appear only once, and the relative order of the element...
from typing import List def maxProfit(prices: List[int], n: int) -> int: if n < 2: return 0 # Though constraints say n >=2, handle just in case max_profit = 0 min_price = prices[0] for i in range(1, n): if prices[i] < min_price: min_price = prices[i] curre...
simplelr_Taco
[ { "content": "Question:\nGiven an array of integers where each element represents the price of a house on a certain day, determine the maximum possible profit that can be made by buying and selling the house on exactly two distinct days. You may buy the house once and sell it once, or you can choose not to enga...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 392, "level": 1, "question": "Given an array of integers where each element represents the price of a house on a certain day, determine the maximum possible profit that can be made by buying and selling the house on exactly two distinct days. You may buy the house once and sell it o...
def max_profit(prices): if len(prices) < 2: return 0 max_profit = 0 min_price = prices[0] for price in prices[1:]: current_profit = price - min_price if current_profit > max_profit: max_profit = current_profit if price < min_price: min_price = pric...
simplelr_Prefill
[ { "content": "Question:\nWrite a function to find the maximum profit that can be generated from a single buy and sell operation on a given list of stock prices. The list will contain the daily prices of a stock, with each index representing the day. For example, if the list is [7, 1, 5, 3, 6, 4], the maximum pr...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 393, "level": 1, "question": "Write a function to find the maximum profit that can be generated from a single buy and sell operation on a given list of stock prices. The list will contain the daily prices of a stock, with each index representing the day. For example, if the list is ...
def print_fibonacci(n): """Prints the first n numbers in the Fibonacci sequence.""" a, b = 0, 1 for _ in range(n): print(a) a, b = b, a + b
simplelr_Filter
[ { "content": "Question:\nThis is the task:\n\nCreate a Python code snippet for a function called `print_fibonacci` that takes one argument, `n`, and prints the first `n` numbers in the Fibonacci sequence.\n\nFor example, `print_fibonacci(5)` should print the following:\n\n```\n0\n1\n1\n2\n3\n```\n\n```python\nd...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 394, "level": 1, "question": "This is the task:\n\nCreate a Python code snippet for a function called `print_fibonacci` that takes one argument, `n`, and prints the first `n` numbers in the Fibonacci sequence.\n\nFor example, `print_fibonacci(5)` should print the following:\n\n```\n...
from typing import List, Optional def max_consecutive_sum(arr: List[int], k: int) -> Optional[int]: n = len(arr) if n < k: return None current_sum = sum(arr[:k]) max_sum = current_sum for i in range(k, n): current_sum += arr[i] - arr[i - k] if current_sum > max_sum: ...
simplelr_Code_Contests
[ { "content": "Question:\nWrite a function that takes a list of integers and an integer `k` as input and returns the maximum sum of `k` consecutive elements in the list. If the list contains fewer than `k` elements, return `None`.\n\n### Example Input\n\n```python\narr = [1, 2, 3, 4, 5]\nk = 3\n```\n\n### Exampl...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 395, "level": 1, "question": "Write a function that takes a list of integers and an integer `k` as input and returns the maximum sum of `k` consecutive elements in the list. If the list contains fewer than `k` elements, return `None`.\n\n### Example Input\n\n```python\narr = [1, 2, ...
def reverse_words(sentence): return ' '.join(sentence.split()[::-1])
simplelr_Prefill
[ { "content": "Question:\nWrite a function to reverse the order of words in a sentence, but keep the words' internal order intact.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 396, "level": 1, "question": "Write a function to reverse the order of words in a sentence, but keep the words' internal order intact.", "split": "train" }
def minDaysToClimb(N, H, P): P_sorted = sorted(P, reverse=True) prefix = [0] * (N + 1) for i in range(1, N + 1): prefix[i] = prefix[i - 1] + P_sorted[i - 1] left, right = 1, N answer = N + 1 # Indicates not found within N days while left <= right: mid = (left + right) // 2 ...
simplelr_Taco
[ { "content": "Question:\n## Problem Statement\nJohn is training for a mountain climbing competition. He needs to climb a certain total height, H meters, over N days, but due to varying weather conditions, the height he can climb each day is uncertain. Given an array P of length N where P[i] represents the maxim...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 397, "level": 1, "question": "## Problem Statement\nJohn is training for a mountain climbing competition. He needs to climb a certain total height, H meters, over N days, but due to varying weather conditions, the height he can climb each day is uncertain. Given an array P of length...
import heapq def min_meeting_rooms(meetings: list[tuple[int, int]]) -> int: meetings.sort() heap = [] max_rooms = 0 for start, end in meetings: if heap and start >= heap[0]: heapq.heappop(heap) heapq.heappush(heap, end) if len(heap) > max_rooms: max_rooms...
simplelr_Algorithm
[ { "content": "Question:\n### Coding Assessment Question\n\nYou are required to implement a function that calculates the minimum number of meeting rooms required to accommodate all meetings given their start and end times.\n\n### Requirements\n1. **Input**: A list of tuples, where each tuple consists of two inte...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 398, "level": 1, "question": "### Coding Assessment Question\n\nYou are required to implement a function that calculates the minimum number of meeting rooms required to accommodate all meetings given their start and end times.\n\n### Requirements\n1. **Input**: A list of tuples, whe...
import json def generate_summary_report(filename): with open(filename, 'r') as f: data = json.load(f) summary = {} for user in data: user_id = user['user_id'] tasks = user['tasks'] total_tasks = len(tasks) completed_tasks = 0 for task in tasks: if...
simplelr_Evol
[ { "content": "Question:\nWrite a Python function that reads a JSON file containing a list of users and their respective tasks. Each user has a unique ID and an associated list of tasks with attributes like task ID, description, and status (completed or pending). The function should generate a summary report det...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 399, "level": 1, "question": "Write a Python function that reads a JSON file containing a list of users and their respective tasks. Each user has a unique ID and an associated list of tasks with attributes like task ID, description, and status (completed or pending). The function sh...