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 int_modified_euclidean(a, b):
while b != 0:
a, b = b, a % b
return 1 if a == 1 else 0 | simplelr_Filter | [
{
"content": "Question:\nA modified version of the Euclidean algorithm is as follows:\n\nCreate a function `int_modified_euclidean(int a, int b)` which takes 2 integer arguments and returns 1 if the GCD of `a` and `b` is 1, otherwise returns 0.\n\nThe modified Euclidean algorithm is: `GCD(a,b) = GCD(b, a mod b)... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2100,
"level": 1,
"question": "A modified version of the Euclidean algorithm is as follows:\n\nCreate a function `int_modified_euclidean(int a, int b)` which takes 2 integer arguments and returns 1 if the GCD of `a` and `b` is 1, otherwise returns 0.\n\nThe modified Euclidean algori... |
def max_subarray_sum(array):
if not array:
return 0
max_current = max_so_far = array[0]
for num in array[1:]:
max_current = max(num, max_current + num)
max_so_far = max(max_so_far, max_current)
return max_so_far | simplelr_Filter | [
{
"content": "Question:\nCreate a Kadane's Algorithm to find the maximum subarray sum of a given array.\nAnswer:\nLet's think step by step.\n",
"role": "user"
}
] | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2101,
"level": 1,
"question": "Create a Kadane's Algorithm to find the maximum subarray sum of a given array.",
"split": "train"
} |
from collections import Counter
def intersection_unique_elements(list1, list2):
count1 = Counter(list1)
count2 = Counter(list2)
common = count1.keys() & count2.keys()
result = [item for item in common if count1[item] == 1 and count2[item] == 1]
return sorted(result) | simplelr_Prefill | [
{
"content": "Question:\nWrite a python function to find the intersection of two lists, but the intersection should only include elements that appear exactly once in both lists.\nAnswer:\nLet's think step by step.\n",
"role": "user"
}
] | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2102,
"level": 1,
"question": "Write a python function to find the intersection of two lists, but the intersection should only include elements that appear exactly once in both lists.",
"split": "train"
} |
def factorial(n):
"""
Calculate the factorial of a non-negative integer n using recursion.
Args:
n (int): A non-negative integer.
Returns:
int: The factorial of n.
Raises:
ValueError: If n is a negative integer.
"""
if n < 0:
raise ValueError("n must be a n... | simplelr_Filter | [
{
"content": "Question:\nGenerate a sample code snippet in Python for a function that calculates the factorial of a number using recursion.\nAnswer:\nLet's think step by step.\n",
"role": "user"
}
] | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2103,
"level": 1,
"question": "Generate a sample code snippet in Python for a function that calculates the factorial of a number using recursion.",
"split": "train"
} |
def find_keyword_positions(text, keyword):
positions = []
start = 0
while True:
pos = text.find(keyword, start)
if pos == -1:
break
positions.append(pos)
start = pos + 1
return positions | simplelr_Codeforces | [
{
"content": "Question:\nYou are working on a new text editor application. One of the features is a keyword-based search that highlights all occurrences of a given keyword in the text. To create an efficient search algorithm, you decide to implement a function that finds all the starting positions of the keywor... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2104,
"level": 1,
"question": "You are working on a new text editor application. One of the features is a keyword-based search that highlights all occurrences of a given keyword in the text. To create an efficient search algorithm, you decide to implement a function that finds all t... |
def sum_of_squares(arr):
return sum(x ** 2 for x in arr) | simplelr_Prefill | [
{
"content": "Question:\nCreate a function that takes an array of integers as input and returns the sum of the squares of the numbers. For example, if the input is `[2, 3, 4]`, the function should return `4 + 9 + 16 = 39`.\nAnswer:\nLet's think step by step.\n",
"role": "user"
}
] | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2105,
"level": 1,
"question": "Create a function that takes an array of integers as input and returns the sum of the squares of the numbers. For example, if the input is `[2, 3, 4]`, the function should return `4 + 9 + 16 = 39`.",
"split": "train"
} |
def toggle_bulbs(arr, k):
new_arr = arr.copy()
for j in range(len(new_arr)):
if (j + 1) % k == 0:
new_arr[j] = 1 - new_arr[j]
return new_arr | simplelr_Leetcode | [
{
"content": "Question:\nGiven an integer array `arr` representing the state of `n` bulbs, where `arr[i] = 1` means the `i`-th bulb is on and `arr[i] = 0` means the `i`-th bulb is off, you are tasked to perform a sequence of operations to toggle the state of the bulbs. The operations are defined as follows:\n\n... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2106,
"level": 1,
"question": "Given an integer array `arr` representing the state of `n` bulbs, where `arr[i] = 1` means the `i`-th bulb is on and `arr[i] = 0` means the `i`-th bulb is off, you are tasked to perform a sequence of operations to toggle the state of the bulbs. The ope... |
def find_last_occurrence_of_substring(input_string, substring):
lower_input = input_string.lower()
lower_sub = substring.lower()
return lower_input.rfind(lower_sub) | simplelr_Filter | [
{
"content": "Question:\nI'll provide you with a string of text, and I want you to write a simple Python function that takes that string as input and returns the index of the last occurrence of a specific substring.\n\nHere's the string: \"The quick brown fox jumps over the lazy dog\"\n\nAnd I want to find the ... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2107,
"level": 1,
"question": "I'll provide you with a string of text, and I want you to write a simple Python function that takes that string as input and returns the index of the last occurrence of a specific substring.\n\nHere's the string: \"The quick brown fox jumps over the la... |
def sortQueue(arr, N):
arr.sort()
| simplelr_Taco | [
{
"content": "Question:\nYou are given an array of integers representing the heights of people standing in a queue. The heights can vary, but shorter people should be seated in front while taller ones should be at the back, maintaining the original order of people with the same height.\n\nExample 1:\nInput: N =... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2108,
"level": 1,
"question": "You are given an array of integers representing the heights of people standing in a queue. The heights can vary, but shorter people should be seated in front while taller ones should be at the back, maintaining the original order of people with the sam... |
def reverse_words_order(s):
words = s.split()
words.reverse()
return ' '.join(words) | simplelr_Prefill | [
{
"content": "Question:\nWrite a function to reverse the order of words in a string, but keep the words themselves in their original order. For example, if the input is \"The quick brown fox jumps over the lazy dog\", the output should be \"dog lazy the over jumps fox brown quick The\". Here, the words are sepa... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2109,
"level": 1,
"question": "Write a function to reverse the order of words in a string, but keep the words themselves in their original order. For example, if the input is \"The quick brown fox jumps over the lazy dog\", the output should be \"dog lazy the over jumps fox brown qu... |
def sum_of_digits(num):
num = abs(num)
total = 0
while num > 0:
digit = num % 10
total += digit
num //= 10
return total | simplelr_Filter | [
{
"content": "Question:\nThis is the code I have written for the following prompt:\n\n\"Write a Python program to find the sum of digits of a given number.\"\n\n```python\ndef sum_of_digits(num):\n sum = 0 \n while num > 0:\n digit = num % 10\n sum += digit\n num //= 10\n return su... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2110,
"level": 1,
"question": "This is the code I have written for the following prompt:\n\n\"Write a Python program to find the sum of digits of a given number.\"\n\n```python\ndef sum_of_digits(num):\n sum = 0 \n while num > 0:\n digit = num % 10\n sum += digit... |
def hardy_ramanujan(n):
"""
Checks if a number can be expressed as the sum of two cubes in two different ways.
Args:
n: An integer.
Returns:
True if the number can be expressed as the sum of two cubes in two different ways,
and False otherwise.
"""
pairs = set()
a ... | simplelr_Filter | [
{
"content": "Question:\nThe number 1729 is called the Hardy-Ramanujan number. It is the smallest number that can be expressed as the sum of two cubes in two different ways:\n\n1729 = 1³ + 12³ = 9³ + 10³.\n\n**Here's your question:**\n\nWrite a Python function called \"hardy_ramanujan\" that takes an integer `n... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2111,
"level": 1,
"question": "The number 1729 is called the Hardy-Ramanujan number. It is the smallest number that can be expressed as the sum of two cubes in two different ways:\n\n1729 = 1³ + 12³ = 9³ + 10³.\n\n**Here's your question:**\n\nWrite a Python function called \"hardy_r... |
def frequency(arr, num):
count = 0
for element in arr:
if element == num:
count += 1
return count | simplelr_Prefill | [
{
"content": "Question:\nWrite a function to determine the frequency of a given integer in a non-empty array of integers. The function should return the count of occurrences of the integer.\nAnswer:\nLet's think step by step.\n",
"role": "user"
}
] | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2112,
"level": 1,
"question": "Write a function to determine the frequency of a given integer in a non-empty array of integers. The function should return the count of occurrences of the integer.",
"split": "train"
} |
import re
def extract_emails(text):
# Regular expression pattern for matching email addresses
email_pattern = r'\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b'
# Find all matches in the text
emails = re.findall(email_pattern, text)
return emails
# Example usage:
text = "Contact me at john.doe... | simplelr_Filter | [
{
"content": "Question:\nCan you provide a Python code to extract the email addresses from a given text string?\nAnswer:\nLet's think step by step.\n",
"role": "user"
}
] | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2113,
"level": 1,
"question": "Can you provide a Python code to extract the email addresses from a given text string?",
"split": "train"
} |
def list_to_comma_separated_string(lst):
return ','.join(str(x) for x in lst) | simplelr_Filter | [
{
"content": "Question:\nWrite a Python function to convert a list of integers into a comma-separated string. The function should be able to handle an empty list and return an empty string in that case. Additionally, ensure that there are no trailing commas at the end of the string.\nAnswer:\nLet's think step b... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2114,
"level": 1,
"question": "Write a Python function to convert a list of integers into a comma-separated string. The function should be able to handle an empty list and return an empty string in that case. Additionally, ensure that there are no trailing commas at the end of the s... |
def generateModifiedFibonacci(n):
if n == 1:
return [0]
elif n == 2:
return [0, 1]
elif n == 3:
return [0, 1, 1]
else:
fib = [0, 1, 1]
for i in range(3, n):
next_val = fib[i-1] + fib[i-2] + fib[i-3]
fib.append(next_val)
return fib[:... | simplelr_Taco | [
{
"content": "Question:\nJay loves mathematics, particularly the study of number sequences. Recently, he came across the Fibonacci sequence and became fascinated with it. He decided to extend it in his own way and call it the \"Modified Fibonacci Sequence.\" In this sequence, every third term is the sum of the ... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2115,
"level": 1,
"question": "Jay loves mathematics, particularly the study of number sequences. Recently, he came across the Fibonacci sequence and became fascinated with it. He decided to extend it in his own way and call it the \"Modified Fibonacci Sequence.\" In this sequence, ... |
import re
from collections import defaultdict
def word_count(s):
s = s.lower()
cleaned = re.sub(r"[^a-z']", ' ', s)
words = cleaned.split()
words = [word.strip("'") for word in words]
words = [word for word in words if word]
counts = defaultdict(int)
for word in words:
counts[word] ... | simplelr_Filter | [
{
"content": "Question:\nYou have been tasked with writing a function `word_count` that takes a string as input, counts the frequency of each word, and returns a dictionary where the keys are the unique words and the values are their corresponding frequencies. The function should ignore case, punctuation, and l... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2116,
"level": 1,
"question": "You have been tasked with writing a function `word_count` that takes a string as input, counts the frequency of each word, and returns a dictionary where the keys are the unique words and the values are their corresponding frequencies. The function sho... |
def shortest_palindrome(s):
n = len(s)
for i in range(n):
substr = s[i:]
if substr == substr[::-1]:
return s + s[:i][::-1]
return s + s[:-1][::-1] | simplelr_Prefill | [
{
"content": "Question:\nWrite a function to generate the shortest possible palindrome by appending characters to the end of a given string. The function should not change the original string.\nAnswer:\nLet's think step by step.\n",
"role": "user"
}
] | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2117,
"level": 1,
"question": "Write a function to generate the shortest possible palindrome by appending characters to the end of a given string. The function should not change the original string.",
"split": "train"
} |
def count_consonants(s):
vowels = {'a', 'e', 'i', 'o', 'u'}
count = 0
for char in s:
if char.isalpha():
if char.lower() not in vowels:
count += 1
return count | simplelr_Filter | [
{
"content": "Question:\nCan you provide a Python code snippet to count the number of consonants in a given string?\nAnswer:\nLet's think step by step.\n",
"role": "user"
}
] | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2118,
"level": 1,
"question": "Can you provide a Python code snippet to count the number of consonants in a given string?",
"split": "train"
} |
def threeSum(nums, target):
nums.sort()
for i in range(len(nums)):
if i > 0 and nums[i] == nums[i - 1]:
continue
left = i + 1
right = len(nums) - 1
while left < right:
current_sum = nums[i] + nums[left] + nums[right]
if current_sum == target:
... | simplelr_Taco | [
{
"content": "Question:\nGiven a list of integers `nums` and an integer `target`, determine whether there exist three distinct elements in `nums` that add up to the `target`. The function should return a boolean value `True` if such a combination exists, and `False` otherwise.\n\nExamples:\nInput: nums = [1, 2,... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2119,
"level": 1,
"question": "Given a list of integers `nums` and an integer `target`, determine whether there exist three distinct elements in `nums` that add up to the `target`. The function should return a boolean value `True` if such a combination exists, and `False` otherwise.... |
def compute_grade(hw, proj, exam, hw_weight, proj_weight, exam_weight):
return hw * hw_weight + proj * proj_weight + exam * exam_weight | simplelr_Filter | [
{
"content": "Question:\nIn the United States, a student's final grade on a university course is typically computed from three components: a homework component, a project component, and an exam component. The weights of these three components are usually not the same. The usual formula is 20% for homework, 30% ... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2120,
"level": 1,
"question": "In the United States, a student's final grade on a university course is typically computed from three components: a homework component, a project component, and an exam component. The weights of these three components are usually not the same. The usua... |
def max_product_of_two(arr):
if len(arr) < 2:
return 0 # Assuming the function should handle cases where array has less than two elements, though the problem states it's guaranteed.
first = max(arr[0], arr[1])
second = min(arr[0], arr[1])
for num in arr[2:]:
if num > first:
... | simplelr_Leetcode | [
{
"content": "Question:\nGiven an integer array `arr`, find the maximum product of two distinct elements in the array. Return the product of these two elements. Each element in the array is guaranteed to be a positive integer. Ensure the solution has a time complexity of `O(n)` and uses only constant extra spac... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2121,
"level": 1,
"question": "Given an integer array `arr`, find the maximum product of two distinct elements in the array. Return the product of these two elements. Each element in the array is guaranteed to be a positive integer. Ensure the solution has a time complexity of `O(n)... |
def reverse_string(s):
"""Reverses a string.
Args:
s: The string to reverse.
Returns:
The reversed string.
"""
return s[::-1] | simplelr_Filter | [
{
"content": "Question:\nThis code defines a function to reverse a string:\n\n```python\ndef reverse_string(s):\n\"\"\"Reverses a string.\n\nArgs:\n s: The string to reverse.\n\nReturns:\n The reversed string.\n\"\"\"\n return s[::-1]\nAnswer:\nLet's think step by step.\n",
"role": "user"
}
] | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2122,
"level": 1,
"question": "This code defines a function to reverse a string:\n\n```python\ndef reverse_string(s):\n\"\"\"Reverses a string.\n\nArgs:\n s: The string to reverse.\n\nReturns:\n The reversed string.\n\"\"\"\n return s[::-1]",
"split": "train"
} |
def fibonacci(n):
if n == 0:
return 0
elif n == 1:
return 1
a, b = 0, 1
for i in range(2, n + 1):
c = a + b
a = b
b = c
return b | simplelr_Prefill | [
{
"content": "Question:\nWrite a python function to generate the nth Fibonacci number using a dynamic programming approach. The function should take the position `n` as input and return the nth Fibonacci number.\nAnswer:\nLet's think step by step.\n",
"role": "user"
}
] | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2123,
"level": 1,
"question": "Write a python function to generate the nth Fibonacci number using a dynamic programming approach. The function should take the position `n` as input and return the nth Fibonacci number.",
"split": "train"
} |
def transform_string(input_str):
words = input_str.split()
transformed = []
for word in words:
if not word:
transformed_word = ''
else:
first_char = word[0].upper() if word[0].isalpha() else word[0]
rest = [c.lower() if c.isalpha() else c for c in word[1:]... | simplelr_Evol | [
{
"content": "Question:\nWrite a function that accepts a string consisting of multiple words. The function should capitalize the first letter of each word and lowercase the rest of the letters in each word. Special characters should remain unchanged. The transformed string should be returned as the output. For ... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2124,
"level": 1,
"question": "Write a function that accepts a string consisting of multiple words. The function should capitalize the first letter of each word and lowercase the rest of the letters in each word. Special characters should remain unchanged. The transformed string sho... |
def list_intersection(list1, list2):
set1 = set(list1)
set2 = set(list2)
common = set1 & set2
return sorted(list(common)) | simplelr_Prefill | [
{
"content": "Question:\nCreate a function that takes in two lists of strings and returns a new list containing the intersection of these lists. The intersection should contain only unique elements and be returned in alphabetical order.\nAnswer:\nLet's think step by step.\n",
"role": "user"
}
] | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2125,
"level": 1,
"question": "Create a function that takes in two lists of strings and returns a new list containing the intersection of these lists. The intersection should contain only unique elements and be returned in alphabetical order.",
"split": "train"
} |
def find_missing_number(arr):
n = len(arr)
expected_sum = n * (n + 1) // 2
actual_sum = sum(arr)
return expected_sum - actual_sum | simplelr_Prefill | [
{
"content": "Question:\nWrite a function to find the missing number in an array containing distinct numbers from 0 to n. There is exactly one number missing from the array.\nAnswer:\nLet's think step by step.\n",
"role": "user"
}
] | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2126,
"level": 1,
"question": "Write a function to find the missing number in an array containing distinct numbers from 0 to n. There is exactly one number missing from the array.",
"split": "train"
} |
def square(number):
return number ** 2 | simplelr_Filter | [
{
"content": "Question:\nWhich of the following is the correct way to define a function in Python that calculates the square of a number?\nAnswer:\nLet's think step by step.\n",
"role": "user"
}
] | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2127,
"level": 1,
"question": "Which of the following is the correct way to define a function in Python that calculates the square of a number?",
"split": "train"
} |
def shift_right(arr, n):
if not arr:
return []
m = n % len(arr)
return arr[-m:] + arr[:-m] | simplelr_Filter | [
{
"content": "Question:\nI have an array of items and want to generate a new array that contains all the items from the original array, but with every item shifted to the right by a fixed number of positions, say n. \n\nFor example, if I have the following array:\n\n`[1, 2, 3, 4, 5]`\n\nAnd I want to shift all ... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2128,
"level": 1,
"question": "I have an array of items and want to generate a new array that contains all the items from the original array, but with every item shifted to the right by a fixed number of positions, say n. \n\nFor example, if I have the following array:\n\n`[1, 2, 3,... |
def sum_factors(n):
factors = []
for i in range(1, n + 1):
if n % i == 0:
factors.append(i)
return sum(factors)
print(sum_factors(6)) # Output: 12 | simplelr_Filter | [
{
"content": "Question:\ndef sum_factors(n):\n factors = []\n for i in range(1, n + 1):\n if n % i == 0:\n factors.append(i)\n return sum(factors)\n\nprint(sum_factors(6))\nAnswer:\nLet's think step by step.\n",
"role": "user"
}
] | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2129,
"level": 1,
"question": "def sum_factors(n):\n factors = []\n for i in range(1, n + 1):\n if n % i == 0:\n factors.append(i)\n return sum(factors)\n\nprint(sum_factors(6))",
"split": "train"
} |
def subset_sum_to_k(arr, k):
if k == 0:
return True
dp = [False] * (k + 1)
dp[0] = True # Base case: sum of 0 is always possible with an empty subset
for num in arr:
# Iterate backwards to avoid using the same number multiple times
for s in range(k, num - 1, -1):
if ... | simplelr_Leetcode | [
{
"content": "Question:\nYou are given an integer array `arr` and an integer `k`. Your task is to determine if there exists a subset of `arr` whose sum is equal to `k`. If such a subset exists, return `True`; otherwise, return `False`. The elements in the subset must be distinct and can be selected in any order... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2130,
"level": 1,
"question": "You are given an integer array `arr` and an integer `k`. Your task is to determine if there exists a subset of `arr` whose sum is equal to `k`. If such a subset exists, return `True`; otherwise, return `False`. The elements in the subset must be distin... |
def longest_substring_with_k_distinct_chars(s, k):
left = 0
max_length = 0
counts = {}
for right in range(len(s)):
c = s[right]
counts[c] = counts.get(c, 0) + 1
# While the number of distinct characters exceeds k, shrink the window from left
while len(counts) > k:
... | simplelr_Leetcode | [
{
"content": "Question:\nGiven a string `s` of lowercase English letters and an integer `k`, you need to find the length of the longest substring of `s` such that the number of distinct characters in this substring is less than or equal to `k`. Return _this length as an integer_.\nAnswer:\nLet's think step by s... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2131,
"level": 1,
"question": "Given a string `s` of lowercase English letters and an integer `k`, you need to find the length of the longest substring of `s` such that the number of distinct characters in this substring is less than or equal to `k`. Return _this length as an intege... |
def compress_list(lst):
if not lst:
return []
result = []
current = lst[0]
count = 1
for num in lst[1:]:
if num == current:
count += 1
else:
result.append((current, count))
current = num
count = 1
result.append((current, cou... | simplelr_Apps | [
{
"content": "Question:\nYou are given a list of integers. Your task is to write a function `compress_list(lst)` that compresses the list by grouping consecutive runs of the same number.\n\nThe function should return a list of tuples, where each tuple contains the number and the count of its consecutive occurre... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2132,
"level": 1,
"question": "You are given a list of integers. Your task is to write a function `compress_list(lst)` that compresses the list by grouping consecutive runs of the same number.\n\nThe function should return a list of tuples, where each tuple contains the number and t... |
def roman_to_int(s):
roman_dict = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000}
total = 0
for i in range(len(s)):
current_value = roman_dict[s[i]]
if i < len(s) - 1 and current_value < roman_dict[s[i + 1]]:
total -= current_value
else:
tota... | simplelr_Filter | [
{
"content": "Question:\nI need to create a function in Python that converts a Roman numeral to an integer. The Roman numeral is given as a string. Can you provide a detailed explanation and a code example?\nAnswer:\nLet's think step by step.\n",
"role": "user"
}
] | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2133,
"level": 1,
"question": "I need to create a function in Python that converts a Roman numeral to an integer. The Roman numeral is given as a string. Can you provide a detailed explanation and a code example?",
"split": "train"
} |
def hello_world():
return "Hello, World!" | simplelr_Prefill | [
{
"content": "Question:\nCreate a function that outputs a string that says \"Hello, World!\" in Python.\nAnswer:\nLet's think step by step.\n",
"role": "user"
}
] | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2134,
"level": 1,
"question": "Create a function that outputs a string that says \"Hello, World!\" in Python.",
"split": "train"
} |
def is_prime(num):
if num < 2:
return False
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
return False
return True | simplelr_Filter | [
{
"content": "Question:\nCan you generate a simple code snippet that checks if a number is a prime number in Python?\nAnswer:\nLet's think step by step.\n",
"role": "user"
}
] | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2135,
"level": 1,
"question": "Can you generate a simple code snippet that checks if a number is a prime number in Python?",
"split": "train"
} |
import re
def find_pattern_in_file(file_path, pattern, case_sensitive=True):
"""
Searches for a given pattern in a file and returns the line numbers where the pattern is found.
Args:
file_path (str): Path to the file to be searched.
pattern (str): The regular expression pattern to search f... | simplelr_Filter | [
{
"content": "Question:\nCould you provide a Python code that checks if a specific string pattern exists in a file and returns the line numbers where the pattern is found? You can use regular expressions for this task.\nAnswer:\nLet's think step by step.\n",
"role": "user"
}
] | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2136,
"level": 1,
"question": "Could you provide a Python code that checks if a specific string pattern exists in a file and returns the line numbers where the pattern is found? You can use regular expressions for this task.",
"split": "train"
} |
def sort_by_length(lst):
return sorted(lst, key=lambda x: len(x))
| simplelr_Taco | [
{
"content": "Question:\nSort strings in a given list based on their length and return the sorted list.\n\nPython:\n\n sort_by_length(['apple', 'banana', 'kiwi', 'fig', 'strawberry', 'date']) = ['fig', 'kiwi', 'date', 'apple', 'banana', 'strawberry']\n \nEnsure to handle strings of different lengths corre... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2137,
"level": 1,
"question": "Sort strings in a given list based on their length and return the sorted list.\n\nPython:\n\n sort_by_length(['apple', 'banana', 'kiwi', 'fig', 'strawberry', 'date']) = ['fig', 'kiwi', 'date', 'apple', 'banana', 'strawberry']\n \nEnsure to handle... |
def filter_strings_start_with_vowel(strings_list):
vowels = {'a', 'e', 'i', 'o', 'u'}
return [s for s in strings_list if s and s[0].lower() in vowels] | simplelr_Filter | [
{
"content": "Question:\nHow can I use Python to create a function that takes a list of strings as input and returns a new list containing only the strings that start with a vowel?\nAnswer:\nLet's think step by step.\n",
"role": "user"
}
] | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2138,
"level": 1,
"question": "How can I use Python to create a function that takes a list of strings as input and returns a new list containing only the strings that start with a vowel?",
"split": "train"
} |
def is_sorted_ascending(arr):
for i in range(len(arr) - 1):
if arr[i] > arr[i + 1]:
return False
return True | simplelr_Filter | [
{
"content": "Question:\nCan you help me write a program that can determine whether an array is sorted in ascending order or not using Python?\nAnswer:\nLet's think step by step.\n",
"role": "user"
}
] | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2139,
"level": 1,
"question": "Can you help me write a program that can determine whether an array is sorted in ascending order or not using Python?",
"split": "train"
} |
def generate_catalan_numbers(n: int) -> list[int]:
if not isinstance(n, int):
raise ValueError("Input must be a non-negative integer.")
if n < 0:
raise ValueError("Input must be a non-negative integer.")
if n == 0:
return []
catalan_numbers = [1] # C_0
for i in range(1, n):
... | simplelr_Algorithm | [
{
"content": "Question:\n### Coding Assessment Question\n\n#### Context\n\nFactorials are a fundamental concept in mathematics, often used in permutations, combinations, and other areas of discrete mathematics and number theory. The factorial of a non-negative integer \\( n \\), denoted by \\( n! \\), is the pr... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2140,
"level": 1,
"question": "### Coding Assessment Question\n\n#### Context\n\nFactorials are a fundamental concept in mathematics, often used in permutations, combinations, and other areas of discrete mathematics and number theory. The factorial of a non-negative integer \\( n \\... |
def encode_string(s):
encoded = []
for char in s:
if char.isalpha():
if char.islower():
base = ord('a')
else:
base = ord('A')
offset = ord(char) - base
new_offset = (offset + 3) % 26
new_char = chr(base + new_off... | simplelr_Filter | [
{
"content": "Question:\nWrite a Python function to encode a string by replacing each letter with the letter three places ahead in the alphabet. For example, 'a' becomes 'd', 'b' becomes 'e', and so on. The function should wrap around so that 'z' becomes 'c'. Spaces and punctuation should remain unchanged. Test... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2141,
"level": 1,
"question": "Write a Python function to encode a string by replacing each letter with the letter three places ahead in the alphabet. For example, 'a' becomes 'd', 'b' becomes 'e', and so on. The function should wrap around so that 'z' becomes 'c'. Spaces and punctu... |
def count_sublists_with_target_sum(arr, target):
prefix_counts = {0: 1}
current_sum = 0
count = 0
for num in arr:
current_sum += num
# Check if there are existing prefix sums such that current_sum - (current_sum - target) = target
count += prefix_counts.get(current_sum - target, ... | simplelr_Prefill | [
{
"content": "Question:\nCreate a function that takes a list of integers and returns the count of distinct, non-empty contiguous sublists that have a sum equal to a given target sum.\nAnswer:\nLet's think step by step.\n",
"role": "user"
}
] | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2142,
"level": 1,
"question": "Create a function that takes a list of integers and returns the count of distinct, non-empty contiguous sublists that have a sum equal to a given target sum.",
"split": "train"
} |
def swap_case(sentence: str) -> str:
result = []
for char in sentence:
if char.isupper():
result.append(char.lower())
elif char.islower():
result.append(char.upper())
else:
result.append(char)
return ''.join(result) | simplelr_Algorithm | [
{
"content": "Question:\nSwap Case in a Sentence\n\nYou are to write a function that swaps the case of each letter in a given sentence. If the character is in uppercase, you should convert it to lowercase, and vice versa. Non-alphabetical characters should remain unchanged.\n\n### Function Signature\n\n```pytho... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2143,
"level": 1,
"question": "Swap Case in a Sentence\n\nYou are to write a function that swaps the case of each letter in a given sentence. If the character is in uppercase, you should convert it to lowercase, and vice versa. Non-alphabetical characters should remain unchanged.\n\... |
def sort_users_by_age(users):
return sorted(users, key=lambda x: x[1]) | simplelr_Prefill | [
{
"content": "Question:\nWrite a python function to take a list of tuples that contain user information (name, age, height in cm) and return a list of tuples sorted by age in ascending order.\nAnswer:\nLet's think step by step.\n",
"role": "user"
}
] | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2144,
"level": 1,
"question": "Write a python function to take a list of tuples that contain user information (name, age, height in cm) and return a list of tuples sorted by age in ascending order.",
"split": "train"
} |
def is_palindrome(n):
s = str(n)
return s == s[::-1] | simplelr_Apps | [
{
"content": "Question:\nWrite an algorithm to check if a positive integer is a palindrome.\n\nA number is considered a palindrome when it reads the same backward as forward. For example, 121 is a palindrome while 123 is not.\n\nExample:\n\nInput: 12321\nOutput: true\nExplanation:\nThe number reads the same bac... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2145,
"level": 1,
"question": "Write an algorithm to check if a positive integer is a palindrome.\n\nA number is considered a palindrome when it reads the same backward as forward. For example, 121 is a palindrome while 123 is not.\n\nExample:\n\nInput: 12321\nOutput: true\nExplanat... |
def count_prefix_words(words, prefixes):
count = 0
for word in words:
for prefix in prefixes:
if word.startswith(prefix):
count += 1
break
return count | simplelr_Leetcode | [
{
"content": "Question:\nYou are given a list of strings `words` and a list of prefixes `prefixes`, each element in the list `prefixes` is non-empty. A string is called a **prefix word** if it starts with one of the given prefixes. Return _the number of **prefix words** in the list_ `words`.\nAnswer:\nLet's thi... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2146,
"level": 1,
"question": "You are given a list of strings `words` and a list of prefixes `prefixes`, each element in the list `prefixes` is non-empty. A string is called a **prefix word** if it starts with one of the given prefixes. Return _the number of **prefix words** in the... |
def max_subarray_sum(array):
if not array:
return 0 # Returns 0 for an empty array
max_current = max_global = array[0]
for num in array[1:]:
max_current = max(num, max_current + num)
if max_current > max_global:
max_global = max_current
return max_glob... | simplelr_Prefill | [
{
"content": "Question:\nWrite a function to find the maximum sum of a contiguous subarray in a given one-dimensional array of integers. This is known as Kadane's Algorithm. You should implement this algorithm in a self-contained manner with clear comments.\nAnswer:\nLet's think step by step.\n",
"role": "u... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2147,
"level": 1,
"question": "Write a function to find the maximum sum of a contiguous subarray in a given one-dimensional array of integers. This is known as Kadane's Algorithm. You should implement this algorithm in a self-contained manner with clear comments.",
"split": "train... |
def reverse_bits(num: int) -> int:
binary_str = format(num, '032b')
reversed_str = binary_str[::-1]
return int(reversed_str, 2) | simplelr_Data_Structure | [
{
"content": "Question:\n### Context:\nYou are developing a low-level data compression algorithm where you need to manipulate individual bits of a data sequence efficiently. To do this, you will use bit manipulation functions.\n\n### Task:\nImplement the following function that utilizes bit manipulation to reve... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2148,
"level": 1,
"question": "### Context:\nYou are developing a low-level data compression algorithm where you need to manipulate individual bits of a data sequence efficiently. To do this, you will use bit manipulation functions.\n\n### Task:\nImplement the following function tha... |
def is_palindrome(s: str) -> bool:
cleaned = ''.join([c.lower() for c in s if c.isalnum()])
return cleaned == cleaned[::-1] | simplelr_Filter | [
{
"content": "Question:\nGiven a string s, determine if it is a palindrome. A palindrome is a word, phrase, number, or other sequences of characters that reads the same forward and backward (ignoring spaces, punctuation, and capitalization).\n \nExample 1:\nInput: s = \"A man, a plan, a canal: Panama\"\nOutput:... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2149,
"level": 1,
"question": "Given a string s, determine if it is a palindrome. A palindrome is a word, phrase, number, or other sequences of characters that reads the same forward and backward (ignoring spaces, punctuation, and capitalization).\n \nExample 1:\nInput: s = \"A man,... |
def find_and_sum_even_numbers(number_list):
return sum(num for num in number_list if num % 2 == 0) | simplelr_Filter | [
{
"content": "Question:\ndef find_and_sum_even_numbers(number_list):\n return sum(num for num in number_list if num % 2 == 0)\nAnswer:\nLet's think step by step.\n",
"role": "user"
}
] | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2150,
"level": 1,
"question": "def find_and_sum_even_numbers(number_list):\n return sum(num for num in number_list if num % 2 == 0)",
"split": "train"
} |
from typing import List
def pigeonhole_sort(arr: List[int]) -> List[int]:
if not arr:
return []
if len(arr) == 1:
return arr
min_val = min(arr)
max_val = max(arr)
pigeonhole_size = max_val - min_val + 1
pigeonhole = [0] * pigeonhole_size
for x in arr:
index... | simplelr_Data_Structure | [
{
"content": "Question:\n### Question: Implement and Optimize Pigeonhole Sort\n\n#### Context\nYou are tasked with developing an efficient sorting system for a manufacturing quality control process. The system captures a large number of small integer values representing the defect count in batches of products. ... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2151,
"level": 1,
"question": "### Question: Implement and Optimize Pigeonhole Sort\n\n#### Context\nYou are tasked with developing an efficient sorting system for a manufacturing quality control process. The system captures a large number of small integer values representing the de... |
def min_distance(s, t):
m = len(s)
n = len(t)
dp = [[0] * (n + 1) for _ in range(m + 1)]
for i in range(m + 1):
for j in range(n + 1):
if i == 0:
dp[i][j] = j
elif j == 0:
dp[i][j] = i
else:
cost = 0 if s[i-... | simplelr_Leetcode | [
{
"content": "Question:\nYou are tasked with developing an algorithm to transform an input string `s` into a target string `t` using a minimum number of operations. The only operations you can perform are:\n\n1. Insert a character\n2. Delete a character\n3. Replace a character\n\nBoth the input and target strin... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2152,
"level": 1,
"question": "You are tasked with developing an algorithm to transform an input string `s` into a target string `t` using a minimum number of operations. The only operations you can perform are:\n\n1. Insert a character\n2. Delete a character\n3. Replace a character... |
def factorial(n):
result = 1
for i in range(2, n + 1):
result *= i
return result | simplelr_Filter | [
{
"content": "Question:\nCan you show me an example of a recursive function in Python, that solves a problem that can be solved iteratively, to demonstrate how recursion works?\nAnswer:\nLet's think step by step.\n",
"role": "user"
}
] | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2153,
"level": 1,
"question": "Can you show me an example of a recursive function in Python, that solves a problem that can be solved iteratively, to demonstrate how recursion works?",
"split": "train"
} |
def tribonacci(n: int) -> int:
if n == 0:
return 0
elif n <= 2:
return 1
else:
a, b, c = 0, 1, 1
for i in range(3, n + 1):
next_val = a + b + c
a, b, c = b, c, next_val
return c | simplelr_Algorithm | [
{
"content": "Question:\n**Scenario**: \nYou are tasked with writing a function that computes the nth number in a specific sequence known as the \"Tribonacci sequence\". The exercise will test your understanding of dynamic programming concepts and efficient computation for sequences.\n\n**Problem Statement**: ... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2154,
"level": 1,
"question": "**Scenario**: \nYou are tasked with writing a function that computes the nth number in a specific sequence known as the \"Tribonacci sequence\". The exercise will test your understanding of dynamic programming concepts and efficient computation for se... |
def longestIncreasingSubsequence(arr):
n = len(arr)
if n == 0:
return 0
dp = [1] * n
for i in range(n):
for j in range(i):
if arr[j] < arr[i]:
dp[i] = max(dp[i], dp[j] + 1)
return max(dp)
| simplelr_Taco | [
{
"content": "Question:\nGiven an array of integers, determine the length of the longest sequence of elements that are strictly increasing. The elements of the sequence do not have to be contiguous, but the order must be maintained from the original array.\n\nFor example, given the array \\[10, 22, 9, 33, 21, 5... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2155,
"level": 1,
"question": "Given an array of integers, determine the length of the longest sequence of elements that are strictly increasing. The elements of the sequence do not have to be contiguous, but the order must be maintained from the original array.\n\nFor example, give... |
def is_palindrome(s):
s_lower = s.lower()
return s_lower == s_lower[::-1] | simplelr_Prefill | [
{
"content": "Question:\nCreate a function that checks if a given string is a palindrome under case-insensitive comparison. If the string is a palindrome, return true. If not, return false.\nAnswer:\nLet's think step by step.\n",
"role": "user"
}
] | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2156,
"level": 1,
"question": "Create a function that checks if a given string is a palindrome under case-insensitive comparison. If the string is a palindrome, return true. If not, return false.",
"split": "train"
} |
def first_unique_char(donors: str) -> int:
# Count the occurrences of each character
counts = {}
for c in donors:
if c in counts:
counts[c] += 1
else:
counts[c] = 1
# Find the first character with a count of 1
for index, c in enumerate(donors):
if... | simplelr_Data_Structure | [
{
"content": "Question:\n### Problem Context\nA non-profit organization is trying to identify the most frequent donors who have not donated in the past week. They have a list of donor ids where some ids repeat if a donor has contributed multiple times during that week. They need to identify the first donor who ... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2157,
"level": 1,
"question": "### Problem Context\nA non-profit organization is trying to identify the most frequent donors who have not donated in the past week. They have a list of donor ids where some ids repeat if a donor has contributed multiple times during that week. They ne... |
def generate_monthly_summary(records: list) -> dict:
summary = {}
for category, amount in records:
summary[category] = summary.get(category, 0) + amount
return summary | simplelr_Algorithm | [
{
"content": "Question:\n### Coding Assessment Question\n\n#### Context\nYou are developing a personal finance application that helps users track their monthly expenses. Users enter expenses as individual records, and your application needs to generate a summary report.\n\n#### Task\nImplement a function `gener... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2158,
"level": 1,
"question": "### Coding Assessment Question\n\n#### Context\nYou are developing a personal finance application that helps users track their monthly expenses. Users enter expenses as individual records, and your application needs to generate a summary report.\n\n###... |
def longestSubarray(nums, k):
prefix_sums = {0: -1}
current_sum = 0
max_length = 0
for i, num in enumerate(nums):
current_sum += num
target = current_sum - k
if target in prefix_sums:
length = i - prefix_sums[target]
if length > max_length:
... | simplelr_Evol | [
{
"content": "Question:\nGiven an array of integers `nums`, return the length of the longest contiguous subarray that sums to a given target `k`. The subarray must have at least a length of 1. If no such subarray exists, return `0`.\n\nExample 1:\nInput: nums = [1, -1, 5, -2, 3], k = 3\nOutput: 4\nExplanation: ... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2159,
"level": 1,
"question": "Given an array of integers `nums`, return the length of the longest contiguous subarray that sums to a given target `k`. The subarray must have at least a length of 1. If no such subarray exists, return `0`.\n\nExample 1:\nInput: nums = [1, -1, 5, -2, ... |
def minimum_parts(parts: list, criteria: dict) -> int:
count = 0
required_size = criteria['size']
required_efficiency = criteria['efficiency']
for part in parts:
if part['size'] >= required_size and part['efficiency'] >= required_efficiency:
count += 1
return count | simplelr_Algorithm | [
{
"content": "Question:\n### Problem Statement:\n\nYou are tasked with devising a function that determines the minimum number of interchangeable parts needed for a piece of machinery, given each part's unique specifications. The parts must be matched with given criteria based on size and efficiency.\n\n### Requ... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2160,
"level": 1,
"question": "### Problem Statement:\n\nYou are tasked with devising a function that determines the minimum number of interchangeable parts needed for a piece of machinery, given each part's unique specifications. The parts must be matched with given criteria based ... |
def get_element(array, index):
if index < 0:
return array[0]
elif index >= len(array):
return array[-1]
else:
return array[index] | simplelr_Filter | [
{
"content": "Question:\nI have an array with 3 elements. For example: `[10, 20, 30]`. I want a function that takes an array and an index as input and returns the element at that index, but with a twist: if the index is out of range, it should return the first or last element of the array instead. \n\nFor examp... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2161,
"level": 1,
"question": "I have an array with 3 elements. For example: `[10, 20, 30]`. I want a function that takes an array and an index as input and returns the element at that index, but with a twist: if the index is out of range, it should return the first or last element ... |
def double_list(nums):
return [num * 2 for num in nums] | simplelr_Prefill | [
{
"content": "Question:\nCreate a function that takes a list of numbers and returns the list with each element multiplied by 2. For example, given the list `[1, 2, 3]`, the function should return `[2, 4, 6]`.\nAnswer:\nLet's think step by step.\n",
"role": "user"
}
] | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2162,
"level": 1,
"question": "Create a function that takes a list of numbers and returns the list with each element multiplied by 2. For example, given the list `[1, 2, 3]`, the function should return `[2, 4, 6]`.",
"split": "train"
} |
def search_movies(movies, query):
results = []
if ':' in query:
field_part, value_part = query.split(':', 1)
field = field_part.strip()
value = value_part.strip()
for movie in movies:
found_field = None
for key in movie:
if key.lower() == f... | simplelr_Filter | [
{
"content": "Question:\nI have a list of movies, and for each movie I have extra information (e.g. rating, director etc). I want to create a search function that can search through my movies, but I also want it to be able to search on the extra information.\n\nHere is an example of what my movie list might loo... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2163,
"level": 1,
"question": "I have a list of movies, and for each movie I have extra information (e.g. rating, director etc). I want to create a search function that can search through my movies, but I also want it to be able to search on the extra information.\n\nHere is an exam... |
def max_diff_increasing_subarray(nums):
if len(nums) < 2:
return 0
max_diff = 0
current_max = 0
for i in range(1, len(nums)):
if nums[i] > nums[i-1]:
diff = nums[i] - nums[i-1]
if diff > current_max:
current_max = diff
else:
... | simplelr_Leetcode | [
{
"content": "Question:\nGiven an integer array `nums`, return _the **maximum difference** between the increasing adjacent elements in a subarray where the elements are in strictly increasing order._ If the array is already in strictly increasing order, return the maximum difference between its adjacent element... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2164,
"level": 1,
"question": "Given an integer array `nums`, return _the **maximum difference** between the increasing adjacent elements in a subarray where the elements are in strictly increasing order._ If the array is already in strictly increasing order, return the maximum diff... |
def count_less_than_zero(lst):
return sum(x < 0 for x in lst) | simplelr_Filter | [
{
"content": "Question:\nDefine a method `count_less_than_zero` in Python that calculates the number of elements in a list that are less than zero. This method should take a list of integers as its argument and return the count of integers less than zero.\nAnswer:\nLet's think step by step.\n",
"role": "use... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2165,
"level": 1,
"question": "Define a method `count_less_than_zero` in Python that calculates the number of elements in a list that are less than zero. This method should take a list of integers as its argument and return the count of integers less than zero.",
"split": "train"
... |
def final_position(commands: list) -> tuple:
x, y = 0, 0
for cmd in commands:
direction, distance_str = cmd.split()
distance = int(distance_str)
if direction == "UP":
y += distance
elif direction == "DOWN":
y -= distance
elif direction == "LEFT":
... | simplelr_Package | [
{
"content": "Question:\nYour task is to write a Python function called `final_position` that calculates the final position of a point after a series of movements in a 2D plane. Each movement is represented by a command in a string format, and all movements start from the origin point (0, 0).\n\nThe function sh... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2166,
"level": 1,
"question": "Your task is to write a Python function called `final_position` that calculates the final position of a point after a series of movements in a 2D plane. Each movement is represented by a command in a string format, and all movements start from the orig... |
def multiply_matrices(A, B):
# Get the dimensions of the matrices
num_rows_A = len(A)
num_cols_A = len(A[0])
num_cols_B = len(B[0])
# Initialize the result matrix with zeros
result = [[0 for _ in range(num_cols_B)] for _ in range(num_rows_A)]
# Perform matrix multiplication
for... | simplelr_Prefill | [
{
"content": "Question:\nWrite a python function to multiply two matrices A and B, where A is a 2D list (list of lists) and B is also a 2D list. Assume that the multiplication is valid (i.e., the number of columns in A is equal to the number of rows in B). The function should return the resulting matrix as a 2D... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2167,
"level": 1,
"question": "Write a python function to multiply two matrices A and B, where A is a 2D list (list of lists) and B is also a 2D list. Assume that the multiplication is valid (i.e., the number of columns in A is equal to the number of rows in B). The function should ... |
def move_evens_to_front(arr):
evens = []
odds = []
for num in arr:
if num % 2 == 0:
evens.append(num)
else:
odds.append(num)
return evens + odds | simplelr_Apps | [
{
"content": "Question:\nYou are given an array of integers. Your task is to create a function that moves all the even integers to the beginning of the array, followed by all the odd integers, while preserving the relative order of the even and odd integers.\n\nFor example:\n```python\nmove_evens_to_front([3, 1... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2168,
"level": 1,
"question": "You are given an array of integers. Your task is to create a function that moves all the even integers to the beginning of the array, followed by all the odd integers, while preserving the relative order of the even and odd integers.\n\nFor example:\n`... |
def sum_of_integers(n):
if n <= 0:
return 0
return n * (n + 1) // 2 | simplelr_Filter | [
{
"content": "Question:\nQwen, how can I write a Python function that calculates the sum of all integers from 1 to a given number `n`?\nAnswer:\nLet's think step by step.\n",
"role": "user"
}
] | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2169,
"level": 1,
"question": "Qwen, how can I write a Python function that calculates the sum of all integers from 1 to a given number `n`?",
"split": "train"
} |
def letter_frequency(s):
freq = {}
for char in s:
char_lower = char.lower()
if char_lower.isalpha():
if char_lower in freq:
freq[char_lower] += 1
else:
freq[char_lower] = 1
return freq
# Example usage:
input_string = "Hello, World!"
pr... | simplelr_Filter | [
{
"content": "Question:\nWrite a Python code to create a dictionary that contains the frequency of occurrence of each letter in a given string.\nAnswer:\nLet's think step by step.\n",
"role": "user"
}
] | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2170,
"level": 1,
"question": "Write a Python code to create a dictionary that contains the frequency of occurrence of each letter in a given string.",
"split": "train"
} |
from typing import List
def rank_scores(scores: List[int], target: int) -> int:
# Check if scores is a list
if not isinstance(scores, list):
raise TypeError("'scores' should be a list of integers")
# Check if all elements in scores are integers
for s in scores:
if not isinstance(s, int)... | simplelr_Algorithm | [
{
"content": "Question:\n### Coding Assessment Question\n\n**Context:**\nYou are developing a utility module for managing game scores. One of the functionalities required is to compute the rank of a particular score in a list of scores. The rank should be determined based on the highest scores, with 1 being the... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2171,
"level": 1,
"question": "### Coding Assessment Question\n\n**Context:**\nYou are developing a utility module for managing game scores. One of the functionalities required is to compute the rank of a particular score in a list of scores. The rank should be determined based on t... |
import bisect
def longest_increasing_subsequence(nums):
tails = []
for num in nums:
idx = bisect.bisect_left(tails, num)
if idx == len(tails):
tails.append(num)
else:
tails[idx] = num
return len(tails) | simplelr_Prefill | [
{
"content": "Question:\nWrite a function to find the longest increasing subsequence in an array of integers. The function should return the length of the longest subsequence. A subsequence is considered increasing if each element is greater than the previous element. For example, given the array [10, 9, 2, 5, ... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2172,
"level": 1,
"question": "Write a function to find the longest increasing subsequence in an array of integers. The function should return the length of the longest subsequence. A subsequence is considered increasing if each element is greater than the previous element. For exam... |
from collections import deque
from typing import List, Tuple
def is_path_exists(vertex_count: int, edges: List[Tuple[int, int]], source: int, target: int) -> bool:
if source == target:
return True
# Create adjacency list
adj = [[] for _ in range(vertex_count)]
for u, v in edges:
adj[u]... | simplelr_Data_Structure | [
{
"content": "Question:\n### Question: Path Existence in a Directed Graph\n\nYou are provided with a directed graph of `V` vertices. Your task is to write a function that determines whether there exists a path between two given nodes in this graph.\n\n#### Function Signature:\n```python\ndef is_path_exists(vert... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2173,
"level": 1,
"question": "### Question: Path Existence in a Directed Graph\n\nYou are provided with a directed graph of `V` vertices. Your task is to write a function that determines whether there exists a path between two given nodes in this graph.\n\n#### Function Signature:\... |
def chairs_needed(n):
return (n // 8, n % 8)
| simplelr_Taco | [
{
"content": "Question:\nYou are organizing an outdoor concert and need to set up a number of chairs for the audience. Each row can only have exactly 8 chairs for uniformity, and any chairs that cannot fill a full row should be stored for future use.\n\nYou are given the total number of chairs `n` and you need ... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2174,
"level": 1,
"question": "You are organizing an outdoor concert and need to set up a number of chairs for the audience. Each row can only have exactly 8 chairs for uniformity, and any chairs that cannot fill a full row should be stored for future use.\n\nYou are given the total... |
def quick_sort(arr):
"""
Sorts an array of integers in ascending order using the Quick Sort algorithm.
Parameters:
arr (list): A list of integers
Returns:
list: A sorted list of integers
"""
if len(arr) <= 1:
return arr
pivot = arr[len(arr) // 2]
left = [x for x in arr ... | simplelr_Data_Structure | [
{
"content": "Question:\nYou are tasked with implementing an improved sorting algorithm to replace a slow sorting process in a legacy system. While considering the limitations and characteristics of the Exchange Sort, your goal is to develop a more efficient algorithm. The requirements are that the algorithm mu... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2175,
"level": 1,
"question": "You are tasked with implementing an improved sorting algorithm to replace a slow sorting process in a legacy system. While considering the limitations and characteristics of the Exchange Sort, your goal is to develop a more efficient algorithm. The req... |
def stutter_in_place(stack):
n = len(stack)
stack += [0] * n # Extend the list to twice its original length
for i in range(n - 1, -1, -1):
stack[2 * i + 1] = stack[i]
stack[2 * i] = stack[i] | simplelr_Data_Structure | [
{
"content": "Question:\n### Scenario\n\nYou are tasked with writing a function that duplicates every value in a given stack but must optimize the function to avoid using additional space for storage (i.e., in-place duplication).\n\n### Problem Statement\n\nImplement the function `stutter_in_place(stack)` that ... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2176,
"level": 1,
"question": "### Scenario\n\nYou are tasked with writing a function that duplicates every value in a given stack but must optimize the function to avoid using additional space for storage (i.e., in-place duplication).\n\n### Problem Statement\n\nImplement the funct... |
import math
def product_of_first_n_odds(n):
return math.factorial(2 * n) // (2 ** n * math.factorial(n)) | simplelr_Prefill | [
{
"content": "Question:\nWrite a function to find the product of the first n odd numbers.\nAnswer:\nLet's think step by step.\n",
"role": "user"
}
] | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2177,
"level": 1,
"question": "Write a function to find the product of the first n odd numbers.",
"split": "train"
} |
def format_date(date_str):
day, month, year = date_str.split('-')
return f"{day}/{month}/{year}" | simplelr_Filter | [
{
"content": "Question:\nPlease write a code snippet to format a date in \"DD/MM/YYYY\" format. The input date will always be in the format \"DD-MM-YYYY\". You are not allowed to use any built-in date formatting functions or libraries.\nAnswer:\nLet's think step by step.\n",
"role": "user"
}
] | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2178,
"level": 1,
"question": "Please write a code snippet to format a date in \"DD/MM/YYYY\" format. The input date will always be in the format \"DD-MM-YYYY\". You are not allowed to use any built-in date formatting functions or libraries.",
"split": "train"
} |
import math
def calculate_distance(point1, point2):
dx = point2[0] - point1[0]
dy = point2[1] - point1[1]
return math.sqrt(dx**2 + dy**2) | simplelr_Filter | [
{
"content": "Question:\nI'm new to programming. I'm trying to write a function in Python that calculates the distance between two points. The points are represented as tuples.\n\nI understand the Euclidean distance formula:\n\n√((x2 - x1)² + (y2 - y1)²)\n\nI'm not sure how to implement this formula in Python c... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2179,
"level": 1,
"question": "I'm new to programming. I'm trying to write a function in Python that calculates the distance between two points. The points are represented as tuples.\n\nI understand the Euclidean distance formula:\n\n√((x2 - x1)² + (y2 - y1)²)\n\nI'm not sure how to... |
def findPeakElement(arr, N):
low = 0
high = N - 1
while low < high:
mid = (low + high) // 2
if arr[mid] < arr[mid + 1]:
low = mid + 1
else:
high = mid
return low
| simplelr_Taco | [
{
"content": "Question:\nGiven an array of N distinct integers, find a peak element. A peak element is an element that is greater than its neighbors. If the array contains multiple peaks, return the index of any one of them.\n\nExample 1:\nInput:\narr = {1, 3, 20, 4, 1, 0}\nOutput: 2\nExplanation: 20 is a peak ... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2180,
"level": 1,
"question": "Given an array of N distinct integers, find a peak element. A peak element is an element that is greater than its neighbors. If the array contains multiple peaks, return the index of any one of them.\n\nExample 1:\nInput:\narr = {1, 3, 20, 4, 1, 0}\nOu... |
def count_words(s):
return len(s.split()) | simplelr_Prefill | [
{
"content": "Question:\nWrite a function to count the number of words in a string. Assume that words are separated by spaces.\nAnswer:\nLet's think step by step.\n",
"role": "user"
}
] | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2181,
"level": 1,
"question": "Write a function to count the number of words in a string. Assume that words are separated by spaces.",
"split": "train"
} |
from collections import deque
def countHierarchyLevels(n, relations):
# Step 1: Find the root
y_set = set()
for x, y in relations:
y_set.add(y)
root = -1
for i in range(1, n+1):
if i not in y_set:
root = i
break
# Step 2: Build adjacency list
adj... | simplelr_Taco | [
{
"content": "Question:\nIn a company’s HR system, each employee is represented by an employee ID number. Additionally, every employee except the highest-ranking one has a manager who is also an employee, identified by their own employee ID. The company's structure forms a hierarchy similar to a tree, where eac... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2182,
"level": 1,
"question": "In a company’s HR system, each employee is represented by an employee ID number. Additionally, every employee except the highest-ranking one has a manager who is also an employee, identified by their own employee ID. The company's structure forms a hie... |
import re
from typing import List, Tuple
def extract_and_filter_comments(text: str, keywords: List[str]) -> List[Tuple[str, str, str]]:
result = []
# Regex pattern to capture username, date, and comment
pattern = r'username:\s*(.*?)(?=,\s*date:\s*\d{4}-\d{2}-\d{2}),\s*date:\s*(\d{4}-\d{2}-\d{2}),\s*comment... | simplelr_Docs | [
{
"content": "Question:\n### **Pattern Matching and Data Extraction using Regular Expressions**\n\nYou are given a series of text entries from a blog comment section. Each entry contains the username of the commenter, the date of the comment, and the content of the comment itself. For example:\n\n```\nusername:... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2183,
"level": 1,
"question": "### **Pattern Matching and Data Extraction using Regular Expressions**\n\nYou are given a series of text entries from a blog comment section. Each entry contains the username of the commenter, the date of the comment, and the content of the comment its... |
from typing import List
def spiral_order(matrix: List[List[int]]) -> List[int]:
if not matrix:
return []
res = []
top = 0
bottom = len(matrix) - 1
left = 0
right = len(matrix[0]) - 1
while top <= bottom and left <= right:
# Traverse from left to right on the top ro... | simplelr_Apps | [
{
"content": "Question:\nMatrix Spiral\n\nWrite a function that takes an n x n matrix (a list of lists) of integers and returns a list of integers representing the spiral order of the matrix.\n\nThe spiral order starts from the top-left corner of the matrix and proceeds to the right. When the end of a row is re... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2184,
"level": 1,
"question": "Matrix Spiral\n\nWrite a function that takes an n x n matrix (a list of lists) of integers and returns a list of integers representing the spiral order of the matrix.\n\nThe spiral order starts from the top-left corner of the matrix and proceeds to the... |
def power_of_threes(n):
if n <= 0:
return []
return [3 ** i for i in range(n)] | simplelr_Evol | [
{
"content": "Question:\nCreate a function `power_of_threes` that takes an integer `n` as input and returns a list of the first `n` powers of 3 in ascending order. Ensure the function is optimized for performance and takes into account edge cases such as `n` being 0 or negative.\n\nFor example:\npower_of_threes... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2185,
"level": 1,
"question": "Create a function `power_of_threes` that takes an integer `n` as input and returns a list of the first `n` powers of 3 in ascending order. Ensure the function is optimized for performance and takes into account edge cases such as `n` being 0 or negativ... |
from typing import List
def max_product_subarray(nums: List[int]) -> int:
if not nums:
return 0 # According to constraints, this case won't occur as len(nums) >=1
current_max = current_min = global_max = nums[0]
for num in nums[1:]:
candidate1 = current_max * num
candidat... | simplelr_Taco | [
{
"content": "Question:\n### Maximum Product Subarray\n\nGiven an array of integers, you need to find the contiguous subarray within the array that has the largest product.\n\n### Function Signature\n```python\ndef max_product_subarray(nums: List[int]) -> int:\n```\n\n### Input\n- A list of integers `nums` with... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2186,
"level": 1,
"question": "### Maximum Product Subarray\n\nGiven an array of integers, you need to find the contiguous subarray within the array that has the largest product.\n\n### Function Signature\n```python\ndef max_product_subarray(nums: List[int]) -> int:\n```\n\n### Inpu... |
def pascal_row(n):
row = [1]
for k in range(1, n + 1):
next_element = row[k - 1] * (n - k + 1) // k
row.append(next_element)
return row | simplelr_Apps | [
{
"content": "Question:\n## Pascal's Triangle Row Calculation\n\n## Input\n\nA single integer:\n```\n0 ≤ n ≤ 34\n```\n\n## Output\n\nA list of integers representing the nth row of Pascal's Triangle.\n\n## Description\n\nPascal's Triangle is a triangular array of numbers, where the numbers at the boundary of the... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2187,
"level": 1,
"question": "## Pascal's Triangle Row Calculation\n\n## Input\n\nA single integer:\n```\n0 ≤ n ≤ 34\n```\n\n## Output\n\nA list of integers representing the nth row of Pascal's Triangle.\n\n## Description\n\nPascal's Triangle is a triangular array of numbers, where... |
def remove_duplicate_events(events: list[int]) -> list[int]:
seen = set()
result = []
for event in events:
if event not in seen:
seen.add(event)
result.append(event)
return result | simplelr_Algorithm | [
{
"content": "Question:\n### Coding Assessment Question\n\n#### Problem Description:\nYou are working on a system that processes video streams from security cameras. Each stream captures a sequence of events, where each event is represented by a unique integer. Your task is to remove any duplicate events from t... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2188,
"level": 1,
"question": "### Coding Assessment Question\n\n#### Problem Description:\nYou are working on a system that processes video streams from security cameras. Each stream captures a sequence of events, where each event is represented by a unique integer. Your task is to... |
def can_win_game(n):
return n % 4 != 0 | simplelr_Apps | [
{
"content": "Question:\nA group of friends went on a hiking trip and decided to play a game to pass their time. They brought a large bag of stones with them. The rules of the game are simple:\n\n1. Each player, in their turn, can pick 1, 2, or 3 stones from the bag.\n2. The player who picks the last stone wins... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2189,
"level": 1,
"question": "A group of friends went on a hiking trip and decided to play a game to pass their time. They brought a large bag of stones with them. The rules of the game are simple:\n\n1. Each player, in their turn, can pick 1, 2, or 3 stones from the bag.\n2. The p... |
def closest_point(points):
closest = points[0]
min_dist_sq = closest[0]**2 + closest[1]**2
for point in points[1:]:
x, y = point
current_dist_sq = x**2 + y**2
if current_dist_sq < min_dist_sq:
min_dist_sq = current_dist_sq
closest = point
return closest
| simplelr_Taco | [
{
"content": "Question:\nWrite a function that takes a list of tuples representing 2D points on a plane, and returns the tuple that is closest to the origin (0,0).\n\n##### Inputs:\nA list of tuples `points`, where each tuple contains two integers representing the x and y coordinates of a point on the plane. Th... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2190,
"level": 1,
"question": "Write a function that takes a list of tuples representing 2D points on a plane, and returns the tuple that is closest to the origin (0,0).\n\n##### Inputs:\nA list of tuples `points`, where each tuple contains two integers representing the x and y coor... |
def update_inventory(inventory, action, item, quantity):
if action == "add":
if item in inventory:
inventory[item] += quantity
else:
inventory[item] = quantity
elif action == "remove":
available = inventory.get(item, 0)
if quantity > available:
... | simplelr_Package | [
{
"content": "Question:\nYou are required to write a function to manage the state of a simplified inventory system for a game. The function you will write, `update_inventory`, will handle adding items, removing items, and checking the inventory for items' availability.\n\nThe requirements are as follows:\n\n1. ... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2191,
"level": 1,
"question": "You are required to write a function to manage the state of a simplified inventory system for a game. The function you will write, `update_inventory`, will handle adding items, removing items, and checking the inventory for items' availability.\n\nThe ... |
def find_insertion_index(arr: list[int], target: int) -> int:
low = 0
high = len(arr)
while low < high:
mid = (low + high) // 2
if arr[mid] < target:
low = mid + 1
else:
high = mid
return low | simplelr_Data_Structure | [
{
"content": "Question:\n### Binary Search Insertion Index\n\n**Problem Statement**:\nGiven a sorted array of integers `arr` and a target integer `target`, your task is to write a function `find_insertion_index` that finds and returns the index where the target should be inserted to maintain the array's sorted ... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2192,
"level": 1,
"question": "### Binary Search Insertion Index\n\n**Problem Statement**:\nGiven a sorted array of integers `arr` and a target integer `target`, your task is to write a function `find_insertion_index` that finds and returns the index where the target should be inser... |
def check_string(s):
has_digit = False
has_vowel = False
for char in s:
if char.isdigit():
has_digit = True
elif char.lower() in 'aeiou':
has_vowel = True
return has_digit and has_vowel | simplelr_Filter | [
{
"content": "Question:\nHere is a problem I need help with. \n\nGiven a string, check if it contains at least one vowel and at least one digit.\n*/\n\nExample: \n Input: \"a1b2c3\"\n Output: \"True\"\n \n Input: \"test123\"\n Output: \"True\"\n \n Input: \"alles\"\n Output: \"False\"\n ... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2193,
"level": 1,
"question": "Here is a problem I need help with. \n\nGiven a string, check if it contains at least one vowel and at least one digit.\n*/\n\nExample: \n Input: \"a1b2c3\"\n Output: \"True\"\n \n Input: \"test123\"\n Output: \"True\"\n \n Input: ... |
def reverse_words(sentence):
return ' '.join(sentence.split()[::-1]) | simplelr_Prefill | [
{
"content": "Question:\nWrite a function to reverse the order of words in a given sentence. For example, if the input is \"hello world\", the output should be \"world hello\". You should consider preserving the original order of the characters within each word.\nAnswer:\nLet's think step by step.\n",
"role... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2194,
"level": 1,
"question": "Write a function to reverse the order of words in a given sentence. For example, if the input is \"hello world\", the output should be \"world hello\". You should consider preserving the original order of the characters within each word.",
"split": "... |
def can_form_palindrome(s):
# Preprocess the string to include only alphanumeric characters in lowercase
processed = [c.lower() for c in s if c.isalnum()]
# Count the frequency of each character
char_count = {}
for c in processed:
char_count[c] = char_count.get(c, 0) + 1
# Count the numb... | simplelr_Leetcode | [
{
"content": "Question:\nDetermine if a given string can be rearranged to form a palindrome. A palindrome is a word, phrase, number, or other sequence of characters that reads the same forward and backward (ignoring spaces, punctuation, and capitalization). **Example:** * \"A man a plan a canal Panama\" can be ... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2195,
"level": 1,
"question": "Determine if a given string can be rearranged to form a palindrome. A palindrome is a word, phrase, number, or other sequence of characters that reads the same forward and backward (ignoring spaces, punctuation, and capitalization). **Example:** * \"A ... |
import zlib
from typing import List
def compress_and_check_integrity(data_list: List[str], compression_level: int = -1) -> bool:
try:
# Combine the list of strings into a single string and encode to bytes
combined_str = ''.join(data_list)
original_data = combined_str.encode('utf-8')
... | simplelr_Docs | [
{
"content": "Question:\n**Objective**: Assess students' ability to work with the `zlib` module for compression and decompression tasks.\n\n**Problem Statement**:\nWrite a Python function `compress_and_check_integrity` that takes a list of strings, compresses them using the `zlib` module, and then verifies the ... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2196,
"level": 1,
"question": "**Objective**: Assess students' ability to work with the `zlib` module for compression and decompression tasks.\n\n**Problem Statement**:\nWrite a Python function `compress_and_check_integrity` that takes a list of strings, compresses them using the `z... |
def moving_average(sequence: list[float], window_size: int) -> list[float]:
n = len(sequence) - window_size + 1
averages = []
for i in range(n):
current_window = sequence[i:i + window_size]
avg = sum(current_window) / window_size
averages.append(avg)
return averages | simplelr_Algorithm | [
{
"content": "Question:\n### Scenario\nIn a streaming data analysis workshop, you are asked to create a function to compute the moving average of a sequence of numbers. You have observed that understanding moving averages is crucial for data smoothing and trend identification.\n\n### Task\nWrite a function `mov... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2197,
"level": 1,
"question": "### Scenario\nIn a streaming data analysis workshop, you are asked to create a function to compute the moving average of a sequence of numbers. You have observed that understanding moving averages is crucial for data smoothing and trend identification.... |
def isBackToOrigin(moves: str) -> bool:
x = 0
y = 0
for move in moves:
if move == 'U':
y += 1
elif move == 'D':
y -= 1
elif move == 'R':
x += 1
elif move == 'L':
x -= 1
return x == 0 and y == 0
| simplelr_Taco | [
{
"content": "Question:\nYou are given a string that represents a sequence of moves on an infinite grid. The moves are represented by characters:\n\n- 'U' means move one step up.\n- 'D' means move one step down.\n- 'L' means move one step left.\n- 'R' means move one step right.\n\nThe string of moves will start... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2198,
"level": 1,
"question": "You are given a string that represents a sequence of moves on an infinite grid. The moves are represented by characters:\n\n- 'U' means move one step up.\n- 'D' means move one step down.\n- 'L' means move one step left.\n- 'R' means move one step right... |
def calculate_average_temperature(temperatures):
if not temperatures:
return 0
return sum(temperatures) / len(temperatures) | simplelr_Filter | [
{
"content": "Question:\nWrite a Python function named `calculate_average_temperature` that takes a list of daily temperatures as input and returns the average temperature for the week. If the list is empty, the function should return 0. Assume the list contains valid temperature readings (float or integer valu... | code | {
"ground_truth": "pass",
"style": "exec"
} | {
"answer": "pass",
"index": 2199,
"level": 1,
"question": "Write a Python function named `calculate_average_temperature` that takes a list of daily temperatures as input and returns the average temperature for the week. If the list is empty, the function should return 0. Assume the list contains valid temperat... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.