version
stringclasses
1 value
style
stringclasses
2 values
subset
stringclasses
12 values
question_id
stringlengths
9
23
question
stringlengths
27
8.13k
solution
stringlengths
99
5.97k
test
stringlengths
105
4.45k
test_info
listlengths
0
13
gpt_pass_sequence
listlengths
1
10
gpt_pass_trial_num
int64
1
10
gpt_difficulty
stringclasses
3 values
gpt_pass_percentage
float64
0.1
1
trials
dict
chosen_trial
stringclasses
10 values
metadata
dict
benchmark_similarity
float64
0.16
0.93
benchmark_instruction
stringclasses
1 value
benchmark_task_id
stringclasses
1 value
filter_reason
stringclasses
1 value
base_id
stringlengths
7
21
variant
stringclasses
2 values
top_function_names
listlengths
2
13
n_top_functions
int64
2
13
helper_call_edges
listlengths
1
16
n_helper_call_edges
int64
1
16
harness_functions
listlengths
0
3
structural_wrapper
bool
1 class
class_names
listlengths
0
5
has_class
bool
2 classes
test_kind
stringclasses
1 value
test_has_solution_import
bool
2 classes
third_party_imports
listlengths
0
5
stdlib_only
bool
2 classes
question_norm_sha1
stringlengths
40
40
solution_ast_sha1
stringlengths
40
40
v1.0
complete
Leetcode
Leetcode_27401_C
def find_minimum_pages(A: List[int], N: int, K: int) -> int: """ Allocate books to students such that the maximum number of pages assigned to a student is minimized. Each student must be assigned at least one book and books must be assigned contiguously. Args: A (List[int]): List of integers repres...
def is_valid_distribution(A, N, K, max_pages): required_students = 1 current_pages = 0 for pages in A: if current_pages + pages > max_pages: required_students += 1 current_pages = pages if required_students > K: return False else: ...
from solution import find_minimum_pages def test_find_minimum_pages_general_case(): A = [12, 34, 67, 90] K = 2 assert find_minimum_pages(A, len(A), K) == 113 def test_find_minimum_pages_more_students_than_books(): A = [12, 34, 67, 90] K = 5 assert find_minimum_pages(A, len(A), K) == -1 def te...
[ { "docstring": null, "function_declaration": "def is_valid_distribution(A, N, K, max_pages):", "function_name": "is_valid_distribution", "parameter_list": "(A, N, K, max_pages)" }, { "docstring": null, "function_declaration": "def find_minimum_pages(A, N, K):", "function_name": "find...
[ 0, 0, 1, 0, 1, 1, 0, 0, 0, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_feasible(A, N, K, mid):\n student_count = 1\n current_sum = 0\n \n for pages in A:\n if pages > mid:\n return False\n \n if...
trial_gpt4o_5
{ "original_instruction": "You are given an array of integers `A` and an integer `K`. The array represents the **number of pages** in `N` books, and `K` represents the number of students. The task is to allocate books to each student in such a way that the **maximum number of pages** assigned to a student is minimize...
0.700973
Leetcode_27401
C
[ "is_valid_distribution", "find_minimum_pages" ]
2
[ [ "find_minimum_pages", "is_valid_distribution" ] ]
1
[]
false
[]
false
pytest
true
[]
true
127763f54c404e7ed67bf48913f38912bf6b7b26
3eacffcdd95fa1f6c831f24bd96143d2d76c4d1e
v1.0
complete
Leetcode
Leetcode_27770_C
def max_sum_submatrix(matrix): """Returns the maximum sum of any rectangular submatrix. The submatrix must contain at least one element. >>> max_sum_submatrix([ ... [1, -2], ... [-1, 2] ... ]) == 2 >>> max_sum_submatrix([ ... [1, 2], ... [3, 4] ... ]) == 10 ...
def max_sum_submatrix(matrix): """ Returns the maximum sum of any rectangular submatrix. """ m, n = len(matrix), len(matrix[0]) if matrix else 0 max_sum = float('-inf') for left in range(n): temp = [0] * m for right in range(left, n): for i in range(m): ...
from solution import max_sum_submatrix def test_max_sum_simple(): matrix = [ [1, -2], [-1, 2] ] assert max_sum_submatrix(matrix) == 2 def test_max_sum_with_all_positive(): matrix = [ [1, 2], [3, 4] ] assert max_sum_submatrix(matrix) == 10 def test_max_sum_with_...
[ { "docstring": "Returns the maximum sum of any rectangular submatrix.", "function_declaration": "def max_sum_submatrix(matrix):", "function_name": "max_sum_submatrix", "parameter_list": "(matrix)" }, { "docstring": "Helper function to find the maximum sum of a subarray.", "function_decla...
[ 0, 0, 1, 1, 0, 0, 0, 0, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def max_sum_submatrix(matrix):\n if not matrix or not matrix[0]:\n return 0\n\n def kadane(arr):\n max_sum = current_sum = arr[0]\n for num in arr[...
trial_gpt4o_3
{ "original_instruction": "Given a `m x n` matrix of integers `matrix`, return the _maximum sum of any rectangular submatrix_. The submatrix must contain at least one element, and the sum refers to the sum of all elements in the submatrix.", "prompt_id": "0000027770", "row_id": 27770, "seed_ids": "['1619', '44...
0.620527
Leetcode_27770
C
[ "max_sum_submatrix", "max_subarray_sum" ]
2
[ [ "max_sum_submatrix", "max_subarray_sum" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b0e6ad32e24b4c53291053e13b15a3a7360f63e4
7b205c6d40310a7ac28d73476b0f600c6cd4d44a
v1.0
complete
Leetcode
Leetcode_28007_C
def min_adjacent_swaps_to_sort(nums: List[int]) -> int: """ Return the minimum number of adjacent swaps required to sort the list. >>> min_adjacent_swaps_to_sort([1, 2, 3, 4, 5]) 0 >>> min_adjacent_swaps_to_sort([5, 4, 3, 2, 1]) 10 >>> min_adjacent_swaps_to_sort([3, 1, 2, 4, 5]) 2 >>> min_adjacent_s...
def count_inversions(nums): """ Helper function to count inversions using merge sort. """ def merge_count_split_inv(arr, temp_arr, left, mid, right): i = left # Starting index for left subarray j = mid + 1 # Starting index for right subarray k = left # Starting index to be ...
from solution import min_adjacent_swaps_to_sort def test_sorted_list(): assert min_adjacent_swaps_to_sort([1, 2, 3, 4, 5]) == 0 def test_reversed_list(): assert min_adjacent_swaps_to_sort([5, 4, 3, 2, 1]) == 10 def test_random_list(): assert min_adjacent_swaps_to_sort([3, 1, 2, 4, 5]) == 2 def test_sing...
[ { "docstring": "Helper function to count inversions using merge sort.", "function_declaration": "def count_inversions(nums):", "function_name": "count_inversions", "parameter_list": "(nums)" }, { "docstring": "Returns the minimum number of adjacent swaps required to sort the list.", "fun...
[ 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def merge_and_count(arr, temp_arr, left, mid, right):\n i = left # Starting index for left subarray\n j = mid + 1 # Starting index for right subarray\n k = left ...
trial_gpt4o_3
{ "original_instruction": "You are given a list of integers `nums`, where the length of `nums` is `n`. Initially, the list is sorted in ascending order. In one operation, you can take any two consecutive elements in the list and swap them. \n\nReturn _the minimum number of adjacent swaps required to sort the list in ...
0.677808
Leetcode_28007
C
[ "count_inversions", "min_adjacent_swaps_to_sort" ]
2
[ [ "min_adjacent_swaps_to_sort", "count_inversions" ] ]
1
[]
false
[]
false
pytest
true
[]
true
75cb31ea31b827e15c391e0b26dec356c8709d2f
2d6c16bc51d174c75d44f38b4fda2a6e0f60442e
v1.0
complete
Leetcode
Leetcode_28352_C
def findLexSmallestString(s: str, a: int, b: int) -> str: """You are given a string `s` and two integers `a` and `b`. Your task is to apply the following operation any number of times and return the lexicographically smallest string that you can obtain: 1. **Add operation**: Add `a` to all the odd indices of th...
from collections import deque def add_operation(s, a): s = list(s) for i in range(1, len(s), 2): s[i] = str((int(s[i]) + a) % 10) return ''.join(s) def findLexSmallestString(s, a, b): visited = set() queue = deque([s]) smallest = s while queue: current = queue.popleft() ...
from solution import findLexSmallestString def test_findLexSmallestString_example1(): s = "5525" a = 9 b = 2 assert findLexSmallestString(s, a, b) == "2050" def test_findLexSmallestString_example2(): s = "74" a = 5 b = 1 assert findLexSmallestString(s, a, b) == "24" def test_findLexSm...
[ { "docstring": null, "function_declaration": "def add_operation(s, a):", "function_name": "add_operation", "parameter_list": "(s, a)" }, { "docstring": null, "function_declaration": "def findLexSmallestString(s, a, b):", "function_name": "findLexSmallestString", "parameter_list":...
[ 0, 0, 0, 0, 0, 0, 0, 1, 1, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef add_operation(s, a):\n s = list(s)\n for i in range(1, len(s), 2):\n s[i] = str((int(s[i]) + a) % 10)\n return ''.join(s)...
trial_gpt4o_8
{ "original_instruction": "You are given a string `s` and two integers `a` and `b`. Your task is to apply the following operation any number of times and return the lexicographically smallest string that you can obtain:\n\n1. **Add operation**: Add `a` to all the odd indices of the string `s` (index 1, 3, 5, etc.). D...
0.667311
Leetcode_28352
C
[ "add_operation", "findLexSmallestString" ]
2
[ [ "findLexSmallestString", "add_operation" ] ]
1
[]
false
[]
false
pytest
true
[]
true
65b783acb537ffcebfcbe62ed79d390e740618c9
6f09e4206ff20635c8ba2a206c428f2fb356343c
v1.0
complete
Leetcode
Leetcode_28432_C
def is_palindrome(s): """ Helper function to determine if a given string s is a palindrome. """ pass def can_divide_substring(s, start, end): """ Determines if the substring s[start...end] can be divided into two non-empty parts such that one is a palindrome and the other is not. """ ...
def is_palindrome(s): """ Helper function to determine if a given string s is a palindrome. """ return s == s[::-1] def can_divide_substring(s, start, end): """ Determines if the substring s[start...end] can be divided into two non-empty parts such that one is a palindrome and the other is ...
from solution import can_divide_substring def test_valid_division(): assert can_divide_substring("abca", 1, 3) == True # "bca" => "b" (not palindrome), "ca" (palindrome) def test_no_palindrome(): assert can_divide_substring("abcd", 1, 3) == True # "bcd" => "bc" (not palindrome), "d" (palindrome) def test_n...
[ { "docstring": "Helper function to determine if a given string s is a palindrome.", "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": "Determines if the substring s[start...end] can be divided into two non-empty parts...
[ 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_palindrome(sub):\n \"\"\"\n Helper function to determine if the given string is a palindrome.\n \"\"\"\n return sub == sub[::-1]\n\ndef can_divide_into_pal...
trial_gpt4o_4
{ "original_instruction": "You are given a string `s` and two integers `start` and `end`. Determine if you can divide the substring `s[start...end]` into two non-empty parts such that one is a palindrome and the other is not. Return `true` if it is possible, otherwise return `false`. Note that the substring `s[start....
0.836245
Leetcode_28432
C
[ "is_palindrome", "can_divide_substring" ]
2
[ [ "can_divide_substring", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a53f36133164573a3328386874af6492f38e285a
7c2d770aed1ea0ca4f05f10274e7848502f24c66
v1.0
complete
Leetcode
Leetcode_28466_C
def max_value_events(events: List[Tuple[int, int, int]]) -> int: """ Given an array events where each event is represented as a tuple (start, end, value) indicating the start time, end time, and value of the event, find the maximum value you can achieve by attending non-overlapping events. >>> max_value_ev...
def binary_search(events, end_time): left, right = 0, len(events) - 1 while left <= right: mid = (left + right) // 2 if events[mid][1] <= end_time: left = mid + 1 else: right = mid - 1 return right def max_value_events(events): events.sort(key=lambda x: x...
from solution import max_value_events def test_single_event(): assert max_value_events([(1, 2, 50)]) == 50 def test_non_overlapping_events(): assert max_value_events([(1, 2, 50), (3, 4, 60)]) == 110 def test_overlapping_events(): assert max_value_events([(1, 3, 50), (2, 5, 60)]) == 60 def test_mixed_eve...
[ { "docstring": null, "function_declaration": "def binary_search(events, end_time):", "function_name": "binary_search", "parameter_list": "(events, end_time)" }, { "docstring": null, "function_declaration": "def max_value_events(events):", "function_name": "max_value_events", "par...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "from typing import List, Tuple\n\ndef max_value_of_non_overlapping_events(events: List[Tuple[int, int, int]]) -> int:\n \"\"\"\n Finds the maximum value achievable by a...
trial_gpt4o_8
{ "original_instruction": "Given an array `events` where each event is represented as a tuple `(start, end, value)` indicating the start time, end time, and value of the event, find the maximum value you can achieve by attending non-overlapping events. Each event can only be attended if it does not overlap with any o...
0.602794
Leetcode_28466
C
[ "binary_search", "max_value_events" ]
2
[ [ "max_value_events", "binary_search" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f076102a09794922baf543a3398bf4012a0f6182
538c926e54095d00556eea8bf3c0bf6465a206fa
v1.0
complete
Leetcode
Leetcode_28498_C
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def is_symmetric(root): """ Determine whether a binary tree is symmetric. :param root: TreeNode, the root of the binary tree. :return: bool, True if the tree...
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def is_symmetric(root): """ Determine whether a binary tree is symmetric. :param root: TreeNode, the root of the binary tree. :return: bool, True if the tree...
from solution import TreeNode, is_symmetric def test_symmetric_tree(): # Construct a symmetric tree # 1 # / \ # 2 2 # / \ / \ # 3 4 4 3 root = TreeNode(1) root.left = TreeNode(2) root.right = TreeNode(2) root.left.left = TreeNode(3) root.left....
[]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\ndef is_symmetric(root)...
trial_gpt4o_9
{ "original_instruction": "Given a binary tree, write a function to check whether it is a mirror of itself (i.e., symmetric around its center). Implement a helper function that checks two trees for mirror symmetry. Return `true` if the given tree is symmetric, and `false` otherwise.", "prompt_id": "0000028498", "...
0.615725
Leetcode_28498
C
[ "is_symmetric", "is_mirror" ]
2
[ [ "is_symmetric", "is_mirror" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
cf03547b3b89802622295c763ff186c07897bfd9
b689ebe83577ed68ad943d58573fff37b6335783
v1.0
complete
Leetcode
Leetcode_28601_C
def longest_palindromic_subsequence_lengths(s: str) -> List[int]: """You are given a string `s` consisting of lowercase English letters. A palindromic subsequence is a subsequence (i.e., sequence that can be derived from another sequence by deleting some or no elements without changing the order of the rem...
def longest_palindromic_subsequence_lengths(s): n = len(s) result = [0] * n for i in range(n): subsequence = s[:i+1] result[i] = longest_palindromic_subsequence(subsequence) return result def longest_palindromic_subsequence(subsequence): m = len(subsequence) dp = [[0] * m for ...
from solution import longest_palindromic_subsequence_lengths def test_single_character(): assert longest_palindromic_subsequence_lengths("a") == [1] def test_all_characters_same(): assert longest_palindromic_subsequence_lengths("aaaaa") == [1, 2, 3, 4, 5] def test_palindromic_subsequences(): assert longe...
[ { "docstring": null, "function_declaration": "def longest_palindromic_subsequence_lengths(s):", "function_name": "longest_palindromic_subsequence_lengths", "parameter_list": "(s)" }, { "docstring": null, "function_declaration": "def longest_palindromic_subsequence(subsequence):", "fu...
[ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def longest_palindromic_subsequence_lengths(s):\n n = len(s)\n result = [0] * n\n\n for i in range(n):\n subsequence = s[:i+1]\n result[i] = longest_pa...
trial_gpt4o_0
{ "original_instruction": "You are given a string `s` consisting of lowercase English letters. A **palindromic subsequence** is a subsequence (i.e., sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements) of `s` that reads the same forwa...
0.80759
Leetcode_28601
C
[ "longest_palindromic_subsequence_lengths", "longest_palindromic_subsequence" ]
2
[ [ "longest_palindromic_subsequence_lengths", "longest_palindromic_subsequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8c07e0096d5d5f41ec63784b4595160ce70f7bd1
33198fda8c7c68293ed49751b219e140e7ce2aa7
v1.0
complete
Leetcode
Leetcode_28760_C
def min_partitions(s: str) -> int: """ Given a string `s` containing only digits, return the minimum number of partitions you need to make in such a way that each substring is a power of 2 in binary representation. If it is not possible to partition the string in such a way, return -1. >>> min_p...
def is_power_of_2(s): """ Helper function to check if a given string s of digits is a power of 2. """ # Convert string s to integer num = int(s) # Check if num is a power of 2 return num != 0 and (num & (num - 1)) == 0 def min_partitions(s): """ Returns the minimum number of partiti...
from solution import min_partitions def test_single_digit_powers(): assert min_partitions("1") == 1 # 1 is a power of 2 (2^0) assert min_partitions("2") == 1 # 2 is a power of 2 (2^1) assert min_partitions("4") == 1 # 4 is a power of 2 (2^2) assert min_partitions("8") == 1 # 8 is a power of 2 (2^3)...
[ { "docstring": "Helper function to check if a given string s of digits is a power of 2.", "function_declaration": "def is_power_of_2(s):", "function_name": "is_power_of_2", "parameter_list": "(s)" }, { "docstring": "Returns the minimum number of partitions needed for the string\nsuch that ea...
[ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_power_of_2(n):\n \"\"\"\n Check if a given number (in string format) is a power of 2.\n \"\"\"\n if n[0] == '0': # No leading zeroes are allowed\n ...
trial_gpt4o_5
{ "original_instruction": "Given a string `s` containing only digits, return _the minimum number of partitions you need to make in such a way that each substring is a **power of 2** in binary representation_. If it is not possible to partition the string in such a way, return `-1`. A power of 2 is a number such tha...
0.773638
Leetcode_28760
C
[ "is_power_of_2", "min_partitions" ]
2
[ [ "min_partitions", "is_power_of_2" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a0bc97e9128e2481cd524f8ad5a568152f0c7775
88f689ab972b49daf703aee0f864ee71471e63c0
v1.0
complete
Leetcode
Leetcode_28937_C
def is_self_dividing(number: int) -> bool: """ Helper function that checks if a number is self-dividing. >>> is_self_dividing(128) True >>> is_self_dividing(1) True >>> is_self_dividing(12) True >>> is_self_dividing(102) False >>> is_self_dividing(20) False >>> is_self_di...
def is_self_dividing(number): """ Helper function that checks if a number is self-dividing. """ original_number = number while number > 0: digit = number % 10 if digit == 0 or original_number % digit != 0: return False number //= 10 return True def self_divid...
from solution import self_dividing_numbers, is_self_dividing def test_is_self_dividing_true(): assert is_self_dividing(128) == True assert is_self_dividing(1) == True assert is_self_dividing(12) == True def test_is_self_dividing_false(): assert is_self_dividing(102) == False assert is_self_div...
[ { "docstring": "Helper function that checks if a number is self-dividing.", "function_declaration": "def is_self_dividing(number):", "function_name": "is_self_dividing", "parameter_list": "(number)" }, { "docstring": "Returns a list of all self-dividing numbers between 1 and n (inclusive).",...
[ 0, 1, 0, 0, 1, 1, 1, 0, 1, 0 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_self_dividing(number):\n \"\"\"\n Returns True if the number is a self-dividing number, False otherwise.\n \"\"\"\n original_number = number\n while num...
trial_gpt4o_8
{ "original_instruction": "Given an integer `n`, write a function that returns a list of all self-dividing numbers between `1` and `n` (inclusive). A self-dividing number is a number that is divisible by every digit it contains. For example, `128` is a self-dividing number because `128 % 1 == 0`, `128 % 2 == 0`, and ...
0.65491
Leetcode_28937
C
[ "is_self_dividing", "self_dividing_numbers" ]
2
[ [ "self_dividing_numbers", "is_self_dividing" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1106aee8f23ece98242d76bd36dccd1800d73259
8cb765f9c0531e5a79a955749e5324fc60874685
v1.0
complete
Leetcode
Leetcode_29050_C
def longest_concatenated_word(words: List[str]) -> str: """ Return the longest string in `words` that can be constructed by concatenating other strings from `words`. If there is no such string, return an empty string. >>> longest_concatenated_word(["cat","dog","catdog"]) 'catdog' >>> longe...
def can_form_word(word, words_set, memo): """ Helper function to determine if a word can be formed by concatenating other words in the set. """ if word in memo: return memo[word] for i in range(1, len(word)): prefix = word[:i] suffix = word[i:] if prefix in w...
from solution import longest_concatenated_word def test_longest_concatenated_word(): assert longest_concatenated_word(["cat","dog","catdog"]) == "catdog" assert longest_concatenated_word(["cat","dog","catdog","dogcatdog"]) == "dogcatdog" assert longest_concatenated_word(["rat","ratcat","cat","dog","catdog"...
[ { "docstring": "Helper function to determine if a word can be formed by concatenating\nother words in the set.", "function_declaration": "def can_form_word(word, words_set, memo):", "function_name": "can_form_word", "parameter_list": "(word, words_set, memo)" }, { "docstring": "Returns the l...
[ 1, 0, 0, 1, 0, 1, 1, 1, 0, 0 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "from collections import defaultdict\n\ndef longest_concatenated_word(words):\n \"\"\"\n Returns the longest string in `words` that can be constructed by concatenating o...
trial_gpt4o_6
{ "original_instruction": "Given an array of strings `words`, return _the longest string in `words` that can be constructed by concatenating other strings from `words`_. If there is no such string, return an empty string. \nEach string in `words` is unique.", "prompt_id": "0000029050", "row_id": 29050, "seed_i...
0.769716
Leetcode_29050
C
[ "can_form_word", "longest_concatenated_word" ]
2
[ [ "longest_concatenated_word", "can_form_word" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c2d63b838f3823ef9f2ecf627a3fa1cfc15e4698
17c6fc01b39257c884364064f5902df32b5b61c1
v1.0
complete
Leetcode
Leetcode_29057_C
def minimized_maximum_sum(nums: List[int], k: int) -> int: """ You are given a **0-indexed** integer array `nums` with length `n` and an integer `k`. Your task is to partition the array into exactly `k` non-empty subsets such that the maximum sum of any subset is minimized. Return the minimized m...
def can_partition(nums, k, max_sum): """ Helper function to check if we can partition the array into k subsets with each subset having a sum less than or equal to max_sum. """ current_sum = 0 subsets = 1 for num in nums: if current_sum + num > max_sum: subsets += 1 ...
from solution import minimized_maximum_sum def test_example_case(): assert minimized_maximum_sum([1, 2, 3, 4, 5], 3) == 6 def test_single_element(): assert minimized_maximum_sum([10], 1) == 10 def test_all_elements_equal(): assert minimized_maximum_sum([5, 5, 5, 5], 2) == 10 def test_increasing_elements...
[ { "docstring": "Helper function to check if we can partition the array into k subsets\nwith each subset having a sum less than or equal to max_sum.", "function_declaration": "def can_partition(nums, k, max_sum):", "function_name": "can_partition", "parameter_list": "(nums, k, max_sum)" }, { ...
[ 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
1
hard
0.111
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def can_partition(nums, k, max_sum):\n subset_sums = [0] * k\n if backtrack(nums, len(nums) - 1, subset_sums, max_sum):\n return True\n return False\n\ndef ba...
trial_gpt4o_8
{ "original_instruction": "You are given a **0-indexed** integer array `nums` with length `n` and an integer `k`. Your task is to partition the array into exactly `k` non-empty subsets such that the maximum sum of any subset is minimized. Return the minimized maximum sum.", "prompt_id": "0000029057", "row_id": 29...
0.717295
Leetcode_29057
C
[ "can_partition", "minimized_maximum_sum" ]
2
[ [ "minimized_maximum_sum", "can_partition" ] ]
1
[]
false
[]
false
pytest
true
[]
true
89c7415f4c3c0cfa6846fefd1cde02f98fd924ce
bf8fa60e4856cc114aa1d86326097ce54b1a9933
v1.0
complete
Leetcode
Leetcode_29486_C
def min_max_weight_partition(nums, k): """ Returns the minimum possible value of max weight W for a valid partition into k components. >>> min_max_weight_partition([1, 2, 3, 4, 5], 2) 9 >>> min_max_weight_partition([7, 2, 5, 10, 8], 1) 32 >>> min_max_weight_partition([7, 2, 5, 10, 8], 5) 10 >>> min_...
def is_valid_partition(nums, k, max_weight): """ Helper function to determine if we can partition nums into k components with max weight max_weight. """ current_sum = 0 count = 1 # We start with 1 component for weight in nums: if current_sum + weight <= max_weight: current_...
from solution import min_max_weight_partition def test_example_case(): nums = [1, 2, 3, 4, 5] k = 2 assert min_max_weight_partition(nums, k) == 9 def test_single_partition(): nums = [7, 2, 5, 10, 8] k = 1 assert min_max_weight_partition(nums, k) == 32 # Sum of all elements def test_max_parti...
[ { "docstring": "Helper function to determine if we can partition nums into k components with max weight max_weight.", "function_declaration": "def is_valid_partition(nums, k, max_weight):", "function_name": "is_valid_partition", "parameter_list": "(nums, k, max_weight)" }, { "docstring": "Re...
[ 0, 0, 0, 0, 0, 1, 0, 0, 0, 1 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def valid_partition(nums, k):\n def can_partition(nums, k, max_weight):\n current_sum = 0\n components = 1\n for num in nums:\n current_sum...
trial_gpt4o_9
{ "original_instruction": "You are given an integer array `nums` of length `n` representing the weight of `n` items. You are also given an integer `k` representing the number of components that you need to divide these items into. Each component should contain at least one item, and the total weight of items in each ...
0.613937
Leetcode_29486
C
[ "is_valid_partition", "min_max_weight_partition" ]
2
[ [ "min_max_weight_partition", "is_valid_partition" ] ]
1
[]
false
[]
false
pytest
true
[]
true
17acbd611e94d58914d18ce3de919396b1558852
c6a544e62d06a13df52f2976203a248840cca8cd
v1.0
complete
Leetcode
Leetcode_29544_C
def longest_palindromic_substring_length(s: str) -> int: """ Returns the length of the longest palindromic substring in a given string. """ pass def find_longest_palindromic_substring_length(strings: List[str]) -> int: """ Given a list of strings, returns the length of the longest palindrome fo...
def longest_palindromic_substring_length(s): """ Returns the length of the longest palindromic substring in a given string. """ if not s: return 0 n = len(s) longest = 1 # Create a 2D array to keep track of palindromes dp = [[False] * n for _ in range(n)] # Every single ch...
from solution import find_longest_palindromic_substring_length def test_single_string(): assert find_longest_palindromic_substring_length(["babad"]) == 3 assert find_longest_palindromic_substring_length(["cbbd"]) == 2 def test_multiple_strings(): assert find_longest_palindromic_substring_length(["babad", ...
[ { "docstring": "Returns the length of the longest palindromic substring in a given string.", "function_declaration": "def longest_palindromic_substring_length(s):", "function_name": "longest_palindromic_substring_length", "parameter_list": "(s)" }, { "docstring": "Given a list of strings, re...
[ 1, 0, 1, 0, 1, 1, 0, 0, 0, 0 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def longest_palindromic_substring_length(s):\n \"\"\"\n Return the length of the longest palindromic substring in the given string.\n \"\"\"\n n = len(s)\n if ...
trial_gpt4o_5
{ "original_instruction": "Given a list of strings, return the length of the **longest substring** that is a palindrome. A palindrome is a string that reads the same backward as forward.", "prompt_id": "0000029544", "row_id": 29544, "seed_ids": "['1295', '1622', '1145']" }
0.781705
Leetcode_29544
C
[ "longest_palindromic_substring_length", "find_longest_palindromic_substring_length" ]
2
[ [ "find_longest_palindromic_substring_length", "longest_palindromic_substring_length" ] ]
1
[]
false
[]
false
pytest
true
[]
true
42f776a6e90d4c0b71a412d2ebab29c34f084421
94f6f72e0663445894f22ee74d4317c98f6d9bc1
v1.0
complete
Leetcode
Leetcode_29845_C
def shift_string(word: str, k: int) -> str: """ Shifts the characters in the word k times. >>> shift_string("abc", 1) == "bcd" >>> shift_string("xyz", 1) == "yza" >>> shift_string("abc", 3) == "def" >>> shift_string("xyz", 3) == "abc" """ pass def shift_strings(words: List[str], k: int...
def shift_string(word, k): """ Shifts the characters in the word k times. """ shifted = [] for char in word: shifted.append(chr((ord(char) - ord('a') + k) % 26 + ord('a'))) return ''.join(shifted) def shift_strings(words, k): """ Returns an array of strings where each string is ...
from solution import shift_string, shift_strings # Test for shift_string function def test_shift_string_single_shift(): assert shift_string("abc", 1) == "bcd" assert shift_string("xyz", 1) == "yza" def test_shift_string_multiple_shift(): assert shift_string("abc", 3) == "def" assert shift_string("xyz"...
[ { "docstring": "Shifts the characters in the word k times.", "function_declaration": "def shift_string(word, k):", "function_name": "shift_string", "parameter_list": "(word, k)" }, { "docstring": "Returns an array of strings where each string is shifted from 1 to k times.", "function_dec...
[ 1, 1, 0, 0, 0, 0, 0, 0, 0, 1 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def shift_string_by_k_times(string, k):\n \"\"\"\n Shifts the characters of the string by k positions.\n \"\"\"\n shifted_string = \"\"\n for character in stri...
trial_gpt4o_9
{ "original_instruction": "You are given an array of strings `words` and an integer `k`. Each string consists of exactly `k` characters in the range `['a', 'z']`. A shift on a string means replacing each character by the next one in the alphabet (with 'z' shifting to 'a'). \n\nFor example, a shift on `\"abc\"` result...
0.69737
Leetcode_29845
C
[ "shift_string", "shift_strings" ]
2
[ [ "shift_strings", "shift_string" ] ]
1
[]
false
[]
false
pytest
true
[]
true
69d0cb60eca2cb3e40dfcb511a62b668f6f64cd1
d1be12db908a1414331ce429dea2ba156c5859c6
v1.0
complete
Leetcode
Leetcode_29961_C
def rotate(nums, k): """ Rotates the array `nums` to the right by `k` steps in-place. Parameters: nums (List[int]): The input array of integers. k (int): The number of steps to rotate the array. Returns: None """ pass def reverse(nums, start, end): """ ...
def rotate(nums, k): """ Rotates the array `nums` to the right by `k` steps in-place. Parameters: nums (List[int]): The input array of integers. k (int): The number of steps to rotate the array. Returns: None """ n = len(nums) k %= n reverse(nums, 0,...
from solution import rotate, reverse def test_rotate_example_case(): nums = [1, 2, 3, 4, 5, 6, 7] rotate(nums, 3) assert nums == [5, 6, 7, 1, 2, 3, 4] def test_rotate_zero_steps(): nums = [1, 2, 3, 4, 5, 6, 7] rotate(nums, 0) assert nums == [1, 2, 3, 4, 5, 6, 7] def test_rotate_full_cycle(): ...
[ { "docstring": "Rotates the array `nums` to the right by `k` steps in-place.\n\nParameters:\n nums (List[int]): The input array of integers.\n k (int): The number of steps to rotate the array.\n \nReturns:\n None", "function_declaration": "def rotate(nums, k):", "function_name": "rotate", ...
[ 1, 1, 0, 1, 0, 1, 1, 0, 1, 1 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def rotate(nums, k):\n \"\"\"\n Rotates the array nums to the right by k steps.\n \"\"\"\n n = len(nums)\n k = k % n # In case k is greater than n\n nums[:...
trial_gpt4o_9
{ "original_instruction": "You are given an array of integers `nums` and an integer `k`. Your task is to rotate the array to the right by `k` steps, where `k` is non-negative. Implement a function to perform this rotation without using extra space for another array. For example, if the array is `[1, 2, 3, 4, 5, 6, 7]...
0.639458
Leetcode_29961
C
[ "rotate", "reverse" ]
2
[ [ "rotate", "reverse" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ee45faff6fbc38c0beb28c53918ce6584fd807d5
6346216943b48bf81fb3d6e698f7a249b6bf9c45
v1.0
complete
Leetcode
Leetcode_30087_C
def longest_substring_transformed_palindrome(s: str, k: int) -> int: """ Returns the length of the longest substring of s that can be transformed into a palindrome by inserting at most k characters. >>> longest_substring_transformed_palindrome("abcdeca", 2) 7 >>> longest_substring_transformed_palindrom...
def longest_palindrome_subseq(s: str) -> int: """ Helper function to find the length of the longest palindromic subsequence in s. """ n = len(s) dp = [[0] * n for _ in range(n)] for i in range(n - 1, -1, -1): dp[i][i] = 1 for j in range(i + 1, n): if s[i] == s[j]: ...
def test_longest_substring_transformed_palindrome_1(): assert longest_substring_transformed_palindrome("abcdeca", 2) == 7 def test_longest_substring_transformed_palindrome_2(): assert longest_substring_transformed_palindrome("aabbc", 1) == -1 def test_longest_substring_transformed_palindrome_3(): assert l...
[ { "docstring": "Helper function to find the length of the longest palindromic subsequence in s.", "function_declaration": "def longest_palindrome_subseq(s):", "function_name": "longest_palindrome_subseq", "parameter_list": "(s)" }, { "docstring": "Returns the length of the longest substring ...
[ 0, 1, 0, 1, 0, 0, 0, 0, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def longest_palin_subseq(s):\n n = len(s)\n dp = [[0] * n for _ in range(n)]\n \n for i in range(n):\n dp[i][i] = 1\n \n for l in range(2, n + 1):\n ...
trial_gpt4o_3
{ "original_instruction": "Given a string `s` and an integer `k`, return the length of the longest substring of `s` that can be transformed into a palindrome by inserting at most `k` characters.", "prompt_id": "0000030087", "row_id": 30087, "seed_ids": "['1344', '1099', '1124']" }
0.778866
Leetcode_30087
C
[ "longest_palindrome_subseq", "longest_substring_transformed_palindrome" ]
2
[ [ "longest_substring_transformed_palindrome", "longest_palindrome_subseq" ] ]
1
[]
false
[]
false
pytest
false
[]
true
8edfa104f8e294892fe0b4bac39f7d565bccf495
a7d5fd2f3de50c8fa57b23bbc14c0bd6a9547bd8
v1.0
complete
Leetcode
Leetcode_30135_C
def max_sum_submatrix(mat): """ Returns the maximum sum of any rectangle in a 2D matrix. :param mat: List of List of integers representing the matrix :return: Integer representing the maximum rectangle sum >>> mat1 = [[1, 2, -1, -4, -20], [-8, -3, 4, 2, 1], [3, 8, 10, 1, 3], [-4, -1, 1, 7,...
def max_sum_submatrix(mat): """ Returns the maximum sum of any rectangle in a 2D matrix. :param mat: List of List of integers representing the matrix :return: Integer representing the maximum rectangle sum """ if not mat or not mat[0]: return 0 m, n = len(mat), len(mat[0]) ...
from solution import max_sum_submatrix def test_max_sum_submatrix_all_positive(): mat = [ [1, 2, -1, -4, -20], [-8, -3, 4, 2, 1], [3, 8, 10, 1, 3], [-4, -1, 1, 7, -6] ] assert max_sum_submatrix(mat) == 29 # Rectangle from (1,2) to (3,3) def test_max_sum_submatrix_mixed_va...
[ { "docstring": "Returns the maximum sum of any rectangle in a 2D matrix.\n\n:param mat: List of List of integers representing the matrix\n:return: Integer representing the maximum rectangle sum", "function_declaration": "def max_sum_submatrix(mat):", "function_name": "max_sum_submatrix", "parameter_...
[ 0, 0, 0, 0, 0, 1, 0, 0, 1, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def max_sum_submatrix(mat):\n \"\"\"\n Returns the maximum sum of any rectangle in the 2D matrix mat.\n \"\"\"\n if not mat or not mat[0]:\n return 0\n\n ...
trial_gpt4o_8
{ "original_instruction": "Given a 2D matrix `mat` of size `m x n` where each cell contains an integer, write a function to determine the maximum sum of any rectangle from the matrix. A rectangle is defined by its top-left and bottom-right corners, and it should contain at least one element. The function should retur...
0.662328
Leetcode_30135
C
[ "max_sum_submatrix", "max_sum_subarray" ]
2
[ [ "max_sum_submatrix", "max_sum_subarray" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ceccb23c5a8d5d7e11be1861a951a38fa4265d12
acb6bace979e566f6bdf7cd80b66e8353f5cd20b
v1.0
complete
Leetcode
Leetcode_30289_C
def minimizeMaxWorkload(tasks: List[int], k: int) -> int: """ Given a list of non-negative integers representing the amount of time taken by each task, and an integer 'k' representing the number of workers available to complete these tasks, return the minimum possible maximum workload whenever the tasks are dis...
def canDistribute(tasks, k, max_workload): current_workers = 1 current_load = 0 for task in tasks: if current_load + task <= max_workload: current_load += task else: current_workers += 1 current_load = task if current_workers > k: ...
from solution import minimizeMaxWorkload def test_minimizeMaxWorkload_basic(): assert minimizeMaxWorkload([10, 20, 30, 40], 2) == 60 def test_minimizeMaxWorkload_single_task(): assert minimizeMaxWorkload([15], 1) == 15 def test_minimizeMaxWorkload_equal_tasks(): assert minimizeMaxWorkload([10, 10, 10, 10...
[ { "docstring": null, "function_declaration": "def canDistribute(tasks, k, max_workload):", "function_name": "canDistribute", "parameter_list": "(tasks, k, max_workload)" }, { "docstring": null, "function_declaration": "def minimizeMaxWorkload(tasks, k):", "function_name": "minimizeMa...
[ 0, 0, 0, 0, 1, 0, 0, 1, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def canDistribute(tasks, k, max_workload):\n \"\"\"\n Helper function to check if tasks can be distributed among \n k workers with each worker having no more than ma...
trial_gpt4o_7
{ "original_instruction": "Given a list of non-negative integers representing the amount of time taken by each task, and an integer `k` representing the number of workers available to complete these tasks, return the minimum possible maximum workload whenever the tasks are distributed optimally among the workers. Eac...
0.682744
Leetcode_30289
C
[ "canDistribute", "minimizeMaxWorkload" ]
2
[ [ "minimizeMaxWorkload", "canDistribute" ] ]
1
[]
false
[]
false
pytest
true
[]
true
256b5abfcf21f163f8cdf3382052804996316b49
ff6e6f2f803ccaa8b90cb8880fdd09d5fc3526e1
v1.0
complete
Leetcode
Leetcode_30496_C
def largest_clique_size(s: str) -> int: """ Find the size of the largest clique where each word shares at least one common letter with every other word in the group. >>> largest_clique_size("a b c d e") == 1 >>> largest_clique_size("ab cd ef gh") == 1 >>> largest_clique_size("abc bde efg fgh hij") == 5 ...
def share_common_letter(word1, word2): """ Check if two words share at least one common letter. """ return bool(set(word1) & set(word2)) def largest_clique_size(s): """ Find the size of the largest clique where each word shares at least one common letter with every other word in the group. ...
from solution import largest_clique_size def test_largest_clique_size(): # Test cases assert largest_clique_size("a b c d e") == 1 # each word is its own clique assert largest_clique_size("ab cd ef gh") == 1 # each word is its own clique assert largest_clique_size("abc bde efg fgh hij") == 5 # all w...
[ { "docstring": "Check if two words share at least one common letter.", "function_declaration": "def share_common_letter(word1, word2):", "function_name": "share_common_letter", "parameter_list": "(word1, word2)" }, { "docstring": "Find the size of the largest clique where each word shares\na...
[ 0, 0, 0, 1, 0, 0, 0, 0, 1, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def largest_clique_size(s):\n \"\"\"\n Returns the size of the largest clique in the given string of words.\n A \"clique\" is defined as a group of words where each ...
trial_gpt4o_8
{ "original_instruction": "You are given a string `s` representing a list of words separated by spaces. Each word consists of lowercase letters only. We define a \"clique\" as a group of words where each word shares at least one common letter with every other word in the group. Your task is to find the size of the la...
0.605453
Leetcode_30496
C
[ "share_common_letter", "largest_clique_size" ]
2
[ [ "largest_clique_size", "share_common_letter" ] ]
1
[]
false
[]
false
pytest
true
[]
true
51ead58ed4702e73d8a2a7466662fc51cd829e7a
828f955ac78eb57b807e207ffa116ded81c22b6f
v1.0
complete
Leetcode
Leetcode_30629_C
def is_subsequence(s: str, pattern: str) -> bool: """ Helper function to determine if a pattern is a subsequence of the string s. """ it = iter(s) return all(char in it for char in pattern) def check_patterns(s: str, patterns: List[str]) -> List[bool]: """ Determines for each pattern in pat...
def is_subsequence(s, pattern): """ Helper function to determine if a pattern is a subsequence of s. """ it = iter(s) return all(char in it for char in pattern) def check_patterns(s, patterns): """ Determines for each pattern in patterns whether it is a subsequence of the string s. ...
from solution import check_patterns def test_single_pattern(): s = "abcdef" patterns = ["abc"] assert check_patterns(s, patterns) == [True] def test_multiple_patterns(): s = "abcdef" patterns = ["abc", "def", "acf", "af"] assert check_patterns(s, patterns) == [True, True, True, True] def test...
[ { "docstring": "Helper function to determine if a pattern is a subsequence of s.", "function_declaration": "def is_subsequence(s, pattern):", "function_name": "is_subsequence", "parameter_list": "(s, pattern)" }, { "docstring": "Determines for each pattern in patterns whether it is a subsequ...
[ 1, 1, 1, 0, 0, 1, 0, 0, 1, 0 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_subsequence(s, patterns):\n \"\"\"\n Determines whether each pattern in patterns is a subsequence of the string s.\n \n Args:\n s (str): The string to c...
trial_gpt4o_8
{ "original_instruction": "You are given a string `s` and an array of strings `patterns`. Your task is to determine for each pattern in `patterns`, whether it is a subsequence of the string `s`. A subsequence of a string is a new string generated from the original string with some characters (can be none) deleted wit...
0.67542
Leetcode_30629
C
[ "is_subsequence", "check_patterns" ]
2
[ [ "check_patterns", "is_subsequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3213a90dc4e750e6d42381eb8742c1bbef55dc2a
3cb8449f2c4a3254785aa57b1968f0a217c41582
v1.0
complete
Leetcode
Leetcode_30841_C
class TreeNode: def __init__(self, value=0, left=None, right=None): self.value = value self.left = left self.right = right def shortest_path_length(root: TreeNode, node1: TreeNode, node2: TreeNode) -> int: """ Find the length of the shortest path between two nodes in a binary tree. ...
class TreeNode: def __init__(self, value=0, left=None, right=None): self.value = value self.left = left self.right = right def find_lca(root, node1, node2): if root is None: return None if root == node1 or root == node2: return root left_lca = find_lca(root.left...
from solution import TreeNode, shortest_path_length def test_shortest_path_length(): # Example tree # 1 # / \ # 2 3 # / \ # 4 5 # Tree Node Declaration node5 = TreeNode(5) node4 = TreeNode(4) node3 = TreeNode(3) node2 = TreeNode(2, left=node...
[]
[ 1, 0, 1, 0, 1, 1, 0, 1, 1, 0 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\ndef find_lca(root: Tre...
trial_gpt4o_2
{ "original_instruction": "Given a binary tree, find the length of the shortest path between two nodes. The length is defined as the number of edges between the two nodes. You may assume that both nodes exist within the tree. Return the length of the shortest path between the two specified nodes.", "prompt_id": "00...
0.639698
Leetcode_30841
C
[ "find_lca", "find_distance_from_ancestor", "shortest_path_length" ]
3
[ [ "shortest_path_length", "find_distance_from_ancestor" ], [ "shortest_path_length", "find_lca" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
d02c9157fab31fa03d0c6876f0f48dcf6aad3fee
bc0e51cd27ff4bb0bfd64c89ac2aeef703ce4b07
v1.0
complete
Leetcode
Leetcode_31060_C
class ListNode: def __init__(self, val=0, next=None): self.val = val self.next = next def sum_queries(head, queries): """ You are given a linked list, where the head node is at index 0 and each node contains an integer value and a reference to the next node. You are also given a list queri...
class ListNode: def __init__(self, val=0, next=None): self.val = val self.next = next def compute_prefix_sums(head): prefix_sums = [] current = head index = 0 current_sum = 0 while current is not None: current_sum += current.val prefix_sums.append(current_su...
import pytest from solution import ListNode, sum_queries def test_sum_queries_single_node(): head = ListNode(5) queries = [(0, 0)] assert sum_queries(head, queries) == [5] def test_sum_queries_multiple_nodes(): head = ListNode(1, ListNode(2, ListNode(3, ListNode(4, ListNode(5))))) queries = [(0, 2...
[]
[ 0, 1, 0, 1, 1, 1, 1, 1, 1, 0 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "class ListNode:\n def __init__(self, value=0, next=None):\n self.value = value\n self.next = next\n\ndef linked_list_sum_for_queries(head, queries):\n \"\...
trial_gpt4o_8
{ "original_instruction": "You are given a linked list, where the `head` node is at index 0 and each node contains an integer value and a reference to the next node. You are also given a list `queries` where each query contains two integers: the start index `start` and the end index `end`. For each query, you need to...
0.53664
Leetcode_31060
C
[ "compute_prefix_sums", "sum_queries" ]
2
[ [ "sum_queries", "compute_prefix_sums" ] ]
1
[]
false
[ "ListNode" ]
true
pytest
true
[]
true
3cc633404fad1e495d465a21c95faa1424999036
9a15ccd3155e78620d5c4c22b3304d9e2d774a5a
v1.0
complete
Leetcode
Leetcode_31066_C
def is_subsequence(word: str, dict_word: str) -> bool: """ Check if `word` is a subsequence of `dict_word`. """ it = iter(dict_word) return all(char in it for char in word) def find_subsequences(words: List[str], dictionary: str) -> List[str]: """ Given a list of strings `words` and a dicti...
def is_subsequence(word, dict_word): """ Check if `word` is a subsequence of `dict_word`. """ it = iter(dict_word) return all(char in it for char in word) def find_subsequences(words, dictionary): """ Given a list of strings `words` and a dictionary string `dictionary`, returns all the ...
from solution import find_subsequences def test_find_subsequences_all_match(): words = ["a", "ab", "abc"] dictionary = "abc abc abc" assert find_subsequences(words, dictionary) == ["a", "ab", "abc"] def test_find_subsequences_some_match(): words = ["a", "ax", "abc", "xyz"] dictionary = "abc xyz" ...
[ { "docstring": "Check if `word` is a subsequence of `dict_word`.", "function_declaration": "def is_subsequence(word, dict_word):", "function_name": "is_subsequence", "parameter_list": "(word, dict_word)" }, { "docstring": "Given a list of strings `words` and a dictionary string `dictionary`,...
[ 1, 0, 1, 0, 0, 1, 0, 1, 1, 0 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_subsequence(sub, full):\n \"\"\"\n Check if sub is a subsequence of full.\n \"\"\"\n it = iter(full)\n return all(char in it for char in sub)\n\ndef fin...
trial_gpt4o_8
{ "original_instruction": "You are given a list of strings `words` and a dictionary string `dictionary` which contains words separated by spaces. Your task is to identify all the words from the input `words` list that are subsequences of any word in the `dictionary`. A string `A` is a subsequence of string `B` if `A`...
0.703037
Leetcode_31066
C
[ "is_subsequence", "find_subsequences" ]
2
[ [ "find_subsequences", "is_subsequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
477599b98045e70605f4ceb5f0172af2aac19b5e
b69626b37af1aa62b3076214d5befb2a8763ca31
v1.0
complete
Leetcode
Leetcode_31334_C
from typing import List, Tuple def shortest_path(n: int, edges: List[Tuple[int, int]], weights: List[int], queries: List[Tuple[int, int]]) -> List[int]: """ You are given a directed graph with `n` nodes and `m` edges, where each edge has a weight. The nodes are numbered from 1 to n. You need to find the le...
import heapq def dijkstra(graph, start): # Implementation of Dijkstra's algorithm to find shortest paths from a single source n = len(graph) dist = [float('inf')] * n dist[start] = 0 pq = [(0, start)] while pq: current_distance, current_vertex = heapq.heappop(pq) i...
from solution import shortest_path def test_shortest_path_case1(): n = 4 edges = [(1, 2), (2, 3), (3, 4), (1, 4)] weights = [1, 2, 3, 10] queries = [(1, 4), (1, 3)] assert shortest_path(n, edges, weights, queries) == [6, 3] def test_shortest_path_no_path(): n = 3 edges = [(1, 2), (2, 3)] ...
[ { "docstring": null, "function_declaration": "def dijkstra(graph, start):", "function_name": "dijkstra", "parameter_list": "(graph, start)" }, { "docstring": null, "function_declaration": "def shortest_path(n, edges, weights, queries):", "function_name": "shortest_path", "paramet...
[ 0, 0, 0, 0, 1, 0, 0, 1, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "import heapq\n\ndef dijkstra(n, adj, start, end):\n \"\"\"\n Finds the shortest path length from start to end using Dijkstra's algorithm.\n \"\"\"\n dist = [float...
trial_gpt4o_7
{ "original_instruction": "You are given a **directed graph** with `n` nodes and `m` edges, where each edge has a **weight**. The nodes are numbered from `1` to `n`. You need to find the length of the **shortest path** from a given source node `s` to a target node `t`. If there is no path from `s` to `t`, return `-1`...
0.751849
Leetcode_31334
C
[ "dijkstra", "shortest_path" ]
2
[ [ "shortest_path", "dijkstra" ] ]
1
[]
false
[]
false
pytest
true
[]
true
521692a872b2eae0708ffe97877b6a2cf5441ec7
af272cbf66c36b4a7ac1714242efc1d49f53d2af
v1.0
complete
Leetcode
Leetcode_31619_C
def minimum_heater_radius(houses: List[int], k: int) -> int: """ Returns the minimum heater radius `d` such that all houses are covered by `k` heaters. >>> minimum_heater_radius([5, 5, 5, 5], 1) == 0 >>> minimum_heater_radius([1, 2, 3, 4, 5], 1) == 2 >>> minimum_heater_radius([1, 2, 3, 4, 5, 6, 7], 2) =...
def can_cover_with_d(houses, k, d): """ Helper function to check if all houses can be covered by k heaters with a given radius d. """ heaters_count = 0 i = 0 while i < len(houses): heaters_count += 1 if heaters_count > k: return False # Place the heater t...
from solution import minimum_heater_radius def test_minimum_heater_radius_all_houses_at_same_position(): houses = [5, 5, 5, 5] k = 1 assert minimum_heater_radius(houses, k) == 0 def test_minimum_heater_radius_example_1(): houses = [1, 2, 3, 4, 5] k = 1 assert minimum_heater_radius(houses, k) =...
[ { "docstring": "Helper function to check if all houses can be covered by k heaters with a given radius d.", "function_declaration": "def can_cover_with_d(houses, k, d):", "function_name": "can_cover_with_d", "parameter_list": "(houses, k, d)" }, { "docstring": "Returns the minimum heater rad...
[ 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def min_distance_to_cover_houses(houses, k):\n def can_cover_all_houses(d):\n heaters_used = 0\n i = 0\n while i < len(houses):\n heaters_u...
trial_gpt4o_1
{ "original_instruction": "You are given a **0-indexed** 1D integer array `houses`, where `houses[i]` represents the position of the ith house along a street. You are also given an integer `k`, the number of heaters you can place. You can place heaters at any integer position along the street. Each heater covers all ...
0.546008
Leetcode_31619
C
[ "can_cover_with_d", "minimum_heater_radius" ]
2
[ [ "minimum_heater_radius", "can_cover_with_d" ] ]
1
[]
false
[]
false
pytest
true
[]
true
fda8d605f49a5a1f6e1dc17d5485b9fd25adc914
88baa26c539bf12db4d0a7d101056d34029684d6
v1.0
complete
Leetcode
Leetcode_31620_C
def num_valid_parentheses(n: int) -> int: """ Returns the number of valid parentheses strings of length 2n. >>> num_valid_parentheses(0) == 1 >>> num_valid_parentheses(1) == 1 >>> num_valid_parentheses(2) == 2 >>> num_valid_parentheses(3) == 5 >>> num_valid_parentheses(4) == 14 >>> num_valid...
def catalan_number(n): """ Returns the nth Catalan number. """ if n == 0: return 1 catalan = [0] * (n + 1) catalan[0] = 1 for i in range(1, n + 1): for j in range(i): catalan[i] += catalan[j] * catalan[i - 1 - j] return catalan[n] def num_valid_parentheses(n)...
from solution import num_valid_parentheses def test_num_valid_parentheses(): assert num_valid_parentheses(0) == 1 assert num_valid_parentheses(1) == 1 assert num_valid_parentheses(2) == 2 assert num_valid_parentheses(3) == 5 assert num_valid_parentheses(4) == 14 assert num_valid_parentheses(5) ...
[ { "docstring": "Returns the nth Catalan number.", "function_declaration": "def catalan_number(n):", "function_name": "catalan_number", "parameter_list": "(n)" }, { "docstring": "Returns the number of valid parentheses strings of length 2n.", "function_declaration": "def num_valid_parenth...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def count_valid_parentheses_strings(n):\n \"\"\"\n Returns the number of valid parentheses strings of length 2n.\n \"\"\"\n if n == 0:\n return 1\n \n ...
trial_gpt4o_9
{ "original_instruction": "You are given a positive integer `n`. Write a function to determine the number of valid parentheses strings of length `2n`. A valid parentheses string is defined as a string of length `2n` that consists only of characters '(' and ')', and is balanced such that every open parenthesis '(' has ...
0.721194
Leetcode_31620
C
[ "catalan_number", "num_valid_parentheses" ]
2
[ [ "num_valid_parentheses", "catalan_number" ] ]
1
[]
false
[]
false
pytest
true
[]
true
790d8c0324f0877e7005ec978c2da0d1ed9b44df
b94e45c42c6b6a7cc64fa660419e47bef92b921a
v1.0
complete
Leetcode
Leetcode_31647_C
def is_subsequence(s: str, word: str) -> bool: """ Helper function to check if word is a subsequence of s >>> is_subsequence("abcde", "ace") True >>> is_subsequence("abcde", "aec") False """ # Implement the function here def num_matching_subseq(s: str, words: List[str]) -> int: """ Determine th...
def is_subsequence(s, word): """ Helper function to check if word is a subsequence of s """ it = iter(s) return all(char in it for char in word) def num_matching_subseq(s, words): """ Returns the number of words that are subsequences of s """ count = 0 for word in words: ...
from solution import is_subsequence, num_matching_subseq def test_is_subsequence(): assert is_subsequence("abcde", "ace") == True assert is_subsequence("abcde", "aec") == False assert is_subsequence("abcde", "abcde") == True assert is_subsequence("abcde", "") == True assert is_subsequence("abcde", ...
[ { "docstring": "Helper function to check if word is a subsequence of s", "function_declaration": "def is_subsequence(s, word):", "function_name": "is_subsequence", "parameter_list": "(s, word)" }, { "docstring": "Returns the number of words that are subsequences of s", "function_declarat...
[ 0, 0, 0, 0, 1, 0, 1, 0, 1, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def num_matching_subseq(s, words):\n \"\"\"\n Returns the number of words in the list which are subsequences of the string s.\n \"\"\"\n def is_subsequence(word, ...
trial_gpt4o_8
{ "original_instruction": "You are given a string `s` and a list of words `words`. Determine the **number of words** in `words` that are **subsequences** of `s`. A subsequence of a string is a new string generated from the original string with some characters (can be none) deleted without changing the relative order ...
0.710046
Leetcode_31647
C
[ "is_subsequence", "num_matching_subseq" ]
2
[ [ "num_matching_subseq", "is_subsequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
37f893c153cbc435eb80fafb63d3ce8126a054c7
e7b2fba3b1dd8fd70ce00224827db480cac9ad41
v1.0
complete
Leetcode
Leetcode_31803_C
def find_longest_word(words: List[str], s: str) -> str: """ Returns the largest word in 'words' that can be formed by deleting some characters of 's' without reordering the characters of 's'. If there is more than one possible result, returns the word that appears first in 'words'. If no words...
def is_subsequence(word, s): """ Helper function to check if `word` is a subsequence of `s`. """ it = iter(s) return all(char in it for char in word) def find_longest_word(words, s): """ Returns the largest word in 'words' that can be formed by deleting some characters of 's' without r...
from solution import find_longest_word def test_case1(): words = ["apple", "plea", "ale"] s = "abpcplea" assert find_longest_word(words, s) == "apple" def test_case2(): words = ["a", "b", "c"] s = "abpcplea" assert find_longest_word(words, s) == "a" def test_case3(): words = ["ab", "ba"] ...
[ { "docstring": "Helper function to check if `word` is a subsequence of `s`.", "function_declaration": "def is_subsequence(word, s):", "function_name": "is_subsequence", "parameter_list": "(word, s)" }, { "docstring": "Returns the largest word in 'words' that can be formed by deleting \nsome ...
[ 0, 0, 1, 0, 0, 1, 0, 0, 1, 1 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_subsequence(word, s):\n # Helper function to check if 'word' is a subsequence of 's'\n it = iter(s)\n return all(char in it for char in word)\n\ndef find_larg...
trial_gpt4o_9
{ "original_instruction": "You are provided a list of words, `words`, and a string `s`. Write a function that returns the largest word in `words` that can be formed by deleting some characters of `s` without reordering the characters in `s`. If there is more than one possible result, return the word that appears firs...
0.805251
Leetcode_31803
C
[ "is_subsequence", "find_longest_word" ]
2
[ [ "find_longest_word", "is_subsequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
72376e2b0a2e4e387518158773bada77a891e189
f7da5480ea8838189d0f43fbd94683e85ed8c86c
v1.0
complete
Leetcode
Leetcode_31825_C
def max_pages(books: List[int], k: int) -> int: """ Given an array `books` where each element represents the number of pages in a particular book, and an integer `k` representing the number of friends, find the minimum possible value of the maximum number of pages read by any friend after optimally dividi...
def is_valid(books, n, k, curr_min): current_sum = 0 required_students = 1 for i in range(n): if (books[i] > curr_min): return False if (current_sum + books[i] > curr_min): required_students += 1 current_sum = books[i] if required_students...
from solution import max_pages def test_single_book(): assert max_pages([50], 1) == 50 def test_equal_books(): assert max_pages([10, 10, 10, 10], 2) == 20 def test_books_division(): assert max_pages([10, 20, 30, 40, 50], 2) == 90 assert max_pages([10, 20, 30, 40, 50], 3) == 60 assert max_pages([1...
[ { "docstring": null, "function_declaration": "def is_valid(books, n, k, curr_min):", "function_name": "is_valid", "parameter_list": "(books, n, k, curr_min)" }, { "docstring": null, "function_declaration": "def max_pages(books, k):", "function_name": "max_pages", "parameter_list"...
[ 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def minimize_max_pages(books, k):\n def is_valid(books, k, mid):\n num_students = 1\n current_sum = 0\n for pages in books:\n if current_su...
trial_gpt4o_1
{ "original_instruction": "You are given an array `books` where each element represents the number of pages in a particular book. A group of friends wants to divide these books among themselves such that each friend gets a contiguous segment of books. However, they want to minimize the maximum number of pages any fri...
0.649766
Leetcode_31825
C
[ "is_valid", "max_pages" ]
2
[ [ "max_pages", "is_valid" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a1827b56d18f24928fe5a8d7a092ffb572336013
2c4752b368c08d79b0e2eb4872c2d2639318dd2b
v1.0
complete
Leetcode
Leetcode_31942_C
def longest_word(words: list, letters: str) -> str: """ Returns the longest word that can be constructed from the given letters. >>> longest_word(["apple"], "aplinfre") == "apple" >>> longest_word(["apple", "bat", "cat", "car"], "aplinfre") == "apple" >>> longest_word(["apple", "bat", "cat"], "xyz"...
def can_construct(word, letters): """ Helper function to determine if a word can be constructed from given letters. """ # Create a set of available letters available_letters = set(letters) # Try to construct the word for letter in word: if letter not in available_letters: ...
from solution import longest_word def test_single_word_constructible(): assert longest_word(["apple"], "aplinfre") == "apple" def test_multiple_options(): assert longest_word(["apple", "bat", "cat", "car"], "aplinfre") == "apple" def test_no_words_constructible(): assert longest_word(["apple", "bat", "ca...
[ { "docstring": "Helper function to determine if a word can be constructed from given letters.", "function_declaration": "def can_construct(word, letters):", "function_name": "can_construct", "parameter_list": "(word, letters)" }, { "docstring": "Returns the longest word that can be construct...
[ 0, 0, 1, 0, 0, 0, 0, 0, 1, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def longest_word(words, letters):\n \"\"\"\n Returns the longest word from the array `words` that can be constructed using letters from `letters`\n without repeating...
trial_gpt4o_8
{ "original_instruction": "You are given an array of `words` and a string `letters`. Each word consists of lowercase English letters and the string `letters` contains distinct lowercase English letters. Return _the longest word from the array that can be constructed using letters from_ `letters` without repeating any...
0.8017
Leetcode_31942
C
[ "can_construct", "longest_word" ]
2
[ [ "longest_word", "can_construct" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0ae14f6a5c9e3530b8ee09c1aa47acf128c0977f
19d54fbc00ab40ae2ea4f6542e6ce56642ce92b0
v1.0
complete
Leetcode
Leetcode_32094_C
class ListNode: def __init__(self, x): self.val = x self.next = None def rotateRight(head: ListNode, k: int) -> ListNode: """ Given a linked list, rotate the list to the right by k places, where k is a non-negative integer. Return the head of the rotated linked list. >>> head = Lis...
class ListNode: def __init__(self, x): self.val = x self.next = None def get_list_length(head): length = 0 current = head while current: length += 1 current = current.next return length def rotateRight(head, k): if not head or k == 0: return head ...
from solution import ListNode, rotateRight def linked_list_to_list(head): result = [] current = head while current: result.append(current.val) current = current.next return result def list_to_linked_list(lst): if not lst: return None head = ListNode(lst[0]) current ...
[]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "class ListNode:\n def __init__(self, val=0, next=None):\n self.val = val\n self.next = next\n\ndef rotateRight(head, k):\n if not head or not head.next or...
trial_gpt4o_8
{ "original_instruction": "Given a linked list, rotate the list to the right by `k` places, where `k` is a non-negative integer. Return _the head of the rotated linked list_. Here is the definition for the singly linked list node:\n\nclass ListNode {\n int val;\n ListNode next;\n ListNode(int x) {\n ...
0.654185
Leetcode_32094
C
[ "get_list_length", "rotateRight" ]
2
[ [ "rotateRight", "get_list_length" ] ]
1
[]
false
[ "ListNode" ]
true
pytest
true
[]
true
c6d083a92c7075ec757cddc733bbeebde2b65fc7
9096299f853c52c2bca6f1557d09b60cb9b71ce6
v1.0
complete
Leetcode
Leetcode_32138_C
def is_prime(n: int) -> bool: """ Check if a number is prime. >>> is_prime(2) True >>> is_prime(3) True >>> is_prime(4) False >>> is_prime(11) True """ def reverse_number(n: int) -> int: """ Reverse the digits of a number. >>> reverse_number(123) 321 >>> reverse_number(400) 4...
def is_prime(n): """ Check if a number is prime. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 return True...
from solution import is_prime, reverse_number, largest_emirp def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(11) == True def test_reverse_number(): assert reverse_number(123) == 321 assert reverse_number(400) == 4 asser...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Reverse the digits of a number.", "function_declaration": "def reverse_number(n):", "function_name": "reverse_number", ...
[ 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_prime(n):\n if n <= 1:\n return False\n if n == 2:\n return True \n if n % 2 == 0:\n return False\n for i in range(3, int(n**0.5) + 1,...
trial_gpt4o_4
{ "original_instruction": "A **prime number** is a natural number greater than 1 that has no positive divisors other than 1 and itself. A prime number `p` is called an **emirp** if the reverse of its digits is also a prime. Given an integer `k`, return _the **largest emirp** number **less than or equal to**_ `k`_. If...
0.694297
Leetcode_32138
C
[ "is_prime", "reverse_number", "largest_emirp" ]
3
[ [ "largest_emirp", "is_prime" ], [ "largest_emirp", "reverse_number" ] ]
2
[]
false
[]
false
pytest
true
[]
true
82120a5574af03661efcde608d6efe4c1579b847
80fe6a84f9fa2eb66da56b5f1cd868ab878bb566
v1.0
complete
Leetcode
Leetcode_32347_C
class ListNode: def __init__(self, val=0, prev=None, next=None): self.val = val self.prev = prev self.next = next def merge_k_lists(lists): """ Write a function to merge a group of `k` sorted doubly linked lists into a single sorted doubly linked list. :param lists: List of Lis...
class ListNode: def __init__(self, val=0, prev=None, next=None): self.val = val self.prev = prev self.next = next def merge_two_lists(l1, l2): dummy = ListNode() curr = dummy while l1 and l2: if l1.val < l2.val: curr.next = l1 l1.prev = curr ...
from solution import ListNode, merge_k_lists def list_to_doubly_linked_list(lst): if not lst: return None head = ListNode(lst[0]) current = head for val in lst[1:]: new_node = ListNode(val) current.next = new_node new_node.prev = current current = new_node re...
[]
[ 1, 1, 0, 1, 1, 1, 1, 1, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "class ListNode:\n def __init__(self, value=0, next=None, prev=None):\n self.value = value\n self.next = next\n self.prev = prev\n\ndef merge_two_lists...
trial_gpt4o_9
{ "original_instruction": "You are given a **doubly linked list** where each node contains an integer value and a pointer to the next node and the previous node. Write a function to merge a group of `k` sorted doubly linked lists into a single sorted doubly linked list. The function should efficiently merge the lists...
0.541123
Leetcode_32347
C
[ "merge_two_lists", "merge_k_lists" ]
2
[ [ "merge_k_lists", "merge_two_lists" ] ]
1
[]
false
[ "ListNode" ]
true
pytest
true
[]
true
c401686312e39baa1a93bfb1a049e4edf578469b
d6bc9fceda044c8095201d540625eb1f5889f138
v1.0
complete
Leetcode
Leetcode_32598_C
class TreeNode: def __init__(self, value): self.value = value self.left = None self.right = None def add_child(parent, child, is_left, nodes): if is_left: parent.left = child else: parent.right = child nodes[child.value - 1] = child def find_max_depth_node(relat...
class TreeNode: def __init__(self, value): self.value = value self.left = None self.right = None def add_child(parent, child, is_left, nodes): if is_left: parent.left = child else: parent.right = child nodes[child.value - 1] = child def find_max_depth_node(relat...
from solution import find_max_depth_node def test_single_node_tree(): relations = [] assert find_max_depth_node(relations) == -1 def test_two_node_tree(): relations = [[1, 2, 1]] assert find_max_depth_node(relations) == 2 def test_left_heavy_tree(): relations = [[1, 2, 1], [2, 3, 1], [3, 4, 1]] ...
[]
[ 1, 1, 1, 0, 1, 1, 0, 0, 0, 1 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, value):\n self.value = value\n self.left = None\n self.right = None\n\ndef findNodeWithMaxDepth(n, relations):\n ...
trial_gpt4o_4
{ "original_instruction": "You are given a binary tree with `n` nodes. Each node is uniquely assigned a value from `1` to `n`. All left and right child pointers in the tree are initially `null`. You are provided with a **0-indexed** 2D integer array `relations` where `relations[i] = [parenti, childi, isLefti]` indica...
0.524876
Leetcode_32598
C
[ "add_child", "find_max_depth_node" ]
2
[ [ "find_max_depth_node", "add_child" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
86ba058ada97a171455218c82eaca8fffee444ae
9996cd977f67e488797c0f1418213e4129764ded
v1.0
complete
Leetcode
Leetcode_32864_C
def is_palindrome(s: str) -> bool: """ Helper function to check if a string is a palindrome.""" return s == s[::-1] def max_sum_of_palindromic_substrings(s: str) -> int: """ Find the maximum sum of substrings such that no two substrings overlap and each substring is a palindrome. >>> max_sum_of_palindr...
def is_palindrome(s): return s == s[::-1] def max_sum_of_palindromic_substrings(s): n = len(s) dp = [0] * (n + 1) for i in range(1, n + 1): for j in range(i): if is_palindrome(s[j:i]): dp[i] = max(dp[i], dp[j] + int(s[j:i])) return dp[n]
from solution import max_sum_of_palindromic_substrings def test_single_digit(): assert max_sum_of_palindromic_substrings("5") == 5 def test_no_palindromes(): assert max_sum_of_palindromic_substrings("12345") == 15 # summing all individual digits def test_all_palindromes(): assert max_sum_of_palindromic_...
[ { "docstring": null, "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": null, "function_declaration": "def max_sum_of_palindromic_substrings(s):", "function_name": "max_sum_of_palindromic_substrings", "para...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_palindrome(s):\n return s == s[::-1]\n\ndef max_palindrome_sum(s):\n n = len(s)\n dp = [0] * (n + 1)\n \n for i in range(1, n + 1):\n for j in ra...
trial_gpt4o_9
{ "original_instruction": "You are given a string `s` that consists of only digits. We want to find the maximum sum of its substrings such that no two substrings overlap and each substring is a palindrome. Return the maximum sum you can achieve. A substring `s[i:j]` is a palindrome if it reads the same backward as fo...
0.731918
Leetcode_32864
C
[ "is_palindrome", "max_sum_of_palindromic_substrings" ]
2
[ [ "max_sum_of_palindromic_substrings", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2aa2a1a6862136bc85b51318fdafd62fa9ed3cdd
5a0e34ce6eda00e0fcbc3dae09a7143db607a4d5
v1.0
complete
Leetcode
Leetcode_33179_C
def is_subsequence(small: str, large: str) -> bool: """Check if a string is a subsequence of another string. Args: small (str): The string to check as a subsequence. large (str): The string to check against. Returns: bool: True if small is a subsequence of large, False otherwise. ...
def is_subsequence(small, large): it = iter(large) return all(char in it for char in small) def count_subsequences(patterns, s): count = 0 for pattern in patterns: if is_subsequence(pattern, s): count += 1 return count
from solution import is_subsequence, count_subsequences def test_is_subsequence(): assert is_subsequence("abc", "aabbcc") == True assert is_subsequence("abc", "acb") == False assert is_subsequence("abc", "abacbc") == True assert is_subsequence("", "anything") == True assert is_subsequence("longsequ...
[ { "docstring": null, "function_declaration": "def is_subsequence(small, large):", "function_name": "is_subsequence", "parameter_list": "(small, large)" }, { "docstring": null, "function_declaration": "def count_subsequences(patterns, s):", "function_name": "count_subsequences", "...
[ 0, 1, 0, 0, 0, 1, 0, 0, 1, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_subsequence(pattern, s):\n \"\"\"\n Helper function to check if `pattern` is a subsequence of `s`.\n \"\"\"\n it = iter(s)\n return all(char in it for c...
trial_gpt4o_8
{ "original_instruction": "You are given a list of strings `patterns` and a single string `s`. A string is considered a subsequence of another string if it can be derived from the other string by deleting some characters without changing the order of the remaining characters. Your task is to determine how many string...
0.72216
Leetcode_33179
C
[ "is_subsequence", "count_subsequences" ]
2
[ [ "count_subsequences", "is_subsequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0661d3c9be16b5483824b2f13a39ad65bac72e05
2fda68d61089681f6c210ada452e36355eb5a803
v1.0
complete
Leetcode
Leetcode_33578_C
from typing import List def is_one_char_different(word1: str, word2: str) -> bool: """ Helper function to determine if two words differ by exactly one character. """ pass def minTransformations(wordList: List[str], targetWord: str) -> int: """ Returns the minimum number of transformations need...
from collections import deque def is_one_char_different(word1, word2): """ Helper function to determine if two words differ by exactly one character. """ if len(word1) != len(word2): return False diff_count = sum(1 for a, b in zip(word1, word2) if a != b) return diff_count == 1 def min...
import pytest from solution import minTransformations def test_no_possible_transformation(): wordList = ["hot", "dot", "dog", "lot", "log"] targetWord = "hit" assert minTransformations(wordList, targetWord) == -1 def test_single_transformation(): wordList = ["hot", "dot", "dog", "lot", "log"] targ...
[ { "docstring": "Helper function to determine if two words differ by exactly one character.", "function_declaration": "def is_one_char_different(word1, word2):", "function_name": "is_one_char_different", "parameter_list": "(word1, word2)" }, { "docstring": "Returns the minimum number of trans...
[ 0, 0, 1, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "import collections\nfrom typing import List\n\ndef minTransformations(wordList: List[str], targetWord: str) -> int:\n wordSet = set(wordList)\n if targetWord not in wor...
trial_gpt4o_2
{ "original_instruction": "You are given a list of strings `wordList` of length `n` and a target string `targetWord`. Each word in `wordList` has the same length as `targetWord`. You need to transform `targetWord` into another word by changing exactly one character at a time. Each transformed word must exist in `word...
0.711966
Leetcode_33578
C
[ "is_one_char_different", "minTransformations" ]
2
[ [ "minTransformations", "is_one_char_different" ] ]
1
[]
false
[]
false
pytest
true
[]
true
bc780e78a326e01eace2a37f886e766fe3ed70c1
62e93fcc45643fcccd66b4cc054cd97b527461e2
v1.0
complete
Leetcode
Leetcode_33649_C
def can_form_prefix(words: List[str], pref: str) -> bool: """ Checks if it is possible to make at least one of the words start with the prefix `pref` after removing any number of characters from the words. >>> can_form_prefix(["apple", "banana", "cherry"], "ape") True >>> can_form_prefix(["apple", "bana...
def can_form_prefix(words, pref): """ Checks if it is possible to make at least one of the words start with the prefix `pref` after removing any number of characters from the words. """ # Sorting the prefix itself due to the operation: Letters are arbitrary in positions pref_sorted = sorted(pre...
from solution import can_form_prefix def test_can_form_prefix_true_case(): assert can_form_prefix(["apple", "banana", "cherry"], "ape") == True def test_can_form_prefix_false_case(): assert can_form_prefix(["apple", "banana", "cherry"], "xyz") == False def test_can_form_prefix_prefix_longer_than_word(): ...
[ { "docstring": "Checks if it is possible to make at least one of the words start with the prefix `pref` \nafter removing any number of characters from the words.", "function_declaration": "def can_form_prefix(words, pref):", "function_name": "can_form_prefix", "parameter_list": "(words, pref)" }, ...
[ 0, 1, 0, 0, 0, 0, 0, 1, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def can_form_prefix(words, pref):\n \"\"\"\n Determines if it is possible to make at least one of the words start with the prefix `pref`\n after removing a single ch...
trial_gpt4o_7
{ "original_instruction": "You are given an array of strings `words` and a prefix string `pref`. You may perform the following operation any number of times:\n\n * Choose any word `w` from `words` and remove a single character from `w`.\n\nYour goal is to determine if it is possible to make at least one of the wor...
0.767344
Leetcode_33649
C
[ "can_form_prefix", "can_form_from" ]
2
[ [ "can_form_prefix", "can_form_from" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ea8062050bb52ae6dea2e21dc392f9e85f1bab33
803603f5a6d8ea5b27d6916e3cdbd527c61f1539
v1.0
complete
Leetcode
Leetcode_33794_C
def is_prime(n: int) -> bool: """ Returns True if n is a prime number, otherwise False. >>> is_prime(1) == False >>> is_prime(2) == True >>> is_prime(3) == True >>> is_prime(4) == False >>> is_prime(5) == True >>> is_prime(9) == False >>> is_prime(11) == True >>> is_prime(25) == ...
def is_prime(n): """ Returns True if n is a prime number, otherwise False. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False ...
def test_next_prime(): assert next_prime(1) == 2 assert next_prime(2) == 3 assert next_prime(3) == 5 assert next_prime(10) == 11 assert next_prime(14) == 17 assert next_prime(20) == 23 assert next_prime(30) == 31 assert next_prime(100) == 101 assert next_prime(200) == 211 def test_i...
[ { "docstring": "Returns True if n is a prime number, otherwise False.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns the smallest prime number greater than n.", "function_declaration": "def next_prime(n):", ...
[ 1, 1, 1, 1, 1, 1, 1, 0, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"\n Helper function to determine if a number is a prime number.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n ...
trial_gpt4o_4
{ "original_instruction": "Given an integer `n`, return the smallest prime number that is greater than `n`. A prime number is a natural number greater than 1 that is not divisible by any number other than 1 and itself. Use an efficient algorithm to handle large values of `n`.", "prompt_id": "0000033794", "row_id"...
0.843546
Leetcode_33794
C
[ "is_prime", "next_prime" ]
2
[ [ "next_prime", "is_prime" ] ]
1
[]
false
[]
false
pytest
false
[]
true
185da2cfab76e8312e1f4be60da330a15ea76c57
e755c8807e857c378f54ea2a3650f36989e22380
v1.0
complete
Leetcode
Leetcode_33918_C
def is_subsequence(small: str, large: str) -> bool: """ Check if 'small' is a subsequence of 'large'. >>> is_subsequence("abc", "abcd") True >>> is_subsequence("de", "efghi") True >>> is_subsequence("gh", "efghi") False """ def count_subsequences(words1: list[str], words2: list[str]) ->...
def is_subsequence(small, large): """ Helper function to determine if 'small' is a subsequence of 'large'. """ it = iter(large) return all(char in it for char in small) def count_subsequences(words1, words2): """ Counts the number of strings in words1 which are subsequences of any strings i...
from solution import count_subsequences def test_example_case(): words1 = ["abc", "de", "f", "gh"] words2 = ["abcd", "efghi"] assert count_subsequences(words1, words2) == 3 def test_empty_words1(): words1 = [] words2 = ["abcd", "efghi"] assert count_subsequences(words1, words2) == 0 def test_...
[ { "docstring": "Helper function to determine if 'small' is a subsequence of 'large'.", "function_declaration": "def is_subsequence(small, large):", "function_name": "is_subsequence", "parameter_list": "(small, large)" }, { "docstring": "Counts the number of strings in words1 which are subseq...
[ 0, 0, 0, 0, 1, 1, 0, 0, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_subsequence(s, t):\n \"\"\"\n Helper function to determine if string `s` is a subsequence of string `t`.\n \"\"\"\n it = iter(t)\n return all(char in it...
trial_gpt4o_5
{ "original_instruction": "You are given two string arrays `words1` and `words2`. A string `b` is a **subsequence** of a string `a` if `b` can be obtained from `a` by deleting some number of characters (possibly zero), without rearranging the remaining characters. Determine the count of strings in `words1` that are s...
0.683523
Leetcode_33918
C
[ "is_subsequence", "count_subsequences" ]
2
[ [ "count_subsequences", "is_subsequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
df47036297df01d830a6a45dbfc1a687420debac
6b8b44624f0f1c82ea4ee5f827dc52fa4372d4a6
v1.0
complete
Leetcode
Leetcode_33954_C
import math from typing import List, Tuple def euclidean_distance(p1: Tuple[int, int], p2: Tuple[int, int]) -> float: """ Calculate the Euclidean distance between two points p1 and p2. """ return math.sqrt((p1[0] - p2[0])**2 + (p1[1] - p2[1])**2) def kth_closest_pair(friends: List[Tuple[int, int]], k:...
import math from itertools import combinations def euclidean_distance(p1, p2): """ Calculate the Euclidean distance between two points p1 and p2. """ return math.sqrt((p1[0] - p2[0])**2 + (p1[1] - p2[1])**2) def kth_closest_pair(friends, k): """ Find the k-th closest pair of friends based on t...
from solution import kth_closest_pair def test_kth_closest_pair_case_1(): friends = [(0, 0), (1, 1), (2, 2)] assert kth_closest_pair(friends, 1) == [0, 1] def test_kth_closest_pair_case_2(): friends = [(0, 0), (1, 1), (2, 2)] assert kth_closest_pair(friends, 2) == [1, 2] def test_kth_closest_pair_cas...
[ { "docstring": "Calculate the Euclidean distance between two points p1 and p2.", "function_declaration": "def euclidean_distance(p1, p2):", "function_name": "euclidean_distance", "parameter_list": "(p1, p2)" }, { "docstring": "Find the k-th closest pair of friends based on the Euclidean dist...
[ 0, 0, 1, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "import math\nfrom itertools import combinations\n\ndef euclidean_distance(pos1, pos2):\n \"\"\"\n Calculate the Euclidean distance between two points pos1 and pos2.\n ...
trial_gpt4o_2
{ "original_instruction": "You are given a list of `n` friends numbered from `0` to `n-1`. Each friend is represented by a pair `(xi, yi)` which indicates their position on a 2D grid. You are also given an integer `k`. The goal is to find the **k-th closest pair** of friends based on the **Euclidean distance** betwee...
0.672636
Leetcode_33954
C
[ "euclidean_distance", "kth_closest_pair" ]
2
[ [ "kth_closest_pair", "euclidean_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3a4f7eadcd866183282b780054be4a0dfa2fcc3e
71781ecc29d169133ee0ed7eaffe1af5a39d0e89
v1.0
complete
Leetcode
Leetcode_34048_C
class TreeNode: def __init__(self, value=0, left=None, right=None): self.value = value self.left = left self.right = right def find_minimum_distance(root: TreeNode, x: int, y: int) -> int: """ Given the root of a binary tree and two integers x and y, find the minimum distance be...
class TreeNode: def __init__(self, value=0, left=None, right=None): self.value = value self.left = left self.right = right def find_lca(root, x, y): if not root: return None if root.value == x or root.value == y: return root left_lca = find_lca(root.left, x, y) ...
def test_find_minimum_distance(): # Create the tree # 1 # / \ # 2 3 # / \ \ # 4 5 6 root = TreeNode(1) root.left = TreeNode(2) root.right = TreeNode(3) root.left.left = TreeNode(4) root.left.right = TreeNode(5) root.right.right = TreeNode(6) ...
[]
[ 1, 1, 1, 0, 1, 1, 1, 1, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\ndef findDistance(root,...
trial_gpt4o_4
{ "original_instruction": "You are given a binary tree where each node represents a different unique integer value. The distance between two nodes in the tree is defined as the number of edges in the path connecting them. Given the root of the tree and two integers `x` and `y`, find the minimum distance between the n...
0.622111
Leetcode_34048
C
[ "find_lca", "find_distance_from_lca", "find_minimum_distance" ]
3
[ [ "find_minimum_distance", "find_distance_from_lca" ], [ "find_minimum_distance", "find_lca" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
false
[]
true
71969b4ade4879610fd236c9986342c372eb117d
a3b5c8c69299c5a0d6e5e0e6803db47fe12c1e19
v1.0
complete
Leetcode
Leetcode_34127_C
def manhattan_distance(point1, point2): """ Returns the Manhattan distance between two points. >>> manhattan_distance([1, 2], [4, 6]) 7 >>> manhattan_distance([1, 1], [1, 1]) 0 """ ... def closest_pair(points): """ Returns the Manhattan distance of the closest pair of points. ...
def manhattan_distance(point1, point2): """ Returns the Manhattan distance between two points. """ return abs(point1[0] - point2[0]) + abs(point1[1] - point2[1]) def closest_pair(points): """ Returns the Manhattan distance of the closest pair of points. """ min_distance = float('inf') ...
from solution import closest_pair def test_closest_pair_basic(): points = [[1, 2], [4, 6], [1, 3]] assert closest_pair(points) == 1 def test_closest_pair_multiple_points(): points = [[0, 0], [0, 2], [0, 4], [2, 0]] assert closest_pair(points) == 2 def test_closest_pair_same_points(): points = [[1...
[ { "docstring": "Returns the Manhattan distance between two points.", "function_declaration": "def manhattan_distance(point1, point2):", "function_name": "manhattan_distance", "parameter_list": "(point1, point2)" }, { "docstring": "Returns the Manhattan distance of the closest pair of points....
[ 1, 0, 1, 0, 1, 0, 0, 0, 1, 0 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def manhattan_distance(point1, point2):\n \"\"\"\n Helper function to calculate the Manhattan distance between two points.\n \"\"\"\n return abs(point1[0] - point...
trial_gpt4o_4
{ "original_instruction": "There are `n` distinct points on a 2D plane, each represented by an array `points` where `points[i] = [xi, yi]` indicates that there is a point at coordinates `(xi, yi)`. Your task is to determine the pair of points that are closest to each other, and return the **Manhattan distance** betwe...
0.661646
Leetcode_34127
C
[ "manhattan_distance", "closest_pair" ]
2
[ [ "closest_pair", "manhattan_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
fec3cc960e024e6448c818af795211434615321f
5f6cb342d60993c15cb35c2f47d99adcd4b48bac
v1.0
complete
Leetcode
Leetcode_34152_C
from typing import List def find_kth_largest(nums: List[int], k: int) -> int: """ Given a list of integers `nums` and an integer `k`, where `k` is guaranteed to be smaller than the length of the list, find the `k`-th largest element in the list in `O(n)` average time complexity. >>> find_kth_largest([...
import random def partition(nums, left, right): pivot_index = random.randint(left, right) pivot_value = nums[pivot_index] nums[pivot_index], nums[right] = nums[right], nums[pivot_index] store_index = left for i in range(left, right): if nums[i] < pivot_value: nums[i], nums[store...
from solution import find_kth_largest def test_example_case(): assert find_kth_largest([3, 2, 1, 5, 6, 4], 2) == 5 def test_single_element(): assert find_kth_largest([1], 1) == 1 def test_sorted_array(): assert find_kth_largest([1, 2, 3, 4, 5], 4) == 2 def test_reversed_array(): assert find_kth_larg...
[ { "docstring": null, "function_declaration": "def partition(nums, left, right):", "function_name": "partition", "parameter_list": "(nums, left, right)" }, { "docstring": null, "function_declaration": "def quick_select(nums, left, right, k):", "function_name": "quick_select", "par...
[ 1, 1, 1, 0, 1, 1, 1, 1, 0 ]
7
easy
0.778
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "import random\n\ndef partition(nums, left, right, pivot_index):\n pivot_value = nums[pivot_index]\n nums[pivot_index], nums[right] = nums[right], nums[pivot_index]\n ...
trial_gpt4o_8
{ "original_instruction": "Given a list of integers `nums` and an integer `k`, where `k` is guaranteed to be smaller than the length of the list, find the `k`-th largest element in the list. Note that it is the `k`-th largest element in the sorted order, not the `k`-th distinct element. You must solve it in `O(n)` av...
0.802198
Leetcode_34152
C
[ "partition", "quick_select", "find_kth_largest" ]
3
[ [ "find_kth_largest", "quick_select" ], [ "quick_select", "partition" ] ]
2
[]
false
[]
false
pytest
true
[]
true
20501e1ffffba533df9d78f93d9d802cf628c57d
54002933978f52dd4512a2d8386a3a8ae4328e52
v1.0
complete
Leetcode
Leetcode_34481_C
from typing import List def min_job_duration(nums: List[int], d: int) -> int: """ Given an array of integers `nums`, where `nums[i]` represents a different job's duration, and an integer `d` which represents the maximum number of days you have to complete all the jobs, return the minimum possible maximum j...
from typing import List def is_valid(nums: List[int], days: int, max_job_duration: int) -> bool: day_count = 1 current_duration = 0 for num in nums: if current_duration + num > max_job_duration: day_count += 1 current_duration = 0 current_duration += num if d...
from solution import min_job_duration def test_min_job_duration_single_day(): assert min_job_duration([7, 2, 5, 10, 8], 1) == 32 # Sum of all jobs def test_min_job_duration_multiple_days(): assert min_job_duration([7, 2, 5, 10, 8], 2) == 18 assert min_job_duration([7, 2, 5, 10, 8], 3) == 14 assert mi...
[ { "docstring": null, "function_declaration": "def is_valid(nums, days, max_job_duration):", "function_name": "is_valid", "parameter_list": "(nums, days, max_job_duration)" }, { "docstring": null, "function_declaration": "def min_job_duration(nums, days):", "function_name": "min_job_d...
[ 0, 0, 0, 0, 1, 0, 0, 1, 1, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def min_max_job_duration(nums, d):\n def possible(max_job_duration):\n days_needed = 1\n current_total = 0\n for duration in nums:\n if cur...
trial_gpt4o_8
{ "original_instruction": "Given an array of integers `nums`, where `nums[i]` represents a different job's duration, and an integer `d` which represents the maximum number of days you have to complete all the jobs. Your goal is to minimize the maximum job duration that you need to work over the days. Return the minim...
0.665707
Leetcode_34481
C
[ "is_valid", "min_job_duration" ]
2
[ [ "min_job_duration", "is_valid" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b2564486151bf27fb8269d6f0502d8683a557b80
5b0c8c68307835ca38ab29c67627972c62009f69
v1.0
complete
Leetcode
Leetcode_34551_C
def find_min_radius(houses: List[int], heaters: List[int]) -> int: """ Returns the minimum radius `r` such that all houses can be covered by at least one heater. >>> find_min_radius([1, 2, 3], [2]) 1 >>> find_min_radius([1, 2, 3, 4], [1, 4]) 1 >>> find_min_radius([1, 5, 9], [2, 8]) ...
def find_closest_heater(house, heaters): """ Returns the minimum distance from the house to the nearest heater using binary search. """ left, right = 0, len(heaters) - 1 while left < right: mid = (left + right) // 2 if heaters[mid] < house: left = mid + 1 else: ...
from solution import find_min_radius def test_example_case_1(): houses = [1, 2, 3] heaters = [2] assert find_min_radius(houses, heaters) == 1 def test_example_case_2(): houses = [1, 2, 3, 4] heaters = [1, 4] assert find_min_radius(houses, heaters) == 1 def test_houses_between_heaters(): h...
[ { "docstring": "Returns the minimum distance from the house to the nearest heater using binary search.", "function_declaration": "def find_closest_heater(house, heaters):", "function_name": "find_closest_heater", "parameter_list": "(house, heaters)" }, { "docstring": "Returns the minimum rad...
[ 0, 1, 0, 0, 0, 0, 0, 1, 1, 1 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def findRadius(houses, heaters):\n \"\"\"\n Finds the minimum radius required to cover all houses using the provided heaters.\n \n Args:\n houses (List[int]): ...
trial_gpt4o_9
{ "original_instruction": "You are given an array `houses` and an integer `heaters`. Each element in `houses` represents the position of a house along a street, and each element in `heaters` represents the position of a heater along the street. Both arrays are sorted in ascending order. Every house can only be warmed...
0.539635
Leetcode_34551
C
[ "find_closest_heater", "find_min_radius" ]
2
[ [ "find_min_radius", "find_closest_heater" ] ]
1
[]
false
[]
false
pytest
true
[]
true
01b07f65223b822050c35abb5c03e15abdde450e
0665d787004fcfdc11becdd8b31fddd4fb5a4ca4
v1.0
complete
Leetcode
Leetcode_34575_C
def splitArray(nums: List[int], k: int) -> int: """ Returns the minimum possible maximum reading time to split the array into k subarrays. >>> splitArray([7, 2, 5, 10, 8], 2) == 18 >>> splitArray([1, 1, 1, 1], 2) == 2 >>> splitArray([1, 2, 3, 4, 5], 1) == 15 >>> splitArray([1, 2, 3, 4, 5], 5) == 5 ...
def can_split(nums, k, max_time): current_sum = 0 required_splits = 1 for num in nums: if current_sum + num > max_time: required_splits += 1 current_sum = num if required_splits > k: return False else: current_sum += num ret...
from solution import splitArray def test_split_array_simple_case(): assert splitArray([7, 2, 5, 10, 8], 2) == 18 def test_split_array_all_equal(): assert splitArray([1, 1, 1, 1], 2) == 2 def test_split_array_single_subarray(): assert splitArray([1, 2, 3, 4, 5], 1) == 15 def test_split_array_large_k(): ...
[ { "docstring": null, "function_declaration": "def can_split(nums, k, max_time):", "function_name": "can_split", "parameter_list": "(nums, k, max_time)" }, { "docstring": "Returns the minimum possible maximum reading time to split the array into k subarrays.", "function_declaration": "def...
[ 0, 1, 0, 1, 1, 1, 1, 0, 0, 1 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def splitArray(nums, k):\n def valid(mid):\n current_sum, splits = 0, 1\n for num in nums:\n if current_sum + num > mid:\n splits +...
trial_gpt4o_9
{ "original_instruction": "Given an array of integers `nums` and an integer `k`, where the array represents the number of books and each integer in the array represents the time required to read a book. You want to split the books into `k` contiguous subarrays (each subarray represents a set of books assigned to one ...
0.648009
Leetcode_34575
C
[ "can_split", "splitArray" ]
2
[ [ "splitArray", "can_split" ] ]
1
[]
false
[]
false
pytest
true
[]
true
330d954bc2817feb177637620ecda4f2e3e54d0e
49a205bd105f36a9ed0f23c5f370981ed418d1f2
v1.0
complete
Leetcode
Leetcode_34583_C
class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None def array_to_tree(arr): """ Convert an array representation of a tree to a TreeNode """ if not arr: return None nodes = [None if val is None else TreeNode(val) for val in arr] kid ...
class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None def array_to_tree(arr): if not arr: return None nodes = [None if val is None else TreeNode(val) for val in arr] kid = nodes[::-1] root = kid.pop() for node in nodes: ...
from solution import longest_univalue_path def test_longest_univalue_path_single_value(): assert longest_univalue_path([5, 5, 5, 5, 5, None, 5]) == 4 def test_longest_univalue_path_no_univalue_paths(): assert longest_univalue_path([1, 2, 3, 4, 5]) == 0 def test_longest_univalue_path_single_node(): assert...
[]
[ 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, x):\n self.val = x\n self.left = None\n self.right = None\n\ndef longestUnivaluePath(root):\n \"\"\"\n Give...
trial_gpt4o_3
{ "original_instruction": "Given a binary tree, find the longest path where each node in the path has the same value. This path may or may not pass through the root. The length of the path is the number of edges between the nodes in the path. You need to return the length of this longest path. The tree is represented...
0.562831
Leetcode_34583
C
[ "array_to_tree", "longest_univalue_path" ]
2
[ [ "longest_univalue_path", "array_to_tree" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
0900e21fec5900ece09c4c21315c28def0868ff0
418c7a47ddeba696eb9a8d373bd76409c3ae90e8
v1.0
complete
Leetcode
Leetcode_34636_C
class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None def build_tree(arr): """Build a binary tree in a level-order manner from the given array.""" if not arr: return None nodes = [TreeNode(val) if val is not None else None for val in...
class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None def build_tree(arr): if not arr: return None nodes = [TreeNode(val) if val is not None else None for val in arr] root = nodes[0] child_index = 1 for node in nodes: ...
import pytest from solution import TreeNode, build_tree, longest_unique_path_from_array def test_empty_array(): assert longest_unique_path_from_array([]) == 0 def test_single_element_array(): assert longest_unique_path_from_array([1]) == 1 def test_unique_elements(): assert longest_unique_path_from_array...
[]
[ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, x):\n self.val = x\n self.left = None\n self.right = None\n\ndef build_tree(arr):\n if not arr:\n retur...
trial_gpt4o_0
{ "original_instruction": "Given an array of integers `arr` of size `n`, implement a function to find and return the length of the longest **unique path** in a binary tree structured from the `arr` elements such that each node in this path has a unique value. Here, unique path means each node's value appears only onc...
0.572021
Leetcode_34636
C
[ "build_tree", "longest_unique_path", "longest_unique_path_from_array" ]
3
[ [ "longest_unique_path_from_array", "build_tree" ], [ "longest_unique_path_from_array", "longest_unique_path" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
6a8fe765bcdd04d0fde0c69d1d08a4d5075193a1
f8dc825adecf5e58a33ec9da4695763cde56aec6
v1.0
complete
Leetcode
Leetcode_34936_C
from typing import List def isValidSquare(points: List[List[int]]) -> bool: """ Determines if a set of four of these points can form a square. >>> isValidSquare([[0, 0], [1, 0], [1, 1], [0, 1]]) True >>> isValidSquare([[0, 0], [2, 0], [3, 1], [1, 1]]) False >>> isValidSquare([[0, 0], [1, 1], [1...
from typing import List from itertools import combinations def distance_squared(p1, p2): return (p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2 def is_square(p1, p2, p3, p4): distances = [ distance_squared(p1, p2), distance_squared(p1, p3), distance_squared(p1, p4), distance_square...
from solution import isValidSquare def test_no_points(): assert not isValidSquare([]) def test_less_than_four_points(): assert not isValidSquare([[0, 0], [1, 1]]) assert not isValidSquare([[0, 0], [1, 1], [1, 0]]) def test_four_collinear_points(): assert not isValidSquare([[0, 0], [1, 1], [2, 2],...
[ { "docstring": null, "function_declaration": "def distance_squared(p1, p2):", "function_name": "distance_squared", "parameter_list": "(p1, p2)" }, { "docstring": null, "function_declaration": "def is_square(p1, p2, p3, p4):", "function_name": "is_square", "parameter_list": "(p1, ...
[ 1, 0, 0, 0, 0, 1, 1, 1, 1, 1 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "import itertools\nimport math\nfrom typing import List\n\ndef distance_sq(p1, p2):\n \"\"\"\n Calculate squared distance between two points p1 and p2.\n \"\"\"\n ...
trial_gpt4o_9
{ "original_instruction": "You are given a list of `points` in the 2D plane. Each point is represented as a coordinate pair `[x, y]`. Your task is to determine if a set of four of these points can form a square. A square is defined as a quadrilateral with four equal sides and four right angles. \n\nWrite a function `...
0.602352
Leetcode_34936
C
[ "distance_squared", "is_square", "isValidSquare" ]
3
[ [ "isValidSquare", "is_square" ], [ "is_square", "distance_squared" ] ]
2
[]
false
[]
false
pytest
true
[]
true
9153ea0b2a0839701aba28d6ff62e48feb2d360f
0af2aa6109373e520cac57a01e15323b43ffe40d
v1.0
complete
Leetcode
Leetcode_35177_C
import math from typing import List def is_prime(n: int) -> bool: """Helper function to determine if a number `n` is prime.""" if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i...
import math def is_prime(n): """Helper function to determine if a number `n` is prime.""" if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False ...
from solution import count_elements_with_three_divisors def test_single_element_with_three_divisors(): assert count_elements_with_three_divisors([4]) == 1 def test_multiple_elements_with_three_divisors(): assert count_elements_with_three_divisors([4, 9, 25]) == 3 def test_no_elements_with_three_divisors(): ...
[ { "docstring": "Helper function to determine if a number `n` is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Counts the number of elements in the array `arr` that have exactly three divisors.", "function_decl...
[ 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "import math\n\ndef is_prime(n):\n if n <= 1:\n return False\n if n == 2 or n == 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n return False\n...
trial_gpt4o_6
{ "original_instruction": "Given an integer array `arr`, you need to count the number of elements that have **exactly** three divisors. A number `x` is said to have exactly `3` divisors if there exist exactly three distinct integers `a`, `b`, and `c` such that `a * b * c = x`. Return _the **count** of such elements i...
0.752703
Leetcode_35177
C
[ "is_prime", "count_elements_with_three_divisors" ]
2
[ [ "count_elements_with_three_divisors", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
60ddaa77e59af432cf2e4f6092c315c4a4147d41
e9411d36d282c82a1c23d550af5c42792d704cee
v1.0
complete
Leetcode
Leetcode_35187_C
from typing import List def minimize_difference(nums: List[int], k: int) -> int: """ Split the array `nums` into `k` consecutive subarrays such that the difference between the maximum sum of any subarray and the minimum sum of any subarray is minimized. Return the minimum difference between the maxim...
def can_partition(nums, k, max_sum): current_sum = 0 required_subarrays = 1 for num in nums: if current_sum + num > max_sum: required_subarrays += 1 current_sum = num if required_subarrays > k: return False else: current_su...
def test_minimize_difference_example(): nums = [7, 2, 5, 10, 8] k = 2 assert minimize_difference(nums, k) == 18 def test_minimize_difference_single_element(): nums = [10] k = 1 assert minimize_difference(nums, k) == 10 def test_minimize_difference_all_same_elements(): nums = [5, 5, 5, 5, 5...
[ { "docstring": null, "function_declaration": "def can_partition(nums, k, max_sum):", "function_name": "can_partition", "parameter_list": "(nums, k, max_sum)" }, { "docstring": null, "function_declaration": "def minimize_difference(nums, k):", "function_name": "minimize_difference", ...
[ 1, 0, 0, 0, 0, 1, 1, 0, 1, 0 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def splitArray(nums, k):\n \"\"\"\n Returns the minimum difference between the maximum and minimum subarray sums \n achieved by any way of splitting the array into k...
trial_gpt4o_8
{ "original_instruction": "You are given an integer array `nums` and an integer `k`. Your task is to split `nums` into `k` consecutive subarrays such that the difference between the maximum sum of any subarray and the minimum sum of any subarray is minimized. Return _the minimum difference between the maximum and mi...
0.699764
Leetcode_35187
C
[ "can_partition", "minimize_difference" ]
2
[ [ "minimize_difference", "can_partition" ] ]
1
[]
false
[]
false
pytest
false
[]
true
fd2176d3c5112a9d724db0c00ec36798ab7a2ad6
61d76d93f71dfd92868a85cc42e06c3e2ee1bf74
v1.0
complete
Leetcode
Leetcode_35357_C
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def bstFromPreorderInorderTraversal(preorder): """ Given an integer `n` representing the number of nodes in a binary search tree (BST) and an array `preorder` of len...
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def bstFromPreorder(preorder): if not preorder: return None def buildBST(preorder, lower, upper): if not preorder or preorder[0] < lower or preorder[...
from solution import bstFromPreorderInorderTraversal def test_empty_preorder(): assert bstFromPreorderInorderTraversal([]) == [] def test_single_node(): assert bstFromPreorderInorderTraversal([5]) == [5] def test_two_nodes(): assert bstFromPreorderInorderTraversal([5, 3]) == [3, 5] def test_three_nodes(...
[]
[ 0, 1, 1, 1, 0, 1, 1, 1, 1, 1 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\ndef bst_from_preorder(...
trial_gpt4o_9
{ "original_instruction": "Given an integer `n` representing the number of nodes in a **binary search tree (BST)** and an array `preorder` of length `n` containing the preorder traversal of the BST, construct the BST and return _the inorder traversal of its nodes' values_.", "prompt_id": "0000035357", "row_id": 3...
0.553121
Leetcode_35357
C
[ "bstFromPreorder", "inorderTraversal", "bstFromPreorderInorderTraversal" ]
3
[ [ "bstFromPreorderInorderTraversal", "bstFromPreorder" ], [ "bstFromPreorderInorderTraversal", "inorderTraversal" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
7a6bc93a88b2ec055addaec512825a9ffae1b23e
cff245e39166061b077a815a418b0740332aa03e
v1.0
complete
Leetcode
Leetcode_35790_C
def max_score_common_substring(s1: str, s2: str) -> int: """ Return the maximum score of any substring that appears in both s1 and s2. The score of a substring is defined as the sum of the positions of its characters in the English alphabet ('a' is 1, 'b' is 2, ..., 'z' is 26). >>> max_score_common_su...
def get_char_score(c): return ord(c) - ord('a') + 1 def get_substring_score(s): return sum(get_char_score(c) for c in s) def max_score_common_substring(s1, s2): max_score = 0 s2_substrings = set() for i in range(len(s2)): for j in range(i + 1, len(s2) + 1): s2_substrings.a...
from solution import max_score_common_substring def test_max_score_common_substring(): assert max_score_common_substring("abc", "cde") == 3 # "c": 3 assert max_score_common_substring("abcd", "defg") == 4 # "d": 4 assert max_score_common_substring("abacaba", "bacabac") == 10 # "bacab": 2+1+3+1+2 = 10 ...
[ { "docstring": null, "function_declaration": "def get_char_score(c):", "function_name": "get_char_score", "parameter_list": "(c)" }, { "docstring": null, "function_declaration": "def get_substring_score(s):", "function_name": "get_substring_score", "parameter_list": "(s)" }, ...
[ 1, 0, 0, 0, 0, 0, 1, 0, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def get_char_score(c):\n \"\"\"\n Returns the position score of the character in the English alphabet.\n \"\"\"\n return ord(c) - ord('a') + 1\n\ndef maximum_comm...
trial_gpt4o_6
{ "original_instruction": "You are given two strings `s1` and `s2`, both consisting of lowercase English letters. Define the **score** of a substring as the sum of the positions of its characters in the English alphabet (`a` is 1, `b` is 2, ..., `z` is 26). A **substring** is a contiguous segment of a string. \n\n*...
0.70574
Leetcode_35790
C
[ "get_char_score", "get_substring_score", "max_score_common_substring" ]
3
[ [ "get_substring_score", "get_char_score" ], [ "max_score_common_substring", "get_substring_score" ] ]
2
[]
false
[]
false
pytest
true
[]
true
91b7bab96b375917ca75bcaa80f6dea483f4257f
efd231b4e9b145c128bb6ec49185d793a667bb42
v1.0
complete
Leetcode
Leetcode_35857_C
from typing import List def minimize_max_task_duration(tasks: List[int]) -> int: """ You are given a list of `n` different tasks, where each task has a specific duration in minutes. Tasks are represented as an array of integers `tasks`, where `tasks[i]` is the duration of the `i`th task. You have `two` w...
def can_assign_tasks(tasks, max_time): # Start with two workers worker1_time, worker2_time = 0, 0 for task in sorted(tasks, reverse=True): if worker1_time + task <= max_time: worker1_time += task elif worker2_time + task <= max_time: worker2_time += task else...
from solution import minimize_max_task_duration def test_example_case(): tasks = [5, 8, 1, 4] assert minimize_max_task_duration(tasks) == 9 def test_single_task(): tasks = [10] assert minimize_max_task_duration(tasks) == 10 def test_multiple_tasks_equal(): tasks = [3, 3, 3, 3] assert minimize...
[ { "docstring": null, "function_declaration": "def can_assign_tasks(tasks, max_time):", "function_name": "can_assign_tasks", "parameter_list": "(tasks, max_time)" }, { "docstring": null, "function_declaration": "def minimize_max_task_duration(tasks):", "function_name": "minimize_max_t...
[ 0, 0, 1, 0, 0, 0, 0, 0, 0 ]
1
hard
0.111
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def min_max_task_duration(tasks):\n def can_assign(tasks, mid, k):\n current_sum = 0\n required_workers = 1\n for task in tasks:\n if curre...
trial_gpt4o_2
{ "original_instruction": "You are given a list of `n` different tasks, where each task has a specific duration in minutes. Tasks are represented as an array of integers `tasks`, where `tasks[i]` is the duration of the `ith` task. \n\nYou have `two` workers who can work simultaneously on tasks. Your objective is to a...
0.696412
Leetcode_35857
C
[ "can_assign_tasks", "minimize_max_task_duration" ]
2
[ [ "minimize_max_task_duration", "can_assign_tasks" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5995f3e5c5e482bd1da545a14c5f604f8905ce6f
7718d496caf184d71b4e2cc1e4d87f5927606211
v1.0
complete
Leetcode
Leetcode_36604_C
class ListNode: def __init__(self, val=0, next=None): self.val = val self.next = next def is_happy_linked_list(head: ListNode) -> bool: """ Determine whether the linked list is a "happy" linked list. >>> head = ListNode(1, ListNode(9, ListNode(7))) >>> is_happy_linked_list(head) ==...
class ListNode: def __init__(self, val=0, next=None): self.val = val self.next = next def is_happy_number(n): def sum_of_squares(num): return sum(int(digit) ** 2 for digit in str(num)) seen = set() while n != 1 and n not in seen: seen.add(n) n = sum_of_squar...
from solution import ListNode, is_happy_linked_list def test_is_happy_linked_list_happy(): head = ListNode(1, ListNode(9, ListNode(7))) assert is_happy_linked_list(head) == False # Linked list 791 which is not happy def test_is_happy_linked_list_unhappy(): head = ListNode(1) assert is_happy_linked_li...
[]
[ 0, 1, 0, 0, 1, 0, 1, 1, 0, 1 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "class ListNode:\n def __init__(self, val=0, next=None):\n self.val = val\n self.next = next\n\ndef square_sum(n):\n \"\"\"\n Helper function to calcula...
trial_gpt4o_9
{ "original_instruction": "You are given the head node of a singly linked list where each node contains a positive integer value. Write a function to determine whether the linked list is a \"happy\" linked list. A linked list is considered \"happy\" if the sequence of values it contains forms a \"happy number.\" A nu...
0.519798
Leetcode_36604
C
[ "is_happy_number", "linked_list_to_number", "is_happy_linked_list" ]
3
[ [ "is_happy_linked_list", "is_happy_number" ], [ "is_happy_linked_list", "linked_list_to_number" ] ]
2
[]
false
[ "ListNode" ]
true
pytest
true
[]
true
fca1412656d45ddb8974de8c2e4643fbe57eaf18
71ce60a8be145d31f0a8b0eb73bddc2678a25370
v1.0
complete
Leetcode
Leetcode_36692_C
def is_palindrome(n: int) -> bool: """ Helper function to check if a number is a palindrome. >>> is_palindrome(121) True >>> is_palindrome(123) False >>> is_palindrome(1) True >>> is_palindrome(1221) True >>> is_palindrome(10) False """ def closest_palindromic_number(num: int) -> in...
def is_palindrome(n): """ Helper function to check if a number is a palindrome. """ return str(n) == str(n)[::-1] def closest_palindromic_number(num): """ Returns the closest palindromic number to the given number. If the number is already a palindrome, it returns the number itself. """...
from solution import is_palindrome, closest_palindromic_number def test_is_palindrome(): assert is_palindrome(121) is True assert is_palindrome(123) is False assert is_palindrome(1) is True assert is_palindrome(1221) is True assert is_palindrome(10) is False def test_closest_palindromic_number(): ...
[ { "docstring": "Helper function to check if a number is a palindrome.", "function_declaration": "def is_palindrome(n):", "function_name": "is_palindrome", "parameter_list": "(n)" }, { "docstring": "Returns the closest palindromic number to the given number.\nIf the number is already a palind...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_palindrome(n):\n return str(n) == str(n)[::-1]\n\ndef closest_palindromic_number(num):\n if is_palindrome(num):\n return num\n \n lower_palindrome =...
trial_gpt4o_8
{ "original_instruction": "A palindromic number is a number that remains the same when its digits are reversed. For example, `121` is a palindromic number as it remains `121` after reversing, while `123` is not a palindromic number as it becomes `321` after reversing. Given an integer `num`, find the closest palindro...
0.716072
Leetcode_36692
C
[ "is_palindrome", "closest_palindromic_number" ]
2
[ [ "closest_palindromic_number", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1afded23ff782d362681ff515db06902a9fa5776
6b7ce9249bf424efaa3a37da8edb242ddab679b8
v1.0
complete
Leetcode
Leetcode_36932_C
def is_subsequence(s: str, word: str) -> bool: """ Checks if word is a subsequence of s. >>> is_subsequence("abcde", "ace") == True >>> is_subsequence("abcde", "aec") == False >>> is_subsequence("abcde", "abcde") == True >>> is_subsequence("abcde", "") == True """ def longest_subseq_length(s: s...
def is_subsequence(s, word): """ Checks if word is a subsequence of s. """ it = iter(s) return all(char in it for char in word) def longest_subseq_length(s, words): """ Finds the length of the longest subsequence from s that can form one of the words in words. """ longest_length = 0...
from solution import longest_subseq_length, is_subsequence def test_is_subsequence(): assert is_subsequence("abcde", "ace") == True assert is_subsequence("abcde", "aec") == False assert is_subsequence("abcde", "abcde") == True assert is_subsequence("abcde", "") == True def test_longest_subseq_length()...
[ { "docstring": "Checks if word is a subsequence of s.", "function_declaration": "def is_subsequence(s, word):", "function_name": "is_subsequence", "parameter_list": "(s, word)" }, { "docstring": "Finds the length of the longest subsequence from s that can form one of the words in words.", ...
[ 0, 1, 1, 1, 1, 1, 1, 1, 1 ]
8
easy
0.889
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_1_results_combined.jsonl", "solution_code": "def is_subsequence(s, sub):\n \"\"\"\n Checks if sub is a subsequence of s.\n \"\"\"\n it = iter(s)\n return all(char in it for char i...
trial_gpt4o_9
{ "original_instruction": "You are given a string `s` consisting of lowercase English letters, and an array of strings `words`. You need to select a non-empty subsequence from `s` and determine if it can form one of the strings in `words` when concatenated in order without reordering the characters. Return the length...
0.763192
Leetcode_36932
C
[ "is_subsequence", "longest_subseq_length" ]
2
[ [ "longest_subseq_length", "is_subsequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b72f4d967cae0fe08efa04e6c97921032ae70184
5d68687631d7417d338001a7239ae8d9634ff307
v1.0
complete
Leetcode
Leetcode_37607_C
def is_prime(n: int) -> bool: """Check if a number n is a prime number. >>> is_prime(2) True >>> is_prime(3) True >>> is_prime(4) False >>> is_prime(29) True """ def primes_from_list(lst: List[int]) -> List[int]: """Returns a list of prime numbers from the given list. >>> primes_fro...
def is_prime(n): """ Check if a number n is a prime number. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 ...
from solution import is_prime, primes_from_list def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(29) == True assert is_prime(35) == False assert is_prime(1) == False assert is_prime(-5) == False def test_primes_from_list...
[ { "docstring": "Check if a number n is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list of prime numbers from the given list.", "function_declaration": "def primes_from_list(lst):", "f...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n %...
trial_gpt4o_8
{ "original_instruction": "Write a function that takes a list of integers as input and returns a new list containing all the prime numbers from the given list. A prime number is a number greater than 1 that has no positive divisors other than 1 and itself. Ensure that your solution is efficient in terms of time compl...
0.797111
Leetcode_37607
C
[ "is_prime", "primes_from_list" ]
2
[ [ "primes_from_list", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e086add9542677ad4099cc49123bb15973e3805d
6d72878a8fb41e45239a058c9f40fe665a188cb1
v1.0
complete
Leetcode
Leetcode_37649_C
def is_palindrome(s): """ Helper function to check if a given string is a palindrome. """ return s == s[::-1] def can_split_into_two_palindromes(s: str) -> bool: """ Given a string 's', split 's' into at most two palindromic substrings. Return 'true' if it is possible to split 's' such that bot...
def is_palindrome(s): """ Helper function to check if a given string is a palindrome. """ return s == s[::-1] def can_split_into_two_palindromes(s): """ Checks if the string 's' can be split into at most two palindromic substrings. """ n = len(s) for i in range(1, n): # We ite...
from solution import can_split_into_two_palindromes def test_simple_true_cases(): assert can_split_into_two_palindromes("abba") == True assert can_split_into_two_palindromes("racecar") == True def test_simple_false_cases(): assert can_split_into_two_palindromes("abcd") == False assert can_split_into_t...
[ { "docstring": "Helper function to check if a given string is a palindrome.", "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": "Checks if the string 's' can be split into at most two palindromic substrings.", "fu...
[ 0, 0, 0, 1, 0, 0, 0, 0, 0, 1 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def can_split_into_two_palindromes(s):\n \"\"\"\n Returns true if the provided string can be split into exactly two substrings that are both palindromes.\n \"\"\"\n ...
trial_gpt4o_9
{ "original_instruction": "Given a string `s`, you need to split `s` into at most two palindromic substrings. Return `true` if it is possible to split `s` such that both substrings are palindromes and `false` otherwise. A string is a palindrome if it reads the same forward and backward.", "prompt_id": "0000037649",...
0.878899
Leetcode_37649
C
[ "is_palindrome", "can_split_into_two_palindromes" ]
2
[ [ "can_split_into_two_palindromes", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2a5a25e8a82ec8237c8709058e924143128b2c6f
b2bc3202c3118ba834092bc45bccda17e2e03c6b
v1.0
complete
Leetcode
Leetcode_37949_C
def has_cycle(edges: List[List[int]], n: int) -> bool: """ Function to detect cycle in an undirected graph. :param edges: List of edges where each edge is represented as a pair of nodes [u, v]. :param n: Number of nodes in the graph. :return: True if there is a cycle, otherwise False. ...
def find_parent(parent, i): if parent[i] == -1: return i if parent[i] != -1: return find_parent(parent, parent[i]) def union(parent, x, y): x_set = find_parent(parent, x) y_set = find_parent(parent, y) if x_set != y_set: parent[x_set] = y_set def has_cycle(edges, n): ""...
from solution import has_cycle def test_no_cycle(): edges = [[0, 1], [1, 2], [2, 3]] n = 4 assert not has_cycle(edges, n) def test_with_cycle(): edges = [[0, 1], [1, 2], [2, 0]] n = 3 assert has_cycle(edges, n) def test_disconnected_graph_with_no_cycle(): edges = [[0, 1], [2, 3]] n = ...
[ { "docstring": null, "function_declaration": "def find_parent(parent, i):", "function_name": "find_parent", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, x, y):", "function_name": "union", "parameter_list": "(parent, x, y)" }...
[ 1, 1, 1, 0, 1, 1, 1, 1, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def hasCycle(n, edges):\n \"\"\"\n Determines if there is a cycle in the given undirected graph.\n \n :param int n: The number of nodes in the graph.\n :param ...
trial_gpt4o_2
{ "original_instruction": "You are given a list of `edges` representing the connections between nodes in an undirected graph. Each `edge` is a pair `[u, v]` indicating a connection between node `u` and node `v`. Write a function to detect if there is a cycle in the graph. If a cycle exists, return `true`. Otherwise, ...
0.602302
Leetcode_37949
C
[ "find_parent", "union", "has_cycle" ]
3
[ [ "has_cycle", "find_parent" ], [ "has_cycle", "union" ], [ "union", "find_parent" ] ]
3
[]
false
[]
false
pytest
true
[]
true
4c6d9e1337cb8ac27b10a4ca925c7bc3724a63bb
97eda2bc6f4c45ad26158154759762f783da6716
v1.0
complete
Leetcode
Leetcode_37950_C
def minimized_largest_sum(arr: List[int], k: int) -> int: """ Partition the array into k subsets such that the sum of integers in each subset is maximized. Return the minimized sum of the largest subset. >>> minimized_largest_sum([1, 2, 3, 4, 5], 2) == 9 >>> minimized_largest_sum([1, 2, 3, 4, 5], 3) ==...
def can_partition(nums, k, max_sum): # This helper function checks if we can partition the array into `k` or fewer parts # so that no part has a sum greater than `max_sum`. current_sum = 0 required_parts = 1 for num in nums: if current_sum + num > max_sum: required_parts += 1 ...
from solution import minimized_largest_sum def test_case_1(): assert minimized_largest_sum([1, 2, 3, 4, 5], 2) == 9 def test_case_2(): assert minimized_largest_sum([1, 2, 3, 4, 5], 3) == 6 def test_case_3(): assert minimized_largest_sum([1, 2, 3, 4, 5], 1) == 15 def test_case_4(): assert minimized_l...
[ { "docstring": null, "function_declaration": "def can_partition(nums, k, max_sum):", "function_name": "can_partition", "parameter_list": "(nums, k, max_sum)" }, { "docstring": null, "function_declaration": "def minimized_largest_sum(arr, k):", "function_name": "minimized_largest_sum"...
[ 1, 1, 0, 0, 1, 0, 0, 0, 0 ]
3
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def can_partition(arr, k, max_sum):\n current_sum = 0\n partitions = 1\n \n for num in arr:\n if current_sum + num > max_sum:\n partitions += 1\...
trial_gpt4o_5
{ "original_instruction": "Given an array of integers `arr` and an integer `k`, partition the array into `k` subsets such that the sum of integers in each subset is maximized. Return _the minimized sum of the largest subset_. You may assume that both the array and `k` are such that a valid partitioning is always poss...
0.702094
Leetcode_37950
C
[ "can_partition", "minimized_largest_sum" ]
2
[ [ "minimized_largest_sum", "can_partition" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e9a8b6366517a747d523b0ae4343454c9f1a9df1
ad6e4d5ccbbfb69e30c3d94a234d49a9f7ffe241
v1.0
complete
Leetcode
Leetcode_38185_C
def minimum_communication_time(n: int, edges: List[Tuple[int, int, int]]) -> int: """ Determine the minimum total communication time to enable all departments to communicate with each other. Parameters: n (int): The number of departments. edges (List[Tuple[int, int, int]]): A list of tuples re...
def find(parent, i): if parent[i] == i: return i return find(parent, parent[i]) def union(parent, rank, x, y): rootX = find(parent, x) rootY = find(parent, y) if rank[rootX] < rank[rootY]: parent[rootX] = rootY elif rank[rootX] > rank[rootY]: parent[rootY] = rootX ...
from solution import minimum_communication_time def test_minimum_communication_time_basic(): assert minimum_communication_time(4, [(0, 1, 1), (1, 2, 2), (2, 3, 1), (0, 3, 4)]) == 4 def test_minimum_communication_time_disconnected(): assert minimum_communication_time(4, [(0, 1, 1), (1, 2, 2)]) == -1 def test_...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 1, 0, 1, 0, 0, 1, 1, 1, 0 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n else:\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n root_x = find(parent,...
trial_gpt4o_3
{ "original_instruction": "A company is trying to optimize the performance of their network by minimizing the total communication time between different departments. The departments are connected by a certain number of bidirectional cables, and each cable has a specific time delay to send information. The company pro...
0.553143
Leetcode_38185
C
[ "find", "union", "minimum_communication_time" ]
3
[ [ "minimum_communication_time", "find" ], [ "minimum_communication_time", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
true
[]
true
531e987b65862a8d5d1cc1d689c83f148ca29072
eb47dc719bf1e3024eaafc321c08da3dec05d22b
v1.0
complete
Leetcode
Leetcode_38216_C
from typing import List from collections import Counter def is_subset(a: Counter, b: Counter) -> bool: """ Checks if string b is a subset of string a. """ pass def wordSubsets(words1: List[str], words2: List[str]) -> List[str]: """ Returns an array of all the strings in words1 which are subset...
from collections import Counter def is_subset(a, b): """ Checks if string b is a subset of string a. """ counter_a = Counter(a) counter_b = Counter(b) for char, count in counter_b.items(): if counter_a[char] < count: return False return True def wordSubsets(words1, word...
from solution import wordSubsets def test_wordSubsets_simple_case(): assert wordSubsets(["amazon","apple","facebook","google","leetcode"], ["e","o"]) == ["facebook","google","leetcode"] def test_wordSubsets_empty_words1(): assert wordSubsets([], ["e","o"]) == [] def test_wordSubsets_empty_words2(): asser...
[ { "docstring": "Checks if string b is a subset of string a.", "function_declaration": "def is_subset(a, b):", "function_name": "is_subset", "parameter_list": "(a, b)" }, { "docstring": "Returns an array of all the strings in words1 which are subsets of all the strings in words2.", "funct...
[ 1, 1, 0, 0, 0, 0, 1, 1, 0, 0 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "from collections import Counter\n\ndef word_subset(words1, words2):\n \"\"\"\n Return an array of all the strings in words1 which are subsets of all the strings in word...
trial_gpt4o_7
{ "original_instruction": "You are given two string arrays `words1` and `words2`. A string `b` is a subset of string `a` if every letter in `b` occurs in `a` including multiplicity. For example, \"wrr\" is a subset of \"warrior,\" but is not a subset of \"world\" or \"elloworld.\" Return an array of all the strings i...
0.586231
Leetcode_38216
C
[ "is_subset", "wordSubsets" ]
2
[ [ "wordSubsets", "is_subset" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4b97ceccd8e4a5fe9fb558335f65cf8856213d7a
31887c5f4c148b46df72e9e85ce834b345b266b7
v1.0
complete
Leetcode
Leetcode_38297_C
def maximalRectangle(matrix: List[List[int]]) -> int: """ Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its area. >>> maximalRectangle([ ... [1, 0, 1, 0, 0], ... [1, 0, 1, 1, 1], ... [1, 1, 1, 1, 1], ... [...
def maximalRectangle(matrix): """ Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its area. """ if not matrix or not matrix[0]: return 0 max_area = 0 num_cols = len(matrix[0]) heights = [0] * num_cols for r...
from solution import maximalRectangle def test_example_case(): matrix = [ [1, 0, 1, 0, 0], [1, 0, 1, 1, 1], [1, 1, 1, 1, 1], [1, 0, 0, 1, 0] ] assert maximalRectangle(matrix) == 6 def test_all_zeros(): matrix = [ [0, 0], [0, 0] ] assert maximalRe...
[ { "docstring": "Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and\nreturn its area.", "function_declaration": "def maximalRectangle(matrix):", "function_name": "maximalRectangle", "parameter_list": "(matrix)" }, { "docstring": "Helper functi...
[ 0, 1, 1, 1, 0, 1, 1, 0, 1, 0 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def maximalRectangle(matrix):\n if not matrix:\n return 0\n\n max_area = 0\n num_cols = len(matrix[0])\n heights = [0] * (num_cols + 1) # Extra element to ...
trial_gpt4o_8
{ "original_instruction": "Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its area. A rectangle is defined as a group of contiguous cells arranged in a rectangular shape, where each cell contains a 1. The matrix is represented as a list of lists, where each...
0.741921
Leetcode_38297
C
[ "maximalRectangle", "largestRectangleArea" ]
2
[ [ "maximalRectangle", "largestRectangleArea" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1dad8ee870cc5bb39851c4138645d07d323ed01c
d4e1af2c8c7a2e6789d88d0fde524e2977a0d2cc
v1.0
complete
Leetcode
Leetcode_38708_C
from typing import List def partition(nums: List[int], left: int, right: int, pivot_index: int) -> int: pivot_value = nums[pivot_index] nums[pivot_index], nums[right] = nums[right], nums[pivot_index] # Move pivot to end store_index = left for i in range(left, right): if nums[i] < pivot_value: ...
import random def partition(nums, left, right, pivot_index): pivot_value = nums[pivot_index] nums[pivot_index], nums[right] = nums[right], nums[pivot_index] # Move pivot to end store_index = left for i in range(left, right): if nums[i] < pivot_value: nums[store_index], nums[i] = nu...
from solution import find_kth_smallest def test_find_kth_smallest(): assert find_kth_smallest([3, 2, 1, 5, 6, 4], 2) == 2 assert find_kth_smallest([3, 2, 3, 1, 2, 4, 5, 5, 6], 4) == 3 assert find_kth_smallest([7, 10, 4, 3, 20, 15], 3) == 7 assert find_kth_smallest([7, 10, 4, 3, 20, 15], 4) == 10 as...
[ { "docstring": null, "function_declaration": "def partition(nums, left, right, pivot_index):", "function_name": "partition", "parameter_list": "(nums, left, right, pivot_index)" }, { "docstring": null, "function_declaration": "def quickselect(nums, left, right, k):", "function_name":...
[ 1, 0, 0, 1, 1, 1, 1, 0, 0, 1 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def kth_smallest(nums, k):\n \"\"\"\n Returns the k-th smallest element in the array nums.\n \"\"\"\n def partition(arr, low, high):\n pivot = arr[high]\n ...
trial_gpt4o_9
{ "original_instruction": "You are given an unsorted array of integers `nums` and an integer `k`. Your task is to find the `k`-th smallest element in the array. Note that it is the k-th smallest element in the sorted order, not the k-th distinct element. You are required to solve this problem with an algorithm that h...
0.609882
Leetcode_38708
C
[ "partition", "quickselect", "find_kth_smallest" ]
3
[ [ "find_kth_smallest", "quickselect" ], [ "quickselect", "partition" ] ]
2
[]
false
[]
false
pytest
true
[]
true
542293631ba185a841be13d71ec35d27657ae1db
1a3067b52d7e01c3c59b6b776dfe7895b413a47d
v1.0
complete
Leetcode
Leetcode_38753_C
def same_final_position(s1: str, s2: str) -> bool: """ Determine if two sequences of moves s1 and s2 end up at the same final position. >>> same_final_position('UDLR', 'LRUD') True >>> same_final_position('UUDDLRR', 'UDLR') False >>> same_final_position('UUU', 'DDD') False >>> same_final_position('L...
def final_position(s): """ Calculates the final position after performing the moves in s. """ x, y = 0, 0 for move in s: if move == 'U': y += 1 elif move == 'D': y -= 1 elif move == 'L': x -= 1 elif move == 'R': x += 1 ...
from solution import same_final_position def test_same_final_position(): assert same_final_position('UDLR', 'LRUD') == True assert same_final_position('UUDDLRR', 'UDLR') == False assert same_final_position('UUU', 'DDD') == False assert same_final_position('LLRR', 'RRLL') == True assert same_final_p...
[ { "docstring": "Calculates the final position after performing the moves in s.", "function_declaration": "def final_position(s):", "function_name": "final_position", "parameter_list": "(s)" }, { "docstring": "Determines if two sequences of moves s1 and s2 end up at the same final position.",...
[ 1, 0, 0, 0, 0, 1, 0, 1, 1, 0 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def end_up_at_same_position(s1, s2):\n \"\"\"\n Returns True if strings s1 and s2 result in the same final position on a 2D plane.\n \n Moves are:\n 'U' - up\n...
trial_gpt4o_8
{ "original_instruction": "You are given two strings `s1` and `s2`, both representing sequence of moves in a 2D plane where each move is one of the characters: 'U' (up), 'D' (down), 'L' (left), 'R' (right). Starting from the origin point (0, 0), determine if it is possible for these two sequences to make you end up a...
0.650334
Leetcode_38753
C
[ "final_position", "same_final_position" ]
2
[ [ "same_final_position", "final_position" ] ]
1
[]
false
[]
false
pytest
true
[]
true
14d12976fd681305765f8d956673e40472e9af42
3018b8d1179c8712c7a00486b49d1eff749da0c5
v1.0
complete
Leetcode
Leetcode_38801_C
class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None def build_tree(nodes): if not nodes: return None root = TreeNode(nodes[0]) queue = [root] idx = 1 while queue and idx < len(nodes): node = queue.pop(0) if nodes...
class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None def build_tree(nodes): if not nodes: return None root = TreeNode(nodes[0]) queue = [root] idx = 1 while queue and idx < len(nodes): node = queue.pop(0) if nodes...
from solution import lowest_common_ancestor def test_case_1(): nodes = [3, 5, 1, 6, 2, 0, 8, -1, -1, 7, 4] node1 = 5 node2 = 1 assert lowest_common_ancestor(nodes, node1, node2) == 3 def test_case_2(): nodes = [3, 5, 1, 6, 2, 0, 8, -1, -1, 7, 4] node1 = 5 node2 = 4 assert lowest_common...
[]
[ 1, 0, 1, 1, 1, 0, 1, 1, 0, 1 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, x):\n self.val = x\n self.left = None\n self.right = None\n\ndef build_tree(nodes):\n if not nodes:\n r...
trial_gpt4o_0
{ "original_instruction": "You are given a **binary tree** in the form of an integer array `nodes`, where each element represents a node in the tree in level order traversal. The value `-1` represents a `null` node (i.e., no child). You are also given two node values `node1` and `node2` that are guaranteed to be pres...
0.590938
Leetcode_38801
C
[ "build_tree", "find_lca", "lowest_common_ancestor" ]
3
[ [ "lowest_common_ancestor", "build_tree" ], [ "lowest_common_ancestor", "find_lca" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
7eefe8bf8ed8d346d1ac5ddc865fb7e231f70069
95079123ee309c1e9e2de1db2410f4ee7736dc1f
v1.0
complete
Leetcode
Leetcode_38997_C
def is_subsequence(text: str, word: str) -> bool: """ Helper function to check if a word is a subsequence of text. """ it = iter(text) return all(char in it for char in word) def subsequences_check(text: str, words: List[str]) -> List[bool]: """ For each word in words, determine if it is a ...
def is_subsequence(text, word): """ Helper function to check if a word is a subsequence of text. """ it = iter(text) return all(char in it for char in word) def subsequences_check(text, words): """ For each word in words, determine if it is a subsequence of text. Args: text (st...
from solution import subsequences_check def test_subsequences_check_all_true(): words = ["abc", "ace", "a"] text = "abcde" assert subsequences_check(text, words) == [True, True, True] def test_subsequences_check_all_false(): words = ["aec", "xyz", "abf"] text = "abcde" assert subsequences_chec...
[ { "docstring": "Helper function to check if a word is a subsequence of text.", "function_declaration": "def is_subsequence(text, word):", "function_name": "is_subsequence", "parameter_list": "(text, word)" }, { "docstring": "For each word in words, determine if it is a subsequence of text.\n...
[ 1, 0, 1, 0, 0, 0, 1, 1, 1, 1 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_subsequence(text, words):\n \"\"\"\n Determine if each word in words is a subsequence of text.\n \n Parameters:\n text (str): The main string.\n word...
trial_gpt4o_9
{ "original_instruction": "You are given a string `text` and an array of strings `words`. For each word in `words`, determine if it is a **subsequence** of `text`. Return an array of booleans, where the `i-th` boolean is `true` if `words[i]` is a subsequence of `text`, and `false` otherwise. A subsequence is a sequen...
0.645583
Leetcode_38997
C
[ "is_subsequence", "subsequences_check" ]
2
[ [ "subsequences_check", "is_subsequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
87ed2362a1213ffa38704b1c7d2df93683314c14
429a36982887d12f8a553908f1c40d122e4dd87c
v1.0
complete
Leetcode
Leetcode_39420_C
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def generate_preorder(node): """ Generate preorder traversal of a BST. Args: node (TreeNode): The root of the BST. Returns: List[int]: The preord...
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def generate_preorder(node): return [node.val] + generate_preorder(node.left) + generate_preorder(node.right) if node else [] def generate_trees(start, end): if star...
from solution import generate_all_bst_preorders def test_generate_all_bst_preorders_zero(): assert generate_all_bst_preorders(0) == [] def test_generate_all_bst_preorders_one(): assert generate_all_bst_preorders(1) == [[1]] def test_generate_all_bst_preorders_two(): assert generate_all_bst_preorders(2) =...
[]
[ 1, 1, 0, 0, 1, 0, 0, 1, 0, 0 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\ndef generate_trees(n):...
trial_gpt4o_7
{ "original_instruction": "Given an integer `n`, generate all structurally unique **BST's** (Binary Search Trees) that store values `1 ... n`. For each generated BST, return its preorder traversal. Note that the preorder traversal is a process of visiting the root node first, then recursively visiting the left subtre...
0.539969
Leetcode_39420
C
[ "generate_preorder", "generate_trees", "generate_all_bst_preorders" ]
3
[ [ "generate_all_bst_preorders", "generate_preorder" ], [ "generate_all_bst_preorders", "generate_trees" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
9c3e0377f27e4f0e9596f057d625bcb748f77e9c
011b3d469e4f27cd9d44fba1d1673d90c74e0b60
v1.0
complete
Leetcode
Leetcode_39626_C
def longest_subsequence_length(sequence: str, words: List[str]) -> int: """ Given a string `sequence` and an array of strings `words`, find the length of the longest string in `words` that is a subsequence of `sequence`. A subsequence is a sequence that can be derived from another sequence by deleting...
def is_subsequence(seq, word): """ Helper function to check if 'word' is a subsequence of 'seq'. """ it = iter(seq) return all(char in it for char in word) def longest_subsequence_length(sequence, words): """ Returns the length of the longest string in 'words' that is a subsequence of 'sequ...
from solution import longest_subsequence_length def test_longest_subsequence_length_no_subsequence(): assert longest_subsequence_length("abc", ["def", "ghi"]) == 0 def test_longest_subsequence_length_one_subsequence(): assert longest_subsequence_length("abcde", ["a", "ac", "ace"]) == 3 def test_longest_subse...
[ { "docstring": "Helper function to check if 'word' is a subsequence of 'seq'.", "function_declaration": "def is_subsequence(seq, word):", "function_name": "is_subsequence", "parameter_list": "(seq, word)" }, { "docstring": "Returns the length of the longest string in 'words' that is a subseq...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_subsequence(sequence, word):\n \"\"\" Check if word is a subsequence of sequence \"\"\"\n it = iter(sequence)\n return all(char in it for char in word)\n\ndef...
trial_gpt4o_8
{ "original_instruction": "Given a string `sequence` and an array of strings `words`, find the length of the longest string in `words` that is a subsequence of `sequence`. A subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elemen...
0.762702
Leetcode_39626
C
[ "is_subsequence", "longest_subsequence_length" ]
2
[ [ "longest_subsequence_length", "is_subsequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
00a5dea4010f4cfd11e942864928906e51ef12ab
16fecf8dd58cecaf22063bcc4f408a47c4decbb2
v1.0
complete
Leetcode
Leetcode_39720_C
from typing import List def distributeTasks(tasks: List[int], n: int) -> int: """ Distribute the tasks among the workers such that the maximum time taken by any worker to complete their assigned tasks is minimized. >>> distributeTasks([1, 2, 3, 4, 5], 2) 9 >>> distributeTasks([2, 2, 2, 2, 2, 2], 3) ...
def canDistributeWithinTime(tasks, n, maxTime): # Helper function to check if tasks can be distributed within given maxTime current_time = 0 workers_used = 1 for task in tasks: if current_time + task <= maxTime: current_time += task else: workers_used += 1 ...
from solution import distributeTasks def test_distribute_tasks_basic(): assert distributeTasks([1, 2, 3, 4, 5], 2) == 9 def test_distribute_tasks_equal_tasks(): assert distributeTasks([2, 2, 2, 2, 2, 2], 3) == 4 def test_distribute_tasks_single_worker(): assert distributeTasks([1, 2, 3, 4, 5], 1) == 15 ...
[ { "docstring": null, "function_declaration": "def canDistributeWithinTime(tasks, n, maxTime):", "function_name": "canDistributeWithinTime", "parameter_list": "(tasks, n, maxTime)" }, { "docstring": null, "function_declaration": "def distributeTasks(tasks, n):", "function_name": "dist...
[ 0, 1, 0, 1, 0, 1, 1, 1, 0, 0 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def distribute_tasks(tasks, n):\n \"\"\"\n Distribute the tasks among the workers such that the maximum time \n taken by any worker to complete their assigned tasks ...
trial_gpt4o_7
{ "original_instruction": "You are given an array of integers `tasks` where each element represents the duration of a task in minutes. You are also given an integer `n` representing the number of workers. Each worker can perform exactly one task at a time, and once a worker starts a task, they must complete it withou...
0.621435
Leetcode_39720
C
[ "canDistributeWithinTime", "distributeTasks" ]
2
[ [ "distributeTasks", "canDistributeWithinTime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
385b992881b0e1de26fd3423f236b16c56760367
fb4b98c1894a3d716d2cc1cacda15b6cfd2350f3
v1.0
complete
Leetcode
Leetcode_39733_C
class TreeNode: def __init__(self, value=0, left=None, right=None): self.value = value self.left = left self.right = right def lowest_common_ancestor(root: TreeNode, p: int, q: int) -> int: """ Given a binary tree, find the lowest common ancestor of two given nodes. The lowest...
class TreeNode: def __init__(self, value=0, left=None, right=None): self.value = value self.left = left self.right = right def find_lca(root, p, q): """ Finds the lowest common ancestor of two nodes p and q in the binary tree with root. Returns the value of the LCA, or -1 if one...
import pytest from solution import TreeNode, lowest_common_ancestor def test_lca_common_case(): root = TreeNode(3) root.left = TreeNode(5) root.right = TreeNode(1) root.left.left = TreeNode(6) root.left.right = TreeNode(2) root.left.right.left = TreeNode(7) root.left.right.right = TreeNode...
[]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\ndef lowestCommonAncest...
trial_gpt4o_9
{ "original_instruction": "Given a binary tree with `n` nodes, each node containing an integer value, determine the **lowest common ancestor** of two given nodes in the tree. The lowest common ancestor of two nodes `p` and `q` is defined as the deepest node that has both `p` and `q` as descendants (where we allow a n...
0.58397
Leetcode_39733
C
[ "find_lca", "node_exists", "lowest_common_ancestor" ]
3
[ [ "lowest_common_ancestor", "find_lca" ], [ "lowest_common_ancestor", "node_exists" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
5a5248430855176b8dbee653b600463c20e848bd
9ba95ee33ede015b1615cbd9f8351e2db35a1246
v1.0
complete
Leetcode
Leetcode_39745_C
def maxRob(nums): """ Returns the maximum amount of money that can be robbed in a circular arrangement of houses. >>> maxRob([5]) == 5 >>> maxRob([2, 3]) == 3 >>> maxRob([2, 3, 2]) == 3 >>> maxRob([1, 2, 3, 1]) == 4 >>> maxRob([200, 3, 140, 20, 200]) == 340 >>> maxRob([0, 0, 0, 0, 0...
def rob_linear(nums): """ Returns the maximum amount of money that can be robbed in a linear arrangement of houses.""" prev, curr = 0, 0 for num in nums: prev, curr = curr, max(curr, prev + num) return curr def maxRob(nums): """ Returns the maximum amount of money that can be robbed...
from solution import maxRob def test_single_house(): assert maxRob([5]) == 5 def test_two_houses(): assert maxRob([2, 3]) == 3 def test_three_houses(): assert maxRob([2, 3, 2]) == 3 def test_four_houses(): assert maxRob([1, 2, 3, 1]) == 4 def test_large_amounts(): assert maxRob([200, 3, 140...
[ { "docstring": "Returns the maximum amount of money that can be robbed\nin a linear arrangement of houses.", "function_declaration": "def rob_linear(nums):", "function_name": "rob_linear", "parameter_list": "(nums)" }, { "docstring": "Returns the maximum amount of money that can be robbed in...
[ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def rob_linear(nums):\n prev, curr = 0, 0\n for num in nums:\n prev, curr = curr, max(curr, prev + num)\n return curr\n\n\ndef maxRob(nums):\n if len(nums)...
trial_gpt4o_5
{ "original_instruction": "You are given a list of non-negative integers `nums` representing the amount of money of each house arranged in a circular manner. Calculate the maximum amount of money you can rob tonight without alerting the police. Since it is a circular list, if you rob the first house, you cannot rob t...
0.592246
Leetcode_39745
C
[ "rob_linear", "maxRob" ]
2
[ [ "maxRob", "rob_linear" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1dd0435eb82a9dbd4037782db92ec15ad4724276
cdf3d56d2c933544f2c9da8cb60497cdd390890c
v1.0
complete
Leetcode
Leetcode_40101_C
def min_eating_speed(piles: List[int], H: int) -> int: """ Returns the minimum integer K such that it is possible to eat all the stones in the piles within H hours. Parameters: piles (List[int]): Array of integers where piles[i] is the number of stones in the i-th pile. H (int): Represents the n...
def can_finish(piles, H, K): """ Helper function to determine if we can finish eating all piles with speed K in H hours. """ time = 0 for pile in piles: time += (pile + K - 1) // K # Equivalent to ceil(pile / K) return time <= H def min_eating_speed(piles, H): """ Returns the m...
from solution import min_eating_speed def test_min_eating_speed_single_pile(): assert min_eating_speed([30], 30) == 1 assert min_eating_speed([30], 1) == 30 def test_min_eating_speed_equal_piles(): assert min_eating_speed([3, 3, 3], 3) == 3 assert min_eating_speed([4, 4, 4, 4], 4) == 4 def test_min_e...
[ { "docstring": "Helper function to determine if we can finish eating all piles with speed K in H hours.", "function_declaration": "def can_finish(piles, H, K):", "function_name": "can_finish", "parameter_list": "(piles, H, K)" }, { "docstring": "Returns the minimum integer K such that it is ...
[ 0, 1, 1, 0, 0, 0, 1, 1, 1, 0 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def can_finish(piles, H, K):\n hours = 0\n for pile in piles:\n hours += (pile + K - 1) // K # equivalent to ceiling(pile / K)\n if hours > H:\n ...
trial_gpt4o_8
{ "original_instruction": "You are given an array of integers `piles` where `piles[i]` is the number of stones in the `i-th` pile, and an integer `H` representing the number of hours you have to finish eating all the stones. Each hour, you can decide to eat any number of stones from a single pile. After each hour, on...
0.647664
Leetcode_40101
C
[ "can_finish", "min_eating_speed" ]
2
[ [ "min_eating_speed", "can_finish" ] ]
1
[]
false
[]
false
pytest
true
[]
true
75895a1e18fd543672c18357b2aad4af7149d2dd
5eaed04ae0b3ba0fcd9d5b10e7b6adc5a17bdd64
v1.0
complete
Leetcode
Leetcode_40225_C
from typing import List, Optional class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def levelOrderTraversalFromList(lst: List[Optional[int]]) -> List[int]: """ Given a binary tree serialized as a list of integer val...
from typing import List, Optional class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def build_tree_from_list(lst: List[Optional[int]]) -> Optional[TreeNode]: if not lst: return None root = TreeNode(lst[...
from solution import levelOrderTraversalFromList def test_example(): assert levelOrderTraversalFromList([3, 9, 20, None, None, 15, 7]) == [3, 9, 20, 15, 7] def test_empty(): assert levelOrderTraversalFromList([]) == [] def test_single_node(): assert levelOrderTraversalFromList([1]) == [1] def test_left_...
[]
[ 0, 0, 1, 0, 0, 0, 1, 1, 1, 1 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "from collections import deque\n\nclass TreeNode:\n def __init__(self, x):\n self.val = x\n self.left = None\n self.right = None\n\ndef levelOrderTrave...
trial_gpt4o_9
{ "original_instruction": "Given a binary tree, return the level order traversal of its nodes' values. (i.e., from left to right, level by level). Each node has a unique value. \nHere's an example binary tree that is serialized as `[3,9,20,null,null,15,7]`. The level order traversal of this tree is `[3, 9, 20, 15, 7]...
0.548384
Leetcode_40225
C
[ "build_tree_from_list", "levelOrderTraversal", "levelOrderTraversalFromList" ]
3
[ [ "levelOrderTraversalFromList", "build_tree_from_list" ], [ "levelOrderTraversalFromList", "levelOrderTraversal" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
f257f4d777a8e4efc8b4ee35c6f8421780c7da2d
a9efd098f05bb4bacd65c52788797c18d2fd9461
v1.0
complete
Leetcode
Leetcode_40244_C
import math from typing import List, Tuple def euclidean_distance(p1: Tuple[float, float], p2: Tuple[float, float]) -> float: """Calculates the Euclidean distance between two 2D points p1 and p2""" return math.sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2) def minPath(points: List[Tuple[float, float]]) -> ...
import itertools import math def euclidean_distance(p1, p2): """ Calculates the Euclidean distance between two 2D points p1 and p2. """ return math.sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2) def minPath(points): """ Calculates the length of the shortest path that visits all points s...
from solution import minPath def test_minPath_single_point(): points = [(0, 0)] assert minPath(points) == 0 def test_minPath_two_points(): points = [(0, 0), (1, 1)] assert math.isclose(minPath(points), 2 * math.sqrt(2), rel_tol=1e-9) def test_minPath_three_points(): points = [(0, 0), (1, 0), (0, ...
[ { "docstring": "Calculates the Euclidean distance between two 2D points p1 and p2.", "function_declaration": "def euclidean_distance(p1, p2):", "function_name": "euclidean_distance", "parameter_list": "(p1, p2)" }, { "docstring": "Calculates the length of the shortest path that visits all po...
[ 0, 0, 0, 0, 1, 0, 0, 0, 1, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "import itertools\nimport math\n\ndef euclidean_distance(p1, p2):\n \"\"\"\n Calculate the Euclidean distance between two points.\n \"\"\"\n return math.sqrt((p1[0...
trial_gpt4o_8
{ "original_instruction": "Given a list of `n` points, where each point is represented as a tuple `(x, y)` on a 2D plane, find the shortest path that visits all the points. The order of visiting the points does not matter. Implement the function `minPath(points)`, where `points` is a list of tuples. The function shou...
0.68471
Leetcode_40244
C
[ "euclidean_distance", "minPath" ]
2
[ [ "minPath", "euclidean_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c8fef2f3b52c57e224ef50c7df8bb0852f19408f
206aec56cb2efcc4a312cb0cf59dcd14c346eba6
v1.0
complete
Leetcode
Leetcode_40936_C
import functools def compare_digits(x, y): if x + y < y + x: return -1 else: return 1 def smallest_number(arr: List[int]) -> str: """ Given an integer array `arr`, arranges the digits to form the smallest possible number. >>> smallest_number([50, 2, 1, 9]) "12509" >>> smallest_...
import functools def compare_digits(x, y): if x + y < y + x: return -1 else: return 1 def smallest_number(arr): """ Given an integer array `arr`, arranges the digits to form the smallest possible number. """ str_arr = list(map(str, arr)) str_arr.sort(key=functools.cmp_to_ke...
from solution import smallest_number def test_example_case(): assert smallest_number([50, 2, 1, 9]) == "12509" def test_all_single_digit_numbers(): assert smallest_number([5, 3, 2, 1, 9, 7, 8, 6, 4, 0]) == "0123456789" def test_mixed_length_numbers(): assert smallest_number([13, 32, 321]) == "1332132" ...
[ { "docstring": null, "function_declaration": "def compare_digits(x, y):", "function_name": "compare_digits", "parameter_list": "(x, y)" }, { "docstring": "Given an integer array `arr`, arranges the digits to form the smallest possible number.", "function_declaration": "def smallest_numbe...
[ 1, 1, 0, 1, 0, 0, 0, 0, 1, 0 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "from functools import cmp_to_key\n\ndef smallest_number(arr):\n \"\"\"\n Given an integer array arr, returns the smallest possible number by\n rearranging the digits...
trial_gpt4o_8
{ "original_instruction": "Given an integer array `arr`, your task is to arrange the digits of the numbers to form the smallest possible number. The smallest number should be returned as a string to handle large numeric values.\n\nFor example, given the input array `arr = [50, 2, 1, 9]`, the output should be \"12509\...
0.735127
Leetcode_40936
C
[ "compare_digits", "smallest_number" ]
2
[ [ "smallest_number", "compare_digits" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c8164517c006ca37794693eb4c9ab25628ff7b28
7336af5f40cc3e2fc0220baed163b059200ad4bf
v1.0
complete
Leetcode
Leetcode_41057_C
def is_palindrome(s: str) -> bool: """ Helper function to check if a string is a palindrome. """ return s == s[::-1] def palindrome_pair(words: List[str]) -> bool: """ Determine if there exists a pair of words in the input list such that their concatenation is a palindrome. >>> palindr...
def is_palindrome(s): """ Helper function to check if a string is a palindrome. """ return s == s[::-1] def palindrome_pair(words): """ Function to determine if there exists a pair of words in the input list such that their concatenation is a palindrome. """ word_set = set(words) ...
from solution import palindrome_pair def test_palindrome_pair_true(): assert palindrome_pair(["bat", "tab", "cat"]) == True assert palindrome_pair(["abc", "cba", "xyz"]) == True assert palindrome_pair(["race", "car"]) == True def test_palindrome_pair_false(): assert palindrome_pair(["abc", "def", "ghi...
[ { "docstring": "Helper function to check if a string is a palindrome.", "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": "Function to determine if there exists a pair of words in the input list\nsuch that their conca...
[ 1, 0, 1, 1, 0, 1, 1, 0, 1, 1 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_palindrome(s):\n return s == s[::-1]\n\ndef check_palindrome_pair(words):\n \"\"\"\n This function checks if there exists a pair of words (word1, word2) such ...
trial_gpt4o_9
{ "original_instruction": "You are given a list of strings `words`, where each string is a word consisting of lowercase English letters only. Your task is to determine if there exists a pair of words `(word1, word2)` from the list, such that `word1 + word2` (concatenation of `word1` and `word2`) is a palindrome. A pa...
0.85868
Leetcode_41057
C
[ "is_palindrome", "palindrome_pair" ]
2
[ [ "palindrome_pair", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
cd5c19d61b6d7df64dbc0add60026a8b0450d0ed
06bbe0d997b573bfcd4103f82d5af5acb0057633
v1.0
complete
Leetcode
Leetcode_41556_C
def is_prime(num): """ Check if a number is prime. """ pass def sum_of_primes(m, n): """ Returns the sum of all prime numbers between m and n inclusive. >>> sum_of_primes(1, 10) 17 >>> sum_of_primes(3, 3) 3 >>> sum_of_primes(1, 1) 0 >>> sum_of_primes(2, 3) 5 ...
def is_prime(num): """ Check if a number is prime. """ if num < 2: return False for i in range(2, int(num**0.5) + 1): if num % i == 0: return False return True def sum_of_primes(m, n): """ Returns the sum of all prime numbers between m and n inclusive. ""...
from solution import sum_of_primes def test_sum_of_primes_within_range(): assert sum_of_primes(1, 10) == 17 # primes are 2, 3, 5, 7 def test_sum_of_primes_single_prime(): assert sum_of_primes(3, 3) == 3 # only 3 is prime def test_sum_of_primes_no_primes(): assert sum_of_primes(1, 1) == 0 # no primes i...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns the sum of all prime numbers between m and n inclusive.", "function_declaration": "def sum_of_primes(m, n):", ...
[ 0, 0, 0, 0, 0, 1, 0, 1, 1, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num == 2:\n return True\n if num % 2 == ...
trial_gpt4o_8
{ "original_instruction": "Given two integers `m` and `n`, where `1 <= m <= n`, return _the sum of all prime numbers between_ `m` _and_ `n` _inclusive_. If there are no prime numbers in the given range, return `0`.", "prompt_id": "0000041556", "row_id": 41556, "seed_ids": "['1314', '637', '795']" }
0.822128
Leetcode_41556
C
[ "is_prime", "sum_of_primes" ]
2
[ [ "sum_of_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2fa24392d7c3db67d04b72749d36b3ce14d68a87
bd6f6e821a5fc71b15608f0d0cae600a7b144510
v1.0
complete
Leetcode
Leetcode_41593_C
def transform(nums): """ Transforms the input array such that each element is replaced by the sum of all distinct integers except for the element at the current position. >>> transform([1]) == [0] >>> transform([1, 2]) == [2, 1] >>> transform([1, 2, 3]) == [5, 4, 3] >>> transform([4, 5, 6])...
def transform(nums): """ Transforms the input array such that each element is replaced by the sum of all distinct integers except for the element at the current position. """ total_sum = sum(set(nums)) return [total_sum - num for num in nums] def simulate_transform(nums, k): """ Simula...
from solution import transform, simulate_transform def test_transform_single_element(): assert transform([1]) == [0] def test_transform_two_elements(): assert transform([1, 2]) == [2, 1] def test_transform_distinct_elements(): assert transform([1, 2, 3]) == [5, 4, 3] assert transform([4, 5, 6]) =...
[ { "docstring": "Transforms the input array such that each element is replaced by the sum of all distinct integers \nexcept for the element at the current position.", "function_declaration": "def transform(nums):", "function_name": "transform", "parameter_list": "(nums)" }, { "docstring": "Si...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def transform(nums):\n \"\"\"\n Transform the input array such that each element at index i is replaced\n with the sum of all distinct integers in the input array ex...
trial_gpt4o_8
{ "original_instruction": "You are given an array `nums` consisting of non-negative integers. The function `transform(arr)` is defined as follows: It takes an array of integers as input and returns an array where `arr[i]` is replaced with the **sum of all distinct** integers in the input array excluding `arr[i]`.\n\n...
0.630773
Leetcode_41593
C
[ "transform", "simulate_transform" ]
2
[ [ "simulate_transform", "transform" ] ]
1
[]
false
[]
false
pytest
true
[]
true
68d4e284078102627f44c30672816c8411220bf6
f568accd722d347b7f36eef9535eec5dfb0ee7fe
v1.0
complete
Leetcode
Leetcode_41631_C
class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None def find_lca(root, p, q): """ Function to find the minimum value node that is a common ancestor of nodes p and q. """ pass def min_common_ancestor(root, p, q): """ Returns the val...
class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None def find_lca(root, p, q): """ Function to find the minimum value node that is a common ancestor of nodes p and q. """ if root is None: return None # If either p or q m...
from solution import TreeNode, min_common_ancestor def create_sample_tree(): # Creating a sample tree: # 5 # / \ # 3 8 # / \ \ # 2 4 9 root = TreeNode(5) root.left = TreeNode(3) root.right = TreeNode(8) root.left.left = TreeNode(2) root....
[]
[ 1, 0, 1, 0, 0, 0, 0, 1, 0 ]
3
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, value=0, left=None, right=None):\n self.value = value\n self.left = left\n self.right = right\n\ndef find_min_com...
trial_gpt4o_8
{ "original_instruction": "You are given a binary tree in which each node contains a value. Design an algorithm to find the minimum value node that is a common ancestor of two given nodes `p` and `q`. The value of each node is unique and `p` and `q` refer to the values of the nodes you need to find the common ancesto...
0.563141
Leetcode_41631
C
[ "find_lca", "min_common_ancestor" ]
2
[ [ "min_common_ancestor", "find_lca" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
2b99543c28dc9916fbbf57eba38b28fecdcff033
b85d61e00630cccf5851a23e12cd8ea4c248e50e
v1.0
complete
Leetcode
Leetcode_41947_C
class TreeNode: def __init__(self, value=0, left=None, right=None): self.value = value self.left = left self.right = right def insert_node(root, value): """ Insert a node with 'value' into the tree rooted at 'root'. :param root: TreeNode, the root of the tree :param val...
class TreeNode: def __init__(self, value=0, left=None, right=None): self.value = value self.left = left self.right = right def insert_node(root, value): if not root: return TreeNode(value) if value < root.value: root.left = insert_node(root.left, value) else: ...
from solution import level_order def test_level_order_single_element(): assert level_order([1]) == [[1]] def test_level_order_two_elements(): assert level_order([2, 1]) == [[2], [1]] assert level_order([1, 2]) == [[1], [2]] def test_level_order_multiple_elements(): assert level_order([3, 1, 2, 4, 5])...
[]
[ 1, 1, 1, 0, 1, 0, 1, 0, 1, 0 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "from collections import deque\n\nclass TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right ...
trial_gpt4o_8
{ "original_instruction": "You are given an array of integers `nums` representing a permutation of numbers from `1` to `n`. You need to build a binary tree by inserting the elements of the array in the given order. After constructing the binary tree, return the level-order traversal of the tree as a 2D array, where e...
0.54388
Leetcode_41947
C
[ "insert_node", "build_tree", "level_order_traversal", "level_order" ]
4
[ [ "build_tree", "insert_node" ], [ "level_order", "build_tree" ], [ "level_order", "level_order_traversal" ] ]
3
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
db5a19190610649ef40a9de35954970d9a452262
18eeba5eeeea398ea09e12763f2270b400f9a517
v1.0
complete
Leetcode
Leetcode_41956_C
from typing import List, Tuple def find_pairs_and_scaling_factor(nums: List[int], target: int, m: int) -> Tuple[List[Tuple[int, int]], int]: """ You are given an integer array 'nums' and an integer 'target'. You need to find all unique pairs (nums[i], nums[j]) such that their sum is equal to 'target', and 'i'...
def find_unique_pairs(nums, target): """ Finds all unique pairs in nums that sum up to the target. """ nums.sort() seen = set() pairs = set() for num in nums: complement = target - num if complement in seen: pair = (min(num, complement), max(num, complement))...
from solution import find_pairs_and_scaling_factor def test_find_pairs_and_scaling_factor_no_pairs(): result = find_pairs_and_scaling_factor([1, 2, 3], 7, 3) assert result == ([], 1) def test_find_pairs_and_scaling_factor_single_pair(): result = find_pairs_and_scaling_factor([1, 2, 3, 4], 5, 3) assert...
[ { "docstring": "Finds all unique pairs in nums that sum up to the target.", "function_declaration": "def find_unique_pairs(nums, target):", "function_name": "find_unique_pairs", "parameter_list": "(nums, target)" }, { "docstring": "Determines the scaling factor required to fit all the pairs ...
[ 0, 0, 0, 0, 0, 0, 0, 1, 0, 1 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "from typing import List, Tuple\n\ndef find_unique_pairs(nums: List[int], target: int) -> List[Tuple[int, int]]:\n # Use a set to track unique pairs and seen numbers\n p...
trial_gpt4o_9
{ "original_instruction": "You are given an integer array `nums` and an integer `target`. You need to find all **unique pairs** `(nums[i], nums[j])` such that their sum is equal to `target`, and `i` is not equal to `j`. A pair `(nums[i], nums[j])` is considered unique if there are no other pairs with the same element...
0.606601
Leetcode_41956
C
[ "find_unique_pairs", "determine_scaling_factor", "find_pairs_and_scaling_factor" ]
3
[ [ "find_pairs_and_scaling_factor", "determine_scaling_factor" ], [ "find_pairs_and_scaling_factor", "find_unique_pairs" ] ]
2
[]
false
[]
false
pytest
true
[]
true
5eb0a25f3824e1c612e7fd36c84c2e023be01d0e
031b09edb76291b4bc40437868ce11829277601f
v1.0
complete
Leetcode
Leetcode_42004_C
def count_secluded_islands(grid): """ Returns the number of secluded islands in the given grid. Args: grid (list[list[str]]): 2D list of '1's and '0's representing land and water respectively. Returns: int: The number of secluded islands. >>> grid = [ ... ['0', '0', '0'...
def is_secluded(grid, x, y): """Helper function to determine if a position (x, y) in the grid is a secluded island.""" m, n = len(grid), len(grid[0]) for dx, dy in [(-1, 0), (1, 0), (0, -1), (0, 1)]: nx, ny = x + dx, y + dy if 0 <= nx < m and 0 <= ny < n and grid[nx][ny] == '1': ...
from solution import count_secluded_islands def test_no_secluded_islands(): grid = [ ['0', '0', '0', '0'], ['0', '1', '1', '0'], ['0', '1', '1', '0'], ['0', '0', '0', '0'] ] assert count_secluded_islands(grid) == 0 def test_one_secluded_island(): grid = [ ['0', ...
[ { "docstring": "Helper function to determine if a position (x, y) in the grid is a secluded island.", "function_declaration": "def is_secluded(grid, x, y):", "function_name": "is_secluded", "parameter_list": "(grid, x, y)" }, { "docstring": "Returns the number of secluded islands in the give...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def num_secluded_islands(grid):\n m, n = len(grid), len(grid[0])\n isolated_islands = 0\n \n def is_isolated(i, j):\n if i < 0 or i >= m or j < 0 or j >= n...
trial_gpt4o_8
{ "original_instruction": "You are given a 2D grid `grid` of size `m x n` where each cell represents a different block of land or water. The grid has '1's (land) and '0's (water). A block of land is considered a secluded island if all the land blocks are completely surrounded by water and there are no adjacent land b...
0.579496
Leetcode_42004
C
[ "is_secluded", "count_secluded_islands" ]
2
[ [ "count_secluded_islands", "is_secluded" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5ee7ef91fbb3fa20bec38b39f0249964f8a56b49
2100f9452c7d50972f5be1176a2959a0fc51c889
v1.0
complete
Leetcode
Leetcode_42019_C
from typing import List def sum_of_digits(n: int) -> int: """ Return the sum of the digits of a positive number n. """ return sum(int(digit) for digit in str(n)) def product_of_digits(n: int) -> int: """ Return the product of the digits of a positive number n. """ product = 1 for ...
def sum_of_digits(n): """ Return the sum of the digits of a positive number n. """ return sum(int(digit) for digit in str(n)) def product_of_digits(n): """ Return the product of the digits of a positive number n. """ product = 1 for digit in str(n): product *= int(digit) ...
from solution import transform def test_transform_positive_numbers(): assert transform([12, 34]) == [3, 7] # 1+2 = 3, 3+4 = 7 def test_transform_negative_numbers(): assert transform([-23, -45]) == [6, 20] # 2*3 = 6, 4*5 = 20 def test_transform_zero(): assert transform([0, 0]) == [0, 0] def test_transf...
[ { "docstring": "Return the sum of the digits of a positive number n.", "function_declaration": "def sum_of_digits(n):", "function_name": "sum_of_digits", "parameter_list": "(n)" }, { "docstring": "Return the product of the digits of a positive number n.", "function_declaration": "def pro...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def transform_array(nums):\n def sum_of_digits(num):\n return sum(int(digit) for digit in str(num))\n\n def product_of_digits(num):\n product = 1\n ...
trial_gpt4o_9
{ "original_instruction": "You are given an integer array `nums` of length `n` which may contain both positive and negative integers. Your task is to modify the array by applying the following transformation rules exactly once. The transformation rules are:\n- If the number is positive, replace it with the sum of its...
0.749451
Leetcode_42019
C
[ "sum_of_digits", "product_of_digits", "transform" ]
3
[ [ "transform", "product_of_digits" ], [ "transform", "sum_of_digits" ] ]
2
[]
false
[]
false
pytest
true
[]
true
2f949c106d427d79c1501a7f0f02b6315a4113ae
3ac2726254324cb4936b9a31dac17073bdfbbe1a
v1.0
complete
Leetcode
Leetcode_42033_C
def is_subsequence(s: str, word: str) -> bool: """ Helper function to check if 'word' is a subsequence of 's'. """ pass def longest_subsequence_length(words: List[str], s: str) -> int: """ Returns the length of the longest subsequence from words that can be formed by deleting some characte...
def is_subsequence(s, word): """ Helper function to check if 'word' is a subsequence of 's'. """ it = iter(s) return all(char in it for char in word) def longest_subsequence_length(words, s): """ Returns the length of the longest subsequence from words that can be formed by deleting so...
from solution import longest_subsequence_length def test_longest_subsequence_length_all_subsequences(): assert longest_subsequence_length(["a", "b", "c"], "abc") == 1 def test_longest_subsequence_length_empty_words(): assert longest_subsequence_length([], "abc") == 0 def test_longest_subsequence_length_singl...
[ { "docstring": "Helper function to check if 'word' is a subsequence of 's'.", "function_declaration": "def is_subsequence(s, word):", "function_name": "is_subsequence", "parameter_list": "(s, word)" }, { "docstring": "Returns the length of the longest subsequence from words that can be \nfor...
[ 0, 0, 0, 0, 0, 1, 1, 1, 0, 1 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_subsequence(word, s):\n \"\"\"\n Check if 'word' is subsequence of 's'\n \"\"\"\n it = iter(s)\n return all(char in it for char in word)\n\ndef longest_...
trial_gpt4o_9
{ "original_instruction": "You are given a list of strings `words` and an input string `s`. Your task is to determine the length of the longest subsequence in the list of strings `words` that can be formed by deleting some (or no) characters from the input string `s` so that the ordering of characters in the input st...
0.756154
Leetcode_42033
C
[ "is_subsequence", "longest_subsequence_length" ]
2
[ [ "longest_subsequence_length", "is_subsequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b1cef93977298463d6238d42b32728e2c7d89b5b
ff132232cc2398dbc91a901b0992a3b32fecb94e
v1.0
complete
Leetcode
Leetcode_42125_C
def subsequence_indexes(textQuoteStore: List[str], quote: str) -> List[int]: """ Returns a list of indexes of the quotes in textQuoteStore where 'quote' is a subsequence. >>> subsequence_indexes(["hello world", "herb", "hhooo"], "ho") == [0, 2] >>> subsequence_indexes(["abc", "def", "ghi"], "z") == [] ...
def is_subsequence(s, t): """ Helper function to determine if the string s is a subsequence of t. """ iter_t = iter(t) return all(char in iter_t for char in s) def subsequence_indexes(textQuoteStore, quote): """ Returns a list of indexes of the quotes in textQuoteStore where 'quote' is a su...
from solution import subsequence_indexes def test_basic(): textQuoteStore = ["hello world", "herb", "hhooo"] quote = "ho" assert subsequence_indexes(textQuoteStore, quote) == [0, 2] def test_no_match(): textQuoteStore = ["abc", "def", "ghi"] quote = "z" assert subsequence_indexes(textQuoteStor...
[ { "docstring": "Helper function to determine if the string s is a subsequence of t.", "function_declaration": "def is_subsequence(s, t):", "function_name": "is_subsequence", "parameter_list": "(s, t)" }, { "docstring": "Returns a list of indexes of the quotes in textQuoteStore where 'quote' ...
[ 0, 0, 0, 0, 1, 1, 1, 1, 1, 1 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_subsequence(quote, text):\n \"\"\"Helper function that checks if `quote` is a subsequence of `text`.\"\"\"\n it = iter(text)\n return all(c in it for c in quo...
trial_gpt4o_9
{ "original_instruction": "You are given a list of strings `textQuoteStore` containing short quotes from various books and a string `quote` representing the text of a new quote. Your task is to determine if the new quote is a *subsequence* of any of the existing quotes in `textQuoteStore`. A `subsequence` is a sequen...
0.584665
Leetcode_42125
C
[ "is_subsequence", "subsequence_indexes" ]
2
[ [ "subsequence_indexes", "is_subsequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c18107d9c5fa97e69aa300f4087dae042ac1a888
ebdae85ea5719205b9a83cde08d2917b4f346aba
v1.0
complete
Leetcode
Leetcode_42257_C
from typing import List, Optional class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def binary_trees_with_sum(n: int, m: int) -> List[Optional[TreeNode]]: """ Given two integers `n` and `m`, find all possible unique bin...
from typing import List, Optional class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def find_trees(n, m, start=1): if n == 0 and m == 0: return [None] if n <= 0 or m <= 0: return [] trees = [] ...
from solution import binary_trees_with_sum from solution import TreeNode def test_single_node(): result = binary_trees_with_sum(1, 1) assert len(result) == 1 assert result[0].val == 1 assert result[0].left == None assert result[0].right == None def test_two_nodes(): result = binary_trees_with_...
[]
[ 0, 0, 0, 1, 0, 0, 0, 1, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "from typing import List, Optional\n\nclass TreeNode:\n def __init__(self, val: int, left: Optional['TreeNode'] = None, right: Optional['TreeNode'] = None):\n self.v...
trial_gpt4o_3
{ "original_instruction": "Given two integers `n` and `m`, you have to find all possible unique binary trees with `n` nodes that can be formed such that the sum of the values of the nodes in the tree is equal to `m`. Return _a list of such possible binary trees_, where each tree is represented by its root node. Each ...
0.601024
Leetcode_42257
C
[ "find_trees", "binary_trees_with_sum" ]
2
[ [ "binary_trees_with_sum", "find_trees" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
9401891b85ba1bbdb4380ac66652cef28cb82109
8ef1073aef9f9e9ecd8434af4c351a58045f9511
v1.0
complete
Leetcode
Leetcode_42311_C
def minimize_maximum_time(projects: List[int], k: int) -> int: """ Given an integer array `projects` where `projects[i]` represents the time required to complete the `i`-th project and an integer `k` representing the number of workers available, return the minimum possible value of the maximum w...
def is_valid(workloads, k, max_workload): current_sum = 0 workers_needed = 1 for workload in workloads: if current_sum + workload > max_workload: workers_needed += 1 current_sum = workload if workers_needed > k: return False else: ...
from solution import minimize_maximum_time def test_case_1(): projects = [10, 20, 30] k = 2 assert minimize_maximum_time(projects, k) == 30 def test_case_2(): projects = [10, 5, 10] k = 2 assert minimize_maximum_time(projects, k) == 15 def test_case_3(): projects = [7, 2, 5, 10, 8] k ...
[ { "docstring": null, "function_declaration": "def is_valid(workloads, k, max_workload):", "function_name": "is_valid", "parameter_list": "(workloads, k, max_workload)" }, { "docstring": null, "function_declaration": "def minimize_maximum_time(projects, k):", "function_name": "minimiz...
[ 0, 1, 0, 1, 0, 0, 0, 0, 0 ]
2
hard
0.222
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def canComplete(projects, k, mid):\n workers = [0] * k\n \n for time in projects:\n if time > mid:\n return False\n min_worker = workers.ind...
trial_gpt4o_3
{ "original_instruction": "You are given an integer array `projects` where `projects[i]` represents the time required to complete the `i`-th project. You are also given an integer `k` representing the number of workers available. Each worker can be assigned to any project, but each project must be completed by one wo...
0.663267
Leetcode_42311
C
[ "is_valid", "minimize_maximum_time" ]
2
[ [ "minimize_maximum_time", "is_valid" ] ]
1
[]
false
[]
false
pytest
true
[]
true
07c6576a10714d3e9b5e94eb918978615779c716
a1da3aa9e0075b0a759324e3a55948f086784506
v1.0
complete
Leetcode
Leetcode_42340_C
from typing import List def find_median(arr: List[int]) -> float: """ Compute the median of an array of integers. >>> find_median([1, 2, 3]) == 2.0 >>> find_median([4, 3, 2, 1]) == 2.5 >>> find_median([12, 3, 5, 7, 19, 26, 14]) == 12.0 """ def k_closest_to_median(arr: List[int], k: int) -> List[in...
def find_median(arr): arr_sorted = sorted(arr) n = len(arr) if n % 2 == 1: return float(arr_sorted[n // 2]) else: return (arr_sorted[n // 2 - 1] + arr_sorted[n // 2]) / 2.0 def k_closest_to_median(arr, k): median = find_median(arr) arr_sorted = sorted(arr, key=lambda x: (ab...
from solution import find_median, k_closest_to_median def test_find_median_odd_length(): assert find_median([1, 2, 3]) == 2.0 assert find_median([3, 1, 2]) == 2.0 def test_find_median_even_length(): assert find_median([1, 2, 3, 4]) == 2.5 assert find_median([4, 3, 2, 1]) == 2.5 def test_find_median_s...
[ { "docstring": null, "function_declaration": "def find_median(arr):", "function_name": "find_median", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "def k_closest_to_median(arr, k):", "function_name": "k_closest_to_median", "parameter_list": "(arr, k)"...
[ 0, 1, 0, 0, 0, 0, 0, 0, 0, 1 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def find_median(arr):\n \"\"\"\n Finds the median of the array.\n \"\"\"\n arr.sort()\n length = len(arr)\n \n if length % 2 == 1:\n return arr[le...
trial_gpt4o_9
{ "original_instruction": "Given an array of integers `arr` and an integer `k`, return the _k_ closest integers to the median of `arr`. **Note**: If there is a tie, return the smaller integers first. The median is computed as follows: \n1. If the array length is odd, the median is the middle element after sorting the...
0.820593
Leetcode_42340
C
[ "find_median", "k_closest_to_median" ]
2
[ [ "k_closest_to_median", "find_median" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f76bdb1370f18d3b4d25b08db9d160c9f9b0249c
0932aa305e4408bfc18d12022168c07d70d1bdc0
v1.0
complete
Leetcode
Leetcode_42648_C
def contains_magic_square(matrix): """ Determine if there is a magic square of size 3x3 in the given matrix. A magic square is a 3x3 grid filled with distinct integers from 1 to 9 such that each row, each column, and both diagonals all have the same sum. >>> contains_magic_square([ .....
def is_magic_square(submatrix): s = 15 # Sum of each row/column/diagonal in a 3x3 magic square of 1-9 return ( sum(submatrix[0]) == s and sum(submatrix[1]) == s and sum(submatrix[2]) == s and sum(submatrix[i][0] for i in range(3)) == s and sum(submatrix[i][1] for i in ra...
from solution import contains_magic_square def test_no_magic_square(): matrix = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] assert contains_magic_square(matrix) == False def test_one_magic_square(): matrix = [ [4, 9, 2], [3, 5, 7], [8, 1, 6] ] assert con...
[ { "docstring": null, "function_declaration": "def is_magic_square(submatrix):", "function_name": "is_magic_square", "parameter_list": "(submatrix)" }, { "docstring": null, "function_declaration": "def contains_magic_square(matrix):", "function_name": "contains_magic_square", "par...
[ 0, 0, 1, 0, 0, 0, 1, 1, 1, 0 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_magic_square(grid):\n # Check if the 3x3 grid is a magic square\n s = set()\n for i in range(3):\n for j in range(3):\n s.add(grid[i][j])\n\...
trial_gpt4o_6
{ "original_instruction": "You are given an `n x n` integer matrix `mat`. You need to determine if there is a **magic square** of size `3 x 3` anywhere in the matrix. A **magic square** is a `3 x 3` grid filled with distinct integers from 1 to 9 such that each row, each column, and both diagonals all have the same su...
0.683379
Leetcode_42648
C
[ "is_magic_square", "contains_magic_square" ]
2
[ [ "contains_magic_square", "is_magic_square" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d39cfc6df7f1b3914f6ee34a91366043513457a2
cea89283b22ebb848d3fb6874af75260f7823689
v1.0
complete
Leetcode
Leetcode_42684_C
def time_diff_in_minutes(time1: str, time2: str) -> int: """ Returns the difference in minutes between two time strings formatted as "HH:MM". >>> time_diff_in_minutes("09:00", "10:30") 90 >>> time_diff_in_minutes("09:00", "09:15") 15 >>> time_diff_in_minutes("13:45", "14:15") 30 >>> time_diff_in...
def time_diff_in_minutes(time1, time2): """ Returns the difference in minutes between two time strings formatted as "HH:MM". """ h1, m1 = map(int, time1.split(':')) h2, m2 = map(int, time2.split(':')) return (h2 - h1) * 60 + (m2 - m1) def calculate_total_minutes(logTimes): """ Given a l...
from solution import calculate_total_minutes, time_diff_in_minutes def test_single_log_period(): assert calculate_total_minutes(["09:00-10:30"]) == [90] def test_multiple_log_periods(): assert calculate_total_minutes(["09:00-10:30", "13:45-14:15", "16:00-17:00"]) == [90, 30, 60] def test_multiple_same_period...
[ { "docstring": "Returns the difference in minutes between two time strings formatted as \"HH:MM\".", "function_declaration": "def time_diff_in_minutes(time1, time2):", "function_name": "time_diff_in_minutes", "parameter_list": "(time1, time2)" }, { "docstring": "Given a list of log-in/log-ou...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def calculate_total_minutes(logTimes):\n \"\"\"\n Calculates the total log-in duration in minutes for each time period in logTimes.\n \n Args:\n logTimes (list...
trial_gpt4o_8
{ "original_instruction": "A company is developing an employee time-tracking application. Each employee has an associated list of timestamps that indicate their log-ins and log-outs throughout the day. You are given a list of strings `logTimes` where each element is in the format \"HH:MM-HH:MM\" (e.g., \"09:00-17:00\...
0.629682
Leetcode_42684
C
[ "time_diff_in_minutes", "calculate_total_minutes" ]
2
[ [ "calculate_total_minutes", "time_diff_in_minutes" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e70126d325cd84ac94a43015629c0b6af05861ec
158647dd3c67d6b108acf386ab591266684c3061
v1.0
complete
Leetcode
Leetcode_42977_C
def maximalRectangle(matrix: List[List[str]]) -> int: """ Given a `m x n` binary matrix `mat`, return the maximum area of a rectangle that contains only '1's. >>> maximalRectangle([["1","0","1","0","0"], ... ["1","0","1","1","1"], ... ["1","1","1","1","1"], ....
def maximalRectangle(matrix): if not matrix: return 0 max_area = 0 dp = [0] * len(matrix[0]) for row in matrix: for index, val in enumerate(row): dp[index] = dp[index] + 1 if val == '1' else 0 max_area = max(max_area, largestRectangleArea(dp)) return max_are...
from solution import maximalRectangle def test_single_row_matrix(): matrix = [["1","0","1","0","0"], ["1","0","1","1","1"], ["1","1","1","1","1"], ["1","0","0","1","0"]] assert maximalRectangle(matrix) == 6 def test_all_zeros(): matrix = [["0","0","0"], ...
[ { "docstring": null, "function_declaration": "def maximalRectangle(matrix):", "function_name": "maximalRectangle", "parameter_list": "(matrix)" }, { "docstring": null, "function_declaration": "def largestRectangleArea(heights):", "function_name": "largestRectangleArea", "paramete...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def maximal_rectangle(matrix):\n \"\"\"\n Returns the maximum area of a rectangle containing only 1's in a given binary matrix.\n \"\"\"\n if not matrix or not ma...
trial_gpt4o_8
{ "original_instruction": "Given a `m x n` binary matrix `mat`, return _the **maximum area** of a rectangle that contains only `1`s_. A rectangle is defined as a contiguous block of cells that all have the value `1` and can span over multiple rows and columns. The area of the rectangle is given by the number of cell...
0.70295
Leetcode_42977
C
[ "maximalRectangle", "largestRectangleArea" ]
2
[ [ "maximalRectangle", "largestRectangleArea" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f0c12964098beaf173c58eb468bccee51d4891f8
3c4cf6272706ae39223ef6b81341dd4a0cc54b33
v1.0
complete
Leetcode
Leetcode_43228_C
def count_k_palin_substrings(s: str, k: int) -> int: """ Return the number of k-palin substrings in the string s. A k-palin is a substring that can be rearranged to form a palindrome with at most k characters having an odd frequency. >>> count_k_palin_substrings("", 1) == 0 >>> count_k_palin_subst...
from collections import Counter def is_k_palin(substring, k): """ Helper function to check if the substring can be rearranged to form a k-palindrome. A string can be rearranged to form a palindrome if at most one character has an odd count. For k-palindrome, it's allowed to have up to k characters with...
from solution import count_k_palin_substrings def test_empty_string(): assert count_k_palin_substrings("", 1) == 0 def test_single_character_string(): assert count_k_palin_substrings("a", 1) == 1 def test_all_characters_same(): assert count_k_palin_substrings("aaaa", 0) == 10 # All substrings are palind...
[ { "docstring": "Helper function to check if the substring can be rearranged to form a k-palindrome.\nA string can be rearranged to form a palindrome if at most one character has an odd count.\nFor k-palindrome, it's allowed to have up to k characters with odd counts.", "function_declaration": "def is_k_pali...
[ 0, 1, 0, 0, 0, 0, 0, 0, 1, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "from collections import Counter\n\ndef is_k_palin(substring, k):\n \"\"\"\n Check if a substring is k-palindromic.\n \"\"\"\n freq = Counter(substring)\n odd_c...
trial_gpt4o_8
{ "original_instruction": "You are given a string `s` and an integer `k`. A substring is called a **k-palin** if it is k-palindromic, meaning the substring can be rearranged to form a palindrome. Return _the **number** of k-palin substrings in the string `s`._ A substring is a **contiguous** part of a string. For ins...
0.740885
Leetcode_43228
C
[ "is_k_palin", "count_k_palin_substrings" ]
2
[ [ "count_k_palin_substrings", "is_k_palin" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2b832b97185037fc8d49209c850a813faa1adb16
54c28f11b971b10280058d1501fd249a2ebdf5a4
v1.0
complete
Leetcode
Leetcode_43265_C
def find_longest_word(s: str, dict: List[str]) -> str: """ Given a string s and an array of strings dict, return the longest string in dict that can be formed by deleting some of the characters of s. If there are multiple strings with the same length, return the lexicographically smallest one. If there ...
def is_subsequence(x, y): it = iter(y) return all(c in it for c in x) def find_longest_word(s, dict): dict.sort(key=lambda x: (-len(x), x)) for word in dict: if is_subsequence(word, s): return word return ""
from solution import find_longest_word def test_find_longest_word_no_subsequence(): s = "abc" dictionary = ["def", "ghi"] assert find_longest_word(s, dictionary) == "" def test_find_longest_word_single_matching(): s = "abpcplea" dictionary = ["ale", "apple", "monkey", "plea"] assert find_longe...
[ { "docstring": null, "function_declaration": "def is_subsequence(x, y):", "function_name": "is_subsequence", "parameter_list": "(x, y)" }, { "docstring": null, "function_declaration": "def find_longest_word(s, dict):", "function_name": "find_longest_word", "parameter_list": "(s, ...
[ 0, 1, 1, 1, 0, 0, 0, 1, 0, 1 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def find_longest_word(s, dict):\n def is_subsequence(x, y):\n it = iter(y)\n return all(c in it for c in x)\n\n longest_word = \"\"\n for word in sorte...
trial_gpt4o_9
{ "original_instruction": "Given a string `s` and an array of strings `dict`, return _the longest string in_ `dict` _that can be formed by deleting some of the characters of_ `s`. If there are multiple strings with the same length, return the lexicographically smallest one. If there is no possible result, return an e...
0.797313
Leetcode_43265
C
[ "is_subsequence", "find_longest_word" ]
2
[ [ "find_longest_word", "is_subsequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9bc024eb38a19f9ed1b7292be005c4cd840b9fa0
25ddcd2869277e225fb9124e021aa2575c45cf67
v1.0
complete
Leetcode
Leetcode_43314_C
def find(parent, i): """ Finds the root of the set in which element i is present. Args: parent (List[int]): The parent list representing the union-find structure. i (int): The index of the element for which to find the root. Returns: int: The root of the set in which element i is prese...
def find(parent, i): if parent[i] == i: return i return find(parent, parent[i]) def union(parent, rank, x, y): rootX = find(parent, x) rootY = find(parent, y) if rootX != rootY: if rank[rootX] > rank[rootY]: parent[rootY] = rootX elif rank[rootX] < rank[root...
from solution import find, union, smallestStringWithSwaps def test_find_union(): parent = [0, 1, 2, 3] rank = [0, 0, 0, 0] union(parent, rank, 0, 1) union(parent, rank, 1, 2) assert find(parent, 2) == find(parent, 0) == 0 or find(parent, 2) == find(parent, 0) == 2 def test_smallest_string_with_swa...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "from collections import defaultdict\n\ndef smallestStringWithSwaps(s, pairs):\n def find(x):\n if parent[x] != x:\n parent[x] = find(parent[x])\n ...
trial_gpt4o_9
{ "original_instruction": "You are given a string `s` consisting of lowercase English letters and a list of operations. Each operation is characterized by swapping two characters at given indices `i` and `j`. After performing all given operations, a string is considered to be lexicographically smallest if no permutat...
0.580461
Leetcode_43314
C
[ "find", "union", "smallestStringWithSwaps" ]
3
[ [ "smallestStringWithSwaps", "find" ], [ "smallestStringWithSwaps", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
true
[]
true
cdad625f9649fa807efa940f6f72db2f19425a71
32f7e54e0a8edf1f69f1920dc22f5a5e68f1a19a
v1.0
complete
Leetcode
Leetcode_43535_C
import random def partition(arr, low, high): pivot = arr[high] i = low - 1 for j in range(low, high): if arr[j] <= pivot: i += 1 arr[i], arr[j] = arr[j], arr[i] arr[i + 1], arr[high] = arr[high], arr[i + 1] return i + 1 def quickselect(arr, low, high, k): if low...
import random def partition(arr, low, high): pivot = arr[high] i = low - 1 for j in range(low, high): if arr[j] <= pivot: i += 1 arr[i], arr[j] = arr[j], arr[i] arr[i + 1], arr[high] = arr[high], arr[i + 1] return i + 1 def quickselect(arr, low, high, k): if low...
from solution import kthSmallest def test_kth_smallest_general(): assert kthSmallest([7, 10, 4, 3, 20, 15], 3) == 7 assert kthSmallest([7, 10, 4, 3, 20, 15], 2) == 4 def test_kth_smallest_edge_cases(): assert kthSmallest([1, 2], 1) == 1 assert kthSmallest([1, 2], 2) == 2 def test_kth_smallest_negativ...
[ { "docstring": null, "function_declaration": "def partition(arr, low, high):", "function_name": "partition", "parameter_list": "(arr, low, high)" }, { "docstring": null, "function_declaration": "def quickselect(arr, low, high, k):", "function_name": "quickselect", "parameter_list...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def partition(arr, low, high):\n pivot = arr[high]\n i = low\n for j in range(low, high):\n if arr[j] <= pivot:\n arr[i], arr[j] = arr[j], arr[i]\n...
trial_gpt4o_9
{ "original_instruction": "You are given an array `arr` of integers and an integer `k`. The array `arr` contains at least two distinct elements. Your task is to find the `k`-th smallest number in the array using the Quickselect algorithm, an optimization of the QuickSort algorithm.\n\nThe Quickselect algorithm works ...
0.588077
Leetcode_43535
C
[ "partition", "quickselect", "kthSmallest" ]
3
[ [ "kthSmallest", "quickselect" ], [ "quickselect", "partition" ] ]
2
[]
false
[]
false
pytest
true
[]
true
8dfeb8abb78f378bbd33e52030b32e331466feda
ee1224f6dd7b685cf1221fecf03525405d786aa9
v1.0
complete
Leetcode
Leetcode_43959_C
from typing import List def minimizeLargestSum(nums: List[int], threshold: int) -> int: """ Find the minimum possible largest sum of the subarrays that the list can be divided into, such that the sum of each subarray does not exceed the threshold. >>> minimizeLargestSum([7, 2, 5, 10, 8], 2) 18 ...
from typing import List def can_split(nums: List[int], max_sum: int, threshold: int) -> bool: current_sum = 0 count_splits = 1 for num in nums: if current_sum + num <= max_sum: current_sum += num else: count_splits += 1 current_sum = num if c...
from solution import minimizeLargestSum def test_case_1(): assert minimizeLargestSum([7, 2, 5, 10, 8], 2) == 18 def test_case_2(): assert minimizeLargestSum([1, 2, 3, 4, 5], 2) == 9 def test_case_3(): assert minimizeLargestSum([1, 4, 4], 3) == 4 def test_case_4(): assert minimizeLargestSum([1, 2, 3,...
[ { "docstring": null, "function_declaration": "def can_split(nums, max_sum, threshold):", "function_name": "can_split", "parameter_list": "(nums, max_sum, threshold)" }, { "docstring": null, "function_declaration": "def minimizeLargestSum(nums, threshold):", "function_name": "minimize...
[ 0, 1, 0, 0, 1, 1, 1, 1, 1, 0 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def minimizeLargestSum(nums, threshold):\n def isValid(mid):\n current_sum = 0\n count = 1\n for num in nums:\n if current_sum + num > mid:...
trial_gpt4o_8
{ "original_instruction": "You are given a list of `n` integers `nums`, and an integer `threshold`. Your task is to find the minimum possible largest sum of the subarrays that the list can be divided into, such that the sum of each subarray does not exceed `threshold`. You need to perform the split in such a way that...
0.722094
Leetcode_43959
C
[ "can_split", "minimizeLargestSum" ]
2
[ [ "minimizeLargestSum", "can_split" ] ]
1
[]
false
[]
false
pytest
true
[]
true
175e153e0f7025a97bd405c8e3bb60999ad14ce6
17e084f79ac0340900c6db174d6502a025a9af7d