target
stringlengths
29
3.65k
data_source
stringclasses
12 values
prompt
listlengths
1
1
ability
stringclasses
1 value
reward_model
dict
extra_info
dict
from collections import Counter def second_most_frequent(numbers): if len(set(numbers)) < 2: return None count = Counter(numbers) freq_list = sorted(count.values(), reverse=True) target_freq = freq_list[1] candidates = [num for num, freq in count.items() if freq == target_freq] return m...
simplelr_Evol
[ { "content": "Question:\nWrite a Python function that takes a list of integers and returns the second most frequent element in the list. If there is a tie for the second most frequent element, return the smallest one. If there are less than two distinct elements, return None. Below is an example of how the func...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7200, "level": 1, "question": "Write a Python function that takes a list of integers and returns the second most frequent element in the list. If there is a tie for the second most frequent element, return the smallest one. If there are less than two distinct elements, return None. ...
def remove_vowels(s): vowels = {'a', 'e', 'i', 'o', 'u'} new_str = ''.join([c for c in s if c.lower() not in vowels]) count = len(s) - len(new_str) return (new_str, count)
simplelr_Evol
[ { "content": "Question:\nWrite a Python function that takes a string as input and returns a new string with all the vowels removed. Additionally, your function should count and return the number of vowels that were removed.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7201, "level": 1, "question": "Write a Python function that takes a string as input and returns a new string with all the vowels removed. Additionally, your function should count and return the number of vowels that were removed.", "split": "train" }
def two_sum(nums, target): seen = {} for i, num in enumerate(nums): complement = target - num if complement in seen: return [seen[complement], i] seen[num] = i return []
simplelr_Codeforces
[ { "content": "Question:\nGiven an integer array nums and an integer target, return indices of the two numbers such that they add up to the target. You may assume that each input would have exactly one solution, and you may not use the same element twice.\n\nYou can return the answer in any order.\n\nExample:\n\...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7202, "level": 1, "question": "Given an integer array nums and an integer target, return indices of the two numbers such that they add up to the target. You may assume that each input would have exactly one solution, and you may not use the same element twice.\n\nYou can return the ...
def move_robot(commands): x, y = 0, 0 direction_map = { 'N': (0, 1), 'S': (0, -1), 'E': (1, 0), 'W': (-1, 0) } for cmd in commands: dx, dy = direction_map[cmd] x += dx y += dy return (x, y) # Example usage: # commands = "NW" # print(robot_posi...
simplelr_Filter
[ { "content": "Question:\nDesign a Python program that simulates the movement of a robot in a 2D grid. The robot starts at position (0, 0) and can receive a series of commands to move in the four cardinal directions: North, South, East, and West. The grid is unbounded, and the robot can move indefinitely in any ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7203, "level": 1, "question": "Design a Python program that simulates the movement of a robot in a 2D grid. The robot starts at position (0, 0) and can receive a series of commands to move in the four cardinal directions: North, South, East, and West. The grid is unbounded, and the ...
def longestPrefixSuffix(s: str) -> int: n = len(s) for m in range(n-1, 0, -1): prefix = s[:m] suffix = s[-m:] i = j = 0 while i < len(prefix) and j < len(suffix): if prefix[i] == suffix[j]: i += 1 j += 1 if i == len(prefix): ...
simplelr_Taco
[ { "content": "Question:\nGiven a string consisting of lowercase and uppercase alphabets, output the length of the longest subsequence that can be found both as a prefix and as a suffix in the given string. Note that the subsequence does not need to be contiguous.\n\nImplement the function `longestPrefixSuffix(s...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7204, "level": 1, "question": "Given a string consisting of lowercase and uppercase alphabets, output the length of the longest subsequence that can be found both as a prefix and as a suffix in the given string. Note that the subsequence does not need to be contiguous.\n\nImplement ...
def unique_paths(x, y): k = min(x, y) result = 1 for i in range(1, k + 1): result = result * (x + y - k + i) // i return result
simplelr_Leetcode
[ { "content": "Question:\nYou are given two integers `x` and `y`, representing the coordinates of a point on a 2D graph. Write a function that determines the number of unique paths from the origin `(0, 0)` to the point `(x, y)` if you can only move either right or up at each step. Each path consists of exactly `...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7205, "level": 1, "question": "You are given two integers `x` and `y`, representing the coordinates of a point on a 2D graph. Write a function that determines the number of unique paths from the origin `(0, 0)` to the point `(x, y)` if you can only move either right or up at each st...
def insert_interval(intervals, newInterval): # Combine the original intervals with the new interval all_intervals = intervals.copy() all_intervals.append(newInterval) # Sort intervals based on the start of each interval all_intervals.sort(key=lambda x: x[0]) # Merge the intervals m...
simplelr_Leetcode
[ { "content": "Question:\nYou are given an array `intervals` where `intervals[i] = [start_i, end_i]` represents the start and end of the `i-th` interval. The intervals are disjoint and in sorted order. Insert a new interval `newInterval = [start, end]` into `intervals`, merging overlapping intervals if necessary...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7206, "level": 1, "question": "You are given an array `intervals` where `intervals[i] = [start_i, end_i]` represents the start and end of the `i-th` interval. The intervals are disjoint and in sorted order. Insert a new interval `newInterval = [start, end]` into `intervals`, merging...
import re def is_match(string, pattern): return re.fullmatch(pattern, string) is not None
simplelr_Filter
[ { "content": "Question:\nHow can I implement a Python function to check if a string matches a given pattern using regular expressions?\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7207, "level": 1, "question": "How can I implement a Python function to check if a string matches a given pattern using regular expressions?", "split": "train" }
from collections import Counter def can_construct_words(word_list, char_list): count = 0 for word in word_list: for char_str in char_list: word_counter = Counter(word) char_counter = Counter(char_str) can_form = True for char, required in word_counter.ite...
simplelr_Evol
[ { "content": "Question:\nWrite a Python function that takes a list of strings and returns the number of strings that can be constructed using the characters of another list of strings. Each character in the second list of strings may only be used once per string formation. If a string cannot be completely const...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7208, "level": 1, "question": "Write a Python function that takes a list of strings and returns the number of strings that can be constructed using the characters of another list of strings. Each character in the second list of strings may only be used once per string formation. If ...
def string_lengths(strings, min_length=0): result = {} for s in strings: if len(s) >= min_length: result[s] = len(s) return result
simplelr_Evol
[ { "content": "Question:\nWrite a function that accepts a list of strings and returns a dictionary where the keys are the strings and the values are the lengths of those strings. The function should have an optional keyword argument `min_length` which filters out strings shorter than the specified length (defaul...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7209, "level": 1, "question": "Write a function that accepts a list of strings and returns a dictionary where the keys are the strings and the values are the lengths of those strings. The function should have an optional keyword argument `min_length` which filters out strings shorte...
import numpy as np def create_mask(tensor): """ This function takes a 3D tensor as input and returns a mask tensor where non-zero elements are 1 and zeros remain 0. Args: tensor (numpy.ndarray): A 3D tensor of shape (batch_size, num_sequences, sequence_length). Returns: numpy....
simplelr_Filter
[ { "content": "Question:\nImplement a function in Python that takes a 3D tensor as input and returns a mask tensor where the elements corresponding to non-zero values in the input tensor are 1, and 0 otherwise. The input tensor has a shape of (batch_size, num_sequences, sequence_length). The output tensor should...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7210, "level": 1, "question": "Implement a function in Python that takes a 3D tensor as input and returns a mask tensor where the elements corresponding to non-zero values in the input tensor are 1, and 0 otherwise. The input tensor has a shape of (batch_size, num_sequences, sequenc...
def rotate_matrix(matrix): n = len(matrix) # Transpose the matrix for i in range(n): for j in range(i + 1, n): matrix[j][i], matrix[i][j] = matrix[i][j], matrix[j][i] # Reverse each row to complete the rotation for row in matrix: row.reverse()
simplelr_Package
[ { "content": "Question:\nYou are tasked with creating a function that rotates a given square matrix by 90 degrees in a clockwise direction. The function should modify the matrix in-place and should not return anything. The matrix will be given as a list of lists, where each element is a row of the matrix.\n\nTh...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7211, "level": 1, "question": "You are tasked with creating a function that rotates a given square matrix by 90 degrees in a clockwise direction. The function should modify the matrix in-place and should not return anything. The matrix will be given as a list of lists, where each el...
def print_square(num): print(num ** 2)
simplelr_Prefill
[ { "content": "Question:\nCreate a function that takes an integer as an argument and prints the square of that number.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7212, "level": 1, "question": "Create a function that takes an integer as an argument and prints the square of that number.", "split": "train" }
import math from collections import Counter def sum_of_unique_permutations(nums): counts = Counter(nums) sum_digits = sum(nums) n = len(nums) if n == 0: return 0 numerator = math.factorial(n) denominator = 1 for d in counts: denominator *= math.factorial(counts[d]) T = n...
simplelr_Leetcode
[ { "content": "Question:\nGiven an integer array `nums`, return _the sum of all the **unique permutations** of its elements_. A **permutation** of an array is any possible ordering of its elements. Two permutations are considered unique if they have different element orderings (regardless of possible repeated el...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7213, "level": 1, "question": "Given an integer array `nums`, return _the sum of all the **unique permutations** of its elements_. A **permutation** of an array is any possible ordering of its elements. Two permutations are considered unique if they have different element orderings ...
def is_identity_matrix(matrix): n = len(matrix) # Check if the matrix is square for row in matrix: if len(row) != n: return False # Check each element for i in range(n): if matrix[i][i] != 1: return False for j in range(n): if j !...
simplelr_Taco
[ { "content": "Question:\nIn this Kata, you must implement a function to check if a given matrix is an identity matrix. An identity matrix is a square one with '1's on the main diagonal and '0's elsewhere. The given matrix will always be square.\n\n```python\nis_identity_matrix([[1, 0, 0], [0, 1, 0], [0, 0, 1]])...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7214, "level": 1, "question": "In this Kata, you must implement a function to check if a given matrix is an identity matrix. An identity matrix is a square one with '1's on the main diagonal and '0's elsewhere. The given matrix will always be square.\n\n```python\nis_identity_matrix...
def get_index(my_list, my_element): for index, element in enumerate(my_list): if element == my_element: return index return -1
simplelr_Filter
[ { "content": "Question:\nYou've been tasked with writing a function `get_index` that takes two parameters: `my_list` and `my_element`. Your function should return the index of the first occurrence of `my_element` in the list `my_list`.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7215, "level": 1, "question": "You've been tasked with writing a function `get_index` that takes two parameters: `my_list` and `my_element`. Your function should return the index of the first occurrence of `my_element` in the list `my_list`.", "split": "train" }
from datetime import datetime, timedelta def date_range(start_date, end_date): """ Generates a list of datetime objects for each day in a date range, inclusive. Args: start_date: A datetime object representing the start date. end_date: A datetime object representing the end date. ...
simplelr_Filter
[ { "content": "Question:\nThe code that makes this work is:\n\n```python\nfrom datetime import datetime, timedelta\n\ndef date_range(start_date, end_date):\n \"\"\"\n Generates a list of datetime objects for each day in a date range, inclusive.\n args: \n start_date: datetime object representing ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7216, "level": 1, "question": "The code that makes this work is:\n\n```python\nfrom datetime import datetime, timedelta\n\ndef date_range(start_date, end_date):\n \"\"\"\n Generates a list of datetime objects for each day in a date range, inclusive.\n args: \n start_...
def generate_pascals_triangle(n): if n <= 0: return [] result = [[1]] for i in range(1, n): prev_row = result[i-1] middle = [prev_row[j] + prev_row[j+1] for j in range(len(prev_row)-1)] new_row = [1] + middle + [1] result.append(new_row) return result
simplelr_Leetcode
[ { "content": "Question:\nWrite a function that accepts a positive integer `n` and returns an array representing the first `n` rows of Pascal's Triangle. In Pascal's Triangle, each number is the sum of the two numbers directly above it.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7217, "level": 1, "question": "Write a function that accepts a positive integer `n` and returns an array representing the first `n` rows of Pascal's Triangle. In Pascal's Triangle, each number is the sum of the two numbers directly above it.", "split": "train" }
def merge_integers(arr1, arr2, descending=False): merged = [] i = j = 0 while i < len(arr1) and j < len(arr2): if arr1[i] <= arr2[j]: merged.append(arr1[i]) i += 1 else: merged.append(arr2[j]) j += 1 if i < len(arr1): merged += arr1...
simplelr_Algorithm
[ { "content": "Question:\nYou are tasked to write a Python function to solve the following problem:\n\n### Problem:\nWrite a function `merge_integers(arr1, arr2, descending=False)` that merges two sorted lists of integers into one sorted list. The combined list should be sorted in ascending order by default, but...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7218, "level": 1, "question": "You are tasked to write a Python function to solve the following problem:\n\n### Problem:\nWrite a function `merge_integers(arr1, arr2, descending=False)` that merges two sorted lists of integers into one sorted list. The combined list should be sorted...
def is_sorted_ascending(lst): return all(lst[i] <= lst[i+1] for i in range(len(lst)-1))
simplelr_Filter
[ { "content": "Question:\nHow can I check if a list is sorted in ascending order using Python?\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7219, "level": 1, "question": "How can I check if a list is sorted in ascending order using Python?", "split": "train" }
def switch_pairs_optimal(stack: list) -> list: n = len(stack) for i in range(0, n - 1, 2): stack[i], stack[i + 1] = stack[i + 1], stack[i] return stack
simplelr_Data_Structure
[ { "content": "Question:\nIn this task, you are required to implement an algorithm that processes a stack to switch successive pairs of elements starting from the bottom of the stack.\n\nGiven a stack, you need to write a function `switch_pairs_optimal(stack)` that modifies the stack such that each pair of succe...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7220, "level": 1, "question": "In this task, you are required to implement an algorithm that processes a stack to switch successive pairs of elements starting from the bottom of the stack.\n\nGiven a stack, you need to write a function `switch_pairs_optimal(stack)` that modifies the...
def cumulative_sum_until_limit(numbers: list, limit: float) -> float: """ Calculates cumulative sum of the list elements until the limit is surpassed. Parameters: numbers (list): A list of numerical (float or int) values. limit (float): The cumulative sum limit. Returns: float: The cumulat...
simplelr_Algorithm
[ { "content": "Question:\n### Problem Statement: Cumulative Sum with Early Termination\n\nYou are required to implement a function `cumulative_sum_until_limit` that calculates the cumulative sum of a list of numerical values but stops and discards the rest of the list if a given limit is surpassed by any cumulat...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7221, "level": 1, "question": "### Problem Statement: Cumulative Sum with Early Termination\n\nYou are required to implement a function `cumulative_sum_until_limit` that calculates the cumulative sum of a list of numerical values but stops and discards the rest of the list if a give...
def card_number_frequency(card_string): cards = card_string.split() frequency = {} for card in cards: if card in frequency: frequency[card] += 1 else: frequency[card] = 1 return frequency
simplelr_Filter
[ { "content": "Question:\nWrite a Python function that takes in a string of card numbers separated by spaces and returns a dictionary with the frequency of each card number. Assume the card numbers are always valid and consist of digits only.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7222, "level": 1, "question": "Write a Python function that takes in a string of card numbers separated by spaces and returns a dictionary with the frequency of each card number. Assume the card numbers are always valid and consist of digits only.", "split": "train" }
def longest_common_subsequence(sequence1, sequence2): n = len(sequence1) m = len(sequence2) # Create a table with (n+1) rows and (m+1) columns dp = [[0] * (m + 1) for _ in range(n + 1)] for i in range(1, n + 1): for j in range(1, m + 1): if sequence1[i - 1] == sequence2[j - ...
simplelr_Prefill
[ { "content": "Question:\nWrite a python function to compute the length of the longest common subsequence between two sequences. The function should return the length of the longest common subsequence.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7223, "level": 1, "question": "Write a python function to compute the length of the longest common subsequence between two sequences. The function should return the length of the longest common subsequence.", "split": "train" }
from collections import Counter def find_anagrams(s, words): s_counter = Counter(s) s_len = len(s) result = [] for word in words: if len(word) == s_len: word_counter = Counter(word) if word_counter == s_counter: result.append(word) return result
simplelr_Filter
[ { "content": "Question:\nGiven a string, find all possible anagrams of the string in a given list of words.\n\nExample: \nInput: \nString: \"cat\" \nList of words: [\"cat\",\"dog\",\"tac\",\"god\",\"good\",\"act\"]\nOutput: \n[\"cat\", \"tac\", \"act\"]\n\nNote: \n1. The input string can contain duplicate chara...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7224, "level": 1, "question": "Given a string, find all possible anagrams of the string in a given list of words.\n\nExample: \nInput: \nString: \"cat\" \nList of words: [\"cat\",\"dog\",\"tac\",\"god\",\"good\",\"act\"]\nOutput: \n[\"cat\", \"tac\", \"act\"]\n\nNote: \n1. The input...
def prefix_sum(arr): prefix_sums = [] run_sum = 0 for num in arr: run_sum += num prefix_sums.append(run_sum) return prefix_sums
simplelr_Prefill
[ { "content": "Question:\nWrite a function to implement prefix sum for an array efficiently.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7225, "level": 1, "question": "Write a function to implement prefix sum for an array efficiently.", "split": "train" }
def three_sum(nums, target): res = [] nums.sort() n = len(nums) for i in range(n - 2): # Skip the same result to avoid duplicates if i > 0 and nums[i] == nums[i - 1]: continue left, right = i + 1, n - 1 while left < right: current_sum = nums[i] + n...
simplelr_Filter
[ { "content": "Question:\nHere's the problem: Given a set of integers, find all the unique triplets in the set that add up to a given target sum.\n\nExample:\n\nInput: [1, 2, 3, 4, 5], target sum = 6\nOutput: [(1, 2, 3), (1, 3, 2), (1, 4, 1), (2, 2, 2), (2, 3, 1), (3, 1, 2), (3, 2, 1), (4, 1, 1)]\n\nHowever, the...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7226, "level": 1, "question": "Here's the problem: Given a set of integers, find all the unique triplets in the set that add up to a given target sum.\n\nExample:\n\nInput: [1, 2, 3, 4, 5], target sum = 6\nOutput: [(1, 2, 3), (1, 3, 2), (1, 4, 1), (2, 2, 2), (2, 3, 1), (3, 1, 2), (3...
def merge(arr1, arr2): i = j = 0 result = [] 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 # Add the remaining elements from arr1 and arr2 result.extend(a...
simplelr_Taco
[ { "content": "Question:\nYou are given two arrays, `arr1` and `arr2`, both of which are sorted in ascending order. Each array may have different sizes. Your task is to merge these two arrays into a single sorted array without using any built-in sort functions.\n\nExample:\n\nInput: arr1 = [1, 3, 5, 7], arr2 = [...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7227, "level": 1, "question": "You are given two arrays, `arr1` and `arr2`, both of which are sorted in ascending order. Each array may have different sizes. Your task is to merge these two arrays into a single sorted array without using any built-in sort functions.\n\nExample:\n\nI...
import os def search_files(directory, search_term): # Convert the search term to lowercase for case-insensitive comparison search_term_lower = search_term.lower() # Walk through the directory and subdirectories for root, dirs, files in os.walk(directory): for file in files: # C...
simplelr_Filter
[ { "content": "Question:\nI have been trying to write an app that can search for files in my directory and subdirectories from a given starting point. \n\nI am using Python and was wondering if there is an easy way to do this. \n\nI would like the file search function to be case insensitive.\n\nHere is what I ha...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7228, "level": 1, "question": "I have been trying to write an app that can search for files in my directory and subdirectories from a given starting point. \n\nI am using Python and was wondering if there is an easy way to do this. \n\nI would like the file search function to be cas...
def is_symmetric(arr): return arr == arr[::-1]
simplelr_Filter
[ { "content": "Question:\nDesign a Python function, which accepts an array comprised solely of integer values, as its parameter. This function's duty is to examine and analyze the given array, with the ultimate goal of outputting a True signal if the array's structure is symmetric or palindromic in nature. For i...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7229, "level": 1, "question": "Design a Python function, which accepts an array comprised solely of integer values, as its parameter. This function's duty is to examine and analyze the given array, with the ultimate goal of outputting a True signal if the array's structure is symmet...
def replace_vowels(s, replacement): result = [] for c in s: if c.lower() in {'a', 'e', 'i', 'o', 'u'}: result.append(replacement) else: result.append(c) return ''.join(result)
simplelr_Prefill
[ { "content": "Question:\nCreate a function that takes a string as an input and returns a new string that is a version of the original string but with every vowel replaced by a specified vowel.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7230, "level": 1, "question": "Create a function that takes a string as an input and returns a new string that is a version of the original string but with every vowel replaced by a specified vowel.", "split": "train" }
def to_uppercase(lst): return [s.upper() for s in lst]
simplelr_Prefill
[ { "content": "Question:\nWrite a python function to convert a list of strings to uppercase.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7231, "level": 1, "question": "Write a python function to convert a list of strings to uppercase.", "split": "train" }
def max_non_adjacent_sum(nums): if not nums: return 0 n = len(nums) if n == 1: return nums[0] prev_inc = nums[0] prev_excl = 0 for i in range(1, n): current_inc = prev_excl + nums[i] current_excl = max(prev_inc, prev_excl) prev_inc, prev_excl = current_inc...
simplelr_Filter
[ { "content": "Question:\nYou are given a sequence of 5864 integers. You need to find the maximum sum of a subsequence of these integers such that no two elements in the subsequence are adjacent in the original sequence. Write a function in Python to solve this problem.\nAnswer:\nLet's think step by step.\n", ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7232, "level": 1, "question": "You are given a sequence of 5864 integers. You need to find the maximum sum of a subsequence of these integers such that no two elements in the subsequence are adjacent in the original sequence. Write a function in Python to solve this problem.", "sp...
def countBits(n): if n < 0: return [] ret = [0] * (n + 1) for i in range(1, n + 1): j = i - 1 k = 0 temp = j while temp & 1: k += 1 temp >>= 1 ret[i] = ret[i-1] + 1 - k return ret
simplelr_Leetcode
[ { "content": "Question:\nYou are given a positive integer `n`. Return an array `ret`, where `ret[i]` denotes the number of `1` bits in the binary representation of the integer `i` for 0 ≤ `i` ≤ `n`. Write an efficient solution with a time complexity lower than O(n log n).\nAnswer:\nLet's think step by step.\n",...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7233, "level": 1, "question": "You are given a positive integer `n`. Return an array `ret`, where `ret[i]` denotes the number of `1` bits in the binary representation of the integer `i` for 0 ≤ `i` ≤ `n`. Write an efficient solution with a time complexity lower than O(n log n).", ...
def compare_version(s1, s2): v1 = list(map(int, s1.split('.'))) v2 = list(map(int, s2.split('.'))) max_len = max(len(v1), len(v2)) for i in range(max_len): a = v1[i] if i < len(v1) else 0 b = v2[i] if i < len(v2) else 0 if a > b: return 1 elif a < b: ...
simplelr_Leetcode
[ { "content": "Question:\nYou are given two strings `s1` and `s2` representing two version numbers. A version number is composed of one or more numbers separated by dots `.`. Each number is an integer representing a part of the version number. Compare the two version numbers `s1` and `s2`. If `s1` is greater tha...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7234, "level": 1, "question": "You are given two strings `s1` and `s2` representing two version numbers. A version number is composed of one or more numbers separated by dots `.`. Each number is an integer representing a part of the version number. Compare the two version numbers `s...
def is_palindrome(s): # Preprocess the string: keep only alphanumeric characters and convert to lowercase processed = ''.join([c.lower() for c in s if c.isalnum()]) # Check if the processed string is the same as its reverse return processed == processed[::-1]
simplelr_Prefill
[ { "content": "Question:\nWrite a function to check if a string s is a palindrome (A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward as forward, such as \"A man, a plan, a canal: Panama\").\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7235, "level": 1, "question": "Write a function to check if a string s is a palindrome (A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward as forward, such as \"A man, a plan, a canal: Panama\").", "split": "train" }
from typing import List def enhanced_gnome_sort(arr: List[int]) -> List[int]: n = len(arr) swapped = True while swapped: swapped = False pos = 0 while pos < n - 1: if arr[pos] > arr[pos + 1]: # Swap the elements arr[pos], arr[pos + 1] = ar...
simplelr_Data_Structure
[ { "content": "Question:\n### Problem: Enhanced Gnome Sort with Early Termination\n\nYou are tasked with enhancing the given Gnome Sort algorithm. The goal is to improve it by adding a mechanism to detect if the array is already sorted during the sorting process. If a complete pass through the array is made with...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7236, "level": 1, "question": "### Problem: Enhanced Gnome Sort with Early Termination\n\nYou are tasked with enhancing the given Gnome Sort algorithm. The goal is to improve it by adding a mechanism to detect if the array is already sorted during the sorting process. If a complete ...
from collections import Counter def canFormPalindrome(s: str) -> bool: counts = Counter(s) odd_counts = sum(1 for cnt in counts.values() if cnt % 2 != 0) n = len(s) if n % 2 == 0: return odd_counts == 0 else: return odd_counts == 1
simplelr_Apps
[ { "content": "Question:\nWrite a function to determine whether a given string can be rearranged to form a palindrome. A palindrome is a string that reads the same forward and backward.\n\nThe input string will only contain lowercase alphabets and its length will be between 1 and 1000 inclusive.\n\nFunction sign...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7237, "level": 1, "question": "Write a function to determine whether a given string can be rearranged to form a palindrome. A palindrome is a string that reads the same forward and backward.\n\nThe input string will only contain lowercase alphabets and its length will be between 1 a...
def clean_string(s): result = [] for c in s: if c.isalnum() or c == ' ': result.append(c) return ''.join(result)
simplelr_Taco
[ { "content": "Question:\nWrite a function that takes an input string and removes all non-alphanumeric characters (excluding spaces), ensuring that the resulting string preserves spaces and the original order of characters. The function should return the cleaned string.\n\nExample:\n```\nInput: \"Hello, World! W...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7238, "level": 1, "question": "Write a function that takes an input string and removes all non-alphanumeric characters (excluding spaces), ensuring that the resulting string preserves spaces and the original order of characters. The function should return the cleaned string.\n\nExam...
def find_pair(arr: list[int], target: int) -> tuple[int, int] | None: 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 e...
simplelr_Algorithm
[ { "content": "Question:\n## Question: Find Elements that Sum to Target in a Sorted Array\n\nYou are given a sorted array of integers `arr` and a target integer `target`. Implement a function `find_pair(arr: list[int], target: int) -> tuple`: that finds two distinct elements in the array that sum up to the targe...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7239, "level": 1, "question": "## Question: Find Elements that Sum to Target in a Sorted Array\n\nYou are given a sorted array of integers `arr` and a target integer `target`. Implement a function `find_pair(arr: list[int], target: int) -> tuple`: that finds two distinct elements in...
from collections import deque def shortest_path(grid): if not grid or not grid[0]: return -1 M = len(grid) N = len(grid[0]) start = (0, 0) end = (M-1, N-1) if grid[start[0]][start[1]] != 0 or grid[end[0]][end[1]] != 0: return -1 visited = [[False for _ in...
simplelr_Filter
[ { "content": "Question:\nI have a 4x4 grid (5x5 grid with a 1 cell border around it) and I need to find a path from the top left to the bottom right. The cell can only move up, down, left or right, no diagonals. The move can only be made to an empty cell (i.e., a cell with value 0). \n\nHowever, in my grid some...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7240, "level": 1, "question": "I have a 4x4 grid (5x5 grid with a 1 cell border around it) and I need to find a path from the top left to the bottom right. The cell can only move up, down, left or right, no diagonals. The move can only be made to an empty cell (i.e., a cell with val...
def can_split_equal_sum(arr): total = sum(arr) if total % 2 != 0: return False target = total // 2 current_sum = 0 for num in arr: current_sum += num if current_sum == target: return True return False
simplelr_Leetcode
[ { "content": "Question:\nYou are given an array of integers `arr`. Your task is to determine if it is possible to split the array into two non-empty parts such that the sum of the elements in the first part is equal to the sum of the elements in the second part. If such a split is possible, return `true`, other...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7241, "level": 1, "question": "You are given an array of integers `arr`. Your task is to determine if it is possible to split the array into two non-empty parts such that the sum of the elements in the first part is equal to the sum of the elements in the second part. If such a spli...
def character_count(strings): return dict(sorted({s: len(s) for s in strings}.items(), key=lambda x: x[1], reverse=True))
simplelr_Package
[ { "content": "Question:\nWrite a function that takes a list of strings as an input and returns a dictionary where the keys are the strings and the values are the number of characters in each string. Additionally, the function should sort the dictionary by values in descending order before returning it.\n\nThe f...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7242, "level": 1, "question": "Write a function that takes a list of strings as an input and returns a dictionary where the keys are the strings and the values are the number of characters in each string. Additionally, the function should sort the dictionary by values in descending ...
def is_rotated_optimized(s1: str, s2: str) -> bool: if len(s1) != len(s2): return False if len(s1) == 0: return True return s2 in s1 + s1
simplelr_Data_Structure
[ { "content": "Question:\n**Scenario**:\nImagine you are developing a text processing tool that needs to check if a string is a rotation of another to support cyclic pattern recognition features. This functionality will enhance the ability to process and identify patterns efficiently.\n\n**Task**:\nWrite a Pytho...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7243, "level": 1, "question": "**Scenario**:\nImagine you are developing a text processing tool that needs to check if a string is a rotation of another to support cyclic pattern recognition features. This functionality will enhance the ability to process and identify patterns effic...
import random def average_latency( message_count: int, max_latency: int, min_latency: int = 10 ) -> float: total = sum( random.randint(min_latency, max_latency) for _ in range(message_count) ) return total / message_count
simplelr_Algorithm
[ { "content": "Question:\n### Network Latency Simulation\n\nYou are responsible for simulating network latency for messages sent between two systems over a specified duration. The goal is to calculate the average round-trip latency for a given number of messages sent within a defined time interval.\n\n#### Task\...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7244, "level": 1, "question": "### Network Latency Simulation\n\nYou are responsible for simulating network latency for messages sent between two systems over a specified duration. The goal is to calculate the average round-trip latency for a given number of messages sent within a d...
from collections import deque def word_ladder_length(start, end, dictionary): if start == end: return 1 dict_set = set(dictionary) if end not in dict_set: return 0 # End word must be in the dictionary to be reachable queue = deque() queue.append((start, 1)) visit...
simplelr_Code_Contests
[ { "content": "Question:\nWord Ladder: Given a start word, an end word, and a dictionary of words of the same length, transform the start word into the end word using the fewest number of transformations. Each transformation consists of changing exactly one character in the word such that the new word is still i...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7245, "level": 1, "question": "Word Ladder: Given a start word, an end word, and a dictionary of words of the same length, transform the start word into the end word using the fewest number of transformations. Each transformation consists of changing exactly one character in the wor...
def fast_power(base: int, exponent: int, mod: int) -> int: if mod == 1: return 0 if exponent == 0: return 1 % mod result = 1 current_base = base % mod exponent_remaining = exponent while exponent_remaining > 0: if exponent_remaining % 2 == 1: result = (result ...
simplelr_Data_Structure
[ { "content": "Question:\nYou are tasked to implement an efficient function that calculates the result of raising a base integer to the power of an exponent integer, and then taking the modulo of this result with another integer. This operation is crucial in various applications such as cryptography and large nu...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7246, "level": 1, "question": "You are tasked to implement an efficient function that calculates the result of raising a base integer to the power of an exponent integer, and then taking the modulo of this result with another integer. This operation is crucial in various application...
def binary_search_first_occurrence(nums: list[int], target: int) -> int: low = 0 high = len(nums) - 1 result = -1 while low <= high: mid = (low + high) // 2 if nums[mid] == target: result = mid high = mid - 1 # Continue searching left for earlier occurrence ...
simplelr_Algorithm
[ { "content": "Question:\n### Question\n\n#### Context\nSearching within a sorted array is a common task in many applications. The Binary Search algorithm is efficient for this purpose with a time complexity of O(log n). In this problem, you will implement a variant of Binary Search that not only determines the ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7247, "level": 1, "question": "### Question\n\n#### Context\nSearching within a sorted array is a common task in many applications. The Binary Search algorithm is efficient for this purpose with a time complexity of O(log n). In this problem, you will implement a variant of Binary S...
def remove_duplicate_letters(s: str) -> str: from collections import defaultdict # Count the frequency of each character in the string count = defaultdict(int) for c in s: count[c] += 1 stack = [] used = set() for c in s: # Decrement the count as we process this character ...
simplelr_Code_Contests
[ { "content": "Question:\nYou are given a string `s` consisting of lowercase English letters, and you need to return the lexicographically smallest sequence obtained by removing duplicate letters such that every letter appears once. \n\nYou have to ensure that you remove the minimum number of characters to achie...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7248, "level": 1, "question": "You are given a string `s` consisting of lowercase English letters, and you need to return the lexicographically smallest sequence obtained by removing duplicate letters such that every letter appears once. \n\nYou have to ensure that you remove the mi...
def segment_count(s, seg): count = 0 seg_len = len(seg) s_len = len(s) for i in range(s_len - seg_len + 1): if s[i:i+seg_len] == seg: count += 1 return count
simplelr_Apps
[ { "content": "Question:\n___\n\nString Segment Frequency is the process of determining how many times a specified segment (sub-string) occurs within a larger text string.\n\nWhen given the string `hellohellohello` and the segment `hello`, the following process occurs:\n\n```\n The segment 'hello' appears three ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7249, "level": 1, "question": "___\n\nString Segment Frequency is the process of determining how many times a specified segment (sub-string) occurs within a larger text string.\n\nWhen given the string `hellohellohello` and the segment `hello`, the following process occurs:\n\n```\n...
def find_prefix(s, prefixes): for prefix in prefixes: if s.startswith(prefix): return prefix return ""
simplelr_Prefill
[ { "content": "Question:\nWrite a python function to determine if a given string starts with any of the given prefixes. If it does, return the prefix that matches. If not, return an empty string.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7250, "level": 1, "question": "Write a python function to determine if a given string starts with any of the given prefixes. If it does, return the prefix that matches. If not, return an empty string.", "split": "train" }
def max_rectangle_area(heights): stack = [-1] max_area = 0 n = len(heights) for i in range(n): while stack[-1] != -1 and heights[i] < heights[stack[-1]]: h = heights[stack.pop()] width = i - stack[-1] - 1 max_area = max(max_area, h * width) stack.appen...
simplelr_Leetcode
[ { "content": "Question:\nGiven an array of integers where each integer represents the height of a building in a skyline, determine the **maximum area** of a rectangle that can be formed using any number of contiguous buildings. The height of the rectangle is determined by the shortest building in the selected r...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7251, "level": 1, "question": "Given an array of integers where each integer represents the height of a building in a skyline, determine the **maximum area** of a rectangle that can be formed using any number of contiguous buildings. The height of the rectangle is determined by the ...
import re def extract_version(filename): version_pattern = r'v(\d+\.\d+\.\d+)' match = re.search(version_pattern, filename) if match: return match.group(1) else: return "Version number not found"
simplelr_Filter
[ { "content": "Question:\nCan you write a Python function that extracts the version number from a given file name? The version number should be in the format \"major.minor.patch\" and should be preceded by the letter 'v' for version. For example, from the file name \"example_v1.2.3.txt\", the function should ret...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7252, "level": 1, "question": "Can you write a Python function that extracts the version number from a given file name? The version number should be in the format \"major.minor.patch\" and should be preceded by the letter 'v' for version. For example, from the file name \"example_v1...
def remove_consecutive_duplicates(input_string): if not input_string: return "" result = [input_string[0]] for char in input_string[1:]: if char != result[-1]: result.append(char) return ''.join(result)
simplelr_Algorithm
[ { "content": "Question:\n### Consecutive Duplicates Removal\n\nIn a text processing application, you need to write a function that removes consecutive duplicate characters in a given string. The function should ensure that if the same character appears consecutively multiple times, only one instance of it shoul...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7253, "level": 1, "question": "### Consecutive Duplicates Removal\n\nIn a text processing application, you need to write a function that removes consecutive duplicate characters in a given string. The function should ensure that if the same character appears consecutively multiple t...
def remove_duplicates(lst): seen = set() unique_list = [] for item in lst: if item not in seen: seen.add(item) unique_list.append(item) return unique_list
simplelr_Filter
[ { "content": "Question:\nCan you help me with a Python function to remove all the duplicates from a given list of integers and return a list of unique elements, while preserving the original order? For example, if I have a list like [4, 5, 4, 6, 7, 5, 8], after removing duplicates, the function should return [4...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7254, "level": 1, "question": "Can you help me with a Python function to remove all the duplicates from a given list of integers and return a list of unique elements, while preserving the original order? For example, if I have a list like [4, 5, 4, 6, 7, 5, 8], after removing duplic...
def sort_rgb(colors: list[str]) -> list[str]: count_R = 0 count_G = 0 count_B = 0 for color in colors: if color == 'R': count_R += 1 elif color == 'G': count_G += 1 else: count_B += 1 return ['R'] * count_R + ['G'] * count_G + ['B'] * count...
simplelr_Algorithm
[ { "content": "Question:\nRGB Sorting Algorithm\n\n**Context**:\nYou are provided with a list of colors represented as 'R', 'G', and 'B', mapping to red, green, and blue respectively. The task is to sort the list so that all 'R's come first, followed by 'G's and then 'B's.\n\n**Function Specification**:\n\nWrite...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7255, "level": 1, "question": "RGB Sorting Algorithm\n\n**Context**:\nYou are provided with a list of colors represented as 'R', 'G', and 'B', mapping to red, green, and blue respectively. The task is to sort the list so that all 'R's come first, followed by 'G's and then 'B's.\n\n*...
def generate_matrix(n, m, step=1): """ Generates a 2D numerical matrix of dimension n x m where numbers increment sequentially starting from 1 with a specified step. Args: n (int): Number of rows in the matrix. m (int): Number of columns in the matrix. step (int, optional): The ...
simplelr_Filter
[ { "content": "Question:\nRevise the Python script to enable the function to take in two numbers as parameters: n and m. Your function should now generate a two-dimensional, responsive, numerical乘matrix of dimension n * m. The catch here however, lies in the reality that the script returns an added functionality...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7256, "level": 1, "question": "Revise the Python script to enable the function to take in two numbers as parameters: n and m. Your function should now generate a two-dimensional, responsive, numerical乘matrix of dimension n * m. The catch here however, lies in the reality that the sc...
def min_path_cost(grid): m = len(grid) if m == 0: return 0 n = len(grid[0]) dp = [[0 for _ in range(n)] for _ in range(m)] dp[0][0] = grid[0][0] # Fill the first row for j in range(1, n): dp[0][j] = dp[0][j-1] + grid[0][j] # Fill the first column for i in range(1, m):...
simplelr_Leetcode
[ { "content": "Question:\nGiven a 2D grid of size `m x n`, where each cell represents a cost to traverse, find the minimum cost to make a path from the top left corner to the bottom right corner. You can only move either down or right at any point in time. Return the minimum cost of the path. \n\nThe grid is rep...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7257, "level": 1, "question": "Given a 2D grid of size `m x n`, where each cell represents a cost to traverse, find the minimum cost to make a path from the top left corner to the bottom right corner. You can only move either down or right at any point in time. Return the minimum co...
def selection_sort(arr): for i in range(len(arr)): min_index = i for j in range(i + 1, len(arr)): if arr[j] < arr[min_index]: min_index = j arr[i], arr[min_index] = arr[min_index], arr[i] return arr arr = [64, 25, 12, 22, 11] print("Original array:", arr) pri...
simplelr_Filter
[ { "content": "Question:\nHere is the problem: \nGiven an array of integers, sort the array in ascending order using selection sort algorithm.\n\nHere is my code (getting an error):\n```python\ndef selection_sort(arr):\n for i in range(len(arr)):\n min_index = i\n for j in range(i+1, len(arr)):\...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7258, "level": 1, "question": "Here is the problem: \nGiven an array of integers, sort the array in ascending order using selection sort algorithm.\n\nHere is my code (getting an error):\n```python\ndef selection_sort(arr):\n for i in range(len(arr)):\n min_index = i\n ...
def cocktail_shaker_sort(arr): if len(arr) <= 1: return arr left = 0 right = len(arr) - 1 while True: swapped = False # Left to right pass 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:\nGiven an array of integers, implement the Cocktail Shaker Sort algorithm to sort the array in ascending order. You should ensure the algorithm handles all possible edge cases efficiently and performs minimal swaps.\n\n### Requirements:\n* Implement the function `cocktail_shaker_sort(arr...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7259, "level": 1, "question": "Given an array of integers, implement the Cocktail Shaker Sort algorithm to sort the array in ascending order. You should ensure the algorithm handles all possible edge cases efficiently and performs minimal swaps.\n\n### Requirements:\n* Implement the...
def trapezoidal_rule(points): total_area = 0.0 for i in range(len(points) - 1): x_i, y_i = points[i] x_next, y_next = points[i+1] area = (y_i + y_next) / 2 * (x_next - x_i) total_area += area return total_area
simplelr_Filter
[ { "content": "Question:\nWrite a Python function that calculates the total area under a curve defined by a list of (x, y) points using the trapezoidal rule. The trapezoidal rule estimates the area under a curve by dividing the area into trapezoids and summing their areas.\nAnswer:\nLet's think step by step.\n",...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7260, "level": 1, "question": "Write a Python function that calculates the total area under a curve defined by a list of (x, y) points using the trapezoidal rule. The trapezoidal rule estimates the area under a curve by dividing the area into trapezoids and summing their areas.", ...
def bubble_sort(lst): n = len(lst) for i in range(n - 1): swapped = False for j in range(n - 1 - i): if lst[j] > lst[j + 1]: lst[j], lst[j + 1] = lst[j + 1], lst[j] swapped = True if not swapped: break return lst
simplelr_Prefill
[ { "content": "Question:\nWrite a function to sort a list of integers in ascending order using the bubble sort algorithm. The function should take a list of integers as input and return the sorted list.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7261, "level": 1, "question": "Write a function to sort a list of integers in ascending order using the bubble sort algorithm. The function should take a list of integers as input and return the sorted list.", "split": "train" }
import numpy as np def reverse_memory_order(arr): return np.flip(arr, axis=0)
simplelr_Prefill
[ { "content": "Question:\nCreate a function that reverses the memory order for a slice (or array) in Numpy. This function should be equivalent to numpy.flipud() for 2D arrays, but it should work for any given number of dimensions.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7262, "level": 1, "question": "Create a function that reverses the memory order for a slice (or array) in Numpy. This function should be equivalent to numpy.flipud() for 2D arrays, but it should work for any given number of dimensions.", "split": "train" }
def find_value_index(arr, val): for i in range(len(arr)): for j in range(len(arr[i])): if arr[i][j] == val: return [i, j] return [-1, -1]
simplelr_Filter
[ { "content": "Question:\nYou need to write a function to find the index of a value in a 2D array. The 2D array can have duplicates and can contain both positive and negative integers. The function should return the index of the first occurrence of the value in the 2D array. If the value is not found in the 2D a...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7263, "level": 1, "question": "You need to write a function to find the index of a value in a 2D array. The 2D array can have duplicates and can contain both positive and negative integers. The function should return the index of the first occurrence of the value in the 2D array. If...
def four_sum_exists(arr, target): arr.sort() n = len(arr) if n < 4: return False for i in range(n - 3): for j in range(i + 1, n - 2): left = j + 1 right = n - 1 required = target - arr[i] - arr[j] while left < right: current...
simplelr_Leetcode
[ { "content": "Question:\nYou are given a list of integers `arr` and an integer `target`. Write a function that determines if there are four elements in `arr` whose sum is equal to `target`. Return `true` if such a combination of elements exists, otherwise return `false`.\n\nCreate a question with relevant const...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7264, "level": 1, "question": "You are given a list of integers `arr` and an integer `target`. Write a function that determines if there are four elements in `arr` whose sum is equal to `target`. Return `true` if such a combination of elements exists, otherwise return `false`.\n\nCr...
def find_min_year(data): min_companies = float('inf') min_year = None for year, num in data: if num < min_companies: min_companies = num min_year = year return min_year
simplelr_Filter
[ { "content": "Question:\nHi! I will provide you a set of graph data and then you have to code a Python function to process the data, and finally provide the algorithm time complexity and space complexity for this function. \n\nThe data are the number of Chinese companies from 1993 to 2013, and the data will be ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7265, "level": 1, "question": "Hi! I will provide you a set of graph data and then you have to code a Python function to process the data, and finally provide the algorithm time complexity and space complexity for this function. \n\nThe data are the number of Chinese companies from ...
import re def find_misspelled_words(paragraph, dictionary): # Preprocess the dictionary into a set of lower-cased words dictionary_set = set(word.lower() for word in dictionary) # Split the paragraph into tokens based on the delimiters: spaces, commas, periods tokens = re.split(r'[, .]+', paragrap...
simplelr_Code_Contests
[ { "content": "Question:\nA software development company wants to implement a spell check feature in their text editor. To accomplish this, they need a function to identify potential misspelled words in a given paragraph. A misspelled word is defined as a word that does not appear in a provided dictionary of cor...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7266, "level": 1, "question": "A software development company wants to implement a spell check feature in their text editor. To accomplish this, they need a function to identify potential misspelled words in a given paragraph. A misspelled word is defined as a word that does not app...
def rgb_to_hex(r, g, b): return f"#{r:02X}{g:02X}{b:02X}"
simplelr_Taco
[ { "content": "Question:\nIn computer graphics, colors are often represented using the RGB color model. Each color in the RGB model can be described by its red, green, and blue components, which are usually integers between 0 and 255 (inclusive). Let's write a function that converts an RGB color to a hexadecimal...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7267, "level": 1, "question": "In computer graphics, colors are often represented using the RGB color model. Each color in the RGB model can be described by its red, green, and blue components, which are usually integers between 0 and 255 (inclusive). Let's write a function that con...
from collections import deque def minTransformationSteps(start, end, wordPairs): # Collect all unique words from the wordPairs word_set = set() for a, b in wordPairs: word_set.add(a) word_set.add(b) # Check if start or end is not present in the word_set if start not in word_set...
simplelr_Taco
[ { "content": "Question:\nGiven a list of word pairs, write a function that determines if a transformation sequence from one word to another exists. The transformation sequence is defined such that each word in the sequence is transformed into another word by changing exactly one character, and each transformed ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7268, "level": 1, "question": "Given a list of word pairs, write a function that determines if a transformation sequence from one word to another exists. The transformation sequence is defined such that each word in the sequence is transformed into another word by changing exactly o...
def mixed_sort(input_list): """ Sorts a given list based on the following criteria: - Integers in ascending order - Floats in descending order - Strings by length (shortest to longest) - Removes other data types Args: input_list (list): List containing elements of mixed data types. ...
simplelr_Evol
[ { "content": "Question:\nWrite a function that takes a list of mixed data types and returns a new list where integers are sorted in ascending order, floats are sorted in descending order, strings are sorted by length (shortest to longest), and any other types are removed.\n\n```python\ndef mixed_sort(input_list...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7269, "level": 1, "question": "Write a function that takes a list of mixed data types and returns a new list where integers are sorted in ascending order, floats are sorted in descending order, strings are sorted by length (shortest to longest), and any other types are removed.\n\n`...
def multiply_by_three(lst): return [x * 3 for x in lst]
simplelr_Filter
[ { "content": "Question:\nI need to create a Python function that takes a list of integers and returns a new list with each element multiplied by 3. Write a function called `multiply_by_three` that accomplishes this.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7270, "level": 1, "question": "I need to create a Python function that takes a list of integers and returns a new list with each element multiplied by 3. Write a function called `multiply_by_three` that accomplishes this.", "split": "train" }
def compare_strings(str1, str2): return str1.strip().lower() == str2.strip().lower()
simplelr_Filter
[ { "content": "Question:\nGenerate a code to compare two strings and return a boolean result. The code should be case-insensitive and should ignore leading and trailing white spaces in the strings.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7271, "level": 1, "question": "Generate a code to compare two strings and return a boolean result. The code should be case-insensitive and should ignore leading and trailing white spaces in the strings.", "split": "train" }
from typing import List, Dict def count_frequencies(nums: List[int]) -> Dict[int, int]: freq = {} for num in nums: if num in freq: freq[num] += 1 else: freq[num] = 1 return freq
simplelr_Apps
[ { "content": "Question:\n=====Problem Statement=====\nYou often work with numbers and sometimes need to process lists containing those numbers. One useful operation is to find which numbers in a list are repeated and how many times they each occur.\n\nTask:\nGiven a list of integers, write a program to count th...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7272, "level": 1, "question": "=====Problem Statement=====\nYou often work with numbers and sometimes need to process lists containing those numbers. One useful operation is to find which numbers in a list are repeated and how many times they each occur.\n\nTask:\nGiven a list of in...
def string_to_chars(text): """Returns a list of characters from a string. Args: text: The input string. Returns: A list of individual characters from the string, each as a string. """ return [char for char in text]
simplelr_Filter
[ { "content": "Question:\nHere's a Python function that takes a string as input and returns a list of its characters as individual strings:\n\n```python\ndef string_to_chars(text):\n \"\"\"Returns a list of characters from a string.\n\n Args:\n text: The input string.\n\n Returns:\n A list of individual...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7273, "level": 1, "question": "Here's a Python function that takes a string as input and returns a list of its characters as individual strings:\n\n```python\ndef string_to_chars(text):\n \"\"\"Returns a list of characters from a string.\n\n Args:\n text: The input string.\n\n ...
def subsets(nums): result = [[]] for num in nums: result += [curr + [num] for curr in result] return result
simplelr_Filter
[ { "content": "Question:\nHere is the problem: Given a non-empty set of unique positive integers, write a function that returns all possible subsets of the given set.\n\nExample:\nInput: [1, 2, 3]\nOutput: [[1], [2], [3], [1,2], [1,3], [2,3], [1,2,3]]\n\nThis output seems incorrect. The correct output should be:...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7274, "level": 1, "question": "Here is the problem: Given a non-empty set of unique positive integers, write a function that returns all possible subsets of the given set.\n\nExample:\nInput: [1, 2, 3]\nOutput: [[1], [2], [3], [1,2], [1,3], [2,3], [1,2,3]]\n\nThis output seems incor...
import seaborn as sns import matplotlib.pyplot as plt def plot_aesthetic_line(x: list, y: list, context: str, font_scale: float, linewidth: float) -> None: sns.set_context(context, font_scale=font_scale) plt.figure() sns.lineplot(x=x, y=y, linewidth=linewidth) plt.show()
simplelr_Docs
[ { "content": "Question:\n<|Analysis Begin|>\n\nThe provided documentation snippet about the seaborn library focuses on the `sns.set_context()` function for setting the context parameters for plots. This function helps to adjust the aesthetics of the plotted figures, including the scaling of font elements and ov...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7275, "level": 1, "question": "<|Analysis Begin|>\n\nThe provided documentation snippet about the seaborn library focuses on the `sns.set_context()` function for setting the context parameters for plots. This function helps to adjust the aesthetics of the plotted figures, including ...
def sumFirstLast(N): last = N % 10 first = N while first >= 10: first = first // 10 return first + last
simplelr_Taco
[ { "content": "Question:\nGiven a positive integer N, find the sum of the first and last digit of N. \n\nExample 1:\nInput: N = 1234\nOutput: 5\nExplanation:\nFirst digit is 1 and last digit is 4. Their sum is 1 + 4 = 5.\n\nExample 2:\nInput: N = 56789\nOutput: 14\nExplanation:\nFirst digit is 5 and last digit i...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7276, "level": 1, "question": "Given a positive integer N, find the sum of the first and last digit of N. \n\nExample 1:\nInput: N = 1234\nOutput: 5\nExplanation:\nFirst digit is 1 and last digit is 4. Their sum is 1 + 4 = 5.\n\nExample 2:\nInput: N = 56789\nOutput: 14\nExplanation:...
import bisect def length_of_lis(nums): tails = [] for num in nums: # Find the index to replace or append idx = bisect.bisect_left(tails, num) if idx == len(tails): tails.append(num) else: tails[idx] = num return len(tails)
simplelr_Filter
[ { "content": "Question:\nIn Python, how can I implement a function to find the length of the longest increasing subsequence in a list of integers?\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7277, "level": 1, "question": "In Python, how can I implement a function to find the length of the longest increasing subsequence in a list of integers?", "split": "train" }
def custom_sort(arr): if len(arr) <= 1: return arr pivot_index = len(arr) // 2 pivot = arr[pivot_index] left = [x for x in arr if x < pivot] middle = [x for x in arr if x == pivot] right = [x for x in arr if x > pivot] return custom_sort(left) + middle + custom_sort(right)
simplelr_Package
[ { "content": "Question:\nIn database applications, sorting functionality is frequently required. Many programming languages, including Python, provide robust methods for sorting data. Your task is to implement a custom sorting function without using any built-in sort functions.\n\nSpecifically:\n1. Write a Pyth...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7278, "level": 1, "question": "In database applications, sorting functionality is frequently required. Many programming languages, including Python, provide robust methods for sorting data. Your task is to implement a custom sorting function without using any built-in sort functions...
def diagonal_difference(matrix): n = len(matrix) sum_principal = 0 sum_secondary = 0 for i in range(n): sum_principal += matrix[i][i] sum_secondary += matrix[i][n - 1 - i] return abs(sum_principal - sum_secondary)
simplelr_Filter
[ { "content": "Question:\nCreate a Python function that takes a square matrix of size `n x n` as an input, where `n` is an odd integer between 3 and 100, inclusive. The function should determine the absolute difference between the sums of both principal and secondary diagonals of the matrix. The matrix is repres...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7279, "level": 1, "question": "Create a Python function that takes a square matrix of size `n x n` as an input, where `n` is an odd integer between 3 and 100, inclusive. The function should determine the absolute difference between the sums of both principal and secondary diagonals ...
def k_smallest_numbers(nums, k): if not nums or k <= 0: return [] n = len(nums) if k >= n: return sorted(nums) sorted_nums = sorted(nums) return sorted_nums[:k]
simplelr_Filter
[ { "content": "Question:\nWrite a Python function that takes in a list of integers and an integer `k` as arguments and returns the `k` smallest numbers from the list. The function should return the result in ascending order.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7280, "level": 1, "question": "Write a Python function that takes in a list of integers and an integer `k` as arguments and returns the `k` smallest numbers from the list. The function should return the result in ascending order.", "split": "train" }
def find_in_matrix(matrix, target): n = len(matrix) row = 0 col = n - 1 while row < n and col >= 0: current = matrix[row][col] if current == target: return (row, col) elif target < current: col -= 1 else: row += 1 return -1
simplelr_Apps
[ { "content": "Question:\nGiven a square matrix and a target number, write a function to determine if the matrix contains the target number. If found, return its position as a tuple `(row, col)`. Otherwise, return `-1`.\n\n*Parameters*: `matrix` and `target`\n\n*Example input*:\n```\nmatrix = [\n [5, 12, 17, 21...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7281, "level": 1, "question": "Given a square matrix and a target number, write a function to determine if the matrix contains the target number. If found, return its position as a tuple `(row, col)`. Otherwise, return `-1`.\n\n*Parameters*: `matrix` and `target`\n\n*Example input*:...
def max_length_of_special_substring(s): sum_dict = {0: -1} max_length = 0 current_sum = 0 for index, char in enumerate(s): current_sum += 1 if char == 'a' else -1 if current_sum in sum_dict: length = index - sum_dict[current_sum] if length > max_length: ...
simplelr_Leetcode
[ { "content": "Question:\nYou are given a string `s` containing only the characters `a` and `b`. A substring of `s` is called **special** if it contains equal numbers of the character `a` and the character `b`. Find the **maximum length** of a special substring. If no such substring exists, return 0.\nAnswer:\nL...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7282, "level": 1, "question": "You are given a string `s` containing only the characters `a` and `b`. A substring of `s` is called **special** if it contains equal numbers of the character `a` and the character `b`. Find the **maximum length** of a special substring. If no such subs...
def longest_common_subsequence(s1, s2): m = len(s1) n = len(s2) prev = [0] * (n + 1) for i in range(m): current = [0] * (n + 1) for j in range(1, n + 1): if s1[i] == s2[j - 1]: current[j] = prev[j - 1] + 1 else: current[j] = max(pre...
simplelr_Leetcode
[ { "content": "Question:\nDesign an algorithm to find the longest common subsequence of two given strings `s1` and `s2`. The longest common subsequence (LCS) is defined as the longest sequence that can be derived from both strings by deleting some characters without reordering the remaining characters. For examp...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7283, "level": 1, "question": "Design an algorithm to find the longest common subsequence of two given strings `s1` and `s2`. The longest common subsequence (LCS) is defined as the longest sequence that can be derived from both strings by deleting some characters without reordering ...
def count_vowels(s): if not s: return 0 lower_s = s.lower() count = 0 for char in lower_s: if char in {'a', 'e', 'i', 'o', 'u'}: count += 1 if lower_s[-1] == 'y': count += 1 return count
simplelr_Prefill
[ { "content": "Question:\nCreate a function that takes a string as input and returns the count of vowels in it. Consider 'aeiou' as vowels and they can appear in both uppercase and lowercase. Also, count 'y' as a vowel if it's at the end of the string.\nAnswer:\nLet's think step by step.\n", "role": "user" ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7284, "level": 1, "question": "Create a function that takes a string as input and returns the count of vowels in it. Consider 'aeiou' as vowels and they can appear in both uppercase and lowercase. Also, count 'y' as a vowel if it's at the end of the string.", "split": "train" }
def highest_grades(students): highest_grades = {} for name, grade in students: current_max = highest_grades.get(name) if current_max is None or grade > current_max: highest_grades[name] = grade return highest_grades
simplelr_Filter
[ { "content": "Question:\nQwen, I want to make a function that takes a list of tuples, where each tuple contains a student's name and their grades. The function should return a dictionary where each key is a student's name and the value is the highest grade they received. How can I do this?\nAnswer:\nLet's think...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7285, "level": 1, "question": "Qwen, I want to make a function that takes a list of tuples, where each tuple contains a student's name and their grades. The function should return a dictionary where each key is a student's name and the value is the highest grade they received. How c...
def yc_interview(applicants): # Create a dictionary to group applications by their application time groups = {} for app in applicants: time = app[1] if time not in groups: groups[time] = [] groups[time].append(app) # Sort the times in ascending order sorted_t...
simplelr_Filter
[ { "content": "Question:\n### Preparing for the Future: Y Combinator's Job Opening\n\nY Combinator is seeking an exceptional individual to join their team. For this position, they will be accepting applications for only one week. Every morning, a set of new applications will arrive, and the applicant with the mo...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7286, "level": 1, "question": "### Preparing for the Future: Y Combinator's Job Opening\n\nY Combinator is seeking an exceptional individual to join their team. For this position, they will be accepting applications for only one week. Every morning, a set of new applications will ar...
def iterative_binomial_coefficient(n: int, k: int) -> int: """ Computes the binomial coefficient C(n, k) using an iterative approach. :param n: a positive integer (n >= k) :param k: a non-negative integer :return: an integer value of the binomial coefficient C(n, k) """ if k == 0 or k == n:...
simplelr_Data_Structure
[ { "content": "Question:\nGiven a positive integer `n` and a non-negative integer `k` where `n >= k`, the binomial coefficient \\( C(n, k) \\) represents the number of ways to choose `k` elements from a set of `n` elements. It is given by:\n\n\\[ C(n, k) = \\frac{n!}{k!(n-k)!} \\]\n\nThe function `recursive_bino...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7287, "level": 1, "question": "Given a positive integer `n` and a non-negative integer `k` where `n >= k`, the binomial coefficient \\( C(n, k) \\) represents the number of ways to choose `k` elements from a set of `n` elements. It is given by:\n\n\\[ C(n, k) = \\frac{n!}{k!(n-k)!} ...
def is_palindrome(n): s = str(n) return s == s[::-1]
simplelr_Filter
[ { "content": "Question:\nI need to write a function that checks if a given number is a palindrome. Can you provide me with some code examples in different programming languages?\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7288, "level": 1, "question": "I need to write a function that checks if a given number is a palindrome. Can you provide me with some code examples in different programming languages?", "split": "train" }
def is_prime(n): if n < 2: return False if n in (2, 3): return True if n % 2 == 0: return False max_divisor = int(n ** 0.5) + 1 for d in range(3, max_divisor, 2): if n % d == 0: return False return True
simplelr_Filter
[ { "content": "Question:\nWrite a simple function in Python to check if a given number is a prime number. The function should return `True` if the number is prime, and `False` otherwise. Also, provide a brief explanation of how the function works.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7289, "level": 1, "question": "Write a simple function in Python to check if a given number is a prime number. The function should return `True` if the number is prime, and `False` otherwise. Also, provide a brief explanation of how the function works.", "split": "train" }
from typing import List, Tuple from itertools import groupby from functools import reduce from operator import itemgetter, add def summarize_sales(sales_data: List[Tuple[str, int, float]]) -> List[Tuple[str, float]]: # Sort the sales data by product name sorted_data = sorted(sales_data, key=itemgetter(0)) ...
simplelr_Docs
[ { "content": "Question:\n**Question: Functional Programming in Python**\n\nYou are given a list of tuples representing the sales data of different products over several months. Each tuple contains the product name, a month (as an integer from 1 to 12), and the sales figure for that month. Your task is to write ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7290, "level": 1, "question": "**Question: Functional Programming in Python**\n\nYou are given a list of tuples representing the sales data of different products over several months. Each tuple contains the product name, a month (as an integer from 1 to 12), and the sales figure for...
import math def smallest_common_multiple(a, b): return (a * b) // math.gcd(a, b)
simplelr_Leetcode
[ { "content": "Question:\nYou are given two **positive** integers `a` and `b`. Return _the smallest positive integer `x` such that both `x % a == 0` and `x % b == 0`_.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7291, "level": 1, "question": "You are given two **positive** integers `a` and `b`. Return _the smallest positive integer `x` such that both `x % a == 0` and `x % b == 0`_.", "split": "train" }
def find_largest_palindromic_substring(s: str) -> str: n = len(s) if n == 0: return "" max_len = 1 start = 0 # Initialize DP table dp = [[False] * n for _ in range(n)] # All substrings of length 1 are palindromes for i in range(n): dp[i][i] = True ...
simplelr_Package
[ { "content": "Question:\nYou are tasked with writing a function named `find_largest_palindromic_substring` that takes a single string as an input and returns the longest palindromic substring within that string. A palindrome is a string that reads the same backward as forward, such as \"racecar\" or \"madam\".\...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7292, "level": 1, "question": "You are tasked with writing a function named `find_largest_palindromic_substring` that takes a single string as an input and returns the longest palindromic substring within that string. A palindrome is a string that reads the same backward as forward,...
def multiplyStrings(num1, num2): if num1 == "0" or num2 == "0": return "0" return str(int(num1) * int(num2))
simplelr_Taco
[ { "content": "Question:\nYou are given two non-negative integers as strings, `num1` and `num2`. Your task is to compute the product of these two numbers and return the result as a string.\n\nExample 1:\nInput:\nnum1 = \"123\", num2 = \"45\"\nOutput:\n\"5535\"\nExplanation:\n123 * 45 = 5535\n\nExample 2:\nInput:...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7293, "level": 1, "question": "You are given two non-negative integers as strings, `num1` and `num2`. Your task is to compute the product of these two numbers and return the result as a string.\n\nExample 1:\nInput:\nnum1 = \"123\", num2 = \"45\"\nOutput:\n\"5535\"\nExplanation:\n12...
def is_palindrome(s): processed = ''.join([c for c in s if c.isalnum()]).lower() return processed == processed[::-1]
simplelr_Prefill
[ { "content": "Question:\nWrite a python function to determine if a given string is a palindrome. I want the function to be case-insensitive and should ignore any non-alphanumeric characters. Non-alphanumeric characters are defined as any character that is not a letter or a digit.\nAnswer:\nLet's think step by s...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7294, "level": 1, "question": "Write a python function to determine if a given string is a palindrome. I want the function to be case-insensitive and should ignore any non-alphanumeric characters. Non-alphanumeric characters are defined as any character that is not a letter or a dig...
def minimum_moves(arr, target): if not arr: return 0 count = 0 for num in arr: if num != target: count += 1 return count
simplelr_Taco
[ { "content": "Question:\nYou are given an array of integers and a target value. In one move, you can change any integer in the array to any other integer. Determine the minimum number of moves required to make all elements of the array equal to the target value.\n\nFor Example:\n\n* If the array is `[1, 2, 3]` ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7295, "level": 1, "question": "You are given an array of integers and a target value. In one move, you can change any integer in the array to any other integer. Determine the minimum number of moves required to make all elements of the array equal to the target value.\n\nFor Example...
def double_positive(nums): return [num * 2 if num > 0 else num for num in nums]
simplelr_Apps
[ { "content": "Question:\n## Kata Task\n\nWrite a function that takes in a list of integers and returns a new list with each element doubled. However, the function should exclude any integers that are negative or zero when doubling and include them in their original form in the output.\n\n### Example\nGiven the ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7296, "level": 1, "question": "## Kata Task\n\nWrite a function that takes in a list of integers and returns a new list with each element doubled. However, the function should exclude any integers that are negative or zero when doubling and include them in their original form in the...
def greet(name=None): if name is None: return "Hello, World!" else: return f"Hello, {name}!" # Example usage: print(greet()) # Outputs: Hello, World! print(greet("Alice")) # Outputs: Hello, Alice!
simplelr_Prefill
[ { "content": "Question:\nCreate a function that accepts an optional parameter.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7297, "level": 1, "question": "Create a function that accepts an optional parameter.", "split": "train" }
def find_first_event_timestamp(logs, event): for log in logs: time_part, _, event_part = log.partition(' ') if event_part == event: return time_part return "Event not found"
simplelr_Apps
[ { "content": "Question:\n# Task\nYou are given a list of strings representing log entries. Each log entry is in the format of \"hh:mm:ss event\", where \"hh:mm:ss\" is a time stamp and \"event\" is an event description. Your objective is to identify the time stamp of the first occurrence of a specific event.\n\...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7298, "level": 1, "question": "# Task\nYou are given a list of strings representing log entries. Each log entry is in the format of \"hh:mm:ss event\", where \"hh:mm:ss\" is a time stamp and \"event\" is an event description. Your objective is to identify the time stamp of the first...
def find_minimum_bribes(queue): n = len(queue) for i in range(n): current_pos = i + 1 # 1-based current position original_pos = queue[i] if current_pos < original_pos - 2: return "Too chaotic" bribes = 0 for i in range(n): for j in range(i): ...
simplelr_Package
[ { "content": "Question:\nIn this problem, you are required to create a function `find_minimum_bribes` that calculates the minimum number of bribes required for people to achieve their positions in a queue. The function will assess the given queue and identify if it is possible to determine the number of bribes....
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 7299, "level": 1, "question": "In this problem, you are required to create a function `find_minimum_bribes` that calculates the minimum number of bribes required for people to achieve their positions in a queue. The function will assess the given queue and identify if it is possible...