target
stringlengths
29
3.65k
data_source
stringclasses
12 values
prompt
listlengths
1
1
ability
stringclasses
1 value
reward_model
dict
extra_info
dict
import math def generate_primes(n): if n < 2: return [] sieve = [True] * (n + 1) sieve[0] = sieve[1] = False for p in range(2, int(math.sqrt(n)) + 1): if sieve[p]: for multiple in range(p * p, n + 1, p): sieve[multiple] = False primes = [i for i, is_prime...
simplelr_Prefill
[ { "content": "Question:\nCreate a function that generates a list of prime numbers up to a given number. For instance, if the input is 10, the output should be [2, 3, 5, 7]. If the input is 15, the output should be [2, 3, 5, 7, 11, 13].\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8100, "level": 1, "question": "Create a function that generates a list of prime numbers up to a given number. For instance, if the input is 10, the output should be [2, 3, 5, 7]. If the input is 15, the output should be [2, 3, 5, 7, 11, 13].", "split": "train" }
def find_intervals_to_remove(intervals): if not intervals: return [] # Sort intervals by their end times sorted_intervals = sorted(intervals, key=lambda x: x[1]) removed = [] last_end = -float('inf') for interval in sorted_intervals: start, end = interval if sta...
simplelr_Filter
[ { "content": "Question:\nWrite a Python function to find the non-overlapping intervals that need to be removed to make the rest of the intervals non-overlapping. The function should return a list of lists, where each sublist contains the start and end indices of the intervals to be removed.\nAnswer:\nLet's thin...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8101, "level": 1, "question": "Write a Python function to find the non-overlapping intervals that need to be removed to make the rest of the intervals non-overlapping. The function should return a list of lists, where each sublist contains the start and end indices of the intervals ...
def is_fibonacci_subsequence(arr: list[int]) -> bool: if not arr: return True # Check for negative numbers for num in arr: if num < 0: raise ValueError("Elements in the input list must be non-negative") max_elem = max(arr) # Generate the Fibonacci list up t...
simplelr_Algorithm
[ { "content": "Question:\n### Fibonacci Subsequence Checker\n\n#### Context\nFibonacci sequences are well-known in computational contexts due to their recursive definition and interesting properties. The Fibonacci sequence starts with 0 and 1, and each subsequent number is the sum of the previous two. Given the ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8102, "level": 1, "question": "### Fibonacci Subsequence Checker\n\n#### Context\nFibonacci sequences are well-known in computational contexts due to their recursive definition and interesting properties. The Fibonacci sequence starts with 0 and 1, and each subsequent number is the ...
def reverse_integer(x): if x == 0: return 0 sign = 1 if x < 0: sign = -1 abs_x = abs(x) s = str(abs_x) reversed_s = s[::-1] reversed_num = int(reversed_s) result = reversed_num * sign if result < -2**31 or result > 2**31 - 1: return 0 return result
simplelr_Filter
[ { "content": "Question:\nWrite a Python function that reverses the digits of a given integer. If the reversed integer exceeds the 32-bit signed integer range, the function should return 0. The function should handle both positive and negative integers.\nAnswer:\nLet's think step by step.\n", "role": "user" ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8103, "level": 1, "question": "Write a Python function that reverses the digits of a given integer. If the reversed integer exceeds the 32-bit signed integer range, the function should return 0. The function should handle both positive and negative integers.", "split": "train" }
def merge_alternately(word1, word2): result = [] max_len = max(len(word1), len(word2)) for i in range(max_len): if i < len(word1): result.append(word1[i]) if i < len(word2): result.append(word2[i]) return ''.join(result)
simplelr_Leetcode
[ { "content": "Question:\nYou are given two strings `word1` and `word2`. You want to construct a string `result` by merging these two strings such that:\n - `result` alternates characters from `word1` and `word2`, starting with `word1`.\n - If a string is longer than the other, append the remaining character...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8104, "level": 1, "question": "You are given two strings `word1` and `word2`. You want to construct a string `result` by merging these two strings such that:\n - `result` alternates characters from `word1` and `word2`, starting with `word1`.\n - If a string is longer than the ot...
import re def extract_temperature(s): pattern = r'(-?\d+\.?\d*|\.\d+)([CF])' match = re.search(pattern, s) return match.group(0) if match else None
simplelr_Filter
[ { "content": "Question:\nWrite a Python function `extract_temperature` that takes a string as input and returns the first occurrence of a temperature value in the string. The temperature should be a floating-point number followed by either \"C\" for Celsius or \"F\" for Fahrenheit. If no temperature is found, t...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8105, "level": 1, "question": "Write a Python function `extract_temperature` that takes a string as input and returns the first occurrence of a temperature value in the string. The temperature should be a floating-point number followed by either \"C\" for Celsius or \"F\" for Fahren...
from collections import deque def shortest_path(graph, start, end): if start == end: return 0 if start not in graph or end not in graph: return -1 visited = set() queue = deque() queue.append((start, 0)) visited.add(start) while queue: current, distance = q...
simplelr_Algorithm
[ { "content": "Question:\n### Context\nIn a social network graph, users are represented as nodes, and friendships between them are represented as edges. Given such a graph, we want to determine the shortest path between two users. The shortest path is the minimum number of edges required to travel from one user ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8106, "level": 1, "question": "### Context\nIn a social network graph, users are represented as nodes, and friendships between them are represented as edges. Given such a graph, we want to determine the shortest path between two users. The shortest path is the minimum number of edge...
def can_split_equal_sum(nums): total = sum(nums) if total % 2 != 0: return False target = total // 2 current_sum = 0 for i in range(len(nums)): current_sum += nums[i] if current_sum == target and i != len(nums) - 1: return True return False
simplelr_Leetcode
[ { "content": "Question:\nGiven a list of `n` integers, determine if you can split the list into two non-empty sublists such that the sum of the integers in each sublist is equal. If it is possible, return `True`; otherwise, return `False`. Note that the order of elements cannot be changed and each element must ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8107, "level": 1, "question": "Given a list of `n` integers, determine if you can split the list into two non-empty sublists such that the sum of the integers in each sublist is equal. If it is possible, return `True`; otherwise, return `False`. Note that the order of elements canno...
def next_power_of_two(value: int) -> int: if value == 0: return 1 if (value & (value - 1)) == 0: return value return 1 << (value.bit_length())
simplelr_Package
[ { "content": "Question:\nYour task is to write a function called `next_power_of_two` that finds the smallest power of two greater than or equal to a given non-negative integer. \n\n### Requirements:\n1. **Function Signature**: \n ```python\n def next_power_of_two(value: int) -> int\n ```\n\n2. **Input**:\...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8108, "level": 1, "question": "Your task is to write a function called `next_power_of_two` that finds the smallest power of two greater than or equal to a given non-negative integer. \n\n### Requirements:\n1. **Function Signature**: \n ```python\n def next_power_of_two(value: in...
def distribute_water_bottles(total_bottles, checkpoints): if checkpoints == 0: return "We need more checkpoints!" if total_bottles == 0: return [0] * checkpoints base = total_bottles // checkpoints remainder = total_bottles % checkpoints result = [] for _ in range(remainder): ...
simplelr_Taco
[ { "content": "Question:\nYou are organizing a marathon event and need to distribute water bottles to different checkpoints evenly. Some checkpoints may have more water bottles than others if they cannot be divided perfectly.\n\nWrite a function `distribute_water_bottles(total_bottles, checkpoints)` that takes i...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8109, "level": 1, "question": "You are organizing a marathon event and need to distribute water bottles to different checkpoints evenly. Some checkpoints may have more water bottles than others if they cannot be divided perfectly.\n\nWrite a function `distribute_water_bottles(total_...
from typing import List, Union def advanced_fizzbuzz(n: int) -> List[Union[int, str]]: result = [] for i in range(1, n + 1): if i % 105 == 0: result.append("FizzBuzzBazz") elif i % 15 == 0: result.append("FizzBuzz") elif i % 21 == 0: result.append("Fi...
simplelr_Data_Structure
[ { "content": "Question:\n### Coding Challenge: Advanced FizzBuzz Variations\n\n#### Description\nWrite a function called `advanced_fizzbuzz()` that generates a list of numbers from 1 to N inclusive with the following replacements:\n- If a number is divisible by 3, 5, and 7 simultaneously, replace it with \"Fizz...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8110, "level": 1, "question": "### Coding Challenge: Advanced FizzBuzz Variations\n\n#### Description\nWrite a function called `advanced_fizzbuzz()` that generates a list of numbers from 1 to N inclusive with the following replacements:\n- If a number is divisible by 3, 5, and 7 sim...
def most_frequent_characters(s): if not s: return [] char_count = {} for char in s: char_count[char] = char_count.get(char, 0) + 1 max_count = max(char_count.values()) most_frequent = [(char, count) for char, count in char_count.items() if count == max_count] return most_frequent
simplelr_Prefill
[ { "content": "Question:\nWrite a python function to find the most frequent character(s) in a given string. The function should return the character(s) that appear the most times and the corresponding counts. If there are multiple characters with the same highest frequency, include all of them in the output.\nAn...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8111, "level": 1, "question": "Write a python function to find the most frequent character(s) in a given string. The function should return the character(s) that appear the most times and the corresponding counts. If there are multiple characters with the same highest frequency, inc...
def sum_of_even_numbers(*args): sum_even = 0 for num in args: if num % 2 == 0: sum_even += num return sum_even
simplelr_Prefill
[ { "content": "Question:\nCreate a function that takes any number of integer arguments and returns the sum of all the even numbers among them.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8112, "level": 1, "question": "Create a function that takes any number of integer arguments and returns the sum of all the even numbers among them.", "split": "train" }
def min_lanterns(n: int, m: int) -> int: return (n + 2 * m) // (2 * m + 1)
simplelr_Codeforces
[ { "content": "Question:\nThe mayor of a small town has decided to organize a lantern festival. In the town, there is a main street represented as a straight line with n positions (numbered from 1 to n). A lantern can be placed at any position along this line.\n\nEach lantern can illuminate a certain number of p...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8113, "level": 1, "question": "The mayor of a small town has decided to organize a lantern festival. In the town, there is a main street represented as a straight line with n positions (numbered from 1 to n). A lantern can be placed at any position along this line.\n\nEach lantern c...
def calculate_checksum(numbers): checksum = 0 for index, num in enumerate(numbers): if index % 2 == 0: checksum += num else: checksum -= num return checksum
simplelr_Apps
[ { "content": "Question:\nWrite a function `calculate_checksum` that takes an array of integers `numbers` as input. The array can contain any non-negative integers. The function should compute and return a checksum by summing all the integers at even indices and subtracting the sum of all the integers at odd ind...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8114, "level": 1, "question": "Write a function `calculate_checksum` that takes an array of integers `numbers` as input. The array can contain any non-negative integers. The function should compute and return a checksum by summing all the integers at even indices and subtracting the...
def singleNumber(nums): res = 0 for num in nums: res ^= num return res
simplelr_Taco
[ { "content": "Question:\nGiven an integer array nums[] of size N, find the single element that appears only once in the array. All other elements appear exactly twice. Your solution should have a linear runtime complexity and use only constant extra space.\n\nExample 1:\nInput: N = 5, nums[] = {4, 1, 2, 1, 2}\n...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8115, "level": 1, "question": "Given an integer array nums[] of size N, find the single element that appears only once in the array. All other elements appear exactly twice. Your solution should have a linear runtime complexity and use only constant extra space.\n\nExample 1:\nInput...
def find_unique_elements(input_list): if not isinstance(input_list, list): raise TypeError("Input must be a list") if len(input_list) == 0: return [] seen = set() unique_list = [] for element in input_list: if element not in seen: unique_list.append(element) ...
simplelr_Filter
[ { "content": "Question:\n### Code Completion\nGiven the following code:\n```\ndef find_unique_elements(input_list):\n if not isinstance(input_list, list):\n raise TypeError(\"Input must be a list\")\n if len(input_list) == 0:\n return []\n # Complete the code here\n```\n\nThe task is to r...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8116, "level": 1, "question": "### Code Completion\nGiven the following code:\n```\ndef find_unique_elements(input_list):\n if not isinstance(input_list, list):\n raise TypeError(\"Input must be a list\")\n if len(input_list) == 0:\n return []\n # Complete the...
from typing import List, Dict, Union def average_reputation(media: List[Dict[str, Union[str, int, float]]]) -> Dict[str, Union[float, List[Dict[str, Union[str, int, float]]]]]: valid_scores = [] errors = [] for item in media: score = item['score'] if isinstance(score, (int, float)) and...
simplelr_Algorithm
[ { "content": "Question:\n### Reputable Media Content Tracker\n\n#### Context\nYou work for a start-up that helps users track reputations of their favorite media content such as movies, video games, and books. Your task is to create a utility function that accepts a list of media content details and computes the...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8117, "level": 1, "question": "### Reputable Media Content Tracker\n\n#### Context\nYou work for a start-up that helps users track reputations of their favorite media content such as movies, video games, and books. Your task is to create a utility function that accepts a list of med...
from collections import Counter def uniqueElements(arr): counts = Counter(arr) unique = [k for k, v in counts.items() if v == 1] unique.sort() return unique
simplelr_Taco
[ { "content": "Question:\n# Definition\n\nAn **_element is unique_** *if it is present only once in the array*.\n____\n\n# Task\n\n**_Given_** an *array/list [] of integers* , **_find_** *the unique element(s) in the array and return them in ascending order*.\n___\n\n# Notes \n\n* **_Array/list_** size is *at le...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8118, "level": 1, "question": "# Definition\n\nAn **_element is unique_** *if it is present only once in the array*.\n____\n\n# Task\n\n**_Given_** an *array/list [] of integers* , **_find_** *the unique element(s) in the array and return them in ascending order*.\n___\n\n# Notes \n...
def find_common_elements(lists): if not lists: return [] for sublist in lists: if not sublist: return [] result = lists[0] for sublist in lists[1:]: i = j = 0 temp = [] while i < len(result) and j < len(sublist): if result[i] == sublist[j]:...
simplelr_Package
[ { "content": "Question:\nYou are tasked with creating a function named `find_common_elements` that will identify common elements from multiple lists of integers. Each list is sorted in ascending order. The function should return a list of integers that are present in all the input lists.\n\n**Task:**\n1. Implem...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8119, "level": 1, "question": "You are tasked with creating a function named `find_common_elements` that will identify common elements from multiple lists of integers. Each list is sorted in ascending order. The function should return a list of integers that are present in all the i...
import string def find_shortest_word_length(s): if not s: return 0 punctuation = string.punctuation words = s.split() valid_words = [] for word in words: stripped = word.strip(punctuation) if stripped: valid_words.append(stripped) if not valid_words: ...
simplelr_Evol
[ { "content": "Question:\nWrite a function that takes a string consisting of multiple sentences and returns the length of the shortest word in the entire string. The words are separated by spaces, and the sentences are separated by periods. You should handle cases where punctuation marks such as commas or exclam...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8120, "level": 1, "question": "Write a function that takes a string consisting of multiple sentences and returns the length of the shortest word in the entire string. The words are separated by spaces, and the sentences are separated by periods. You should handle cases where punctua...
def count_distinct_prime_factors(n): if n < 2: return 0 factors = set() i = 2 while i * i <= n: while n % i == 0: factors.add(i) n = n // i i += 1 if n > 1: factors.add(n) return len(factors)
simplelr_Filter
[ { "content": "Question:\nI want to create a Python function that takes a single integer as input and returns the number of distinct prime factors of that integer. For example, the number 12 has two distinct prime factors: 2 and 3. How can I implement this function?\nAnswer:\nLet's think step by step.\n", "r...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8121, "level": 1, "question": "I want to create a Python function that takes a single integer as input and returns the number of distinct prime factors of that integer. For example, the number 12 has two distinct prime factors: 2 and 3. How can I implement this function?", "split"...
def convert_binary_to_decimal(binary_str: str) -> int: if binary_str is None: return -1 stripped = binary_str.strip() if not stripped: return -1 for c in stripped: if c not in ('0', '1'): return -1 decimal = 0 for c in stripped: decimal = decimal * 2 +...
simplelr_Algorithm
[ { "content": "Question:\n### Introduction\nBinary numbers can be converted into their decimal form and vice versa. This process involves understanding and applying the base-2 and base-10 numerical systems.\n\n### Task\nWrite a function named `convert_binary_to_decimal(binary_str: str) -> int` that converts a bi...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8122, "level": 1, "question": "### Introduction\nBinary numbers can be converted into their decimal form and vice versa. This process involves understanding and applying the base-2 and base-10 numerical systems.\n\n### Task\nWrite a function named `convert_binary_to_decimal(binary_s...
def find_nth_in_series(n): if n == 1: return 1 s = n - 1 m = s // 2 r = s % 2 total = 1 + (m * 5) + (r * 2) return total
simplelr_Apps
[ { "content": "Question:\nWrite a function that accepts an integer `n` and returns the `n`-th number in the series where the series is constructed as follows: \n\n- Start with the number 1.\n- Alternate between adding 2 and 3 to the previous number in the series.\n\nFor example:\n- The 1st number in the series i...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8123, "level": 1, "question": "Write a function that accepts an integer `n` and returns the `n`-th number in the series where the series is constructed as follows: \n\n- Start with the number 1.\n- Alternate between adding 2 and 3 to the previous number in the series.\n\nFor example...
def second_largest(nums): unique_nums = list(set(nums)) if len(unique_nums) < 2: return "No second largest number" sorted_unique = sorted(unique_nums, reverse=True) return sorted_unique[1]
simplelr_Evol
[ { "content": "Question:\nWrite a function to find the second largest number in a given list of integers. Your function should handle both positive and negative numbers and return appropriate output if there isn't a second largest number (e.g., if the list has fewer than two unique numbers).\n\nExamples:\n- Inpu...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8124, "level": 1, "question": "Write a function to find the second largest number in a given list of integers. Your function should handle both positive and negative numbers and return appropriate output if there isn't a second largest number (e.g., if the list has fewer than two un...
def reverse_string(s): chars = list(s) i = 0 j = len(chars) - 1 while i < j: # Swap characters at positions i and j chars[i], chars[j] = chars[j], chars[i] i += 1 j -= 1 return ''.join(chars)
simplelr_Filter
[ { "content": "Question:\nHey, can you help me with a Python code snippet to reverse a string without using the built-in reverse function or slicing?\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8125, "level": 1, "question": "Hey, can you help me with a Python code snippet to reverse a string without using the built-in reverse function or slicing?", "split": "train" }
import os def rename_files_with_prefix(directory='.', prefix='archive_'): """ Renames all files in the specified directory by adding the given prefix. Skips files that already start with the prefix to avoid duplication. """ for entry in os.scandir(directory): if entry.is_file(): ...
simplelr_Filter
[ { "content": "Question:\nCan you help me with a Python script that renames files in a directory based on a specific pattern? I want to add a prefix to all the files in a directory, and also ensure that if the prefix already exists, it doesn't get added again. For example, if the prefix is \"archive_\", a file n...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8126, "level": 1, "question": "Can you help me with a Python script that renames files in a directory based on a specific pattern? I want to add a prefix to all the files in a directory, and also ensure that if the prefix already exists, it doesn't get added again. For example, if t...
def deep_copy_list(input_list): copied_list = [] for item in input_list: if isinstance(item, list): copied_list.append(deep_copy_list(item)) else: copied_list.append(item) return copied_list
simplelr_Filter
[ { "content": "Question:\nWrite a Python function `deep_copy_list` that performs a deep copy of a given list, handling nested lists as well. The function should not use the `copy` module's `deepcopy` method. Instead, it should recursively copy each element of the list, ensuring that modifications to the copied l...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8127, "level": 1, "question": "Write a Python function `deep_copy_list` that performs a deep copy of a given list, handling nested lists as well. The function should not use the `copy` module's `deepcopy` method. Instead, it should recursively copy each element of the list, ensuring...
def find_non_repeated(s: str) -> str: if not s: return None char_count = {} for char in s: char_count[char] = char_count.get(char, 0) + 1 for char in s: if char_count[char] == 1: return char return None
simplelr_Package
[ { "content": "Question:\nYou are required to write a function called `find_non_repeated` that takes a single string input and returns the first non-repeated character in the string. A non-repeated character is a character that appears only once in the string. If all characters are repeated or the string is empt...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8128, "level": 1, "question": "You are required to write a function called `find_non_repeated` that takes a single string input and returns the first non-repeated character in the string. A non-repeated character is a character that appears only once in the string. If all characters...
import matplotlib.pyplot as plt def plot_avg_word_length(filename): """ Reads a text file, computes the average word length per sentence, and saves a bar chart of the results. Parameters: filename (str): The name of the text file to read. Returns: None """ with open(filename, 'r')...
simplelr_Package
[ { "content": "Question:\nYou are asked to create a function that reads a text file containing multiple sentences and computes the average word length for each sentence. The function should then plot and save a bar chart displaying the average word length for each sentence using Matplotlib.\n\nThe function `plot...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8129, "level": 1, "question": "You are asked to create a function that reads a text file containing multiple sentences and computes the average word length for each sentence. The function should then plot and save a bar chart displaying the average word length for each sentence usin...
import numpy as np import matplotlib.pyplot as plt def generate_mask_image(size, cell_coords, grid_divisions=8): """ Generate a mask image where specified cells are highlighted. Args: size (int): The size of the square image (size x size). cell_coords (list of tuples): List of (row, column...
simplelr_Filter
[ { "content": "Question:\nI have an encoding aerial view image of traffic. The image is divided into grid cells. Each cell has a unique id number. I want to write a function that takes a list of cell id and returns a mask image indicating the cell areas. \n\nHere is a code to generate the grid image:\n```python\...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8130, "level": 1, "question": "I have an encoding aerial view image of traffic. The image is divided into grid cells. Each cell has a unique id number. I want to write a function that takes a list of cell id and returns a mask image indicating the cell areas. \n\nHere is a code to g...
def find_middle(words): n = len(words) if n % 2 == 1: mid = n // 2 return words[mid] else: mid1 = (n // 2) - 1 mid2 = n // 2 return f"{words[mid1]} {words[mid2]}"
simplelr_Apps
[ { "content": "Question:\n# Description:\n\nCreate a function `find_middle` that takes a list of words as input and returns the word(s) that is/are in the middle of the list. If the list has an even number of words, return the two middle words concatenated with a space in between. If the list has an odd number o...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8131, "level": 1, "question": "# Description:\n\nCreate a function `find_middle` that takes a list of words as input and returns the word(s) that is/are in the middle of the list. If the list has an even number of words, return the two middle words concatenated with a space in betwe...
def even_sorted(lst): evens = [num for num in lst if num % 2 == 0] return sorted(evens)
simplelr_Taco
[ { "content": "Question:\nWrite a function that takes a list of integers and returns a new list containing only the even integers from the original list, sorted in non-decreasing order. The list can contain negative numbers and is not necessarily sorted. If the input list is empty or contains no even integers, t...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8132, "level": 1, "question": "Write a function that takes a list of integers and returns a new list containing only the even integers from the original list, sorted in non-decreasing order. The list can contain negative numbers and is not necessarily sorted. If the input list is em...
def find_divisors(n): if n == 0: return [] n = abs(n) divisors = [] for i in range(1, int(n**0.5) + 1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n // i) divisors.sort() return divisors
simplelr_Prefill
[ { "content": "Question:\nWrite a python function to find all divisors of a number.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8133, "level": 1, "question": "Write a python function to find all divisors of a number.", "split": "train" }
def unique_gene_names(gene_list): return {gene.lower() for gene in gene_list}
simplelr_Filter
[ { "content": "Question:\nWrite a Python function that takes a list of gene names and returns a set of unique gene names after removing duplicates. Additionally, the function should handle any case sensitivities by normalizing all gene names to lowercase before processing. This function will help in cleaning up ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8134, "level": 1, "question": "Write a Python function that takes a list of gene names and returns a set of unique gene names after removing duplicates. Additionally, the function should handle any case sensitivities by normalizing all gene names to lowercase before processing. This...
def longest_unique_substring(s: str) -> str: last_seen = {} max_length = 0 start = 0 left = 0 for right in range(len(s)): char = s[right] if char in last_seen and last_seen[char] >= left: left = last_seen[char] + 1 last_seen[char] = right current_leng...
simplelr_Algorithm
[ { "content": "Question:\n### Problem Statement\n`fetch_pharmacy_and_price_list`\n\nCreate a function `longest_unique_substring(s: str) -> str` that takes a single string argument and returns the longest substring without repeating characters.\n\n### Function Signature\n```python\ndef longest_unique_substring(s:...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8135, "level": 1, "question": "### Problem Statement\n`fetch_pharmacy_and_price_list`\n\nCreate a function `longest_unique_substring(s: str) -> str` that takes a single string argument and returns the longest substring without repeating characters.\n\n### Function Signature\n```pyth...
from collections import defaultdict def counting_sort(arr: list[int]) -> list[int]: if not arr: return [] min_val = min(arr) max_val = max(arr) offset = -min_val max_shifted = max_val - min_val # Create buckets buckets = defaultdict(list) for x in arr: shifted_...
simplelr_Data_Structure
[ { "content": "Question:\n### Counting Sort Implementation with Edge Cases\nGiven an array of integers, implement the Counting Sort algorithm to sort the array in ascending order. Your implementation should be able to handle negative numbers as well as positive numbers, and should preserve the relative order of ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8136, "level": 1, "question": "### Counting Sort Implementation with Edge Cases\nGiven an array of integers, implement the Counting Sort algorithm to sort the array in ascending order. Your implementation should be able to handle negative numbers as well as positive numbers, and sho...
def bubble_sort_desc(arr): arr = arr.copy() n = len(arr) for i in range(n): 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 retu...
simplelr_Filter
[ { "content": "Question:\nSort an array of integers using the bubble sort technique in descending order. The array can contain up to 10^6 elements. The integers in the array range from -10^9 to 10^9.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8137, "level": 1, "question": "Sort an array of integers using the bubble sort technique in descending order. The array can contain up to 10^6 elements. The integers in the array range from -10^9 to 10^9.", "split": "train" }
def optimized_knapsack(values, weights, max_weight): """ Optimized implementation of the 0/1 Knapsack problem using dynamic programming with reduced space complexity. :param values: List of item values. :param weights: List of item weights. :param max_weight: Integer representing the maximum weight...
simplelr_Algorithm
[ { "content": "Question:\n### Knapsack Problem - Dynamic Programming Optimization\n\nYou are given the task of optimizing the provided `knapsack.py` code that implements the Dynamic Programming (DP) solution for solving the 0/1 Knapsack Problem. Your focus should be on enhancing the space complexity of the dynam...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8138, "level": 1, "question": "### Knapsack Problem - Dynamic Programming Optimization\n\nYou are given the task of optimizing the provided `knapsack.py` code that implements the Dynamic Programming (DP) solution for solving the 0/1 Knapsack Problem. Your focus should be on enhancin...
def is_match(s: str, p: str) -> bool: len_s = len(s) len_p = len(p) dp = [[False] * (len_p + 1) for _ in range(len_s + 1)] dp[0][0] = True # Empty string matches empty pattern # Handle the case when s is empty for j in range(1, len_p + 1): if j >= 2 and p[j-1] == '*' and dp[0][j-2]...
simplelr_Data_Structure
[ { "content": "Question:\n### Coding Challenge\n\nYou are tasked with implementing a function to match strings against given patterns with support for special characters. This function should adopt a dynamic programming approach to ensure efficient and comprehensive matching.\n\n#### Function Signature\n```pytho...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8139, "level": 1, "question": "### Coding Challenge\n\nYou are tasked with implementing a function to match strings against given patterns with support for special characters. This function should adopt a dynamic programming approach to ensure efficient and comprehensive matching.\n...
def max_consecutive_characters(s: str) -> tuple[str, int]: if not s: return ('', 0) current_char = s[0] max_char = current_char current_count = 1 max_count = 1 for char in s[1:]: if char == current_char: current_count += 1 else: if curren...
simplelr_Algorithm
[ { "content": "Question:\n### Problem Statement: Consecutive Characters in a String\n\nWrite a function `max_consecutive_characters(s: str) -> Tuple[str, int]` that takes a string and returns a tuple containing the character and the length of the maximum consecutive character sequence in the string. If there are...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8140, "level": 1, "question": "### Problem Statement: Consecutive Characters in a String\n\nWrite a function `max_consecutive_characters(s: str) -> Tuple[str, int]` that takes a string and returns a tuple containing the character and the length of the maximum consecutive character s...
from typing import List, Dict def sort_employees(employees: List[Dict[str, str]]) -> List[Dict[str, str]]: """ Sorts a list of employee dictionaries by department and then by name, both in ascending order. The sorting is case-insensitive. Args: employees (List[Dict[str, str]]): A list of d...
simplelr_Algorithm
[ { "content": "Question:\n### Sorting Department Employees\n\nImplement a function to sort a list of employee records based on their department and then by their names. You must ensure the solution adheres to the specified performance and constraints.\n\n#### Function Signature\n\n```python\ndef sort_employees(e...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8141, "level": 1, "question": "### Sorting Department Employees\n\nImplement a function to sort a list of employee records based on their department and then by their names. You must ensure the solution adheres to the specified performance and constraints.\n\n#### Function Signature...
def min_completion_time(tasks): total = sum(tasks) target = total // 2 dp = [False] * (target + 1) dp[0] = True # Base case: sum of 0 is possible by choosing nothing for num in tasks: for j in range(target, num - 1, -1): if dp[j - num]: dp[j] = True # Find ...
simplelr_Leetcode
[ { "content": "Question:\nYou are given an array `tasks` where `tasks[i]` represents the time in minutes required to complete the `i-th` task. Each task can only be done by one person, but there are two people available to work on these tasks. You need to assign each task to a person such that the maximum comple...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8142, "level": 1, "question": "You are given an array `tasks` where `tasks[i]` represents the time in minutes required to complete the `i-th` task. Each task can only be done by one person, but there are two people available to work on these tasks. You need to assign each task to a ...
import pandas as pd import seaborn as sns import matplotlib.pyplot as plt def create_custom_boxenplot(data: pd.DataFrame): # Plot 1: Single horizontal boxen plot representing distribution of feature1 plt.figure(figsize=(10, 6)) sns.boxenplot(x=data["feature1"], orient='h') # Explicitly set horizontal orie...
simplelr_Docs
[ { "content": "Question:\n### **Task: Creating Customized Boxen Plots with Seaborn**\n\nYou are required to write a function `create_custom_boxenplot` that takes in a dataframe and creates multiple customized boxen plots using seaborn. Your function should demonstrate your understanding of seaborn's advanced plo...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8143, "level": 1, "question": "### **Task: Creating Customized Boxen Plots with Seaborn**\n\nYou are required to write a function `create_custom_boxenplot` that takes in a dataframe and creates multiple customized boxen plots using seaborn. Your function should demonstrate your unde...
def reverse_without_punctuation(s: str) -> str: if not s: return s words = s.split() processed_words = [] for word in words: letters = [] non_letters = [] for i, c in enumerate(word): if c.isalpha(): letters.append(c) ...
simplelr_Algorithm
[ { "content": "Question:\n### Reverse String Except Punctuation\n\nYou are given a string `s` that contains words separated by spaces and may include punctuation marks. Your task is to write a function `reverse_without_punctuation` that reverses the characters of each word in the string while keeping the punctua...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8144, "level": 1, "question": "### Reverse String Except Punctuation\n\nYou are given a string `s` that contains words separated by spaces and may include punctuation marks. Your task is to write a function `reverse_without_punctuation` that reverses the characters of each word in t...
def longest_substring(s): if not s: return 0 max_length = 0 left = 0 char_map = {} for right in range(len(s)): char = s[right] if char in char_map: left = max(left, char_map[char] + 1) char_map[char] = right current_length = right - left ...
simplelr_Apps
[ { "content": "Question:\n# Description:\n\nWrite a function that takes a string as input and returns the length of the longest substring that contains no repeating characters.\n\n# Examples\n\n```\nLongestSubstring(\"\") == 0\nLongestSubstring(\"a\") == 1\nLongestSubstring(\"abcabcbb\") == 3\nLongestSubstring(\...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8145, "level": 1, "question": "# Description:\n\nWrite a function that takes a string as input and returns the length of the longest substring that contains no repeating characters.\n\n# Examples\n\n```\nLongestSubstring(\"\") == 0\nLongestSubstring(\"a\") == 1\nLongestSubstring(\"a...
def max_subarray_sum(arr, k): if not arr or k == 0 or k > len(arr): return None current_sum = sum(arr[:k]) max_sum = current_sum for i in range(k, len(arr)): current_sum = current_sum - arr[i - k] + arr[i] if current_sum > max_sum: max_sum = current_sum return max...
simplelr_Filter
[ { "content": "Question:\nWrite a function that takes an array of integers and returns the maximum sum of a subarray of a given length. For example, given the array [1, 2, 3, 4, 5] and the length 3, the maximum sum of a subarray of length 3 is 12 (from the subarray [3, 4, 5]). Use the sliding window technique to...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8146, "level": 1, "question": "Write a function that takes an array of integers and returns the maximum sum of a subarray of a given length. For example, given the array [1, 2, 3, 4, 5] and the length 3, the maximum sum of a subarray of length 3 is 12 (from the subarray [3, 4, 5]). ...
def factorial(n): """Calculates the factorial of a non-negative integer.""" result = 1 for i in range(2, n + 1): result *= i return result
simplelr_Filter
[ { "content": "Question:\nWrite a Python function to calculate the factorial of a non-negative integer. \n\nFunction Signature:\n\n```python\nfactorial(n)\n```\n\nInput:\n\n n: A non-negative integer.\n\nOutput:\n\n The factorial of n, which is the product of all positive integers less than or equal to n.\n\nExa...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8147, "level": 1, "question": "Write a Python function to calculate the factorial of a non-negative integer. \n\nFunction Signature:\n\n```python\nfactorial(n)\n```\n\nInput:\n\n n: A non-negative integer.\n\nOutput:\n\n The factorial of n, which is the product of all positive integ...
def average_after_removals(input_string: str, k: int) -> float: # Split the input string into individual number strings numbers_str = input_string.split(',') # Convert each string to an integer after stripping any surrounding whitespace numbers = [int(s.strip()) for s in numbers_str] # Sort the list...
simplelr_Algorithm
[ { "content": "Question:\n### Coding Question\n\n#### Context\nIn data analysis and manipulation, it is often necessary to perform operations on strings and lists to validate certain conditions, replace elements, or compute specific values. A typical example involves parsing a string of numbers and calculating t...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8148, "level": 1, "question": "### Coding Question\n\n#### Context\nIn data analysis and manipulation, it is often necessary to perform operations on strings and lists to validate certain conditions, replace elements, or compute specific values. A typical example involves parsing a ...
import numpy as np from sklearn.covariance import (EmpiricalCovariance, ShrunkCovariance, LedoitWolf, OAS, GraphicalLasso) def compare_covariance_estimators(returns: np.ndarray, shrinkage_coef: float, alpha: float) -> dict: # Center the data centered_returns = returns - np.mean(returns, axis=0) # Empi...
simplelr_Docs
[ { "content": "Question:\nYou have been given a financial dataset consisting of daily returns of different stocks. The objective is to estimate the covariance matrix of this dataset using various methods and compare their performance. Specifically, you are required to implement the following:\n\n1. **Empirical C...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8149, "level": 1, "question": "You have been given a financial dataset consisting of daily returns of different stocks. The objective is to estimate the covariance matrix of this dataset using various methods and compare their performance. Specifically, you are required to implement...
def majority_element(nums): if not nums: return -1 count = 0 candidate = None for num in nums: if count == 0: candidate = num count = 1 elif num == candidate: count += 1 else: count -= 1 # Check if the can...
simplelr_Evol
[ { "content": "Question:\nGiven a list of integers, write a function to find and return the integer that appears more than half the times in the list. If no such integer exists, return -1. Ensure that the function works efficiently even for large lists. For example, for the list [2, 2, 3, 2, 5, 2, 2], the output...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8150, "level": 1, "question": "Given a list of integers, write a function to find and return the integer that appears more than half the times in the list. If no such integer exists, return -1. Ensure that the function works efficiently even for large lists. For example, for the lis...
import math def normalize_vector(vector): if not vector: raise ValueError("Input vector should not be empty.") sum_squares = sum(x ** 2 for x in vector) norm = math.sqrt(sum_squares) if norm == 0: return [0.0 for _ in vector] else: return [x / norm for x in vector]
simplelr_Algorithm
[ { "content": "Question:\n### Scenario\nYou are working on a machine learning algorithm that involves the normalization of feature vectors. Normalizing vectors is a crucial task in many statistical and machine learning applications to ensure consistency and improve model performance. Your task is to implement a ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8151, "level": 1, "question": "### Scenario\nYou are working on a machine learning algorithm that involves the normalization of feature vectors. Normalizing vectors is a crucial task in many statistical and machine learning applications to ensure consistency and improve model perfor...
from collections import defaultdict def string_to_char_count(s): char_dict = defaultdict(int) for char in s: char_lower = char.lower() char_dict[char_lower] += 1 return dict(char_dict) # Example usage: input_string = "Hello, World!" result = string_to_char_count(input_string) print(result)
simplelr_Filter
[ { "content": "Question:\nWrite a Python script to convert a given string into a dictionary where keys are unique characters from the string and values are the counts of these characters. How can I modify the script to ignore case sensitivity, so 'A' and 'a' are considered the same character?\nAnswer:\nLet's thi...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8152, "level": 1, "question": "Write a Python script to convert a given string into a dictionary where keys are unique characters from the string and values are the counts of these characters. How can I modify the script to ignore case sensitivity, so 'A' and 'a' are considered the ...
from collections import deque def walls_and_gates(grid): if not grid or not grid[0]: return m, n = len(grid), len(grid[0]) q = deque() INF = 2147483647 for i in range(m): for j in range(n): if grid[i][j] == 0: q.append((i, j)) directions = [...
simplelr_Leetcode
[ { "content": "Question:\nYou are given an `m x n` 2D grid initialized with these three possible values:\n \n* `-1` - A wall or an obstacle.\n* `0` - A gate.\n* `inf` (2147483647) - An empty room.\n\nFill each empty room with the distance to its nearest gate. If it is impossible to reach a gate, it should...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8153, "level": 1, "question": "You are given an `m x n` 2D grid initialized with these three possible values:\n \n* `-1` - A wall or an obstacle.\n* `0` - A gate.\n* `inf` (2147483647) - An empty room.\n\nFill each empty room with the distance to its nearest gate. If it is im...
def findMedianSortedArrays(arr1, arr2): # Ensure arr1 is the smaller array if len(arr1) > len(arr2): arr1, arr2 = arr2, arr1 m, n = len(arr1), len(arr2) total = m + n half = (total + 1) // 2 left = 0 right = m while left <= right: i = (left + right) // 2 j = ...
simplelr_Filter
[ { "content": "Question:\nWrite a Python function to find the median of two sorted arrays. The function should have a time complexity of O(log(min(m, n))) where m and n are the lengths of the two arrays.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8154, "level": 1, "question": "Write a Python function to find the median of two sorted arrays. The function should have a time complexity of O(log(min(m, n))) where m and n are the lengths of the two arrays.", "split": "train" }
def 无不有(longestWord, shortestWord): return shortestWord in longestWord
simplelr_Filter
[ { "content": "Question:\nI came across this programming task on a recent online coding challenge: \"Write a function named无不有 which takes two parameters, also known as arguments. The first parameter is longestWord, which is supposed to be the longest word from a linguistic perspective. The second argument, shor...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8155, "level": 1, "question": "I came across this programming task on a recent online coding challenge: \"Write a function named无不有 which takes two parameters, also known as arguments. The first parameter is longestWord, which is supposed to be the longest word from a linguistic per...
def sum_multiples_3_and_5(n: int) -> int: if n < 1: return 0 m3 = n // 3 sum3 = 3 * m3 * (m3 + 1) // 2 m5 = n // 5 sum5 = 5 * m5 * (m5 + 1) // 2 m15 = n // 15 sum15 = 15 * m15 * (m15 + 1) // 2 return sum3 + sum5 - sum15
simplelr_Algorithm
[ { "content": "Question:\n### Summing Multiples of 3 and 5\n\nYou are tasked with creating a function that calculates the sum of all multiples of 3 and 5 up to and including a given number `n`. Your function should be able to handle large numbers efficiently and return the appropriate sum.\n\nImplement the funct...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8156, "level": 1, "question": "### Summing Multiples of 3 and 5\n\nYou are tasked with creating a function that calculates the sum of all multiples of 3 and 5 up to and including a given number `n`. Your function should be able to handle large numbers efficiently and return the appr...
def first_non_repeating(s): freq = {} for c in s: if c in freq: freq[c] += 1 else: freq[c] = 1 for c in s: if freq[c] == 1: return c return ' '
simplelr_Apps
[ { "content": "Question:\nGiven a string s consisting of lowercase letters, find and return the first non-repeating character in it. If there is no non-repeating character, return a single space (' ').\n\nExample 1:\nInput: s = \"leetcode\"\nOutput: 'l'\nExplanation: The first non-repeating character is 'l'.\n\n...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8157, "level": 1, "question": "Given a string s consisting of lowercase letters, find and return the first non-repeating character in it. If there is no non-repeating character, return a single space (' ').\n\nExample 1:\nInput: s = \"leetcode\"\nOutput: 'l'\nExplanation: The first ...
def fibonacci(n): if n == 0: return 0 elif n == 1: return 1 a, b = 0, 1 for i in range(2, n + 1): c = a + b a = b b = c return b
simplelr_Algorithm
[ { "content": "Question:\nFibonacci Sequence Generator\n\n#### Problem Statement\nYou are required to implement a function `fibonacci(n)` that returns the `n-th` number in the Fibonacci sequence. The Fibonacci sequence is defined as follows:\n- `F(0) = 0`\n- `F(1) = 1`\n- `F(n) = F(n-1) + F(n-2)` for `n ≥ 2`\n\n...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8158, "level": 1, "question": "Fibonacci Sequence Generator\n\n#### Problem Statement\nYou are required to implement a function `fibonacci(n)` that returns the `n-th` number in the Fibonacci sequence. The Fibonacci sequence is defined as follows:\n- `F(0) = 0`\n- `F(1) = 1`\n- `F(n)...
import math def is_prime(n): if n <= 1: return False if n == 2: return True if n % 2 == 0: return False for i in range(3, int(math.sqrt(n)) + 1, 2): if n % i == 0: return False return True
simplelr_Prefill
[ { "content": "Question:\nWrite a python function to check if a given integer n is a prime number.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8159, "level": 1, "question": "Write a python function to check if a given integer n is a prime number.", "split": "train" }
def min_bricks_to_add(brickHeights): if not brickHeights: return 0 max_h = max(brickHeights) return sum(max_h - h for h in brickHeights)
simplelr_Leetcode
[ { "content": "Question:\nYou are given an integer array `brickHeights` where each element represents the height of a brick in a wall. You need to add new bricks of height `1` in between the existing bricks to make the wall's height uniform. Return the minimum number of new bricks you need to add so that all the...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8160, "level": 1, "question": "You are given an integer array `brickHeights` where each element represents the height of a brick in a wall. You need to add new bricks of height `1` in between the existing bricks to make the wall's height uniform. Return the minimum number of new bri...
def num_decodings(s): n = len(s) if n == 0: return 0 dp = [0] * (n + 1) dp[0] = 1 for i in range(1, n + 1): # Check single digit if i - 1 >= 0 and s[i - 1] != '0': dp[i] += dp[i - 1] # Check two digits if i >= 2: two_digits = s[i - 2:i]...
simplelr_Taco
[ { "content": "Question:\nGiven a string containing only digits, the task is to compute the number of ways we can decode it to letters. (1 maps to 'A', 2 maps to 'B', ..., 26 maps to 'Z'). \n\nExample 1:\nInput: s = \"12\"\nOutput: 2\nExplanation: \"12\" can be decoded as \"AB\" (1 2) or \"L\" (12).\n\nExample 2...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8161, "level": 1, "question": "Given a string containing only digits, the task is to compute the number of ways we can decode it to letters. (1 maps to 'A', 2 maps to 'B', ..., 26 maps to 'Z'). \n\nExample 1:\nInput: s = \"12\"\nOutput: 2\nExplanation: \"12\" can be decoded as \"AB\...
def library_catalog(operations: list) -> list: catalog = [] results = [] for op in operations: if op['operation'] == 'add': book = { 'id': op['id'], 'title': op['title'], 'author': op['author'], 'borrowed': False ...
simplelr_Package
[ { "content": "Question:\nYou are tasked with creating a function that simulates a basic library's catalog system. This function will handle adding new books, borrowing books, returning books, and listing all available books. Each book in the catalog should be represented as a dictionary containing the following...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8162, "level": 1, "question": "You are tasked with creating a function that simulates a basic library's catalog system. This function will handle adding new books, borrowing books, returning books, and listing all available books. Each book in the catalog should be represented as a ...
def is_integer_in_list(num, lst): return num in lst
simplelr_Prefill
[ { "content": "Question:\nCreate a function that takes two inputs, an integer and a list of integers. The function should return True if the integer is present in the list, and False otherwise.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8163, "level": 1, "question": "Create a function that takes two inputs, an integer and a list of integers. The function should return True if the integer is present in the list, and False otherwise.", "split": "train" }
def filter_even_greater_than_ten(numbers): return [num for num in numbers if num % 2 == 0 and num > 10]
simplelr_Filter
[ { "content": "Question:\nHow can I design a Python function that filters a list of numbers, returning only those that are even and greater than 10?\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8164, "level": 1, "question": "How can I design a Python function that filters a list of numbers, returning only those that are even and greater than 10?", "split": "train" }
def can_see_front(arr): arr.sort(reverse=True) return arr
simplelr_Leetcode
[ { "content": "Question:\nYou are given an array of integers `arr` representing the heights of students in a row. Arrange the students standing in such a way that each student can see the front students if they are taller than the one immediately in front of them. Specifically, rearrange the array such that ever...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8165, "level": 1, "question": "You are given an array of integers `arr` representing the heights of students in a row. Arrange the students standing in such a way that each student can see the front students if they are taller than the one immediately in front of them. Specifically,...
def min_steps_to_sort(nums): inversion_count = 0 n = len(nums) for i in range(n): for j in range(i + 1, n): if nums[i] > nums[j]: inversion_count += 1 return inversion_count
simplelr_Filter
[ { "content": "Question:\nYou are given an array of integers called `nums`. Write a function `min_steps_to_sort(nums)` that takes this array as input and returns the minimum number of steps required to sort the array in ascending order.\n\nConstraints:\n\n You can only swap adjacent elements in the array.\n Each...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8166, "level": 1, "question": "You are given an array of integers called `nums`. Write a function `min_steps_to_sort(nums)` that takes this array as input and returns the minimum number of steps required to sort the array in ascending order.\n\nConstraints:\n\n You can only swap adj...
def compute_average(numbers): if not numbers: return None return sum(numbers) / len(numbers)
simplelr_Filter
[ { "content": "Question:\nPropose a Python code that computes the average value of an arbitrary list of floating-point numbers. Consider dealing with potential issues like empty lists.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8167, "level": 1, "question": "Propose a Python code that computes the average value of an arbitrary list of floating-point numbers. Consider dealing with potential issues like empty lists.", "split": "train" }
def even_digit_numbers(nums): result = [] for num in nums: if len(str(num)) % 2 == 0: result.append(num) return result
simplelr_Taco
[ { "content": "Question:\nWrite a function that takes an array of integers and returns a new array containing only the integers that are an even number of digits long. For example, the number 123456 has 6 digits and is considered an even-length number, while 12345 has 5 digits and is not. \n\n### Constraints\n- ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8168, "level": 1, "question": "Write a function that takes an array of integers and returns a new array containing only the integers that are an even number of digits long. For example, the number 123456 has 6 digits and is considered an even-length number, while 12345 has 5 digits ...
from collections import Counter from typing import List def find_LHS(nums: List[int]) -> int: if not nums: return 0 count = Counter(nums) max_len = 0 for num in count: if (num + 1) in count: current_sum = count[num] + count[num + 1] if current_sum > max_len: ...
simplelr_Algorithm
[ { "content": "Question:\n### Coding Assessment Question: Find Longest Harmonious Subsequence\n\n**Objective:**\n\nWrite a function, `find_LHS(nums: List[int]) -> int`, to find the length of the longest harmonious subsequence of an array. A harmonious subsequence is one where the difference between the maximum a...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8169, "level": 1, "question": "### Coding Assessment Question: Find Longest Harmonious Subsequence\n\n**Objective:**\n\nWrite a function, `find_LHS(nums: List[int]) -> int`, to find the length of the longest harmonious subsequence of an array. A harmonious subsequence is one where t...
from collections import Counter def is_permutation(a, b): return Counter(a) == Counter(b)
simplelr_Filter
[ { "content": "Question:\nIn Python, how can I create a function to check if an array is a permutation of another array?\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8170, "level": 1, "question": "In Python, how can I create a function to check if an array is a permutation of another array?", "split": "train" }
def fib(n): if not isinstance(n, int): return "Invalid input" if n < 0: return "Invalid input" if n == 0: return 0 elif n == 1: return 1 a, b = 0, 1 for i in range(2, n + 1): c = a + b a = b b = c return b
simplelr_Taco
[ { "content": "Question:\nGiven an integer `n`, write a function that returns the nth number in the Fibonacci sequence. The Fibonacci sequence is a series of numbers where the next number is found by adding up the two numbers before it. Starting with 0 and 1, the first 10 numbers in the sequence are:\n\n0, 1, 1,...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8171, "level": 1, "question": "Given an integer `n`, write a function that returns the nth number in the Fibonacci sequence. The Fibonacci sequence is a series of numbers where the next number is found by adding up the two numbers before it. Starting with 0 and 1, the first 10 numbe...
def length_of_longest_substring(s): last_seen = {} max_length = 0 start = 0 for end in range(len(s)): char = s[end] if char in last_seen and last_seen[char] >= start: start = last_seen[char] + 1 last_seen[char] = end current_length = end - start + 1 if...
simplelr_Filter
[ { "content": "Question:\n[Problem](https://leetcode.com/problems/longest-substring-without-repeating-characters/)\n\n**Given a string s, find the length of the longest substring without repeating characters.**\n\n**Input:** s = \"abcabcbb\"\n**Output:** 3\n\n**Explanation:** The answer is \"abc\", with the leng...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8172, "level": 1, "question": "[Problem](https://leetcode.com/problems/longest-substring-without-repeating-characters/)\n\n**Given a string s, find the length of the longest substring without repeating characters.**\n\n**Input:** s = \"abcabcbb\"\n**Output:** 3\n\n**Explanation:** T...
def array_sum(arr): return sum(arr)
simplelr_Prefill
[ { "content": "Question:\nWrite a python function to calculate the sum of elements in an array. The function should take an array as an input and return the sum of its elements.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8173, "level": 1, "question": "Write a python function to calculate the sum of elements in an array. The function should take an array as an input and return the sum of its elements.", "split": "train" }
def length_of_longest_substring(s): char_map = {} max_length = 0 left = 0 for right in range(len(s)): char = s[right] if char in char_map and char_map[char] >= left: left = char_map[char] + 1 char_map[char] = right current_length = right - left + 1 if ...
simplelr_Leetcode
[ { "content": "Question:\nGiven a string `s`, return _the length of the longest substring without repeating characters_. \n\nFor example:\n```python\n# Example 1\ns = \"abcabcbb\"\nOutput: 3\nExplanation: The answer is \"abc\", with the length of 3.\n\n# Example 2\ns = \"bbbbb\"\nOutput: 1\nExplanation: The answ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8174, "level": 1, "question": "Given a string `s`, return _the length of the longest substring without repeating characters_. \n\nFor example:\n```python\n# Example 1\ns = \"abcabcbb\"\nOutput: 3\nExplanation: The answer is \"abc\", with the length of 3.\n\n# Example 2\ns = \"bbbbb\...
def trap_water(arr): n = len(arr) if n < 3: return 0 left_max = [0] * n for i in range(1, n): left_max[i] = max(left_max[i-1], arr[i-1]) right_max = [0] * n for i in range(n-2, -1, -1): right_max[i] = max(right_max[i+1], arr[i+1]) total = 0 for i in rang...
simplelr_Codeforces
[ { "content": "Question:\nYou are given an array of integers `arr` of length `n`. Each integer in the array represents the height of a building. Your task is to determine the amount of water that can be trapped after raining. The amount of water trapped at any building is determined by the difference between the...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8175, "level": 1, "question": "You are given an array of integers `arr` of length `n`. Each integer in the array represents the height of a building. Your task is to determine the amount of water that can be trapped after raining. The amount of water trapped at any building is deter...
def rotate_array(nums, k): n = len(nums) if n == 0: return [] k_effective = k % n return nums[-k_effective:] + nums[:-k_effective]
simplelr_Leetcode
[ { "content": "Question:\nYou are given an array of integers `nums` of size `n` and an integer `k`. You need to transform the array by rotating it to the right `k` times. This means that the last `k` elements of the array will become the first `k` elements, shifting the remaining elements `k` positions to the ri...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8176, "level": 1, "question": "You are given an array of integers `nums` of size `n` and an integer `k`. You need to transform the array by rotating it to the right `k` times. This means that the last `k` elements of the array will become the first `k` elements, shifting the remaini...
from typing import List def check_logs(logs: List[str], k: int) -> bool: if not logs: return True # Extract timestamps from each log entry timestamps = [] for log in logs: parts = log.split() timestamp = int(parts[1]) timestamps.append(timestamp) # Count the number o...
simplelr_Codeforces
[ { "content": "Question:\nA software company is testing a new logging system where each log entry has a unique identifier and a timestamp. Each log message follows this format: `\"[id] msg\"`, where `id` is the unique identifier and `msg` is the log message content.\n\nThe logs are stored in the order they were ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8177, "level": 1, "question": "A software company is testing a new logging system where each log entry has a unique identifier and a timestamp. Each log message follows this format: `\"[id] msg\"`, where `id` is the unique identifier and `msg` is the log message content.\n\nThe logs...
def binary_search(lst, target): low = 0 high = len(lst) - 1 while low <= high: mid = (low + high) // 2 if lst[mid] == target: return mid elif lst[mid] > target: high = mid - 1 else: low = mid + 1 return -1
simplelr_Filter
[ { "content": "Question:\nI'm looking for a simple implementation of a binary search algorithm in Python. Do you have one you can share?\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8178, "level": 1, "question": "I'm looking for a simple implementation of a binary search algorithm in Python. Do you have one you can share?", "split": "train" }
def minDiffSubarray(Arr, N, K): Arr.sort() min_diff = float('inf') for i in range(N - K + 1): current_diff = Arr[i + K - 1] - Arr[i] if current_diff < min_diff: min_diff = current_diff return min_diff
simplelr_Taco
[ { "content": "Question:\nGiven an integer array Arr[] of size N, and an integer K, the task is to find a subarray of length K such that the difference between the maximum and minimum values in the subarray is minimized. Print the minimized difference value.\n\nExample 1:\nInput:\nN = 7, K = 3\nArr[] = {10, 1, 5...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8179, "level": 1, "question": "Given an integer array Arr[] of size N, and an integer K, the task is to find a subarray of length K such that the difference between the maximum and minimum values in the subarray is minimized. Print the minimized difference value.\n\nExample 1:\nInpu...
from collections import Counter def is_palindrome_permutation(s): s = s.lower() filtered = [c for c in s if c.isalpha()] n = len(filtered) if n == 0: return True # An empty string is a palindrome counter = Counter(filtered) odd_counts = sum(1 for count in counter.values() if count...
simplelr_Taco
[ { "content": "Question:\nGiven a string, write a function to determine if it is a permutation of a palindrome. A palindrome is a word or phrase that is the same forwards and backwards. A permutation is a rearrangement of letters. The palindrome does not need to be limited to just dictionary words.\n\nExample 1:...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8180, "level": 1, "question": "Given a string, write a function to determine if it is a permutation of a palindrome. A palindrome is a word or phrase that is the same forwards and backwards. A permutation is a rearrangement of letters. The palindrome does not need to be limited to j...
def filter_books(library, criteria): result = [] for book in library: is_match = True for key, value in criteria.items(): if book[key] != value: is_match = False break if is_match: result.append(book) return result
simplelr_Algorithm
[ { "content": "Question:\n### Coding Assessment Question:\n\n#### Scenario:\nYou are developing an application to manage a library's book collection. Each book can have several attributes like title, author, genre, and publication year. Occasionally, the library needs to search for books matching a specific set ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8181, "level": 1, "question": "### Coding Assessment Question:\n\n#### Scenario:\nYou are developing an application to manage a library's book collection. Each book can have several attributes like title, author, genre, and publication year. Occasionally, the library needs to search...
import datetime import pytz def convert_timestamp_to_datetime(ts): # Convert the timestamp to a datetime object in UTC utc_dt = datetime.datetime.utcfromtimestamp(ts) # Make it aware of the UTC timezone utc_aware = pytz.utc.localize(utc_dt) # Convert to US/Eastern timezone eastern = utc_aware.a...
simplelr_Filter
[ { "content": "Question:\nWrite a Python function that converts a given timestamp in seconds since the epoch (January 1, 1970) to a human-readable date and time format. The function should take into account time zones and daylight saving time adjustments. Use the `pytz` library for timezone handling and `datetim...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8182, "level": 1, "question": "Write a Python function that converts a given timestamp in seconds since the epoch (January 1, 1970) to a human-readable date and time format. The function should take into account time zones and daylight saving time adjustments. Use the `pytz` library...
def is_rotated_version(original: str, encrypted: str) -> bool: if len(original) != len(encrypted): return False if len(original) == 0: return True concatenated = original + original return encrypted in concatenated
simplelr_Data_Structure
[ { "content": "Question:\n#### Scenario\nYou are working at a company that handles a lot of encrypted messages. Due to the nature of some encryption algorithms, it is necessary to determine if one encrypted message is just a rotation of another original message. This step is crucial to ensure the integrity of th...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8183, "level": 1, "question": "#### Scenario\nYou are working at a company that handles a lot of encrypted messages. Due to the nature of some encryption algorithms, it is necessary to determine if one encrypted message is just a rotation of another original message. This step is cr...
def squares_array(arr): return [x ** 2 for x in arr]
simplelr_Prefill
[ { "content": "Question:\nWrite a function to create and return an array in which the elements are the squares of the elements in a given array. For example, given the array [2, 3, 4], the function should return the array [4, 9, 16].\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8184, "level": 1, "question": "Write a function to create and return an array in which the elements are the squares of the elements in a given array. For example, given the array [2, 3, 4], the function should return the array [4, 9, 16].", "split": "train" }
def floyd_warshall(graph): """ Computes the shortest paths between all pairs of nodes in a weighted graph using the Floyd-Warshall algorithm. Args: graph: A square matrix representing the adjacency matrix of the graph. graph[i][j] is the weight of the edge from node i to node j. ...
simplelr_Filter
[ { "content": "Question:\nCan you provide a Python implementation of Floyd-Warshall's algorithm for finding the shortest path between all pairs of nodes in a weighted graph?\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8185, "level": 1, "question": "Can you provide a Python implementation of Floyd-Warshall's algorithm for finding the shortest path between all pairs of nodes in a weighted graph?", "split": "train" }
def is_permutation(s1: str, s2: str) -> bool: if len(s1) != len(s2): return False return sorted(s1) == sorted(s2)
simplelr_Apps
[ { "content": "Question:\nEvaluate a Permutation\n\nGiven two strings `s1` and `s2`, write a function that checks if `s1` is a permutation of `s2`. A permutation is a rearrangement of the letters of one string to match another string. The lengths of both strings should be the same in order for them to be permuta...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8186, "level": 1, "question": "Evaluate a Permutation\n\nGiven two strings `s1` and `s2`, write a function that checks if `s1` is a permutation of `s2`. A permutation is a rearrangement of the letters of one string to match another string. The lengths of both strings should be the s...
def string_interleave(s1: str, s2: str) -> str: result = [] min_len = min(len(s1), len(s2)) for i in range(min_len): result.append(s1[i]) result.append(s2[i]) result.append(s1[min_len:]) result.append(s2[min_len:]) return ''.join(result)
simplelr_Algorithm
[ { "content": "Question:\n### Problem Statement\n\nImplement a function `string_interleave` that merges two input strings by alternating their characters. If one string is longer than the other, append the remaining characters of the longer string at the end of the result.\n\n### Requirements\n\n1. **Function Si...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8187, "level": 1, "question": "### Problem Statement\n\nImplement a function `string_interleave` that merges two input strings by alternating their characters. If one string is longer than the other, append the remaining characters of the longer string at the end of the result.\n\n#...
from typing import List def check_consecutive_scores(stack: List[int]) -> bool: if len(stack) <= 1: return True for i in range(1, len(stack)): if stack[i] != stack[i-1] + 1: return False return True
simplelr_Data_Structure
[ { "content": "Question:\n#### Scenario\nYou are a software engineer working on a game server that frequently receives stacks of player scores (represented as integers) in sequential levels. You need to implement a function to verify whether the received scores for each level are in consecutive order. Efficient ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8188, "level": 1, "question": "#### Scenario\nYou are a software engineer working on a game server that frequently receives stacks of player scores (represented as integers) in sequential levels. You need to implement a function to verify whether the received scores for each level a...
def min_steps(grid): # Find the start and target positions rows = len(grid) cols = len(grid[0]) if rows > 0 else 0 start = None target = None for i in range(rows): for j in range(cols): if grid[i][j] == 'S': start = (i, j) elif grid[i][j] == 'T': ...
simplelr_Code_Contests
[ { "content": "Question:\nA software company is developing an advanced navigation system for autonomous robots that move on a 2D grid. Each robot can travel in four directions (up, down, left, right) and can perform a set of specific tasks at certain grid locations. While traveling, robots have to avoid obstacle...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8189, "level": 1, "question": "A software company is developing an advanced navigation system for autonomous robots that move on a 2D grid. Each robot can travel in four directions (up, down, left, right) and can perform a set of specific tasks at certain grid locations. While trave...
def count_unique_elements(arr): return len(set(arr))
simplelr_Prefill
[ { "content": "Question:\nCreate a function that counts the number of unique elements in an array. The function should take an array of integers as input and return the count of distinct elements.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8190, "level": 1, "question": "Create a function that counts the number of unique elements in an array. The function should take an array of integers as input and return the count of distinct elements.", "split": "train" }
from typing import List def rotate_matrix(matrix: List[List[int]]) -> None: n = len(matrix) # Transpose the matrix for i in range(n): for j in range(i + 1, n): matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j] # Reverse each row for row in matrix: row.rev...
simplelr_Package
[ { "content": "Question:\nYou are asked to develop a function named `rotate_matrix` that rotates a given N x N 2D matrix 90 degrees clockwise. The function should modify the matrix in place without using any extra space for another matrix.\n\nThe function should follow the steps described below:\n1. Transpose th...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8191, "level": 1, "question": "You are asked to develop a function named `rotate_matrix` that rotates a given N x N 2D matrix 90 degrees clockwise. The function should modify the matrix in place without using any extra space for another matrix.\n\nThe function should follow the step...
def points_diff(points, K): if len(points) <= 1: return True sorted_points = sorted(points) for i in range(len(sorted_points) - 1): if sorted_points[i+1] - sorted_points[i] > K: return False return True
simplelr_Apps
[ { "content": "Question:\nYou are given a list of integers that represent the number of points scored by N players in a game. Your task is to determine if the difference in points scored by any two players is at most K. \n\n- If the difference between any two players' scores is greater than K, return `False`.\n-...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8192, "level": 1, "question": "You are given a list of integers that represent the number of points scored by N players in a game. Your task is to determine if the difference in points scored by any two players is at most K. \n\n- If the difference between any two players' scores is...
def count(coins, value): dp = [0] * (value + 1) dp[0] = 1 # Base case: one way to make 0 value (using no coins) for coin in coins: for j in range(coin, value + 1): dp[j] += dp[j - coin] return dp[value]
simplelr_Data_Structure
[ { "content": "Question:\n### Question\n\n#### Scenario\nYou are tasked with developing a system that needs to handle financial transactions through a vending machine. As part of verifying the number of ways to provide change, you are given a set of coin denominations and a value.\n\n#### Task\nImplement a funct...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8193, "level": 1, "question": "### Question\n\n#### Scenario\nYou are tasked with developing a system that needs to handle financial transactions through a vending machine. As part of verifying the number of ways to provide change, you are given a set of coin denominations and a val...
def three_sum(nums, target): nums.sort() n = len(nums) for i in range(n): left = i + 1 right = n - 1 while left < right: current_sum = nums[i] + nums[left] + nums[right] if current_sum == target: return True elif current_sum < targe...
simplelr_Leetcode
[ { "content": "Question:\nYou are given a **0-indexed** integer array `nums` and an integer `target`. You need to determine if there exist three numbers in `nums` whose sum is equal to `target`. Return `true` if such a triplet exists, otherwise return `false`.\n\nFor example, given `nums = [1, 2, 3, 4, 5]` and `...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8194, "level": 1, "question": "You are given a **0-indexed** integer array `nums` and an integer `target`. You need to determine if there exist three numbers in `nums` whose sum is equal to `target`. Return `true` if such a triplet exists, otherwise return `false`.\n\nFor example, g...
def longest_unique_substring(s): last_seen = {} max_len = 0 left = 0 for right in range(len(s)): char = s[right] last_index = last_seen.get(char, -1) if last_index >= left: left = last_index + 1 last_seen[char] = right current_len = right - left + 1 ...
simplelr_Taco
[ { "content": "Question:\nGiven a string, return the length of the longest substring without repeating characters. Assume the input string contains only ASCII characters.\n\nFor example:\n```\nlongest_unique_substring(\"abcabcbb\") = 3, because the longest substring without repeating characters is \"abc\".\nlong...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8195, "level": 1, "question": "Given a string, return the length of the longest substring without repeating characters. Assume the input string contains only ASCII characters.\n\nFor example:\n```\nlongest_unique_substring(\"abcabcbb\") = 3, because the longest substring without rep...
def findThreeSum(arr, k): arr.sort() n = len(arr) for i in range(n - 2): left = i + 1 right = n - 1 while left < right: current_sum = arr[i] + arr[left] + arr[right] if current_sum == k: return True elif current_sum < k: ...
simplelr_Taco
[ { "content": "Question:\nGiven an array of integers and a target integer `k`, your task is to write a function that determines whether there are three distinct integers in the array that sum up to `k`. \n\nFor example:\n\n * `findThreeSum([1,2,3,4,5,6], 10) == true`, because `1 + 3 + 6` is equal to `10`.\n * ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8196, "level": 1, "question": "Given an array of integers and a target integer `k`, your task is to write a function that determines whether there are three distinct integers in the array that sum up to `k`. \n\nFor example:\n\n * `findThreeSum([1,2,3,4,5,6], 10) == true`, because ...
import configparser def manage_config(file_path: str, section: str, updates: dict) -> None: # Create a new ConfigParser object config = configparser.ConfigParser() # Read the existing configuration config.read(file_path) # Check if the section exists; if not, add it if not config.has_secti...
simplelr_Docs
[ { "content": "Question:\n### Configuration Parser using `configparser`\n\n**Task**:\nImplement a function to manage a configuration file using the `configparser` module in Python. The function will perform the following operations based on given input parameters:\n1. Read the configuration from an INI file.\n2....
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8197, "level": 1, "question": "### Configuration Parser using `configparser`\n\n**Task**:\nImplement a function to manage a configuration file using the `configparser` module in Python. The function will perform the following operations based on given input parameters:\n1. Read the ...
import heapq def minTime(tasks, workers): if not tasks: return 0 # Sort tasks in descending order to handle larger tasks first tasks.sort(reverse=True) # Initialize a min-heap to track the end times of each worker heap = [0] * workers heapq.heapify(heap) for task in tasks: #...
simplelr_Leetcode
[ { "content": "Question:\n[Question]: You are given a list of positive integers representing the durations of tasks you need to complete. Additionally, you have a fixed number of workers, each of whom can work on one task at a time. Each worker can complete exactly one task in a given unit of time. Implement a f...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8198, "level": 1, "question": "[Question]: You are given a list of positive integers representing the durations of tasks you need to complete. Additionally, you have a fixed number of workers, each of whom can work on one task at a time. Each worker can complete exactly one task in ...
def get_info(name, age, returnType): if returnType == "fullInfo": return f"{name} is {age} years old." elif returnType == "shortInfo": return f"{name} is {age}y." else: return "Invalid input"
simplelr_Prefill
[ { "content": "Question:\nCreate a function that takes in three parameters: `name` (a string), `age` (an integer), and `returnType` (a string). The function should return a string based on the `returnType` parameter. If `returnType` is `\"fullInfo\"`, the function should return a string in the following format: ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8199, "level": 1, "question": "Create a function that takes in three parameters: `name` (a string), `age` (an integer), and `returnType` (a string). The function should return a string based on the `returnType` parameter. If `returnType` is `\"fullInfo\"`, the function should return...