target stringlengths 29 3.65k | data_source stringclasses 12
values | prompt listlengths 1 1 | ability stringclasses 1
value | reward_model dict | extra_info dict |
|---|---|---|---|---|---|
import heapq
def process_transactions(transactions):
lower = [] # Max-heap implemented using min-heap with negated values
upper = [] # Min-heap
medians = []
for num in transactions:
if lower and num <= -lower[0]:
heapq.heappush(lower, -num)
else:
heapq.hea... | simplelr_Docs | [
{
"content": "Question:\n### Description\nYou are given a stream of numerical data, representing transaction amounts being processed by a bank. To efficiently manage fraud detection and reporting, you need to maintain a list of these transaction amounts in sorted order. Additionally, you should be able to effic... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9000,
"level": 1,
"question": "### Description\nYou are given a stream of numerical data, representing transaction amounts being processed by a bank. To efficiently manage fraud detection and reporting, you need to maintain a list of these transaction amounts in sorted order. Additi... |
def generateSubsets(numbers):
numbers = sorted(numbers)
n = len(numbers)
subsets = []
for mask in range(1 << n):
subset = [numbers[i] for i in range(n) if (mask >> i) & 1]
subsets.append(subset)
subsets.sort()
return subsets
| simplelr_Taco | [
{
"content": "Question:\nWrite a function `generateSubsets(numbers)` to generate all possible distinct subsets of the given list of integers `numbers`. The function should return the subsets as a list of lists, with each subset being sorted in non-decreasing order, and the list of subsets should also be sorted ... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9001,
"level": 1,
"question": "Write a function `generateSubsets(numbers)` to generate all possible distinct subsets of the given list of integers `numbers`. The function should return the subsets as a list of lists, with each subset being sorted in non-decreasing order, and the lis... |
def sort_tuples_by_second_item(tuples_list):
return sorted(tuples_list, key=lambda x: x[1]) | simplelr_Filter | [
{
"content": "Question:\nCan you explain the task in the given text \"Given a list of tuples, write a Python function to sort the list based on the second item of each tuple\"?\nAnswer:\nLet's think step by step.\n",
"role": "user"
}
] | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9002,
"level": 1,
"question": "Can you explain the task in the given text \"Given a list of tuples, write a Python function to sort the list based on the second item of each tuple\"?",
"split": "train"
} |
def sort_string(s):
uppercase = [c for c in s if c.isupper()]
lowercase = [c for c in s if c.islower()]
return ''.join(sorted(uppercase) + sorted(lowercase)) | simplelr_Prefill | [
{
"content": "Question:\nCreate a function that takes a string as input and returns the string in a case-insensitive alphabetical order. Sort the characters in the string such that all uppercase letters come first, followed by all lowercase letters, and each group is sorted alphabetically.\nAnswer:\nLet's think... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9003,
"level": 1,
"question": "Create a function that takes a string as input and returns the string in a case-insensitive alphabetical order. Sort the characters in the string such that all uppercase letters come first, followed by all lowercase letters, and each group is sorted al... |
def find_max_min(lst):
if not lst:
raise ValueError("List is empty")
max_val = min_val = lst[0]
for num in lst[1:]:
if num > max_val:
max_val = num
if num < min_val:
min_val = num
return (max_val, min_val) | simplelr_Prefill | [
{
"content": "Question:\nWrite a python function to find the maximum and minimum values in a list of integers using a single traversal of the list.\nAnswer:\nLet's think step by step.\n",
"role": "user"
}
] | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9004,
"level": 1,
"question": "Write a python function to find the maximum and minimum values in a list of integers using a single traversal of the list.",
"split": "train"
} |
import datetime
def day_of_week(year: int, month: int, day: int) -> str:
"""
Returns the day of the week for the given date as a string.
Args:
year (int): The year of the date.
month (int): The month of the date.
day (int): The day of the date.
Returns:
str: Th... | simplelr_Filter | [
{
"content": "Question:\nI need to create a Python function that can determine the day of the week for any given date. How can I achieve this?\nAnswer:\nLet's think step by step.\n",
"role": "user"
}
] | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9005,
"level": 1,
"question": "I need to create a Python function that can determine the day of the week for any given date. How can I achieve this?",
"split": "train"
} |
from typing import List
def sort_by_custom_order(arr: List[int], order: List[int]) -> List[int]:
order_index = {value: idx for idx, value in enumerate(order)}
return sorted(arr, key=lambda x: order_index[x]) | simplelr_Package | [
{
"content": "Question:\n**Task**: Write a function `sort_by_custom_order(arr: List[int], order: List[int]) -> List[int]` that takes an array of integers and sorts it according to a specified custom order provided in a list.\n\n**Parameters**:\n- `arr`: A list of integers that needs to be sorted.\n- `order`: A ... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9006,
"level": 1,
"question": "**Task**: Write a function `sort_by_custom_order(arr: List[int], order: List[int]) -> List[int]` that takes an array of integers and sorts it according to a specified custom order provided in a list.\n\n**Parameters**:\n- `arr`: A list of integers that... |
def list_to_dict(numbers):
index_dict = {}
for index, num in enumerate(numbers):
if num not in index_dict:
index_dict[num] = index
else:
if isinstance(index_dict[num], list):
index_dict[num].append(index)
else:
index_dict[num] =... | simplelr_Prefill | [
{
"content": "Question:\nWrite a function to convert a given list of numbers into a dictionary where the keys are the numbers and the values are their corresponding indices in the list. If a number appears more than once in the list, store all its indices in a list as the value for that key.\nAnswer:\nLet's thi... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9007,
"level": 1,
"question": "Write a function to convert a given list of numbers into a dictionary where the keys are the numbers and the values are their corresponding indices in the list. If a number appears more than once in the list, store all its indices in a list as the valu... |
def process_set_operations(commands: list) -> list:
current_set = set()
results = []
for cmd in commands:
parts = cmd.split()
operation = parts[0]
if operation == 'add':
x = int(parts[1])
current_set.add(x)
results.append(None)
elif operati... | simplelr_Docs | [
{
"content": "Question:\nYou are required to implement a function that performs several operations on sets based on input commands.\n\n#### Function Signature\n```python\ndef process_set_operations(commands: list) -> list:\n pass\n```\n\n#### Input\n- `commands`: A list of strings where each string is a comm... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9008,
"level": 1,
"question": "You are required to implement a function that performs several operations on sets based on input commands.\n\n#### Function Signature\n```python\ndef process_set_operations(commands: list) -> list:\n pass\n```\n\n#### Input\n- `commands`: A list of ... |
def cocktail_shaker_sort(arr: list[int]) -> list[int]:
left = 0
right = len(arr) - 1
while left < right:
swapped = False
# Forward pass from left to right-1
for i in range(left, right):
if arr[i] > arr[i + 1]:
arr[i], arr[i + 1] = arr[i + 1], arr[i]
... | simplelr_Data_Structure | [
{
"content": "Question:\nYou are working with an e-commerce company that needs to sort product ratings to display the most positively reviewed products at the top of their listings. You have been asked to write an efficient function to sort these ratings using the Cocktail Shaker Sort algorithm.\n\nWrite a func... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9009,
"level": 1,
"question": "You are working with an e-commerce company that needs to sort product ratings to display the most positively reviewed products at the top of their listings. You have been asked to write an efficient function to sort these ratings using the Cocktail Sha... |
from collections import deque
def bfs_traversal(graph, start_node):
"""
Performs a Breadth-First Search (BFS) traversal starting from the given start_node.
Args:
graph (dict): Adjacency list representation of the graph.
start_node: The node from which to start the traversal.
R... | simplelr_Prefill | [
{
"content": "Question:\nWrite a python function to print BFS (Breadth First Traversal) of a graph.\nAnswer:\nLet's think step by step.\n",
"role": "user"
}
] | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9010,
"level": 1,
"question": "Write a python function to print BFS (Breadth First Traversal) of a graph.",
"split": "train"
} |
def filter_strings_containing_substring(strings, substring):
return [s for s in strings if substring in s] | simplelr_Filter | [
{
"content": "Question:\nWrite a function in Python that takes a list of strings and returns a new list with only the strings that contain a specific substring.\nAnswer:\nLet's think step by step.\n",
"role": "user"
}
] | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9011,
"level": 1,
"question": "Write a function in Python that takes a list of strings and returns a new list with only the strings that contain a specific substring.",
"split": "train"
} |
def group_equal_elements(lst):
if not lst:
return []
result = []
current_group = [lst[0]]
for num in lst[1:]:
if num == current_group[-1]:
current_group.append(num)
else:
result.append(current_group)
current_group = [num]
result.append(curr... | simplelr_Code_Contests | [
{
"content": "Question:\nGiven a list of integers, write a function `group_equal_elements(lst)` that groups all equal elements into sublists. Each sublist should contain only identical elements and the sublists should appear in the order of their first appearance in the input list.\n\n### Input:\n- `lst`: A lis... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9012,
"level": 1,
"question": "Given a list of integers, write a function `group_equal_elements(lst)` that groups all equal elements into sublists. Each sublist should contain only identical elements and the sublists should appear in the order of their first appearance in the input ... |
def convert_values_to_opposite_case(input_dict):
result = {}
for key, value in input_dict.items():
if isinstance(value, str):
result[key] = value.swapcase()
return result | simplelr_Prefill | [
{
"content": "Question:\nCreate a function that takes a dictionary as input and returns a new dictionary that contains the same keys as the original dictionary, but with all values converted to their opposite cases. If a value is not a string, ignore that key-value pair.\nAnswer:\nLet's think step by step.\n",
... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9013,
"level": 1,
"question": "Create a function that takes a dictionary as input and returns a new dictionary that contains the same keys as the original dictionary, but with all values converted to their opposite cases. If a value is not a string, ignore that key-value pair.",
"... |
def find_three_sum(arr, x):
arr.sort()
n = len(arr)
for i in range(n - 2):
left = i + 1
right = n - 1
while left < right:
current_sum = arr[i] + arr[left] + arr[right]
if current_sum == x:
return True
elif current_sum < x:
... | simplelr_Leetcode | [
{
"content": "Question:\nYou are given a **0-indexed** array of integers `arr` and a **target** integer `x`. You need to determine if there are any three distinct indices `i`, `j`, and `k` in the array such that the sum of the elements at these indices is equal to `x`. Return `true` if such a combination exists... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9014,
"level": 1,
"question": "You are given a **0-indexed** array of integers `arr` and a **target** integer `x`. You need to determine if there are any three distinct indices `i`, `j`, and `k` in the array such that the sum of the elements at these indices is equal to `x`. Return ... |
def sort_descending(nums):
return sorted(nums, reverse=True) | simplelr_Prefill | [
{
"content": "Question:\nCreate a function that accepts a list of integers and returns the list sorted in descending order using Python's built-in sort functionalities.\nAnswer:\nLet's think step by step.\n",
"role": "user"
}
] | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9015,
"level": 1,
"question": "Create a function that accepts a list of integers and returns the list sorted in descending order using Python's built-in sort functionalities.",
"split": "train"
} |
import numpy as np
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_absolute_error, mean_squared_error
from sklearn.ensemble import GradientBoostingRegressor
# Set random seed for reproducibility
np.random.seed(42)
# Generate synthetic dataset with ... | simplelr_Docs | [
{
"content": "Question:\n#### Objective\nAssess your understanding of evaluating machine learning models using scikit-learn's scoring metrics and implementing custom scoring functions.\n\n#### Problem Statement\nAs a data scientist at an e-commerce company, you are tasked with building a predictive model to for... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9016,
"level": 1,
"question": "#### Objective\nAssess your understanding of evaluating machine learning models using scikit-learn's scoring metrics and implementing custom scoring functions.\n\n#### Problem Statement\nAs a data scientist at an e-commerce company, you are tasked with... |
import re
HEX_PATTERN = re.compile(r'^[0-9a-fA-F]+$')
def is_valid_hexadecimal(s: str) -> bool:
"""
Returns True if the string is a valid hexadecimal number, False otherwise.
:param s: String, the input string to be checked
:return: Boolean, True if the string is a valid hexadecimal number, False oth... | simplelr_Algorithm | [
{
"content": "Question:\n**Problem Description**:\nYou are asked to implement a function that determines if a given string is a valid representation of a hexadecimal number. A hexadecimal number can include the digits `0-9` and letters `a-f` or `A-F`, without any prefixes like `0x`.\n\n**Function Signature**:\n... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9017,
"level": 1,
"question": "**Problem Description**:\nYou are asked to implement a function that determines if a given string is a valid representation of a hexadecimal number. A hexadecimal number can include the digits `0-9` and letters `a-f` or `A-F`, without any prefixes like... |
from collections import defaultdict
def group_anagrams(strs):
"""
This function groups an array of strings into anagrams.
Parameters:
strs (list): The list of strings.
Returns:
list: A list of lists, where each sublist contains strings that are anagrams of each other.
"""
groups = def... | simplelr_Filter | [
{
"content": "Question:\n### Task 3: Text Preprocessing\n# Given a text, write a function to remove all punctuation and convert to lowercase. \n# The function should return a new string without the punctuation and in lowercase.\n\n```python\nimport string\n\ndef remove_punctuation(text):\n \"\"\"\n This f... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9018,
"level": 1,
"question": "### Task 3: Text Preprocessing\n# Given a text, write a function to remove all punctuation and convert to lowercase. \n# The function should return a new string without the punctuation and in lowercase.\n\n```python\nimport string\n\ndef remove_punctua... |
def filter_by_key_value(dict_list, key, value):
filtered = []
for person in dict_list:
if key in person and person[key] == value:
filtered.append(person)
return filtered | simplelr_Filter | [
{
"content": "Question:\nHow can I create a Python function that filters a list of dictionaries based on a specific key-value pair and returns the filtered list? For example, if I have a list of dictionaries representing people with their age, I want to filter out only those who are 18 years old.\nAnswer:\nLet'... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9019,
"level": 1,
"question": "How can I create a Python function that filters a list of dictionaries based on a specific key-value pair and returns the filtered list? For example, if I have a list of dictionaries representing people with their age, I want to filter out only those w... |
def max_sum_subarray_k(arr, k):
if not arr or k == 0:
return 0
n = len(arr)
if k > n:
return 0 # Assuming k is not larger than the array length as per problem constraints
current_sum = sum(arr[:k])
max_sum = current_sum
for i in range(k, n):
current_sum = curre... | simplelr_Leetcode | [
{
"content": "Question:\nYou are given an array of integers `arr` and a positive integer `k`. You need to select `k` elements from the array such that the sum of these `k` elements is as large as possible. However, there is an additional constraint: you can only select contiguous subarrays of size exactly `k`. ... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9020,
"level": 1,
"question": "You are given an array of integers `arr` and a positive integer `k`. You need to select `k` elements from the array such that the sum of these `k` elements is as large as possible. However, there is an additional constraint: you can only select contigu... |
def mod_exp(base: int, exponent: int, mod: int) -> int:
if exponent < 0:
raise ValueError("Exponent must be non-negative.")
if exponent == 0:
return 1 % mod
result = 1
current_base = base % mod
exponent_remaining = exponent
while exponent_remaining > 0:
if exponent_remain... | simplelr_Data_Structure | [
{
"content": "Question:\n## Problem Statement\n\nYou are a security consultant and need to implement a function that calculates the modular exponentiation, which is an essential part of many cryptographic algorithms.\n\n### Task\n\nWrite a Python function `mod_exp(base: int, exponent: int, mod: int) -> int` tha... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9021,
"level": 1,
"question": "## Problem Statement\n\nYou are a security consultant and need to implement a function that calculates the modular exponentiation, which is an essential part of many cryptographic algorithms.\n\n### Task\n\nWrite a Python function `mod_exp(base: int, e... |
def checkWinner(board):
# Check rows
for row in board:
if row[0] == row[1] == row[2] != 0:
return row[0]
# Check columns
for col in range(3):
if board[0][col] == board[1][col] == board[2][col] != 0:
return board[0][col]
# Check first diagonal (top-le... | simplelr_Taco | [
{
"content": "Question:\nA Tic-Tac-Toe board is represented as a 3x3 matrix, where each cell contains one of three values: 0, 1, or 2. The values represent the following:\n- 0 represents an empty cell.\n- 1 represents a move by player 1 ('X').\n- 2 represents a move by player 2 ('O').\n\nWrite a function that d... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9022,
"level": 1,
"question": "A Tic-Tac-Toe board is represented as a 3x3 matrix, where each cell contains one of three values: 0, 1, or 2. The values represent the following:\n- 0 represents an empty cell.\n- 1 represents a move by player 1 ('X').\n- 2 represents a move by player ... |
def find_max_min(lst):
if not lst:
return None
return (max(lst), min(lst)) | simplelr_Filter | [
{
"content": "Question:\nWrite a Python function to find the maximum and minimum values in a given list of integers. The function should return a tuple containing the maximum and minimum values respectively. Ensure your function handles an empty list by returning `None`.\nAnswer:\nLet's think step by step.\n",
... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9023,
"level": 1,
"question": "Write a Python function to find the maximum and minimum values in a given list of integers. The function should return a tuple containing the maximum and minimum values respectively. Ensure your function handles an empty list by returning `None`.",
"... |
def find_unique_integer(nums):
count = {}
for num in nums:
if num in count:
count[num] += 1
else:
count[num] = 1
for key, value in count.items():
if value == 1:
return key | simplelr_Apps | [
{
"content": "Question:\nYou are given a list of integers, where each integer appears exactly three times, except for one integer that appears exactly once. Your task is to find the integer that appears only once in the list.\n\nWrite a function `find_unique_integer(nums)` that takes in a list of integers `nums... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9024,
"level": 1,
"question": "You are given a list of integers, where each integer appears exactly three times, except for one integer that appears exactly once. Your task is to find the integer that appears only once in the list.\n\nWrite a function `find_unique_integer(nums)` tha... |
def find_pair(arr, target):
left = 0
right = len(arr) - 1
while left < right:
current_sum = arr[left] + arr[right]
if current_sum == target:
return (arr[left], arr[right])
elif current_sum < target:
left += 1
else:
right -= 1
return Non... | simplelr_Filter | [
{
"content": "Question:\nGiven a sorted array of integers, find the first pair of elements that add up to a given target sum.\n\nExample:\nInput: [1, 2, 3, 4, 5], target = 7\nOutput: (2, 5)\n\nNote: The array is sorted in ascending order.\n\nHere is the code in python:\n```python\ndef find_pair(arr, target):\n ... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9025,
"level": 1,
"question": "Given a sorted array of integers, find the first pair of elements that add up to a given target sum.\n\nExample:\nInput: [1, 2, 3, 4, 5], target = 7\nOutput: (2, 5)\n\nNote: The array is sorted in ascending order.\n\nHere is the code in python:\n```pyt... |
def sum_of_even_numbers(list_of_numbers):
total_sum = 0
for number in list_of_numbers:
if number % 2 == 0:
total_sum += number
return total_sum | simplelr_Filter | [
{
"content": "Question:\nHey, can you provide a Python code snippet to calculate the sum of all even numbers in a given list of integers?\nAnswer:\nLet's think step by step.\n",
"role": "user"
}
] | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9026,
"level": 1,
"question": "Hey, can you provide a Python code snippet to calculate the sum of all even numbers in a given list of integers?",
"split": "train"
} |
def two_sum(nums, target):
num_to_index = {}
for index, num in enumerate(nums):
complement = target - num
if complement in num_to_index:
return [num_to_index[complement], index]
num_to_index[num] = index | simplelr_Apps | [
{
"content": "Question:\nCreate a function that takes an array of integers and a target integer as parameters. The function should return the indices of the two numbers in the array that add up to the target integer. You can assume that each input has exactly one solution, and you may not use the same element t... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9027,
"level": 1,
"question": "Create a function that takes an array of integers and a target integer as parameters. The function should return the indices of the two numbers in the array that add up to the target integer. You can assume that each input has exactly one solution, and... |
def isDivisible(k, N):
current = 0
for char in N:
digit = int(char)
current = (current * 10 + digit) % k
return current == 0
| simplelr_Taco | [
{
"content": "Question:\nGiven an integer k and a number N in the form of string, your task is to determine whether the number N is divisible by k.\n\nNote: The given number is very large and so the input is taken as a string.\n\nExample 1:\nInput:\nk = 11\nN = \"123456789\"\nOutput:\nFalse\nExplanation:\n12345... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9028,
"level": 1,
"question": "Given an integer k and a number N in the form of string, your task is to determine whether the number N is divisible by k.\n\nNote: The given number is very large and so the input is taken as a string.\n\nExample 1:\nInput:\nk = 11\nN = \"123456789\"\n... |
def search_rotated_array(arr: list[int], target: int) -> int:
low = 0
high = len(arr) - 1
while low <= high:
mid = (low + high) // 2
if arr[mid] == target:
return mid
# Determine if the left half is sorted
is_left_sorted = arr[low] <= arr[mid]
... | simplelr_Algorithm | [
{
"content": "Question:\n### Question: Rotated Array Search\n\n#### Context\nYou are working on a problem involving rotated sorted arrays. In a rotated array, the sort order is disrupted at a single point and resumed. This makes a normal binary search infeasible without modifications.\n\n#### Problem\nGiven a r... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9029,
"level": 1,
"question": "### Question: Rotated Array Search\n\n#### Context\nYou are working on a problem involving rotated sorted arrays. In a rotated array, the sort order is disrupted at a single point and resumed. This makes a normal binary search infeasible without modifi... |
def maxSubarraySum(arr):
if not arr:
return 0
current_max = max_so_far = arr[0]
for num in arr[1:]:
current_max = max(num, current_max + num)
if current_max > max_so_far:
max_so_far = current_max
return max_so_far | simplelr_Package | [
{
"content": "Question:\n**Title**: Largest Contiguous Subarray Sum\n\nIn this problem, you are required to write a function named `maxSubarraySum` that finds the sum of the largest contiguous subarray within a given list of integers.\n\n**Context**:\nGiven a list of integers, a contiguous subarray is a subset ... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9030,
"level": 1,
"question": "**Title**: Largest Contiguous Subarray Sum\n\nIn this problem, you are required to write a function named `maxSubarraySum` that finds the sum of the largest contiguous subarray within a given list of integers.\n\n**Context**:\nGiven a list of integers,... |
def sum_of_evens(n):
if n < 2:
return 0
m = n if n % 2 == 0 else n - 1
count = m // 2
return count * (count + 1) | simplelr_Prefill | [
{
"content": "Question:\nCreate a function that takes a number and returns the sum of all even numbers between 1 and the given number.\nAnswer:\nLet's think step by step.\n",
"role": "user"
}
] | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9031,
"level": 1,
"question": "Create a function that takes a number and returns the sum of all even numbers between 1 and the given number.",
"split": "train"
} |
def simplify_path(path):
segments = path.split('/')
filtered = [s for s in segments if s != '']
stack = []
for seg in filtered:
if seg == '.':
continue
elif seg == '..':
if stack:
stack.pop()
else:
stack.append(seg)
return '... | simplelr_Data_Structure | [
{
"content": "Question:\n### Context: Simplifying File Paths\n\nYou are developing a command-line interface (CLI) tool for file management in a Unix-based environment. One of the features required is to simplify file paths provided by users. These paths may include unnecessary navigation such as `.` (current di... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9032,
"level": 1,
"question": "### Context: Simplifying File Paths\n\nYou are developing a command-line interface (CLI) tool for file management in a Unix-based environment. One of the features required is to simplify file paths provided by users. These paths may include unnecessary... |
def max_of_three(a, b, c):
return max(a, b, c) | simplelr_Filter | [
{
"content": "Question:\nWrite a Python function that receives three integers and returns the maximum among them. If two or more numbers are equal and are the maximum, return that number.\nAnswer:\nLet's think step by step.\n",
"role": "user"
}
] | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9033,
"level": 1,
"question": "Write a Python function that receives three integers and returns the maximum among them. If two or more numbers are equal and are the maximum, return that number.",
"split": "train"
} |
import re
def sum_numbers_in_string(s):
"""
This function takes a string as input, extracts all the numbers from the string,
and returns their sum as a floating point number.
Args:
s (str): The input string.
Returns:
float: The sum of the numbers in the string.
"""
total ... | simplelr_Filter | [
{
"content": "Question:\n### Scenario\nYou've been tasked with writing a function that can find the sum of all the numbers in a given string. It should be able to handle strings that contain multiple numbers, decimal numbers, and negative numbers. For example, given the string \"10 20 30\", it should return 60.... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9034,
"level": 1,
"question": "### Scenario\nYou've been tasked with writing a function that can find the sum of all the numbers in a given string. It should be able to handle strings that contain multiple numbers, decimal numbers, and negative numbers. For example, given the string... |
def words_with_min_length(s, n):
words = s.split()
result = []
for word in words:
if len(word) >= n:
result.append(word)
return result | simplelr_Prefill | [
{
"content": "Question:\nWrite a function to return a list of words in a string that have at least a specified number of characters.\nAnswer:\nLet's think step by step.\n",
"role": "user"
}
] | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9035,
"level": 1,
"question": "Write a function to return a list of words in a string that have at least a specified number of characters.",
"split": "train"
} |
def longestSubarray(arr, n, k):
current_sum = 0
prefix_mod = {0: -1}
max_length = 0
best_start = 0
for i in range(n):
current_sum += arr[i]
mod = current_sum % k
if mod == 0:
length = i + 1
if length > max_length:
max_length = length
... | simplelr_Taco | [
{
"content": "Question:\nMaxwell loves numbers and wants to perform unique operations on them. He has an array of N integers. He wants to know the longest subarray such that the sum of the subarray is divisible by a given integer K. If there are multiple subarrays with the same length, return the one with the s... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9036,
"level": 1,
"question": "Maxwell loves numbers and wants to perform unique operations on them. He has an array of N integers. He wants to know the longest subarray such that the sum of the subarray is divisible by a given integer K. If there are multiple subarrays with the sam... |
def is_match(s: str, p: str) -> bool:
n = len(s)
m = len(p)
# Create a DP table with (n+1) rows and (m+1) columns
dp = [[False] * (m + 1) for _ in range(n + 1)]
dp[0][0] = True # empty string matches empty pattern
for i in range(n + 1):
for j in range(m + 1):
if i == 0 ... | simplelr_Data_Structure | [
{
"content": "Question:\n### Regular Expression Matching (Advanced)\n\n#### Context\nIn software applications involving text validation, it is common to use regular expressions to define patterns that text data must conform to. Your task is to implement a robust function to determine whether a given text string... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9037,
"level": 1,
"question": "### Regular Expression Matching (Advanced)\n\n#### Context\nIn software applications involving text validation, it is common to use regular expressions to define patterns that text data must conform to. Your task is to implement a robust function to de... |
def format_time(hours: int, minutes: int, seconds: int) -> str:
return f"{hours:02d}:{minutes:02d}:{seconds:02d}"
| simplelr_Taco | [
{
"content": "Question:\n**Problem**:\n\nYou are tasked with providing a visualization of a digital clock. The digital clock displays the time in a 24-hour format (hh:mm:ss). Your goal is to implement a function that accepts three integers representing hours, minutes, and seconds. The function should return a s... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9038,
"level": 1,
"question": "**Problem**:\n\nYou are tasked with providing a visualization of a digital clock. The digital clock displays the time in a 24-hour format (hh:mm:ss). Your goal is to implement a function that accepts three integers representing hours, minutes, and seco... |
def min_operations_to_alternate(s):
count1 = 0 # Starts with 'X'
count2 = 0 # Starts with 'Y'
for i, c in enumerate(s):
expected1 = 'X' if i % 2 == 0 else 'Y'
if c != expected1:
count1 += 1
expected2 = 'Y' if i % 2 == 0 else 'X'
if c != expected2:
co... | simplelr_Leetcode | [
{
"content": "Question:\nImplement a function that receives a string `s` containing only characters `X` and `Y`. The function should return the minimum number of operations required to make the string alternating, where no two consecutive characters are the same. Each operation consists of changing one `X` to `... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9039,
"level": 1,
"question": "Implement a function that receives a string `s` containing only characters `X` and `Y`. The function should return the minimum number of operations required to make the string alternating, where no two consecutive characters are the same. Each operatio... |
def reverse_string_preserve_case(s: str) -> str:
s_reversed = s[::-1]
result = []
for i in range(len(s)):
char = s_reversed[i]
if s[i].isupper():
result.append(char.upper())
else:
result.append(char.lower())
return ''.join(result) | simplelr_Package | [
{
"content": "Question:\nWrite a Python function named `reverse_string_preserve_case` that takes a single string as an argument and returns the string reversed while preserving the case of each character as it appeared in the original string. Specifically, if a character was uppercase in the original string, th... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9040,
"level": 1,
"question": "Write a Python function named `reverse_string_preserve_case` that takes a single string as an argument and returns the string reversed while preserving the case of each character as it appeared in the original string. Specifically, if a character was u... |
def length_of_longest_substring_k_distinct(s: str, k: int) -> int:
if k == 0:
return 0
char_count = {}
left = 0
max_length = 0
distinct = 0
for right in range(len(s)):
current_char = s[right]
if current_char not in char_count or char_count[current_char] == 0:
... | simplelr_Leetcode | [
{
"content": "Question:\nGiven a string `s` and an integer `k`, you need to return the length of the longest substring that contains at most `k` distinct characters. If `k` is zero, the longest substring will have a length of zero. For example, for the input `s = \"eceba\"` and `k = 2`, the output would be `3` ... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9041,
"level": 1,
"question": "Given a string `s` and an integer `k`, you need to return the length of the longest substring that contains at most `k` distinct characters. If `k` is zero, the longest substring will have a length of zero. For example, for the input `s = \"eceba\"` an... |
def find_strings_with_a(strings):
return [s for s in strings if 'a' in s.lower()] | simplelr_Filter | [
{
"content": "Question:\nI will provide you with a list of strings. I want to create a function that can take this list of strings as input, and return a new list with all the strings that contain the character 'a' or 'A' (case insensitive). \n\nHere's my code so far:\n\n```python\ndef find_strings_with_a(strin... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9042,
"level": 1,
"question": "I will provide you with a list of strings. I want to create a function that can take this list of strings as input, and return a new list with all the strings that contain the character 'a' or 'A' (case insensitive). \n\nHere's my code so far:\n\n```py... |
def filter_apple_strings(strings):
return [s for s in strings if 'apple' in s.lower()] | simplelr_Filter | [
{
"content": "Question:\nWrite a Python function that takes a list of strings and returns a list of strings that contain the substring \"apple\". The function should be case-insensitive.\nAnswer:\nLet's think step by step.\n",
"role": "user"
}
] | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9043,
"level": 1,
"question": "Write a Python function that takes a list of strings and returns a list of strings that contain the substring \"apple\". The function should be case-insensitive.",
"split": "train"
} |
def reverse_string(s):
reversed_str = ""
length = 0
# Calculate the length without using len()
while True:
try:
s[length]
length += 1
except IndexError:
break
i = length - 1
while i >= 0:
reversed_str += s[i]
i -= 1
return r... | simplelr_Prefill | [
{
"content": "Question:\nWrite a python function to reverse a string without using any built-in functions or methods. Here is the string: \"hello world\".\nAnswer:\nLet's think step by step.\n",
"role": "user"
}
] | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9044,
"level": 1,
"question": "Write a python function to reverse a string without using any built-in functions or methods. Here is the string: \"hello world\".",
"split": "train"
} |
from typing import List
def single_number(nums: List[int]) -> int:
res = 0
for num in nums:
res ^= num
return res | simplelr_Algorithm | [
{
"content": "Question:\n### Problem Statement\nYou are given an array of integers where each element appears twice except for one element which appears only once. Your task is to implement a function that finds the element that appears only once. The algorithm should run in linear time and use constant space.\... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9045,
"level": 1,
"question": "### Problem Statement\nYou are given an array of integers where each element appears twice except for one element which appears only once. Your task is to implement a function that finds the element that appears only once. The algorithm should run in l... |
def are_disjoint_sets(set1: list[int], set2: list[int]) -> bool:
return set(set1).isdisjoint(set(set2)) | simplelr_Algorithm | [
{
"content": "Question:\n### Coding Question\n\n#### Context\nIn the realm of data handling, it's common to manage sets of integers and perform various operations on them. One such important operation is to verify if two sets are disjoint. Two sets are disjoint if they have no elements in common.\n\n#### Proble... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9046,
"level": 1,
"question": "### Coding Question\n\n#### Context\nIn the realm of data handling, it's common to manage sets of integers and perform various operations on them. One such important operation is to verify if two sets are disjoint. Two sets are disjoint if they have no... |
def sum_and_product(a, b):
try:
sum_result = a + b
product_result = a * b
return (sum_result, product_result)
except Exception:
return None | simplelr_Prefill | [
{
"content": "Question:\nWrite a function to calculate the sum and product of two numbers. The function should return both values as a tuple. If the calculation causes an error, such as division by zero, the function should return None.\nAnswer:\nLet's think step by step.\n",
"role": "user"
}
] | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9047,
"level": 1,
"question": "Write a function to calculate the sum and product of two numbers. The function should return both values as a tuple. If the calculation causes an error, such as division by zero, the function should return None.",
"split": "train"
} |
def second_smallest_unique(nums):
unique = list(set(nums))
unique_sorted = sorted(unique)
if len(unique_sorted) < 2:
return None
else:
return unique_sorted[1] | simplelr_Filter | [
{
"content": "Question:\nWrite a Python script that takes a list of integers and returns the second smallest unique number in the list. If there is no such number, the script should return `None`.\nAnswer:\nLet's think step by step.\n",
"role": "user"
}
] | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9048,
"level": 1,
"question": "Write a Python script that takes a list of integers and returns the second smallest unique number in the list. If there is no such number, the script should return `None`.",
"split": "train"
} |
from typing import List
def merge(nums1: List[int], m: int, nums2: List[int], n: int) -> None:
i = m - 1
j = n - 1
k = m + n - 1
while i >= 0 and j >= 0:
if nums1[i] > nums2[j]:
nums1[k] = nums1[i]
i -= 1
else:
nums1[k] = nums2[j]
j -= 1
... | simplelr_Codeforces | [
{
"content": "Question:\nYou are given two integer arrays nums1 and nums2, sorted in non-decreasing order, and two integers m and n, representing the number of elements in nums1 and nums2 respectively. Merge nums1 and nums2 into a single array sorted in non-decreasing order.\n\nThe final sorted array should not... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9049,
"level": 1,
"question": "You are given two integer arrays nums1 and nums2, sorted in non-decreasing order, and two integers m and n, representing the number of elements in nums1 and nums2 respectively. Merge nums1 and nums2 into a single array sorted in non-decreasing order.\n... |
import re
def is_valid_email(email):
pattern = r"^[a-zA-Z0-9]([._-]?[a-zA-Z0-9])*@([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,6}$"
return bool(re.match(pattern, email)) | simplelr_Prefill | [
{
"content": "Question:\nCreate a function that checks if a string is a valid email. A valid email should have the format of \"username@domain.extension\".\nAnswer:\nLet's think step by step.\n",
"role": "user"
}
] | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9050,
"level": 1,
"question": "Create a function that checks if a string is a valid email. A valid email should have the format of \"username@domain.extension\".",
"split": "train"
} |
def is_repeated_substring(s: str) -> bool:
n = len(s)
if n == 1:
return False
for i in range(1, int(n**0.5) + 1):
if n % i == 0:
# Check for k = i
k = i
if k <= n // 2 and (n // k) >= 2:
m = n // k
substring = s[:k]
... | simplelr_Data_Structure | [
{
"content": "Question:\n#### Problem Statement\nYou are tasked with implementing an algorithm to check if a given non-empty string `s` can be constructed by repeating a substring of it.\n\nYour goal is to write a function `is_repeated_substring` that returns `True` if the string `s` can be constructed by repea... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9051,
"level": 1,
"question": "#### Problem Statement\nYou are tasked with implementing an algorithm to check if a given non-empty string `s` can be constructed by repeating a substring of it.\n\nYour goal is to write a function `is_repeated_substring` that returns `True` if the str... |
def fibonacci(n):
if n <= 0:
return 0
elif n == 1:
return 1
a, b = 0, 1
for _ in range(2, n + 1):
a, b = b, a + b
return b
# Example usage
n = 10 # You can change this value
print(f"The {n}th Fibonacci number is {fibonacci(n)}") | simplelr_Filter | [
{
"content": "Question:\nI want to create a Python program that finds the nth Fibonacci number. Can you provide a simple and efficient way to do this?\nAnswer:\nLet's think step by step.\n",
"role": "user"
}
] | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9052,
"level": 1,
"question": "I want to create a Python program that finds the nth Fibonacci number. Can you provide a simple and efficient way to do this?",
"split": "train"
} |
def can_reach_destination(x, y, k):
"""Determines if a robot can reach a specific point on a 2D grid within a limited number of steps.
Args:
x: The x-coordinate of the target point.
y: The y-coordinate of the target point.
k: The maximum number of steps the robot can take.
Returns:... | simplelr_Filter | [
{
"content": "Question:\nI have been trying to solve this problem for a while now:\n\nProblem:\n\nYou have a robot on a 2D grid. The robot can only move in four directions: up, down, left, and right. It starts at position (0, 0), and its goal is to reach the position (x, y). \n\nThe robot can only move a certai... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9053,
"level": 1,
"question": "I have been trying to solve this problem for a while now:\n\nProblem:\n\nYou have a robot on a 2D grid. The robot can only move in four directions: up, down, left, and right. It starts at position (0, 0), and its goal is to reach the position (x, y). \... |
from bisect import bisect_left
def longest_increasing_subsequence(A):
if not A:
return 0
lis = []
for num in A:
pos = bisect_left(lis, num)
if pos == len(lis):
lis.append(num)
else:
lis[pos] = num
return len(lis) | simplelr_Algorithm | [
{
"content": "Question:\n### Problem: Longest Increasing Subsequence in O(n log n) Time\n\nImplement a function to compute the length of the longest increasing subsequence (LIS) in an array of integers. Your function should have a time complexity of \\( O(n \\log n) \\).\n\n**Input Format**\n- The first line co... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9054,
"level": 1,
"question": "### Problem: Longest Increasing Subsequence in O(n log n) Time\n\nImplement a function to compute the length of the longest increasing subsequence (LIS) in an array of integers. Your function should have a time complexity of \\( O(n \\log n) \\).\n\n**... |
def second_smallest(lst):
# Filter list to include only int or float, excluding NaN and non-numeric values
numeric = [x for x in lst if (type(x) == int) or (type(x) == float and x == x)]
# Use a set to get unique elements
unique = list(set(numeric))
# Check if there are at least two unique numeric e... | simplelr_Filter | [
{
"content": "Question:\nWrite a Python function that takes a list of numbers and returns the second smallest element in the list. If the list has fewer than 2 unique elements, the function should return None. Ensure to handle possible edge cases, such as the list being empty or containing non-numeric values.\n... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9055,
"level": 1,
"question": "Write a Python function that takes a list of numbers and returns the second smallest element in the list. If the list has fewer than 2 unique elements, the function should return None. Ensure to handle possible edge cases, such as the list being empty ... |
def optimized_power(base: int, exponent: int, modulo: int = None) -> int:
if exponent == 0:
return 1
if base == 0:
return 0
if modulo is not None:
mod_val = modulo
base_mod = base % mod_val
if base_mod == 0:
return 0
result = 1
current... | simplelr_Data_Structure | [
{
"content": "Question:\n### Binary Exponentiation Challenge\n\n#### Scenario\nYou are a software developer tasked with developing a feature for a cryptographic application that involves frequent calculations of large exponentiations with moduli. To ensure efficiency, you plan to use binary exponentiation.\n\n#... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9056,
"level": 1,
"question": "### Binary Exponentiation Challenge\n\n#### Scenario\nYou are a software developer tasked with developing a feature for a cryptographic application that involves frequent calculations of large exponentiations with moduli. To ensure efficiency, you plan... |
def bubble_sort(lst):
lst_copy = lst.copy()
n = len(lst_copy)
for i in range(n - 1):
swapped = False
for j in range(n - i - 1):
if lst_copy[j] > lst_copy[j + 1]:
lst_copy[j], lst_copy[j + 1] = lst_copy[j + 1], lst_copy[j]
swapped = True
if ... | simplelr_Filter | [
{
"content": "Question:\nCan you provide a Python implementation of the bubble sort algorithm?\nAnswer:\nLet's think step by step.\n",
"role": "user"
}
] | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9057,
"level": 1,
"question": "Can you provide a Python implementation of the bubble sort algorithm?",
"split": "train"
} |
def has_pair_with_sum(nums, target):
seen = {}
for num in nums:
complement = target - num
if complement in seen:
return True
seen[num] = True
return False | simplelr_Filter | [
{
"content": "Question:\nYou are given an array of integers and a target sum. You need to determine if there are two numbers in the array that add up to the target sum.\n\nExample:\n\n```\nInput array: [2, 7, 11, 15]\nTarget sum: 9\n\nOutput: True (because 2 + 7 = 9)\n\nInput array: [3, 2, 4]\nTarget sum: 6\n\n... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9058,
"level": 1,
"question": "You are given an array of integers and a target sum. You need to determine if there are two numbers in the array that add up to the target sum.\n\nExample:\n\n```\nInput array: [2, 7, 11, 15]\nTarget sum: 9\n\nOutput: True (because 2 + 7 = 9)\n\nInput ... |
from typing import List, Dict
def search_books(inventory: List[Dict[str, str]], keyword: str) -> List[Dict[str, str]]:
keyword_lower = keyword.strip().lower()
result = []
for book in inventory:
title_lower = book['title'].lower()
author_lower = book['author'].lower()
if keyword_lowe... | simplelr_Algorithm | [
{
"content": "Question:\n### Context:\nYou are designing a digital library system, and part of the system requires a way to manage and query books efficiently. One of the features needed is the ability to search for books that match certain criteria from the inventory.\n\n### Problem Statement:\nImplement a fun... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9059,
"level": 1,
"question": "### Context:\nYou are designing a digital library system, and part of the system requires a way to manage and query books efficiently. One of the features needed is the ability to search for books that match certain criteria from the inventory.\n\n### ... |
def max_len_even_odd(arr):
prefix_sums = {0: -1}
current_sum = 0
max_len = 0
for index, num in enumerate(arr):
if num % 2 == 0:
current_sum += 1
else:
current_sum -= 1
if current_sum in prefix_sums:
length = index - prefix_sums[current_sum]
... | simplelr_Leetcode | [
{
"content": "Question:\nGiven an array of integers `arr`, find the maximum length of a contiguous subarray that has an equal number of even and odd integers.\nAnswer:\nLet's think step by step.\n",
"role": "user"
}
] | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9060,
"level": 1,
"question": "Given an array of integers `arr`, find the maximum length of a contiguous subarray that has an equal number of even and odd integers.",
"split": "train"
} |
def morse_code_converter(text):
MORSE_CODE_DICT = {
'A': '.-', 'B': '-...', 'C': '-.-.', 'D': '-..', 'E': '.', 'F': '..-.',
'G': '--.', 'H': '....', 'I': '..', 'J': '.---', 'K': '-.-', 'L': '.-..',
'M': '--', 'N': '-.', 'O': '---', 'P': '.--.', 'Q': '--.-', 'R': '.-.',
'S': '...', 'T... | simplelr_Apps | [
{
"content": "Question:\nA **Morse Code Converter** translates textual information into Morse code, a system of encoding letters and numbers through sequences of dots and dashes. Here's the Morse code representation for some common letters and numbers:\n```\nA -> .-\nB -> -...\nC -> -.-.\n...\n1 -> .----\n2 -> ... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9061,
"level": 1,
"question": "A **Morse Code Converter** translates textual information into Morse code, a system of encoding letters and numbers through sequences of dots and dashes. Here's the Morse code representation for some common letters and numbers:\n```\nA -> .-\nB -> -...... |
def remove_duplicates(s):
seen = set()
result = []
for char in s:
if char not in seen:
seen.add(char)
result.append(char)
return ''.join(result) | simplelr_Filter | [
{
"content": "Question:\nGiven a string, implement an algorithm to remove duplicate characters from the string while maintaining the order of the remaining characters. The string may contain any printable ASCII characters.\nAnswer:\nLet's think step by step.\n",
"role": "user"
}
] | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9062,
"level": 1,
"question": "Given a string, implement an algorithm to remove duplicate characters from the string while maintaining the order of the remaining characters. The string may contain any printable ASCII characters.",
"split": "train"
} |
def find_unique(nums):
unique = 0
for num in nums:
unique ^= num
return unique | simplelr_Package | [
{
"content": "Question:\nYou are given an array of integers `nums`, where each integer appears twice except for one integer, which appears only once. Your task is to write a function `find_unique(nums)` that returns the single integer that appears only once.\n\nTo solve this problem, use the bitwise XOR operato... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9063,
"level": 1,
"question": "You are given an array of integers `nums`, where each integer appears twice except for one integer, which appears only once. Your task is to write a function `find_unique(nums)` that returns the single integer that appears only once.\n\nTo solve this p... |
from typing import List, Tuple
def find_longest_plateau(nums: List[int]) -> Tuple[int, int]:
if not nums:
return (0, 0)
max_start = 0
max_end = 0
max_length = 1
current_start = 0
for i in range(1, len(nums)):
if nums[i] != nums[i-1]:
current_length = i - cu... | simplelr_Algorithm | [
{
"content": "Question:\n### Task Description\nDesign and implement a function that detects plateaus in a numerical list and returns the start and end indices of the longest plateau. A plateau is defined as a contiguous subarray where all elements are the same.\n\n### Problem Statement\nGiven a list of integers... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9064,
"level": 1,
"question": "### Task Description\nDesign and implement a function that detects plateaus in a numerical list and returns the start and end indices of the longest plateau. A plateau is defined as a contiguous subarray where all elements are the same.\n\n### Problem ... |
def find_min_traffic_path(matrix):
if not matrix:
return 0
n = len(matrix)
if n == 1:
return matrix[0][0]
dp = [[0 for _ in range(n)] for _ in range(n)]
dp[0][0] = matrix[0][0]
for i in range(n):
for j in range(n):
if i == 0 and j == 0:
continu... | simplelr_Taco | [
{
"content": "Question:\nDavid lives in a world where roads are laid out in a perfect grid, and he wants to find the shortest route from his home to his favorite cafe. However, he wants to avoid busy streets at all costs. The grid is represented as an `n x n` matrix, where each cell contains a value representin... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9065,
"level": 1,
"question": "David lives in a world where roads are laid out in a perfect grid, and he wants to find the shortest route from his home to his favorite cafe. However, he wants to avoid busy streets at all costs. The grid is represented as an `n x n` matrix, where eac... |
def multiply(a, b):
"""
Returns the product of two numbers.
Args:
a (int or float): The first number.
b (int or float): The second number.
Returns:
int or float: The product of a and b.
"""
return a * b | simplelr_Prefill | [
{
"content": "Question:\nWrite a python function to multiply two numbers given as inputs.\nAnswer:\nLet's think step by step.\n",
"role": "user"
}
] | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9066,
"level": 1,
"question": "Write a python function to multiply two numbers given as inputs.",
"split": "train"
} |
def lowest_lexicographical_representation(digits):
"""Finds the lowest lexicographical representation of the unique digits in a string.
Args:
digits: A string consisting of digits only.
Returns:
A string containing the unique digits of the input string arranged in
lexicographical o... | simplelr_Filter | [
{
"content": "Question:\nThe following is my problem statement:\n\n\"Given a string of digits as input, determine the lowest possible lexicographical representation of its unique digits in ascending order.\"\n\nProblem: Find the lowest lexicographical representation of the unique digits in the input string.\n\n... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9067,
"level": 1,
"question": "The following is my problem statement:\n\n\"Given a string of digits as input, determine the lowest possible lexicographical representation of its unique digits in ascending order.\"\n\nProblem: Find the lowest lexicographical representation of the uni... |
def max_subarray(array):
current_max = array[0]
global_max = array[0]
for i in range(1, len(array)):
current_max = max(array[i], current_max + array[i])
if current_max > global_max:
global_max = current_max
return global_max | simplelr_Data_Structure | [
{
"content": "Question:\nMaximum Sum Subarray\n\n#### Objective\nImplement a function that finds the maximum sum of a contiguous subarray in a given integer array.\n\n#### Description\nGiven an integer array `array`, implement the function `max_subarray(array)` that computes the maximum sum of a contiguous suba... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9068,
"level": 1,
"question": "Maximum Sum Subarray\n\n#### Objective\nImplement a function that finds the maximum sum of a contiguous subarray in a given integer array.\n\n#### Description\nGiven an integer array `array`, implement the function `max_subarray(array)` that computes t... |
import math
def sieve_of_eratosthenes(n):
if n < 2:
return []
sieve = [True] * (n + 1)
sieve[0], sieve[1] = False, False
for p in range(2, int(math.sqrt(n)) + 1):
if sieve[p]:
for multiple in range(p * p, n + 1, p):
sieve[multiple] = False
primes = [i for... | simplelr_Prefill | [
{
"content": "Question:\nCreate a function that finds all the prime numbers between 1 and a given integer n. The function should use the Sieve of Eratosthenes algorithm to efficiently find all the prime numbers within the range. The function should return a list of these prime numbers.\nAnswer:\nLet's think ste... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9069,
"level": 1,
"question": "Create a function that finds all the prime numbers between 1 and a given integer n. The function should use the Sieve of Eratosthenes algorithm to efficiently find all the prime numbers within the range. The function should return a list of these prime... |
def maximumSum(arr):
return sum(arr)
| simplelr_Taco | [
{
"content": "Question:\nYou are given an integer array `arr`. You can choose any two adjacent elements in the array and swap them. Your goal is to obtain the maximum possible sum of the array elements after at most one swap.\n\nExample 1:\nInput: arr = [1, 3, 5, 4, 2]\nOutput: 15\nExplanation: Swapping element... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9070,
"level": 1,
"question": "You are given an integer array `arr`. You can choose any two adjacent elements in the array and swap them. Your goal is to obtain the maximum possible sum of the array elements after at most one swap.\n\nExample 1:\nInput: arr = [1, 3, 5, 4, 2]\nOutput... |
def are_cyclic_permutations(str1: str, str2: str) -> bool:
if len(str1) != len(str2):
return False
if not str1:
return False
return str2 in (str1 + str1) | simplelr_Algorithm | [
{
"content": "Question:\n### Problem Description\nYou are tasked with implementing a function to determine if a given string is a cyclic permutation of another string. Two strings are cyclic permutations of each other if one can be obtained by rotating the other. For example, \"abcd\" and \"dabc\" are cyclic pe... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9071,
"level": 1,
"question": "### Problem Description\nYou are tasked with implementing a function to determine if a given string is a cyclic permutation of another string. Two strings are cyclic permutations of each other if one can be obtained by rotating the other. For example, ... |
def sum_of_digits(n):
total = 0
while n > 0:
total += n % 10
n = n // 10
return total
| simplelr_Taco | [
{
"content": "Question:\n## Sum of Digits\n\nWrite a function that takes a non-negative integer as input and returns the sum of its digits. You are not allowed to convert the integer to a string or any other non-integer type. You should implement this function using mathematical operations only.\n\nYour functio... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9072,
"level": 1,
"question": "## Sum of Digits\n\nWrite a function that takes a non-negative integer as input and returns the sum of its digits. You are not allowed to convert the integer to a string or any other non-integer type. You should implement this function using mathematic... |
def is_vowel_sequence_consonant_free(answer):
vowels = {'a', 'e', 'i', 'o', 'u'}
for c in answer:
if c.lower() not in vowels:
return 'Invalid'
return 'Valid' | simplelr_Package | [
{
"content": "Question:\nYou are tasked with creating a function `is_vowel_sequence_consonant_free(answer)` to validate a given string that should consist only of vowels to ensure it is free from consonants. Your function will parse the input string and check whether all characters exclusively belong to the set... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9073,
"level": 1,
"question": "You are tasked with creating a function `is_vowel_sequence_consonant_free(answer)` to validate a given string that should consist only of vowels to ensure it is free from consonants. Your function will parse the input string and check whether all chara... |
def max_score(grid):
if not grid or not grid[0]:
return 0
rows = len(grid)
cols = len(grid[0])
prev_row = [0] * cols
prev_row[0] = grid[0][0]
for j in range(1, cols):
prev_row[j] = prev_row[j-1] + grid[0][j]
for i in range(1, rows):
current_row = [... | simplelr_Taco | [
{
"content": "Question:\nImplement a function to simulate a simplified version of a text-based game. The game involves a grid of cells, each having a certain value. The player starts at the top-left corner of the grid and aims to reach the bottom-right corner. The player can only move right or down at each step... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9074,
"level": 1,
"question": "Implement a function to simulate a simplified version of a text-based game. The game involves a grid of cells, each having a certain value. The player starts at the top-left corner of the grid and aims to reach the bottom-right corner. The player can o... |
def smallest_lexicographical_string(s):
res = []
for c in s:
if c == '*':
res.append('a')
else:
res.append(c)
return ''.join(res) | simplelr_Leetcode | [
{
"content": "Question:\nYou are given a string `s` consisting of lowercase English letters and the `*` character, which acts as a wildcard that can be replaced by any single lowercase English letter. Consider all possible strings that can be produced by replacing each `*` character with any single lowercase En... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9075,
"level": 1,
"question": "You are given a string `s` consisting of lowercase English letters and the `*` character, which acts as a wildcard that can be replaced by any single lowercase English letter. Consider all possible strings that can be produced by replacing each `*` cha... |
import math
def arrays_equal(array1, array2, epsilon=1e-8):
# Check if the number of rows is the same
if len(array1) != len(array2):
return False
# Check each row
for row1, row2 in zip(array1, array2):
# Check if the number of elements in the row is the same
if len(row1) != len(... | simplelr_Filter | [
{
"content": "Question:\nWrite a routine to correctly check if two 2D arrays are completely equal. The arrays can contain integers or floating point values. Also, take into consideration floating point precision issue, thus two floating point numbers should be considered equal if their difference is within a pe... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9076,
"level": 1,
"question": "Write a routine to correctly check if two 2D arrays are completely equal. The arrays can contain integers or floating point values. Also, take into consideration floating point precision issue, thus two floating point numbers should be considered equal... |
def most_frequent_char(input_str: str) -> str:
if not input_str:
return ''
char_info = {}
for index, char in enumerate(input_str):
if char not in char_info:
char_info[char] = (1, index)
else:
current_count, first_index = char_info[char]
char_i... | simplelr_Algorithm | [
{
"content": "Question:\nMost Frequent Character\n\nYou are tasked with developing a function that identifies the most frequent character in a given string. In case of a tie, the earliest occurring character in the string should be returned.\n\n**Function Signature**:\n```python\ndef most_frequent_char(input_st... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9077,
"level": 1,
"question": "Most Frequent Character\n\nYou are tasked with developing a function that identifies the most frequent character in a given string. In case of a tie, the earliest occurring character in the string should be returned.\n\n**Function Signature**:\n```pyth... |
from collections import Counter
def count_pairs_with_difference_k(nums, k):
freq = Counter(nums)
k = abs(k)
count = 0
if k == 0:
for x in freq:
if freq[x] >= 2:
count += 1
else:
for x in freq:
y = x + k
if y in freq and y > x:
... | simplelr_Leetcode | [
{
"content": "Question:\nYou are given an integer array `nums`. Two numbers form a pair if the absolute difference between them is `k`. Your task is to count the number of unique pairs in the array where the absolute difference between the pairs is equal to `k`. Return _the number of unique pairs_.\n\n**Note:**... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9078,
"level": 1,
"question": "You are given an integer array `nums`. Two numbers form a pair if the absolute difference between them is `k`. Your task is to count the number of unique pairs in the array where the absolute difference between the pairs is equal to `k`. Return _the nu... |
def convert_to_binary(n):
if n == 0:
return '0' * 32
elif n > 0:
m = n
else:
m = (1 << 32) + n
bits = []
for i in range(31, -1, -1):
bit = (m >> i) & 1
bits.append('1' if bit else '0')
return ''.join(bits) | simplelr_Evol | [
{
"content": "Question:\nYour task is to create a Python function that converts a given integer into its binary representation without using the built-in `bin()` function. The function should take an integer as input and return a string representing the binary format of that integer. \n\n### Requirements:\n1. T... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9079,
"level": 1,
"question": "Your task is to create a Python function that converts a given integer into its binary representation without using the built-in `bin()` function. The function should take an integer as input and return a string representing the binary format of that i... |
def convert_to_html_entities(s):
entity_map = {
'&': '&',
'<': '<',
'>': '>',
'"': '"',
"'": '''
}
result = []
for char in s:
if char in entity_map:
result.append(entity_map[char])
else:
result.append(char... | simplelr_Prefill | [
{
"content": "Question:\nCreate a function that converts a given string to HTML entities.\nAnswer:\nLet's think step by step.\n",
"role": "user"
}
] | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9080,
"level": 1,
"question": "Create a function that converts a given string to HTML entities.",
"split": "train"
} |
def is_armstrong_number(n):
s = str(n)
d = len(s)
total = 0
for char in s:
digit = int(char)
total += digit ** d
return total == n
| simplelr_Taco | [
{
"content": "Question:\n=====Problem Statement=====\nIn this challenge, you are tasked with writing a function that determines whether a given number is an Armstrong number or not.\nAn Armstrong number (also known as a narcissistic number) is a number that is equal to the sum of its own digits each raised to t... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9081,
"level": 1,
"question": "=====Problem Statement=====\nIn this challenge, you are tasked with writing a function that determines whether a given number is an Armstrong number or not.\nAn Armstrong number (also known as a narcissistic number) is a number that is equal to the sum... |
def is_leap_year(year):
return year % 4 == 0 and year % 100 != 0 or year % 400 == 0
# Example usage:
print(is_leap_year(2024)) # Output: True | simplelr_Filter | [
{
"content": "Question:\nCreate a Python function that checks if a given year is a leap year. The function should return `True` if the year is a leap year, and `False` otherwise. Remember, a leap year is divisible by 4, but not by 100 unless it is also divisible by 400. Use this function to determine if the yea... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9082,
"level": 1,
"question": "Create a Python function that checks if a given year is a leap year. The function should return `True` if the year is a leap year, and `False` otherwise. Remember, a leap year is divisible by 4, but not by 100 unless it is also divisible by 400. Use th... |
def find_unique_elements(lst):
counts = {}
for num in lst:
if num in counts:
counts[num] += 1
else:
counts[num] = 1
result = []
for num in lst:
if counts[num] == 1:
result.append(num)
return result | simplelr_Evol | [
{
"content": "Question:\nWrite a function `find_unique_elements` that accepts a list of integers and returns a new list containing only the elements that are unique in the input list (i.e., elements that appear exactly once). Ensure that the output list maintains the original order of appearance in the input li... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9083,
"level": 1,
"question": "Write a function `find_unique_elements` that accepts a list of integers and returns a new list containing only the elements that are unique in the input list (i.e., elements that appear exactly once). Ensure that the output list maintains the original ... |
def longest_substr_two_distinct(s: str) -> str:
left = 0
max_length = 0
max_start = 0
char_count = {}
for right in range(len(s)):
c = s[right]
if c in char_count:
char_count[c] += 1
else:
char_count[c] = 1
# Shrink the window if it has more t... | simplelr_Algorithm | [
{
"content": "Question:\n### Problem Statement\n\nYou are provided with a string that contains alphanumeric characters. Your task is to write a function that finds the longest substring of the input string containing at most two distinct characters.\n\n**Function Signature**:\n```python\ndef longest_substr_two_... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9084,
"level": 1,
"question": "### Problem Statement\n\nYou are provided with a string that contains alphanumeric characters. Your task is to write a function that finds the longest substring of the input string containing at most two distinct characters.\n\n**Function Signature**:\... |
def multiply_list_elements(numbers):
"""
This function calculates the product of all elements in a given list of numbers.
Args:
numbers (list): A list of numeric values.
Returns:
int or float: The product of all elements in the list. If the list is empty, it returns 1.
"""
... | simplelr_Prefill | [
{
"content": "Question:\nWrite a python function to multiply all the elements in a list. I'm looking for a solution that is efficient and handles any list size.\nAnswer:\nLet's think step by step.\n",
"role": "user"
}
] | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9085,
"level": 1,
"question": "Write a python function to multiply all the elements in a list. I'm looking for a solution that is efficient and handles any list size.",
"split": "train"
} |
def fizzbuzz(n):
result = []
for i in range(1, n + 1):
if i % 3 == 0 and i % 5 == 0:
result.append("FizzBuzz")
elif i % 3 == 0:
result.append("Fizz")
elif i % 5 == 0:
result.append("Buzz")
else:
result.append(i)
return result | simplelr_Filter | [
{
"content": "Question:\nThe following code defines a function called `fizzbuzz` that takes a single integer argument `n`. It should return a list containing the numbers from 1 to `n`, but replacing any multiples of 3 with `\"Fizz\"`, any multiples of 5 with `\"Buzz\"`, and any multiples of both 3 and 5 with `\... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9086,
"level": 1,
"question": "The following code defines a function called `fizzbuzz` that takes a single integer argument `n`. It should return a list containing the numbers from 1 to `n`, but replacing any multiples of 3 with `\"Fizz\"`, any multiples of 5 with `\"Buzz\"`, and an... |
def reverse_list(lst):
n = len(lst)
for i in range(n // 2):
lst[i], lst[n - 1 - i] = lst[n - 1 - i], lst[i]
return lst
# Example usage:
numbers = [1, 2, 3, 4, 5]
print("Original List:", numbers)
print("Reversed List:", reverse_list(numbers)) | simplelr_Filter | [
{
"content": "Question:\nI need help with writing a function in Python to reverse the elements of a list without using any built-in functions or methods. Can you provide a simple example?\nAnswer:\nLet's think step by step.\n",
"role": "user"
}
] | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9087,
"level": 1,
"question": "I need help with writing a function in Python to reverse the elements of a list without using any built-in functions or methods. Can you provide a simple example?",
"split": "train"
} |
def group_anagrams(strs):
anagrams = {}
for word in strs:
key = ''.join(sorted(word))
if key in anagrams:
anagrams[key].append(word)
else:
anagrams[key] = [word]
return list(anagrams.values())
| simplelr_Taco | [
{
"content": "Question:\nWrite a function that takes a list of strings and merges all the anagrams into a list of lists. Each list within the list should contain strings that are anagrams of each other. An anagram is a word, phrase, or name formed by rearranging the letters of another, such as 'cinema', formed ... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9088,
"level": 1,
"question": "Write a function that takes a list of strings and merges all the anagrams into a list of lists. Each list within the list should contain strings that are anagrams of each other. An anagram is a word, phrase, or name formed by rearranging the letters of... |
def count_distinct_substrings(s):
substrings = set()
n = len(s)
for start in range(n + 1):
for end in range(start, n + 1):
substr = s[start:end]
substrings.add(substr)
return len(substrings) | simplelr_Filter | [
{
"content": "Question:\nWrite a Python function that accepts a string and returns the count of distinct substrings including the empty string.\nAnswer:\nLet's think step by step.\n",
"role": "user"
}
] | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9089,
"level": 1,
"question": "Write a Python function that accepts a string and returns the count of distinct substrings including the empty string.",
"split": "train"
} |
def product_except_self(nums):
n = len(nums)
prefix = [1] * n
for i in range(1, n):
prefix[i] = prefix[i-1] * nums[i-1]
suffix = [1] * n
for i in range(n-2, -1, -1):
suffix[i] = suffix[i+1] * nums[i+1]
result = [prefix[i] * suffix[i] for i in range(n)]
return result | simplelr_Evol | [
{
"content": "Question:\nWrite a function in Python that takes a list of integers and returns a new list where each element at index i is the product of all the numbers in the original list except the one at index i. You must achieve this without using division and in O(n) time complexity. For example, given th... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9090,
"level": 1,
"question": "Write a function in Python that takes a list of integers and returns a new list where each element at index i is the product of all the numbers in the original list except the one at index i. You must achieve this without using division and in O(n) tim... |
def uniquePaths(N, M):
total = N + M - 2
k = min(N - 1, M - 1)
result = 1
for i in range(1, k + 1):
result = result * (total - k + i) // i
return result
| simplelr_Taco | [
{
"content": "Question:\nA new online gaming company wants to design a game where a player can move a character on a two-dimensional grid. The grid is composed of N rows and M columns, and initially, the character is positioned at the top-left corner of the grid (i.e., at cell (1,1)). The player can move the ch... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9091,
"level": 1,
"question": "A new online gaming company wants to design a game where a player can move a character on a two-dimensional grid. The grid is composed of N rows and M columns, and initially, the character is positioned at the top-left corner of the grid (i.e., at cell... |
def first_unique_character(s: str) -> str:
freq = {}
for char in s:
if char in freq:
freq[char] += 1
else:
freq[char] = 1
for char in s:
if freq[char] == 1:
return char
return '' | simplelr_Algorithm | [
{
"content": "Question:\n### Unique String Identifier Finder\n\n**Context**: In many applications, it's important to find and identify unique elements within a dataset. This can promote efficiency in data retrieval operations and is crucial in operations like removing duplicates or identifying anomalies.\n\n**Y... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9092,
"level": 1,
"question": "### Unique String Identifier Finder\n\n**Context**: In many applications, it's important to find and identify unique elements within a dataset. This can promote efficiency in data retrieval operations and is crucial in operations like removing duplicat... |
def is_match(s: str, p: str) -> bool:
n = len(s)
m = len(p)
dp = [[False] * (m + 1) for _ in range(n + 1)]
dp[0][0] = True # Empty string matches empty pattern
for i in range(n + 1):
for j in range(m + 1):
if i == 0 and j == 0:
continue # Already initialize... | simplelr_Data_Structure | [
{
"content": "Question:\n### Regular Expression Matching Algorithm\n\nGiven a string `s` and a pattern `p` that contains `.` and `*` as regular expression symbols, implement a function `bool is_match(const char *s, const char *p)` to determine if `s` matches the entire pattern `p`. \n\n#### Regular Expression R... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9093,
"level": 1,
"question": "### Regular Expression Matching Algorithm\n\nGiven a string `s` and a pattern `p` that contains `.` and `*` as regular expression symbols, implement a function `bool is_match(const char *s, const char *p)` to determine if `s` matches the entire pattern... |
def max_profit(prices: list[int]) -> int:
min_price = prices[0]
max_profit = 0
for price in prices[1:]:
current_profit = price - min_price
if current_profit > max_profit:
max_profit = current_profit
if price < min_price:
min_price = price
return max_profit | simplelr_Algorithm | [
{
"content": "Question:\n### Problem Statement\nYou are tasked with evaluating the performance of cryptocurrency investments over a period. Given a list of daily prices for a certain cryptocurrency, determine the best possible profit that could have been made by buying on one day and selling on another later da... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9094,
"level": 1,
"question": "### Problem Statement\nYou are tasked with evaluating the performance of cryptocurrency investments over a period. Given a list of daily prices for a certain cryptocurrency, determine the best possible profit that could have been made by buying on one ... |
def merge_sorted_arrays(arr1, arr2):
result = []
i = j = 0
while i < len(arr1) and j < len(arr2):
if arr1[i] <= arr2[j]:
result.append(arr1[i])
i += 1
else:
result.append(arr2[j])
j += 1
result += arr1[i:]
result += arr2[j:]
return ... | simplelr_Evol | [
{
"content": "Question:\nWrite a function `merge_sorted_arrays` in Python that takes two lists of integers, `arr1` and `arr2`, which are both already sorted in ascending order, and returns a single merged list that contains all elements from both lists, also sorted in ascending order. Ensure the merged list mai... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9095,
"level": 1,
"question": "Write a function `merge_sorted_arrays` in Python that takes two lists of integers, `arr1` and `arr2`, which are both already sorted in ascending order, and returns a single merged list that contains all elements from both lists, also sorted in ascendin... |
def heightChecker(heights):
sorted_heights = sorted(heights)
count = 0
for i in range(len(heights)):
if heights[i] != sorted_heights[i]:
count += 1
return count | simplelr_Leetcode | [
{
"content": "Question:\nYou are given an array of integers `heights` representing the heights of students standing in a line. A \"heightChecker\" determines how many students are not standing in the right positions. More formally, a student `i` is standing in the wrong position if `heights[i]` != `heights[i]` ... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9096,
"level": 1,
"question": "You are given an array of integers `heights` representing the heights of students standing in a line. A \"heightChecker\" determines how many students are not standing in the right positions. More formally, a student `i` is standing in the wrong positi... |
def binary_search(sorted_list, target):
low = 0
high = len(sorted_list) - 1
while low <= high:
mid = (low + high) // 2
if sorted_list[mid] == target:
return mid
elif sorted_list[mid] > target:
high = mid - 1
else:
low = mid + 1
return ... | simplelr_Filter | [
{
"content": "Question:\nCan you explain the concept of binary search and provide a Python implementation?\nAnswer:\nLet's think step by step.\n",
"role": "user"
}
] | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9097,
"level": 1,
"question": "Can you explain the concept of binary search and provide a Python implementation?",
"split": "train"
} |
def restore_string(s, indices):
res = [''] * len(s)
for i in range(len(s)):
res[indices[i]] = s[i]
return ''.join(res) | simplelr_Leetcode | [
{
"content": "Question:\nYou are given a string `s` consisting of lowercase English letters and an integer array `indices` of the same length. The string `s` has to be reconstructed by placing each character from `s` at the index specified in the array `indices`. Return _the reconstructed string_.\nAnswer:\nLet... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9098,
"level": 1,
"question": "You are given a string `s` consisting of lowercase English letters and an integer array `indices` of the same length. The string `s` has to be reconstructed by placing each character from `s` at the index specified in the array `indices`. Return _the r... |
def sort_descending(numbers):
return sorted(numbers, reverse=True) | simplelr_Prefill | [
{
"content": "Question:\nWrite a python function to sort a given list of numbers in descending order.\nAnswer:\nLet's think step by step.\n",
"role": "user"
}
] | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 9099,
"level": 1,
"question": "Write a python function to sort a given list of numbers in descending order.",
"split": "train"
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.