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 fibonacci(n): a, b = 0, 1 fib_sequence = [] for _ in range(n): fib_sequence.append(a) a, b = b, a + b return fib_sequence
simplelr_Prefill
[ { "content": "Question:\nWrite a python function to print the Fibonacci sequence of a given number of terms. The Fibonacci sequence starts with 0 and 1, and each subsequent number is the sum of the previous two. For example, the first six terms are 0, 1, 1, 2, 3, 5.\nAnswer:\nLet's think step by step.\n", "...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3800, "level": 1, "question": "Write a python function to print the Fibonacci sequence of a given number of terms. The Fibonacci sequence starts with 0 and 1, and each subsequent number is the sum of the previous two. For example, the first six terms are 0, 1, 1, 2, 3, 5.", "split...
def merge_intervals(intervals): if len(intervals) == 0: return [] # Sort intervals based on the start time of each interval intervals = sorted(intervals, key=lambda x: x[0]) merged = [] # Initialize with the first interval merged.append(intervals[0]) for current in intervals[1:]...
simplelr_Filter
[ { "content": "Question:\nHere is the problem:\n\nGiven a list of intervals where each interval is a list of two integers. Write a function that merges overlapping intervals and returns the merged list of intervals. \n\nThis is the code I was using:\n\n```python\ndef merge_intervals(intervals):\n if len(inter...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3801, "level": 1, "question": "Here is the problem:\n\nGiven a list of intervals where each interval is a list of two integers. Write a function that merges overlapping intervals and returns the merged list of intervals. \n\nThis is the code I was using:\n\n```python\ndef merge_inte...
def reverse_string(s): """ Returns the reverse of the input string. Args: s (str): The string to reverse. Returns: str: The reversed string. """ return s[::-1]
simplelr_Filter
[ { "content": "Question:\nWhat is the Python code to implement a function to reverse a string?\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3802, "level": 1, "question": "What is the Python code to implement a function to reverse a string?", "split": "train" }
def merge_and_sort_lists(list1, list2): s = set() s.update(list1) s.update(list2) return sorted(s)
simplelr_Algorithm
[ { "content": "Question:\n### List Merging and Sorting Function\n\nWrite a function in Python called `merge_and_sort_lists` that accepts two parameters:\n1. `list1` (List[int]): A list of integers.\n2. `list2` (List[int]): Another list of integers.\n\nThe function should merge the two lists, sort the resulting l...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3803, "level": 1, "question": "### List Merging and Sorting Function\n\nWrite a function in Python called `merge_and_sort_lists` that accepts two parameters:\n1. `list1` (List[int]): A list of integers.\n2. `list2` (List[int]): Another list of integers.\n\nThe function should merge ...
def unique_elements(input_list): result = [] seen = set() for element in input_list: if element not in seen: result.append(element) seen.add(element) return result
simplelr_Package
[ { "content": "Question:\nWrite a function named `unique_elements` that takes a list of integers and returns a new list with duplicate elements removed, while preserving the order of the first occurrence of each element. The function should not use any external library for this task.\n\nSpecifically, the `unique...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3804, "level": 1, "question": "Write a function named `unique_elements` that takes a list of integers and returns a new list with duplicate elements removed, while preserving the order of the first occurrence of each element. The function should not use any external library for this...
from typing import List def magic_triangle(n: int) -> List[List[int]]: if n < 1: return [] triangle = [[1]] for i in range(2, n + 1): new_row = [1] prev_row = triangle[-1] for j in range(1, i - 1): new_element = (prev_row[j - 1] + prev_row[j]) % 100 n...
simplelr_Codeforces
[ { "content": "Question:\nWrite a function `magic_triangle(n)` that generates a triangular pattern of numbers. The pattern starts with 1 at the top, and every subsequent row contains numbers that are the sum of the two directly above them, modulo 100. The function should take one argument, `n`, representing the ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3805, "level": 1, "question": "Write a function `magic_triangle(n)` that generates a triangular pattern of numbers. The pattern starts with 1 at the top, and every subsequent row contains numbers that are the sum of the two directly above them, modulo 100. The function should take o...
def are_all_items_unique(lst): # Determine the length of the list without using len() count = 0 while True: try: element = lst[count] count += 1 except IndexError: break length = count # Check each element against all subsequent elements i = 0...
simplelr_Filter
[ { "content": "Question:\nCreate a Python program to check if all items in a list are unique, without using any built-in functions or data structures. Additionally, consider time and space complexity.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3806, "level": 1, "question": "Create a Python program to check if all items in a list are unique, without using any built-in functions or data structures. Additionally, consider time and space complexity.", "split": "train" }
from collections import Counter def min_replacements_to_uniform_string(s): if not s: return 0 counts = Counter(s) max_count = max(counts.values()) return len(s) - max_count
simplelr_Leetcode
[ { "content": "Question:\nYou are given a string `s` consisting of only lowercase English letters. You are allowed to choose any letter from `s` and replace it with any other lowercase English letter. You want to make `s` consist of a single repeated character but want to minimize the number of replacements need...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3807, "level": 1, "question": "You are given a string `s` consisting of only lowercase English letters. You are allowed to choose any letter from `s` and replace it with any other lowercase English letter. You want to make `s` consist of a single repeated character but want to minim...
def print_square(n): for _ in range(n): print('*' * n)
simplelr_Filter
[ { "content": "Question:\nDevelop a Python function that prints an n x n square of asterisks ('*') for given n.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3808, "level": 1, "question": "Develop a Python function that prints an n x n square of asterisks ('*') for given n.", "split": "train" }
def count_repeated_substrings(s: str, k: int) -> int: if k <= 0 or len(s) < k: return 0 freq = {} n = len(s) for i in range(n - k + 1): substr = s[i:i+k] if substr in freq: freq[substr] += 1 else: freq[substr] = 1 count = 0 for v in freq.va...
simplelr_Leetcode
[ { "content": "Question:\nYou are given a string `s` and an integer `k`. A **substring** is defined as a contiguous sequence of characters within the string. Calculate the number of distinct substrings of length `k` that occur more than once in the string `s`. Return the count of such substrings. Note that the s...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3809, "level": 1, "question": "You are given a string `s` and an integer `k`. A **substring** is defined as a contiguous sequence of characters within the string. Calculate the number of distinct substrings of length `k` that occur more than once in the string `s`. Return the count ...
def calculate_reading_time(text: str) -> int: word_count = len(text.split()) return (word_count + 199) // 200
simplelr_Package
[ { "content": "Question:\nYou are required to write a Python function named `calculate_reading_time` that estimates the time it would take to read a given text. This problem will help you practice using string manipulation and basic math operations.\n\nHere's what your function should do:\n\n1. Calculate the tot...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3810, "level": 1, "question": "You are required to write a Python function named `calculate_reading_time` that estimates the time it would take to read a given text. This problem will help you practice using string manipulation and basic math operations.\n\nHere's what your function...
def can_partition(nums: list[int]) -> bool: total = sum(nums) if total % 2 != 0: return False target = total // 2 dp = [False] * (target + 1) dp[0] = True for num in nums: for j in range(target, num - 1, -1): if dp[j - num]: dp[j] = True return dp[...
simplelr_Taco
[ { "content": "Question:\n# Your Task\nGiven a list of integers, your task is to determine if it can be split into two subsets such that the sum of the elements in both subsets is equal. The function should return a boolean indicating whether such a split is possible.\n\n```python\ncan_partition([1, 5, 11, 5]) =...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3811, "level": 1, "question": "# Your Task\nGiven a list of integers, your task is to determine if it can be split into two subsets such that the sum of the elements in both subsets is equal. The function should return a boolean indicating whether such a split is possible.\n\n```pyt...
def minOperations(s, words): n = len(s) dp = [float('inf')] * (n + 1) dp[0] = 0 len_to_words = {} for word in words: l = len(word) if l not in len_to_words: len_to_words[l] = set() len_to_words[l].add(word) for i in range(1, n + 1): for l in len_...
simplelr_Taco
[ { "content": "Question:\nGiven an empty string s and a list of non-empty unique substrings words. An operation is defined as picking one substring from words and removing it from s once. The task is to find out the minimum number of operations needed to make s empty. Each substring in the words list can be used...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3812, "level": 1, "question": "Given an empty string s and a list of non-empty unique substrings words. An operation is defined as picking one substring from words and removing it from s once. The task is to find out the minimum number of operations needed to make s empty. Each subs...
def process_set_commands(commands: list) -> set: """ Process a list of set commands and return the final state of the set. Parameters: commands (list): A list of commands where each command is a tuple. The first element of the tuple is a string denoting the operation, ...
simplelr_Docs
[ { "content": "Question:\n#### Problem Statement\n\nYou are tasked with implementing a function that processes a series of commands to manipulate a set. The function should handle various set operations described in the provided list of commands.\n\n#### Function Signature\n\n```python\ndef process_set_commands(...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3813, "level": 1, "question": "#### Problem Statement\n\nYou are tasked with implementing a function that processes a series of commands to manipulate a set. The function should handle various set operations described in the provided list of commands.\n\n#### Function Signature\n\n`...
def sort_movies_by_rating(movies): return sorted(movies, key=lambda x: x[2], reverse=True)
simplelr_Filter
[ { "content": "Question:\nI've got a list of tuples where each tuple contains information about a movie. I'm having trouble writing a function to sort the movies based on their ratings, in descending order. \n\nFor example, if I have the following list of movies: \n```python\nmovies = [\n (\"Inception\", 2010...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3814, "level": 1, "question": "I've got a list of tuples where each tuple contains information about a movie. I'm having trouble writing a function to sort the movies based on their ratings, in descending order. \n\nFor example, if I have the following list of movies: \n```python\nm...
from collections import defaultdict def merge_orders(orders: list[dict[str, int]]) -> dict[str, int]: merged = defaultdict(int) for order in orders: for item, qty in order.items(): merged[item] += qty return dict(merged)
simplelr_Algorithm
[ { "content": "Question:\n### Problem Statement\n\nYou have been assigned the task of refactoring a component in an order management system. Specifically, the task involves implementing an efficient algorithm to manage and merge users' purchase orders. Users can place multiple orders, and each order contains dis...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3815, "level": 1, "question": "### Problem Statement\n\nYou have been assigned the task of refactoring a component in an order management system. Specifically, the task involves implementing an efficient algorithm to manage and merge users' purchase orders. Users can place multiple ...
import math def compute_escape_velocity(mass: float, radius: float) -> float: G = 6.67430e-11 if mass <= 0: raise ValueError("Mass cannot be 0 or negative") if radius <= 0: raise ValueError("Radius cannot be 0 or negative") escape_velocity = math.sqrt((2 * G * mass) / radius) return...
simplelr_Algorithm
[ { "content": "Question:\n### Context\n\nAs part of a space exploration project, you have been assigned the task of developing software that calculates the escape velocity needed for a spacecraft to break free from a planet's gravitational pull. The escape velocity depends on the mass and the radius of the plane...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3816, "level": 1, "question": "### Context\n\nAs part of a space exploration project, you have been assigned the task of developing software that calculates the escape velocity needed for a spacecraft to break free from a planet's gravitational pull. The escape velocity depends on t...
def longest_balanced_substring(s): seen = {0: -1} balance = 0 max_length = 0 start = 0 end = 0 for i, c in enumerate(s): if c.isalpha(): balance += 1 else: balance -= 1 if balance in seen: current_length = i - seen[balance] ...
simplelr_Apps
[ { "content": "Question:\n# Task\n\nGiven a string `s` consisting of lower-case alphabets and digits, find the longest substring that contains equal numbers of alphabets and digits. If there are multiple substrings with the same length, return the leftmost one. If there is no such substring, return an empty stri...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3817, "level": 1, "question": "# Task\n\nGiven a string `s` consisting of lower-case alphabets and digits, find the longest substring that contains equal numbers of alphabets and digits. If there are multiple substrings with the same length, return the leftmost one. If there is no s...
def average_with_threshold(numbers, threshold): total = 0 count = 0 for num in numbers: if num >= threshold: total += num count += 1 if count == 0: return 0 else: return total / count
simplelr_Filter
[ { "content": "Question:\nWrite a Python program to calculate the average of a list of numbers, but exclude any numbers that are below a certain threshold. The threshold should be a parameter of the function.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3818, "level": 1, "question": "Write a Python program to calculate the average of a list of numbers, but exclude any numbers that are below a certain threshold. The threshold should be a parameter of the function.", "split": "train" }
def top_n_elements(n, lst): if n <= 0: return [] sorted_list = sorted(lst, reverse=True) return sorted_list[:n]
simplelr_Prefill
[ { "content": "Question:\nCreate a function that takes two arguments, an integer n and a list of integers lst, and returns a new list containing the top n elements from the list lst, sorted in descending order. If n is greater than the length of lst, return the entire list sorted in descending order.\nAnswer:\nL...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3819, "level": 1, "question": "Create a function that takes two arguments, an integer n and a list of integers lst, and returns a new list containing the top n elements from the list lst, sorted in descending order. If n is greater than the length of lst, return the entire list sort...
def min_operations_to_make_good(nums, k): return sum(1 for num in nums if num % k != 0)
simplelr_Leetcode
[ { "content": "Question:\nYou are given an array of integers `nums` and an integer `k`. We call an integer `x` a **good number** if `x` is divisible by `k`. Your task is to make all elements of the array `nums` **good numbers** by performing the following operation any number of times: Choose an element of the a...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3820, "level": 1, "question": "You are given an array of integers `nums` and an integer `k`. We call an integer `x` a **good number** if `x` is divisible by `k`. Your task is to make all elements of the array `nums` **good numbers** by performing the following operation any number o...
def first_non_repeating_character(s): freq = {} for char in s: if char in freq: freq[char] += 1 else: freq[char] = 1 for index, char in enumerate(s): if freq[char] == 1: return index return -1
simplelr_Prefill
[ { "content": "Question:\nWrite a python function to find the index of the first non-repeating character in a string. If there is no non-repeating character, return -1. For example, if the input is \"swiss\" the function should return 1 which corresponds to the character 'w'.\nAnswer:\nLet's think step by step.\...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3821, "level": 1, "question": "Write a python function to find the index of the first non-repeating character in a string. If there is no non-repeating character, return -1. For example, if the input is \"swiss\" the function should return 1 which corresponds to the character 'w'.",...
def crawl_website(base_url, useragent): import urllib.robotparser from urllib import request, error import time rp = urllib.robotparser.RobotFileParser() rp.set_url(base_url + "robots.txt") try: rp.read() except error.URLError as e: print(f"Error fetching robots.txt: {e...
simplelr_Docs
[ { "content": "Question:\n### Web Crawler with Robots.txt Adherence\n\n#### Objective:\nImplement a Python function `crawl_website(base_url, useragent)` that crawls the given `base_url`, but adheres to the website's `robots.txt` rules for the specified `useragent`.\n\n#### Description:\n1. The function should fi...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3822, "level": 1, "question": "### Web Crawler with Robots.txt Adherence\n\n#### Objective:\nImplement a Python function `crawl_website(base_url, useragent)` that crawls the given `base_url`, but adheres to the website's `robots.txt` rules for the specified `useragent`.\n\n#### Desc...
def max_light_distance(n, lights): if len(lights) < 2: return 0 sorted_lights = sorted(lights) max_dist = 0 for i in range(1, len(sorted_lights)): current_dist = sorted_lights[i] - sorted_lights[i-1] if current_dist > max_dist: max_dist = current_dist return max_d...
simplelr_Taco
[ { "content": "Question:\nIn a certain land, houses line up on one side of a straight road. The houses are numbered sequentially from left to right starting from 1. During a certain festive season, some houses have lights on.\n\nYou are given an integer `n` representing the total number of houses and a list of i...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3823, "level": 1, "question": "In a certain land, houses line up on one side of a straight road. The houses are numbered sequentially from left to right starting from 1. During a certain festive season, some houses have lights on.\n\nYou are given an integer `n` representing the tot...
def reverse_string(s): return s[::-1]
simplelr_Filter
[ { "content": "Question:\nIs there any way in Python to create a function that takes a lowercase string as input and returns the same string with the characters reversed? Could you provide an example of how this could be implemented?\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3824, "level": 1, "question": "Is there any way in Python to create a function that takes a lowercase string as input and returns the same string with the characters reversed? Could you provide an example of how this could be implemented?", "split": "train" }
def sum_of_integers(lst): total = 0 for number in lst: total += number return total # Test the function test_list = [1, 2, 3, 4, 5] print(f"Sum of {test_list} is {sum_of_integers(test_list)}")
simplelr_Filter
[ { "content": "Question:\nDefine a function in Python that takes a list of integers as input and returns the sum of all the integers in the list. Use a loop to iterate through the list and add up the integers. Test the function with a list of integers of your choice.\nAnswer:\nLet's think step by step.\n", "...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3825, "level": 1, "question": "Define a function in Python that takes a list of integers as input and returns the sum of all the integers in the list. Use a loop to iterate through the list and add up the integers. Test the function with a list of integers of your choice.", "split...
def shortest_subarray_with_k_types(nums, k): min_len = float('inf') count_map = {} unique = 0 left = 0 for right in range(len(nums)): num = nums[right] if num not in count_map or count_map[num] == 0: unique += 1 count_map[num] = count_map.get(num, 0) + 1 ...
simplelr_Leetcode
[ { "content": "Question:\nYou are given an array of integers `nums` and an integer `k`. Each element in the array represents a type of candy, and `k` represents the number of different types of candy you need to collect. The goal is to find the shortest subarray of `nums` that contains at least `k` different typ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3826, "level": 1, "question": "You are given an array of integers `nums` and an integer `k`. Each element in the array represents a type of candy, and `k` represents the number of different types of candy you need to collect. The goal is to find the shortest subarray of `nums` that ...
def euler_totient(n: int) -> int: if n == 1: return 1 original_n = n set_primes = set() # Check for divisibility by 2 if n % 2 == 0: set_primes.add(2) while n % 2 == 0: n = n // 2 # Check for divisibility by odd numbers starting from 3 i = 3 ...
simplelr_Data_Structure
[ { "content": "Question:\n**Problem Statement**:\n\nYou are tasked with implementing a function that utilizes Euler's Totient function to determine the number of integers between 1 and `n` (inclusive) which are coprime to `n`.\n\nGiven an integer `n`, your function should compute the value of ϕ(n) efficiently.\n...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3827, "level": 1, "question": "**Problem Statement**:\n\nYou are tasked with implementing a function that utilizes Euler's Totient function to determine the number of integers between 1 and `n` (inclusive) which are coprime to `n`.\n\nGiven an integer `n`, your function should compu...
def find_first_duplicate(arr): seen = set() for num in arr: if num in seen: return num seen.add(num) return None
simplelr_Filter
[ { "content": "Question:\nI have an array of integers and I want to find the first duplicate in the array. A duplicate is an element that appears at least twice in the array.\n\nHere is an example of an array with a duplicate: `[2, 1, 3, 5, 3, 2]` - The first duplicate is `3`.\n\nHere is an example of an array w...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3828, "level": 1, "question": "I have an array of integers and I want to find the first duplicate in the array. A duplicate is an element that appears at least twice in the array.\n\nHere is an example of an array with a duplicate: `[2, 1, 3, 5, 3, 2]` - The first duplicate is `3`.\...
import math def sieve_of_eratosthenes(n): """ Generates a list of all prime numbers up to n using the Sieve of Eratosthenes algorithm. Args: n (int): The upper limit for finding prime numbers. Returns: list: A list of all prime numbers from 2 to n. """ if n < 2: ...
simplelr_Filter
[ { "content": "Question:\nImplement a program that utilizes Sieve of Eratosthenes algorithm to find all prime numbers up to a given number n. The program should be well-commented and include functions for generating the sieve and identifying prime numbers. The sieve algorithm should begin by assuming all numbers...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3829, "level": 1, "question": "Implement a program that utilizes Sieve of Eratosthenes algorithm to find all prime numbers up to a given number n. The program should be well-commented and include functions for generating the sieve and identifying prime numbers. The sieve algorithm s...
def unique_elements(input_list): seen = set() unique_list = [] for num in input_list: if num not in seen: seen.add(num) unique_list.append(num) return unique_list
simplelr_Filter
[ { "content": "Question:\nWrite a Python function that takes a list of integers as input and returns a new list containing only the unique elements from the input list.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3830, "level": 1, "question": "Write a Python function that takes a list of integers as input and returns a new list containing only the unique elements from the input list.", "split": "train" }
def construct_pattern(n: int) -> str: if n < 1 or n > 26: return "Invalid input" lines = [] for i in range(1, n + 1): line = ' '.join([chr(64 + j) for j in range(1, i + 1)]) lines.append(line) return '\n'.join(lines)
simplelr_Evol
[ { "content": "Question:\nCreate a function `construct_pattern` that takes an integer `n` as input and returns a string that represents a specific pattern. The pattern should be constructed as follows:\n\n1. It will have `n` lines.\n2. The first line will contain only the letter 'A'.\n3. The second line will con...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3831, "level": 1, "question": "Create a function `construct_pattern` that takes an integer `n` as input and returns a string that represents a specific pattern. The pattern should be constructed as follows:\n\n1. It will have `n` lines.\n2. The first line will contain only the lette...
def most_frequent_item(lst): if not lst: return None frequency = {} for item in lst: if item in frequency: frequency[item] += 1 else: frequency[item] = 1 max_count = max(frequency.values()) for item in lst: if frequency[item] == max_count: ...
simplelr_Prefill
[ { "content": "Question:\nWrite a python function to return the most frequent item in a list. If there is a tie, return the item that appears first in the list.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3832, "level": 1, "question": "Write a python function to return the most frequent item in a list. If there is a tie, return the item that appears first in the list.", "split": "train" }
import math def is_prime(n): if n < 2: return False if n == 2: return True if n % 2 == 0: return False sqrt_n = int(math.sqrt(n)) for i in range(3, sqrt_n + 1, 2): if n % i == 0: return False return True
simplelr_Algorithm
[ { "content": "Question:\n### Problem Statement\n\n#### Scenario\nYou are given the task to write a function for a system that processes numerical data to analyze its factors. One of the key functionalities required is to determine if a given number is a prime number or not.\n\n#### Task\nWrite a function `is_pr...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3833, "level": 1, "question": "### Problem Statement\n\n#### Scenario\nYou are given the task to write a function for a system that processes numerical data to analyze its factors. One of the key functionalities required is to determine if a given number is a prime number or not.\n\...
import random def random_walk_2d(n, seed=None): if n <= 0: return [] path = [(0, 0)] if seed is not None: random.seed(seed) directions = [(0, 1), (1, 0), (0, -1), (-1, 0)] x, y = 0, 0 for _ in range(n): dx, dy = random.choice(directions) x += ...
simplelr_Package
[ { "content": "Question:\n### Problem: Simulating a Two-Dimensional Random Walk\n\nIn this problem, you will implement a function to simulate a two-dimensional random walk. A random walk is a path that consists of a series of random steps in a mathematical space. This type of walk is often used to simulate vario...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3834, "level": 1, "question": "### Problem: Simulating a Two-Dimensional Random Walk\n\nIn this problem, you will implement a function to simulate a two-dimensional random walk. A random walk is a path that consists of a series of random steps in a mathematical space. This type of w...
from collections import Counter def anagram_difference(str1: str, str2: str) -> int: counter1 = Counter(str1) counter2 = Counter(str2) all_chars = set(counter1.keys()).union(set(counter2.keys())) total_deletions = 0 for char in all_chars: count1 = counter1.get(char, 0) cou...
simplelr_Algorithm
[ { "content": "Question:\n### Anagram Difference Calculation\n\nYou are tasked with implementing a function that calculates the minimum number of character deletions required to make two strings anagrams of each other. An anagram of a string is another string that contains the same characters, only the order of ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3835, "level": 1, "question": "### Anagram Difference Calculation\n\nYou are tasked with implementing a function that calculates the minimum number of character deletions required to make two strings anagrams of each other. An anagram of a string is another string that contains the ...
def find_longest_word(word_list): """Returns the longest word in the given list. If multiple words have the same maximum length, returns the first encountered.""" if not word_list: return "" longest_word = word_list[0] max_length = len(longest_word) for word in word_list[1:]: if len(...
simplelr_Filter
[ { "content": "Question:\nWrite a Python function that takes a list of words and returns the longest word in the list. If there are multiple words of the same maximum length, return the first one encountered. Include a brief docstring explaining what the function does.\nAnswer:\nLet's think step by step.\n", ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3836, "level": 1, "question": "Write a Python function that takes a list of words and returns the longest word in the list. If there are multiple words of the same maximum length, return the first one encountered. Include a brief docstring explaining what the function does.", "spl...
import os def configure_environment(variable_name: str, new_value: str) -> None: current_value = os.getenv(variable_name) if current_value is not None: print(f"{variable_name} is currently set to: {current_value}") else: print(f"{variable_name} does not currently exist. Adding to the enviro...
simplelr_Docs
[ { "content": "Question:\n**Objective**: The goal of this assignment is to assess your understanding of the `os` module, specifically how to interact with and manipulate environment variables in Python.\n\n### Problem Statement\n\nCreate a Python function named `configure_environment` that performs the following...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3837, "level": 1, "question": "**Objective**: The goal of this assignment is to assess your understanding of the `os` module, specifically how to interact with and manipulate environment variables in Python.\n\n### Problem Statement\n\nCreate a Python function named `configure_envir...
from collections import deque def min_time_to_complete_tasks(tasks: int, dependencies: list[list[int]]) -> int: # Build the adjacency list and in-degree list adj = [[] for _ in range(tasks)] in_degree = [0] * tasks for a, b in dependencies: adj[a].append(b) in_degree[b] += 1 # Kah...
simplelr_Algorithm
[ { "content": "Question:\n### Problem Statement\n\nYou are given a directed acyclic graph (DAG) representation of tasks, where each task may depend on another task. Your goal is to determine the minimum number of time units required to complete all the tasks given that one time unit is needed to complete any tas...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3838, "level": 1, "question": "### Problem Statement\n\nYou are given a directed acyclic graph (DAG) representation of tasks, where each task may depend on another task. Your goal is to determine the minimum number of time units required to complete all the tasks given that one time...
def concatenate_words(words): return ' '.join(words)
simplelr_Prefill
[ { "content": "Question:\nCreate a function that takes a list of words and returns a new list where all the words are concatenated into a single string, separated by spaces.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3839, "level": 1, "question": "Create a function that takes a list of words and returns a new list where all the words are concatenated into a single string, separated by spaces.", "split": "train" }
from typing import List def sum_of_row_max(arr: List[List[int]]) -> int: total = 0 for row in arr: total += max(row) return total
simplelr_Algorithm
[ { "content": "Question:\n### Problem Statement\n\nYou are tasked with implementing a function that calculates the sum of the maximum elements from each row of a given 2D array. The function should return the cumulative sum of these maximum values.\n\n### Function Signature\n```python\ndef sum_of_row_max(arr: Li...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3840, "level": 1, "question": "### Problem Statement\n\nYou are tasked with implementing a function that calculates the sum of the maximum elements from each row of a given 2D array. The function should return the cumulative sum of these maximum values.\n\n### Function Signature\n``...
def filter_even_numbers(input_list): even_numbers = [] for item in input_list: if type(item) is int and item % 2 == 0: even_numbers.append(item) return even_numbers
simplelr_Filter
[ { "content": "Question:\nPlease write a python function that takes in a list of integers and returns a new list that contains only the even numbers from the original list. If there are no even numbers in the original list, the function should return an empty list. Additionally, the function should ignore any no...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3841, "level": 1, "question": "Please write a python function that takes in a list of integers and returns a new list that contains only the even numbers from the original list. If there are no even numbers in the original list, the function should return an empty list. Additionally...
def remove_special_characters(s): return ''.join([c for c in s if c.isalpha()])
simplelr_Prefill
[ { "content": "Question:\nWrite a python function to remove all special characters, numbers, and punctuation from a string, keeping only English alphabet letters.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3842, "level": 1, "question": "Write a python function to remove all special characters, numbers, and punctuation from a string, keeping only English alphabet letters.", "split": "train" }
from typing import List def rotate_array(nums: List[int], k: int) -> List[int]: n = len(nums) effective_k = k % n if effective_k == 0: return nums[:] else: return nums[-effective_k:] + nums[:-effective_k]
simplelr_Apps
[ { "content": "Question:\n# Task\nGiven an integer array `nums`, rotate the array to the right by `k` steps, where `k` is a non-negative integer.\n\nWrite a function:\n```python\ndef rotate_array(nums: List[int], k: int) -> List[int]:\n # your code here\n```\n\n# Input/Output\n- `[input]` integer array `nums`...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3843, "level": 1, "question": "# Task\nGiven an integer array `nums`, rotate the array to the right by `k` steps, where `k` is a non-negative integer.\n\nWrite a function:\n```python\ndef rotate_array(nums: List[int], k: int) -> List[int]:\n # your code here\n```\n\n# Input/Outpu...
def find_index(nums): for index, num in enumerate(nums): if num > 25: return index return -1
simplelr_Taco
[ { "content": "Question:\nGiven an integer array nums, return the index of the first occurrence of an element that is greater than 25. \n\nIf no such element exists, return -1.\n\nExample:\n\nInput: [5, 8, 12, 30, 7, 19]\nOutput: 3\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3844, "level": 1, "question": "Given an integer array nums, return the index of the first occurrence of an element that is greater than 25. \n\nIf no such element exists, return -1.\n\nExample:\n\nInput: [5, 8, 12, 30, 7, 19]\nOutput: 3", "split": "train" }
def competition_results(results): leaderboard = [] for competitor in results: name = competitor['competitor'] total = sum(competitor['points']) leaderboard.append({'competitor': name, 'points': total}) # Sort by points descending, then by name ascending leaderboard.sort(key=lambd...
simplelr_Apps
[ { "content": "Question:\nA company organizes an annual programming competition that consists of several coding challenges. Each challenge has a different difficulty rating and different competitors. Competitors earn points from each challenge based on their performance.\n\nThe competition results are recorded i...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3845, "level": 1, "question": "A company organizes an annual programming competition that consists of several coding challenges. Each challenge has a different difficulty rating and different competitors. Competitors earn points from each challenge based on their performance.\n\nThe...
def product_except_self(nums): if not nums: return [] n = len(nums) left = [1] * n for i in range(1, n): left[i] = left[i-1] * nums[i-1] right = [1] * n for i in range(n-2, -1, -1): right[i] = right[i+1] * nums[i+1] return [left[i] * right[i] for i in range(n)]
simplelr_Apps
[ { "content": "Question:\nWrite a function that takes a list of integers and returns a new list where each element is the product of all other elements in the original list except for the one at that index. Do this without using division. For example:\n```\n[1, 2, 3, 4] --> [24, 12, 8, 6]\n[2, 3, 4, 5] --> [...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3846, "level": 1, "question": "Write a function that takes a list of integers and returns a new list where each element is the product of all other elements in the original list except for the one at that index. Do this without using division. For example:\n```\n[1, 2, 3, 4] --> [...
def reorder_array(arr, pivot): less_or_equal = [x for x in arr if x <= pivot] greater = [x for x in arr if x > pivot] return less_or_equal + greater
simplelr_Filter
[ { "content": "Question:\nGiven an integer array, write a function to reorder the elements such that all elements less than or equal to a specified value come before any elements larger than that value. The order of the elements within these groups doesn't matter. The function should work for both positive and n...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3847, "level": 1, "question": "Given an integer array, write a function to reorder the elements such that all elements less than or equal to a specified value come before any elements larger than that value. The order of the elements within these groups doesn't matter. The function ...
def quicksort(arr): """ Sorts a list of integers in ascending order using the quicksort algorithm. Args: arr (list): A list of integers to be sorted. Returns: list: A new list containing the same integers sorted in ascending order. Notes: Quicksort is a divide-and-conquer ...
simplelr_Prefill
[ { "content": "Question:\nWrite a python function to sort a list of integers in ascending order using the quicksort algorithm. Ensure your function is well-documented and follows best practices for Python coding.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3848, "level": 1, "question": "Write a python function to sort a list of integers in ascending order using the quicksort algorithm. Ensure your function is well-documented and follows best practices for Python coding.", "split": "train" }
from typing import List def mars_house_robber(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 = prev_not_rob + houses[i] current_not_rob = max(prev_rob, prev_not_rob) prev_rob, prev_not_...
simplelr_Data_Structure
[ { "content": "Question:\n### Scenario\nYou are a consultant upgrading the security system of a future colony on Mars. The Martian houses are arranged in a single line, and each house contains some valuables. Your task is to design a robbing strategy so that you can maximize the amount of valuables you rob witho...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3849, "level": 1, "question": "### Scenario\nYou are a consultant upgrading the security system of a future colony on Mars. The Martian houses are arranged in a single line, and each house contains some valuables. Your task is to design a robbing strategy so that you can maximize th...
def swap_dict_keys_values(d): new_dict = {} for key, value in d.items(): if value in new_dict: new_dict[value].append(key) else: new_dict[value] = [key] return new_dict
simplelr_Filter
[ { "content": "Question:\nWrite a Python function that takes a dictionary as an input and returns a new dictionary with the keys and values swapped. If the original dictionary has duplicate values, the function should accumulate the keys in a list for each value. For example, if the input is `{1: 'a', 2: 'b', 3:...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3850, "level": 1, "question": "Write a Python function that takes a dictionary as an input and returns a new dictionary with the keys and values swapped. If the original dictionary has duplicate values, the function should accumulate the keys in a list for each value. For example, i...
def are_all_strings_unique(strings): return len(set(strings)) == len(strings)
simplelr_Filter
[ { "content": "Question:\nWrite a Python function that takes a list of strings and returns `True` if all the strings in the list are unique, and `False` otherwise. The function should be efficient in terms of both time and space complexity.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3851, "level": 1, "question": "Write a Python function that takes a list of strings and returns `True` if all the strings in the list are unique, and `False` otherwise. The function should be efficient in terms of both time and space complexity.", "split": "train" }
def valid_chessboard(arr): allowed = {'.', 'P', 'N', 'B', 'R', 'Q', 'K', 'p', 'n', 'b', 'r', 'q', 'k'} n = len(arr) # Check each cell for validity for row in arr: for cell in row: if cell not in allowed: return False # Initialize counts count_K = 0 ...
simplelr_Apps
[ { "content": "Question:\nYou are given a chessboard with dimensions `n x n`. Each cell on the chessboard can either be empty or occupied by a piece. Each piece can either be a pawn, knight, bishop, rook, queen, or king. The pieces can be of either white or black color.\n\nYour task is to write a function `valid...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3852, "level": 1, "question": "You are given a chessboard with dimensions `n x n`. Each cell on the chessboard can either be empty or occupied by a piece. Each piece can either be a pawn, knight, bishop, rook, queen, or king. The pieces can be of either white or black color.\n\nYour...
def create_grid(rows, columns): if rows <= 0 or columns <= 0: return "" row = ' '.join(['X'] * columns) return '\n'.join([row] * rows)
simplelr_Apps
[ { "content": "Question:\nWrite a function that takes two integers as arguments and returns a string. The two integers represent the dimensions of a grid (rows and columns). Your function should visualize the grid following these rules:\n\n- Each cell in the grid should be represented by the character \"X\".\n- ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3853, "level": 1, "question": "Write a function that takes two integers as arguments and returns a string. The two integers represent the dimensions of a grid (rows and columns). Your function should visualize the grid following these rules:\n\n- Each cell in the grid should be repr...
from typing import List, Tuple def max_profit_days(prices: List[float]) -> Tuple[int, int]: if len(prices) < 2: return (-1, -1) min_price = prices[0] min_index = 0 max_profit = float('-inf') buy_day = -1 sell_day = -1 for i in range(1, len(prices)): current_price =...
simplelr_Algorithm
[ { "content": "Question:\n### Problem Statement\nYou are given a function that returns the daily stock prices of a company over a certain period. Your task is to implement an algorithm that identifies periods of maximum profit for both buying and selling stocks. Specifically, you should find the best day to buy ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3854, "level": 1, "question": "### Problem Statement\nYou are given a function that returns the daily stock prices of a company over a certain period. Your task is to implement an algorithm that identifies periods of maximum profit for both buying and selling stocks. Specifically, y...
def reverse_array(arr): return arr[::-1]
simplelr_Prefill
[ { "content": "Question:\nCreate a function that rearranges the elements of a given array in reverse order.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3855, "level": 1, "question": "Create a function that rearranges the elements of a given array in reverse order.", "split": "train" }
def count_unique_elements(nums, k): frequency = {} for num in nums: if num in frequency: frequency[num] += 1 else: frequency[num] = 1 count = 0 for v in frequency.values(): if v >= k: count += 1 return count
simplelr_Apps
[ { "content": "Question:\nGiven an integer array nums and an integer k, return the number of unique elements that appear at least k times in nums.\n\nExample 1:\nInput: nums = [1,2,3,1,2,3,1,2,3], k = 2\nOutput: 3\n\nExample 2:\nInput: nums = [1,2,2,3,3,3,4], k = 2\nOutput: 2\n\nExample 3:\nInput: nums = [1,2,3,...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3856, "level": 1, "question": "Given an integer array nums and an integer k, return the number of unique elements that appear at least k times in nums.\n\nExample 1:\nInput: nums = [1,2,3,1,2,3,1,2,3], k = 2\nOutput: 3\n\nExample 2:\nInput: nums = [1,2,2,3,3,3,4], k = 2\nOutput: 2\n...
import string from collections import defaultdict def count_words(sentence): sentence_lower = sentence.lower() words = sentence_lower.split() word_counts = defaultdict(int) for word in words: cleaned_word = word.strip(string.punctuation) if cleaned_word: word_counts[cle...
simplelr_Evol
[ { "content": "Question:\nCreate a Python function that takes a sentence as input and returns a dictionary where the keys are the words, and the values are the counts of their occurrences, sorted by the counts in descending order. Ignore punctuation and consider letter case insensitive.\nAnswer:\nLet's think ste...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3857, "level": 1, "question": "Create a Python function that takes a sentence as input and returns a dictionary where the keys are the words, and the values are the counts of their occurrences, sorted by the counts in descending order. Ignore punctuation and consider letter case ins...
def min_transformations(s1: str, s2: str) -> int: m = len(s1) n = len(s2) dp = [[0] * (n + 1) for _ in range(m + 1)] for i in range(m + 1): dp[i][0] = i for j in range(n + 1): dp[0][j] = j for i in range(1, m + 1): for j in range(1, n + 1): cost = 0 ...
simplelr_Codeforces
[ { "content": "Question:\nYou are given two strings, `s1` and `s2`, and your task is to transform `s1` into `s2` using the minimum number of operations. You can perform the following operations on `s1`:\n\n1. Insertion of a character.\n2. Deletion of a character.\n3. Substitution of a character with another char...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3858, "level": 1, "question": "You are given two strings, `s1` and `s2`, and your task is to transform `s1` into `s2` using the minimum number of operations. You can perform the following operations on `s1`:\n\n1. Insertion of a character.\n2. Deletion of a character.\n3. Substituti...
from typing import List def custom_pivot_sort(arr: List[int], pivot: int) -> List[int]: # Create a list of tuples containing the absolute difference, original index, and the element elements = [(abs(x - pivot), i, x) for i, x in enumerate(arr)] # Sort the list of tuples first by the absolute differenc...
simplelr_Data_Structure
[ { "content": "Question:\n### Question\n\nYou are tasked with sorting a list of integers using a custom sorting algorithm inspired by Exchange Sort, but with a twist. Instead of a simple comparison, the algorithm should swap elements based on the absolute difference with a pivot value. This 'pivot' value will be...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3859, "level": 1, "question": "### Question\n\nYou are tasked with sorting a list of integers using a custom sorting algorithm inspired by Exchange Sort, but with a twist. Instead of a simple comparison, the algorithm should swap elements based on the absolute difference with a pivo...
def find_largest_number(arr): max_num = float('-inf') for row in arr: for num in row: if num > max_num: max_num = num return max_num
simplelr_Prefill
[ { "content": "Question:\nCreate a function that indentifies the largest number in a 2D array.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3860, "level": 1, "question": "Create a function that indentifies the largest number in a 2D array.", "split": "train" }
def longest_bitonic_subsequence(arr): n = len(arr) if n == 0: return 0 # Compute increasing subsequence lengths inc = [1] * n for i in range(n): for j in range(i): if arr[j] < arr[i]: if inc[i] < inc[j] + 1: inc[i] = inc[j] + 1 # Co...
simplelr_Taco
[ { "content": "Question:\nSarah is a computer programmer working on a software module that involves processing sequences of positive integers. There's a particular task where she needs to detect a specific pattern within these sequences. The pattern she's looking for is a \"bitonic subsequence\" of a given seque...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3861, "level": 1, "question": "Sarah is a computer programmer working on a software module that involves processing sequences of positive integers. There's a particular task where she needs to detect a specific pattern within these sequences. The pattern she's looking for is a \"bit...
from collections import Counter def sock_merchant(n, ar): color_counts = Counter(ar) total_pairs = 0 for count in color_counts.values(): total_pairs += count // 2 return total_pairs
simplelr_Filter
[ { "content": "Question:\n### Data Structures and Algorithms in Python\n#### Problem: Sales by Match\nIt's her birthday and we are going to buy her the best socks in the store.\nThe store has $n$ socks and they are all different, but in order to form a pair, the socks must have the same color.\nThe socks are rep...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3862, "level": 1, "question": "### Data Structures and Algorithms in Python\n#### Problem: Sales by Match\nIt's her birthday and we are going to buy her the best socks in the store.\nThe store has $n$ socks and they are all different, but in order to form a pair, the socks must have...
from collections import Counter def matching_integers_count(list1, list2): counter1 = Counter(list1) counter2 = Counter(list2) common_keys = counter1.keys() & counter2.keys() total = 0 for key in common_keys: total += min(counter1[key], counter2[key]) return total
simplelr_Prefill
[ { "content": "Question:\nCreate a function that takes two lists of integers and returns the count of matching integers, including those that appear multiple times. For example, if the first list is [1, 2, 2, 3] and the second list is [2, 2, 4, 6], the function should return 2, because there are two matching int...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3863, "level": 1, "question": "Create a function that takes two lists of integers and returns the count of matching integers, including those that appear multiple times. For example, if the first list is [1, 2, 2, 3] and the second list is [2, 2, 4, 6], the function should return 2,...
def remove_duplicates(lst): seen = set() result = [] for num in lst: if num not in seen: result.append(num) seen.add(num) return result
simplelr_Package
[ { "content": "Question:\nYour task is to implement a function `remove_duplicates(lst)` that takes a list of integers `lst` and returns a new list with all duplicate elements removed while preserving the order of the first occurrence of each unique element.\n\nTo achieve this, you should:\n\n1. Traverse through ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3864, "level": 1, "question": "Your task is to implement a function `remove_duplicates(lst)` that takes a list of integers `lst` and returns a new list with all duplicate elements removed while preserving the order of the first occurrence of each unique element.\n\nTo achieve this, ...
def subsequence_occurrences(s: str, t: str) -> int: n = len(t) m = len(s) # Initialize DP table dp = [[0] * (m + 1) for _ in range(n + 1)] # Base case: empty substring of t has one subsequence (itself) for j in range(m + 1): dp[0][j] = 1 # Fill the DP table for i i...
simplelr_Taco
[ { "content": "Question:\nWrite a function `subsequence_occurrences(s: str, t: str) -> int` that takes two strings `s` and `t`, and returns the number of distinct subsequences of `t` that can be found in `s`.\n\nA subsequence is a sequence that can be derived from another sequence by deleting some or no elements...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3865, "level": 1, "question": "Write a function `subsequence_occurrences(s: str, t: str) -> int` that takes two strings `s` and `t`, and returns the number of distinct subsequences of `t` that can be found in `s`.\n\nA subsequence is a sequence that can be derived from another seque...
def longest_common_prefix(str1, str2): prefix = [] for a, b in zip(str1, str2): if a == b: prefix.append(a) else: break return ''.join(prefix)
simplelr_Filter
[ { "content": "Question:\nI'm working on a project where I need to determine the similarity between two strings. I've decided to use the longest common prefix as a measure of similarity. How can I implement this in Python?\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3866, "level": 1, "question": "I'm working on a project where I need to determine the similarity between two strings. I've decided to use the longest common prefix as a measure of similarity. How can I implement this in Python?", "split": "train" }
def max_rect_area(heights): stack = [-1] max_area = 0 n = len(heights) for i in range(n): while stack[-1] != -1 and heights[i] < heights[stack[-1]]: h = stack.pop() width = i - stack[-1] - 1 area = heights[h] * width if area > max_area: ...
simplelr_Leetcode
[ { "content": "Question:\nYou are given an array `heights` representing the heights of buildings where each height `heights[i]` is the height of a building at position `i`. You are tasked with finding the maximum area of a rectangular section that can be formed using adjacent buildings. Each building forms a wid...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3867, "level": 1, "question": "You are given an array `heights` representing the heights of buildings where each height `heights[i]` is the height of a building at position `i`. You are tasked with finding the maximum area of a rectangular section that can be formed using adjacent b...
import re def replace_substring_case_insensitive(original, target, replacement): pattern = re.compile(re.escape(target), re.IGNORECASE) return pattern.sub(replacement, original)
simplelr_Filter
[ { "content": "Question:\nWrite a code to replace all occurrences of a given substring inside a string with another substring, ensuring case-insensitive replacement.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3868, "level": 1, "question": "Write a code to replace all occurrences of a given substring inside a string with another substring, ensuring case-insensitive replacement.", "split": "train" }
def get_unique_ids(people): return {person['id'] for person in people}
simplelr_Filter
[ { "content": "Question:\nI've been working on my skills in functional programming and I've hit a bit of a hurdle. I have a list of dictionaries where each dictionary has a key called 'id' and I want to extract all the unique ids from the list of dictionaries and put them into a set. \n\nHere's an example of wha...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3869, "level": 1, "question": "I've been working on my skills in functional programming and I've hit a bit of a hurdle. I have a list of dictionaries where each dictionary has a key called 'id' and I want to extract all the unique ids from the list of dictionaries and put them into ...
from collections import Counter def is_quasi_palindrome(n): s = str(n) counts = Counter(s) odd_counts = 0 for count in counts.values(): if count % 2 != 0: odd_counts += 1 return odd_counts <= 1
simplelr_Apps
[ { "content": "Question:\nCreate a function to calculate the \"quasi-palindrome\" status of a given integer. A quasi-palindrome number is one that can be rearranged to form a palindrome, a sequence that reads the same backward as forward.\n\nThe function should take an integer as input. Determine the frequency o...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3870, "level": 1, "question": "Create a function to calculate the \"quasi-palindrome\" status of a given integer. A quasi-palindrome number is one that can be rearranged to form a palindrome, a sequence that reads the same backward as forward.\n\nThe function should take an integer ...
def factorial(n): """ Calculate the factorial of a number n using recursion. Args: n (int): The number to calculate the factorial of. Returns: int: The factorial of n. Raises: ValueError: If n is greater than 100. """ if n > 100: raise ValueErro...
simplelr_Filter
[ { "content": "Question:\nConvert the following code snippet that calculates the factorial of a number using for loop into equivalent code using a recursive method with an additional constraint - the maximum value of n to be 100.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3871, "level": 1, "question": "Convert the following code snippet that calculates the factorial of a number using for loop into equivalent code using a recursive method with an additional constraint - the maximum value of n to be 100.", "split": "train" }
def minPathSum(grid): m = len(grid) n = len(grid[0]) if m > 0 else 0 if m == 0 or n == 0: return 0 # Create DP table dp = [[0 for _ in range(n)] for _ in range(m)] # Initialize the top-left cell dp[0][0] = grid[0][0] # Fill the first row for j in range(1, ...
simplelr_Taco
[ { "content": "Question:\nGiven a 2D matrix of size m x n filled with non-negative integers, you need to find a path from the top-left cell to the bottom-right cell (both inclusive) such that the sum of the values in the path is minimized. From a given cell, you can move to any of the adjacent cells - down or to...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3872, "level": 1, "question": "Given a 2D matrix of size m x n filled with non-negative integers, you need to find a path from the top-left cell to the bottom-right cell (both inclusive) such that the sum of the values in the path is minimized. From a given cell, you can move to any...
import random def generate_random_integer(): return random.randint(1, 10)
simplelr_Prefill
[ { "content": "Question:\nWrite a python function to generate a random integer between 1 and 10 using the random library.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3873, "level": 1, "question": "Write a python function to generate a random integer between 1 and 10 using the random library.", "split": "train" }
from collections import Counter import string def second_most_frequent_word(s): # Convert the string to lowercase s_lower = s.lower() # Split into tokens based on whitespace tokens = s_lower.split() # Process each token to remove leading and trailing punctuation words = [] for token in toke...
simplelr_Prefill
[ { "content": "Question:\nWrite a python function to find the second most frequent word in a given string. If there is no second most frequent word, return None. The function should be case-insensitive and should ignore punctuation.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3874, "level": 1, "question": "Write a python function to find the second most frequent word in a given string. If there is no second most frequent word, return None. The function should be case-insensitive and should ignore punctuation.", "split": "train" }
from collections import Counter import heapq def reorganize_string(s): count = Counter(s) max_freq = max(count.values()) if count else 0 n = len(s) if max_freq > (n + 1) // 2: return "IMPOSSIBLE" max_heap = [] for char, cnt in count.items(): heapq.heappush(max_heap, (-...
simplelr_Taco
[ { "content": "Question:\nGiven a string consisting of lowercase English letters, you are required to construct a new string by rearranging the letters of the given string. The new string must not contain two consecutive identical characters. If there are multiple possible solutions, any one of them is acceptabl...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3875, "level": 1, "question": "Given a string consisting of lowercase English letters, you are required to construct a new string by rearranging the letters of the given string. The new string must not contain two consecutive identical characters. If there are multiple possible solu...
def unique_integers(lst): seen = set() result = [] for num in lst: if num not in seen: result.append(num) seen.add(num) return result
simplelr_Filter
[ { "content": "Question:\nYou have been tasked with writing a function that takes a list of integers as input and returns a new list containing all the unique integers from the input list, with each integer appearing in the order it first appears in the input list.\nAnswer:\nLet's think step by step.\n", "ro...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3876, "level": 1, "question": "You have been tasked with writing a function that takes a list of integers as input and returns a new list containing all the unique integers from the input list, with each integer appearing in the order it first appears in the input list.", "split":...
def min_insertions_to_make_palindrome(s): n = len(s) if n == 0: return 0 # Create a DP table with n rows and n columns dp = [[0] * n for _ in range(n)] # All substrings of length 1 are palindromes for i in range(n): dp[i][i] = 1 # Fill the table for substrings of le...
simplelr_Leetcode
[ { "content": "Question:\nGiven a string `s`, return _the minimum number of insertions needed to make_ `s` _a palindrome_. A palindrome is a string that reads the same forward and backward. You can insert characters anywhere in the string.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3877, "level": 1, "question": "Given a string `s`, return _the minimum number of insertions needed to make_ `s` _a palindrome_. A palindrome is a string that reads the same forward and backward. You can insert characters anywhere in the string.", "split": "train" }
def reverse_string(s): return s[::-1]
simplelr_Prefill
[ { "content": "Question:\nCreate a function that takes a string and returns a new string with all the characters in reverse order. The function should be named `reverse_string` and should take a single string argument.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3878, "level": 1, "question": "Create a function that takes a string and returns a new string with all the characters in reverse order. The function should be named `reverse_string` and should take a single string argument.", "split": "train" }
import heapq def merge_k_sorted_lists(lists): heap = [] for i in range(len(lists)): if lists[i]: heapq.heappush(heap, (lists[i][0], i, 0)) result = [] while heap: val, list_idx, elem_idx = heapq.heappop(heap) result.append(val) if elem_idx + 1 < len...
simplelr_Filter
[ { "content": "Question:\nSay you have k sorted lists of integers. Write a program that merges these k sorted lists and returns a single sorted list.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3879, "level": 1, "question": "Say you have k sorted lists of integers. Write a program that merges these k sorted lists and returns a single sorted list.", "split": "train" }
def nearest_person(houses): n = len(houses) max_dist = n # The maximum possible distance is n (when all houses are to one side) left_dist = [max_dist] * n last_seen = -max_dist # Initialize to a position far to the left (effectively indicating no person seen) # Left pass to find distance to t...
simplelr_Taco
[ { "content": "Question:\nThere are N houses in a row, numbered from 1 to N. Some houses have people living in them, while others are vacant. You are given an integer array `houses` of length N where `houses[i]` is 1 if there's a person living in the house i+1, and 0 if the house is vacant. \n\nYou need to deter...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3880, "level": 1, "question": "There are N houses in a row, numbered from 1 to N. Some houses have people living in them, while others are vacant. You are given an integer array `houses` of length N where `houses[i]` is 1 if there's a person living in the house i+1, and 0 if the hou...
def dailyTemperatures(temperatures): temp_len = len(temperatures) result = [0] * temp_len stack = [] for i in range(temp_len): while stack and temperatures[i] > temperatures[stack[-1]]: j = stack.pop() result[j] = i - j stack.append(i) return result
simplelr_Filter
[ { "content": "Question:\nYou're given an array of integers representing daily temperatures. For each day, you want to find the number of days you have to wait until a warmer temperature. If there is no future day with a warmer temperature, return 0.\n\nFor example:\n\n```\nInput: temperatures = [73, 74, 75, 71,...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3881, "level": 1, "question": "You're given an array of integers representing daily temperatures. For each day, you want to find the number of days you have to wait until a warmer temperature. If there is no future day with a warmer temperature, return 0.\n\nFor example:\n\n```\nInp...
def count_set_bits(n): count = 0 while n > 0: count += n & 1 n >>= 1 return count
simplelr_Prefill
[ { "content": "Question:\nWrite a python function to calculate the number of set bits (1-bits) in the binary representation of a given non-negative integer. This function should be efficient and handle large integers well.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3882, "level": 1, "question": "Write a python function to calculate the number of set bits (1-bits) in the binary representation of a given non-negative integer. This function should be efficient and handle large integers well.", "split": "train" }
def count_words(s): words = s.split() counts = {} for word in words: if word in counts: counts[word] += 1 else: counts[word] = 1 return counts
simplelr_Apps
[ { "content": "Question:\n## Count Occurrences of Words in a String\n\nWrite a function that counts the occurrences of each word in a given string. The function should take a single parameter, `s`, which is a string containing words separated by spaces. The output should be a dictionary where the keys are the wo...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3883, "level": 1, "question": "## Count Occurrences of Words in a String\n\nWrite a function that counts the occurrences of each word in a given string. The function should take a single parameter, `s`, which is a string containing words separated by spaces. The output should be a d...
def can_schedule(meetings: list[tuple[int, int]], new_meeting: tuple[int, int]) -> bool: new_start, new_end = new_meeting for meeting in meetings: s, e = meeting if new_start < e and s < new_end: return False return True
simplelr_Code_Contests
[ { "content": "Question:\nAlex is a software developer who needs to write a program to manage people's meetings. He wants to create a function that handles adding people to the meeting schedule while making sure that he does not create any time conflicts.\n\nA meeting is represented as a tuple of two integers, (...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3884, "level": 1, "question": "Alex is a software developer who needs to write a program to manage people's meetings. He wants to create a function that handles adding people to the meeting schedule while making sure that he does not create any time conflicts.\n\nA meeting is repres...
def find_maximum(numbers): if not numbers: return None return max(numbers)
simplelr_Filter
[ { "content": "Question:\nI'm trying to find the maximum value in a list of numbers using a Python function. The function should take a list of numbers as input and return the maximum value. If the list is empty, the function should return None. How can I implement this function?\nAnswer:\nLet's think step by st...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3885, "level": 1, "question": "I'm trying to find the maximum value in a list of numbers using a Python function. The function should take a list of numbers as input and return the maximum value. If the list is empty, the function should return None. How can I implement this functio...
def restore_string(s, indices): n = len(s) res = [''] * n for i in range(n): res[indices[i]] = s[i] return ''.join(res)
simplelr_Leetcode
[ { "content": "Question:\nYou are given a string `s` of length `n` containing only lowercase alphabets and a list of integers `indices` of length `n` where `indices[i]` represents the new position of the `ith` character in the shuffled string. Return _the shuffled string_. The string `s` should be shuffled in su...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3886, "level": 1, "question": "You are given a string `s` of length `n` containing only lowercase alphabets and a list of integers `indices` of length `n` where `indices[i]` represents the new position of the `ith` character in the shuffled string. Return _the shuffled string_. The ...
def rotateLeft(d, arr): n = len(arr) k = d % n return arr[k:] + arr[:k]
simplelr_Taco
[ { "content": "Question:\nGiven an array of integers and a positive integer $\\boldsymbol{d}$, rotate the array to the left $\\boldsymbol{d}$ times. To perform a left rotation on an array, shift each of the array's elements $\\boldsymbol{d}$ units to the left. The value at the first index should move to the last...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3887, "level": 1, "question": "Given an array of integers and a positive integer $\\boldsymbol{d}$, rotate the array to the left $\\boldsymbol{d}$ times. To perform a left rotation on an array, shift each of the array's elements $\\boldsymbol{d}$ units to the left. The value at the ...
from urllib.parse import urlparse, parse_qs def parse_url(url: str) -> dict: parsed_url = urlparse(url) scheme = parsed_url.scheme domain = parsed_url.hostname if parsed_url.hostname else "" path = parsed_url.path query = {} query_params = parse_qs(parsed_url.query) for key, value...
simplelr_Algorithm
[ { "content": "Question:\n### Problem Description\n\nYou are tasked with writing a function to validate and parse a URL, extracting specific components from it. The components of interest are the scheme (protocol), domain name, path, and query parameters. Your function should return these components in a structu...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3888, "level": 1, "question": "### Problem Description\n\nYou are tasked with writing a function to validate and parse a URL, extracting specific components from it. The components of interest are the scheme (protocol), domain name, path, and query parameters. Your function should r...
def is_anagram(s1: str, s2: str) -> bool: # Process each string to remove non-alphabetic characters and convert to lowercase processed1 = ''.join([c.lower() for c in s1 if c.isalpha()]) processed2 = ''.join([c.lower() for c in s2 if c.isalpha()]) # Sort both processed strings and compare return...
simplelr_Taco
[ { "content": "Question:\nImplement a function called `is_anagram` that checks whether two given strings are anagrams of each other. An anagram of a string is another string that contains the same characters, only the order of characters can be different. The function should be case-insensitive and ignore spaces...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3889, "level": 1, "question": "Implement a function called `is_anagram` that checks whether two given strings are anagrams of each other. An anagram of a string is another string that contains the same characters, only the order of characters can be different. The function should be...
def list_allergies(score): allergies = [] allergy_list = [ (1, 'Eggs'), (2, 'Peanuts'), (4, 'Shellfish'), (8, 'Strawberries'), (16, 'Tomatoes'), (32, 'Chocolate'), (64, 'Pollen'), (128, 'Cats') ] for value, name in allergy_list: if ...
simplelr_Prefill
[ { "content": "Question:\nCreate a function that returns the allergies a person has based on the score passed to it. The function should take one integer as a parameter and return a string that lists all the allergies.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3890, "level": 1, "question": "Create a function that returns the allergies a person has based on the score passed to it. The function should take one integer as a parameter and return a string that lists all the allergies.", "split": "train" }
def min_operations_to_reduce_size(nums, k): return max(0, len(nums) - k)
simplelr_Leetcode
[ { "content": "Question:\nYou are given an array `nums` of integers and a target integer `k`. You need to find the **minimum** number of operations required to reduce the array to a size of exactly `k`. An operation is defined as removing any one element from the array. Return _the minimum number of operations n...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3891, "level": 1, "question": "You are given an array `nums` of integers and a target integer `k`. You need to find the **minimum** number of operations required to reduce the array to a size of exactly `k`. An operation is defined as removing any one element from the array. Return ...
def sum_of_boundaries(matrix): if not matrix or len(matrix) == 0 or len(matrix[0]) == 0: return 0 rows = len(matrix) cols = len(matrix[0]) if rows == 1 and cols == 1: return matrix[0][0] sum_b = sum(matrix[0]) if rows > 1: sum_b += sum(matrix[-1]) for i...
simplelr_Filter
[ { "content": "Question:\nCan you help me write a Python code to find the sum of the boundaries of a 2D array? By boundaries, I mean the first row, last row, first column, and last column of the array.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3892, "level": 1, "question": "Can you help me write a Python code to find the sum of the boundaries of a 2D array? By boundaries, I mean the first row, last row, first column, and last column of the array.", "split": "train" }
def get_last_element(lst): return lst[-1] if lst else None
simplelr_Prefill
[ { "content": "Question:\nCreate a function that retrieves the last element from a given list in Python.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3893, "level": 1, "question": "Create a function that retrieves the last element from a given list in Python.", "split": "train" }
import math def is_prime(n): if n < 2: return False for i in range(2, int(math.sqrt(n)) + 1): if n % i == 0: return False return True
simplelr_Filter
[ { "content": "Question:\nI need help understanding how to write a basic Python function that checks if a number is prime. Can you guide me through it?\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3894, "level": 1, "question": "I need help understanding how to write a basic Python function that checks if a number is prime. Can you guide me through it?", "split": "train" }
from typing import List def evaluate_xor_expression(expression: List[int]) -> int: result = expression[0] for num in expression[1:]: result ^= num return result
simplelr_Algorithm
[ { "content": "Question:\n### XOR Gate Implementation and Boolean Expression Evaluation\n\nYou are given a function that emulates the behavior of a simple XOR logic gate. Your task is to write a Python function that will evaluate a boolean expression consisting of a series of XOR operations between multiple bool...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3895, "level": 1, "question": "### XOR Gate Implementation and Boolean Expression Evaluation\n\nYou are given a function that emulates the behavior of a simple XOR logic gate. Your task is to write a Python function that will evaluate a boolean expression consisting of a series of X...
def longest_common_substring(string1, string2): m = len(string1) n = len(string2) dp = [[0] * (n + 1) for _ in range(m + 1)] max_length = 0 for i in range(1, m + 1): for j in range(1, n + 1): if string1[i - 1] == string2[j - 1]: dp[i][j] = dp[i - 1][j - 1] + 1 ...
simplelr_Prefill
[ { "content": "Question:\nWrite a python function to return the length of the longest common substring between two given strings string1 and string2.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3896, "level": 1, "question": "Write a python function to return the length of the longest common substring between two given strings string1 and string2.", "split": "train" }
import zipimport def import_and_use_modules(zip_file: str) -> dict: # Create an importer for the given zip file importer = zipimport.zipimporter(zip_file) # Import the modules module_a = importer.load_module('module_a') module_b = importer.load_module('module_b') # Call the greet function with ...
simplelr_Docs
[ { "content": "Question:\n#### Objective:\nCreate a Python script that demonstrates your ability to dynamically import and utilize Python modules from a ZIP archive.\n\n#### Problem Statement:\nYou are provided with a ZIP file named `modules.zip` which contains two Python modules `module_a.py` and `module_b.py`....
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3897, "level": 1, "question": "#### Objective:\nCreate a Python script that demonstrates your ability to dynamically import and utilize Python modules from a ZIP archive.\n\n#### Problem Statement:\nYou are provided with a ZIP file named `modules.zip` which contains two Python modul...
def longest_unique_subarray(nums): last_occurrence = {} max_len = 0 start = 0 left = 0 for right in range(len(nums)): current_num = nums[right] if current_num in last_occurrence and last_occurrence[current_num] >= left: left = last_occurrence[current_num] + 1 last...
simplelr_Leetcode
[ { "content": "Question:\nGiven an array of integers `nums`, return the **longest contiguous subarray** that contains only unique elements. If there are multiple such subarrays, return the one that occurs first. \n\nFor example:\n- Given `nums = [1, 2, 3, 1, 2, 3, 4, 5]`, the function should return `[1, 2, 3, 4,...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3898, "level": 1, "question": "Given an array of integers `nums`, return the **longest contiguous subarray** that contains only unique elements. If there are multiple such subarrays, return the one that occurs first. \n\nFor example:\n- Given `nums = [1, 2, 3, 1, 2, 3, 4, 5]`, the f...
def count_distinct_characters(s): return len(set(s))
simplelr_Apps
[ { "content": "Question:\nComplete the function `count_distinct_characters` (or equivalent, depending on your language) that takes a string as input and returns the number of distinct characters in that string. You may assume the input is always valid and consists of only printable ASCII characters.\n\n## Exampl...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 3899, "level": 1, "question": "Complete the function `count_distinct_characters` (or equivalent, depending on your language) that takes a string as input and returns the number of distinct characters in that string. You may assume the input is always valid and consists of only print...