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 minRemoveToMakeValid(s: str) -> str: stack = [] to_remove = set() # First pass: left to right to find closing brackets to remove for i, c in enumerate(s): if c == '(': stack.append(i) elif c == ')': if stack: stack.pop() else: ...
simplelr_Codeforces
[ { "content": "Question:\nYou are given a string containing parentheses and lowercase English letters. Your task is to remove the minimum number of parentheses to make the string valid. A string is considered valid if it contains no unmatched parentheses and the parentheses are in the correct order.\n\nWrite a f...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1300, "level": 1, "question": "You are given a string containing parentheses and lowercase English letters. Your task is to remove the minimum number of parentheses to make the string valid. A string is considered valid if it contains no unmatched parentheses and the parentheses are...
def combination_sum(arr, target): if target == 0: return True dp = [False] * (target + 1) dp[0] = True for num in arr: for j in range(num, target + 1): if dp[j - num]: dp[j] = True return dp[target]
simplelr_Leetcode
[ { "content": "Question:\nYou are given an array of integers `arr` and an integer `target`. Your task is to determine if there exists a combination of elements in the array (order matters) that sums up to `target`. However, you are allowed to use each element in the array multiple times. Return _true_ if such a ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1301, "level": 1, "question": "You are given an array of integers `arr` and an integer `target`. Your task is to determine if there exists a combination of elements in the array (order matters) that sums up to `target`. However, you are allowed to use each element in the array multi...
def prefix_sums(nums): cumulative = 0 result = [] for num in nums: result.append(cumulative) cumulative += num return result
simplelr_Filter
[ { "content": "Question:\nWrite a Python function that takes a list of integers and returns a new list where each element is the sum of all the elements before it in the input list. For example, if the input list is [1, 2, 3, 4], the output list should be [0, 1, 3, 6].\nAnswer:\nLet's think step by step.\n", ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1302, "level": 1, "question": "Write a Python function that takes a list of integers and returns a new list where each element is the sum of all the elements before it in the input list. For example, if the input list is [1, 2, 3, 4], the output list should be [0, 1, 3, 6].", "spl...
def count_words_in_file(filename): try: with open(filename, 'r') as file: content = file.read() words = content.split() return len(words) except FileNotFoundError: print(f"The file {filename} does not exist.") return None # Example usage: filename = '...
simplelr_Filter
[ { "content": "Question:\nCan you provide a sample code snippet for counting the number of words in a text file using Python?\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1303, "level": 1, "question": "Can you provide a sample code snippet for counting the number of words in a text file using Python?", "split": "train" }
from typing import List def shell_sort(arr: List[int]) -> List[int]: # Create a copy of the input array to avoid mutation arr_copy = list(arr) n = len(arr_copy) gap = n // 2 while gap > 0: for i in range(gap, n): temp = arr_copy[i] j = i # Perfo...
simplelr_Data_Structure
[ { "content": "Question:\n### Scenario\nYour task is to implement a function that sorts an array of integers using the Shell Sort algorithm. Shell Sort improves upon simple insertion sort by breaking the original list into smaller sub-lists, which are then sorted using insertion sort. The array is divided based ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1304, "level": 1, "question": "### Scenario\nYour task is to implement a function that sorts an array of integers using the Shell Sort algorithm. Shell Sort improves upon simple insertion sort by breaking the original list into smaller sub-lists, which are then sorted using insertio...
from collections import Counter def can_form_palindrome(s, words): counts = Counter(s) for word in words: counts += Counter(word) odd_counts = sum(1 for cnt in counts.values() if cnt % 2 != 0) return odd_counts <= 1
simplelr_Leetcode
[ { "content": "Question:\nYou are given a string `s` and an array of strings `words`. Each string in `words` can be inserted into the string `s` at any position. After inserting all the strings from `words`, check if the resulting string is a palindrome. Return `true` if it is possible to create a palindrome; ot...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1305, "level": 1, "question": "You are given a string `s` and an array of strings `words`. Each string in `words` can be inserted into the string `s` at any position. After inserting all the strings from `words`, check if the resulting string is a palindrome. Return `true` if it is ...
def minOperations(str1, str2): n = len(str1) m = len(str2) dp = [[0] * (m + 1) for _ in range(n + 1)] for i in range(n + 1): for j in range(m + 1): if i == 0: dp[i][j] = j elif j == 0: dp[i][j] = i else: if ...
simplelr_Codeforces
[ { "content": "Question:\nYou are given two strings, `str1` and `str2`. Your task is to determine the minimum number of operations required to convert `str1` into `str2`. The operations allowed are:\n\n1. Insert a character.\n2. Remove a character.\n3. Replace a character.\n\nWrite a function `minOperations(str1...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1306, "level": 1, "question": "You are given two strings, `str1` and `str2`. Your task is to determine the minimum number of operations required to convert `str1` into `str2`. The operations allowed are:\n\n1. Insert a character.\n2. Remove a character.\n3. Replace a character.\n\nW...
def binary_search(array, target): left = 0 right = len(array) - 1 while left <= right: mid = (left + right) // 2 if array[mid] == target: return mid elif array[mid] < target: left = mid + 1 else: right = mid - 1 return -1
simplelr_Prefill
[ { "content": "Question:\nCreate a function that searches for a specific value in a sorted array using the binary search algorithm. The function should return the index of the value if it is found, otherwise return -1. Provide the algorithm in pseudocode, then convert it to Python.\nAnswer:\nLet's think step by ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1307, "level": 1, "question": "Create a function that searches for a specific value in a sorted array using the binary search algorithm. The function should return the index of the value if it is found, otherwise return -1. Provide the algorithm in pseudocode, then convert it to Pyt...
import html def sanitize_html(content: str, quote: bool = True) -> str: unescaped_content = html.unescape(content) escaped_content = html.escape(unescaped_content, quote=quote) return escaped_content
simplelr_Docs
[ { "content": "Question:\n**Objective**: Demonstrate your understanding of Python's `html` module for manipulating HTML content.\n\n### Problem Statement:\n\nYou are asked to create a function that accepts a string containing HTML content and returns a version of that string where:\n1. HTML entities such as &lt;...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1308, "level": 1, "question": "**Objective**: Demonstrate your understanding of Python's `html` module for manipulating HTML content.\n\n### Problem Statement:\n\nYou are asked to create a function that accepts a string containing HTML content and returns a version of that string wh...
def remove_duplicates(sentence: str) -> str: words = sentence.split() seen = set() unique_words = [] for word in words: if word not in seen: seen.add(word) unique_words.append(word) return ' '.join(unique_words)
simplelr_Algorithm
[ { "content": "Question:\n### Context:\nYou are developing a text processing library in which one of the features is to identify and remove duplicate words from a sentence while maintaining the order of their first appearance.\n\n### Task:\nImplement the `remove_duplicates` function that takes a sentence as inpu...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1309, "level": 1, "question": "### Context:\nYou are developing a text processing library in which one of the features is to identify and remove duplicate words from a sentence while maintaining the order of their first appearance.\n\n### Task:\nImplement the `remove_duplicates` fun...
def union_of_intervals(intervals): if not intervals: return 0 # Sort intervals based on the start time intervals.sort(key=lambda x: x[0]) # Initialize the merged list with the first interval converted to a list for modification merged = [list(intervals[0])] for current in ...
simplelr_Leetcode
[ { "content": "Question:\nYou are given a `2D` integer array `intervals` where each `intervals[i]` is a `pair` of integers `[start_i, end_i]` representing an interval. Return the length of the union of all the intervals. The union of the intervals is the total length covered by all the intervals, considering ove...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1310, "level": 1, "question": "You are given a `2D` integer array `intervals` where each `intervals[i]` is a `pair` of integers `[start_i, end_i]` representing an interval. Return the length of the union of all the intervals. The union of the intervals is the total length covered by...
from typing import List def linear_sort(arr: List[int]) -> List[int]: if not arr: return [] max_value = 1000000 # As per the problem's constraints counts = [0] * (max_value + 1) for num in arr: counts[num] += 1 result = [] for i in range(max_value + 1): r...
simplelr_Code_Contests
[ { "content": "Question:\nA software company has developed a new sorting algorithm and claimed that it can sort a given list of integers in linear time. As a coding challenge, developers are asked to implement this algorithm. However, the company is not disclosing the details of the algorithm. Instead, they prov...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1311, "level": 1, "question": "A software company has developed a new sorting algorithm and claimed that it can sort a given list of integers in linear time. As a coding challenge, developers are asked to implement this algorithm. However, the company is not disclosing the details o...
def square_numbers(numbers): return [n ** 2 for n in numbers]
simplelr_Filter
[ { "content": "Question:\nCreate a Python function that takes a list of numbers and returns a new list containing the squares of the original numbers. Use a list comprehension to achieve this.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1312, "level": 1, "question": "Create a Python function that takes a list of numbers and returns a new list containing the squares of the original numbers. Use a list comprehension to achieve this.", "split": "train" }
def list_of_lengths(string_list): return [len(string) for string in string_list]
simplelr_Filter
[ { "content": "Question:\nPlease help me write a Python function that takes a list of strings and returns a list of the lengths of each string in the list.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1313, "level": 1, "question": "Please help me write a Python function that takes a list of strings and returns a list of the lengths of each string in the list.", "split": "train" }
def can_jump(nums): max_reach = 0 n = len(nums) for i in range(n): if i > max_reach: return False max_reach = max(max_reach, i + nums[i]) if max_reach >= n - 1: return True return False
simplelr_Leetcode
[ { "content": "Question:\nGiven a list of integers where each element represents the maximum number of steps that can be jumped going forward from that element, determine if you can reach the last index starting from the first index. Each jump requires you to move to an index containing a valid number of steps. ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1314, "level": 1, "question": "Given a list of integers where each element represents the maximum number of steps that can be jumped going forward from that element, determine if you can reach the last index starting from the first index. Each jump requires you to move to an index c...
def maxSubArray(nums): if not nums: return 0 # According to the problem statement, the array is non-empty, so this case is just a fallback. max_so_far = current_max = nums[0] for num in nums[1:]: current_max = max(num, current_max + num) max_so_far = max(max_so_far, current_max) ...
simplelr_Taco
[ { "content": "Question:\nGiven a list of integers, determine the maximum sum of a non-empty subarray.\n\nA subarray is defined as a contiguous segment of the array. The subarray must contain at least one integer.\n\nExample 1:\n\nInput: [-2,1,-3,4,-1,2,1,-5,4]\nOutput: 6\nExplanation: The subarray [4,-1,2,1] ha...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1315, "level": 1, "question": "Given a list of integers, determine the maximum sum of a non-empty subarray.\n\nA subarray is defined as a contiguous segment of the array. The subarray must contain at least one integer.\n\nExample 1:\n\nInput: [-2,1,-3,4,-1,2,1,-5,4]\nOutput: 6\nExpl...
import bisect import heapq def kthLargestSum(arr, k): n = len(arr) if n == 0 or k == 0: return 0 # Compute prefix sums prefix = [0] * (n + 1) for i in range(1, n + 1): prefix[i] = prefix[i - 1] + arr[i - 1] # Initialize the sorted list with the first prefix sum sor...
simplelr_Leetcode
[ { "content": "Question:\nYou are given an integer array `arr` and an integer `k`. A subarray is defined as a contiguous segment of the array. Consider the sum of the elements of a subarray to be the score of that subarray. Return _the **kth** largest score of a subarray_. \n\nNote that the score of a subarray (...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1316, "level": 1, "question": "You are given an integer array `arr` and an integer `k`. A subarray is defined as a contiguous segment of the array. Consider the sum of the elements of a subarray to be the score of that subarray. Return _the **kth** largest score of a subarray_. \n\n...
def remove_duplicates(text: str) -> str: seen = set() result = [] for char in text: if char not in seen: result.append(char) seen.add(char) return ''.join(result)
simplelr_Algorithm
[ { "content": "Question:\n### Coding Assessment Question\n\nYou are a software developer assigned to enhance the company's text processing library. One common task is to remove duplicates from text sequences, which is essential for various preprocessing steps in natural language processing and data cleaning pipe...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1317, "level": 1, "question": "### Coding Assessment Question\n\nYou are a software developer assigned to enhance the company's text processing library. One common task is to remove duplicates from text sequences, which is essential for various preprocessing steps in natural languag...
def remove_bit(num: int, i: int) -> int: return ((num >> (i + 1)) << i) | (num & ((1 << i) - 1))
simplelr_Data_Structure
[ { "content": "Question:\n### **Coding Assessment Question: Remove Bit from Binary Representation**\n\n#### Problem Statement\n\nAs part of a data compression algorithm, you need to remove a bit at a specific position from an integer's binary representation. Write a function `remove_bit(num: int, i: int) -> int`...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1318, "level": 1, "question": "### **Coding Assessment Question: Remove Bit from Binary Representation**\n\n#### Problem Statement\n\nAs part of a data compression algorithm, you need to remove a bit at a specific position from an integer's binary representation. Write a function `r...
def robot_simulation(width, height, commands, start_position, start_orientation): current_x, current_y = start_position directions = ['N', 'E', 'S', 'W'] directions_move = [(0, 1), (1, 0), (0, -1), (-1, 0)] # N, E, S, W current_dir_index = directions.index(start_orientation) for cmd in command...
simplelr_Package
[ { "content": "Question:\nYou are required to write a function in Python that simulates a robot's movements within a given rectangular grid. The robot can move forward, turn left, or turn right based on a series of commands. The function should return the final position and orientation of the robot.\n\n**Functio...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1319, "level": 1, "question": "You are required to write a function in Python that simulates a robot's movements within a given rectangular grid. The robot can move forward, turn left, or turn right based on a series of commands. The function should return the final position and ori...
def find_complementary_strand(dna_sequence: str) -> str: complement_map = {'A': 'T', 'T': 'A', 'C': 'G', 'G': 'C'} result = [] for nucleotide in dna_sequence: if nucleotide not in complement_map: raise ValueError(f"Invalid nucleotide '{nucleotide}' found in the sequence.") result...
simplelr_Algorithm
[ { "content": "Question:\n### DNA Sequence Complementary Strand\n\n### Context:\nIn molecular biology, DNA sequences are composed of nucleotides represented by the letters 'A', 'T', 'C', and 'G'. 'A' pairs with 'T' and 'C' pairs with 'G'. Given a DNA sequence, it is often necessary to find its complementary stra...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1320, "level": 1, "question": "### DNA Sequence Complementary Strand\n\n### Context:\nIn molecular biology, DNA sequences are composed of nucleotides represented by the letters 'A', 'T', 'C', and 'G'. 'A' pairs with 'T' and 'C' pairs with 'G'. Given a DNA sequence, it is often neces...
import numpy as np import matplotlib.pyplot as plt def plot_quadratic(a, b, c, x_range): """ Plots a quadratic function f(x) = ax^2 + bx + c with customized grid styling. Parameters: a (float): The coefficient of x^2 term. b (float): The coefficient of x term. c (float): The constant term....
simplelr_Filter
[ { "content": "Question:\nWrite a function in Python that generates a plot of a quadratic function, where the function is defined as `f(x) = ax^2 + bx + c`. The function should take parameters `a`, `b`, `c`, and a range of `x` values as inputs. Additionally, customize the grid by enabling a minor grid and format...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1321, "level": 1, "question": "Write a function in Python that generates a plot of a quadratic function, where the function is defined as `f(x) = ax^2 + bx + c`. The function should take parameters `a`, `b`, `c`, and a range of `x` values as inputs. Additionally, customize the grid ...
from typing import List, Tuple def search_2d_matrix(matrix: List[List[int]], target: int) -> Tuple[int, int]: if not matrix or not matrix[0]: return (-1, -1) rows = len(matrix) cols = len(matrix[0]) i, j = 0, cols - 1 while i < rows and j >= 0: current = matrix[i][j] if curr...
simplelr_Data_Structure
[ { "content": "Question:\n### Binary Search Implementation in a Multi-Dimensional Array\n\n**Scenario**: \n\nYou have a two-dimensional grid (a list of lists in Python) where each row is sorted in ascending order from left to right, and each column is sorted in ascending order from top to bottom. Write a functio...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1322, "level": 1, "question": "### Binary Search Implementation in a Multi-Dimensional Array\n\n**Scenario**: \n\nYou have a two-dimensional grid (a list of lists in Python) where each row is sorted in ascending order from left to right, and each column is sorted in ascending order ...
def process_string_to_sorted_list(s): parts = [x for x in s.split(', ') if x] if not parts: return [] int_list = [int(x) for x in parts] unique = list(set(int_list)) unique.sort() return unique
simplelr_Filter
[ { "content": "Question:\nGiven a string of comma-separated values representing a list of integers, write a Python function that converts this string into a list of integers. Additionally, the function should remove any duplicate values and sort the list in ascending order before returning it. The input string w...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1323, "level": 1, "question": "Given a string of comma-separated values representing a list of integers, write a Python function that converts this string into a list of integers. Additionally, the function should remove any duplicate values and sort the list in ascending order befo...
def longest_common_subsequence(s, t): n = len(s) m = len(t) # Create a table to store lengths of longest common subsequence. dp = [[0] * (m + 1) for _ in range(n + 1)] # Fill dp table (bottom-up) for i in range(1, n + 1): for j in range(1, m + 1): if s[i-1] == t[j-1...
simplelr_Filter
[ { "content": "Question:\nGiven two text strings s and t, write a function to determine the maximal length of the identical subsequence shared by these two. This function should be optimized for performance, particularly for larger strings.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1324, "level": 1, "question": "Given two text strings s and t, write a function to determine the maximal length of the identical subsequence shared by these two. This function should be optimized for performance, particularly for larger strings.", "split": "train" }
def countStudentsWhoCanSee(heights): max_so_far = 0 count = 0 for height in heights: if height > max_so_far: count += 1 max_so_far = height return count
simplelr_Taco
[ { "content": "Question:\nYou are given a list of integers representing the heights of students standing in a line. Each student wants to be able to see the teacher, who is standing in front of the line. A student can see the teacher if there are no taller or equally tall students in front of them. Determine the...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1325, "level": 1, "question": "You are given a list of integers representing the heights of students standing in a line. Each student wants to be able to see the teacher, who is standing in front of the line. A student can see the teacher if there are no taller or equally tall stude...
def move_zeroes(nums): pos = 0 for i in range(len(nums)): if nums[i] != 0: nums[pos] = nums[i] pos += 1 for j in range(pos, len(nums)): nums[j] = 0 return nums
simplelr_Filter
[ { "content": "Question:\n### Algorithms and Data Structures\n#### Problem Solving\n###### [Problem Link](https://leetcode.com/problems/move-zeroes/)\nGiven an array `nums`, move all 0's to the end of it while maintaining the relative order of the non-zero elements.\nAnswer:\nLet's think step by step.\n", "r...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1326, "level": 1, "question": "### Algorithms and Data Structures\n#### Problem Solving\n###### [Problem Link](https://leetcode.com/problems/move-zeroes/)\nGiven an array `nums`, move all 0's to the end of it while maintaining the relative order of the non-zero elements.", "split"...
def find_unique_elements(arr: [int]) -> [int]: # Check if input is a list if not isinstance(arr, list): raise TypeError("Input must be a list.") # Check each element is an integer and not a boolean for num in arr: if type(num) is not int: raise TypeError("All elements must be...
simplelr_Algorithm
[ { "content": "Question:\n### Problem Statement\n\nYou are given an array of integers, where some integers appear twice and others appear once. Your task is to write a function that finds all the integers that appear only once in the array.\n\n### Function Signature\n```python\ndef find_unique_elements(arr: [int...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1327, "level": 1, "question": "### Problem Statement\n\nYou are given an array of integers, where some integers appear twice and others appear once. Your task is to write a function that finds all the integers that appear only once in the array.\n\n### Function Signature\n```python\...
def find_first_duplicate(arr): seen = set() for num in arr: if num in seen: return num seen.add(num) return None # As per the problem statement, this line is a formality.
simplelr_Filter
[ { "content": "Question:\nI have one-dimensional array of integers. I need to find the first duplicate in the array. \nThe array is not empty, contains only positive integers and can contain duplicates.\nArray length can be up to 10^6 elements. \nExample: for arr = [2,1,3,5,3,2] first duplicate is 3.\n\nMy curr...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1328, "level": 1, "question": "I have one-dimensional array of integers. I need to find the first duplicate in the array. \nThe array is not empty, contains only positive integers and can contain duplicates.\nArray length can be up to 10^6 elements. \nExample: for arr = [2,1,3,5,3,...
def findPair(nums, target): seen = {} for i in range(len(nums)): current = nums[i] complement = target - current if complement in seen: return (seen[complement], i) seen[current] = i return (-1, -1)
simplelr_Taco
[ { "content": "Question:\nGiven an array of integers `nums` and an integer `target`, your task is to find the first pair of indices whose elements sum up to the given target. The pair should be returned as a tuple containing the indices in ascending order. If no such pair exists, return `(-1, -1)`.\n\nExample 1:...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1329, "level": 1, "question": "Given an array of integers `nums` and an integer `target`, your task is to find the first pair of indices whose elements sum up to the given target. The pair should be returned as a tuple containing the indices in ascending order. If no such pair exist...
def elements_greater_than_threshold(arr, threshold): result = [] for index, value in enumerate(arr): if value > threshold: result.append((index, value)) return result
simplelr_Filter
[ { "content": "Question:\nRetrieve all the elements in an array that have a value greater than the given threshold and their indices. Implement a function that solves this problem with a time complexity of O(n).\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1330, "level": 1, "question": "Retrieve all the elements in an array that have a value greater than the given threshold and their indices. Implement a function that solves this problem with a time complexity of O(n).", "split": "train" }
def next_greater_element(nums1, nums2): # Compute next_greater for nums2 next_greater = [-1] * len(nums2) stack = [] for i in range(len(nums2)-1, -1, -1): while stack and stack[-1] <= nums2[i]: stack.pop() if stack: next_greater[i] = stack[-1] else: ...
simplelr_Leetcode
[ { "content": "Question:\nYou are given two arrays of integers, `nums1` and `nums2`, where not all elements of `nums2` are guaranteed to be in `nums1`, but each element in `nums1` is unique. Find the next greater number for each element in `nums1` by using the corresponding order from `nums2`. The next greater n...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1331, "level": 1, "question": "You are given two arrays of integers, `nums1` and `nums2`, where not all elements of `nums2` are guaranteed to be in `nums1`, but each element in `nums1` is unique. Find the next greater number for each element in `nums1` by using the corresponding ord...
def hamming_weight(n: int) -> int: """ Given a 32-bit integer n, return the number of '1' bits it has. Args: n: An unsigned 32-bit integer. Returns: int: The number of '1' bits in the integer's binary representation. """ return bin(n).count('1')
simplelr_Data_Structure
[ { "content": "Question:\n### Problem Description\nWrite a function that calculates the Hamming weight of an unsigned integer. The Hamming weight is the number of '1' bits present in the binary representation of the given unsigned integer. \n\n```python\ndef hamming_weight(n: int) -> int:\n \"\"\"\n Given ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1332, "level": 1, "question": "### Problem Description\nWrite a function that calculates the Hamming weight of an unsigned integer. The Hamming weight is the number of '1' bits present in the binary representation of the given unsigned integer. \n\n```python\ndef hamming_weight(n: i...
from collections import Counter def are_numerical_anagrams(num1, num2): str1 = str(num1) str2 = str(num2) if len(str1) != len(str2): return False return Counter(str1) == Counter(str2)
simplelr_Filter
[ { "content": "Question:\nI would like to verify if two given numbers are anagrams of each other. An anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once. Similarly, a numerical anagram is a number that can be formed by...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1333, "level": 1, "question": "I would like to verify if two given numbers are anagrams of each other. An anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once. Similarly, a numerical anagra...
def product_of_array(arr): total = 1 for num in arr: total *= num return total
simplelr_Filter
[ { "content": "Question:\nConsider the provided Python function, which currently calculates the aggregate of all elements within an array. Could you modify this function to alternatively determine the product of all elements in the array?\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1334, "level": 1, "question": "Consider the provided Python function, which currently calculates the aggregate of all elements within an array. Could you modify this function to alternatively determine the product of all elements in the array?", "split": "train" }
def rotate_array(arr, k): if not arr: return arr n = len(arr) effective_k = k % n return arr[-effective_k:] + arr[:-effective_k]
simplelr_Prefill
[ { "content": "Question:\nCreate a function that rotates an array to the right by `k` steps where `k` is an integer. The rotation should be done in as fast as possible.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1335, "level": 1, "question": "Create a function that rotates an array to the right by `k` steps where `k` is an integer. The rotation should be done in as fast as possible.", "split": "train" }
from typing import List, Set, Tuple def find_subsets(nums: List[int]) -> Set[Tuple[int]]: n = len(nums) subsets = set() for i in range(1 << n): subset = [] for j in range(n): if (i >> j) & 1: subset.append(nums[j]) subsets.add(tuple(subset)) return su...
simplelr_Data_Structure
[ { "content": "Question:\n### Problem Description\n\nYou are given a set of distinct integers in an array. Your task is to write a function that returns all possible subsets of this array, including the empty subset and the array itself. The subsets must be returned as a set of tuples.\n\n### Function Signature\...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1336, "level": 1, "question": "### Problem Description\n\nYou are given a set of distinct integers in an array. Your task is to write a function that returns all possible subsets of this array, including the empty subset and the array itself. The subsets must be returned as a set of...
def sort_by_length(lst): return sorted(lst, key=lambda x: len(x))
simplelr_Taco
[ { "content": "Question:\nWrite a function `sort_by_length` that takes in a list of strings and returns a list of strings sorted by their lengths in ascending order. If two strings have the same length, they should appear in the same order as they do in the input array.\n\nFor example:\n\n```python\n# should ret...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1337, "level": 1, "question": "Write a function `sort_by_length` that takes in a list of strings and returns a list of strings sorted by their lengths in ascending order. If two strings have the same length, they should appear in the same order as they do in the input array.\n\nFor ...
def count_characters(s): char_count = {} for char in s: char_count[char] = char_count.get(char, 0) + 1 return char_count
simplelr_Filter
[ { "content": "Question:\nI am trying to create a Python function that counts the occurrences of each character in a string and returns a dictionary with characters as keys and their counts as values. How can I do this?\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1338, "level": 1, "question": "I am trying to create a Python function that counts the occurrences of each character in a string and returns a dictionary with characters as keys and their counts as values. How can I do this?", "split": "train" }
def increment_list(lst): return [x + 1 for x in lst]
simplelr_Apps
[ { "content": "Question:\nWrite a function that takes a list of integers and returns a new list with each integer increased by 1. For example:\n\n```python\n[1, 2, 3] ==> [2, 3, 4]\n\n[5, -1, 0] ==> [6, 0, 1]\n```\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1339, "level": 1, "question": "Write a function that takes a list of integers and returns a new list with each integer increased by 1. For example:\n\n```python\n[1, 2, 3] ==> [2, 3, 4]\n\n[5, -1, 0] ==> [6, 0, 1]\n```", "split": "train" }
def cumulative_sum(numbers): result = [] running_sum = 0 for num in numbers: running_sum += num result.append(running_sum) return result # Test cases assert cumulative_sum([1, 2, 3, 4]) == [1, 3, 6, 10], "Test case 1 failed" assert cumulative_sum([]) == [], "Test case 2 failed" assert c...
simplelr_Filter
[ { "content": "Question:\nCan you write a Python function that takes a list of numbers and returns a new list where each element is the cumulative sum up to that element? For example, if the input list is `[1, 2, 3, 4]`, the output should be `[1, 3, 6, 10]`. Make sure to include a way to verify the correctness o...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1340, "level": 1, "question": "Can you write a Python function that takes a list of numbers and returns a new list where each element is the cumulative sum up to that element? For example, if the input list is `[1, 2, 3, 4]`, the output should be `[1, 3, 6, 10]`. Make sure to includ...
def find_min_diff(groupSizes, groupValues): groupSizes = [size for size, value in zip(groupSizes, groupValues)] S = sum(groupSizes) if S == 0: return 0 max_target = S // 2 dp = [False] * (S + 1) dp[0] = True for size in groupSizes: for s in range(S, -1, -1): if dp...
simplelr_Leetcode
[ { "content": "Question:\nYou are given two integer arrays `groupSizes` and `groupValues`, both of length `n`, where `groupSizes[i]` indicates the size of a group and `groupValues[i]` indicates the value of that group. Your task is to partition these groups into two non-empty sub-collections such that the sum of...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1341, "level": 1, "question": "You are given two integer arrays `groupSizes` and `groupValues`, both of length `n`, where `groupSizes[i]` indicates the size of a group and `groupValues[i]` indicates the value of that group. Your task is to partition these groups into two non-empty s...
import datetime def find_weekday(date_str): date_obj = datetime.datetime.strptime(date_str, '%Y-%m-%d') return date_obj.strftime('%A')
simplelr_Filter
[ { "content": "Question:\nConstruct a Python function named `find_weekday` that takes a date in the format 'YYYY-MM-DD' as a string and returns the corresponding day of the week. Use the `datetime` module to accomplish this task.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1342, "level": 1, "question": "Construct a Python function named `find_weekday` that takes a date in the format 'YYYY-MM-DD' as a string and returns the corresponding day of the week. Use the `datetime` module to accomplish this task.", "split": "train" }
def minimal_distinct_deadlines(n, deadlines): return n
simplelr_Codeforces
[ { "content": "Question:\nJamie is working on a software module that helps manage a list of tasks. The module should be able to determine the minimal number of distinct deadlines present in a given list of task deadlines, such that each task has a unique deadline.\n\nEach task has a given deadline, and some task...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1343, "level": 1, "question": "Jamie is working on a software module that helps manage a list of tasks. The module should be able to determine the minimal number of distinct deadlines present in a given list of task deadlines, such that each task has a unique deadline.\n\nEach task ...
def binary_search(arr, target): low = 0 high = len(arr) - 1 while low <= high: mid = (low + high) // 2 if arr[mid] == target: return mid elif arr[mid] < target: low = mid + 1 else: high = mid - 1 return -1
simplelr_Filter
[ { "content": "Question:\nGiven a sorted array of integers and an integer value, figure out whether the given value is present in the array or not using a binary search algorithm. If the value is present, return the index at which it is found. Additionally, calculate the time complexity of your solution.\nAnswer...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1344, "level": 1, "question": "Given a sorted array of integers and an integer value, figure out whether the given value is present in the array or not using a binary search algorithm. If the value is present, return the index at which it is found. Additionally, calculate the time c...
def is_sorted_and_unique(words): # Check for duplicates by comparing the length of the tuple to the set if len(words) != len(set(words)): return False # Check each consecutive pair for ascending order for i in range(len(words) - 1): if words[i] > words[i + 1]: return Fal...
simplelr_Filter
[ { "content": "Question:\nDevise a Python function that checks if a sequence of words in a tuple is sorted in ascending lexicographical order. Additionally, the function should also check for uniqueness in the sequence, return False if any word appears more than once.\nAnswer:\nLet's think step by step.\n", ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1345, "level": 1, "question": "Devise a Python function that checks if a sequence of words in a tuple is sorted in ascending lexicographical order. Additionally, the function should also check for uniqueness in the sequence, return False if any word appears more than once.", "spli...
import wave def process_wav_file(input_file: str, output_file: str, new_channels: int, new_frame_rate: int) -> None: # Open the input WAV file for reading with wave.open(input_file, 'rb') as wav_in: # Extract metadata from the input file number_of_input_channels = wav_in.getnchannels() ...
simplelr_Docs
[ { "content": "Question:\n**Coding Question: WAV File Processing in Python**\n\n**Objective**: \n\nWrite a Python function that reads a WAV file, extracts metadata and audio frames, modifies certain parameters, and then writes the modified audio to a new WAV file.\n\n**Function Signature**:\n\n```python\ndef pro...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1346, "level": 1, "question": "**Coding Question: WAV File Processing in Python**\n\n**Objective**: \n\nWrite a Python function that reads a WAV file, extracts metadata and audio frames, modifies certain parameters, and then writes the modified audio to a new WAV file.\n\n**Function...
def longest_substring_without_repeating(s): char_map = {} max_length = 0 start = 0 left = 0 for right in range(len(s)): char = s[right] if char in char_map: if char_map[char] >= left: left = char_map[char] + 1 char_map[char] = right current...
simplelr_Leetcode
[ { "content": "Question:\nWrite a function that takes a string `s` as input, and returns the longest substring without repeating characters. Your implementation should use a sliding window approach to achieve O(n) time complexity where `n` is the length of the string. For example, given the input string `\"abcab...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1347, "level": 1, "question": "Write a function that takes a string `s` as input, and returns the longest substring without repeating characters. Your implementation should use a sliding window approach to achieve O(n) time complexity where `n` is the length of the string. For examp...
def sum_two_numbers(x, y): """ Returns the sum of two numbers. Args: x (int or float): The first number to add. y (int or float): The second number to add. Returns: int or float: The sum of x and y. """ return x + y
simplelr_Filter
[ { "content": "Question:\nWrite a Python function that takes in two parameters, `x` and `y`, and returns their sum. Ensure your code is well-documented, including a docstring that explains what the function does, its parameters, and what it returns.\nAnswer:\nLet's think step by step.\n", "role": "user" } ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1348, "level": 1, "question": "Write a Python function that takes in two parameters, `x` and `y`, and returns their sum. Ensure your code is well-documented, including a docstring that explains what the function does, its parameters, and what it returns.", "split": "train" }
from collections import Counter def are_anagrams(a, b): return Counter(a) == Counter(b)
simplelr_Filter
[ { "content": "Question:\nHere is a function that returns a boolean indicating whether two lists contain exactly the same elements, regardless of the order:\n```python\ndef same_elements(a, b):\n return sorted(a) == sorted(b)\n```\nThis function works, but it has a time complexity of O(n log n) due to the sor...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1349, "level": 1, "question": "Here is a function that returns a boolean indicating whether two lists contain exactly the same elements, regardless of the order:\n```python\ndef same_elements(a, b):\n return sorted(a) == sorted(b)\n```\nThis function works, but it has a time comp...
def convert_negatives_to_positives(numbers): positive_numbers = [] for num in numbers: positive_numbers.append(-num) return positive_numbers
simplelr_Filter
[ { "content": "Question:\nIf I have a list of negative integers and I want to change all of them to positive by inverting their signs, how would I do that in Python? You can provide either a function or a one-liner solution.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1350, "level": 1, "question": "If I have a list of negative integers and I want to change all of them to positive by inverting their signs, how would I do that in Python? You can provide either a function or a one-liner solution.", "split": "train" }
def daily_temperatures(temperatures): stack = [] result = [0] * len(temperatures) for i in range(len(temperatures)): while stack and temperatures[i] > temperatures[stack[-1]]: j = stack.pop() result[j] = i - j stack.append(i) return result
simplelr_Apps
[ { "content": "Question:\nYou are given an array representing the daily temperatures for a week. Write an algorithm to find out how many days you would have to wait until a warmer temperature. If there is no future day for which this is possible, put 0 instead.\n\nFor example, given the temperatures array \n\nEx...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1351, "level": 1, "question": "You are given an array representing the daily temperatures for a week. Write an algorithm to find out how many days you would have to wait until a warmer temperature. If there is no future day for which this is possible, put 0 instead.\n\nFor example, ...
def second_largest(nums): unique = list(set(nums)) if len(unique) < 2: return None sorted_unique = sorted(unique, reverse=True) return sorted_unique[1]
simplelr_Taco
[ { "content": "Question:\nGiven a list of integers, write a function to find and return the second largest number in the list. If the list has fewer than two distinct numbers, return None.\n\nInput:\n- A list of integers.\n\nOutput:\n- An integer representing the second largest number or None if no such number e...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1352, "level": 1, "question": "Given a list of integers, write a function to find and return the second largest number in the list. If the list has fewer than two distinct numbers, return None.\n\nInput:\n- A list of integers.\n\nOutput:\n- An integer representing the second largest...
def is_match(s: str, p: str) -> bool: m = len(s) n = len(p) # Create a DP table with (m+1) rows and (n+1) columns dp = [[False] * (n + 1) for _ in range(m + 1)] dp[0][0] = True # Empty string and empty pattern match # Handle the case when s is empty for j in range(1, n + 1): ...
simplelr_Algorithm
[ { "content": "Question:\n### Dynamic String Pattern Matching\n\n#### Context\nYou are tasked with implementing a dynamic string pattern matching function that can handle multiple wildcard characters. The wildcard characters include '*' which matches zero or more characters, and '?' which matches exactly one cha...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1353, "level": 1, "question": "### Dynamic String Pattern Matching\n\n#### Context\nYou are tasked with implementing a dynamic string pattern matching function that can handle multiple wildcard characters. The wildcard characters include '*' which matches zero or more characters, an...
def is_prime(n): """ Checks if a given number is a prime number. Args: n (int): The number to check. Returns: bool: True if the number is prime, False otherwise. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return Fal...
simplelr_Filter
[ { "content": "Question:\nGenerate a Python function to check if a given number is a prime number.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1354, "level": 1, "question": "Generate a Python function to check if a given number is a prime number.", "split": "train" }
def extended_num_digits(n): """ Given an integer, compute the number of digits. Raise ValueError for non-integer inputs. :param n: int - The input integer to count digits of. :return: int - The number of digits in the integer. :raises: ValueError - If the input is not an integer. """ ...
simplelr_Data_Structure
[ { "content": "Question:\n#### Context\nCounting the number of digits in an integer is a common requirement in many computational tasks, such as formatting numerical data, validation inputs, or analyzing numerical properties. This task requires you to extend this simple digit-counting functionality to handle add...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1355, "level": 1, "question": "#### Context\nCounting the number of digits in an integer is a common requirement in many computational tasks, such as formatting numerical data, validation inputs, or analyzing numerical properties. This task requires you to extend this simple digit-c...
import heapq from typing import List def min_obstacle_path(grid: List[List[int]]) -> int: n = len(grid) if n == 0: return 0 # Though the problem states there's at least one path, so n is at least 1. # Initialize distances with infinity distances = [[float('inf')] * n for _ in range(n)] ...
simplelr_Algorithm
[ { "content": "Question:\n### Background\nIn an n x n grid, each cell in the grid can either be empty (represented by 0) or contain an obstacle (represented by 1). You need to find a path from the top-left cell (0,0) to the bottom-right cell (n-1,n-1), such that you minimize the sum of obstacles encountered alon...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1356, "level": 1, "question": "### Background\nIn an n x n grid, each cell in the grid can either be empty (represented by 0) or contain an obstacle (represented by 1). You need to find a path from the top-left cell (0,0) to the bottom-right cell (n-1,n-1), such that you minimize th...
def sparse_matrix_multiply(A, B): # Handle edge case where either matrix is empty if not A or not A[0] or not B or not B[0]: return [] # Create sparse representation for A len_A = len(A) len_A_cols = len(A[0]) A_sparse = [] for i in range(len_A): sparse_row = {} ...
simplelr_Data_Structure
[ { "content": "Question:\n### Sparse Matrix Multiplication\n\n#### Problem Statement\nYou are provided with two sparse matrices A and B comprised mostly of zero elements. Your task is to compute the product of matrices A and B (denoted as AB). You can assume that A's column number is equal to B's row number, mak...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1357, "level": 1, "question": "### Sparse Matrix Multiplication\n\n#### Problem Statement\nYou are provided with two sparse matrices A and B comprised mostly of zero elements. Your task is to compute the product of matrices A and B (denoted as AB). You can assume that A's column num...
def binary_search(sorted_list, target): low = 0 high = len(sorted_list) - 1 while low <= high: mid = (low + high) // 2 mid_value = sorted_list[mid] if mid_value == target: return mid elif mid_value < target: low = mid + 1 else: hi...
simplelr_Prefill
[ { "content": "Question:\nWrite a python function to search for a specific number in a sorted list using binary search. If the number is found, return its index. Otherwise, return -1.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1358, "level": 1, "question": "Write a python function to search for a specific number in a sorted list using binary search. If the number is found, return its index. Otherwise, return -1.", "split": "train" }
def lis(sequence): """ Finds the length and the actual subsequence of the longest increasing subsequence of a given sequence. Args: sequence: A list of numbers. Returns: A tuple containing the length of the LIS and the subsequence itself. """ n = len(sequence) if n == 0: ...
simplelr_Filter
[ { "content": "Question:\nThis code is supposed to find the longest increasing subsequence (LIS) of a given sequence.\n\n```python\ndef lis(sequence):\n \"\"\"\n Finds the length of the longest increasing subsequence of a given sequence.\n\n Args:\n sequence: A list of numbers.\n\n Returns:\n The l...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1359, "level": 1, "question": "This code is supposed to find the longest increasing subsequence (LIS) of a given sequence.\n\n```python\ndef lis(sequence):\n \"\"\"\n Finds the length of the longest increasing subsequence of a given sequence.\n\n Args:\n sequence: A list of ...
def longest_palindromic_substring(s): if not s: return "" max_len = 0 start = 0 n = len(s) for i in range(n): # Check for odd length palindromes l, r = i, i while l >= 0 and r < n and s[l] == s[r]: if r - l + 1 > max_len: max_len = r -...
simplelr_Filter
[ { "content": "Question:\nYou have a string consisting of only lowercase letters. You want to find the longest substring that is a palindrome.\n\n Example:\n\n```\nInput: \"babad\"\nOutput: \"bab\" or \"aba\"\n\nInput: \"cbbd\"\nOutput: \"bb\"\n```\n\nCan you write a Python code to solve this problem?\nAnswer:\n...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1360, "level": 1, "question": "You have a string consisting of only lowercase letters. You want to find the longest substring that is a palindrome.\n\n Example:\n\n```\nInput: \"babad\"\nOutput: \"bab\" or \"aba\"\n\nInput: \"cbbd\"\nOutput: \"bb\"\n```\n\nCan you write a Python cod...
def second_smallest_unique(numbers): unique = set(numbers) if len(unique) < 2: return None sorted_unique = sorted(unique) return sorted_unique[1] # Test the function numbers = [7, 5, 3, 5, 2, 3] print(second_smallest_unique(numbers)) # Output: 3
simplelr_Filter
[ { "content": "Question:\nWrite a Python function that finds the second smallest unique number in a list of integers. If the list does not contain at least two unique numbers, the function should return `None`. Use the function to find the second smallest unique number from the list `[7, 5, 3, 5, 2, 3]`.\nAnswer...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1361, "level": 1, "question": "Write a Python function that finds the second smallest unique number in a list of integers. If the list does not contain at least two unique numbers, the function should return `None`. Use the function to find the second smallest unique number from the...
def restore_string(s, indices): result = [''] * len(s) for i, index in enumerate(indices): result[index] = s[i] return ''.join(result)
simplelr_Filter
[ { "content": "Question:\nThis is the problem I'm working on:\n\nYou are given a string `s` and a list of sorted integers `indices`. You need to re-arrange the characters of `s` according to the given `indices`.\n\nFor example:\n\n```python\ns = \"codeleet\"\nindices = [4,5,6,7,0,1,2,3]\n```\n\nThe output should...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1362, "level": 1, "question": "This is the problem I'm working on:\n\nYou are given a string `s` and a list of sorted integers `indices`. You need to re-arrange the characters of `s` according to the given `indices`.\n\nFor example:\n\n```python\ns = \"codeleet\"\nindices = [4,5,6,7...
import collections def find_dominant_character(s): n = len(s) counts = collections.Counter(s) for char, cnt in counts.items(): if 2 * cnt > n: return char return ""
simplelr_Leetcode
[ { "content": "Question:\nYou are given a string `s` consisting of lowercase English letters. A character `c` in `s` is said to be **dominant** if the number of times it appears in `s` is strictly greater than the occurrences of all other characters combined. Return the character `c` if it is dominant, otherwise...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1363, "level": 1, "question": "You are given a string `s` consisting of lowercase English letters. A character `c` in `s` is said to be **dominant** if the number of times it appears in `s` is strictly greater than the occurrences of all other characters combined. Return the charact...
import numpy as np def train_recommendation_model(interactions, num_users, num_books, latent_features=10, learning_rate=0.01, iterations=50): if not interactions: return np.random.rand(num_users, latent_features), np.random.rand(num_books, latent_features) # Initialize user and book matrices with ...
simplelr_Algorithm
[ { "content": "Question:\n### Scenario\nYou have been asked to develop a recommendation system for an online bookstore. The system should suggest books to users based on their past reading history. The past reading history is stored in the form of user-book interactions, where each interaction consists of a user...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1364, "level": 1, "question": "### Scenario\nYou have been asked to develop a recommendation system for an online bookstore. The system should suggest books to users based on their past reading history. The past reading history is stored in the form of user-book interactions, where ...
def reconstruct_with_parity(encoded: str, block_size: int) -> str: data = [] for i in range(0, len(encoded), block_size): block = encoded[i:i + block_size] block_list = list(block) total = sum(int(c) for c in block_list) if total % 2 == 0: data.append(''.join(block_li...
simplelr_Algorithm
[ { "content": "Question:\n### Data Reconstruction with Parity Checks\n\nImplement a function in Python to reconstruct a given string using parity bits for error detection and correction. You will be provided with a string that includes parity bits encoded at regular intervals. Your task is to write a function `r...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1365, "level": 1, "question": "### Data Reconstruction with Parity Checks\n\nImplement a function in Python to reconstruct a given string using parity bits for error detection and correction. You will be provided with a string that includes parity bits encoded at regular intervals. ...
def reverse_string(input_string): return input_string[::-1] # Example usage: print(reverse_string("hello")) # Output: 'olleh'
simplelr_Filter
[ { "content": "Question:\nDefining a Function: How can I define a function in a Python script that takes a string as input and returns the reversed version of that string?\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1366, "level": 1, "question": "Defining a Function: How can I define a function in a Python script that takes a string as input and returns the reversed version of that string?", "split": "train" }
def count_unique_triplets(nums, target): nums.sort() count = 0 n = len(nums) for i in range(n): if i > 0 and nums[i] == nums[i-1]: continue left = i + 1 right = n - 1 while left < right: current_sum = nums[i] + nums[left] + nums[right] ...
simplelr_Leetcode
[ { "content": "Question:\nYou are given an integer array `nums` and a **positive** integer `target`. You need to determine the number of **unique** triplets `(a, b, c)` in the array such that `a + b + c = target`. Each triplet should be ordered such that `a <= b <= c` and should be returned in one line as a spac...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1367, "level": 1, "question": "You are given an integer array `nums` and a **positive** integer `target`. You need to determine the number of **unique** triplets `(a, b, c)` in the array such that `a + b + c = target`. Each triplet should be ordered such that `a <= b <= c` and shoul...
from collections import deque def optimize_route(grid, start, end): if start == end: if grid[start[0]][start[1]] == 0: return [start] else: return [] if grid[start[0]][start[1]] != 0 or grid[end[0]][end[1]] != 0: return [] rows = len(grid) cols = len...
simplelr_Apps
[ { "content": "Question:\nWrite a function `optimize_route` that determines the shortest path between two points in a grid filled with obstacles. The function takes the following parameters:\n\n- a 2D list `grid` representing the grid map where `0` indicates an open cell and `1` indicates an obstacle.\n- two tup...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1368, "level": 1, "question": "Write a function `optimize_route` that determines the shortest path between two points in a grid filled with obstacles. The function takes the following parameters:\n\n- a 2D list `grid` representing the grid map where `0` indicates an open cell and `1...
def findPair(nums, target): seen = set() for num in nums: complement = target - num if complement in seen: return [complement, num] seen.add(num) return []
simplelr_Taco
[ { "content": "Question:\nYou are given an array of integers and a target sum. You need to find two distinct elements in the array that sum up to the target sum. If such a pair exists, return the pair as a list. If multiple pairs exist, return any one of them. If no such pair exists, return an empty list.\n\nExa...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1369, "level": 1, "question": "You are given an array of integers and a target sum. You need to find two distinct elements in the array that sum up to the target sum. If such a pair exists, return the pair as a list. If multiple pairs exist, return any one of them. If no such pair e...
def frequency_dict(string_list): counts = {} for string in string_list: counts[string] = counts.get(string, 0) + 1 return counts
simplelr_Filter
[ { "content": "Question:\nI am looking for a Python code snippet that takes a list of strings and returns a dictionary where each key is a unique string from the list and the value is the count of how many times that string appears in the list. This is essentially creating a frequency dictionary.\nAnswer:\nLet's...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1370, "level": 1, "question": "I am looking for a Python code snippet that takes a list of strings and returns a dictionary where each key is a unique string from the list and the value is the count of how many times that string appears in the list. This is essentially creating a fr...
from typing import List def max_height_diff(nums: List[int]) -> int: n = len(nums) if n < 3: return 0 # Though according to problem constraints, len(nums) is at least 3 INF = float('inf') # Precompute left_min and left_max left_min = [INF] * n left_max = [-INF] * n for i ...
simplelr_Algorithm
[ { "content": "Question:\n### Problem Statement\n\nYou are given a list of integers representing the heights of mountains in a range. Your task is to determine the maximum difference in height between two mountains that are separated by at least one other mountain in the range.\n\nWrite a function `max_height_di...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1371, "level": 1, "question": "### Problem Statement\n\nYou are given a list of integers representing the heights of mountains in a range. Your task is to determine the maximum difference in height between two mountains that are separated by at least one other mountain in the range....
def process_string(s): sum_digits = sum(int(c) for c in s if c.isdigit()) count_letters = sum(1 for c in s if c.isalpha()) return sum_digits if sum_digits > count_letters else count_letters
simplelr_Taco
[ { "content": "Question:\n# Description:\n\nGiven a string containing letters, digits, and special characters, write a function that returns the sum of its digits and the count of alphabetical characters. If the sum of digits is greater than the count of letters, return the sum of digits, otherwise return the co...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1372, "level": 1, "question": "# Description:\n\nGiven a string containing letters, digits, and special characters, write a function that returns the sum of its digits and the count of alphabetical characters. If the sum of digits is greater than the count of letters, return the sum...
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_num = fib_sequence[i-1] + fib_sequence[i-2] fib_sequence.append(next_num) return fib_sequence
simplelr_Prefill
[ { "content": "Question:\nWrite a python function to generate the Fibonacci sequence up to a given number N (node number).\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1373, "level": 1, "question": "Write a python function to generate the Fibonacci sequence up to a given number N (node number).", "split": "train" }
def can_form_palindrome(s): char_count = {} odd_count = 0 for char in s: count = char_count.get(char, 0) if count % 2 == 0: odd_count += 1 else: odd_count -= 1 char_count[char] = count + 1 if odd_count > 1: return False return T...
simplelr_Filter
[ { "content": "Question:\nGiven a string of characters, determine if the string can be rearranged to form a palindrome.\nA palindrome is a string that reads the same backward as forward.\n\nExample:\n\nInput: \"aabbccee\"\nOutput: True\n\nInput: \"abcd\"\nOutput: False\n\nHere is a simple solution in Python:\n``...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1374, "level": 1, "question": "Given a string of characters, determine if the string can be rearranged to form a palindrome.\nA palindrome is a string that reads the same backward as forward.\n\nExample:\n\nInput: \"aabbccee\"\nOutput: True\n\nInput: \"abcd\"\nOutput: False\n\nHere ...
def is_balanced_brackets(s): stack = [] for char in s: if char == '(': stack.append(char) elif char == ')': if not stack: return False stack.pop() return len(stack) == 0
simplelr_Prefill
[ { "content": "Question:\nCreate a function that takes in a string and returns a boolean indicating whether the string contains a balanced set of brackets. A balanced set of brackets means that each opening bracket '(' has a corresponding closing bracket ')' and they are properly nested.\nAnswer:\nLet's think st...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1375, "level": 1, "question": "Create a function that takes in a string and returns a boolean indicating whether the string contains a balanced set of brackets. A balanced set of brackets means that each opening bracket '(' has a corresponding closing bracket ')' and they are proper...
def min_cost_path(costMatrix): if not costMatrix or not costMatrix[0]: return 0 # Assuming cost is zero for empty matrix, though constraints say n,m >=1 n = len(costMatrix) m = len(costMatrix[0]) dp = [0] * m dp[0] = costMatrix[0][0] # Initialize first row for j in ra...
simplelr_Apps
[ { "content": "Question:\n## Task\n\nYou are given a matrix `n x m` consisting of numbers that represent the cost of visiting each cell. Your task is to find the minimum cost to reach from the top-left cell to the bottom-right cell of the matrix. You are allowed to move only right or down from a cell.\n\n# Input...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1376, "level": 1, "question": "## Task\n\nYou are given a matrix `n x m` consisting of numbers that represent the cost of visiting each cell. Your task is to find the minimum cost to reach from the top-left cell to the bottom-right cell of the matrix. You are allowed to move only ri...
def most_frequent_char(s): counts = {} for c in s: if c in counts: counts[c] += 1 else: counts[c] = 1 max_freq = max(counts.values()) for c in s: if counts[c] == max_freq: return c
simplelr_Apps
[ { "content": "Question:\nWrite a function that takes a string as input and returns the most frequently occurring character in the string. If there is a tie, return the character that appears first in the string. Assume the string contains only lowercase letters and is not empty.\n\nFor example:\n- For the input...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1377, "level": 1, "question": "Write a function that takes a string as input and returns the most frequently occurring character in the string. If there is a tie, return the character that appears first in the string. Assume the string contains only lowercase letters and is not empt...
from collections import Counter def find_top_k_frequent_elements(nums: list, k: int) -> list: count = Counter(nums) sorted_list = sorted(count.items(), key=lambda x: (-x[1], x[0])) top_k = [x[0] for x in sorted_list[:k]] return top_k
simplelr_Package
[ { "content": "Question:\nYou are asked to implement a function called `find_top_k_frequent_elements` that returns the `k` most frequent elements in a given list of integers, sorted by their frequency in descending order. In the case of a tie in frequency, the elements should be sorted by their value in ascendin...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1378, "level": 1, "question": "You are asked to implement a function called `find_top_k_frequent_elements` that returns the `k` most frequent elements in a given list of integers, sorted by their frequency in descending order. In the case of a tie in frequency, the elements should b...
def final_position(commands: str) -> (int, int): x, y = 0, 0 for c in commands: if c == 'U': y += 1 elif c == 'D': y -= 1 elif c == 'R': x += 1 elif c == 'L': x -= 1 return (x, y)
simplelr_Algorithm
[ { "content": "Question:\n## Problem Statement\n\nGiven a string containing a series of commands representing movements inside a 2D grid, implement a function that calculates the final position after executing all the commands. Each command will either be an upward movement ('U'), a downward movement ('D'), a le...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1379, "level": 1, "question": "## Problem Statement\n\nGiven a string containing a series of commands representing movements inside a 2D grid, implement a function that calculates the final position after executing all the commands. Each command will either be an upward movement ('U...
def string_to_float_list(s): return [float(x) for x in s.split()]
simplelr_Prefill
[ { "content": "Question:\nCreate a function that takes a string of space-separated numbers and returns a list of those numbers as floats.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1380, "level": 1, "question": "Create a function that takes a string of space-separated numbers and returns a list of those numbers as floats.", "split": "train" }
from math import factorial def find_kth_permutation(character_list, k): sorted_chars = sorted(character_list) n = len(sorted_chars) k -= 1 # Convert to 0-based index result = [] current_chars = sorted_chars.copy() for i in range(n, 0, -1): fact = factorial(i - 1) index = k...
simplelr_Algorithm
[ { "content": "Question:\n### Problem Statement\n\n#### Context:\nYou are tasked with analyzing the lexicographical order of permutations of a list of characters. This involves generating and sorting all permutations and returning the k-th permutation in the sorted order.\n\n#### Problem:\nYour task is to write ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1381, "level": 1, "question": "### Problem Statement\n\n#### Context:\nYou are tasked with analyzing the lexicographical order of permutations of a list of characters. This involves generating and sorting all permutations and returning the k-th permutation in the sorted order.\n\n##...
def print_larger(a, b): print(a if a > b else b)
simplelr_Prefill
[ { "content": "Question:\nCreate a function that takes two integers as parameters and prints the larger of the two using the ternary operator in Python.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1382, "level": 1, "question": "Create a function that takes two integers as parameters and prints the larger of the two using the ternary operator in Python.", "split": "train" }
def is_multiple_of_3(num): return "Yes" if num % 3 == 0 else "No"
simplelr_Prefill
[ { "content": "Question:\nWrite a function to check if a given integer is a multiple of 3. If it is, return \"Yes\", otherwise return \"No\".\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1383, "level": 1, "question": "Write a function to check if a given integer is a multiple of 3. If it is, return \"Yes\", otherwise return \"No\".", "split": "train" }
def multiply_elements(array, num): return [element * num for element in array]
simplelr_Prefill
[ { "content": "Question:\nCreate a function that multiplies every element of an array by a given number.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1384, "level": 1, "question": "Create a function that multiplies every element of an array by a given number.", "split": "train" }
def two_sum(nums, target): seen = {} for index, num in enumerate(nums): complement = target - num if complement in seen: return [seen[complement], index] seen[num] = index return []
simplelr_Filter
[ { "content": "Question:\nWrite a Python function that takes a list of numbers and a target number as arguments and returns the indices of the two numbers such that they add up to the target. Each input list will have exactly one solution, and you may not use the same element twice. You can return the answer in ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1385, "level": 1, "question": "Write a Python function that takes a list of numbers and a target number as arguments and returns the indices of the two numbers such that they add up to the target. Each input list will have exactly one solution, and you may not use the same element t...
def recursive_sum(nested_list): """ Recursively calculates the sum of all numbers in a nested list. Args: nested_list: A list that can contain integers, floats, and other lists. Returns: The sum of all numeric elements in the nested list. Examples: >>> recursive_sum([1, 2,...
simplelr_Filter
[ { "content": "Question:\nCreate a recursive function to calculate the sum of all numbers in a nested list. \n\nThe function should be able to handle lists of arbitrary depth and should be able to handle the case where the list is empty.\n\nExample:\nInput: [1, 2, [3, 4], [5, [6, 7]]]\nOutput: 28\n\nExample:\nIn...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1386, "level": 1, "question": "Create a recursive function to calculate the sum of all numbers in a nested list. \n\nThe function should be able to handle lists of arbitrary depth and should be able to handle the case where the list is empty.\n\nExample:\nInput: [1, 2, [3, 4], [5, [...
from typing import Dict, List, Tuple def top_products(products: Dict[str, float], n: int) -> List[Tuple[str, float]]: # Convert the dictionary into a list of tuples products_list = list(products.items()) # Sort the list by price in descending order sorted_products = sorted(products_list, key=lambda x: ...
simplelr_Evol
[ { "content": "Question:\nGiven the following dataset of products and their prices, write a Python function to help an online store owner identify the top n most expensive products. The function should take two parameters: a dictionary where the keys are product names and the values are their corresponding price...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1387, "level": 1, "question": "Given the following dataset of products and their prices, write a Python function to help an online store owner identify the top n most expensive products. The function should take two parameters: a dictionary where the keys are product names and the v...
from collections import Counter def canFormAP(nums, n, d): if len(nums) < n: return False if n == 1: return True freq = Counter(nums) if d == 0: for count in freq.values(): if count >= n: return True return False else: fo...
simplelr_Taco
[ { "content": "Question:\nGiven an integer array `nums`, you are required to determine if there is a subsequence of length `n` that can be rearranged to form an arithmetic progression (AP) with a given common difference `d`. The task is to identify whether such a subsequence exists within the given array.\n\nExa...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1388, "level": 1, "question": "Given an integer array `nums`, you are required to determine if there is a subsequence of length `n` that can be rearranged to form an arithmetic progression (AP) with a given common difference `d`. The task is to identify whether such a subsequence ex...
import random def generate_random_float(a, b): return random.uniform(a, b) # Example usage: random_number = generate_random_float(1.5, 10.2) print(random_number)
simplelr_Filter
[ { "content": "Question:\nHow can I generate a random floating-point number between two specified numbers using Python?\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1389, "level": 1, "question": "How can I generate a random floating-point number between two specified numbers using Python?", "split": "train" }
def min_cost_transform(A, B, ins_cost, del_cost, rep_cost): n = len(A) m = len(B) dp = [[0] * (m + 1) for _ in range(n + 1)] # Initialize the base cases for i in range(n + 1): dp[i][0] = i * del_cost for j in range(m + 1): dp[0][j] = j * ins_cost # Fill the DP table...
simplelr_Filter
[ { "content": "Question:\nThe problem requires you to determine the minimum number of steps to transform string A into string B by performing the following operations:\n1. **Insert a character:** Insert a character anywhere in the string.\n2. **Delete a character:** Delete a character from the string.\n3. **Repl...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1390, "level": 1, "question": "The problem requires you to determine the minimum number of steps to transform string A into string B by performing the following operations:\n1. **Insert a character:** Insert a character anywhere in the string.\n2. **Delete a character:** Delete a ch...
from collections import deque from typing import List def canAssembleModules(n: int, dependencies: List[List[int]]) -> bool: if n == 0: return True # Initialize adjacency list and in_degree array adj = [[] for _ in range(n)] in_degree = [0] * n for dep in dependencies: a, ...
simplelr_Code_Contests
[ { "content": "Question:\nA manufacturer is planning to produce a new line of customizable gadgets. Each gadget is composed of multiple modules, and each module requires to follow a specific order of assembly due to dependencies. For example, if module B depends on module A, then module A must be assembled befor...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1391, "level": 1, "question": "A manufacturer is planning to produce a new line of customizable gadgets. Each gadget is composed of multiple modules, and each module requires to follow a specific order of assembly due to dependencies. For example, if module B depends on module A, th...
def min_cost_path(matrix): if not matrix or not matrix[0]: return 0 m = len(matrix) n = len(matrix[0]) dp = [0] * n dp[0] = matrix[0][0] for j in range(1, n): dp[j] = dp[j-1] + matrix[0][j] for i in range(1, m): dp[0] += matrix[i][0] for j in range(1, n): ...
simplelr_Leetcode
[ { "content": "Question:\nGiven a `matrix` of integers where each element represents the cost to step on that cell, write a function to find the minimum cost to travel from the top-left corner to the bottom-right corner of the matrix. You are only allowed to move either down or right at any point in time. Return...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1392, "level": 1, "question": "Given a `matrix` of integers where each element represents the cost to step on that cell, write a function to find the minimum cost to travel from the top-left corner to the bottom-right corner of the matrix. You are only allowed to move either down or...
def merge_sorted_lists(list1, list2): if not list1: return list2 if not list2: return list1 if list1[0] <= list2[0]: return [list1[0]] + merge_sorted_lists(list1[1:], list2) else: return [list2[0]] + merge_sorted_lists(list1, list2[1:])
simplelr_Prefill
[ { "content": "Question:\nWrite a python function to merge two sorted lists into a single sorted list using recursion.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1393, "level": 1, "question": "Write a python function to merge two sorted lists into a single sorted list using recursion.", "split": "train" }
def min_subarray_len(nums, target): left = 0 current_sum = 0 min_length = float('inf') for right in range(len(nums)): current_sum += nums[right] while current_sum >= target: if (right - left + 1) < min_length: min_length = right - left + 1 current_...
simplelr_Leetcode
[ { "content": "Question:\nYou are given a list of unique positive integers `nums` and an integer `target`. A **subarray** of `nums` is a contiguous part of the list. Find the length of the shortest **subarray** whose sum is greater than or equal to `target`. If there is no such subarray, return `-1`.\nAnswer:\nL...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1394, "level": 1, "question": "You are given a list of unique positive integers `nums` and an integer `target`. A **subarray** of `nums` is a contiguous part of the list. Find the length of the shortest **subarray** whose sum is greater than or equal to `target`. If there is no such...
def limited_array(arr, min_lim=None, max_lim=None): """ Filters the array 'arr' to include only values between 'min_lim' and 'max_lim', inclusive. Parameters: arr (list of int): A list of integers to be filtered. min_lim (int or None): The minimum bound value. If None, it defaults to the minimu...
simplelr_Data_Structure
[ { "content": "Question:\n### Question: Filtering Array by Boundary Values\n\nYou are required to implement a function that filters the values of an array based on given minimum and/or maximum boundary values. The function should traverse the array and retain only those elements that fall between the provided bo...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1395, "level": 1, "question": "### Question: Filtering Array by Boundary Values\n\nYou are required to implement a function that filters the values of an array based on given minimum and/or maximum boundary values. The function should traverse the array and retain only those element...
from typing import List import chunk def get_chunk_ids(file_path: str, min_size: int) -> List[str]: chunk_ids = [] try: with open(file_path, 'rb') as f: while True: try: ch = chunk.Chunk(f) if ch.getsize() >= min_size: ...
simplelr_Docs
[ { "content": "Question:\n### Chunk Data Processing\n\n#### Objective\nYou are given a file containing multiple EA IFF 85 chunks. Your task is to implement a function that reads these chunks and processes them to extract the names (IDs) of chunks that have a specific minimum size.\n\n#### Task\nWrite a Python fu...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1396, "level": 1, "question": "### Chunk Data Processing\n\n#### Objective\nYou are given a file containing multiple EA IFF 85 chunks. Your task is to implement a function that reads these chunks and processes them to extract the names (IDs) of chunks that have a specific minimum si...
from typing import List def count_unobstructed_view(buildings: List[int]) -> int: max_so_far = 0 count = 0 for building in reversed(buildings): if building > max_so_far: count += 1 max_so_far = building return count
simplelr_Code_Contests
[ { "content": "Question:\nYou are given a list of integers representing the heights of students standing in a line, and your task is to determine the number of buildings that have an unobstructed view of the horizon.\n\nA building has an unobstructed view of the horizon if there are no taller buildings to the ri...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1397, "level": 1, "question": "You are given a list of integers representing the heights of students standing in a line, and your task is to determine the number of buildings that have an unobstructed view of the horizon.\n\nA building has an unobstructed view of the horizon if ther...
def first_unique_char(s: str) -> int: counts = [0] * 26 # Initialize a list to store counts of each character # First pass: count the frequency of each character for c in s: counts[ord(c) - ord('a')] += 1 # Second pass: find the first character with count 1 for i in range(len(s)): ...
simplelr_Algorithm
[ { "content": "Question:\n### Problem Statement\n\nGiven the necessary skills to manipulate strings and track their occurrences, this problem tests your ability to identify the first unique character in a string. A unique character is one that appears exactly once in the string.\n\n#### Task\nWrite a function `f...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1398, "level": 1, "question": "### Problem Statement\n\nGiven the necessary skills to manipulate strings and track their occurrences, this problem tests your ability to identify the first unique character in a string. A unique character is one that appears exactly once in the string...
def count_common_elements(list1, list2): common = set(list1) & set(list2) return len(common) if common else -1
simplelr_Filter
[ { "content": "Question:\nWrite a Python program to check if two lists have any common elements. The program should return the number of common elements found. If no common elements are found, it should return -1.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 1399, "level": 1, "question": "Write a Python program to check if two lists have any common elements. The program should return the number of common elements found. If no common elements are found, it should return -1.", "split": "train" }