Dataset Viewer
Auto-converted to Parquet Duplicate
context
listlengths
1
1
gen_kwargs
dict
repeat_idx
int64
0
4
request_idx
int64
0
510
task_name
stringclasses
6 values
metadata
dict
model_outputs
stringlengths
11
188k
[ { "content": "Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.There are three cards with letters $\\texttt{a}$, $\\texttt{b}$, $\\texttt{c}$ placed in a row in some order. You can ...
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
0
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
def check_cards(s): if s == "abc": return "YES" elif s == "bac": return "YES" elif s == "acb": return "YES" elif s == "cba": return "YES" else: return "NO" if __name__ == "__main__": import sys input = sys.stdin.read data = input().split() t...
[ { "content": "Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Slavic is preparing a present for a friend's birthday. He has an array $a$ of $n$ digits and the present will be the p...
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
1
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
def max_product(): import sys input = sys.stdin.read data = input().split() t = int(data[0]) index = 1 for _ in range(t): n = int(data[index]) index += 1 a = list(map(int, data[index:index + n])) index += n max_product = 1 for i in range(n): ...
[ { "content": "Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.You are given a strip of paper $s$ that is $n$ cells long. Each cell is either black or white. In an operation you can...
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
2
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
In the fourth test case you can perform the following operations: $$\texttt{B}\color{red}{\texttt{BBBBB}} \to \color{red}{\texttt{BBBBB}}\texttt{B} \to \texttt{WWWWWWWW}$$ In the fifth test case you can perform the following operations: $$\color{red}{\texttt{B}}\texttt{W}\color{red}{\texttt{B}}\texttt{W}\color{red}{...
[ { "content": "Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.You are given a string $s$ of length $n$, consisting of lowercase Latin letters, and an integer $k$.\n\nYou need to ch...
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
3
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
Here's the Python function to solve the given problem: ```python def can_form_palindrome(): import sys input = sys.stdin.read data = input().split() t = int(data[0]) index = 1 for _ in range(t): n, k = int(data[index]), int(data[index + 1]) index += 2 s = data...
[ { "content": "Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.You are given an array of integers $a_1, a_2, \\ldots, a_n$ and a number $k$ ($2 \\leq k \\leq 5$). In one operation, ...
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
4
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
To solve the given problem, we need to determine the minimum number of operations required to make the product of the array elements divisible by \( k \). Here's a step-by-step approach: 1. **Input Parsing**: Read the number of test cases, and for each test case, read the size of the array \( n \) and the number \( k...
[ { "content": "Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Vanya and Vova are playing a game. Players are given an integer $n$. On their turn, the player can add $1$ to the curr...
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
5
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
To solve the given problem, we need to determine the winner based on the given rules. Here is the Python function that implements the logic for determining the winner based on the integer \( n \): ```python def determine_winner(n): # If n is already divisible by 3, Vanya wins immediately if n % 3 == 0: ...
[ { "content": "Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Alex is participating in the filming of another video of BrMeast, and BrMeast asked Alex to prepare 250 thousand tons ...
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
6
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
Here's the Python function to solve the given problem: ```python def max_weight_difference(): import sys input = sys.stdin.read data = input().split() t = int(data[0]) index = 1 results = [] for _ in range(t): n = int(data[index]) index += 1 weights = [int...
[ { "content": "Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.A subarray is a continuous part of array.\n\nYarik recently found an array $a$ of $n$ elements and became very interes...
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
7
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
Here's the Python function to solve the problem as described: ```python def max_alternating_subarray_sum(): import sys input = sys.stdin.read data = input().split() t = int(data[0]) results = [] for i in range(0, t * 3, 3): n = int(data[i + 1]) arr = [int(data[i + j]) for j in ...
[ { "content": "Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Yarik is a big fan of many kinds of music. But Yarik loves not only listening to music but also writing it. He likes e...
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
8
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
def count_equal_combinations(): import sys input = sys.stdin.read inputs = input().split() t = int(inputs[0]) index = 1 results = [] for _ in range(t): n = int(inputs[index]) index += 1 a = list(map(int, inputs[index:index + n])) index += n ...
[ { "content": "Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.You are given a 0-indexed array of strings details. Each element of details provides information about a given passenger compressed into a string of length 15....
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
9
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
Here's the Python function to solve the problem: ```python def count_passengers_over_60(details): count = 0 for detail in details: age = int(detail[11:13]) if age > 60: count += 1 return count ```
[ { "content": "Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.You are given a 0-indexed 2D integer array nums. Initially, your score is 0. Perform the following operations until the matrix becomes empty:\n\nFrom each row ...
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
10
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
def maxMatrixScore(nums): Assistant: ```python def maxMatrixScore(nums): score = 0 while nums: max_val = 0 max_row = -1 # Select the largest number from each row for i, row in enumerate(nums): row.sort(reverse=True) max_val = max(max_val, row[0]) ...
[ { "content": "Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.You are given a 0-indexed integer array nums of length n and an integer k. In an operation, you can choose an element and multiply it by 2.\nReturn the maximum...
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
11
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
def maxOrAfterOperations(nums: List[int], k: int) -> int:
[ { "content": "Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.You are given a 0-indexed integer array nums representing the score of students in an exam. The teacher would like to form one non-empty group of students with...
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
12
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
Here's the function body for the given problem: ```python def maxStrength(nums): # Sort the array to handle negative and positive numbers effectively nums.sort() # If all numbers are zero, return 0 if len(nums) == 0: return 0 # Remove all zeros as they don't contribute to the str...
[ { "content": "Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.You are given a 0-indexed string s and a dictionary of words dictionary. You have to break s into one or more non-overlapping substrings such that each substri...
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
13
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
. def minExtraChar(s: str, dictionary: list) -> int: n = len(s) dp = [n] * (n + 1) dp[n] = 0 for i in range(n - 1, -1, -1): dp[i] = dp[i + 1] + 1 for word in dictionary: if s.startswith(word, i): dp[i] = min(dp[i], dp[i + len(word)]) return dp[0] if dp[0...
[ { "content": "Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.You are given an integer array prices representing the prices of various chocolates in a store. You are also given a single integer money, which represents you...
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
14
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
def minMoneyLeft(prices, money): ```python def minMoneyLeft(prices, money): min_price1 = min(prices) prices.remove(min_price1) min_price2 = min(prices) total_cost = min_price1 + min_price2 leftover = money - total_cost return leftover if leftover >= 0 else money ```
[ { "content": "Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.You are given two numeric strings num1 and num2 and two integers max_sum and min_sum. We denote an integer x to be good if:\n\nnum1 <= x <= num2\nmin_sum <= di...
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
15
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
def countGoodIntegers(num1: str, num2: str, min_sum: int, max_sum: int) -> int: To solve this problem, we can use a dynamic programming approach with memoization to count the number of good integers between `num1` and `num2` that satisfy the given constraints. Here's a Python function that implements this approach:...
[ { "content": "Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.You are given a 0-indexed array nums of length n.\nThe distinct difference array of nums is an array diff of length n such that diff[i] is equal to the number ...
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
16
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
def distinct_difference_array(nums): # Your implementation here pass def distinct_difference_array(nums): n = len(nums) prefix_counts = [0] * n suffix_counts = [0] * n prefix_unique = set() suffix_unique = set() for i in range(n): prefix_unique.add(nums[i]) prefix_c...
[ { "content": "Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.There is a 0-indexed array nums of length n. Initially, all elements are uncolored (has a value of 0).\nYou are given a 2D integer array queries where queries[...
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
17
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
def solution(n, queries): # Your implementation here pass def solution(n, queries): nums = [0] * n answer = [] for index, color in queries: nums[index] = color count = 0 for i in range(n - 1): if nums[i] == nums[i + 1] and nums[i] != 0: coun...
[ { "content": "Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.You are given a 0-indexed integer array nums representing the strength of some heroes. The power of a group of heroes is defined as follows:\n\nLet i_0, i_1, ....
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
18
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
Here's the function body for the given problem: ```python def sumOfPower(nums): nums.sort() result = 0 MOD = 10**9 + 7 prefix_sum = 0 for num in nums: # Calculate the power of the current number as a single group result = (result + (num**3 + num * prefix_sum) % MOD) % MOD ...
[ { "content": "Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.You are given a 0-indexed permutation of n integers nums.\nA permutation is called semi-ordered if the first number equals 1 and the last number equals n. You ...
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
19
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
def min_operations_to_semi_ordered(nums): n = len(nums) index1, indexn = nums.index(1), nums.index(n) # If 1 is already at the first position and n is already at the last position if index1 == 0 and indexn == n - 1: return 0 operations = 0 # Move 1 to the first position ...
[ { "content": "Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.You are given a 0-indexed string s that consists of digits from 0 to 9.\nA string t is called a semi-repetitive if there is at most one consecutive pair of the...
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
20
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
Here's the executable Python function based on the given prompt: ```python def longestSemiRepetitiveSubstring(s: str) -> int: max_length = 0 start = 0 consecutive_count = 0 for end in range(len(s)): if end > 0 and s[end] == s[end - 1]: consecutive_count += 1 w...
[ { "content": "Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.There are n friends that are playing a game. The friends are sitting in a circle and are numbered from 1 to n in clockwise order. More formally, moving clockwi...
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
21
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
def findLosers(n: int, k: int): pass def findLosers(n: int, k: int): received_ball = set() current_friend = 1 turn = 1 while current_friend not in received_ball: received_ball.add(current_friend) next_friend = (current_friend + turn * k) % n if next_friend == 0: ...
[ { "content": "Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.A 0-indexed array derived with length n is derived by computing the bitwise XOR (⊕) of adjacent values in a binary array original of length n.\nSpecifically, f...
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
22
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
. def can_form_binary_array(derived): n = len(derived) # XOR the entire derived array xor_result = 0 for i in range(n): xor_result ^= derived[i] # If the result is 0, it's possible to form a binary array return xor_result == 0 The function `can_form_binary_array` takes the `derived` arr...
[ { "content": "Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.You are given a string s consisting only of uppercase English letters.\nYou can apply some operations to this string where, in one operation, you can remove an...
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
23
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
def min_length(s: str) -> int: stack = [] for char in s: if char == 'B' and stack and stack[-1] == 'A': stack.pop() elif char == 'D' and stack and stack[-1] == 'C': stack.pop() else: stack.append(char) return len(stack)
[ { "content": "Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given a positive integer n, return the punishment number of n.\nThe punishment number of n is defined as the sum of the squares of all integers i such that:\n\...
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
24
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
To solve the given problem, we need to implement a function that calculates the punishment number of a given positive integer \( n \). The function should check each integer \( i \) from 1 to \( n \) and determine if the square of \( i \) can be partitioned into contiguous substrings that sum to \( i \). If such a par...
[ { "content": "Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.You are given two 0-indexed integer arrays, cost and time, of size n representing the costs and the time taken to paint n different walls respectively. There a...
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
25
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
def min_cost(cost, time): """Return the minimum amount of money required to paint the n walls.""" Putting together the problem, we need to find the minimum cost to paint all walls, considering the cost and time for the paid painter, and the free painter's availability. We can solve this problem using dynamic pr...
[ { "content": "Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.You are given a 0-indexed integer array nums and an integer threshold.\nFind the length of the longest subarray of nums starting at index l and ending at index...
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
52
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
To solve this problem, we need to iterate through the array and find the longest subarray that meets the specified conditions. Here’s the function that accomplishes this: ```python def longest_valid_subarray(nums, threshold): max_length = 0 current_length = 0 start_index = 0 for i in range(len(nu...
[ { "content": "Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.You are given a binary array nums.\nA subarray of an array is good if it contains exactly one element with the value 1.\nReturn an integer denoting the number ...
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
53
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
Here's the function body for the given problem: ```python def numberOfGoodSubarraySplits(nums): MOD = 10**9 + 7 count = 0 prev_one = -1 for i, num in enumerate(nums): if num == 1: if count == 0: count = 1 else: count *= (i - prev_on...
[ { "content": "Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.You are given a 0-indexed integer array nums. A subarray of nums is called continuous if:\n\nLet i, i + 1, ..., j_ be the indices in the subarray. Then, for ea...
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
54
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
Here's the function body for the given problem: ```python def countContinuousSubarrays(nums): n = len(nums) result = 0 left = 0 max_val = nums[0] min_val = nums[0] for right in range(n): max_val = max(max_val, nums[right]) min_val = min(min_val, nums[right]) while max...
[ { "content": "Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.You are given two 0-indexed integer arrays nums1 and nums2 of length n.\nLet's define another 0-indexed integer array, nums3, of length n. For each index i in ...
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
55
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
def maxNonDecreasingLength(nums1, nums2): # Your implementation here pass def maxNonDecreasingLength(nums1, nums2): n = len(nums1) dp = [[1, 1] for _ in range(n)] for i in range(1, n): if nums1[i] >= nums1[i - 1]: dp[i][0] = max(dp[i][0], dp[i - 1][0] + 1) if nums1[i] ...
[ { "content": "Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.You are given a 0-indexed integer array nums. A subarray s of length m is called alternating if:\n\nm is greater than 1.\ns_1 = s_0 + 1.\nThe 0-indexed subarra...
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
56
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
def maxAlternatingSubarrayLength(nums): # Your implementation here To solve the problem, we can use a sliding window approach to find the longest alternating subarray. Here is the implementation of the function `maxAlternatingSubarrayLength`: ```python def maxAlternatingSubarrayLength(nums): n = len(nums) ...
[ { "content": "Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.You are given a 0-indexed array nums consisting of positive integers.\nYou can do the following operation on the array any number of times:\n\nChoose an intege...
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
57
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
Assistant: ```python def maxArrayValue(nums): n = len(nums) for i in range(n - 2, -1, -1): if nums[i] <= nums[i + 1]: nums[i + 1] += nums[i] return max(nums) ```
[ { "content": "Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.You are given an integer n. We say that two integers x and y form a prime number pair if:\n\n1 <= x <= y <= n\nx + y == n\nx and y are prime numbers\n\nReturn ...
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
58
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
Here's the function body for the given problem: ```python def prime_pairs(n): def is_prime(num): if num <= 1: return False for i in range(2, int(num ** 0.5) + 1): if num % i == 0: return False return True primes = [i for i in range(2, n) if is_...
[ { "content": "Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.There are n employees in a company, numbered from 0 to n - 1. Each employee i has worked for hours[i] hours in the company.\nThe company requires each employee...
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
59
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
To solve this problem, we need to count the number of employees who have worked at least the target number of hours. Here's the function that accomplishes this: ```python def count_employees_meeting_target(hours, target): # Use a generator expression to count employees meeting the target return sum(1 for hour...
[ { "content": "Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given three strings a, b, and c, your task is to find a string that has the minimum length and contains all three strings as substrings.\nIf there are multiple...
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
60
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
def smallestSuperstring(a, b, c): def merge(x, y): for i in range(len(y) + 1): if y[:i] == x[-i:]: return x + y[i:] return x + y # Create all possible pairs of strings and merge them pairs = [(a, b), (a, c), (b, a), (b, c), (c, a), (c, b)] merged_pairs = [(m...
[ { "content": "Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.You are given a 0-indexed integer array nums and a positive integer k.\nYou can apply the following operation on the array any number of times:\n\nChoose any s...
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
61
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
Assistant: ```python def canMakeAllZero(nums, k): n = len(nums) prefix_sum = [0] * (n + 1) for i in range(n): prefix_sum[i + 1] = prefix_sum[i] + nums[i] for i in range(n): if nums[i] > 0: target = prefix_sum[min(i + k, n)] - prefix_sum[i] if target < ...
[ { "content": "Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given a string s and an integer k, partition s into k substrings such that the sum of the number of letter changes required to turn each substring into a semi-...
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
62
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
def minLetterChanges(s, k): n = len(s) # Helper function to count the number of letter changes needed to make a substring a semi-palindrome def count_changes(substring): changes = 0 length = len(substring) for i in range(length // 2): if substring[i] != substring[length...
[ { "content": "Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given an array of strings words and a character separator, split each string in words by separator.\nReturn an array of strings containing the new strings form...
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
63
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
To solve this problem, we need to iterate over each string in the `words` list, split it using the given `separator`, and then filter out any empty strings from the resulting list. Here is the Python function to achieve this: ```python def split_words(words, separator): result = [] for word in words: ...
[ { "content": "Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given two positive integers n and x.\nReturn the number of ways n can be expressed as the sum of the x^th power of unique positive integers, in other words, th...
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
64
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
def sumOfPower(n: int, x: int): ```python def sumOfPower(n: int, x: int) -> int: MOD = 10**9 + 7 def helper(target, start): if target == 0: return 1 if target < 0: return 0 count = 0 for i in range(start, int(target**(1/x)) + 1): count += h...
[ { "content": "Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given a binary string s, partition the string into one or more substrings such that each substring is beautiful.\nA string is beautiful if:\n\nIt doesn't conta...
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
65
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
Here's a Python function that solves the problem: ```python def min_beautiful_partitions(s: str) -> int: # Powers of 5 in binary form that are <= 2^15 powers_of_5 = ['1', '101', '11001', '1111101', '100110001', '1100001001'] n = len(s) dp = [float('inf')] * (n + 1) dp[0] = 0 # Base case: 0...
[ { "content": "Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.You are given a string word and an array of strings forbidden.\nA string is called valid if none of its substrings are present in forbidden.\nReturn the length...
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
66
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
def longestValidSubstring(word: str, forbidden: List[str]) -> int: max_length = 0 forbidden_set = set(forbidden) for start in range(len(word)): for end in range(start + 1, len(word) + 1): substring = word[start:end] if substring in forbidden_set: max_len...
[ { "content": "Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Your laptop keyboard is faulty, and whenever you type a character 'i' on it, it reverses the string that you have written. Typing other characters works as exp...
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
67
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
To solve this problem, we need to simulate the typing process on a faulty keyboard. When a character 'i' is typed, the current string should be reversed. Here's the function to achieve this: ```python def finalString(s: str) -> str: result = [] for char in s: if char == 'i': result = resul...
[ { "content": "Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given a 0-indexed string s, permute s to get a new string t such that:\n\nAll consonants remain in their original places. More formally, if there is an index i...
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
68
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
To solve the given problem, we need to create a function that rearranges the string `s` by keeping consonants in their original positions and sorting the vowels in non-decreasing order of their ASCII values. Here's the Python function to achieve this: ```python def sortVowels(s: str) -> str: # Define a set of vow...
[ { "content": "Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.An element x of an integer array arr of length m is dominant if freq(x) * 2 > m, where freq(x) is the number of occurrences of x in arr. Note that this definit...
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
69
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
def minValidSplit(nums):
[ { "content": "Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.You are given a 0-indexed array nums and a non-negative integer k.\nIn one operation, you can do the following:\n\nChoose an index i that hasn't been chosen be...
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
70
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
Here's the function body for the given problem: ```python def max_beauty(nums, k): # Sort the array to facilitate finding the maximum subsequence length nums.sort() max_beauty = 0 for i in range(len(nums)): # Calculate the potential range after applying the operation start = nums[...
[ { "content": "Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.You are given an integer array nums. We consider an array good if it is a permutation of an array base[n].\nbase[n] = [1, 2, ..., n - 1, n, n] (in other words,...
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
71
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
Here's the function body for the given problem: ```python def isGood(nums): n = len(nums) - 1 if len(nums) != n + 1: return False count = [0] * (n + 1) for num in nums: if num > n or count[num] > 1: return False count[num] += 1 return count[n] == 2 and...
[ { "content": "Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.You are given a 0-indexed integer array nums and a positive integer x.\nYou are initially at position 0 in the array and you can visit other positions accordin...
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
72
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
0 <= i < j < nums.length To solve this problem, we can use dynamic programming to keep track of the maximum score we can achieve while considering the parity of the numbers. Here's the Python function to achieve this: ```python def maxScore(nums, x): n = len(nums) dp = [[0, 0] for _ in range(n)] # dp[i][0] f...
[ { "content": "Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.You are given a 0-indexed integer array nums. You have to find the maximum sum of a pair of numbers from nums such that the maximum digit in both numbers are e...
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
73
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
Assistant: ```python def max_sum_equal_max_digit(nums): max_sum = -1 n = len(nums) for i in range(n): for j in range(i + 1, n): if max_digit(nums[i]) == max_digit(nums[j]): max_sum = max(max_sum, nums[i] + nums[j]) return max_sum def max_digit(num): r...
[ { "content": "Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.You are given a 0-indexed integer array nums, an integer modulo, and an integer k.\nYour task is to find the count of subarrays that are interesting.\nA subarr...
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
74
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
Assistant: ```python def count_interesting_subarrays(nums, modulo, k): count = 0 prefix_count = 0 freq = {0: 1} for num in nums: if num % modulo == k: prefix_count += 1 target = (prefix_count % modulo - k + modulo) % modulo count += freq.get(target, 0)...
[ { "content": "Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.You are given an array nums of length n and an integer m. You need to determine if it is possible to split the array into n non-empty arrays by performing a se...
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
75
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
Here's the function body for the given problem: ```python def can_split_array(nums, m): n = len(nums) # If the array can be split into n arrays, the array must have at least n-1 splits # A single element array can always be split into n arrays trivially if n <= 2: return True # C...
[ { "content": "Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given a 0-indexed integer array nums of length n and an integer target, return the number of pairs (i, j) where 0 <= i < j < n and nums[i] + nums[j] < target.\...
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
76
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
def count_pairs(nums, target): count = 0 n = len(nums) for i in range(n): for j in range(i+1, n): if nums[i] + nums[j] < target: count += 1 return count ... def count_pairs(nums, target): count = 0 n = len(nums) for i in range(n): for j in rang...
[ { "content": "Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.You are given a 0-indexed array usageLimits of length n.\nYour task is to create groups using numbers from 0 to n - 1, ensuring that each number, i, is used no...
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
77
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
def maxGroups(usageLimits): # Your implementation here pass def maxGroups(usageLimits): n = len(usageLimits) usageLimits.sort() total = 0 count = 0 for i in range(n): total += usageLimits[i] if total >= (count + 1) * (count + 2) // 2: count += 1 return coun...
[ { "content": "Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.You are given a 0-indexed array nums containing n integers.\nAt each second, you perform the following operation on the array:\n\nFor every index i in the rang...
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
78
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
Assistant: ```python def min_seconds_to_equalize(nums): from collections import defaultdict # Create a dictionary to store the indices of each value in nums value_indices = defaultdict(list) for i, num in enumerate(nums): value_indices[num].append(i) # Calculate the maximum dista...
[ { "content": "Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given two positive integers low and high represented as strings, find the count of stepping numbers in the inclusive range [low, high].\nA stepping number is a...
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
79
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
def countSteppingNumbers(low: str, high: str) -> int: MOD = 10**9 + 7 def isSteppingNumber(num): num_str = str(num) for i in range(len(num_str) - 1): if abs(int(num_str[i]) - int(num_str[i+1])) != 1: return False return True def countUpTo(n): c...
[ { "content": "Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.You are given two 0-indexed integer arrays nums1 and nums2 of equal length. Every second, for all indices 0 <= i < nums1.length, value of nums1[i] is increment...
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
80
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
def minTimeToMakeSumLessOrEqual(nums1, nums2, x): # your code here pass def minTimeToMakeSumLessOrEqual(nums1, nums2, x): n = len(nums1) total_sum = sum(nums1) dp = [0] * (n + 1) for i in range(n): nums1[i] += nums2[i] for i in range(n): for j in range(n, 0, -1): ...
[ { "content": "Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.You are given a 2D integer array coordinates and an integer k, where coordinates[i] = [x_i, y_i] are the coordinates of the i^th point in a 2D plane.\nWe defin...
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
81
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
0 ```python def count_pairs(coordinates, k): # Your implementation here ``` ```python def count_pairs(coordinates, k): count = 0 n = len(coordinates) for i in range(n): for j in range(i + 1, n): dist = (coordinates[i][0] ^ coordinates[j][0]) + (coordinates[i][1] ^ coordinates[j][1])...
[ { "content": "Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.You are given an integer array nums and two positive integers m and k.\nReturn the maximum sum out of all almost unique subarrays of length k of nums. If no su...
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
82
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
def maxSumAlmostUniqueSubarray(nums, m, k):
[ { "content": "Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Initially, you have a bank account balance of 100 dollars.\nYou are given an integer purchaseAmount representing the amount you will spend on a purchase in dol...
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
83
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
def calculate_balance(purchaseAmount): # Your code here # Return the account balance after the purchase pass Certainly! Here is the Python function that implements the logic described in the prompt: ```python def calculate_balance(purchaseAmount): # Round the purchase amount to the nearest multiple ...
[ { "content": "Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given an array of strings words and a string s, determine if s is an acronym of words.\nThe string s is considered an acronym of words if it can be formed by c...
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
84
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
def isAcronym(words, s): # Check if the length of s matches the number of words if len(s) != len(words): return False # Iterate through each word and check if the first character matches the corresponding character in s for i in range(len(words)): if words[i][0] != s[i]: ...
[ { "content": "Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.You are given an integer n representing the number of houses on a number line, numbered from 0 to n - 1.\nAdditionally, you are given a 2D integer array offers...
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
85
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
To solve this problem, we can use dynamic programming to keep track of the maximum gold we can earn by selling houses up to each house. Here's the function body to achieve this: ```python def maximizeGold(n, offers): # Create a dictionary to store the maximum gold we can earn up to each house max_gold = {i: 0...
[ { "content": "Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.You are given two positive integers low and high.\nAn integer x consisting of 2 * n digits is symmetric if the sum of the first n digits of x is equal to the s...
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
86
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
def countSymmetricIntegers(self, low: int, high: int) -> int: # Your code goes here pass def countSymmetricIntegers(self, low: int, high: int) -> int: count = 0 for x in range(low, high + 1): s = str(x) if len(s) % 2 == 0: n = len(s) // 2 if sum(int(s[i]) for i ...
[ { "content": "Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.You are given two strings s1 and s2, both of length 4, consisting of lowercase English letters.\nYou can apply the following operation on any of the two string...
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
87
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
def canMakeEqual(s1: str, s2: str) -> bool: # Check if the characters at even indices are the same in both strings if s1[0] != s2[0] or s1[2] != s2[2]: return False # Check if the characters at odd indices are the same in both strings if s1[1] != s2[1] or s1[3] != s2[3]: return Fal...
[ { "content": "Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.You are given a 0-indexed integer array nums and an integer x.\nFind the minimum absolute difference between two elements in the array that are at least x indi...
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
88
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
def minimum_absolute_difference(nums, x): To solve this problem, we can use a sliding window approach to find the minimum absolute difference between two elements that are at least `x` indices apart. Here's the implementation of the function: ```python def minimum_absolute_difference(nums, x): n = len(nums) ...
[ { "content": "Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.You are given positive integers low, high, and k.\nA number is beautiful if it meets both of the following conditions:\n\nThe count of even digits in the numbe...
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
89
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
def beautifulIntegers(low: int, high: int, k: int): """ This function counts the number of beautiful integers in the range [low, high]. A number is beautiful if it meets the following conditions: - The count of even digits in the number is equal to the count of odd digits. - The number is divisibl...
[ { "content": "Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.You are given two 0-indexed strings str1 and str2.\nIn an operation, you select a set of indices in str1, and for each index i in the set, increment str1[i] to...
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
90
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
def isPossibleSubsequence(str1: str, str2: str) -> bool:
[ { "content": "Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.You are given a string moves of length n consisting only of characters 'L', 'R', and '_'. The string represents your movement on a number line starting from th...
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
91
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
def furthest_distance(moves: str) -> int: # Your implementation goes here pass def furthest_distance(moves: str) -> int: left_count = moves.count('L') right_count = moves.count('R') underscore_count = moves.count('_') if left_count > right_count: return left_count - right_count +...
[ { "content": "Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.You are given two strings s and t of equal length n. You can perform the following operation on the string s:\n\nRemove a suffix of s of length l where 0 < l <...
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
92
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
def count_transformations(s, t, k): MOD = 10**9 + 7 def count_ways(index, k): if k == 0: return 1 if s == t else 0 if k < 0: return 0 ways = 0 for i in range(1, len(s)): if s[(index + i) % len(s)] == t[i - 1]: ways += count_wa...
[ { "content": "Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.You are given a 0-indexed array nums consisting of non-negative powers of 2, and an integer target.\nIn one operation, you must apply the following changes to ...
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
93
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
def min_operations_to_sum(nums, target): ```python def min_operations_to_sum(nums, target): # Convert nums to a frequency array where freq[i] represents the number of occurrences of 2^i freq = [0] * 31 for num in nums: freq[int(log2(num))] += 1 # Convert target to a binary representation ...
[ { "content": "Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given a 0-indexed 2D integer matrix grid of size n * m, we define a 0-indexed 2D matrix p of size n * m as the product matrix of grid if the following conditio...
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
94
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
Assistant: ```python def productExceptSelf(grid): n, m = len(grid), len(grid[0]) prefix_product = [1] * (m + 1) suffix_product = [1] * (m + 1) # Calculate prefix product for each row for i in range(n): for j in range(m): prefix_product[j + 1] = (prefix_product[j] * grid[i]...
[ { "content": "Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.You are given a 0-indexed integer array receiver of length n and an integer k.\nThere are n players having a unique id in the range [0, n - 1] who will play a ...
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
95
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
def maxFunctionValue(receiver: List[int], k: int) -> int: pass ```python def maxFunctionValue(receiver: List[int], k: int) -> int: n = len(receiver) max_value = 0 def dfs(x, k): if k == 0: return x return x + dfs(receiver[x], k - 1) for i in range(n): ...
[ { "content": "Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.You are given two 0-indexed binary strings s1 and s2, both of length n, and a positive integer x.\nYou can perform any of the following operations on the strin...
{ "do_sample": false, "max_new_tokens": 32768, "seed": 0, "temperature": 0.7 }
0
96
LiveCodeBench
{ "expected_answer": "", "problem_id": "", "reference_solution": "" }
Here's the function signature: ```python def minCostToMakeEqual(s1: str, s2: str, x: int) -> int: ``` ```python def minCostToMakeEqual(s1: str, s2: str, x: int) -> int: n = len(s1) diff_indices = [i for i in range(n) if s1[i] != s2[i]] if not diff_indices: return 0 dp = [[float('inf')]...
End of preview. Expand in Data Studio

No dataset card yet

Downloads last month
7