target
stringlengths
29
3.65k
data_source
stringclasses
12 values
prompt
listlengths
1
1
ability
stringclasses
1 value
reward_model
dict
extra_info
dict
def swap_first_last(s): if len(s) == 1: return s return s[-1] + s[1:-1] + s[0]
simplelr_Taco
[ { "content": "Question:\nGiven a string, return a new string where the first and last characters have been swapped.\n\nFor example:\n\n`\"hello\"` should return `\"oellh\"`.\n\n`\"ab\"` should return `\"ba\"`.\n\n`\"a\"` can remain `\"a\"`.\n\nYou can assume the input string will always contain at least one cha...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5400, "level": 1, "question": "Given a string, return a new string where the first and last characters have been swapped.\n\nFor example:\n\n`\"hello\"` should return `\"oellh\"`.\n\n`\"ab\"` should return `\"ba\"`.\n\n`\"a\"` can remain `\"a\"`.\n\nYou can assume the input string w...
def evaluate_median(numbers): sorted_numbers = sorted(numbers) n = len(sorted_numbers) if n % 2 == 1: return float(sorted_numbers[n // 2]) else: return (sorted_numbers[n // 2 - 1] + sorted_numbers[n // 2]) / 2
simplelr_Taco
[ { "content": "Question:\nWrite a function, evaluate_median(numbers), that calculates the median of a list of integers. The median is the middle number in a sorted list of numbers. If the list has an even number of elements, the median is the average of the two middle numbers.\n\nFor example:\n\nevaluate_median(...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5401, "level": 1, "question": "Write a function, evaluate_median(numbers), that calculates the median of a list of integers. The median is the middle number in a sorted list of numbers. If the list has an even number of elements, the median is the average of the two middle numbers.\...
def can_see_sunset(heights): n = len(heights) if n == 0: return [] max_so_far = 0 result = [0] * n for i in range(n-1, -1, -1): if heights[i] > max_so_far: result[i] = 1 max_so_far = heights[i] return result
simplelr_Leetcode
[ { "content": "Question:\nYou are given an integer array `heights` representing the heights of `n` buildings, where `heights[i]` is the height of the `i-th` building. A building can see the sunset if and only if it is taller than all the buildings to its right. A building that can see the sunset adds a '1' to th...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5402, "level": 1, "question": "You are given an integer array `heights` representing the heights of `n` buildings, where `heights[i]` is the height of the `i-th` building. A building can see the sunset if and only if it is taller than all the buildings to its right. A building that ...
from collections import Counter from typing import List def find_most_frequent(numbers: List[int]) -> int: if not isinstance(numbers, list): raise TypeError("Input must be a list.") if len(numbers) == 0: raise ValueError("List cannot be empty.") counts = Counter(numbers) most_commo...
simplelr_Algorithm
[ { "content": "Question:\n### Problem Scenario\nAs a data engineer, you are tasked to design an algorithm to efficiently find and return the most frequently occurring element in a large list of integers. If there are multiple elements with the same highest frequency, return any one of them.\n\n### Task\nImplemen...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5403, "level": 1, "question": "### Problem Scenario\nAs a data engineer, you are tasked to design an algorithm to efficiently find and return the most frequently occurring element in a large list of integers. If there are multiple elements with the same highest frequency, return any...
import pandas as pd import numpy as np def manipulate_dates(df: pd.DataFrame) -> pd.DataFrame: # Convert the 'date' column to datetime df = df.copy() df['date'] = pd.to_datetime(df['date']) # Step 1: Add 5 Business Days to each date df['date_plus_5bd'] = df['date'] + pd.offsets.BusinessDay(5) ...
simplelr_Docs
[ { "content": "Question:\n#### Objective\nTo assess your understanding of pandas’ date offsets and their application in data manipulation.\n\n#### Problem Statement\n\nYou are given a DataFrame with a single column “date” containing date values. Your task is to implement a function that performs the following op...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5404, "level": 1, "question": "#### Objective\nTo assess your understanding of pandas’ date offsets and their application in data manipulation.\n\n#### Problem Statement\n\nYou are given a DataFrame with a single column “date” containing date values. Your task is to implement a func...
def are_collinear(points): if len(points) < 2: return True # Trivial case with 0 or 1 point x0, y0 = points[0] # Reference point # Calculate initial slope to use for comparison x1, y1 = points[1] if x1 == x0: slope = float('inf') else: slope = (y1 - y0) / (x1 - x0) ...
simplelr_Filter
[ { "content": "Question:\nI have in mind a picture of $N$ points in the plane, and I'd like to write a program to tell me if those points are collinear (lie on the same line). One way to do this is to calculate the slopes of the line segments joining all pairs of points. If any pair of points has a slope that is...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5405, "level": 1, "question": "I have in mind a picture of $N$ points in the plane, and I'd like to write a program to tell me if those points are collinear (lie on the same line). One way to do this is to calculate the slopes of the line segments joining all pairs of points. If any...
def first_repeated_element(arr): seen = set() for num in arr: if num in seen: return num seen.add(num) return -1
simplelr_Prefill
[ { "content": "Question:\nWrite a function to find the first repeated element in an array of integers. The function should return the first repeated element if it exists, otherwise return -1. The array contains integers within the range from 1 to n, where n is the length of the array.\nAnswer:\nLet's think step ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5406, "level": 1, "question": "Write a function to find the first repeated element in an array of integers. The function should return the first repeated element if it exists, otherwise return -1. The array contains integers within the range from 1 to n, where n is the length of the...
def combine(x, y): if x == 0: return [""] elif y == "": return [y] else: return [str(x) + c for c in y]
simplelr_Prefill
[ { "content": "Question:\nCreate a function that takes two parameters, an integer `x` and a string `y`. The function should return a list of all possible combinations of `x` and `y`. If `x` is 0, the function should return a list containing an empty string. If `y` is an empty string, the function should return a...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5407, "level": 1, "question": "Create a function that takes two parameters, an integer `x` and a string `y`. The function should return a list of all possible combinations of `x` and `y`. If `x` is 0, the function should return a list containing an empty string. If `y` is an empty s...
from typing import List def longest_increasing_subsequence(nums: List[int]) -> int: if not nums: return 0 dp = [1] * len(nums) for i in range(1, len(nums)): for j in range(i): if nums[i] > nums[j]: dp[i] = max(dp[i], dp[j] + 1) return max(dp)
simplelr_Package
[ { "content": "Question:\n**Context:**\nIn several applications, you may need to work with lists of numbers and manipulate these lists to provide specific insights or summaries. A common task is to identify patterns or features in a list of integers.\n\n**Requirements:**\nYou need to create a function named `lon...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5408, "level": 1, "question": "**Context:**\nIn several applications, you may need to work with lists of numbers and manipulate these lists to provide specific insights or summaries. A common task is to identify patterns or features in a list of integers.\n\n**Requirements:**\nYou n...
import bisect def longestToysSequence(toys): tails = [] for num in toys: idx = bisect.bisect_left(tails, num) if idx == len(tails): tails.append(num) else: tails[idx] = num return len(tails)
simplelr_Code_Contests
[ { "content": "Question:\nIn a programming competition, there is a problem where you are given a collection of toys, each of which has a distinct length. You need to arrange some of these toys into a single row such that each toy's position in the row guarantees that a toy with a greater length is always placed ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5409, "level": 1, "question": "In a programming competition, there is a problem where you are given a collection of toys, each of which has a distinct length. You need to arrange some of these toys into a single row such that each toy's position in the row guarantees that a toy with...
def sum_of_list(lst): return sum(lst) numbers = [1, 2, 3, 4, 5] print(sum_of_list(numbers)) # Expected output: 15
simplelr_Filter
[ { "content": "Question:\nWrite a Python function that takes a list of integers as input and returns the sum of all the integers in the list. Use the `sum` function to find the sum of the list. Test the function with the list [1, 2, 3, 4, 5]. The expected output is 15.\nAnswer:\nLet's think step by step.\n", ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5410, "level": 1, "question": "Write a Python function that takes a list of integers as input and returns the sum of all the integers in the list. Use the `sum` function to find the sum of the list. Test the function with the list [1, 2, 3, 4, 5]. The expected output is 15.", "spl...
def rotate_list(lst, k): n = len(lst) if n == 0: return [] effective_k = k % n if effective_k == 0: return list(lst) return lst[-effective_k:] + lst[:-effective_k]
simplelr_Evol
[ { "content": "Question:\nCreate a function called `rotate_list` that takes two arguments: a list of integers `lst` and a positive integer `k`. The function should rotate the list to the right by `k` positions. Rotating a list to the right means that for each step, the last element of the list becomes the first ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5411, "level": 1, "question": "Create a function called `rotate_list` that takes two arguments: a list of integers `lst` and a positive integer `k`. The function should rotate the list to the right by `k` positions. Rotating a list to the right means that for each step, the last ele...
from typing import List, Tuple def sort_people(people: List[Tuple[str, int]]) -> List[Tuple[str, int]]: return sorted(people, key=lambda x: (-x[1], x[0]))
simplelr_Algorithm
[ { "content": "Question:\n### Sort People by Height and Name\n\nYou are tasked with implementing a function that sorts a list of people by their height in descending order. If two people have the same height, they should be sorted by their names in ascending order.\n\n### Function Signature\n```python\ndef sort_...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5412, "level": 1, "question": "### Sort People by Height and Name\n\nYou are tasked with implementing a function that sorts a list of people by their height in descending order. If two people have the same height, they should be sorted by their names in ascending order.\n\n### Funct...
from collections import Counter def element_frequency(lst): return Counter(lst)
simplelr_Filter
[ { "content": "Question:\nWrite a Python function to find the frequency of each unique element in the given list.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5413, "level": 1, "question": "Write a Python function to find the frequency of each unique element in the given list.", "split": "train" }
def length_of_longest_substring(s: str) -> int: char_index = {} max_length = 0 left = 0 for right in range(len(s)): current_char = s[right] if current_char in char_index and char_index[current_char] >= left: left = char_index[current_char] + 1 char_index[current_char]...
simplelr_Leetcode
[ { "content": "Question:\nGiven a string `s` of length `n` consisting of only lowercase English letters, you are required to find the **length** of the **longest substring** without repeating characters. Return that length as an integer.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5414, "level": 1, "question": "Given a string `s` of length `n` consisting of only lowercase English letters, you are required to find the **length** of the **longest substring** without repeating characters. Return that length as an integer.", "split": "train" }
def min_moves_to_unlock(start_sequence: str, target_sequence: str) -> int: total = 0 for a, b in zip(start_sequence, target_sequence): a_digit = int(a) b_digit = int(b) diff = (b_digit - a_digit) % 10 if diff > 5: total += 10 - diff else: total += ...
simplelr_Apps
[ { "content": "Question:\nYou are tasked with cracking a safe lock by finding a sequence of movements using a combination lock. The lock has digits from 0 to 9 and you can rotate each digit to increase (+1) or decrease (-1) its value, wrapping around if necessary (e.g., decreasing 0 results in 9 and increasing 9...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5415, "level": 1, "question": "You are tasked with cracking a safe lock by finding a sequence of movements using a combination lock. The lock has digits from 0 to 9 and you can rotate each digit to increase (+1) or decrease (-1) its value, wrapping around if necessary (e.g., decreas...
def fahrenheit_to_celsius(degrees_f): return (degrees_f - 32) * 5 / 9
simplelr_Prefill
[ { "content": "Question:\nCreate a function that calculates the temperature in degrees Celsius given the temperature in degrees Fahrenheit. Remember that the formula to convert from Fahrenheit to Celsius is `(degree_fahrenheit - 32) * 5 / 9`.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5416, "level": 1, "question": "Create a function that calculates the temperature in degrees Celsius given the temperature in degrees Fahrenheit. Remember that the formula to convert from Fahrenheit to Celsius is `(degree_fahrenheit - 32) * 5 / 9`.", "split": "train" }
def second_smallest(lst): smallest = None second_smallest = None for num in lst: if smallest is None: smallest = num else: if num < smallest: second_smallest = smallest smallest = num elif num != smallest: if...
simplelr_Filter
[ { "content": "Question:\nWrite a Python function to find the second smallest element in a list of integers. If the list does not have at least two unique elements, the function should return `None`. Ensure your function is efficient and handles edge cases appropriately. Include a brief explanation of your appro...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5417, "level": 1, "question": "Write a Python function to find the second smallest element in a list of integers. If the list does not have at least two unique elements, the function should return `None`. Ensure your function is efficient and handles edge cases appropriately. Includ...
from collections import Counter def common_elements(list1, list2): c1 = Counter(list1) c2 = Counter(list2) common = [] for element in c1: if element in c2: count = min(c1[element], c2[element]) common += [element] * count common.sort() return common
simplelr_Filter
[ { "content": "Question:\nWrite a Python function to find the common elements between two lists, including duplicates, and return them in a sorted list. The function should handle lists containing any hashable elements.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5418, "level": 1, "question": "Write a Python function to find the common elements between two lists, including duplicates, and return them in a sorted list. The function should handle lists containing any hashable elements.", "split": "train" }
def decode_ways(encoded_message: str) -> int: if not encoded_message: return 0 n = len(encoded_message) dp = [0] * (n + 1) dp[0] = 1 # Base case: one way to decode an empty string for i in range(1, n + 1): # Check single-digit possibility if encoded_message[i-1] !=...
simplelr_Data_Structure
[ { "content": "Question:\n### Decode Ways Challenge\n\n**Context:**\nA message containing letters from A-Z can be encoded as follows:\n- 'A' -> 1\n- 'B' -> 2\n- ...\n- 'Z' -> 26\n\nYou are given an encoded message containing digits. Your task is to determine the total number of ways to decode it. For example, gi...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5419, "level": 1, "question": "### Decode Ways Challenge\n\n**Context:**\nA message containing letters from A-Z can be encoded as follows:\n- 'A' -> 1\n- 'B' -> 2\n- ...\n- 'Z' -> 26\n\nYou are given an encoded message containing digits. Your task is to determine the total number of...
def count_prime_factors(n): if n < 2: return 0 count = 0 # Check for factor 2 while n % 2 == 0: count += 1 n = n // 2 # Check for odd factors d = 3 while d * d <= n: while n % d == 0: count += 1 n = n // d d += 2 # If remain...
simplelr_Prefill
[ { "content": "Question:\nCreate a function that takes in an integer and returns the number of its prime factors.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5420, "level": 1, "question": "Create a function that takes in an integer and returns the number of its prime factors.", "split": "train" }
def find_modes(nums): if not nums: return [] nums.sort() current_num = nums[0] current_count = 1 max_count = 0 modes = [] for num in nums[1:]: if num == current_num: current_count += 1 else: if current_count > max_count: ...
simplelr_Filter
[ { "content": "Question:\nGiven a set of unsorted numbers, you are required to write an algorithm in Python to find the mode (the most frequently occurring number) of the set. If there are multiple modes, the algorithm should return all of them. Ensure your solution can handle both negative and positive integers...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5421, "level": 1, "question": "Given a set of unsorted numbers, you are required to write an algorithm in Python to find the mode (the most frequently occurring number) of the set. If there are multiple modes, the algorithm should return all of them. Ensure your solution can handle ...
def sort_tuples_by_second_element(tuples_list): return sorted(tuples_list, key=lambda x: x[1].lower())
simplelr_Filter
[ { "content": "Question:\nYou've been tasked with writing a function to sort a list of tuples based on the second element in the tuple. The function should take in a list of tuples, where each tuple contains two elements: an integer and a string. The function should return a new list where the tuples are sorted ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5422, "level": 1, "question": "You've been tasked with writing a function to sort a list of tuples based on the second element in the tuple. The function should take in a list of tuples, where each tuple contains two elements: an integer and a string. The function should return a ne...
from typing import List def is_sorted_alternative(stack: List[int]) -> bool: if len(stack) <= 1: return True prev = stack[0] for current in stack[1:]: if prev > current: return False prev = current return True
simplelr_Data_Structure
[ { "content": "Question:\n**Question**: Consider you are given a stack represented as a list in Python, where the last element of the list represents the top of the stack. Your task is to implement a function `is_sorted_alternative(stack)` that validates whether the stack is sorted in ascending order (smallest e...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5423, "level": 1, "question": "**Question**: Consider you are given a stack represented as a list in Python, where the last element of the list represents the top of the stack. Your task is to implement a function `is_sorted_alternative(stack)` that validates whether the stack is so...
def allUniqueNames(names): return len(names) == len(set(names))
simplelr_Taco
[ { "content": "Question:\nYou are given a list of names as input. Your task is to create a function that determines if all the names in the list are unique (i.e., no duplicates).\n\nExample 1:\nInput:\nnames = [\"Alice\", \"Bob\", \"Charlie\", \"David\"]\nOutput:\nUnique\n\nExample 2:\nInput:\nnames = [\"Alice\"...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5424, "level": 1, "question": "You are given a list of names as input. Your task is to create a function that determines if all the names in the list are unique (i.e., no duplicates).\n\nExample 1:\nInput:\nnames = [\"Alice\", \"Bob\", \"Charlie\", \"David\"]\nOutput:\nUnique\n\nExa...
def manipulate_string(input_string: str, drop_vowels: bool, reverse_substrings: bool) -> str: vowels = {'a', 'e', 'i', 'o', 'u'} # Step 1: Remove vowels if required if drop_vowels: new_str = ''.join([c for c in input_string if c not in vowels]) else: new_str = input_string # Step 2: ...
simplelr_Algorithm
[ { "content": "Question:\n### Manipulating Strings Based on Criteria\n\n**Context**: String manipulation is a common requirement in many software projects, particularly when dealing with text processing, data cleaning, and formatting. Dropping characters or modifying strings based on specific criteria is a frequ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5425, "level": 1, "question": "### Manipulating Strings Based on Criteria\n\n**Context**: String manipulation is a common requirement in many software projects, particularly when dealing with text processing, data cleaning, and formatting. Dropping characters or modifying strings ba...
import random def generate_coordinates(x_min, x_max, y_min, y_max): x = random.randint(x_min, x_max) y = random.randint(y_min, y_max) return (x, y) # Example: Generate coordinates within a rectangle from (1,1) to (20,10) coordinates = generate_coordinates(1, 20, 1, 10) print(coordinates)
simplelr_Filter
[ { "content": "Question:\nThe\n\n1. **Problem:** A student was writing a program to generate random coordinates within a specified range. Here's their code:\n\n```python\nimport random\n\ndef generate_coordinates(x_range, y_range):\n x = random.randint(x_range[0], x_range[1])\n y = random.randint(y_range[0], y...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5426, "level": 1, "question": "The\n\n1. **Problem:** A student was writing a program to generate random coordinates within a specified range. Here's their code:\n\n```python\nimport random\n\ndef generate_coordinates(x_range, y_range):\n x = random.randint(x_range[0], x_range[1])\...
import bisect def count_missing_numbers(nums, lower, upper): sorted_unique = sorted(set(nums)) left = bisect.bisect_left(sorted_unique, lower) right = bisect.bisect_right(sorted_unique, upper) count_present = right - left total = upper - lower + 1 return total - count_present
simplelr_Leetcode
[ { "content": "Question:\nYou are given a list of integers `nums` and a continuous range `[lower, upper]`. The task is to count how many numbers within this inclusive range do not appear in `nums`. For example, if `nums = [2, 3, 7, 10]` and the range is `[1, 10]`, then the numbers `1, 4, 5, 6, 8, 9` do not appea...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5427, "level": 1, "question": "You are given a list of integers `nums` and a continuous range `[lower, upper]`. The task is to count how many numbers within this inclusive range do not appear in `nums`. For example, if `nums = [2, 3, 7, 10]` and the range is `[1, 10]`, then the numb...
def next_bigger(num: int) -> int: digits = list(str(num)) n = len(digits) # Step 1: Find the largest index `i` such that digits[i] < digits[i+1] i = n - 2 while i >= 0 and digits[i] >= digits[i + 1]: i -= 1 if i == -1: return -1 # No such index, next permutation does n...
simplelr_Data_Structure
[ { "content": "Question:\n## Problem Description\n\nYou are given a non-negative integer `num`. Your task is to write a function `next_bigger(num)` that returns the next greater number using the same set of digits as `num`. If no such number exists, return `-1`.\n\n### Function Signature\n```python\ndef next_big...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5428, "level": 1, "question": "## Problem Description\n\nYou are given a non-negative integer `num`. Your task is to write a function `next_bigger(num)` that returns the next greater number using the same set of digits as `num`. If no such number exists, return `-1`.\n\n### Function...
def maximum_possible_value(nums): n = len(nums) for i in range(n): current = nums[i] max_val = max(nums[i:]) if max_val > current: # Find the rightmost occurrence of max_val in nums[i:] j = len(nums) - 1 - nums[i:][::-1].index(max_val) nums[i], nums[j]...
simplelr_Leetcode
[ { "content": "Question:\nGiven a list of `non-negative integers nums`, you are allowed to swap any two elements at most once. Return the maximum possible value of the list after making at most one swap. If the list is already in its largest possible permutation, return the list as is.\nAnswer:\nLet's think step...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5429, "level": 1, "question": "Given a list of `non-negative integers nums`, you are allowed to swap any two elements at most once. Return the maximum possible value of the list after making at most one swap. If the list is already in its largest possible permutation, return the lis...
def find_min_max_keys(d): min_key = None max_key = None min_value = None max_value = None for key, value in d.items(): if min_value is None or value < min_value: min_value = value min_key = key if max_value is None or value > max_value: max_value =...
simplelr_Filter
[ { "content": "Question:\nCreate a Python function that, given a dictionary with numerical values, identifies the key associated with the smallest value and the key associated with the largest value. The function should return a tuple containing the smallest and largest value keys, respectively. Ensure the funct...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5430, "level": 1, "question": "Create a Python function that, given a dictionary with numerical values, identifies the key associated with the smallest value and the key associated with the largest value. The function should return a tuple containing the smallest and largest value k...
def partition_list(arr): total_sum = sum(arr) if len(arr) < 2: return 0 # though the problem states len >=2, so perhaps not needed min_sum = sum(x for x in arr if x < 0) max_sum = sum(x for x in arr if x > 0) offset = abs(min_sum) size = max_sum - min_sum + 1 dp = [False] * siz...
simplelr_Code_Contests
[ { "content": "Question:\nGiven a list of integers, the goal is to partition the list into two non-empty sublists such that the absolute difference between the sums of the elements in the two sublists is minimized.\n\nWrite a function `partition_list(arr)` that takes in a list of integers `arr` and returns the m...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5431, "level": 1, "question": "Given a list of integers, the goal is to partition the list into two non-empty sublists such that the absolute difference between the sums of the elements in the two sublists is minimized.\n\nWrite a function `partition_list(arr)` that takes in a list ...
def sort_tuples_by_second(tuple_list): return sorted(tuple_list, key=lambda x: (x[1], x[0]))
simplelr_Prefill
[ { "content": "Question:\nWrite a python function to sort a list of tuples by the second item in each tuple. If two tuples have the same second item, sort them by the first item in ascending order. You should use a lambda function for sorting.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5432, "level": 1, "question": "Write a python function to sort a list of tuples by the second item in each tuple. If two tuples have the same second item, sort them by the first item in ascending order. You should use a lambda function for sorting.", "split": "train" }
def two_sum(nums, target): seen = {} for i, num in enumerate(nums): complement = target - num if complement in seen: return [seen[complement], i] seen[num] = i return []
simplelr_Prefill
[ { "content": "Question:\nCreate a function that accepts two parameters: an array and a target number. The function should return the indices of the two numbers such that they add up to the target number. If no such combination exists, return an empty array. Solve this using a hash map to achieve an efficient so...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5433, "level": 1, "question": "Create a function that accepts two parameters: an array and a target number. The function should return the indices of the two numbers such that they add up to the target number. If no such combination exists, return an empty array. Solve this using a ...
def custom_split(s, sep): result = [] temp = '' for char in s: if char == sep: result.append(temp) temp = '' else: temp += char result.append(temp) return result
simplelr_Apps
[ { "content": "Question:\nCreate a function that takes a string and a separator character, and splits the string into an array of words. Each word is a sequence of characters found between instances of the separator character.\n\nFor example, given the string\n\n```\n\"apple,banana,orange\"\n```\n\nand the separ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5434, "level": 1, "question": "Create a function that takes a string and a separator character, and splits the string into an array of words. Each word is a sequence of characters found between instances of the separator character.\n\nFor example, given the string\n\n```\n\"apple,ba...
def reconstructMessage(packets): sorted_packets = sorted(packets, key=lambda x: x[0]) strings = [p[1] for p in sorted_packets] return ''.join(strings)
simplelr_Taco
[ { "content": "Question:\nIn network communications, data packets often need to be reconstructed into their original form upon arrival. Each packet contains a sequence number that indicates its position in the original message. However, network issues might cause packets to arrive out of order, and your task is ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5435, "level": 1, "question": "In network communications, data packets often need to be reconstructed into their original form upon arrival. Each packet contains a sequence number that indicates its position in the original message. However, network issues might cause packets to arr...
def have_common_elements(list1, list2): return bool(set(list1) & set(list2))
simplelr_Filter
[ { "content": "Question:\nI'm working on a project that involves comparing two sets of data. I have two lists of integers, and I need to determine if they have any common elements. Can you help me write a Python function that takes these two lists as input and returns `True` if there is at least one common eleme...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5436, "level": 1, "question": "I'm working on a project that involves comparing two sets of data. I have two lists of integers, and I need to determine if they have any common elements. Can you help me write a Python function that takes these two lists as input and returns `True` if...
def remove_falsy_values(lst): return [item for item in lst if item]
simplelr_Prefill
[ { "content": "Question:\nWrite a python function to remove all falsy values from a list. A falsy value in Python is a value that is considered `False` in a boolean context. False, None, 0, 0.0, 0j, (), {}, [], and `''` (empty string) are all considered falsy values.\nAnswer:\nLet's think step by step.\n", "...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5437, "level": 1, "question": "Write a python function to remove all falsy values from a list. A falsy value in Python is a value that is considered `False` in a boolean context. False, None, 0, 0.0, 0j, (), {}, [], and `''` (empty string) are all considered falsy values.", "split...
def max_sum_increasing_subsequence(arr): if not arr: return 0 max_sum = [x for x in arr] n = len(arr) for i in range(1, n): for j in range(i): if arr[j] < arr[i]: if max_sum[j] + arr[i] > max_sum[i]: max_sum[i] = max_sum[j] + arr[i] ret...
simplelr_Prefill
[ { "content": "Question:\nWrite a python function to find the maximum sum of an increasing subsequence in an array. An increasing subsequence is defined as a sequence of numbers where each next number in the sequence is greater than the current number.\nAnswer:\nLet's think step by step.\n", "role": "user" ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5438, "level": 1, "question": "Write a python function to find the maximum sum of an increasing subsequence in an array. An increasing subsequence is defined as a sequence of numbers where each next number in the sequence is greater than the current number.", "split": "train" }
def reverse_odd_indices(lst): even = [x for i, x in enumerate(lst) if i % 2 == 0] odd = [x for i, x in enumerate(lst) if i % 2 != 0][::-1] result = [] e_ptr = o_ptr = 0 for i in range(len(lst)): if i % 2 == 0: result.append(even[e_ptr]) e_ptr += 1 else: ...
simplelr_Filter
[ { "content": "Question:\nWrite a Python function that takes a list of integers and returns a new list with the elements in reverse order, but only for elements at odd indices. Even indices should remain unchanged.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5439, "level": 1, "question": "Write a Python function that takes a list of integers and returns a new list with the elements in reverse order, but only for elements at odd indices. Even indices should remain unchanged.", "split": "train" }
def find_max(list_nums): if not list_nums: return None return max(list_nums)
simplelr_Filter
[ { "content": "Question:\nWrite a python function called `find_max` that takes in a list called `list_nums` and returns the largest number in the list. If the list is empty, the function should return None.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5440, "level": 1, "question": "Write a python function called `find_max` that takes in a list called `list_nums` and returns the largest number in the list. If the list is empty, the function should return None.", "split": "train" }
def has_unique_characters(s: str) -> bool: seen = [False] * 256 for c in s: char_code = ord(c) if seen[char_code]: return False seen[char_code] = True return True
simplelr_Algorithm
[ { "content": "Question:\n### Coding Assessment Question: Determine if a String Has All Unique Characters\n\n**Background**:\nOne of the common problems in string manipulation is determining whether a string contains all unique characters. This can help ensure the validity of passwords or identifiers in various ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5441, "level": 1, "question": "### Coding Assessment Question: Determine if a String Has All Unique Characters\n\n**Background**:\nOne of the common problems in string manipulation is determining whether a string contains all unique characters. This can help ensure the validity of p...
def calculate_discount(price, discount): discounted_price = price * (1 - discount / 100) return round(discounted_price, 2)
simplelr_Filter
[ { "content": "Question:\nThis code defines a function called `calculate_discount` that takes a price and a discount percentage as arguments and returns the discounted price.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5442, "level": 1, "question": "This code defines a function called `calculate_discount` that takes a price and a discount percentage as arguments and returns the discounted price.", "split": "train" }
from collections import defaultdict def merge_dicts(dict_list: list) -> dict: merged_dict = defaultdict(list) for d in dict_list: for key, value in d.items(): merged_dict[key].append(value) return merged_dict
simplelr_Package
[ { "content": "Question:\nYou are required to write a Python function `merge_dicts(dict_list)`. This function takes a list of dictionaries as its input and merges them into a single dictionary. If there are duplicate keys across the dictionaries, their values should be aggregated in a list.\n\nYou are explicitly...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5443, "level": 1, "question": "You are required to write a Python function `merge_dicts(dict_list)`. This function takes a list of dictionaries as its input and merges them into a single dictionary. If there are duplicate keys across the dictionaries, their values should be aggregat...
def linear_search(lst, target): for i in range(len(lst)): if lst[i] == target: return i return -1
simplelr_Filter
[ { "content": "Question:\nCreate a Python function that simulates a linear search algorithm to find a target element in a list of integers. The function should return the index of the target element if it is found, or -1 if it is not in the list.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5444, "level": 1, "question": "Create a Python function that simulates a linear search algorithm to find a target element in a list of integers. The function should return the index of the target element if it is found, or -1 if it is not in the list.", "split": "train" }
def can_form_target(words, target): target_len = len(target) word_lengths = [len(word) for word in words] for i in range(len(words)): for j in range(len(words)): if i != j and word_lengths[i] + word_lengths[j] == target_len: if words[i] + words[j] == target: ...
simplelr_Leetcode
[ { "content": "Question:\nYou are given a list of strings `words` and a string `target`. Each string in `words` represents a scrambled word. Your task is to determine if `target` can be constructed by concatenating exactly two different strings from `words`. Return `true` if `target` can be formed this way, and ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5445, "level": 1, "question": "You are given a list of strings `words` and a string `target`. Each string in `words` represents a scrambled word. Your task is to determine if `target` can be constructed by concatenating exactly two different strings from `words`. Return `true` if `t...
def max_product_of_pairs(nums): if len(nums) < 2: return None # Return None if the list has fewer than two elements sorted_nums = sorted(nums) product1 = sorted_nums[-1] * sorted_nums[-2] product2 = sorted_nums[0] * sorted_nums[1] return max(product1, product2)
simplelr_Prefill
[ { "content": "Question:\nWrite a python function to find the maximum product of pairs in a list of numbers.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5446, "level": 1, "question": "Write a python function to find the maximum product of pairs in a list of numbers.", "split": "train" }
def find_min_max(lst): min_num = max_num = lst[0] for num in lst[1:]: if num < min_num: min_num = num if num > max_num: max_num = num return (min_num, max_num)
simplelr_Filter
[ { "content": "Question:\nWrite a function to print the minimum and maximum number in a given list, without using the built-in functions min() and max(). The function should also handle the case where the list contains duplicate numbers. The list will always contain at least one element.\nAnswer:\nLet's think st...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5447, "level": 1, "question": "Write a function to print the minimum and maximum number in a given list, without using the built-in functions min() and max(). The function should also handle the case where the list contains duplicate numbers. The list will always contain at least on...
from itertools import product def letter_combinations(digits): if not digits: return [] digit_mapping = { '2': 'abc', '3': 'def', '4': 'ghi', '5': 'jkl', '6': 'mno', '7': 'pqrs', '8': 'tuv', '9': 'wxyz' } letters = [digit...
simplelr_Taco
[ { "content": "Question:\nGiven a string containing only digits, return all possible letter combinations that the number could represent. This problem is a classic combination generation question, and typically the mapping follows the same pattern as on the telephone buttons ('2' maps to \"abc\", '3' maps to \"d...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5448, "level": 1, "question": "Given a string containing only digits, return all possible letter combinations that the number could represent. This problem is a classic combination generation question, and typically the mapping follows the same pattern as on the telephone buttons ('...
def max_subarray_sum(nums): if not nums: return 0 # Assuming the function should return 0 for an empty array, though the problem states it's non-empty. max_current = max_global = nums[0] for num in nums[1:]: max_current = max(num, max_current + num) if max_current > max_gl...
simplelr_Leetcode
[ { "content": "Question:\nYou are given a **0-indexed** integer array `nums`. Calculate and return _the **maximum** sum of any non-empty **contiguous subarray** of_ `nums`_. A contiguous subarray is a subarray consisting of consecutive elements from the original array.\nAnswer:\nLet's think step by step.\n", ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5449, "level": 1, "question": "You are given a **0-indexed** integer array `nums`. Calculate and return _the **maximum** sum of any non-empty **contiguous subarray** of_ `nums`_. A contiguous subarray is a subarray consisting of consecutive elements from the original array.", "spl...
def longest_substring_without_repeating_characters(s): char_indices = {} left = 0 max_length = 0 for right in range(len(s)): current_char = s[right] if current_char in char_indices and char_indices[current_char] >= left: left = char_indices[current_char] + 1 char_indi...
simplelr_Filter
[ { "content": "Question:\nThis question asks you to write a code snippet for a function called `longest_substring_without_repeating_characters` that takes a string as input and returns the length of the longest substring within that string that contains no repeating characters.\nAnswer:\nLet's think step by step...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5450, "level": 1, "question": "This question asks you to write a code snippet for a function called `longest_substring_without_repeating_characters` that takes a string as input and returns the length of the longest substring within that string that contains no repeating characters....
from typing import List def product_except_self(nums: List[int]) -> List[int]: n = len(nums) result = [1] * n # Forward pass to compute the product of elements to the left for i in range(1, n): result[i] = result[i-1] * nums[i-1] # Backward pass to compute the product of elements ...
simplelr_Evol
[ { "content": "Question:\nImplement a function that takes a list of integers as input and returns a list of integers where each element is the product of all the integers in the input list except the one at the current index. You should solve this problem without using division.\n\n### Function Signature\n```pyt...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5451, "level": 1, "question": "Implement a function that takes a list of integers as input and returns a list of integers where each element is the product of all the integers in the input list except the one at the current index. You should solve this problem without using division...
from typing import List def max_profit_with_two_transactions(prices: List[int]) -> int: if not prices: return 0 s0 = 0 buy1 = -float('inf') sell1 = -float('inf') buy2 = -float('inf') sell2 = -float('inf') for price in prices: new_buy1 = max(buy1, s0 - price) ...
simplelr_Algorithm
[ { "content": "Question:\n### Problem Statement\n\nYou need to manipulate an array of integers representing stock prices on different days to find the maximum profit that could be achieved by making at most two transactions. A transaction consists of buying and then selling the stock on different days. Note that...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5452, "level": 1, "question": "### Problem Statement\n\nYou need to manipulate an array of integers representing stock prices on different days to find the maximum profit that could be achieved by making at most two transactions. A transaction consists of buying and then selling the...
def find_max(lst): integers = [] for num in lst: if type(num) is int: integers.append(num) if not integers: return None return max(integers)
simplelr_Prefill
[ { "content": "Question:\nWrite a python function to find the maximum number in a list of integers. If the list is empty, the function should return `None`. Also, ensure that your function handles non-integer values gracefully by ignoring them.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5453, "level": 1, "question": "Write a python function to find the maximum number in a list of integers. If the list is empty, the function should return `None`. Also, ensure that your function handles non-integer values gracefully by ignoring them.", "split": "train" }
def find_longest_first_string(tuples): if not tuples: return None max_tuple = tuples[0] max_length = len(max_tuple[0]) for tup in tuples[1:]: current_length = len(tup[0]) if current_length > max_length: max_length = current_length max_tuple = tup retur...
simplelr_Filter
[ { "content": "Question:\nI have a Python list of tuples, where each tuple contains two strings. I want to find the tuple with the longest first string. How do I do that? \n\nFor example: `[('apple', 'dog'), ('cat', 'elephant'), ('car', 'turtle')]` should return `('cat', 'elephant')`. \n\nIn this case, the strin...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5454, "level": 1, "question": "I have a Python list of tuples, where each tuple contains two strings. I want to find the tuple with the longest first string. How do I do that? \n\nFor example: `[('apple', 'dog'), ('cat', 'elephant'), ('car', 'turtle')]` should return `('cat', 'eleph...
import math def minimum_time_to_capture_castles(castles, attacks_per_minute, regeneration): result = [] A = attacks_per_minute R = regeneration for D in castles: if D <= A: result.append(1) else: if A <= R: result.append(-1) else: ...
simplelr_Apps
[ { "content": "Question:\nZara is playing a strategy game where she must capture opponents' castles. Each castle has a certain level of defense, which takes a specific number of attacks to breach. Zara commands an army that can perform a number of attacks per minute. However, after each minute of relentless atta...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5455, "level": 1, "question": "Zara is playing a strategy game where she must capture opponents' castles. Each castle has a certain level of defense, which takes a specific number of attacks to breach. Zara commands an army that can perform a number of attacks per minute. However, a...
from typing import List, Tuple def top_three_tasks(tasks: List[Tuple[str, int]]) -> List[str]: # Sort the tasks in descending order of priority sorted_tasks = sorted(tasks, key=lambda x: -x[1]) # Take the top three tasks top_three = sorted_tasks[:3] # Extract and return the task descriptions re...
simplelr_Algorithm
[ { "content": "Question:\n### Context\nAn online platform aims to assist users in managing their daily tasks by organizing them into different priority levels. Users can add tasks with varying levels of priority and the system needs to find and report the three highest priority tasks.\n\n### Problem Statement\nW...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5456, "level": 1, "question": "### Context\nAn online platform aims to assist users in managing their daily tasks by organizing them into different priority levels. Users can add tasks with varying levels of priority and the system needs to find and report the three highest priority...
def longest_increasing_playlist(song_history): if not song_history: return 0 current_length = 1 max_length = 1 for i in range(1, len(song_history)): if song_history[i] == song_history[i-1] + 1: current_length += 1 if current_length > max_length: ma...
simplelr_Apps
[ { "content": "Question:\nYou are part of a team developing an online music-streaming application. The application maintains a history of songs played by each user. You need to implement a feature to analyze user listening patterns by identifying the longest contiguous sequence of songs (playlist) that are seque...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5457, "level": 1, "question": "You are part of a team developing an online music-streaming application. The application maintains a history of songs played by each user. You need to implement a feature to analyze user listening patterns by identifying the longest contiguous sequence...
from typing import List def can_ball_pass(N: int, heights: List[int], H: int, D: int) -> str: if heights[0] > H: return "No" if N == 1: return "Yes" for i in range(1, N): if abs(heights[i] - heights[i-1]) > D: return "No" return "Yes"
simplelr_Code_Contests
[ { "content": "Question:\nYou are given an array consisting of N integers, representing the height of cylinders lined up in a row. You have a ball of height H which needs to roll through this line of cylinders. The ball is initially placed on top of the first cylinder and can roll to the next cylinder if the hei...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5458, "level": 1, "question": "You are given an array consisting of N integers, representing the height of cylinders lined up in a row. You have a ball of height H which needs to roll through this line of cylinders. The ball is initially placed on top of the first cylinder and can r...
def count_vowels(s): count = 0 vowels = {'a', 'e', 'i', 'o', 'u'} for char in s: if char.lower() in vowels: count += 1 return count
simplelr_Filter
[ { "content": "Question:\nThis is a Python 3 code snippet that takes a string as input and outputs the number of vowels in the string.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5459, "level": 1, "question": "This is a Python 3 code snippet that takes a string as input and outputs the number of vowels in the string.", "split": "train" }
def categorize_runner(time): if time < 180: return "Elite Runner" elif time < 240: return "Competitive Runner" elif time < 300: return "Average Runner" else: return "Casual Runner"
simplelr_Taco
[ { "content": "Question:\nYour hometown is hosting its annual marathon, and you've volunteered to create a program that categorizes runners based on their finish times. The marathon committee has decided on specific categories for the runners:\n\nBy completing the function provided, you will be able to classify ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5460, "level": 1, "question": "Your hometown is hosting its annual marathon, and you've volunteered to create a program that categorizes runners based on their finish times. The marathon committee has decided on specific categories for the runners:\n\nBy completing the function prov...
from urllib.parse import urlparse def organize_urls_by_domain(urls): domain_urls = {} for url in urls: parsed_url = urlparse(url) netloc = parsed_url.netloc # Split off the port if present hostname = netloc.split(':')[0] parts = hostname.split('.') domain = '.'.j...
simplelr_Package
[ { "content": "Question:\nYou are tasked with creating a Python function that parses a list of URLs and organizes them into a dictionary based on their domain names. This task assesses your understanding of string manipulation, dictionary operations, and URL parsing.\n\n**Function Specification:**\n\nName: `orga...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5461, "level": 1, "question": "You are tasked with creating a Python function that parses a list of URLs and organizes them into a dictionary based on their domain names. This task assesses your understanding of string manipulation, dictionary operations, and URL parsing.\n\n**Funct...
def second_maximum(numbers): if len(numbers) < 2: return None first = second = float('-inf') for num in numbers: if num > first: second = first first = num elif num > second and num != first: # Ensure it's a different number second = num retur...
simplelr_Prefill
[ { "content": "Question:\nWrite a function to find the second maximum number in a list of integers. If the list does not contain a second maximum number, return `None`.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5462, "level": 1, "question": "Write a function to find the second maximum number in a list of integers. If the list does not contain a second maximum number, return `None`.", "split": "train" }
def musicalChairsWinner(strengths): return max(strengths)
simplelr_Taco
[ { "content": "Question:\nIn a game of musical chairs, N players (numbered 1 through N) are arranged in a circle. Each player has a certain strength value, which indicates their resilience during the game. During each round of the game, two strongest adjacent players compete, and the player with the lesser stren...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5463, "level": 1, "question": "In a game of musical chairs, N players (numbered 1 through N) are arranged in a circle. Each player has a certain strength value, which indicates their resilience during the game. During each round of the game, two strongest adjacent players compete, a...
import bisect def find_kth_missing_positive(arr, k): unique_positive = sorted(set(x for x in arr if x > 0)) if not unique_positive: return k low = 1 high = unique_positive[-1] + k # Initial high value while low < high: mid = (low + high) // 2 count = bisect.bisect_right(uni...
simplelr_Leetcode
[ { "content": "Question:\nGiven an array of integers `arr` and an integer `k`, return the _k-th smallest **missing** positive integer_ from the array. A **missing** positive integer is defined as a positive integer that does not exist in the array. For example, if `arr` is `[2, 3, 4, 7, 11]` and `k` is `5`, the ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5464, "level": 1, "question": "Given an array of integers `arr` and an integer `k`, return the _k-th smallest **missing** positive integer_ from the array. A **missing** positive integer is defined as a positive integer that does not exist in the array. For example, if `arr` is `[2,...
def landing_priorities(flights): return sorted(range(len(flights)), key=lambda i: (flights[i][0], -flights[i][1], i))
simplelr_Taco
[ { "content": "Question:\nYou are tasked with developing a system that allows an air traffic controller to efficiently manage and prioritize landing requests from multiple incoming flights. Each flight has a priority based on its fuel level and flight duration.\n\nWrite a function that, when given a list of flig...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5465, "level": 1, "question": "You are tasked with developing a system that allows an air traffic controller to efficiently manage and prioritize landing requests from multiple incoming flights. Each flight has a priority based on its fuel level and flight duration.\n\nWrite a funct...
def is_alphabetically_sorted(s): for i in range(1, len(s)): prev = s[i-1].lower() current = s[i].lower() if current < prev: return False return True
simplelr_Apps
[ { "content": "Question:\n# Task\nGiven a string representing the order of books in a shelf, check if the shelf is alphabetically sorted or not.\n\n# Example\nFor `s = \"aBcdEfGh\"`, the output should be `true`.\n\nFor `s = \"bAcDeFgH\"`, the output should be `false`.\n\n# Input/Output\n\n- `[input]` string `s`\...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5466, "level": 1, "question": "# Task\nGiven a string representing the order of books in a shelf, check if the shelf is alphabetically sorted or not.\n\n# Example\nFor `s = \"aBcdEfGh\"`, the output should be `true`.\n\nFor `s = \"bAcDeFgH\"`, the output should be `false`.\n\n# Inpu...
from collections import defaultdict from typing import List def counting_sort(arr: List[int]) -> List[int]: if not arr: return [] min_val = min(arr) max_val = max(arr) offset = min_val count_map = defaultdict(list) for x in arr: key = x - offset count_map[key].append(x) ...
simplelr_Data_Structure
[ { "content": "Question:\n### Counting Sort Function Implementation Challenge\n\n#### Objective\nWrite a function implementing Counting Sort to sort an array of integers, including cases with negative numbers.\n\n#### Function Signature\n```python\ndef counting_sort(arr: List[int]) -> List[int]:\n```\n\n#### Inp...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5467, "level": 1, "question": "### Counting Sort Function Implementation Challenge\n\n#### Objective\nWrite a function implementing Counting Sort to sort an array of integers, including cases with negative numbers.\n\n#### Function Signature\n```python\ndef counting_sort(arr: List[i...
def max_sum_subarray_with_one_removal(nums): if not nums: return 0 current_max_without = nums[0] current_max_with = 0 max_sum = current_max_without for i in range(1, len(nums)): # Calculate new values for this iteration new_current_max_without = max(nums[i], current...
simplelr_Leetcode
[ { "content": "Question:\nGiven an array of integers, find the maximum possible sum of a non-empty subarray, with at most one element being removed. A subarray is a contiguous part of an array. Note that you may not remove more than one element, and you may choose not to remove any elements at all.\nAnswer:\nLet...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5468, "level": 1, "question": "Given an array of integers, find the maximum possible sum of a non-empty subarray, with at most one element being removed. A subarray is a contiguous part of an array. Note that you may not remove more than one element, and you may choose not to remove...
def row_with_max_sum(mat): max_sum = sum(mat[0]) max_index = 0 for i in range(1, len(mat)): current_sum = sum(mat[i]) if current_sum > max_sum: max_sum = current_sum max_index = i return max_index
simplelr_Leetcode
[ { "content": "Question:\nGiven a matrix `mat` of size `n x m` consisting of non-negative integers, you are tasked with finding the row which has the maximum sum of its elements and returning the index of that row. If there are multiple rows with the same maximum sum, return the index of the first such row. The ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5469, "level": 1, "question": "Given a matrix `mat` of size `n x m` consisting of non-negative integers, you are tasked with finding the row which has the maximum sum of its elements and returning the index of that row. If there are multiple rows with the same maximum sum, return th...
def count_homogeneous_substrings(s): if not s: return 0 total = 0 current_char = s[0] count = 1 for c in s[1:]: if c == current_char: count += 1 else: total += count * (count + 1) // 2 current_char = c count = 1 total += cou...
simplelr_Leetcode
[ { "content": "Question:\n```markdown\n[Question 4]: You are given a string `s` consisting of lowercase English letters. A **substring** is called a **homogeneous substring** if all the characters of the substring are the same. Return the number of **homogeneous substrings** in `s`.\n\n**Note**:\n* A **substring...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5470, "level": 1, "question": "```markdown\n[Question 4]: You are given a string `s` consisting of lowercase English letters. A **substring** is called a **homogeneous substring** if all the characters of the substring are the same. Return the number of **homogeneous substrings** in...
def rotate_matrix_90_clockwise(matrix): if not matrix: return [] return [[row[j] for row in reversed(matrix)] for j in range(len(matrix[0]))]
simplelr_Filter
[ { "content": "Question:\nGiven a matrix, write a function to rotate it 90 degrees clockwise.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5471, "level": 1, "question": "Given a matrix, write a function to rotate it 90 degrees clockwise.", "split": "train" }
import string def count_unique_words(s): s_lower = s.lower() words = s_lower.split() unique_words = set() for word in words: stripped = word.strip(string.punctuation) if stripped: unique_words.add(stripped) return len(unique_words)
simplelr_Prefill
[ { "content": "Question:\nWrite a function to count the number of unique words in a given string. The function should be case-insensitive and should ignore any punctuation marks.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5472, "level": 1, "question": "Write a function to count the number of unique words in a given string. The function should be case-insensitive and should ignore any punctuation marks.", "split": "train" }
def parse_square_nums(input_nums): """ This function takes a list of integers as input, creates a new list with the square of each number, and returns the new list. Args: input_nums (list): A list of integers. Returns: list: A list of squared integers. """ return [num...
simplelr_Filter
[ { "content": "Question:\nfunction parse_square_nums(input_nums):\n \"\"\"\n This function takes a list of integers as input, \n creates a new list with the square of each number, \n and returns the new list.\n\n Args:\n input_nums (list): A list of integers.\n\n Returns:\n list: ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5473, "level": 1, "question": "function parse_square_nums(input_nums):\n \"\"\"\n This function takes a list of integers as input, \n creates a new list with the square of each number, \n and returns the new list.\n\n Args:\n input_nums (list): A list of intege...
from collections import deque def min_distance_obstacle(grid): """ Calculate the minimum distance from each cell to the nearest obstacle in a 1D grid. Args: grid (list): A 1D grid where negative values are obstacles and non-negative values are free cells. Returns: list: A list of mini...
simplelr_Filter
[ { "content": "Question:\nI have an array of numbers representing a 1D grid where some numbers are obstacles (negative numbers), and other numbers are free (positive numbers). I need to find the minimum distance from each cell to the nearest obstacle. If a cell is an obstacle, then the distance is 0.\n\nHere is ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5474, "level": 1, "question": "I have an array of numbers representing a 1D grid where some numbers are obstacles (negative numbers), and other numbers are free (positive numbers). I need to find the minimum distance from each cell to the nearest obstacle. If a cell is an obstacle, ...
def calculate_total(quarters, dimes, nickels): return (quarters * 25 + dimes * 10 + nickels * 5) / 100
simplelr_Prefill
[ { "content": "Question:\nWrite a function to calculate the total amount of money in a piggy bank given the number of quarters, dimes, and nickels.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5475, "level": 1, "question": "Write a function to calculate the total amount of money in a piggy bank given the number of quarters, dimes, and nickels.", "split": "train" }
def rearrange_array(nums, pivot): less = [] equal = [] greater = [] for num in nums: if num < pivot: less.append(num) elif num == pivot: equal.append(num) else: greater.append(num) return less + equal + greater
simplelr_Leetcode
[ { "content": "Question:\nYou are given an array of integers `nums` and an integer `pivot`. Your task is to rearrange the elements in the array such that all elements less than the pivot appear before all elements equal to the pivot, and those appear before all elements greater than the pivot. The relative order...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5476, "level": 1, "question": "You are given an array of integers `nums` and an integer `pivot`. Your task is to rearrange the elements in the array such that all elements less than the pivot appear before all elements equal to the pivot, and those appear before all elements greater...
def calculate_net_salary(gross_salary: float, total_deductions: float, total_bonuses: float) -> float: """ This function calculates the net salary by considering the gross salary, deductions, and bonuses. Arguments: gross_salary (float): The gross salary of the employee. total_deductions (float): T...
simplelr_Algorithm
[ { "content": "Question:\n### Question Style\n\n#### Context\nYou have been hired to create a module for a basic payroll system. One of the core functionalities requires calculating the net salary of employees after applying deductions and bonuses. \n\n#### Task\nImplement a function that computes the net salary...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5477, "level": 1, "question": "### Question Style\n\n#### Context\nYou have been hired to create a module for a basic payroll system. One of the core functionalities requires calculating the net salary of employees after applying deductions and bonuses. \n\n#### Task\nImplement a fu...
from collections import defaultdict def max_active_users(events: list[tuple[int, int]], duration: int) -> int: user_events = defaultdict(list) for user_id, ts in events: user_events[user_id].append(ts) activation_intervals = [] for user_id, ts_list in user_events.items(): ts_list.s...
simplelr_Codeforces
[ { "content": "Question:\nA large company processes a vast amount of data every day. One of their tasks is to analyze user activity on their platform. Each user event is logged with a timestamp, and the task is to find the maximum number of distinct users that are simultaneously active at any given time. The eve...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5478, "level": 1, "question": "A large company processes a vast amount of data every day. One of their tasks is to analyze user activity on their platform. Each user event is logged with a timestamp, and the task is to find the maximum number of distinct users that are simultaneousl...
def fibonacci_squares(n: int) -> list: if n == 0: return [] a, b = 0, 1 result = [a ** 2] if n == 1: return result result.append(b ** 2) if n == 2: return result for _ in range(2, n): c = a + b result.append(c ** 2) a = b b = c retu...
simplelr_Data_Structure
[ { "content": "Question:\n### Problem: Generating Fibonacci Squares Sequence\n\nYou are given an integer `n` which represents the number of terms in a sequence where each term is the square of Fibonacci numbers. Your task is to implement a function that generates the first `n` terms of this sequence.\n\nThe Fibo...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5479, "level": 1, "question": "### Problem: Generating Fibonacci Squares Sequence\n\nYou are given an integer `n` which represents the number of terms in a sequence where each term is the square of Fibonacci numbers. Your task is to implement a function that generates the first `n` ...
def length_of_longest_unique_substring(s): if not isinstance(s, str): raise TypeError("The input must be a string.") left = 0 max_length = 0 current_set = set() for right in range(len(s)): while s[right] in current_set: current_set.remove(s[left]) le...
simplelr_Algorithm
[ { "content": "Question:\n### Coding Assessment Question\n\n#### Context\nYou are working on a system that deals with words and their transformations. One common task is to determine the length of the longest substring of a word that contains only unique characters.\n\n#### Problem Description\nWrite a function ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5480, "level": 1, "question": "### Coding Assessment Question\n\n#### Context\nYou are working on a system that deals with words and their transformations. One common task is to determine the length of the longest substring of a word that contains only unique characters.\n\n#### Pro...
def replace_digits_with_words(text): digit_map = { '0': 'zero', '1': 'one', '2': 'two', '3': 'three', '4': 'four', '5': 'five', '6': 'six', '7': 'seven', '8': 'eight', '9': 'nine' } result = [] for char in text: if c...
simplelr_Apps
[ { "content": "Question:\nCreate a function that takes a string consisting of text and digits and returns a new string where each digit is replaced by its corresponding English word in lowercase. Ensure that the function maintains the original order of characters and handles all digits from `0` to `9`.\n\nExampl...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5481, "level": 1, "question": "Create a function that takes a string consisting of text and digits and returns a new string where each digit is replaced by its corresponding English word in lowercase. Ensure that the function maintains the original order of characters and handles al...
import json def calculate_order_total(items, discount): try: # Validate inputs if not isinstance(items, list) or not all(isinstance(item, dict) for item in items): return json.dumps({"error": "Invalid items format"}), 400 if not isinstance(discount, (int, float)) or dis...
simplelr_Package
[ { "content": "Question:\nYou are required to implement a function `calculate_order_total` that calculates the total price of an order, including any applicable discounts. Your function will receive two inputs: `items` (a list of dictionaries where each dictionary represents an item with `name`, `quantity`, and ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5482, "level": 1, "question": "You are required to implement a function `calculate_order_total` that calculates the total price of an order, including any applicable discounts. Your function will receive two inputs: `items` (a list of dictionaries where each dictionary represents an...
def count_greater_than_threshold(array, threshold): count = 0 for num in array: if num > threshold: count += 1 return count
simplelr_Prefill
[ { "content": "Question:\nWrite a function to count the number of elements in an array that are greater than a given threshold. The array and threshold should be provided as parameters. Here, I want the function to work specifically with integer arrays.\nAnswer:\nLet's think step by step.\n", "role": "user" ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5483, "level": 1, "question": "Write a function to count the number of elements in an array that are greater than a given threshold. The array and threshold should be provided as parameters. Here, I want the function to work specifically with integer arrays.", "split": "train" }
def find_first_non_repeating_char(s: str) -> str: if not s: return '_' counts = {} for char in s: counts[char] = counts.get(char, 0) + 1 for char in s: if counts[char] == 1: return char return '_'
simplelr_Algorithm
[ { "content": "Question:\n### Problem Statement\nWrite a function `find_first_non_repeating_char` that identifies the first non-repeating character in a given string. If all characters are repeating, the function should return an underscore ('_'). The function should be case-sensitive.\n\n### Function Signature\...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5484, "level": 1, "question": "### Problem Statement\nWrite a function `find_first_non_repeating_char` that identifies the first non-repeating character in a given string. If all characters are repeating, the function should return an underscore ('_'). The function should be case-se...
def alternate_case(s): result = "" for index, char in enumerate(s): if index % 2 == 0: result += char.upper() else: result += char.lower() return result
simplelr_Prefill
[ { "content": "Question:\nWrite a python function to create a string with alternating uppercase and lowercase letters based on a given string.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5485, "level": 1, "question": "Write a python function to create a string with alternating uppercase and lowercase letters based on a given string.", "split": "train" }
import seaborn as sns import seaborn.objects as so def create_custom_plots(): # Load and manipulate the data glue = ( sns.load_dataset("glue") .pivot(index=["Model", "Encoder"], columns="Task", values="Score") .reset_index() # Ensure 'Model' and 'Encoder' are columns for plotting ...
simplelr_Docs
[ { "content": "Question:\n### Seaborn Coding Assessment\n\n**Objective:**\nWrite a Python function that creates a custom Seaborn plot using the `seaborn.objects` interface. The plot should demonstrate your ability to manipulate data and incorporate various text and bar annotations with custom alignment and styli...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5486, "level": 1, "question": "### Seaborn Coding Assessment\n\n**Objective:**\nWrite a Python function that creates a custom Seaborn plot using the `seaborn.objects` interface. The plot should demonstrate your ability to manipulate data and incorporate various text and bar annotati...
def product_except_self(arr): n = len(arr) prefix = [1] * n for i in range(1, n): prefix[i] = prefix[i-1] * arr[i-1] suffix = [1] * n for i in range(n-2, -1, -1): suffix[i] = suffix[i+1] * arr[i+1] return [prefix[i] * suffix[i] for i in range(n)]
simplelr_Apps
[ { "content": "Question:\nComplete the function that takes an array of integers and returns a new array where each element is the product of all the elements in the original array except for the element at the same index.\n\nAssume: The array has at least two elements, and all elements are integers.\n\n## Exampl...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5487, "level": 1, "question": "Complete the function that takes an array of integers and returns a new array where each element is the product of all the elements in the original array except for the element at the same index.\n\nAssume: The array has at least two elements, and all ...
def max_subarray_sum(nums): if not nums: return (0, []) max_sum = float('-inf') current_sum = 0 current_start = 0 current_end = 0 max_start = 0 max_end = 0 for i, num in enumerate(nums): if current_sum + num < num: current_sum = num current_s...
simplelr_Filter
[ { "content": "Question:\nGiven an array of integers, find the maximum sum of a subarray within the array.\n\nExample:\nInput: [-2, 1, -3, 4, -1, 2, 1, -5, 4]\nOutput: 6\nExplanation: The subarray [4, -1, 2, 1] has the maximum sum of 6.\n\nConstraints:\n- The array can contain both positive and negative integers...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5488, "level": 1, "question": "Given an array of integers, find the maximum sum of a subarray within the array.\n\nExample:\nInput: [-2, 1, -3, 4, -1, 2, 1, -5, 4]\nOutput: 6\nExplanation: The subarray [4, -1, 2, 1] has the maximum sum of 6.\n\nConstraints:\n- The array can contain ...
from typing import List def max_square_submatrix(matrix: List[List[int]]) -> int: if not matrix or not matrix[0]: return 0 rows = len(matrix) cols = len(matrix[0]) dp = [[0] * cols for _ in range(rows)] max_side = 0 for i in range(rows): for j in range(cols): if matr...
simplelr_Algorithm
[ { "content": "Question:\n### Problem Statement\n\nYou are given a binary matrix where each cell contains either a `0` or a `1`. Your task is to write a function `max_square_submatrix` that finds the size of the largest square submatrix that contains only `1`s.\n\n### Input\n\n- A list of lists `matrix` where ea...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5489, "level": 1, "question": "### Problem Statement\n\nYou are given a binary matrix where each cell contains either a `0` or a `1`. Your task is to write a function `max_square_submatrix` that finds the size of the largest square submatrix that contains only `1`s.\n\n### Input\n\n...
def fibonacci_sequence(n): if n == 0: return [] elif n == 1: return [0] else: fib_sequence = [0, 1] for i in range(2, n): next_term = fib_sequence[i-1] + fib_sequence[i-2] fib_sequence.append(next_term) return fib_sequence
simplelr_Prefill
[ { "content": "Question:\nCreate a function that generates a sequence of Fibonacci numbers up to the n-th term in Python. The function should take an integer `n` as an argument and return a list containing the Fibonacci sequence up to the n-th term.\nAnswer:\nLet's think step by step.\n", "role": "user" } ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5490, "level": 1, "question": "Create a function that generates a sequence of Fibonacci numbers up to the n-th term in Python. The function should take an integer `n` as an argument and return a list containing the Fibonacci sequence up to the n-th term.", "split": "train" }
def calculate_power_dissipated(voltage, resistance): power = (voltage ** 2) / resistance return round(power, 3)
simplelr_Apps
[ { "content": "Question:\nWrite a function to calculate the power dissipated in a resistor. The function should take two inputs: the voltage across the resistor (in volts) and the resistance of the resistor (in ohms), and it should return the power dissipated (in watts) rounded to three decimal places. \n\nThe f...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5491, "level": 1, "question": "Write a function to calculate the power dissipated in a resistor. The function should take two inputs: the voltage across the resistor (in volts) and the resistance of the resistor (in ohms), and it should return the power dissipated (in watts) rounded...
def hasTwoSum(arr, target): seen = set() for num in arr: complement = target - num if complement in seen: return True seen.add(num) return False
simplelr_Taco
[ { "content": "Question:\nGiven an integer array `arr` and an integer `target`, check if there are two distinct indices `i` and `j` in the array such that `arr[i] + arr[j]` is equal to `target`. Return true if such indices exist, otherwise return false.\n\nExample 1:\nInput: arr = [1, 2, 3, 4], target = 5\nOutpu...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5492, "level": 1, "question": "Given an integer array `arr` and an integer `target`, check if there are two distinct indices `i` and `j` in the array such that `arr[i] + arr[j]` is equal to `target`. Return true if such indices exist, otherwise return false.\n\nExample 1:\nInput: ar...
def transpose_matrix(matrix: list[list[int]]) -> list[list[int]]: # Validate the matrix if not matrix: raise ValueError("Matrix is empty") num_cols = len(matrix[0]) for row in matrix: if len(row) != num_cols: raise ValueError("All rows must have the same length") ...
simplelr_Package
[ { "content": "Question:\nYou are tasked with creating a Python function named `transpose_matrix` that takes a matrix (a list of lists) as input and returns the transpose of the matrix. The transpose of a matrix is obtained by swapping the rows and columns.\n\n### Function Signature:\n```python\ndef transpose_ma...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5493, "level": 1, "question": "You are tasked with creating a Python function named `transpose_matrix` that takes a matrix (a list of lists) as input and returns the transpose of the matrix. The transpose of a matrix is obtained by swapping the rows and columns.\n\n### Function Sign...
def find_pair_with_sum(nums: list[int], target: int) -> tuple[int, int] | None: seen = {} for num in nums: complement = target - num if complement in seen: return (complement, num) seen[num] = True return None # Example usage if __name__ == "__main__": print(find_pai...
simplelr_Algorithm
[ { "content": "Question:\n### Question:\n\n### Description:\nYou are provided with a list of integers and a target sum. Your goal is to determine whether any two integers in the list add up to the target sum. If so, return the pair as a tuple. If multiple pairs exist, return any one of them. If no such pair exis...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5494, "level": 1, "question": "### Question:\n\n### Description:\nYou are provided with a list of integers and a target sum. Your goal is to determine whether any two integers in the list add up to the target sum. If so, return the pair as a tuple. If multiple pairs exist, return an...
def has_unique_characters(s): for char in s: if s.count(char) > 1: return False return True
simplelr_Filter
[ { "content": "Question:\nCan you provide me with a Python function to check if a given string contains all unique characters without using any additional data structures?\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5495, "level": 1, "question": "Can you provide me with a Python function to check if a given string contains all unique characters without using any additional data structures?", "split": "train" }
def priority_selection_sort(tasks): """ Sorts a list of tasks based on their specified priorities using selection sort. Args: - tasks (list of tuple): A list where each tuple is (task_id, priority). Returns: - list of tuple: The sorted list of tasks based on priority. """ arr =...
simplelr_Data_Structure
[ { "content": "Question:\n#### Scenario\nYou are a software engineer tasked with improving system performance for handling priority tasks. An integral part of this involves optimizing how a list of tasks (with associated priorities) is sorted before execution.\n\n#### Problem Statement\nImplement the `priority_s...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5496, "level": 1, "question": "#### Scenario\nYou are a software engineer tasked with improving system performance for handling priority tasks. An integral part of this involves optimizing how a list of tasks (with associated priorities) is sorted before execution.\n\n#### Problem S...
def kth_smallest(matrix, k): n = len(matrix) if n == 0: return None # assuming matrix is non-empty as per problem statement low = matrix[0][0] high = matrix[n-1][n-1] while low < high: mid = (low + high) // 2 count = 0 for row in matrix: # Binary sea...
simplelr_Leetcode
[ { "content": "Question:\nGiven an `n x n` matrix where every row and column is sorted in ascending order, write a function to find the `kth` smallest element in the matrix. The matrix is structured in a way that the smallest element is at the top-left corner and the largest element is at the bottom-right corner...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5497, "level": 1, "question": "Given an `n x n` matrix where every row and column is sorted in ascending order, write a function to find the `kth` smallest element in the matrix. The matrix is structured in a way that the smallest element is at the top-left corner and the largest el...
def unique_elements_with_counts(A, B): a_counts = {} for x in A: if x in a_counts: a_counts[x] += 1 else: a_counts[x] = 1 b_counts = {} for y in B: if y in b_counts: b_counts[y] += 1 else: b_counts[y] = 1 result = [] ...
simplelr_Filter
[ { "content": "Question:\nGiven two lists, list A and list B, which may contain duplicates, write a Python function to find the unique elements that appear in both lists. However, the output should be in the form of a list of tuples where each tuple represents an element and the number of times it occurs in both...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5498, "level": 1, "question": "Given two lists, list A and list B, which may contain duplicates, write a Python function to find the unique elements that appear in both lists. However, the output should be in the form of a list of tuples where each tuple represents an element and th...
def is_ascending(lst): if len(lst) <= 1: return True for i in range(len(lst) - 1): if lst[i] > lst[i + 1]: return False return True
simplelr_Filter
[ { "content": "Question:\nCreate a Python function that checks if a list of numerical values is in ascending order. This function should also manage lists that contain both integers and floating point numbers, and it should be able to handle the presence of negative numbers and zero.\nAnswer:\nLet's think step b...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5499, "level": 1, "question": "Create a Python function that checks if a list of numerical values is in ascending order. This function should also manage lists that contain both integers and floating point numbers, and it should be able to handle the presence of negative numbers and...