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 array_strings_are_equal(word1, word2): return ''.join(word1) == ''.join(word2)
simplelr_Leetcode
[ { "content": "Question:\n[Question] 4: You are given two arrays of strings `word1` and `word2`. Return _`true` if the two arrays represent the same string, and `false` otherwise_. A string is represented by an array if the elements of the array are concatenated in order to form a single string.\nAnswer:\nLet's ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8900, "level": 1, "question": "[Question] 4: You are given two arrays of strings `word1` and `word2`. Return _`true` if the two arrays represent the same string, and `false` otherwise_. A string is represented by an array if the elements of the array are concatenated in order to for...
from sklearn.preprocessing import MinMaxScaler def normalize_features(data, feature_range=(0, 1)): scaler = MinMaxScaler(feature_range=feature_range) normalized_data = scaler.fit_transform(data) return normalized_data
simplelr_Package
[ { "content": "Question:\nYou are required to write a Python function that normalizes (scales) the features of a given dataset using Min-Max Scaling technique. The function will take in the dataset and the range into which the features should be scaled. This function should use the `MinMaxScaler` from `sklearn.p...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8901, "level": 1, "question": "You are required to write a Python function that normalizes (scales) the features of a given dataset using Min-Max Scaling technique. The function will take in the dataset and the range into which the features should be scaled. This function should use...
def longestEvenSubstring(s): max_length = 0 current_mask = 0 first_occurrence = {0: -1} for j in range(len(s)): current_mask ^= 1 << (ord(s[j]) - ord('a')) if current_mask in first_occurrence: length = j - first_occurrence[current_mask] if length > max_length: ...
simplelr_Leetcode
[ { "content": "Question:\nGiven a string `s` containing only lowercase letters, you need to find the length of the longest substring where every character appears an even number of times. If no such substring exists, return `0`. Write a function `longestEvenSubstring(s)` that returns this length.\nAnswer:\nLet's...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8902, "level": 1, "question": "Given a string `s` containing only lowercase letters, you need to find the length of the longest substring where every character appears an even number of times. If no such substring exists, return `0`. Write a function `longestEvenSubstring(s)` that r...
def sum_of_squares(lst): sum_sq = 0 for x in lst: if type(x) not in (int, float): return None sum_sq += x ** 2 return sum_sq
simplelr_Filter
[ { "content": "Question:\nGiven the following snippet of code in Python, identify the errors, fix them and then modify the function to calculate the sum of squares of elements in a list. If you get a list that contains non-integer or non-float values, your function should return None.\nAnswer:\nLet's think step ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8903, "level": 1, "question": "Given the following snippet of code in Python, identify the errors, fix them and then modify the function to calculate the sum of squares of elements in a list. If you get a list that contains non-integer or non-float values, your function should retur...
def remove_element(lst, element): return [x for x in lst if x != element]
simplelr_Filter
[ { "content": "Question:\nWrite a Python function to remove a specific element from a list using functional programming concepts. You are not allowed to use any built-in functions or methods that directly delete elements from a list.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8904, "level": 1, "question": "Write a Python function to remove a specific element from a list using functional programming concepts. You are not allowed to use any built-in functions or methods that directly delete elements from a list.", "split": "train" }
from collections import Counter def are_anagrams(text1: str, text2: str) -> bool: if len(text1) != len(text2): return False return Counter(text1.lower()) == Counter(text2.lower())
simplelr_Algorithm
[ { "content": "Question:\n### Coding Assessment Question\n\n**Scenario**:\nYou have been assigned to create software for filtering duplicate text entries in a large dataset. Your system will have to identify if two given text entries are anagrams of each other, meaning they contain the same characters but in a d...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8905, "level": 1, "question": "### Coding Assessment Question\n\n**Scenario**:\nYou have been assigned to create software for filtering duplicate text entries in a large dataset. Your system will have to identify if two given text entries are anagrams of each other, meaning they con...
def filter_divisible_by_three(nums): return [num for num in nums if num % 3 == 0]
simplelr_Prefill
[ { "content": "Question:\nCreate a function that takes a list of integers and returns a new list containing only the integers that are divisible by 3.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8906, "level": 1, "question": "Create a function that takes a list of integers and returns a new list containing only the integers that are divisible by 3.", "split": "train" }
def find_intersection(list1, list2): return list(set(list1) & set(list2)) list1 = [1, 2, 3, 4, 5] list2 = [4, 5, 6, 7, 8] print(find_intersection(list1, list2))
simplelr_Filter
[ { "content": "Question:\ndef find_intersection(list1, list2):\n return list(set(list1) & set(list2))\n\nlist1 = [1, 2, 3, 4, 5]\nlist2 = [4, 5, 6, 7, 8]\nprint(find_intersection(list1, list2))\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8907, "level": 1, "question": "def find_intersection(list1, list2):\n return list(set(list1) & set(list2))\n\nlist1 = [1, 2, 3, 4, 5]\nlist2 = [4, 5, 6, 7, 8]\nprint(find_intersection(list1, list2))", "split": "train" }
import re def count_unique_words(text): ''' This function counts the number of unique words in the given text. Parameters: text (str): A string containing the text to be analyzed. Returns: int: The count of unique words in the text. ''' # Convert the text to lower case to handle case ...
simplelr_Package
[ { "content": "Question:\nYou are tasked with writing a function that counts the number of unique words in a given text. For this purpose, a \"word\" is defined as any sequence of alphanumeric characters (letters and digits), separated by spaces or punctuation. Your function should ignore case, meaning that \"Wo...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8908, "level": 1, "question": "You are tasked with writing a function that counts the number of unique words in a given text. For this purpose, a \"word\" is defined as any sequence of alphanumeric characters (letters and digits), separated by spaces or punctuation. Your function sh...
def decode_string(encoded_str: str) -> str: stack = [] current_str = '' current_num = 0 for char in encoded_str: if char.isdigit(): current_num = current_num * 10 + int(char) elif char == '[': stack.append((current_str, current_num)) current_str = '' ...
simplelr_Apps
[ { "content": "Question:\nYou are given an encoded string where each character can be multiple consecutive repetitions of substrings. For example, '3[a2[c]]' means 'acccacccaccc'. Write a function to decode such strings.\n\nFunction Signature:\n`def decode_string(encoded_str: str) -> str:`\n\n### Input\n- `encod...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8909, "level": 1, "question": "You are given an encoded string where each character can be multiple consecutive repetitions of substrings. For example, '3[a2[c]]' means 'acccacccaccc'. Write a function to decode such strings.\n\nFunction Signature:\n`def decode_string(encoded_str: s...
def find_common_elements(list1, list2): return sorted(set(list1) & set(list2))
simplelr_Package
[ { "content": "Question:\nYou are to write a Python function named `find_common_elements(list1, list2)` which takes two arguments:\n- `list1` (List[int]): A list of integers.\n- `list2` (List[int]): Another list of integers.\n\nThe function's purpose is to find and return a sorted list of unique elements that ap...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8910, "level": 1, "question": "You are to write a Python function named `find_common_elements(list1, list2)` which takes two arguments:\n- `list1` (List[int]): A list of integers.\n- `list2` (List[int]): Another list of integers.\n\nThe function's purpose is to find and return a sor...
from typing import List def find_min_path_sum(grid: List[List[int]]) -> int: if not grid or not grid[0]: return 0 n = len(grid) m = len(grid[0]) if n == 1 and m == 1: return grid[0][0] prev_row = [0] * m prev_row[0] = grid[0][0] for j in range(1, m): prev_row[j]...
simplelr_Algorithm
[ { "content": "Question:\n### Coding Question: Optimized Pathfinding in a Weighted Grid\n\n**Objective**: Write a function that finds the shortest path from the top-left corner to the bottom-right corner of a grid where each cell contains a positive integer weight, ensuring efficient performance for larger grids...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8911, "level": 1, "question": "### Coding Question: Optimized Pathfinding in a Weighted Grid\n\n**Objective**: Write a function that finds the shortest path from the top-left corner to the bottom-right corner of a grid where each cell contains a positive integer weight, ensuring eff...
def min_add_to_make_valid(s: str) -> int: required_left = 0 balance = 0 for char in s: if char == '(': balance += 1 else: balance -= 1 if balance < 0: required_left += 1 balance = 0 required_right = balance return required_left ...
simplelr_Algorithm
[ { "content": "Question:\n### Problem Statement\n\nYou are given a string `s` containing only the characters `'('` and `')'`. The goal is to determine the minimum number of parentheses that need to be added to make the string valid. A string of parentheses is considered valid if every opening parenthesis has a c...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8912, "level": 1, "question": "### Problem Statement\n\nYou are given a string `s` containing only the characters `'('` and `')'`. The goal is to determine the minimum number of parentheses that need to be added to make the string valid. A string of parentheses is considered valid i...
def second_smallest(lst): unique = list(set(lst)) if len(unique) < 2: raise ValueError("The list must contain at least two unique elements.") unique_sorted = sorted(unique) return unique_sorted[1]
simplelr_Filter
[ { "content": "Question:\nWrite a Python function that finds the second smallest element in an unsorted list of integers. The function should return the second smallest unique element. If the list does not contain at least two unique elements, the function should raise a ValueError.\nAnswer:\nLet's think step by...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8913, "level": 1, "question": "Write a Python function that finds the second smallest element in an unsorted list of integers. The function should return the second smallest unique element. If the list does not contain at least two unique elements, the function should raise a ValueE...
def replace_flagged_words(sentence: str, indices: list[int]) -> str: words = sentence.split() indices_set = set(indices) for i in range(len(words)): if i in indices_set: words[i] = "[REDACTED]" return ' '.join(words)
simplelr_Filter
[ { "content": "Question:\nHi, I have a list of indices of words in a sentence that have been flagged to be replaced. \nMy goal is to replace these words in the sentence with a placeholder (e.g. \"[REDACTED]\") in the most efficient way. \n\nThe goal would be to achieve an average time complexity of O(n), where n...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8914, "level": 1, "question": "Hi, I have a list of indices of words in a sentence that have been flagged to be replaced. \nMy goal is to replace these words in the sentence with a placeholder (e.g. \"[REDACTED]\") in the most efficient way. \n\nThe goal would be to achieve an avera...
import re def analyze_log(log: str) -> dict: result = { "error_times": [], "user_actions": {}, "total_uploads": 0, "fixed_log": [] # To collect each processed line } pattern = re.compile(r'^\[(\d{2}:\d{2}:\d{2})\] User: (\w+) Action: (.+)$') lines = log.strip().split('...
simplelr_Docs
[ { "content": "Question:\n### Objective:\nDesign a function that analyzes and processes a log of user activity to extract certain types of information based on specified patterns.\n\n### Problem Statement:\nYou are given a log containing entries of user activities. Each entry is in the format:\n```\n[HH:MM:SS] U...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8915, "level": 1, "question": "### Objective:\nDesign a function that analyzes and processes a log of user activity to extract certain types of information based on specified patterns.\n\n### Problem Statement:\nYou are given a log containing entries of user activities. Each entry i...
def alternating_sort(arr: list[int]) -> list[int]: sorted_arr = sorted(arr) result = [] left = 0 right = len(sorted_arr) - 1 while left <= right: result.append(sorted_arr[right]) if left != right: result.append(sorted_arr[left]) left += 1 right -= 1 re...
simplelr_Algorithm
[ { "content": "Question:\n### Problem Statement:\nYou are required to write a function that takes a list of integers and returns the list sorted in alternating order such that the first element is the largest, the second element is the smallest, the third element is the second largest, the fourth element is the ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8916, "level": 1, "question": "### Problem Statement:\nYou are required to write a function that takes a list of integers and returns the list sorted in alternating order such that the first element is the largest, the second element is the smallest, the third element is the second ...
def fizz_buzz(n): for i in range(1, n + 1): if i % 3 == 0 and i % 5 == 0: print("FizzBuzz") elif i % 3 == 0: print("Fizz") elif i % 5 == 0: print("Buzz") else: print(i)
simplelr_Prefill
[ { "content": "Question:\nCreate a function that takes an integer as an input and prints \"FizzBuzz\" for multiples of three and five, \"Fizz\" for multiples of three, \"Buzz\" for multiples of five, and the number itself for all other numbers. Here's the challenge: you should only use a for loop to accomplish t...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8917, "level": 1, "question": "Create a function that takes an integer as an input and prints \"FizzBuzz\" for multiples of three and five, \"Fizz\" for multiples of three, \"Buzz\" for multiples of five, and the number itself for all other numbers. Here's the challenge: you should ...
def dijkstra(vertex_count, edges, src): # Build adjacency list adj = [[] for _ in range(vertex_count)] for u, v, w in edges: adj[u].append((v, w)) import heapq INF = float('inf') dist = [INF] * vertex_count dist[src] = 0 heap = [] heapq.heappush(heap, (0, src)) ...
simplelr_Data_Structure
[ { "content": "Question:\n### Question: Dijkstra's Algorithm Implementation with Priority Queue\n\nYou are given a weighted, directed graph represented by an adjacency list. Implement Dijkstra's algorithm to find the shortest path from a given source node to all other nodes using a priority queue for efficient m...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8918, "level": 1, "question": "### Question: Dijkstra's Algorithm Implementation with Priority Queue\n\nYou are given a weighted, directed graph represented by an adjacency list. Implement Dijkstra's algorithm to find the shortest path from a given source node to all other nodes usi...
def count_unique_characters(s): return len(set(s))
simplelr_Prefill
[ { "content": "Question:\nWrite a python function to count the number of unique characters that appear in a string. The function should be case-sensitive, meaning that 'A' and 'a' would be considered two different characters.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8919, "level": 1, "question": "Write a python function to count the number of unique characters that appear in a string. The function should be case-sensitive, meaning that 'A' and 'a' would be considered two different characters.", "split": "train" }
from sympy import pprint def common_elements(set1, set2): common = set1 & set2 pprint(common)
simplelr_Package
[ { "content": "Question:\nYou are tasked with creating a function that finds the common elements between two symbolic sets and prints the resulting set in a human-readable, pretty-printed format using the `sympy.pprint` library.\n\nWrite a function named `common_elements(set1, set2)` that:\n\n1. Takes two parame...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8920, "level": 1, "question": "You are tasked with creating a function that finds the common elements between two symbolic sets and prints the resulting set in a human-readable, pretty-printed format using the `sympy.pprint` library.\n\nWrite a function named `common_elements(set1, ...
def sum_of_integers(lst): return sum(lst)
simplelr_Prefill
[ { "content": "Question:\nCreate a function that adds up integers from a list to find the sum.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8921, "level": 1, "question": "Create a function that adds up integers from a list to find the sum.", "split": "train" }
def reverse_integer(x): sign = 1 if x < 0: sign = -1 abs_x = abs(x) reversed_num = int(str(abs_x)[::-1]) result = sign * reversed_num if result < -2**31 or result > 2**31 - 1: return 0 else: return result
simplelr_Prefill
[ { "content": "Question:\nWrite a python function to reverse the digits of a given integer. For example, if the input is -123, the output should be -321. If the reversed integer overflows (i.e., it is outside the range [-2^31, 2^31 - 1]), return 0.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8922, "level": 1, "question": "Write a python function to reverse the digits of a given integer. For example, if the input is -123, the output should be -321. If the reversed integer overflows (i.e., it is outside the range [-2^31, 2^31 - 1]), return 0.", "split": "train" }
def reverse_string(input_string): words = input_string.split() reversed_words = words[::-1] return ' '.join(reversed_words)
simplelr_Taco
[ { "content": "Question:\nWrite a function that takes a string as input and returns the string in reversed order. However, each word's internal character order should remain the same. \n\nFor example, given `input_string` as `\"hello world this is an example\"`, the function should return `\"example an is this w...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8923, "level": 1, "question": "Write a function that takes a string as input and returns the string in reversed order. However, each word's internal character order should remain the same. \n\nFor example, given `input_string` as `\"hello world this is an example\"`, the function sh...
from collections import deque def longest_subarray(nums, k): if not nums: return 0 max_len = 1 left = 0 max_deque = deque([0]) min_deque = deque([0]) for right in range(1, len(nums)): # Update max_deque while max_deque and nums[right] >= nums[max_deque[-1]]: ...
simplelr_Leetcode
[ { "content": "Question:\nYou are given an integer array `nums` and an integer `k`. A **continuous subarray** is defined as a subarray where the difference between the maximum and minimum values is at most `k`. Return _the length of the longest continuous subarray that meets this condition in_ `nums`. **Note:**...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8924, "level": 1, "question": "You are given an integer array `nums` and an integer `k`. A **continuous subarray** is defined as a subarray where the difference between the maximum and minimum values is at most `k`. Return _the length of the longest continuous subarray that meets th...
def binarySearch(A, X): low = 0 high = len(A) - 1 while low <= high: mid = (low + high) // 2 if A[mid] == X: return mid elif A[mid] < X: low = mid + 1 else: high = mid - 1 return -1
simplelr_Taco
[ { "content": "Question:\nYou have an array A of distinct integers sorted in ascending order and an integer X. You need to find the index of the element X in the array using binary search.\n\nExample 1:\nInput: A = [1, 3, 5, 7, 9, 11], X = 7\nOutput: 3\n\nExample 2:\nInput: A = [2, 4, 6, 8, 10, 12, 14], X = 5\nO...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8925, "level": 1, "question": "You have an array A of distinct integers sorted in ascending order and an integer X. You need to find the index of the element X in the array using binary search.\n\nExample 1:\nInput: A = [1, 3, 5, 7, 9, 11], X = 7\nOutput: 3\n\nExample 2:\nInput: A =...
def is_valid(s: str) -> bool: stack = [] matching = {')': '(', '}': '{', ']': '['} opening = {'(', '{', '['} for char in s: if char in opening: stack.append(char) else: if not stack: return False top = stack.pop() if top != ...
simplelr_Data_Structure
[ { "content": "Question:\n### Scenario\nYou are building a simple lightweight compiler for a custom scripting language. One of the essential tasks is to validate the correctness of the parentheses and brackets in expressions. Your compiler verifies the paired and ordered use of parentheses, curly braces, and squ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8926, "level": 1, "question": "### Scenario\nYou are building a simple lightweight compiler for a custom scripting language. One of the essential tasks is to validate the correctness of the parentheses and brackets in expressions. Your compiler verifies the paired and ordered use of...
def gcd(a: int, b: int) -> int: while b != 0: a, b = b, a % b return a
simplelr_Algorithm
[ { "content": "Question:\n### Coding Assessment: Compute Greatest Common Divisor (GCD)\n\n#### Context\nAs part of a mathematical toolkit, you are tasked with implementing a function to compute the Greatest Common Divisor (GCD) of two integers. The GCD is the largest integer that divides both numbers without lea...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8927, "level": 1, "question": "### Coding Assessment: Compute Greatest Common Divisor (GCD)\n\n#### Context\nAs part of a mathematical toolkit, you are tasked with implementing a function to compute the Greatest Common Divisor (GCD) of two integers. The GCD is the largest integer th...
import re def find_pattern(input_string, pattern, flags=0): """ Searches for all occurrences of a given regex pattern in the input string. Args: input_string (str): The string to search in. pattern (str): The regular expression pattern to match. flags (int, optional): Optional ...
simplelr_Filter
[ { "content": "Question:\nCreate a Python function that parses a given string for a specific pattern defined by a regular expression and returns all occurrences of this pattern in a list. If there is no match, the function should return an empty list.\nAnswer:\nLet's think step by step.\n", "role": "user" ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8928, "level": 1, "question": "Create a Python function that parses a given string for a specific pattern defined by a regular expression and returns all occurrences of this pattern in a list. If there is no match, the function should return an empty list.", "split": "train" }
def top_k_frequent_strings(words: list[str], k: int) -> list[str]: from collections import defaultdict # Count the frequency of each word freqs = defaultdict(int) for word in words: freqs[word] += 1 # Convert to a list of tuples (word, count) items = list(freqs.items()) # Sort by ...
simplelr_Algorithm
[ { "content": "Question:\n### Problem Statement\n\nYou are given a list of strings and an integer `k`. Your task is to implement a function that returns the `k` most frequent strings in the list. The returned result should be a list of the `k` most frequent strings sorted in descending order of their frequency. ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8929, "level": 1, "question": "### Problem Statement\n\nYou are given a list of strings and an integer `k`. Your task is to implement a function that returns the `k` most frequent strings in the list. The returned result should be a list of the `k` most frequent strings sorted in de...
from typing import List def shortest_to_target(s: str, target: str) -> List[int]: n = len(s) distances = [float('inf')] * n # Forward pass: find distance to the previous target last = -1 for i in range(n): if s[i] == target: distances[i] = 0 last = i else: ...
simplelr_Algorithm
[ { "content": "Question:\n## New Question:\n\n**Problem Statement:**\n\nYou are given a string and your goal is to determine the shortest distance from any character in the string to a target character specified. The function should take a string and a target character as input and return a list with each elemen...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8930, "level": 1, "question": "## New Question:\n\n**Problem Statement:**\n\nYou are given a string and your goal is to determine the shortest distance from any character in the string to a target character specified. The function should take a string and a target character as input...
def first_index_greater_than_ten(numbers): for index, value in enumerate(numbers): if value > 10: return index return -1
simplelr_Filter
[ { "content": "Question:\nI want to create a Python function that takes a list of numbers and returns the index of the first number greater than 10. Can you provide me with a simple Python function to achieve this?\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8931, "level": 1, "question": "I want to create a Python function that takes a list of numbers and returns the index of the first number greater than 10. Can you provide me with a simple Python function to achieve this?", "split": "train" }
def max_loot(houses: list[int]) -> int: if not houses: return 0 prev_rob = houses[0] prev_not_rob = 0 for i in range(1, len(houses)): current_rob = houses[i] + prev_not_rob current_not_rob = max(prev_rob, prev_not_rob) prev_rob, prev_not_rob = current_rob, current_not_rob...
simplelr_Data_Structure
[ { "content": "Question:\n### Problem: Maximum Loot Without Alerting Police\n\nYou are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, and the only constraint stopping you from robbing each of them is that adjacent houses have security systems connec...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8932, "level": 1, "question": "### Problem: Maximum Loot Without Alerting Police\n\nYou are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, and the only constraint stopping you from robbing each of them is that adjacent ...
def sum_of_even_numbers(lst): return sum(filter(lambda x: x % 2 == 0, lst))
simplelr_Filter
[ { "content": "Question:\nWrite a Python function that takes a list of integers and returns the sum of all the even numbers in the list. Use a lambda function inside the filter function to filter out the even numbers. Then, use the sum function to calculate the sum of the filtered even numbers. Test your functio...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8933, "level": 1, "question": "Write a Python function that takes a list of integers and returns the sum of all the even numbers in the list. Use a lambda function inside the filter function to filter out the even numbers. Then, use the sum function to calculate the sum of the filte...
from collections import Counter def most_frequent_element(nums): if not nums: return None count = Counter(nums) max_count = max(count.values()) candidates = [k for k, v in count.items() if v == max_count] return min(candidates)
simplelr_Prefill
[ { "content": "Question:\nWrite a function to find the element that appears most frequently in a list. If multiple elements have the same highest frequency, return the smallest one.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8934, "level": 1, "question": "Write a function to find the element that appears most frequently in a list. If multiple elements have the same highest frequency, return the smallest one.", "split": "train" }
def find_reachable_nodes(graph: dict, start_node: int) -> list: if not graph: raise ValueError("graph cannot be empty") if start_node not in graph: raise ValueError(f"start_node {start_node} is not present in the graph") stack = [start_node] visited = set() reachable = [] ...
simplelr_Algorithm
[ { "content": "Question:\n### Problem Statement\n\nYou are given an undirected graph represented as a dictionary where keys are node identifiers (integers) and values are lists of integers representing the nodes directly connected to the key node. Your task is to write a function that returns a list of all nodes...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8935, "level": 1, "question": "### Problem Statement\n\nYou are given an undirected graph represented as a dictionary where keys are node identifiers (integers) and values are lists of integers representing the nodes directly connected to the key node. Your task is to write a functi...
def is_last_char_alpha(s): return len(s) > 0 and s[-1].isalpha()
simplelr_Filter
[ { "content": "Question:\nIs there a quick way to determine if the last character of a string is a letter (a-z, A-Z) in Python? I found some solutions using regular expressions, but I'm wondering if there's a simpler method. Could adding a condition like `if type[-1] == str` help in identifying if the last chara...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8936, "level": 1, "question": "Is there a quick way to determine if the last character of a string is a letter (a-z, A-Z) in Python? I found some solutions using regular expressions, but I'm wondering if there's a simpler method. Could adding a condition like `if type[-1] == str` he...
def longest_subsequence_with_diff_two(nums): dp = {} max_length = 0 for num in nums: prev = num - 2 current_length = 1 if prev in dp: current_length = dp[prev] + 1 if num in dp: if current_length > dp[num]: dp[num] = current_length ...
simplelr_Apps
[ { "content": "Question:\nGiven an integer array nums, return the length of the longest strictly increasing subsequence of the integers in that array where the difference between consecutive integers is exactly 2.\nIf there is no such subsequence in the array, return 0.\n\nExample 1:\nInput: nums = [1, 3, 5, 7, ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8937, "level": 1, "question": "Given an integer array nums, return the length of the longest strictly increasing subsequence of the integers in that array where the difference between consecutive integers is exactly 2.\nIf there is no such subsequence in the array, return 0.\n\nExam...
def are_anagrams(a, b): str_a = str(a) str_b = str(b) return sorted(str_a) == sorted(str_b)
simplelr_Filter
[ { "content": "Question:\n### Question 1\n# Write a function that checks whether two given integers are anagrams of each other\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8938, "level": 1, "question": "### Question 1\n# Write a function that checks whether two given integers are anagrams of each other", "split": "train" }
def max_subarray_sum(arr): if not arr: return 0 # Return 0 for empty array, or raise an appropriate exception max_current = max_global = arr[0] for num in arr[1:]: max_current = max(num, max_current + num) if max_current > max_global: max_global = max_current ...
simplelr_Filter
[ { "content": "Question:\nWrite a Python code to solve the problem of finding the maximum sum of a subarray within a one-dimensional array of numbers, including negative numbers. This is known as the \"Maximum Subarray Problem\" or Kadane's Algorithm.\nAnswer:\nLet's think step by step.\n", "role": "user" ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8939, "level": 1, "question": "Write a Python code to solve the problem of finding the maximum sum of a subarray within a one-dimensional array of numbers, including negative numbers. This is known as the \"Maximum Subarray Problem\" or Kadane's Algorithm.", "split": "train" }
def can_reach_destination(operations): results = [] for op in operations: a, b, x, y, d = op D = abs(x - a) + abs(y - b) if D > d: results.append(False) else: results.append((d - D) % 2 == 0) return results
simplelr_Leetcode
[ { "content": "Question:\nYou are given a 2D integer array, `operations`. For each `operations[i]`, where `operations[i] = [ai, bi, x, y, d]`, you need to determine if it is possible to perform `d` steps, starting from a point `(ai, bi)` in a grid, such that you land on a point `(x, y)` exactly after `d` steps. ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8940, "level": 1, "question": "You are given a 2D integer array, `operations`. For each `operations[i]`, where `operations[i] = [ai, bi, x, y, d]`, you need to determine if it is possible to perform `d` steps, starting from a point `(ai, bi)` in a grid, such that you land on a point...
def sort_even_before_odd(lst): evens = sorted([x for x in lst if x % 2 == 0]) odds = sorted([x for x in lst if x % 2 != 0]) return evens + odds
simplelr_Evol
[ { "content": "Question:\nWrite a function that takes a list of integers as input and returns the list sorted in ascending order, but with all even numbers appearing before any odd numbers. For example, given the input list [3, 1, 4, 2, 5], the function should return [2, 4, 1, 3, 5].\nAnswer:\nLet's think step b...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8941, "level": 1, "question": "Write a function that takes a list of integers as input and returns the list sorted in ascending order, but with all even numbers appearing before any odd numbers. For example, given the input list [3, 1, 4, 2, 5], the function should return [2, 4, 1, ...
def add_strings(num1, num2): i = len(num1) - 1 j = len(num2) - 1 carry = 0 result = '' while i >= 0 or j >= 0 or carry > 0: digit1 = int(num1[i]) if i >= 0 else 0 digit2 = int(num2[j]) if j >= 0 else 0 total = digit1 + digit2 + carry carry = total // 10 ...
simplelr_Filter
[ { "content": "Question:\nWrite a Python function to perform string addition. The function should take two strings as input, each representing a non-negative integer, and return their sum as a string without converting them directly to integers. You may assume that the input strings are valid and do not contain ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8942, "level": 1, "question": "Write a Python function to perform string addition. The function should take two strings as input, each representing a non-negative integer, and return their sum as a string without converting them directly to integers. You may assume that the input st...
def is_palindrome(text): left = 0 right = len(text) - 1 while left < right: if text[left] != text[right]: return False left += 1 right -= 1 return True # Example usage: input_string = "racecar" result = is_palindrome(input_string) print(f"Is '{input_string}' a pali...
simplelr_Filter
[ { "content": "Question:\nYou are given a string containing only lowercase letters. You need to write a function that can determine if the given string is a palindrome.\n\nExample:\nInput: \"racecar\"\nOutput: True\n\nInput: \"apple\"\nOutput: False\n\nApproach:\n\n1. Two Pointer Technique: \nYou can use two poi...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8943, "level": 1, "question": "You are given a string containing only lowercase letters. You need to write a function that can determine if the given string is a palindrome.\n\nExample:\nInput: \"racecar\"\nOutput: True\n\nInput: \"apple\"\nOutput: False\n\nApproach:\n\n1. Two Point...
def average_of_subarrays(nums, k): if k == 0 or len(nums) < k: return [] result = [] for i in range(len(nums) - k + 1): subarray = nums[i:i+k] average = sum(subarray) / k rounded_average = round(average, 2) result.append(rounded_average) return result
simplelr_Leetcode
[ { "content": "Question:\nGiven a list of integers `nums`, implement a function that returns _a list of length `k`, where each element is the average of the contiguous subarray of length `k` in `nums`_. If the list `nums` has less than `k` elements, return an _empty list_. The average should be a floating-point ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8944, "level": 1, "question": "Given a list of integers `nums`, implement a function that returns _a list of length `k`, where each element is the average of the contiguous subarray of length `k` in `nums`_. If the list `nums` has less than `k` elements, return an _empty list_. The ...
def longest_unique_substring(s): max_length = 0 left = 0 last_occurrence = {} for right in range(len(s)): char = s[right] if char in last_occurrence and last_occurrence[char] >= left: left = last_occurrence[char] + 1 last_occurrence[char] = right current_lengt...
simplelr_Codeforces
[ { "content": "Question:\nYou are given a string s consisting of lowercase English letters. Your task is to determine the length of the longest substring in s containing only unique characters.\n\nWrite a function `longest_unique_substring(s)` that takes a string s as input and returns an integer representing th...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8945, "level": 1, "question": "You are given a string s consisting of lowercase English letters. Your task is to determine the length of the longest substring in s containing only unique characters.\n\nWrite a function `longest_unique_substring(s)` that takes a string s as input and...
def process_intervals(intervals, new_interval): """ Merge a new interval into existing intervals and return the updated list. Parameters: intervals (List[List[int]]): A list of intervals where each interval is represented as a list [start, end). new_interval (List[int]): A single interval to be...
simplelr_Data_Structure
[ { "content": "Question:\n<|Analysis Begin|>\n\n### Algorithm/Data Structure Analysis:\n\n#### Core Identification:\n* **Name**: Interval Manipulation and Merging\n* **Type**: Custom Data Structure and Sorting/Merging Algorithm\n* **Main Purpose**: Represent real number intervals and perform operations such as m...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8946, "level": 1, "question": "<|Analysis Begin|>\n\n### Algorithm/Data Structure Analysis:\n\n#### Core Identification:\n* **Name**: Interval Manipulation and Merging\n* **Type**: Custom Data Structure and Sorting/Merging Algorithm\n* **Main Purpose**: Represent real number interva...
def min_coins(coins, amount): if amount == 0: return 0 dp = [float('inf')] * (amount + 1) dp[0] = 0 for i in range(1, amount + 1): for coin in coins: if coin <= i: dp[i] = min(dp[i], dp[i - coin] + 1) return dp[amount] if dp[amount] != float('inf') else -1
simplelr_Filter
[ { "content": "Question:\nWrite a Python function to find the minimum number of coins required to make a given amount of money. The function should take a list of coin denominations and the target amount as input and return the minimum number of coins needed. Assume that there is an infinite supply of each coin ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8947, "level": 1, "question": "Write a Python function to find the minimum number of coins required to make a given amount of money. The function should take a list of coin denominations and the target amount as input and return the minimum number of coins needed. Assume that there ...
import string def count_unique_words(s): # Create a translation table to remove all punctuation translate_table = str.maketrans('', '', string.punctuation) unique_words = set() for word in s.split(): # Convert to lowercase and remove punctuation cleaned_word = word.lower().translate(tra...
simplelr_Prefill
[ { "content": "Question:\nCreate a function that filters and counts the number of unique words in a given string, ignoring case sensitivity and punctuation.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8948, "level": 1, "question": "Create a function that filters and counts the number of unique words in a given string, ignoring case sensitivity and punctuation.", "split": "train" }
def average_grades(students_grades): avg_grades = {} for student, grades in students_grades.items(): if not grades: avg_grades[student] = None continue valid_grades = [] for grade in grades: if isinstance(grade, (int, float)) and 0 <= grade <= 100: ...
simplelr_Evol
[ { "content": "Question:\nCraft a function that receives a dictionary as input, where keys represent student names and values are lists of grades (ranging from 0 to 100). The function should return a new dictionary where each student's name is mapped to their average grade, rounded to the nearest integer. Additi...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8949, "level": 1, "question": "Craft a function that receives a dictionary as input, where keys represent student names and values are lists of grades (ranging from 0 to 100). The function should return a new dictionary where each student's name is mapped to their average grade, rou...
def parse_log_entries(logs: list[str]) -> dict[str, any]: total_requests = 0 methods = {} status_codes = {} total_response_time = 0 for log in logs: parts = log.split() method = parts[0] status = parts[2] time = int(parts[3]) total_requests += 1 # U...
simplelr_Algorithm
[ { "content": "Question:\n### Question\n\nYou are required to implement a function that parses log entries from a web server and returns a summary report. Each log entry follows a standard format and includes the HTTP method, URL path, response status code, and response time in milliseconds.\n\n#### Function Sig...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8950, "level": 1, "question": "### Question\n\nYou are required to implement a function that parses log entries from a web server and returns a summary report. Each log entry follows a standard format and includes the HTTP method, URL path, response status code, and response time in...
def rotate_180(matrix): return [row[::-1] for row in reversed(matrix)]
simplelr_Data_Structure
[ { "content": "Question:\n### Matrix Rotation Challenge\n\nIn this task, you will implement a function that rotates a given N x N matrix by 180 degrees. Unlike simple 90-degree rotations, a 180-degree rotation means every element is moved to its diagonally opposite position in the matrix.\n\n#### Function Signat...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8951, "level": 1, "question": "### Matrix Rotation Challenge\n\nIn this task, you will implement a function that rotates a given N x N matrix by 180 degrees. Unlike simple 90-degree rotations, a 180-degree rotation means every element is moved to its diagonally opposite position in ...
def distinct_characters(strings): result = [] for s in strings: result.append(len(set(s))) return result
simplelr_Evol
[ { "content": "Question:\nDevelop a function named `distinct_characters` that accepts a list of strings and returns a list containing the count of distinct characters in each string. The function should be case-sensitive, treating 'a' and 'A' as different characters.\n\n```python\ndef distinct_characters(strings...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8952, "level": 1, "question": "Develop a function named `distinct_characters` that accepts a list of strings and returns a list containing the count of distinct characters in each string. The function should be case-sensitive, treating 'a' and 'A' as different characters.\n\n```pyth...
def longest_common_substring(s1, s2): m = len(s1) n = len(s2) dp = [[0] * (n + 1) for _ in range(m + 1)] max_len = 0 end = 0 # This will store the end index (1-based) of the longest substring in s1 for i in range(1, m + 1): for j in range(1, n + 1): if s1[i - 1] == s2[j...
simplelr_Prefill
[ { "content": "Question:\nWrite a function to find the longest common substring between two strings using dynamic programming in Python.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8953, "level": 1, "question": "Write a function to find the longest common substring between two strings using dynamic programming in Python.", "split": "train" }
def is_tournament_sorted(lst): if len(lst) < 2: return True for i in range(1, len(lst)): if lst[i][1] > lst[i-1][1]: return False return True
simplelr_Taco
[ { "content": "Question:\nWrite a function `is_tournament_sorted` that takes a `list` of `tuples`. Each `tuple` contains two elements: (team name, score). The function should `return` `True` if the list is sorted in descending order based on the scores; otherwise, it should `return` `False`.\n\nIf the input is a...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8954, "level": 1, "question": "Write a function `is_tournament_sorted` that takes a `list` of `tuples`. Each `tuple` contains two elements: (team name, score). The function should `return` `True` if the list is sorted in descending order based on the scores; otherwise, it should `re...
def calculate_scores(spins): scores = {} for player in spins: final_score = sum([x for x in player[1:] if x > 0]) running_total = sum(player[1:]) cant_lose_score = max(final_score, running_total) scores[player[0]] = cant_lose_score return scores
simplelr_Filter
[ { "content": "Question:\nI have a spinning wheel with 10 numbers ranging from 0 to 9. I spin the wheel one time and it lands on a 7. I spin the wheel a second time and it lands on a 0. On my third spin it lands on 3. I have 3 scores: a final score, a running total, and a 'can't lose' score. My final score is th...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8955, "level": 1, "question": "I have a spinning wheel with 10 numbers ranging from 0 to 9. I spin the wheel one time and it lands on a 7. I spin the wheel a second time and it lands on a 0. On my third spin it lands on 3. I have 3 scores: a final score, a running total, and a 'can'...
import matplotlib.pyplot as plt import seaborn as sns def customized_seaborn_plots(data: dict) -> None: # Create a figure with three subplots fig, axes = plt.subplots(1, 3, figsize=(15, 5)) # Set the global font scale for all plots plt.rcParams.update({'font.size': 12 * 1.5}) # Line plot ...
simplelr_Docs
[ { "content": "Question:\n**Coding Assessment Question:**\n\n### Objective\nYour task is to demonstrate your understanding of seaborn's context and customization functionalities. Write a function that sets different styles for different types of plots and displays them in a single figure.\n\n### Requirements\n1....
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8956, "level": 1, "question": "**Coding Assessment Question:**\n\n### Objective\nYour task is to demonstrate your understanding of seaborn's context and customization functionalities. Write a function that sets different styles for different types of plots and displays them in a sin...
def bubble_sort(lst): n = len(lst) for i in range(n - 1): swapped = False for j in range(n - i - 1): if lst[j] > lst[j + 1]: # Swap the elements lst[j], lst[j + 1] = lst[j + 1], lst[j] swapped = True if not swapped: ...
simplelr_Filter
[ { "content": "Question:\nWrite a function to sort a list of integers in non-decreasing order using the bubble sort algorithm in Python.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8957, "level": 1, "question": "Write a function to sort a list of integers in non-decreasing order using the bubble sort algorithm in Python.", "split": "train" }
import heapq def find_kth_largest(nums, k): return heapq.nlargest(k, nums)[-1]
simplelr_Filter
[ { "content": "Question:\nThis problem is a common one:\n\nYou have an array of integers and you need to find the kth largest element in the array.\n\nHere's how you might solve it using Python:\n\n```python\nimport heapq\n\ndef find_kth_largest(nums, k):\n return heapq.nlargest(k, nums)[-1]\nAnswer:\nLet's thi...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8958, "level": 1, "question": "This problem is a common one:\n\nYou have an array of integers and you need to find the kth largest element in the array.\n\nHere's how you might solve it using Python:\n\n```python\nimport heapq\n\ndef find_kth_largest(nums, k):\n return heapq.nlarge...
def update_prices(items_dict, update_list, new_price): updated = items_dict.copy() for item in update_list: if item in updated: updated[item] = new_price return updated
simplelr_Filter
[ { "content": "Question:\nCreate a script that updates the price of a dictionary of items. The function should take a dictionary of items, a list of items to update, and a new price. The function should return the updated dictionary. The function should also handle cases where an item is not found in the origina...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8959, "level": 1, "question": "Create a script that updates the price of a dictionary of items. The function should take a dictionary of items, a list of items to update, and a new price. The function should return the updated dictionary. The function should also handle cases where ...
def longestPalindrome(s): counts = {} for char in s: counts[char] = counts.get(char, 0) + 1 sum_length = 0 has_odd = False for c in counts.values(): sum_length += (c // 2) * 2 if c % 2 != 0: has_odd = True if has_odd: sum_length += 1 return sum_len...
simplelr_Taco
[ { "content": "Question:\nGiven a string s consisting of lowercase letters, determine the length of the longest palindrome that can be built with those letters. The frequency of characters in the string determines how many letters can be used to form a palindrome. Each character can be used at most as many times...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8960, "level": 1, "question": "Given a string s consisting of lowercase letters, determine the length of the longest palindrome that can be built with those letters. The frequency of characters in the string determines how many letters can be used to form a palindrome. Each characte...
def transpose(matrix): return [list(row) for row in zip(*matrix)]
simplelr_Filter
[ { "content": "Question:\nI need code for a function called `transpose` that takes a 2D matrix (list of lists) as input and returns its transpose.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8961, "level": 1, "question": "I need code for a function called `transpose` that takes a 2D matrix (list of lists) as input and returns its transpose.", "split": "train" }
def remove_sublist_elements(target_list, sub_list): return [x for x in target_list if x not in sub_list]
simplelr_Algorithm
[ { "content": "Question:\n### Problem Description\nYou are given a `target_list` and a `sub_list`. Your task is to write a function `remove_sublist_elements` that removes all the elements in `sub_list` from `target_list`.\n\n### Input\n* `target_list` (list): A list of elements which could be integers, strings, ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8962, "level": 1, "question": "### Problem Description\nYou are given a `target_list` and a `sub_list`. Your task is to write a function `remove_sublist_elements` that removes all the elements in `sub_list` from `target_list`.\n\n### Input\n* `target_list` (list): A list of elements...
def find_first_occurrence(nums, target): left = 0 right = len(nums) - 1 result = -1 while left <= right: mid = (left + right) // 2 if nums[mid] == target: result = mid right = mid - 1 # Look for earlier occurrence in the left half elif nums[mid] > target:...
simplelr_Filter
[ { "content": "Question:\nYou have a list of integers sorted in descending order, and you need to find the index of the first occurrence of a specific target value. If the target value is not found, return -1.\n\nExample: \nInput: [5, 4, 3, 2, 1], target = 3 \nOutput: 2\n\nHere is the code:\n```python\ndef find_...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8963, "level": 1, "question": "You have a list of integers sorted in descending order, and you need to find the index of the first occurrence of a specific target value. If the target value is not found, return -1.\n\nExample: \nInput: [5, 4, 3, 2, 1], target = 3 \nOutput: 2\n\nHere...
def search_matrix(matrix, target): if not matrix or not matrix[0]: return False rows = len(matrix) cols = len(matrix[0]) i, j = 0, cols - 1 while i < rows and j >= 0: current = matrix[i][j] if current == target: return True elif current < target: ...
simplelr_Leetcode
[ { "content": "Question:\nYou are given a 2D matrix of integers `matrix` where each row is sorted in ascending order, and each column is sorted in ascending order. Write a function that takes this matrix and an integer `target` as input and returns a boolean indicating whether `target` is found in the matrix. Im...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8964, "level": 1, "question": "You are given a 2D matrix of integers `matrix` where each row is sorted in ascending order, and each column is sorted in ascending order. Write a function that takes this matrix and an integer `target` as input and returns a boolean indicating whether ...
def kth_smallest_unique_element(arr, k): unique = list(set(arr)) unique.sort() return unique[k-1]
simplelr_Leetcode
[ { "content": "Question:\nGiven an array of integers `arr` and an integer `k`, return the `k-th` smallest element in the array after removing any duplicate values from the array. The array can contain both positive and negative integers. Ensure your solution has a time complexity of `O(n log n)`.\nAnswer:\nLet's...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8965, "level": 1, "question": "Given an array of integers `arr` and an integer `k`, return the `k-th` smallest element in the array after removing any duplicate values from the array. The array can contain both positive and negative integers. Ensure your solution has a time complexi...
def remove_odds(nums): return [num for num in nums if num % 2 == 0]
simplelr_Filter
[ { "content": "Question:\nWrite a Python function that takes a list of integers and returns a new list with all the odd integers removed. Use list comprehension to solve this problem. Example: If the input list is [1, 2, 3, 4, 5], the output list should be [2, 4].\nAnswer:\nLet's think step by step.\n", "rol...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8966, "level": 1, "question": "Write a Python function that takes a list of integers and returns a new list with all the odd integers removed. Use list comprehension to solve this problem. Example: If the input list is [1, 2, 3, 4, 5], the output list should be [2, 4].", "split": ...
import torch from torch.utils.dlpack import to_dlpack, from_dlpack def roundtrip_tensor_conversion(tensor: torch.Tensor) -> bool: """ Convert a PyTorch tensor to a DLPack tensor and then back to a PyTorch tensor. Verify that the final tensor is identical to the original tensor in terms of content. ...
simplelr_Docs
[ { "content": "Question:\n#### Context:\nYou are working on a project that involves converting between different tensor libraries using DLPack for efficient memory sharing. As a part of this project, you need to implement functionality in PyTorch that can convert a tensor from one format to another using DLPack....
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8967, "level": 1, "question": "#### Context:\nYou are working on a project that involves converting between different tensor libraries using DLPack for efficient memory sharing. As a part of this project, you need to implement functionality in PyTorch that can convert a tensor from ...
def max_subarray_sum(arr): if not arr: return 0 current_max = max_so_far = arr[0] for num in arr[1:]: current_max = max(num, current_max + num) if current_max > max_so_far: max_so_far = current_max return max_so_far
simplelr_Filter
[ { "content": "Question:\nI have an array of integers and I need to find the maximum sum of a subarray within it. Can you provide a Python function that can solve this problem efficiently?\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8968, "level": 1, "question": "I have an array of integers and I need to find the maximum sum of a subarray within it. Can you provide a Python function that can solve this problem efficiently?", "split": "train" }
def remove_first_occurrence(lst, elem): try: lst.remove(elem) except ValueError: pass return lst
simplelr_Filter
[ { "content": "Question:\nDevelop a Python program to remove the first occurrence of a specified element from a list. If the element is not found, the list remains unchanged.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8969, "level": 1, "question": "Develop a Python program to remove the first occurrence of a specified element from a list. If the element is not found, the list remains unchanged.", "split": "train" }
from typing import List def counting_sort(arr: List[int]) -> List[int]: """ Sorts an array of integers using the Counting Sort algorithm. If the array is empty, returns an empty array. Args: arr (List[int]): The input array of integers to be sorted. Returns: List[int]: The...
simplelr_Data_Structure
[ { "content": "Question:\n### Counting Sort Implementation\n\nYou are tasked with implementing the Counting Sort algorithm. Refactor the provided structure to conform to the following function specifications:\n\n#### Function Signature\n```python\ndef counting_sort(arr: List[int]) -> List[int]:\n \"\"\"\n ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8970, "level": 1, "question": "### Counting Sort Implementation\n\nYou are tasked with implementing the Counting Sort algorithm. Refactor the provided structure to conform to the following function specifications:\n\n#### Function Signature\n```python\ndef counting_sort(arr: List[in...
def compare_versions(version1: str, version2: str) -> int: """ Compares two version numbers and returns: - 1 if version1 is newer - -1 if version2 is newer - 0 if both versions are the same :param version1: str - The first version number as a string. :param version2: str - The second versio...
simplelr_Algorithm
[ { "content": "Question:\n### Question: Python Module Version Comparison\n\nIn software development, it's often necessary to compare version numbers to determine which is newer. Version numbers are typically written in a format that consists of integers separated by dots, for example `1.2.3`. Each part of the ve...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8971, "level": 1, "question": "### Question: Python Module Version Comparison\n\nIn software development, it's often necessary to compare version numbers to determine which is newer. Version numbers are typically written in a format that consists of integers separated by dots, for e...
def catalan_number(n): if not isinstance(n, int) or n < 0: return "Error: N must be a non-negative integer." if n == 0: return 1 catalan_num = 1 for k in range(1, n + 1): catalan_num = catalan_num * (n + k) // k catalan_num = catalan_num // (n + 1) return catalan_num
simplelr_Prefill
[ { "content": "Question:\nCreate a function that returns the Nth Catalan number. The function should accept an integer N as the parameter and return the Nth Catalan number. The function should also handle cases where N is 0 or negative by returning an appropriate error message. The Catalan number is a sequence o...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8972, "level": 1, "question": "Create a function that returns the Nth Catalan number. The function should accept an integer N as the parameter and return the Nth Catalan number. The function should also handle cases where N is 0 or negative by returning an appropriate error message....
import bisect from typing import List def insert_position(array: List[int], target: int) -> int: return bisect.bisect_left(array, target)
simplelr_Data_Structure
[ { "content": "Question:\n### Question: Efficient Sorted Array Insert\n\n**Background:**\nYou are working on a software project that requires frequently inserting elements into a sorted list. To make this process efficient, you need to determine the correct position to insert an element without disturbing the or...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8973, "level": 1, "question": "### Question: Efficient Sorted Array Insert\n\n**Background:**\nYou are working on a software project that requires frequently inserting elements into a sorted list. To make this process efficient, you need to determine the correct position to insert a...
def first_non_repeated(s): count = {} for char in s: if char in count: count[char] += 1 else: count[char] = 1 for char in s: if count[char] == 1: return char return None
simplelr_Taco
[ { "content": "Question:\nThe function should return the first non-repeated character in a given string. Can you identify the issue and fix it?\n\n```python\nfirst_non_repeated_character(\"swiss\") # should return 'w'\n```\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8974, "level": 1, "question": "The function should return the first non-repeated character in a given string. Can you identify the issue and fix it?\n\n```python\nfirst_non_repeated_character(\"swiss\") # should return 'w'\n```", "split": "train" }
def rotations(s): if len(s) == 0: return [] if len(s) == 1: return [s] else: return [s[i:] + s[:i] for i in range(len(s))]
simplelr_Filter
[ { "content": "Question:\nGiven a binary string, return a list of strings, where each string is a rotation of the original string.\n\nFor example, given the string \"abc\", return the list [\"abc\", \"bca\", \"cab\"]. \n\nIf the string is empty, return an empty list. \n\nIf the string has only one character, ret...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8975, "level": 1, "question": "Given a binary string, return a list of strings, where each string is a rotation of the original string.\n\nFor example, given the string \"abc\", return the list [\"abc\", \"bca\", \"cab\"]. \n\nIf the string is empty, return an empty list. \n\nIf the...
import os import shutil from typing import List def manage_directory_structure(file_paths: List[str], directory: str) -> None: for file_path in file_paths: # Skip if the path does not exist or is not a file if not os.path.isfile(file_path): print(f"Skipping {file_path}: not a file or do...
simplelr_Algorithm
[ { "content": "Question:\n### File Directory Management\n\n#### Context\nEfficiently managing file directories programmatically is a common requirement in many software applications. Often, there is a need to create a directory structure, move files into corresponding directories, and ensure that the operations ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8976, "level": 1, "question": "### File Directory Management\n\n#### Context\nEfficiently managing file directories programmatically is a common requirement in many software applications. Often, there is a need to create a directory structure, move files into corresponding directori...
def reverse_string_using_stack(s): stack = [] for char in s: stack.append(char) reversed_s = "" while stack: reversed_s += stack.pop() return reversed_s
simplelr_Filter
[ { "content": "Question:\nImplement an algorithm in Python that uses a Stack to reverse a string\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8977, "level": 1, "question": "Implement an algorithm in Python that uses a Stack to reverse a string", "split": "train" }
def bubble_sort(numbers): numbers = list(numbers) for i in range(len(numbers)): for j in range(len(numbers) - i - 1): if numbers[j] > numbers[j + 1]: numbers[j], numbers[j + 1] = numbers[j + 1], numbers[j] return numbers
simplelr_Filter
[ { "content": "Question:\nI want to create a Python function that sorts a list of numbers in ascending order using the bubble sort algorithm. Can you provide me with a sample code?\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8978, "level": 1, "question": "I want to create a Python function that sorts a list of numbers in ascending order using the bubble sort algorithm. Can you provide me with a sample code?", "split": "train" }
def trap(heights): if not heights: return 0 left, right = 0, len(heights) - 1 left_max = right_max = 0 res = 0 while left < right: if heights[left] < heights[right]: if heights[left] >= left_max: left_max = heights[left] else: r...
simplelr_Leetcode
[ { "content": "Question:\nYou are given an array of `n` non-negative integers representing the elevations of a terrain where each element represents the height at that point. The terrain is bounded on both ends, and each unit of elevation can hold one unit of water. You need to calculate the total units of water...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8979, "level": 1, "question": "You are given an array of `n` non-negative integers representing the elevations of a terrain where each element represents the height at that point. The terrain is bounded on both ends, and each unit of elevation can hold one unit of water. You need to...
def enhanced_bucket_sort(arr, num_buckets): '''Enhanced Bucket Sort''' if not arr: return [] min_val = min(arr) max_val = max(arr) if min_val == max_val: return sorted(arr) interval = (max_val - min_val) / num_buckets buckets = [[] for _ in range(num_buckets)] ...
simplelr_Data_Structure
[ { "content": "Question:\n**Bucket Sort Implementation Enhancement**\n\n*Goal:* Enhance the given bucket sort implementation to handle arrays with widely distributed non-integer numbers and improve sorting stages.\n\n**Task**:\nWrite a function `enhanced_bucket_sort(arr: List[float], num_buckets: int) -> List[fl...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8980, "level": 1, "question": "**Bucket Sort Implementation Enhancement**\n\n*Goal:* Enhance the given bucket sort implementation to handle arrays with widely distributed non-integer numbers and improve sorting stages.\n\n**Task**:\nWrite a function `enhanced_bucket_sort(arr: List[f...
def unique_paths(maze): if not maze or not maze[0]: return 0 rows = len(maze) cols = len(maze[0]) if maze[0][0] == 1: return 0 dp = [[0 for _ in range(cols)] for _ in range(rows)] dp[0][0] = 1 for i in range(rows): for j in range(cols): if i == 0 and j...
simplelr_Apps
[ { "content": "Question:\n# Task\nYou are given a grid representing a maze and your goal is to determine the number of distinct paths from the top-left corner to the bottom-right corner. The maze may have obstacles which are represented by '1', and open paths represented by '0'. You can only move right or down a...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8981, "level": 1, "question": "# Task\nYou are given a grid representing a maze and your goal is to determine the number of distinct paths from the top-left corner to the bottom-right corner. The maze may have obstacles which are represented by '1', and open paths represented by '0'...
def merge_sorted_lists(list_a, list_b): result = [] i = j = 0 while i < len(list_a) and j < len(list_b): if list_a[i] < list_b[j]: result.append(list_a[i]) i += 1 else: result.append(list_b[j]) j += 1 result += list_a[i:] result += list...
simplelr_Prefill
[ { "content": "Question:\nCreate a function that takes two sorted lists in ascending order and merges them into a single sorted list. You can assume that the input lists do not contain duplicate elements.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8982, "level": 1, "question": "Create a function that takes two sorted lists in ascending order and merges them into a single sorted list. You can assume that the input lists do not contain duplicate elements.", "split": "train" }
def find_nearest_match(array, target): """ Finds the nearest match to a target value in a sorted array. Args: array: A sorted array of numbers. target: The target value to find a match for. Returns: The value in the array that is closest to the target value. """ if not ar...
simplelr_Filter
[ { "content": "Question:\nThis is the code I was working on:\n\n```python\ndef find_nearest_match(array, target):\n \"\"\"\n Finds the nearest match to a target value in a sorted array.\n Args:\n array: A sorted array of numbers.\n target: The target value to find a match for.\n Returns:\n The...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8983, "level": 1, "question": "This is the code I was working on:\n\n```python\ndef find_nearest_match(array, target):\n \"\"\"\n Finds the nearest match to a target value in a sorted array.\n Args:\n array: A sorted array of numbers.\n target: The target value to find ...
def largest_number(s: str) -> str: if all(c == '0' for c in s): return "0" digits = sorted(s, reverse=True) return ''.join(digits)
simplelr_Algorithm
[ { "content": "Question:\n### Problem Statement:\nYou are given a string containing digits from '0' to '9'. Your task is to find the largest number that can be formed by rearranging the digits of the given string. The resultant number should not contain leading zeros unless the number itself is zero.\n\n### Task...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8984, "level": 1, "question": "### Problem Statement:\nYou are given a string containing digits from '0' to '9'. Your task is to find the largest number that can be formed by rearranging the digits of the given string. The resultant number should not contain leading zeros unless the...
def reverse_array(arr): left = 0 right = len(arr) - 1 while left < right: arr[left], arr[right] = arr[right], arr[left] left += 1 right -= 1 return arr
simplelr_Filter
[ { "content": "Question:\nReverse the order of an array, but do not use any built-in functions or libraries. The input array will always contain at least 10 elements and at most 1000 elements. The time complexity of your solution should be O(n), where n is the length of the input array.\nAnswer:\nLet's think ste...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8985, "level": 1, "question": "Reverse the order of an array, but do not use any built-in functions or libraries. The input array will always contain at least 10 elements and at most 1000 elements. The time complexity of your solution should be O(n), where n is the length of the inp...
import random import time import copy def quicksort(arr): """ This function performs the Quicksort algorithm on an array. :param arr: The array to be sorted :return: The sorted array """ if len(arr) <= 1: return arr pivot = arr[len(arr) // 2] # Choosing the middle element as the pi...
simplelr_Filter
[ { "content": "Question:\nI want to observe the behavior of the quicksort algorithm when sorting a large array of random numbers. How can I do this using a Python program?\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8986, "level": 1, "question": "I want to observe the behavior of the quicksort algorithm when sorting a large array of random numbers. How can I do this using a Python program?", "split": "train" }
def find_item_index(inventory: list, item_name: str) -> int: for index, item in enumerate(inventory): if item == item_name: return index return -1
simplelr_Data_Structure
[ { "content": "Question:\n### Scenario\nYou are developing a search feature for a small inventory management system. The inventory list is frequently updated and contains various items stored in no specific order. To keep the implementation simple, you'd like to use a linear search algorithm to find items by the...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8987, "level": 1, "question": "### Scenario\nYou are developing a search feature for a small inventory management system. The inventory list is frequently updated and contains various items stored in no specific order. To keep the implementation simple, you'd like to use a linear se...
def longest_common_subsequence(a: str, b: str) -> int: m = len(a) n = len(b) dp = [[0] * (n + 1) for _ in range(m + 1)] for i in range(1, m + 1): for j in range(1, n + 1): if a[i - 1] == b[j - 1]: dp[i][j] = dp[i - 1][j - 1] + 1 else: ...
simplelr_Algorithm
[ { "content": "Question:\n### Longest Common Subsequence (LCS) Problem\n\n#### Context:\nIn text comparisons, such as version control systems, finding the longest common subsequence between two strings can help identify changes and similarities. For this task, you will implement an algorithm to compute the LCS o...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8988, "level": 1, "question": "### Longest Common Subsequence (LCS) Problem\n\n#### Context:\nIn text comparisons, such as version control systems, finding the longest common subsequence between two strings can help identify changes and similarities. For this task, you will implemen...
from typing import List def is_transpose(matrix1: List[List[int]], matrix2: List[List[int]]) -> bool: if not matrix1: return not matrix2 m = len(matrix1) n = len(matrix1[0]) if m > 0 else 0 if len(matrix2) != n: return False for row in matrix2: if len(row) != m: ...
simplelr_Algorithm
[ { "content": "Question:\n### Matrix Transpose Checker\n\n#### Objective\n\nImplement a function that checks if two matrices are transposes of each other.\n\n#### Problem Statement\n\nImplement a function `is_transpose(matrix1: List[List[int]], matrix2: List[List[int]]) -> bool` that verifies if `matrix2` is the...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8989, "level": 1, "question": "### Matrix Transpose Checker\n\n#### Objective\n\nImplement a function that checks if two matrices are transposes of each other.\n\n#### Problem Statement\n\nImplement a function `is_transpose(matrix1: List[List[int]], matrix2: List[List[int]]) -> bool...
def filter_uppercase_strings(strings): return [s for s in strings if s and s[0].isupper()]
simplelr_Filter
[ { "content": "Question:\nWrite a Python function that takes a list of strings and returns a new list containing only the strings that start with an uppercase letter.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8990, "level": 1, "question": "Write a Python function that takes a list of strings and returns a new list containing only the strings that start with an uppercase letter.", "split": "train" }
def min_distance_dp(word1: str, word2: str) -> int: # Handle edge cases where one or both strings are empty if len(word1) == 0 and len(word2) == 0: return 0 elif len(word1) == 0: return len(word2) elif len(word2) == 0: return len(word1) m = len(word1) n = len(word2) ...
simplelr_Data_Structure
[ { "content": "Question:\nMinimum Delete Operations to Make Strings Identical\n\n#### Problem Description\nGiven two strings `word1` and `word2`, you are tasked with writing a function `min_distance_dp` that computes the minimum number of deletions required to make the two strings identical.\n\n#### Function Sig...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8991, "level": 1, "question": "Minimum Delete Operations to Make Strings Identical\n\n#### Problem Description\nGiven two strings `word1` and `word2`, you are tasked with writing a function `min_distance_dp` that computes the minimum number of deletions required to make the two stri...
from http.cookies import SimpleCookie def get_cookie_value(cookie_string, cookie_name): """ Extracts the value of a specific cookie from a cookie string. Args: cookie_string (str): The string containing cookies. cookie_name (str): The name of the cookie to find. Returns: ...
simplelr_Filter
[ { "content": "Question:\nHi, I'm trying to create a Python script that can parse a cookie string like the one provided in the example and extract the value of a specific cookie. How can I achieve this?\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8992, "level": 1, "question": "Hi, I'm trying to create a Python script that can parse a cookie string like the one provided in the example and extract the value of a specific cookie. How can I achieve this?", "split": "train" }
def max_subarray_sum(nums): if not nums: return 0 current_max = global_max = nums[0] for num in nums[1:]: current_max = max(num, current_max + num) if current_max > global_max: global_max = current_max return global_max
simplelr_Evol
[ { "content": "Question:\nDevelop a Python function that receives a list of integers and identifies the contiguous subarray which has the largest sum, then returns that sum. This exercise tests your comprehension of dynamic programming and array manipulation techniques.\nAnswer:\nLet's think step by step.\n", ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8993, "level": 1, "question": "Develop a Python function that receives a list of integers and identifies the contiguous subarray which has the largest sum, then returns that sum. This exercise tests your comprehension of dynamic programming and array manipulation techniques.", "sp...
def lists_are_equal(list_a, list_b): return list_a == list_b
simplelr_Filter
[ { "content": "Question:\nI want to create a Python function to check if two lists are equal. How can I do this?\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8994, "level": 1, "question": "I want to create a Python function to check if two lists are equal. How can I do this?", "split": "train" }
import bisect from typing import List, Tuple def totalPriceInRange(items: List[Tuple[str, int]], queries: List[Tuple[int, int]]) -> List[int]: # Extract the prices from the items prices = [price for (name, price) in items] # Sort the prices prices.sort() # Create the prefix sum array prefi...
simplelr_Taco
[ { "content": "Question:\nA store has a list of items, each with a name and a price. There are multiple queries, each asking for the total prices of items within a specific price range (inclusive).\n\nWrite a function `totalPriceInRange` that takes the following parameters:\n\n- `items`: a list of tuples, where ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8995, "level": 1, "question": "A store has a list of items, each with a name and a price. There are multiple queries, each asking for the total prices of items within a specific price range (inclusive).\n\nWrite a function `totalPriceInRange` that takes the following parameters:\n\n...
def detect_overlap(rect1: tuple[int, int, int, int], rect2: tuple[int, int, int, int]) -> bool: # Unpack the coordinates of the rectangles x1, y1, x2, y2 = rect1 x3, y3, x4, y4 = rect2 # Check for x-axis overlap x_overlap = (x1 < x4) and (x3 < x2) # Check for y-axis overlap y_overl...
simplelr_Algorithm
[ { "content": "Question:\n### Question: Rectangle Overlap Detection\n\nYou are given the coordinates of two rectangles in a 2D space. Each rectangle is defined by the coordinates of its lower-left and upper-right corners. \n\n**Objective:** Write a function `detect_overlap(rect1: Tuple[int, int, int, int], rect2...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8996, "level": 1, "question": "### Question: Rectangle Overlap Detection\n\nYou are given the coordinates of two rectangles in a 2D space. Each rectangle is defined by the coordinates of its lower-left and upper-right corners. \n\n**Objective:** Write a function `detect_overlap(rect...
def max_subarray_length(nums, k): prefix_map = {0: -1} current_sum = 0 max_length = 0 for i, num in enumerate(nums): current_sum += num target = current_sum - k if target in prefix_map: length = i - prefix_map[target] if length > max_length: ...
simplelr_Taco
[ { "content": "Question:\nGiven an array of integers nums and an integer k, return the maximum length of a subarray that sums to k. If there isn't one, return 0 instead.\n\nExample 1:\nInput: nums = [1, -1, 5, -2, 3], k = 3\nOutput: 4\nExplanation: The subarray [1, -1, 5, -2] sums to 3 and is the longest subarra...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8997, "level": 1, "question": "Given an array of integers nums and an integer k, return the maximum length of a subarray that sums to k. If there isn't one, return 0 instead.\n\nExample 1:\nInput: nums = [1, -1, 5, -2, 3], k = 3\nOutput: 4\nExplanation: The subarray [1, -1, 5, -2] s...
def max_blocks(heights, t): if not heights: return 0 count = 0 for i in range(1, len(heights)): if abs(heights[i] - heights[i-1]) > t: count += 1 return count + 1
simplelr_Leetcode
[ { "content": "Question:\nYou are given an array of integers `heights` representing the heights of buildings in a city. The city inspector decided to create blocks of buildings by merging adjacent buildings as long as the absolute difference in heights between any two adjacent buildings in a block does not excee...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8998, "level": 1, "question": "You are given an array of integers `heights` representing the heights of buildings in a city. The city inspector decided to create blocks of buildings by merging adjacent buildings as long as the absolute difference in heights between any two adjacent ...
def max_nesting_depth(s): max_depth = 0 current_depth = 0 for char in s: if char == '(': current_depth += 1 if current_depth > max_depth: max_depth = current_depth elif char == ')': current_depth -= 1 return max_depth
simplelr_Apps
[ { "content": "Question:\nGiven a sequence of nested parentheses, determine the maximum depth of the nesting. The depth of a position in a balanced parentheses string is defined by the number of parenthesis pairs containing that position, such as in \"(())\", each of the inner parentheses has a depth of 2. \n\nF...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 8999, "level": 1, "question": "Given a sequence of nested parentheses, determine the maximum depth of the nesting. The depth of a position in a balanced parentheses string is defined by the number of parenthesis pairs containing that position, such as in \"(())\", each of the inner ...