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
instruct
Leetcode
Leetcode_19975_I
You are given two integers, `start` and `end`, representing a range [start, end]. Your task is to find the smallest integer `k` that is evenly divisible by all integers in the range. That is, `k` should be the least common multiple (LCM) of all the integers within the given range, both boundaries inclusive. Return the ...
from math import gcd from functools import reduce def lcm(a, b): """ Returns the Least Common Multiple (LCM) of two integers a and b. """ return a * b // gcd(a, b) def smallest_multiple(start, end): """ Returns the smallest integer that is evenly divisible by all integers in the range [start, ...
from solution import smallest_multiple def test_single_element_range(): assert smallest_multiple(5, 5) == 5 def test_small_range(): assert smallest_multiple(1, 2) == 2 assert smallest_multiple(1, 3) == 6 def test_standard_range(): assert smallest_multiple(1, 10) == 2520 def test_medium_range(): ...
[ { "docstring": "Returns the Least Common Multiple (LCM) of two integers a and b.", "function_declaration": "def lcm(a, b):", "function_name": "lcm", "parameter_list": "(a, b)" }, { "docstring": "Returns the smallest integer that is evenly divisible by all integers in the range [start, end]."...
[ 0, 1, 1, 1, 0, 1, 0, 0, 1, 1 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "from math import gcd\nfrom functools import reduce\n\ndef lcm(a, b):\n \"\"\"\n Returns the least common multiple (LCM) of two integers a and b.\n \"\"\"\n return...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000019975", "row_id": 19975, "seed_ids": "['758', '1432', '76']" }
0.65797
Leetcode_19975
I
[ "lcm", "smallest_multiple" ]
2
[ [ "smallest_multiple", "lcm" ] ]
1
[]
false
[]
false
pytest
true
[]
true
474cb56fb237278156af3ce215de80d8edc109c2
0f5ca19eed45ac5faf4b6ccaee398a1e843e538a
v1.0
instruct
Leetcode
Leetcode_20003_I
You are given a list of `strings` and a `string query`. Implement a function that returns the index of the string in the list that matches the `query` after performing at most one string transformation on each string in the list. A transformation consists of either inserting, deleting, or replacing exactly one characte...
def matches_with_one_edit(s1, s2): """ Helper function to determine if s1 can be transformed into s2 by at most one edit (insert, delete, or replace one character). """ m, n = len(s1), len(s2) if abs(m - n) > 1: return False edits = 0 i, j = 0, 0 while i < m and j < n:...
from solution import index_of_query def test_no_transformation_needed(): assert index_of_query(["apple", "banana", "cherry"], "banana") == 1 def test_single_insertion_edit(): assert index_of_query(["apple", "banan", "cherry"], "banana") == 1 def test_single_deletion_edit(): assert index_of_query(["apple"...
[ { "docstring": "Helper function to determine if s1 can be transformed into s2 by at most one edit \n(insert, delete, or replace one character).", "function_declaration": "def matches_with_one_edit(s1, s2):", "function_name": "matches_with_one_edit", "parameter_list": "(s1, s2)" }, { "docstri...
[ 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_one_edit_away(first, second):\n if abs(len(first) - len(second)) > 1:\n return False\n\n if len(first) == len(second):\n return sum(a != b for a, b...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "0000020003", "row_id": 20003, "seed_ids": "['910', '308', '535']" }
0.649778
Leetcode_20003
I
[ "matches_with_one_edit", "index_of_query" ]
2
[ [ "index_of_query", "matches_with_one_edit" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f73e2076bb694ac86b784935875a33527604d7c5
1dc596f723936f24239319fb31a26682790c0ea9
v1.0
instruct
Leetcode
Leetcode_20010_I
A company is planning to structure their IT infrastructure by setting up servers across multiple regions. They have a list of potential regions where a server can be placed, and each server setup has an associated cost. However, the network setup needs to be optimized such that the total cost is minimized while ensurin...
def find(parent, i): if parent[i] == i: return i return find(parent, parent[i]) def union(parent, rank, x, y): root_x = find(parent, x) root_y = find(parent, y) if rank[root_x] < rank[root_y]: parent[root_x] = root_y elif rank[root_x] > rank[root_y]: parent[root_y] = roo...
from solution import minimum_cost def test_example_case(): assert minimum_cost(4, [[0, 1, 1], [1, 2, 2], [2, 3, 3], [3, 0, 4], [1, 3, 5]]) == 6 def test_three_regions_two_edges(): assert minimum_cost(3, [[0, 1, 1], [1, 2, 2]]) == 3 def test_disconnected_regions(): assert minimum_cost(4, [[0, 1, 1], [2, 3...
[ { "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, 1, 0, 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 minimumCost(n, edges):\n \"\"\"\n Finds the minimum cost required to ensure all regions are covered with at least a redundant server placement\n :param n: number...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "0000020010", "row_id": 20010, "seed_ids": "['1489', '1418', '2382']" }
0.635673
Leetcode_20010
I
[ "find", "union", "minimum_cost" ]
3
[ [ "minimum_cost", "find" ], [ "minimum_cost", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
true
[]
true
cd67fdbb29772764fae99ae1eae1d87163e4eabd
0c526abac64131484840a513798ba02adb579460
v1.0
instruct
Leetcode
Leetcode_20022_I
Given an array of integers `nums` and an integer `k`, modify the array in-place such that it becomes its next lexicographical permutation. The replacement must be in-place and use only constant extra memory. If such arrangement is not possible, rearrange `nums` into its lowest possible order (sorted in ascending order)...
def next_permutation(nums): """ Modifies nums in-place to its next lexicographical permutation. If nums is the last permutation, sorts it to the first permutation. """ n = len(nums) if n <= 1: return # Find the rightmost ascent in the array i = n - 2 while i >= 0 and nums[i]...
from solution import next_permutation, kth_permutation def test_one_step_permutation(): nums = [1, 2, 3] next_permutation(nums) assert nums == [1, 3, 2] def test_reverse_permutation(): nums = [3, 2, 1] next_permutation(nums) assert nums == [1, 2, 3] def test_complex_permutation(): nums = ...
[ { "docstring": "Modifies nums in-place to its next lexicographical permutation.\nIf nums is the last permutation, sorts it to the first permutation.", "function_declaration": "def next_permutation(nums):", "function_name": "next_permutation", "parameter_list": "(nums)" }, { "docstring": "Mod...
[ 0, 0, 1, 1, 0, 1, 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 next_permutation(nums):\n \"\"\"\n Modifies nums in-place to the next lexicographical permutation.\n If it isn't possible, rearranges to the lowest possible orde...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000020022", "row_id": 20022, "seed_ids": "['1254', '2452', '69']" }
0.710817
Leetcode_20022
I
[ "next_permutation", "kth_permutation" ]
2
[ [ "kth_permutation", "next_permutation" ] ]
1
[]
false
[]
false
pytest
true
[]
true
15e9d84c01f9efeab1522d0fcbf5a3812871167e
495da7eb1d64ee7bd25477316ed225eb9bb56135
v1.0
instruct
Leetcode
Leetcode_20249_I
Given two integers `x` and `y`, where `x <= y`, return an array of all the prime numbers between `x` and `y` (inclusive). A number is a prime number if it is greater than 1 and cannot be formed by multiplying two smaller natural numbers.
def is_prime(n): """ Helper function to check if a number is prime. """ if n <= 1: return False elif n <= 3: return True elif 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 primes_between def test_primes_within_small_range(): assert primes_between(2, 11) == [2, 3, 5, 7, 11] def test_primes_within_single_number_prime(): assert primes_between(5, 5) == [5] def test_primes_within_single_number_not_prime(): assert primes_between(4, 4) == [] def test_primes_...
[ { "docstring": "Helper function to check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns an array of all prime numbers between x and y (inclusive).", "function_declaration": "def primes_be...
[ 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 if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n return False\n p = 3\n while p * p <= n:\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000020249", "row_id": 20249, "seed_ids": "['2427', '2476', '1952']" }
0.735488
Leetcode_20249
I
[ "is_prime", "primes_between" ]
2
[ [ "primes_between", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0f4793d65191f0269b6f6af80ece1bdb03cfc57d
72a6dece95e54995f8fd48aefbc495eb6360f8fc
v1.0
instruct
Leetcode
Leetcode_20442_I
You are given `n` cities connected by `m` roads. Each road connects two different cities and has an associated travel cost. Your task is to ensure that every city can be reached from any other city and to minimize the total travel cost. Write a function that, given `n`, `m`, and an array `roads` where `roads[i] = [cit...
def find(parent, i): if parent[i] == i: return i else: return find(parent, parent[i]) def union(parent, rank, xroot, yroot): if rank[xroot] < rank[yroot]: parent[xroot] = yroot elif rank[xroot] > rank[yroot]: parent[yroot] = xroot else: parent[yroot] = xroot ...
from solution import minimum_travel_cost def test_minimum_travel_cost_simple(): n = 4 m = 5 roads = [ [0, 1, 10], [0, 2, 6], [0, 3, 5], [1, 3, 15], [2, 3, 4] ] assert minimum_travel_cost(n, m, roads) == 19 def test_minimum_travel_cost_not_connected(): n ...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, xroot, yroot):", "function_name": "union", "parameter_list": "(parent, rank, xroo...
[ 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 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": "", "prompt_id": "0000020442", "row_id": 20442, "seed_ids": "['1223', '631', '1866']" }
0.787277
Leetcode_20442
I
[ "find", "union", "minimum_travel_cost" ]
3
[ [ "minimum_travel_cost", "find" ], [ "minimum_travel_cost", "union" ] ]
2
[]
false
[]
false
pytest
true
[]
true
673c46955591cc57039e1d7eb6b1ba7ec32dbf23
f991076ed5a2b6378fcdcbb151cf9513606ea01c
v1.0
instruct
Leetcode
Leetcode_20455_I
You are given a binary tree root structure. A **pseudo-palindromic path** in a binary tree is a path that starts at the root node and ends at any leaf node where it is possible to rearrange the node values to form a palindrome. Return _the number of pseudo-palindromic paths_ in the tree. Each node in the tree contains ...
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def is_pseudo_palindromic(counts): odd_count = sum(1 for count in counts.values() if count % 2 != 0) return odd_count <= 1 def pseudo_palindromic_paths(root): f...
from solution import TreeNode, pseudo_palindromic_paths def test_single_node_tree(): root = TreeNode(1) assert pseudo_palindromic_paths(root) == 1 def test_all_nodes_same_value(): root = TreeNode(2, TreeNode(2), TreeNode(2)) assert pseudo_palindromic_paths(root) == 2 def test_simple_tree(): root ...
[]
[ 0, 0, 0, 0, 1, 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": "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\n\ndef pseudoPalindromi...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "0000020455", "row_id": 20455, "seed_ids": "['1542', '1239', '1742']" }
0.653954
Leetcode_20455
I
[ "is_pseudo_palindromic", "pseudo_palindromic_paths" ]
2
[ [ "pseudo_palindromic_paths", "is_pseudo_palindromic" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
f526371bcccd63d1333ea144eb451c49f4ba9bbf
5257ecd60cbb1e4adc0635df88e6952d50213b46
v1.0
instruct
Leetcode
Leetcode_20639_I
You are given an `s` consisting of lowercase Latin letters and an integer `limit`. Your task is to partition `s` into as few parts as possible so that the length of each part is at most `limit` and each part is a palindrome. Return the minimum number of parts you need to partition `s`.
def is_palindrome(s): return s == s[::-1] def min_partitions(s, limit): n = len(s) # dp[i] indicates the minimum number of palindrome partitions until index i. dp = [float('inf')] * (n + 1) dp[0] = 0 for i in range(1, n + 1): for j in range(i): if i - j <= limit and is_...
from solution import min_partitions, is_palindrome def test_is_palindrome(): assert is_palindrome("abccba") == True assert is_palindrome("abcd") == False assert is_palindrome("a") == True assert is_palindrome("ab") == False def test_min_partitions(): assert min_partitions("abccba", 6) == 1 ass...
[ { "docstring": null, "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": null, "function_declaration": "def min_partitions(s, limit):", "function_name": "min_partitions", "parameter_list": "(s, limit)" } ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 1, 1 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def min_palindrome_partitions(s, limit):\n n = len(s)\n \n # Function to check if a substring is a palindrome\n def is_palindrome(i, j):\n while i < j:\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000020639", "row_id": 20639, "seed_ids": "['1121', '843', '1589']" }
0.740653
Leetcode_20639
I
[ "is_palindrome", "min_partitions" ]
2
[ [ "min_partitions", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1217b240e0b1da10d4f8cbcd7833d6dfcd944b25
88be7626cbaa3f8374255325088f106246918740
v1.0
instruct
Leetcode
Leetcode_20658_I
You are given a `tree` represented as an adjacency list. Each node has a unique value corresponding to the adjacency list index. The distance between two nodes in the tree is defined as the minimum number of edges that must be traversed to get from one node to the other. Write a function that takes the adjacency list o...
from collections import deque def bfs(tree, start): """ Perform Breadth First Search (BFS) to find the farthest node and its distance from the start node """ visited = [-1] * len(tree) queue = deque([(start, 0)]) visited[start] = 0 farthest_node = start max_distance = 0 while q...
from solution import tree_diameter def test_basic_tree(): tree = [ [1, 2], # connections for node 0 [0, 3, 4], # connections for node 1 [0], # connections for node 2 [1], # connections for node 3 [1] # connections for node 4 ] assert tree_diameter(tree) == 3 d...
[ { "docstring": "Perform Breadth First Search (BFS) to find the farthest node and its distance from the start node", "function_declaration": "def bfs(tree, start):", "function_name": "bfs", "parameter_list": "(tree, start)" }, { "docstring": "Finds the diameter of the tree using two BFS passe...
[ 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 tree_diameter(adj):\n \"\"\"\n Returns the diameter of the tree, which is the maximum distance between any two nodes.\n \n Parameters:\n adj (list[list[int...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "0000020658", "row_id": 20658, "seed_ids": "['1153', '2501', '2459']" }
0.669205
Leetcode_20658
I
[ "bfs", "tree_diameter" ]
2
[ [ "tree_diameter", "bfs" ] ]
1
[]
false
[]
false
pytest
true
[]
true
663c736cff12d8543ef9e6b7e955cf24a156ac7d
7fc8b408077586fc1246da56eb914806855f8583
v1.0
instruct
Leetcode
Leetcode_20726_I
You are given a string `s` consisting only of lower-case English letters. You need to perform the following operation repeatedly until the string becomes empty: * Find the length of the longest prefix which is a palindrome. * Remove this prefix from the string. Return the number of operations required to make th...
def is_palindrome(s): """ Helper function to check if a string 's' is a palindrome. """ return s == s[::-1] def remove_prefix_operations(s): """ Returns the number of operations required to make the string empty by repeatedly removing the longest prefix which is a palindrome. """ op...
from solution import remove_prefix_operations def test_remove_prefix_operations_simple(): assert remove_prefix_operations("ababa") == 1 def test_remove_prefix_operations_tricky(): assert remove_prefix_operations("aabaaa") == 2 def test_remove_prefix_operations_no_palindromes(): assert remove_prefix_opera...
[ { "docstring": "Helper function to check if a string 's' is a palindrome.", "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": "Returns the number of operations required to make the string empty by repeatedly removing\...
[ 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 count_operations_to_empty_string(s):\n def is_palindrome(p):\n return p == p[::-1]\n \n def longest_palindromic_prefix_length(s):\n for length in r...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "0000020726", "row_id": 20726, "seed_ids": "['1904', '2094', '1827']" }
0.804395
Leetcode_20726
I
[ "is_palindrome", "remove_prefix_operations" ]
2
[ [ "remove_prefix_operations", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6837f5ad44b0611a5c0ba3cfb9ced0fd08f29400
52156e31cdba06ce81ded963b334450462db5e54
v1.0
instruct
Leetcode
Leetcode_20950_I
Given a string `s` containing only digits, return the sum of all possible odd length palindromic sub-strings in `s`. A **sub-string** is a contiguous sequence of characters within a string and a **palindromic sub-string** reads the same forwards and backwards.
def is_palindrome(s): """ Check if the given string is palindrome. """ return s == s[::-1] def sum_odd_length_palindromic_substrings(s): """ Given a string `s` containing only digits, return the sum of all possible odd length palindromic substrings in `s`. """ total_sum = 0 n = ...
from solution import sum_odd_length_palindromic_substrings def test_single_digit(): assert sum_odd_length_palindromic_substrings("5") == 5 assert sum_odd_length_palindromic_substrings("0") == 0 def test_two_same_digits(): assert sum_odd_length_palindromic_substrings("22") == 2 + 2 # both individual digit...
[ { "docstring": "Check if the given string is palindrome.", "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": "Given a string `s` containing only digits, return the sum of all possible odd length\npalindromic substring...
[ 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(s):\n return s == s[::-1]\n\ndef sum_of_odd_length_palindromes(s):\n n = len(s)\n total_sum = 0\n\n for i in range(n):\n for length in ra...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "0000020950", "row_id": 20950, "seed_ids": "['2217', '22', '419']" }
0.720979
Leetcode_20950
I
[ "is_palindrome", "sum_odd_length_palindromic_substrings" ]
2
[ [ "sum_odd_length_palindromic_substrings", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
934db092c253db633b3778de0af381f588ef1de6
8a2f4382be232ad0ad925abd73c86e06e9f069bb
v1.0
instruct
Leetcode
Leetcode_20983_I
Given an array of integers `arr` and an integer `k`, your task is to distribute all elements in `arr` into `k` buckets such that the total sum of elements in the bucket with the maximum sum is minimized. Return the minimized maximum bucket sum. Note that each element in `arr` must be assigned to exactly one of the `k` ...
def canDistribute(arr, k, max_sum): current_sum = 0 bucket_count = 1 for num in arr: if current_sum + num <= max_sum: current_sum += num else: bucket_count += 1 current_sum = num if bucket_count > k: return False return...
from solution import minimizeMaxBucketSum def test_single_element(): assert minimizeMaxBucketSum([10], 1) == 10 def test_two_elements_two_buckets(): assert minimizeMaxBucketSum([10, 20], 2) == 20 def test_two_elements_one_bucket(): assert minimizeMaxBucketSum([10, 20], 1) == 30 def test_multiple_element...
[ { "docstring": null, "function_declaration": "def canDistribute(arr, k, max_sum):", "function_name": "canDistribute", "parameter_list": "(arr, k, max_sum)" }, { "docstring": null, "function_declaration": "def minimizeMaxBucketSum(arr, k):", "function_name": "minimizeMaxBucketSum", ...
[ 0, 0, 0, 1, 1, 1, 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": "def canDistribute(arr, k, maxSum):\n current_sum = 0\n count = 1\n for num in arr:\n if current_sum + num <= maxSum:\n current_sum += num\n ...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "0000020983", "row_id": 20983, "seed_ids": "['2208', '860', '290']" }
0.648641
Leetcode_20983
I
[ "canDistribute", "minimizeMaxBucketSum" ]
2
[ [ "minimizeMaxBucketSum", "canDistribute" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f75d4450afc6d77c8b683f5908609af5e97c4c94
c0771171a84f058d4fd67a2a3b63c3de2d49309e
v1.0
instruct
Leetcode
Leetcode_21067_I
You are given a binary tree with `n` nodes, where each node is labeled from `1` to `n`. The tree is rooted at node `1`, and you are provided with an edge list representation of the tree. Each edge is represented as a tuple `(u, v)` indicating that node `u` is connected to node `v`. Write a function to determine if the ...
class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None def create_tree_from_edges(n, edges): from collections import defaultdict, deque if not edges: return TreeNode(1) if n == 1 else None children = defaultdict(list) for u, ...
from solution import tree_is_balanced def test_null_tree(): assert tree_is_balanced(0, []) == True def test_single_node_tree(): assert tree_is_balanced(1, []) == True def test_balanced_tree(): assert tree_is_balanced(3, [(1, 2), (1, 3)]) == True def test_unbalanced_tree(): assert tree_is_balanced(3,...
[]
[ 1, 0, 0, 0, 1, 1, 1, 1, 1, 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, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n \ndef build_tree...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000021067", "row_id": 21067, "seed_ids": "['576', '984', '2461']" }
0.834758
Leetcode_21067
I
[ "create_tree_from_edges", "is_balanced", "tree_is_balanced" ]
3
[ [ "tree_is_balanced", "create_tree_from_edges" ], [ "tree_is_balanced", "is_balanced" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
b520f121de76db455a6d1dde59f0338b7722b811
bbbde5099e81bdeb0e7a2377234ba892a1db1f2c
v1.0
instruct
Leetcode
Leetcode_21458_I
You are given an initial **undirected graph** represented by an array of edges `edges`, where `edges[i] = [ai, bi]` indicates an edge between nodes `ai` and `bi`. The initial graph might not be connected and can have multiple components. Your task is to determine the **minimum number of edges** you must add to make the...
def find(parent, i): if parent[i] == -1: return i return find(parent, parent[i]) def union(parent, x, y): xset = find(parent, x) yset = find(parent, y) if xset != yset: parent[xset] = yset def min_edges_to_connect_graph(n, edges): """ Calculate the minimum number of edges r...
def test_min_edges_to_connect_graph(): assert min_edges_to_connect_graph(5, [[0, 1], [1, 2], [3, 4]]) == 1 assert min_edges_to_connect_graph(4, [[0, 1], [2, 3]]) == 1 assert min_edges_to_connect_graph(3, [[0, 1]]) == 1 assert min_edges_to_connect_graph(7, [[0, 1], [1, 2], [2, 3], [4, 5]]) == 2 # Whe...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, x, y):", "function_name": "union", "parameter_list": "(parent, x, y)" }, { "doc...
[ 1, 1, 1, 1, 1, 1, 0, 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 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 xroot = find(parent, ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000021458", "row_id": 21458, "seed_ids": "['1518', '971', '850']" }
0.640961
Leetcode_21458
I
[ "find", "union", "min_edges_to_connect_graph" ]
3
[ [ "min_edges_to_connect_graph", "find" ], [ "min_edges_to_connect_graph", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
false
[]
true
c6396ed534b6333dfa182790b58ba01bd5eac1e0
0658a31a63e9aecebcb34c51f1cb8d6043b93ab1
v1.0
instruct
Leetcode
Leetcode_21470_I
A **happy number** is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number equals 1, or it loops endlessly in a cycle that does not include 1. Those numbers for which this process ends in 1 are ...
def is_happy(n): """ Determines if a number n is a happy number. """ def get_next(number): total_sum = 0 while number > 0: number, digit = divmod(number, 10) total_sum += digit ** 2 return total_sum seen = set() while n != 1 and n not in seen:...
from solution import find_happy_numbers def test_find_happy_numbers_up_to_10(): assert find_happy_numbers(10) == [1, 7, 10] def test_find_happy_numbers_up_to_20(): assert find_happy_numbers(20) == [1, 7, 10, 13, 19] def test_find_happy_numbers_up_to_50(): assert find_happy_numbers(50) == [1, 7, 10, 13, 1...
[ { "docstring": "Determines if a number n is a happy number.", "function_declaration": "def is_happy(n):", "function_name": "is_happy", "parameter_list": "(n)" }, { "docstring": "Returns a list of all happy numbers in the inclusive range [1, n].", "function_declaration": "def find_happy_n...
[ 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": "def is_happy(n):\n \"\"\"\n Helper function that checks if a number is a happy number.\n \"\"\"\n seen = set()\n while n != 1 and n not in seen:\n seen....
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000021470", "row_id": 21470, "seed_ids": "['2081', '1088', '257']" }
0.5194
Leetcode_21470
I
[ "is_happy", "find_happy_numbers" ]
2
[ [ "find_happy_numbers", "is_happy" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6b12ace08946aabab760f6bea37a50e1fb82a8a7
66b3839c24d5b22316d908d165c3906d8595fef9
v1.0
instruct
Leetcode
Leetcode_21516_I
You are given a string `s` and an integer `k`. You need to partition the string into `k` contiguous substrings such that the highest frequency of any character across all substrings is minimized. Return the minimized highest frequency of any character across all substrings. For example, if `s = "aabbcc"` and `k = 2`, y...
def can_partition(s, k, max_freq): # Helper function to determine if `s` can be partitioned into `k` parts with the highest frequency <= max_freq current_count = 0 current_freq = {} for char in s: if char in current_freq: current_freq[char] += 1 else: current...
from solution import minimized_highest_frequency def test_partition_string(): assert minimized_highest_frequency("aabbcc", 2) == 2 assert minimized_highest_frequency("aabbcc", 3) == 2 assert minimized_highest_frequency("aaaabbbbcccc", 3) == 4 assert minimized_highest_frequency("aabcc", 2) == 2 asse...
[ { "docstring": null, "function_declaration": "def can_partition(s, k, max_freq):", "function_name": "can_partition", "parameter_list": "(s, k, max_freq)" }, { "docstring": "Returns the minimized highest frequency of any character across all k substrings.", "function_declaration": "def mi...
[ 1, 0, 1, 1, 1, 0, 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": "from collections import Counter\n\ndef can_partition(s, k, max_freq):\n \"\"\"\n Helper function to determine if we can partition the string such that\n no substring...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "0000021516", "row_id": 21516, "seed_ids": "['14', '2105', '589']" }
0.699499
Leetcode_21516
I
[ "can_partition", "minimized_highest_frequency" ]
2
[ [ "minimized_highest_frequency", "can_partition" ] ]
1
[]
false
[]
false
pytest
true
[]
true
313f25974661290e0d1ddd7b0642d46076b88a4b
a45442494393e7c608fa90edba90f83d5da9a0a8
v1.0
instruct
Leetcode
Leetcode_21558_I
Suppose you are given a positive integer `n`. Your task is to determine the smallest positive integer that is evenly divisible by all the integers from `1` to `n`. Formally, you need to find the least common multiple (LCM) of the first `n` natural numbers. Implement a function `int smallestMultiple(int n)` that returns...
from math import gcd def lcm(a, b): """ Computes the least common multiple of a and b. """ return a * b // gcd(a, b) def smallestMultiple(n): """ Returns the smallest positive integer that is evenly divisible by all integers from 1 to n. """ multiple = 1 for i in range(2, n + 1): ...
from solution import smallestMultiple def test_smallest_multiple_1(): assert smallestMultiple(1) == 1 def test_smallest_multiple_2(): assert smallestMultiple(2) == 2 def test_smallest_multiple_3(): assert smallestMultiple(3) == 6 def test_smallest_multiple_4(): assert smallestMultiple(4) == 12 def ...
[ { "docstring": "Computes the least common multiple of a and b.", "function_declaration": "def lcm(a, b):", "function_name": "lcm", "parameter_list": "(a, b)" }, { "docstring": "Returns the smallest positive integer that is evenly divisible by all integers from 1 to n.", "function_declara...
[ 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": "from math import gcd\n\ndef smallestMultiple(n):\n \"\"\"\n Returns the smallest positive integer that is evenly divisible by all integers from 1 to n.\n \"\"\"\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000021558", "row_id": 21558, "seed_ids": "['901', '970', '2375']" }
0.663179
Leetcode_21558
I
[ "lcm", "smallestMultiple" ]
2
[ [ "smallestMultiple", "lcm" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ac2cc5b88352d18be898f3d538d5f3d49a5034a0
71d8b74dc28b975d47aa68f3aca2164f63780ba3
v1.0
instruct
Leetcode
Leetcode_21641_I
A conveyor belt has packages that must be shipped from one location to another within a certain timeframe. Each package has a weight represented by an integer array `weights`, where `weights[i]` denotes the weight of the `i-th` package. A conveyor belt has a weight limit represented by an integer `capacity`. It can onl...
def can_ship(weights, days, capacity): current_weight = 0 current_days = 1 for weight in weights: if current_weight + weight > capacity: current_days += 1 current_weight = 0 if current_days > days: return False current_weight += weight return...
from solution import ship_within_days def test_single_day(): assert ship_within_days([1, 2, 3, 4, 5], 1) == 15 def test_two_days(): assert ship_within_days([1, 2, 3, 4, 5], 2) == 9 def test_three_days(): assert ship_within_days([1, 2, 3, 4, 5], 3) == 6 def test_multiple_packages_single_day(): assert...
[ { "docstring": null, "function_declaration": "def can_ship(weights, days, capacity):", "function_name": "can_ship", "parameter_list": "(weights, days, capacity)" }, { "docstring": null, "function_declaration": "def ship_within_days(weights, days):", "function_name": "ship_within_days...
[ 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 shipWithinDays(weights, capacity):\n \"\"\"\n Returns the minimum number of days required to ship all packages within the given capacity.\n \n :param weights:...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "0000021641", "row_id": 21641, "seed_ids": "['1612', '874', '2305']" }
0.668006
Leetcode_21641
I
[ "can_ship", "ship_within_days" ]
2
[ [ "ship_within_days", "can_ship" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b745b893e91b3a9bf5102e520633a0d4704a2a52
35792ddadfccd4bed5f12eaa99f75dc172f8ccca
v1.0
instruct
Leetcode
Leetcode_21840_I
Write a function that finds the difference between the largest and smallest values in a binary search tree (BST). The BST is represented by its root node, and each node contains an integer value. Your function should return the difference as an integer. Note: A binary search tree (BST) is a node-based binary tree where...
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def find_min(node): current = node while current.left is not None: current = current.left return current.val def find_max(node): current = node w...
from solution import TreeNode, find_difference_bst def test_single_node_tree(): root = TreeNode(10) assert find_difference_bst(root) == 0 def test_left_heavy_tree(): root = TreeNode(20) root.left = TreeNode(10) root.left.left = TreeNode(5) assert find_difference_bst(root) == 15 def test_right...
[]
[ 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 find_max_min_diffe...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000021840", "row_id": 21840, "seed_ids": "['1403', '1017', '429']" }
0.593237
Leetcode_21840
I
[ "find_min", "find_max", "find_difference_bst" ]
3
[ [ "find_difference_bst", "find_max" ], [ "find_difference_bst", "find_min" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
0a58601bc36e09ef3efb77fed3025afd54710e19
831f9925115281ada2efe35253af47084adb05dc
v1.0
instruct
Leetcode
Leetcode_21935_I
You are given a **0-indexed** array of integers `arr`. An integer `x` is said to be **special** if the sum of its digits is equal to `x` modulo `10`. For instance, `29` is special because the sum of its digits `2 + 9` is `11`, and `29 % 10` is `9` – they are not equal. If an integer is **not** special, it is considered...
def sum_of_digits(n): """Helper function to return the sum of digits of a given number.""" return sum(int(digit) for digit in str(abs(n))) def is_special(x): """Function to determine if a number x is special.""" return sum_of_digits(x) == x % 10 def partition_array(arr): """ Function to partit...
from solution import partition_array def test_partition_array_equal_special_and_ordinary(): assert partition_array([12, 5, 9, 10]) == [[5, 12], [9, 10]] def test_partition_array_no_partitioning_possible(): assert partition_array([12, 4, 5]) == [] assert partition_array([1, 23, 5]) == [] def test_part...
[ { "docstring": "Helper function to return the sum of digits of a given number.", "function_declaration": "def sum_of_digits(n):", "function_name": "sum_of_digits", "parameter_list": "(n)" }, { "docstring": "Function to determine if a number x is special.", "function_declaration": "def is...
[ 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": "def is_special(x):\n \"\"\"\n Check if a number x is special.\n A number is special if the sum of its digits is equal to x modulo 10.\n \"\"\"\n digit_sum = su...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "0000021935", "row_id": 21935, "seed_ids": "['2157', '544', '2522']" }
0.746148
Leetcode_21935
I
[ "sum_of_digits", "is_special", "partition_array" ]
3
[ [ "is_special", "sum_of_digits" ], [ "partition_array", "is_special" ] ]
2
[]
false
[]
false
pytest
true
[]
true
33d18043665099b024f26673154bebce0b91b61c
9cde2c510fc68f615e74f7c367eb3ca8db7f97b7
v1.0
instruct
Leetcode
Leetcode_21945_I
You are given an array `numbers` consisting of non-negative integers. You need to form the largest possible number by concatenating the integers together. Return the resulting largest number as a string. Note: The result may be very large, so you should return a string representation of the number.
from functools import cmp_to_key def custom_compare(x, y): """ Custom comparator to compare two numbers as strings for concatenation purpose. It compares combined scenarios x+y and y+x to see which forms a larger value. """ if x + y > y + x: return -1 elif x + y < y + x: return ...
from solution import largest_number def test_single_digit_numbers(): assert largest_number([3, 30, 34, 5, 9]) == '9534330' def test_numbers_with_zeros(): assert largest_number([0, 0]) == '0' assert largest_number([10, 2]) == '210' def test_multiple_zeroes_and_others(): assert largest_number([0, 0, 1,...
[ { "docstring": "Custom comparator to compare two numbers as strings for concatenation purpose.\nIt compares combined scenarios x+y and y+x to see which forms a larger value.", "function_declaration": "def custom_compare(x, y):", "function_name": "custom_compare", "parameter_list": "(x, y)" }, { ...
[ 1, 0, 0, 1, 0, 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 largest_number(numbers):\n \"\"\"\n Given a list of non-negative integers, arrange them in such a way that\n they form the largest possible number and return it ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000021945", "row_id": 21945, "seed_ids": "['2575', '1154', '1505']" }
0.675686
Leetcode_21945
I
[ "custom_compare", "largest_number" ]
2
[ [ "largest_number", "custom_compare" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a439f146bdb1f2a0f6e14393a6d52c50bd1a0e7b
d240670b924e35d45bcabe241a3a35a6c61a0ac5
v1.0
instruct
Leetcode
Leetcode_21955_I
You are given a string `s` containing only parentheses '(' and ')'. Your task is to remove the minimum number of parentheses in any positions so that the resulting string is valid (i.e., each open parenthesis is eventually closed). Return all possible results in any order.
def remove_invalid_parentheses(s): """ Removes the minimum number of parentheses to make the string valid. Returns all possible results. """ level = {s} while True: valid = list(filter(is_valid, level)) if valid: return valid # Generate all possible states ...
from solution import remove_invalid_parentheses def test_example_1(): assert set(remove_invalid_parentheses("()())()")) == {"()()()", "(())()"} def test_example_2(): assert set(remove_invalid_parentheses("(a)())()")) == {"(a)()()", "(a())()"} def test_example_3(): assert set(remove_invalid_parentheses(")...
[ { "docstring": "Removes the minimum number of parentheses to make the string valid.\nReturns all possible results.", "function_declaration": "def remove_invalid_parentheses(s):", "function_name": "remove_invalid_parentheses", "parameter_list": "(s)" }, { "docstring": "Checks if the parenthes...
[ 1, 0, 0, 1, 1, 0, 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 remove_invalid_parentheses(s):\n def is_valid(string):\n count = 0\n for char in string:\n if char == '(':\n count += 1\n ...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "0000021955", "row_id": 21955, "seed_ids": "['1793', '1214', '2349']" }
0.740847
Leetcode_21955
I
[ "remove_invalid_parentheses", "is_valid" ]
2
[ [ "remove_invalid_parentheses", "is_valid" ] ]
1
[]
false
[]
false
pytest
true
[]
true
aae7bfb3c369020fc4fee5e7884b9230a7cf32fc
8be71ea7724884ffc70486ca47defb2592fac269
v1.0
instruct
Leetcode
Leetcode_22016_I
You are given a weighted, undirected graph with `n` vertices and an array `edges` where `edges[i] = [u, v, w]` represents an edge connecting vertices `u` and `v` with weight `w`. Your task is to compute _the weight of the minimum spanning tree_ (MST) that can be constructed from this graph. If the graph is disconnected...
def find(parent, i): if parent[i] == i: return i else: return find(parent, parent[i]) def union(parent, rank, x, y): xroot = find(parent, x) yroot = find(parent, y) if rank[xroot] < rank[yroot]: parent[xroot] = yroot elif rank[xroot] > rank[yroot]: parent[yroot]...
from solution import kruskal def test_kruskal_basic(): assert kruskal(4, [[0, 1, 10], [0, 2, 6], [0, 3, 5], [1, 3, 15], [2, 3, 4]]) == 19 def test_kruskal_disconnected(): assert kruskal(4, [[0, 1, 10], [0, 2, 6]]) == -1 def test_kruskal_single_node(): assert kruskal(1, []) == 0 def test_kruskal_already_...
[ { "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, 1, 1, 0, 1, 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(parent, i):\n if parent[i] == i:\n return i\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n rootX = find(parent, x)\n rootY =...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "0000022016", "row_id": 22016, "seed_ids": "['1494', '1306', '730']" }
0.75196
Leetcode_22016
I
[ "find", "union", "kruskal" ]
3
[ [ "kruskal", "find" ], [ "kruskal", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
true
[]
true
9f7595da8f25e868356fa470c496178090011335
17f2ed20fb2e763ffb64f58f3d3f618b387866ba
v1.0
instruct
Leetcode
Leetcode_22067_I
You are given a list of `points` where each `point[i] = [xi, yi]` represents the coordinates of a point in a 2D plane. The diameter of a circle is defined as the greatest distance between any two points on its perimeter. Find the pair of points that forms the diameter of the smallest circle that can enclose all the giv...
import itertools import math def euclidean_distance(point1, point2): """ Calculate the Euclidean distance between two points. """ return math.sqrt((point1[0] - point2[0]) ** 2 + (point1[1] - point2[1]) ** 2) def find_smallest_diameter(points): """ Find the pair of points that forms the diamete...
from solution import find_smallest_diameter def test_simple_case(): assert find_smallest_diameter([[0, 0], [0, 1], [1, 1], [1, 0]]) in [[[0, 0], [1, 1]], [[1, 1], [0, 0]], [[0, 1], [1, 0]], [[1, 0], [0, 1]]] def test_single_pair(): assert find_smallest_diameter([[1, 1], [4, 5]]) == [[1, 1], [4, 5]] def test_...
[ { "docstring": "Calculate the Euclidean distance between two points.", "function_declaration": "def euclidean_distance(point1, point2):", "function_name": "euclidean_distance", "parameter_list": "(point1, point2)" }, { "docstring": "Find the pair of points that forms the diameter of the smal...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1, 1 ]
2
hard
0.2
{ "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 distance(point1, point2):\n return math.sqrt((point1[0] - point2[0])**2 + (point1[1] - point2[1])**2)\n\ndef smalles...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000022067", "row_id": 22067, "seed_ids": "['2007', '472', '997']" }
0.551546
Leetcode_22067
I
[ "euclidean_distance", "find_smallest_diameter" ]
2
[ [ "find_smallest_diameter", "euclidean_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d7c933144440654e935bd37d7d2b6eb5bade0ad5
2f7b650f89d6c61c721936a348d9ebffaca0a389
v1.0
instruct
Leetcode
Leetcode_22102_I
Given an array of strings `words`, return the length of the longest string `w` in `words` such that `w` can be formed by concatenating other strings from the array. Each string in the array can be used multiple times in constructing `w`. If no such string exists, return `0`.
def is_composable(word, word_set): if word in word_set: return True for i in range(1, len(word)): prefix = word[:i] suffix = word[i:] if prefix in word_set and is_composable(suffix, word_set): return True return False def longest_concatenated_word(words): wor...
from solution import longest_concatenated_word def test_no_composable_words(): assert longest_concatenated_word(['cat', 'dog', 'rat']) == 0 def test_single_longest_concatenated_word(): assert longest_concatenated_word(['cat', 'dog', 'catdog']) == 6 def test_multiple_concatenated_words(): assert longest_c...
[ { "docstring": null, "function_declaration": "def is_composable(word, word_set):", "function_name": "is_composable", "parameter_list": "(word, word_set)" }, { "docstring": null, "function_declaration": "def longest_concatenated_word(words):", "function_name": "longest_concatenated_wo...
[ 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 longest_concatenated_word(words):\n def can_form(word, word_dict):\n if word in memo:\n return memo[word]\n \n for i in range(1, len(wo...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "0000022102", "row_id": 22102, "seed_ids": "['2505', '600', '290']" }
0.685248
Leetcode_22102
I
[ "is_composable", "longest_concatenated_word" ]
2
[ [ "longest_concatenated_word", "is_composable" ] ]
1
[]
false
[]
false
pytest
true
[]
true
217cdf0a956c0d8cbc428de8e951dbf1036caffd
5202fecbbfa2674e915af031756b5a21b80892f8
v1.0
instruct
Leetcode
Leetcode_22483_I
You are given a binary tree with `n` nodes, where each node contains a unique integer value. Write a function that finds the path from the root node to a given target node. The path should be represented as a list of integers, corresponding to the values of the nodes in the order they are visited. If the target node do...
class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None def array_to_bst(arr): """ Converts a list representing a binary tree in level order into a BST. """ if not arr: return None root = TreeNode(arr[0]) queue = [root] ...
from solution import find_path_in_tree def test_find_path_exists(): assert find_path_in_tree([5, 3, 8, 1, 4, 7, 10], 4) == [5, 3, 4] def test_find_path_non_existent_target(): assert find_path_in_tree([5, 3, 8, 1, 4, 7, 10], 11) == [] def test_find_path_single_element(): assert find_path_in_tree([5], 5) =...
[]
[ 1, 1, 0, 0, 1, 1, 0, 1, 1, 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 array_to_tree(array, i=0):\n if i >= len(arra...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000022483", "row_id": 22483, "seed_ids": "['2488', '1376', '138']" }
0.574439
Leetcode_22483
I
[ "array_to_bst", "find_path", "find_path_in_tree" ]
3
[ [ "find_path_in_tree", "array_to_bst" ], [ "find_path_in_tree", "find_path" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
4eac17086647da66fbb64ba38fc7e3b95c72bd53
a0792b7dc2eabd4253ed9141571e09e9b8a9b980
v1.0
instruct
Leetcode
Leetcode_22614_I
Given a string `s` and a list of words `words`, where each word is a **subsequence** of `s`, find the **shortest** word in `words` that is not a subsequence of `s`. If there are multiple shortest words with the same length, return the lexicographically smallest one. If all words in `words` are subsequences of `s`, retu...
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 shortest_non_subsequence(s, words): """ Given a string `s` and a list of words `words`, return the shortest word in `words` that is ...
from solution import is_subsequence, shortest_non_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", "abcdef") == False def test_shortest_non_...
[ { "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": "Given a string `s` and a list of words `words`, return the shortest word i...
[ 0, 0, 1, 0, 1, 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 is_subsequence(s, t):\n \"\"\"\n Helper function to determine if t is a subsequence of s.\n \"\"\"\n it = iter(s)\n return all(char in it for char in t)\n\...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "0000022614", "row_id": 22614, "seed_ids": "['1857', '1288', '223']" }
0.731039
Leetcode_22614
I
[ "is_subsequence", "shortest_non_subsequence" ]
2
[ [ "shortest_non_subsequence", "is_subsequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0748f247c5f3b6e9cad77c39d8de1cdd29ab9444
b4d92deac09825f3c4f923fa5d2e19d322d8dda2
v1.0
instruct
Leetcode
Leetcode_22617_I
You are given a **connected** weighted undirected graph with `n` nodes labeled from `0` to `n-1` and an integer `k`. Each node represents a city, and there is a direct road between certain pairs of cities, with a weight representing the distance of that road. Your task is to determine if there exist at least `k` cities...
import heapq def floyd_warshall(n, graph, threshold): # Initialize distance matrix with infinity dist = [[float('inf')] * n for _ in range(n)] # Distance from a node to itself is 0 for i in range(n): dist[i][i] = 0 # Fill in the graph edges for u, v, w in graph: dist[u...
from solution import can_find_k_cities_with_threshold def test_case_1(): n = 4 graph = [ (0, 1, 4), (0, 2, 5), (1, 2, 2), (1, 3, 1), (2, 3, 3) ] k = 3 threshold = 5 assert can_find_k_cities_with_threshold(n, graph, k, threshold) == True def test_case_2()...
[ { "docstring": null, "function_declaration": "def floyd_warshall(n, graph, threshold):", "function_name": "floyd_warshall", "parameter_list": "(n, graph, threshold)" }, { "docstring": null, "function_declaration": "def can_find_k_cities_with_threshold(n, graph, k, threshold):", "func...
[ 1, 1, 1, 0, 0, 0, 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": "import heapq\nimport collections\n\ndef does_k_cities_exist_within_distance(n, roads, k, d):\n \"\"\"\n Determines if there exist at least k cities such that each pair ...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "0000022617", "row_id": 22617, "seed_ids": "['81', '1198', '630']" }
0.650189
Leetcode_22617
I
[ "floyd_warshall", "can_find_k_cities_with_threshold" ]
2
[ [ "can_find_k_cities_with_threshold", "floyd_warshall" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a7d7cbfbffac71d99fa7dd0185bd418ae8f21696
fa025161f13086931da43ca05dd579ed6dae3666
v1.0
instruct
Leetcode
Leetcode_22685_I
You are given a **0-indexed** integer array `nums` of length `n` consisting of only `0` and `1`. You want to perform a series of operations to make all the elements in the array equal, either all `0`s or all `1`s. In one operation, you are allowed to select any subarray of length `k` (`1 <= k <= n`) and flip all the bi...
def min_operations_to_make_equal(nums, k): """ Returns the minimum number of operations required to make all elements in the array equal. If it's impossible, return -1. """ n = len(nums) if k % 2 == 0: return min_operations_even_k(nums, k, n) else: return min_operations_...
def test_min_operations_to_make_equal(): assert min_operations_to_make_equal([0, 1, 0], 2) == -1 assert min_operations_to_make_equal([0, 1, 0], 3) == 1 assert min_operations_to_make_equal([0, 0, 0], 1) == 0 assert min_operations_to_make_equal([1, 1, 1], 1) == 0 assert min_operations_to_make_equal([1...
[ { "docstring": "Returns the minimum number of operations required to make all elements in the array equal.\nIf it's impossible, return -1.", "function_declaration": "def min_operations_to_make_equal(nums, k):", "function_name": "min_operations_to_make_equal", "parameter_list": "(nums, k)" }, { ...
[ 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": "def min_operations_to_equalize(nums, k):\n \"\"\"\n Returns the minimum number of operations required to make all elements in nums equal.\n If it's impossible, retur...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "0000022685", "row_id": 22685, "seed_ids": "['1989', '1209', '2437']" }
0.813883
Leetcode_22685
I
[ "min_operations_to_make_equal", "min_operations_even_k", "min_operations_odd_k" ]
3
[ [ "min_operations_to_make_equal", "min_operations_even_k" ], [ "min_operations_to_make_equal", "min_operations_odd_k" ] ]
2
[]
false
[]
false
pytest
false
[]
true
224f338f614b39043367ac5f99397a756f3a42d6
36d68f020856f0ed295cc2a360167e81d0498d7b
v1.0
instruct
Leetcode
Leetcode_22777_I
You are given a 2D grid of characters representing a crossword puzzle and a list of words. Each cell in the grid can hold a single character, and the words in the list should all be placed on the grid. The words can only be placed horizontally or vertically, and once a word is placed, no other word can overlap any of i...
def can_place_word(board, word, row, col, direction): if direction == "horizontal": if col + len(word) > len(board[0]): return False for i in range(len(word)): if board[row][col + i] not in (' ', word[i]): return False for i in range(len(word)): ...
from solution import place_words_on_board def test_place_words_on_empty_board(): board = [[" " for _ in range(5)] for _ in range(5)] words = ["hello", "world"] assert place_words_on_board(board, words) def test_place_words_on_filled_board(): board = [[" " for _ in range(5)] for _ in range(5)] boar...
[ { "docstring": null, "function_declaration": "def can_place_word(board, word, row, col, direction):", "function_name": "can_place_word", "parameter_list": "(board, word, row, col, direction)" }, { "docstring": null, "function_declaration": "def place_words_on_board(board, words):", "...
[ 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 can_place_word_horizontal(board, word, row, col):\n if col + len(word) > len(board[0]):\n return False\n for i in range(len(word)):\n if board[row][co...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "0000022777", "row_id": 22777, "seed_ids": "['1057', '1609', '2287']" }
0.683384
Leetcode_22777
I
[ "can_place_word", "place_words_on_board" ]
2
[ [ "place_words_on_board", "can_place_word" ] ]
1
[]
false
[]
false
pytest
true
[]
true
fd44cf4d05b976e36bfc09a21b4af28e67f19f27
a2733ab51d77ee071ef7c25958c33ac5f6bc6565
v1.0
instruct
Leetcode
Leetcode_22795_I
You are given a list of integers `nums` representing a binary tree in level order traversal. Write a function to find the maximum path sum. A path in the binary tree is defined as any sequence of nodes from some starting node to any node in the tree along the parent-child connections. The path must contain at least one...
class TreeNode: def __init__(self, value=0, left=None, right=None): self.value = value self.left = left self.right = right def build_tree_from_list(nums): if not nums: return None nodes = [TreeNode(value) if value is not None else None for value in nums] for i in range(l...
from solution import max_path_sum def test_single_node_tree(): assert max_path_sum([5]) == 5 def test_complete_small_tree(): assert max_path_sum([1, 2, 3]) == 6 def test_complete_large_tree(): assert max_path_sum([-10, 9, 20, None, None, 15, 7]) == 42 def test_tree_with_negatives(): assert max_path_...
[]
[ 1, 1, 0, 0, 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": "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 build_tree_f...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "0000022795", "row_id": 22795, "seed_ids": "['1103', '408', '265']" }
0.622316
Leetcode_22795
I
[ "build_tree_from_list", "max_path_sum" ]
2
[ [ "max_path_sum", "build_tree_from_list" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
055d1d2abeee20951be0950deb5520cbcacd9482
861088f83dd66ce6ac56cc86d0d49e141c69722b
v1.0
instruct
Leetcode
Leetcode_22968_I
Given an integer `m`, generate an `m x m` magic square. A magic square is an arrangement of numbers in a square grid where the numbers in each row, each column, and both main diagonals all add up to the same number, known as the magic constant. In this particular problem, the magic square should contain the integers fr...
def is_odd_positive_integer(m): return m > 0 and m % 2 == 1 def generate_magic_square(m): """ Generates an m x m magic square for odd m. :param m: size of the magic square (must be a positive odd integer) :return: m x m list representing the magic square, or an empty list if m is not a positiv...
from solution import generate_magic_square def test_generate_magic_square_3x3(): expected = [ [8, 1, 6], [3, 5, 7], [4, 9, 2] ] assert generate_magic_square(3) == expected def test_generate_magic_square_1x1(): expected = [ [1] ] assert generate_magic_square(1) =...
[ { "docstring": null, "function_declaration": "def is_odd_positive_integer(m):", "function_name": "is_odd_positive_integer", "parameter_list": "(m)" }, { "docstring": "Generates an m x m magic square for odd m.\n\n:param m: size of the magic square (must be a positive odd integer)\n:return: m...
[ 1, 1, 0, 1, 0, 0, 1, 0, 1 ]
5
medium
0.556
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def generate_magic_square(m):\n \"\"\"\n Generates an m x m magic square.\n \n Parameters:\n m (int): The dimension of the magic square.\n \n Returns:\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000022968", "row_id": 22968, "seed_ids": "['276', '623', '1943']" }
0.702525
Leetcode_22968
I
[ "is_odd_positive_integer", "generate_magic_square" ]
2
[ [ "generate_magic_square", "is_odd_positive_integer" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a22ce4c9c4fe33a62c7a655701e41793168e2cc1
2715e019d5d57841d6843b2f4ffffdf63b645255
v1.0
instruct
Leetcode
Leetcode_22969_I
You are given a binary tree with `n` nodes numbered from `1` to `n`. Each node has a unique value representing its position in the tree. You are also given an integer array `queries` where each `queries[i]` represents the value of a node for which you need to find the sum of the values of all descendant nodes (includin...
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def node_sum(node): """ Calculate the sum of all descendant nodes' values including itself. """ if node is None: return 0 left_sum = node_sum(node...
import pytest from solution import TreeNode, find_descendant_sums def test_single_node(): root = TreeNode(1) queries = [1] assert find_descendant_sums(root, queries) == [1] def test_tree_with_two_levels(): root = TreeNode(1, TreeNode(2), TreeNode(3)) queries = [1, 2, 3] assert find_descendant_...
[]
[ 0, 0, 1, 1, 0, 1, 1, 1, 1, 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, value):\n self.value = value\n self.children = []\n\ndef build_tree(edges):\n nodes = {}\n for parent, child in ed...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000022969", "row_id": 22969, "seed_ids": "['1072', '484', '2508']" }
0.578452
Leetcode_22969
I
[ "node_sum", "find_descendant_sums" ]
2
[ [ "find_descendant_sums", "node_sum" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
7ddf9a081483975359159eb77054dfd583d0c967
47f60071fb8139137df7dee93b61996418f32793
v1.0
instruct
Leetcode
Leetcode_23085_I
You are given a list of strings `words` and a string `target`. Your goal is to determine the number of strings in `words` that can be formed by removing some characters from `target` without changing the order of remaining characters. Write a function: ```python def numMatchingSubseq(words, target) -> int: pass ``...
def is_subsequence(word, target): it = iter(target) return all(char in it for char in word) def numMatchingSubseq(words, target): """ Returns the count of words that are subsequences of target. """ return sum(1 for word in words if is_subsequence(word, target))
def test_num_matching_subseq(): assert numMatchingSubseq(["abc", "ac", "xyz"], "abxcdy") == 2 assert numMatchingSubseq(["a", "b", "c"], "abc") == 3 assert numMatchingSubseq(["abcd", "abc", "ab", "xyz"], "abc") == 2 assert numMatchingSubseq(["abc", "def"], "abcdef") == 2 assert numMatchingSubseq(["xy...
[ { "docstring": null, "function_declaration": "def is_subsequence(word, target):", "function_name": "is_subsequence", "parameter_list": "(word, target)" }, { "docstring": "Returns the count of words that are subsequences of target.", "function_declaration": "def numMatchingSubseq(words, t...
[ 1, 1, 0, 1, 0, 0, 1, 0, 1, 1 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def numMatchingSubseq(words, target) -> int:\n def is_subsequence(word, target):\n it = iter(target)\n return all(char in it for char in word)\n \n cou...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000023085", "row_id": 23085, "seed_ids": "['1352', '2556', '1839']" }
0.677934
Leetcode_23085
I
[ "is_subsequence", "numMatchingSubseq" ]
2
[ [ "numMatchingSubseq", "is_subsequence" ] ]
1
[]
false
[]
false
pytest
false
[]
true
2394cf92cd39e1275cef67162a9da0e623f7561f
a1dc944b71b2f2922ee5a87dd19773948a3f96f4
v1.0
instruct
Leetcode
Leetcode_23259_I
You are given a **positive** integer `k` and an array of `k` strings `rows`, where each string represents a word. You need to construct a k x k board such that: * Each word in `rows` corresponds to one of the rows in the board. * Each column in the board, when read from top to bottom, forms a valid English word. The ...
def is_valid_board(rows): """ Checks if the columns in the board form valid English words. Here, we will only simulate the valid check by assuming all columns are valid as words are not provided or checked against actual dictionary. """ k = len(rows) for i in range(k): column_word = ...
from solution import construct_board def test_construct_board_valid_example(): k = 3 rows = ["cat", "dog", "pig"] board = construct_board(k, rows) assert board == ["cat", "dog", "pig"] def test_construct_board_empty_case(): k = 3 rows = ["xyz", "abc", "def"] board = construct_board(k, rows...
[ { "docstring": "Checks if the columns in the board form valid English words.\nHere, we will only simulate the valid check by assuming all columns\nare valid as words are not provided or checked against actual dictionary.", "function_declaration": "def is_valid_board(rows):", "function_name": "is_valid_b...
[ 0, 0, 0, 0, 1, 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 construct_board(k, rows):\n # Validate the input\n if k != len(rows):\n return []\n for row in rows:\n if len(row) != k:\n return []\n\n...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "0000023259", "row_id": 23259, "seed_ids": "['2392', '1998', '1232']" }
0.599068
Leetcode_23259
I
[ "is_valid_board", "construct_board" ]
2
[ [ "construct_board", "is_valid_board" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0e47633ffab55fcd37ec038c0dca67ce05453f21
bf5f6ea1e95fc6a96eeca212bab5d4f9c1dd682a
v1.0
instruct
Leetcode
Leetcode_23282_I
You are given a list of `n` integers, where each integer represents the position of a town along a straight road. There are `k` postal offices to be built along the same road. The goal is to minimize the maximum distance any town has to a postal office. Return the minimum possible value of the maximum distance any town...
def can_place_offices(towns, k, max_dist): # Place the first postal office offices_count = 1 last_office = towns[0] # Traverse the towns to place the offices for town in towns: if town - last_office > max_dist: offices_count += 1 last_office = town if...
from solution import min_max_distance def test_min_max_distance_small_example(): assert min_max_distance([1, 2, 3, 4, 5], 2) == 2 def test_min_max_distance_equal_distances(): assert min_max_distance([1, 3, 5, 7, 9], 2) == 4 def test_min_max_distance_single_town(): assert min_max_distance([5], 2) == 0 de...
[ { "docstring": null, "function_declaration": "def can_place_offices(towns, k, max_dist):", "function_name": "can_place_offices", "parameter_list": "(towns, k, max_dist)" }, { "docstring": null, "function_declaration": "def min_max_distance(towns, k):", "function_name": "min_max_dista...
[ 0, 0, 0, 0, 0, 0, 0, 1, 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_max_distance(towns, k):\n \"\"\"\n Returns the minimum possible value of the maximum distance any town has to a postal office.\n \n :param towns: List of ...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "0000023282", "row_id": 23282, "seed_ids": "['946', '521', '1182']" }
0.669075
Leetcode_23282
I
[ "can_place_offices", "min_max_distance" ]
2
[ [ "min_max_distance", "can_place_offices" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b1a7c62292199ccc5b8d507ff4583aa0883556c1
12c5235936ca8d66f90b0aaaf63c27a2ac3e0ed4
v1.0
instruct
Leetcode
Leetcode_23505_I
You are given a list of strings `words`. Each string S in `words` is composed of lowercase English letters. We'll call a string S a "valid prefix palindrome" if it can be split into two parts (that may be empty), where the first part is a palindrome and the second part is any remaining portion of the string. For each s...
def is_palindrome(s): """ Helper function to check if a given string is a palindrome. """ return s == s[::-1] def longest_valid_prefix_palindrome(words): """ For each word in the list, find the length of the longest valid prefix palindrome. """ result = [] for word in words: ...
from solution import longest_valid_prefix_palindrome def test_single_palindrome(): words = ["abba"] assert longest_valid_prefix_palindrome(words) == [4] def test_no_palindrome(): words = ["abc"] assert longest_valid_prefix_palindrome(words) == [1] def test_empty_string(): words = [""] assert ...
[ { "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": "For each word in the list, find the length of the longest valid prefix palindrome.", ...
[ 0, 0, 0, 0, 1, 0, 0, 0, 1, 1 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_palindrome(s):\n \"\"\"\n Returns True if the string s is a palindrome, else False.\n \"\"\"\n return s == s[::-1]\n\ndef longest_valid_prefix_palindrome(w...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000023505", "row_id": 23505, "seed_ids": "['2509', '1044', '1725']" }
0.782181
Leetcode_23505
I
[ "is_palindrome", "longest_valid_prefix_palindrome" ]
2
[ [ "longest_valid_prefix_palindrome", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
aed31f073aed7ed1c55ed40105af2c3bf258187c
e361a93a0a9517b5926c61dc103fdc81bc86b805
v1.0
instruct
Leetcode
Leetcode_23567_I
You are given a `words` array containing strings of equal length `n`. Two words are considered **similar** if they differ by at most two characters. Find the largest group of similar words in the array. Return the size of this largest group. Note that for a pair of words to be considered similar, their difference in c...
from collections import deque def differByAtMostTwo(word1, word2): """ Return True if words differ by at most 2 characters. """ diff_count = 0 for c1, c2 in zip(word1, word2): if c1 != c2: diff_count += 1 if diff_count > 2: return False return True def b...
from solution import largestSimilarWordsGroup def test_empty_list(): assert largestSimilarWordsGroup([]) == 0 def test_single_word(): assert largestSimilarWordsGroup(["hello"]) == 1 def test_all_similar(): assert largestSimilarWordsGroup(["abcd", "abcf", "abff", "abce"]) == 4 def test_two_groups(): ...
[ { "docstring": "Return True if words differ by at most 2 characters.", "function_declaration": "def differByAtMostTwo(word1, word2):", "function_name": "differByAtMostTwo", "parameter_list": "(word1, word2)" }, { "docstring": "Perform BFS to find the size of the connected component of simila...
[ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def largest_group_of_similar_words(words):\n \"\"\"\n Returns the size of the largest group of similar words in the given list of words.\n \n A word is similar to...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "0000023567", "row_id": 23567, "seed_ids": "['1066', '2464', '1688']" }
0.678628
Leetcode_23567
I
[ "differByAtMostTwo", "bfs", "largestSimilarWordsGroup" ]
3
[ [ "bfs", "differByAtMostTwo" ], [ "largestSimilarWordsGroup", "bfs" ] ]
2
[]
false
[]
false
pytest
true
[]
true
5bda1b8f1c5dcd9556b32c4f996c8398fcf7604b
3694dbe81c7f20af87fba1642ca3ca70bef44975
v1.0
instruct
Leetcode
Leetcode_23590_I
Given an m x n binary matrix `grid`, return the maximum length of a contiguous subarray with an equal number of 1s and 0s in each row of the matrix. The subarray must consist of an entire row or part of a row, and the elements of the subarray must be contiguous. Return the length of the longest such subarray for each r...
def findMaxLength(nums): max_len = 0 count = 0 count_map = {0: -1} for i, num in enumerate(nums): count += 1 if num == 1 else -1 if count in count_map: max_len = max(max_len, i - count_map[count]) else: count_map[count] = i return max_len...
from solution import findMaxLengthInMatrix def test_single_row_all_zeros_and_ones(): grid = [[0, 0, 1, 1]] assert findMaxLengthInMatrix(grid) == [4] def test_single_row_no_subarray(): grid = [[1, 1, 1, 1]] assert findMaxLengthInMatrix(grid) == [0] def test_multiple_rows(): grid = [ [0, 1,...
[ { "docstring": null, "function_declaration": "def findMaxLength(nums):", "function_name": "findMaxLength", "parameter_list": "(nums)" }, { "docstring": null, "function_declaration": "def findMaxLengthInMatrix(grid):", "function_name": "findMaxLengthInMatrix", "parameter_list": "(...
[ 1, 1, 0, 1, 1, 1, 1, 1, 1 ]
8
easy
0.889
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def find_max_length_of_contiguous_subarray(grid):\n \"\"\"\n Given an m x n binary matrix grid, returns an array where each element represents\n the maximum length o...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000023590", "row_id": 23590, "seed_ids": "['1828', '83', '2296']" }
0.626784
Leetcode_23590
I
[ "findMaxLength", "findMaxLengthInMatrix" ]
2
[ [ "findMaxLengthInMatrix", "findMaxLength" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ccaa7f88131d6c99778998d5796129606f3a55f5
a063eb694b46a30fa8d2227a23f3463d7efeb799
v1.0
instruct
Leetcode
Leetcode_23661_I
Given `n` pairs of coordinates `(x[i], y[i])`, determine if there exists a straight line that passes through at least three of these points. If such a line exists, identify the triplet of points that lie on that straight line and return their indices (0-indexed) as a tuple `(i, j, k)`. Otherwise, return `None`. (Note:...
from itertools import combinations def collinear(p1, p2, p3): """ Check if points p1, p2, and p3 are collinear. Points are collinear if the area of the triangle they form is zero. The area can be calculated using the determinant of a 3x3 matrix formed by the points. """ (x1, y1), (x2, y2), ...
from solution import find_triplet def test_find_triplet_no_collinear(): points = [(0, 0), (1, 1), (2, 3), (4, 5)] assert find_triplet(points) == None def test_find_triplet_collinear_points(): points = [(0, 0), (1, 1), (2, 2), (-1, -1)] assert find_triplet(points) in [(0, 1, 2), (0, 1, 3), (0, 2, 3), (...
[ { "docstring": "Check if points p1, p2, and p3 are collinear.\nPoints are collinear if the area of the triangle they form is zero.\nThe area can be calculated using the determinant of a 3x3 matrix\nformed by the points.", "function_declaration": "def collinear(p1, p2, p3):", "function_name": "collinear"...
[ 0, 1, 0, 1, 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 points_on_same_line(points):\n \"\"\"\n Determine if there exists a straight line passing through at least three given points.\n \n Args:\n points (list of...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000023661", "row_id": 23661, "seed_ids": "['1997', '233', '899']" }
0.687143
Leetcode_23661
I
[ "collinear", "find_triplet" ]
2
[ [ "find_triplet", "collinear" ] ]
1
[]
false
[]
false
pytest
true
[]
true
223f53e4f362ac1b427418bdce0c2c93bbda2eb8
7cb6ee32477265882094488b38efa79b8a145e9d
v1.0
instruct
Leetcode
Leetcode_23718_I
You are given an array of strings `words` and a string `target`. Each word in `words` can be formed by a sequence of insertions (possibly zero) made to `target`. Return the length of the longest word in `words` that can be formed by inserting some characters into `target` without changing the order of the existing char...
def is_subsequence(target, word): it = iter(target) return all(char in it for char in word) def longest_valid_word(words, target): """ Returns the length of the longest word in words that can be formed by inserting characters into target without changing the order of target. """ longest_len...
from solution import longest_valid_word def test_longest_valid_word(): words = ["ale", "apple", "monkey", "plea"] target = "abpcplea" assert longest_valid_word(words, target) == 5 def test_no_valid_word(): words = ["x", "y", "z"] target = "abc" assert longest_valid_word(words, target) == 0 de...
[ { "docstring": null, "function_declaration": "def is_subsequence(target, word):", "function_name": "is_subsequence", "parameter_list": "(target, word)" }, { "docstring": "Returns the length of the longest word in words that can be formed\nby inserting characters into target without changing ...
[ 0, 0, 1, 0, 1, 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 is_subsequence(target, word):\n it = iter(target)\n return all(char in it for char in word)\n\ndef longest_word(words, target):\n valid_words = [word for word in...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "0000023718", "row_id": 23718, "seed_ids": "['2537', '1277', '2271']" }
0.724179
Leetcode_23718
I
[ "is_subsequence", "longest_valid_word" ]
2
[ [ "longest_valid_word", "is_subsequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f87766b8fb8f9c82ad21758517582ea9b7813aaf
b23ed5f76be70d6029eb31dc48a047fd5357d167
v1.0
instruct
Leetcode
Leetcode_23739_I
You are given a string `s` and an integer `k`. Your task is to partition the string into as many parts as possible so that each part is a palindrome and each part has a length of at least `k`. Return the list of partitions in the order they appear in the string. If it's not possible to partition the string in such a wa...
def is_palindrome(s): """ Checks if a given string is a palindrome. """ return s == s[::-1] def partition_palindromes(s, k): """ Partitions the given string s into as many parts as possible such that each part is a palindrome and each part has a length of at least k. Returns the list of...
from solution import partition_palindromes def test_partition_palindromes_example1(): assert partition_palindromes("racecarannakayak", 3) == ["racecar", "anna", "kayak"] def test_partition_palindromes_example2(): assert partition_palindromes("racecarannakayak", 5) == [] def test_partition_palindromes_single_...
[ { "docstring": "Checks if a given string is a palindrome.", "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": "Partitions the given string s into as many parts as possible such that\neach part is a palindrome and each...
[ 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 is_palindrome(s):\n \"\"\"\n Checks if a given string is a palindrome.\n \"\"\"\n return s == s[::-1]\n\ndef partition_palindromes(s, k):\n \"\"\"\n Par...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "0000023739", "row_id": 23739, "seed_ids": "['2363', '2487', '313']" }
0.756295
Leetcode_23739
I
[ "is_palindrome", "partition_palindromes" ]
2
[ [ "partition_palindromes", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9f69af108c4e6aa488f4dc726f54dc42f1cb6268
290e3bdc02f4d78a99f0b54805d27bb216e2e95c
v1.0
instruct
Leetcode
Leetcode_23753_I
You are given a grid of numbers represented as a 2D array `grid`, with `n` rows and `m` columns. Your task is to find the largest sum of any rectangular subgrid within `grid`. The subgrid must be non-empty and contiguous. Return the maximum sum of any such subgrid.
def max_sum_subgrid(grid): """ Returns the maximum sum of any subgrid in the given 2D grid. Args: grid (list of list of int): 2D list representing the grid. Returns: int: The maximum sum of any rectangular subgrid within the given grid. """ if not grid or not grid[0]: r...
from solution import max_sum_subgrid def test_example_grid(): grid = [ [1, -2, 3], [-1, 2, -1], [3, -2, 1] ] assert max_sum_subgrid(grid) == 4 # [1, -2, 3] def test_all_positive_grid(): grid = [ [1, 2], [3, 4] ] assert max_sum_subgrid(grid) == 10 #...
[ { "docstring": "Returns the maximum sum of any subgrid in the given 2D grid.\n\nArgs:\ngrid (list of list of int): 2D list representing the grid.\n\nReturns:\nint: The maximum sum of any rectangular subgrid within the given grid.", "function_declaration": "def max_sum_subgrid(grid):", "function_name": "...
[ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def max_sum_subgrid(grid):\n \"\"\"\n Finds the largest sum of any rectangular subgrid within the given grid.\n \n Parameters:\n grid (list of list of int): 2D...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "0000023753", "row_id": 23753, "seed_ids": "['2117', '1618', '422']" }
0.694143
Leetcode_23753
I
[ "max_sum_subgrid", "kadane" ]
2
[ [ "max_sum_subgrid", "kadane" ] ]
1
[]
false
[]
false
pytest
true
[]
true
23cf5faecb3fbe28eb629bf48b668bb7e90d63c3
0aa753d5ddd65bdbf88c09d2d56bbda3d8d0cebe
v1.0
instruct
Leetcode
Leetcode_23757_I
You are given a list of strings `words` and a reference string `reference`. A word from the `words` list can be transformed into another word if the new word can be obtained by rearranging the letters and/or changing exactly one letter in the original word. Return the maximum number of transformations needed to turn a...
def can_transform(word, reference): """ Returns True if the word can be transformed into the reference by rearranging the letters and/or changing exactly one letter. """ if sorted(word) == sorted(reference): return True if len(word) != len(reference): return False diff_count...
from solution import can_transform, max_transformations def test_can_transform_same_letters(): assert can_transform("abc", "cba") == True def test_can_transform_one_change(): assert can_transform("abc", "bbc") == True def test_can_transform_different_length(): assert can_transform("abc", "abcd") == False...
[ { "docstring": "Returns True if the word can be transformed into the reference by \nrearranging the letters and/or changing exactly one letter.", "function_declaration": "def can_transform(word, reference):", "function_name": "can_transform", "parameter_list": "(word, reference)" }, { "docst...
[ 0, 0, 0, 0, 1, 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_transform(word, reference):\n \"\"\"\n Check if a word can be transformed to the reference word by changing at most one letter\n and/or rearranging the lette...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000023757", "row_id": 23757, "seed_ids": "['2548', '282', '1505']" }
0.639232
Leetcode_23757
I
[ "can_transform", "max_transformations" ]
2
[ [ "max_transformations", "can_transform" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7791ebbfc5aec12950c1026f4a2a46e376ec441d
de99786be3d2bf2da0dc02b91f037403a10836e1
v1.0
instruct
Leetcode
Leetcode_23774_I
You are given a string `text` consisting of lowercase English letters and a list of strings `words`. Return _the longest string in_ `words` _such that it is a **subsequence** of_ `text`. If there is more than one possible result, return the longest string that appears earliest in `words`. A **subsequence** is a string ...
def is_subsequence(s, t): """ Check if s is a subsequence of t. Parameters: s (str): The subsequence string to verify. t (str): The main string to check against. Returns: bool: True if s is a subsequence of t, else False. """ it = iter(t) return all(char in it for char ...
from solution import find_longest_subsequence def test_find_longest_subsequence_simple(): assert find_longest_subsequence("abpcplea", ["ale", "apple", "monkey", "plea"]) == "apple" def test_find_longest_subsequence_multiple_valid(): assert find_longest_subsequence("abpcplea", ["a", "b", "c"]) == "a" def test...
[ { "docstring": "Check if s is a subsequence of t.\n\nParameters:\ns (str): The subsequence string to verify.\nt (str): The main string to check against.\n\nReturns:\nbool: True if s is a subsequence of t, else False.", "function_declaration": "def is_subsequence(s, t):", "function_name": "is_subsequence...
[ 0, 1, 0, 1, 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(s, t):\n \"\"\"\n Helper function to check if s is a subsequence of t.\n \"\"\"\n it = iter(t)\n return all(char in it for char in s)\n\ndef...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000023774", "row_id": 23774, "seed_ids": "['2486', '1133', '801']" }
0.76094
Leetcode_23774
I
[ "is_subsequence", "find_longest_subsequence" ]
2
[ [ "find_longest_subsequence", "is_subsequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c5f46ef60e1db0da44bfa5435bdc2507580484d7
6a2a02efba999b0e11255602fa966f4b32b775ad
v1.0
instruct
Leetcode
Leetcode_23946_I
You are given two strings `s1` and `s2`, and an integer `k`. Your task is to determine if you can transform `s1` into `s2` by making **at most** `k` insertions of **any** character anywhere in `s1`. Note that you cannot delete characters from `s1` or change the order of characters. Return _`True` if it is possible to ...
def lcs_length(s1, s2): """Helper function to find the length of the longest common subsequence of s1 and s2.""" m, n = len(s1), len(s2) dp = [[0] * (n + 1) for _ in range(m + 1)] for i in range(1, m + 1): for j in range(1, n + 1): if s1[i - 1] == s2[j - 1]: dp[i...
def test_lcs_length(): assert lcs_length("abc", "def") == 0 assert lcs_length("abc", "abc") == 3 assert lcs_length("abc", "aebdc") == 3 assert lcs_length("", "abc") == 0 assert lcs_length("abc", "") == 0 def test_can_transform_basic(): assert can_transform("abc", "def", 3) == True # All charact...
[ { "docstring": "Helper function to find the length of the longest common subsequence of s1 and s2.", "function_declaration": "def lcs_length(s1, s2):", "function_name": "lcs_length", "parameter_list": "(s1, s2)" }, { "docstring": "Determines if s1 can be transformed into s2 by making at most...
[ 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 can_transform(s1, s2, k):\n \"\"\"\n Determines if s1 can be transformed into s2 by making at most k insertions.\n\n :param s1: Original string.\n :param s2: ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000023946", "row_id": 23946, "seed_ids": "['2154', '1754', '2035']" }
0.762393
Leetcode_23946
I
[ "lcs_length", "can_transform" ]
2
[ [ "can_transform", "lcs_length" ] ]
1
[]
false
[]
false
pytest
false
[]
true
f654c00f6ea80b9433faa002b316b3b87768dc12
f882b1d97df79d7567f8c52dc610eae9ecf2e21f
v1.0
instruct
Leetcode
Leetcode_23986_I
You are given a **binary tree** with `n` nodes, where each node has a unique value from `1` to `n`. The tree is represented as an array `parents` where `parents[i]` is the parent of node `i+1`. The root of the tree has `parents[i]` equal to `-1`. Your task is to find the **lowest common ancestor (LCA)** of two given no...
class TreeNode: def __init__(self, val: int): self.val = val self.parent = None def build_tree(parents): nodes = [TreeNode(i + 1) for i in range(len(parents))] root = None for i, parent_index in enumerate(parents): if parent_index == -1: root = nodes[i] else:...
from solution import lca def test_lca(): parents = [-1, 1, 1, 2, 2, 3, 3] assert lca(parents, 4, 5) == 2 assert lca(parents, 4, 6) == 1 assert lca(parents, 3, 4) == 1 assert lca(parents, 2, 4) == 2 # Test case with one node being the LCA of itself and another node parents = [-1, 1, 1, 2, 3...
[]
[ 0, 1, 0, 1, 1, 1, 1, 1, 1 ]
7
easy
0.778
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def find_lca(parents, p, q):\n \"\"\"\n Finds the lowest common ancestor (LCA) of nodes p and q in a binary tree represented by the parents array.\n \"\"\"\n # Cr...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "0000023986", "row_id": 23986, "seed_ids": "['2223', '1828', '915']" }
0.556436
Leetcode_23986
I
[ "build_tree", "find_path_to_root", "lca" ]
3
[ [ "lca", "build_tree" ], [ "lca", "find_path_to_root" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
5df0716b2903142a318bbed3fabe729ecf950897
3a950f2f755e8a912c5dadbb47f77e85fedb1a81
v1.0
instruct
Leetcode
Leetcode_24129_I
You are given a **binary search tree (BST)** with `n` nodes. Each node carries a unique integer value. You need to implement a function to find the **lowest common ancestor (LCA)** of two given nodes in the BST. The LCA of two nodes `p` and `q` in a BST is defined as the lowest node that has both `p` and `q` as its des...
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def find(root, val): """ Helper function to find a node with given value in BST. """ if root is None: return None if val == root.val: retu...
from solution import TreeNode, lowest_common_ancestor def test_example(): # Construct the BST root = TreeNode(6) root.left = TreeNode(2) root.right = TreeNode(8) root.left.left = TreeNode(0) root.left.right = TreeNode(4) root.left.right.left = TreeNode(3) root.left.right.right = TreeNod...
[]
[ 0, 0, 0, 0, 1, 0, 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": "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_lca(roo...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "0000024129", "row_id": 24129, "seed_ids": "['1170', '566', '2183']" }
0.506794
Leetcode_24129
I
[ "find", "lowest_common_ancestor" ]
2
[ [ "lowest_common_ancestor", "find" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
d0a9a485e62601d78fa8ab0191d9e1b58c385c37
74d7b784684e00fa774aad72c283ddec7bcd5258
v1.0
instruct
Leetcode
Leetcode_24220_I
Given an integer array `nums`, sort the array in ascending order using the Merge Sort algorithm and return the sorted array. The array can contain both positive and negative numbers. Implement the Merge Sort algorithm recursively and ensure your function can handle edge cases such as an empty array or an array with a s...
def merge_sort(nums): """ Sorts the array in ascending order using the Merge Sort algorithm. """ if len(nums) <= 1: return nums mid = len(nums) // 2 left_half = merge_sort(nums[:mid]) right_half = merge_sort(nums[mid:]) return merge(left_half, right_half) def merge(lef...
from solution import merge_sort def test_empty_array(): assert merge_sort([]) == [] def test_single_element_array(): assert merge_sort([1]) == [1] def test_multiple_elements_array(): assert merge_sort([3, 1, 2]) == [1, 2, 3] def test_negative_numbers_array(): assert merge_sort([-1, -3, 2, 1]) == [-3...
[ { "docstring": "Sorts the array in ascending order using the Merge Sort algorithm.", "function_declaration": "def merge_sort(nums):", "function_name": "merge_sort", "parameter_list": "(nums)" }, { "docstring": "Merges two sorted lists into one sorted list.", "function_declaration": "def ...
[ 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 merge_sort(nums):\n \"\"\"\n Sorts the array in ascending order using the Merge Sort algorithm.\n \"\"\"\n if len(nums) <= 1:\n return nums\n\n mid ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000024220", "row_id": 24220, "seed_ids": "['765', '2599', '47']" }
0.688536
Leetcode_24220
I
[ "merge_sort", "merge" ]
2
[ [ "merge_sort", "merge" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8e5e62158300139fbca97dc02ff29cf7636b4bba
163a7790de6f22b4abb4dbff83dd19c4dedfc97c
v1.0
instruct
Leetcode
Leetcode_24305_I
You are given a string `s` and an array `queries` where each query is a two-element list containing two integers, `start` and `end`. For each query, you need to determine whether the substring from index `start` to index `end` (inclusive) is a palindrome. A string is a palindrome if it reads the same forward and backwa...
def preprocess_palindrome(s): n = len(s) dp = [[False] * n for _ in range(n)] for i in range(n): dp[i][i] = True for length in range(2, n+1): for i in range(n-length+1): j = i + length - 1 if length == 2: dp[i][j] = (s[i] == s[j]) els...
def test_is_palindrome(): s = "ababa" queries = [ [0, 4], # "ababa" is a palindrome [1, 3], # "bab" is a palindrome [0, 0], # "a" is a palindrome [1, 2], # "ba" is not a palindrome [2, 4], # "aba" is a palindrome [3, 4] # "ba" is not a palindrome ] ...
[ { "docstring": null, "function_declaration": "def preprocess_palindrome(s):", "function_name": "preprocess_palindrome", "parameter_list": "(s)" }, { "docstring": null, "function_declaration": "def is_palindrome(s, queries):", "function_name": "is_palindrome", "parameter_list": "(...
[ 1, 0, 0, 1, 0, 0, 1, 0, 0, 1 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def preprocess_palindromes(s):\n \"\"\"\n Preprocess the string to enable fast palindrome querying.\n \"\"\"\n n = len(s)\n dp = [[False]*n for _ in range(n)]\...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000024305", "row_id": 24305, "seed_ids": "['275', '2162', '552']" }
0.848974
Leetcode_24305
I
[ "preprocess_palindrome", "is_palindrome" ]
2
[ [ "is_palindrome", "preprocess_palindrome" ] ]
1
[]
false
[]
false
pytest
false
[]
true
889fa9c378ab3712b730e52a7dbbe663cfee11d0
97080c24113ca8cbfafacb15d73b429aac536ef2
v1.0
instruct
Leetcode
Leetcode_24367_I
You are given an unsorted array of integers `arr` and an integer `k`. The task is to find the `k`-th smallest element in the array. You must solve this using an optimal algorithm that has an average time complexity better than `O(n log n)`. Return the `k`-th smallest element in the given array `arr`.
import random def kth_smallest(arr, k): """ Find the k-th smallest element in an unsorted array using the Quickselect algorithm. :param arr: List[int] - List of unsorted integers. :param k: int - The order of the smallest element to find (1 based index). :return: int - The k-th smallest element. ...
from solution import kth_smallest def test_kth_smallest_basic_cases(): assert kth_smallest([3, 2, 1, 5, 6, 4], 2) == 2 assert kth_smallest([3, 2, 1, 5, 6, 4], 1) == 1 assert kth_smallest([3, 2, 3, 1, 2, 4, 5, 5, 6], 4) == 3 def test_kth_smallest_with_duplicates(): assert kth_smallest([1, 1, 1, 1, 1, 1...
[ { "docstring": "Find the k-th smallest element in an unsorted array using the Quickselect algorithm.\n:param arr: List[int] - List of unsorted integers.\n:param k: int - The order of the smallest element to find (1 based index).\n:return: int - The k-th smallest element.", "function_declaration": "def kth_s...
[ 0, 1, 1, 0, 1, 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": "import random\n\ndef kth_smallest(arr, k):\n \"\"\"\n Returns the k-th smallest element in the given unsorted array arr.\n Uses the Quickselect algorithm for optimal...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000024367", "row_id": 24367, "seed_ids": "['1129', '483', '154']" }
0.577173
Leetcode_24367
I
[ "kth_smallest", "quickselect", "partition" ]
3
[ [ "kth_smallest", "quickselect" ], [ "quickselect", "partition" ] ]
2
[]
false
[]
false
pytest
true
[]
true
bb8ea98be2184149ce2846ba680ae445fcaa74f0
9d7d9051d8dcc4c05070558f6f922caf915993a1
v1.0
instruct
Leetcode
Leetcode_24396_I
You are given two non-empty binary trees `s` and `t`. Imagine there is a subtree of `s` that consists of all the nodes in `t`. Check whether `t` is a subtree of `s`. A subtree of a binary tree `s` is a tree `t` consisting of a node in `s` and all of this node's descendants. The tree `s` could also be considered as a su...
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def is_subtree(s, t): if not t: return True if not s: return False if is_same_tree(s, t): return True return is_subtree(s.left, t) or ...
from solution import TreeNode, is_subtree def test_is_subtree_true(): s = TreeNode(3, left=TreeNode(4, left=TreeNode(1), right=TreeNode(2)), right=TreeNode(5)) t = TreeNode(4, left=TreeNode(1), ...
[]
[ 1, 0, 0, 1, 1, 1, 0, 1, 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, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\ndef is_subtree(s, t):\...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "0000024396", "row_id": 24396, "seed_ids": "['1510', '1465', '189']" }
0.510787
Leetcode_24396
I
[ "is_subtree", "is_same_tree" ]
2
[ [ "is_subtree", "is_same_tree" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
93621a97462ca1e7987b15540e349ac9546a33a5
35e32a9d239a87a7f8cde5320d6a0faff6aa744a
v1.0
instruct
Leetcode
Leetcode_24423_I
Given an array of integers `nums`, for each integer in the array, consider the sum of all its distinct prime factors (a prime factor only counted once for each occurrence in the array). Return an array where each element is the sum of the distinct prime factors of the corresponding element in `nums`.
def get_prime_factors(n): """ Returns a set of distinct prime factors of the integer n. """ i = 2 factors = set() while i * i <= n: if n % i: i += 1 else: n //= i factors.add(i) if n > 1: factors.add(n) return factors def sum_o...
from solution import get_prime_factors, sum_of_distinct_prime_factors def test_get_prime_factors(): assert get_prime_factors(28) == {2, 7} assert get_prime_factors(30) == {2, 3, 5} assert get_prime_factors(17) == {17} assert get_prime_factors(1) == set() def test_sum_of_distinct_prime_factors(): a...
[ { "docstring": "Returns a set of distinct prime factors of the integer n.", "function_declaration": "def get_prime_factors(n):", "function_name": "get_prime_factors", "parameter_list": "(n)" }, { "docstring": "Returns an array where each element is the sum of the distinct prime factors \nof ...
[ 1, 1, 0, 0, 0, 0, 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 distinct_prime_factors_sum(nums):\n def prime_factors(n):\n i = 2\n factors = set()\n while i * i <= n:\n if n % i:\n i ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000024423", "row_id": 24423, "seed_ids": "['1123', '1829', '660']" }
0.611113
Leetcode_24423
I
[ "get_prime_factors", "sum_of_distinct_prime_factors" ]
2
[ [ "sum_of_distinct_prime_factors", "get_prime_factors" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8c659c02e6ab2e389acca678ef0a5d0564f23096
5f04150a01d68049e8c0e743daa5a052c8beed14
v1.0
instruct
Leetcode
Leetcode_24508_I
Given a string `s`, count the number of times a non-overlapping substring, which is a palindrome, appears in `s`. A **palindrome** is a sequence of characters that reads the same backward as forward. Two occurrences of the same substring are counted as different if they start at different positions in the string. Retur...
def is_palindrome(s): return s == s[::-1] def count_palindromic_substrings(s): n = len(s) count = 0 # Iterate over all possible substring lengths for length in range(1, n + 1): i = 0 # Iterate over all possible substrings of length `length` while i + length <= n: ...
from solution import count_palindromic_substrings def test_single_character(): assert count_palindromic_substrings("a") == 1 assert count_palindromic_substrings("b") == 1 def test_all_same_characters(): assert count_palindromic_substrings("aaa") == 6 # Palindromes: "a", "a", "a", "aa", "aa", "aaa" ...
[ { "docstring": null, "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": null, "function_declaration": "def count_palindromic_substrings(s):", "function_name": "count_palindromic_substrings", "parameter_list...
[ 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 count_non_overlapping_palindromic_substrings(s):\n \"\"\"\n Returns the number of non-overlapping palindromic substrings in the string s.\n \"\"\"\n def is_pa...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "0000024508", "row_id": 24508, "seed_ids": "['1638', '2442', '2201']" }
0.760478
Leetcode_24508
I
[ "is_palindrome", "count_palindromic_substrings" ]
2
[ [ "count_palindromic_substrings", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c9b12a4167b380945564f32d0f2d4e75450de7b5
c3f9104b8328fa8a182b202807ef44ed1816812c
v1.0
instruct
Leetcode
Leetcode_24706_I
You are given a list of strings `words` and a string `s`. Each string in `words` represents a pattern of dots and dashes (`.` and `-` respectively), and the string `s` contains only dots and dashes as well. The task is to find how many of the strings in `words` can be formed as subsequences of the string `s`. A subsequ...
def is_subsequence(pattern, s): """ Helper function to check if a pattern is a subsequence of string `s`. """ it = iter(s) return all(char in it for char in pattern) def count_subsequences(words, s): """ Returns the count of words that are subsequences of string `s`. """ count = 0 ...
from solution import count_subsequences def test_example_case(): words = ["..", ".", "-."] s = "..-." assert count_subsequences(words, s) == 3 def test_no_match_case(): words = ["..-", "--."] s = ".." assert count_subsequences(words, s) == 0 def test_all_match_case(): words = [".", ".", "...
[ { "docstring": "Helper function to check if a pattern is a subsequence of string `s`.", "function_declaration": "def is_subsequence(pattern, s):", "function_name": "is_subsequence", "parameter_list": "(pattern, s)" }, { "docstring": "Returns the count of words that are subsequences of string...
[ 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 isSubsequence(s, word):\n it = iter(s)\n return all(char in it for char in word)\n\ndef countSubsequences(words, s):\n \"\"\"\n Returns the number of words fr...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000024706", "row_id": 24706, "seed_ids": "['1106', '48', '1637']" }
0.761703
Leetcode_24706
I
[ "is_subsequence", "count_subsequences" ]
2
[ [ "count_subsequences", "is_subsequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5129e1fbc20ded080cadbcad7bea8b3ec50cb7a9
2b7e18add686aa4a7e684ac2cd0c09983d3a2910
v1.0
instruct
Leetcode
Leetcode_24711_I
You are given a **0-indexed** integer array `heights` of length `n` representing the heights of columns in a histogram. Each column's width is `1`. You are asked to find the **largest rectangle** that can be formed under the histogram. You can choose to either: - Leave the array **unchanged** - Modify heights of **at ...
def largestRectangleArea(heights): """ Returns the maximum area of the largest rectangle in the histogram. """ stack = [] max_area = 0 heights.append(0) for i in range(len(heights)): while stack and heights[stack[-1]] > heights[i]: height = heights[stack.pop()] ...
from solution import maxAreaUnderModifiedHistogram def test_maxAreaUnderModifiedHistogram_case1(): assert maxAreaUnderModifiedHistogram([2, 1, 5, 6, 2, 3]) == 10 def test_maxAreaUnderModifiedHistogram_case2(): assert maxAreaUnderModifiedHistogram([2, 4]) == 4 def test_maxAreaUnderModifiedHistogram_case3(): ...
[ { "docstring": "Returns the maximum area of the largest rectangle in the histogram.", "function_declaration": "def largestRectangleArea(heights):", "function_name": "largestRectangleArea", "parameter_list": "(heights)" }, { "docstring": "Returns the maximum rectangle area that can be obtaine...
[ 1, 0, 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 max_histogram_area(heights):\n \"\"\"\n Function to calculate the largest rectangle area in a histogram\n \"\"\"\n stack = []\n max_area = 0\n index = 0...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000024711", "row_id": 24711, "seed_ids": "['2025', '2288', '2033']" }
0.703947
Leetcode_24711
I
[ "largestRectangleArea", "maxAreaUnderModifiedHistogram" ]
2
[ [ "maxAreaUnderModifiedHistogram", "largestRectangleArea" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f9cc140f363b35acd0c8653a1144953226c42b47
d8b9c9314c3e66d0e1b16608cd872d91128eb528
v1.0
instruct
Leetcode
Leetcode_24754_I
Given an `m x n` binary matrix `mat`, return the largest rectangle containing only 1's and its area. Your answer will be an integer representing the area of the largest rectangle. Implement the function `maximalRectangle(List<List<Integer>> mat)` to solve the problem. Ensure your solution efficiently handles the potent...
def maximalRectangle(mat): if not mat: return 0 max_area = 0 n = len(mat[0]) heights = [0] * n for row in mat: for i in range(n): if row[i] == 0: heights[i] = 0 else: heights[i] += 1 max_area = max(max_are...
from solution import maximalRectangle def test_small_matrix(): mat = [ [1, 0, 1, 0, 0], [1, 0, 1, 1, 1], [1, 1, 1, 1, 1], [1, 0, 0, 1, 0] ] assert maximalRectangle(mat) == 6 def test_empty_matrix(): mat = [] assert maximalRectangle(mat) == 0 def test_matrix_with_no...
[ { "docstring": null, "function_declaration": "def maximalRectangle(mat):", "function_name": "maximalRectangle", "parameter_list": "(mat)" }, { "docstring": null, "function_declaration": "def largestRectangleArea(heights):", "function_name": "largestRectangleArea", "parameter_list...
[ 1, 1, 1, 1, 1, 1, 1, 1, 0, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def maximalRectangle(matrix):\n \"\"\"\n Given an m x n binary matrix `matrix`, returns the area of the largest rectangle containing only 1's.\n \"\"\"\n if not m...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000024754", "row_id": 24754, "seed_ids": "['1656', '1446', '1192']" }
0.716485
Leetcode_24754
I
[ "maximalRectangle", "largestRectangleArea" ]
2
[ [ "maximalRectangle", "largestRectangleArea" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3d8921daa06c9c7c7fdec99ab64aeb325a8a5446
9252d92b689b7194202d540d4742b41f9072fa04
v1.0
instruct
Leetcode
Leetcode_24767_I
You are given a list of words `words` and a string `s`, find the number of words in the list 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 of the remaining characters. Impl...
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 numMatchingSubseq(s, words): """ Returns the number of words in the list that are subsequences of 's'. """ count = 0 for ...
from solution import is_subsequence, numMatchingSubseq def test_is_subsequence(): assert is_subsequence("abcde", "a") == True assert is_subsequence("abcde", "bb") == False assert is_subsequence("abcde", "acd") == True assert is_subsequence("abcde", "ace") == True assert is_subsequence("abcde", "ba"...
[ { "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 in the list that are subsequences of 's'.", ...
[ 0, 0, 1, 1, 0, 1, 0, 0, 0, 1 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def numMatchingSubseq(s, words):\n def is_subsequence(word, s):\n it = iter(s)\n return all(char in it for char in word)\n\n count = 0\n for word in wo...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000024767", "row_id": 24767, "seed_ids": "['1570', '1037', '2359']" }
0.74995
Leetcode_24767
I
[ "is_subsequence", "numMatchingSubseq" ]
2
[ [ "numMatchingSubseq", "is_subsequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6e2af133e627194c481a71f9d3fefd79e4858f06
6d024042af9cb37621b238b23acbb9b456e02c69
v1.0
instruct
Leetcode
Leetcode_24959_I
Given two binary trees `root1` and `root2`, return _true_ if the second tree is a **subtree** of the first tree. A subtree of a binary tree is a tree that consists of a node in the tree and all of this node's descendants. The tree `root2` is considered a subtree of `root1` if there is a node in `root1` where the tree r...
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val=val self.left=left self.right=right def is_same_tree(tree1, tree2): """ Checks if two binary trees are the same. """ if not tree1 and not tree2: return True if not tree1 or not tree2: ...
from solution import TreeNode, is_subtree def test_both_empty_trees(): assert is_subtree(None, None) == True def test_tree2_empty(): assert is_subtree(TreeNode(1), None) == True def test_tree1_empty(): assert is_subtree(None, TreeNode(1)) == False def test_same_tree(): tree1 = TreeNode(1, TreeNode(2...
[]
[ 1, 1, 0, 0, 0, 1, 1, 1, 1, 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, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\ndef is_subtree(root1, ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000024959", "row_id": 24959, "seed_ids": "['1955', '46', '318']" }
0.583554
Leetcode_24959
I
[ "is_same_tree", "is_subtree" ]
2
[ [ "is_subtree", "is_same_tree" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
d099d8fe2597996781d85b016b864b6132b9899a
55bedbe9c8785d5767a8180d9108d65a3945326a
v1.0
instruct
Leetcode
Leetcode_24961_I
You are given two integer arrays `X` and `Y` both of size `n` representing coordinates in a 2D plane. A pair of points `(X[i], Y[i])` and `(X[j], Y[j])` is considered **connected** if the Euclidean distance between them is less than or equal to a given threshold `D`. Determine the number of distinct **connected compone...
import math def euclidean_distance(x1, y1, x2, y2): """ Calculate the Euclidean distance between two points (x1, y1) and (x2, y2). """ return math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2) def find_connected_components(X, Y, D): """ Find the number of connected components in the graph defined by t...
from solution import find_connected_components def test_single_component(): X = [0, 1, 2] Y = [0, 1, 2] D = 2 assert find_connected_components(X, Y, D) == 1 def test_multiple_components(): X = [0, 10, 20, 30] Y = [0, 10, 20, 30] D = 5 assert find_connected_components(X, Y, D) == 4 def...
[ { "docstring": "Calculate the Euclidean distance between two points (x1, y1) and (x2, y2).", "function_declaration": "def euclidean_distance(x1, y1, x2, y2):", "function_name": "euclidean_distance", "parameter_list": "(x1, y1, x2, y2)" }, { "docstring": "Find the number of connected componen...
[ 1, 1, 0, 0, 1, 0, 0, 0, 1, 1 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def num_connected_components(X, Y, D):\n \"\"\"\n Determines the number of distinct connected components in the graph formed \n by points (X[i], Y[i]), where points ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000024961", "row_id": 24961, "seed_ids": "['2192', '983', '916']" }
0.707592
Leetcode_24961
I
[ "euclidean_distance", "find_connected_components" ]
2
[ [ "find_connected_components", "euclidean_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b7ae7a121ed56f92cc72e96e4bafe8d3d3fcb0c1
fc2b27e8d1c4be8a89345b4cd1957ac31cb215e3
v1.0
instruct
Leetcode
Leetcode_25081_I
Given a list of words, create a function to find all the pairs of indices (i, j) such that the concatenation of words[i] and words[j] is a palindrome. A palindrome is a word that reads the same backward as forward. Return the list of pairs sorted in lexicographical order according to the pair values. For example, with...
def is_palindrome(word): """ Checks if a given word is a palindrome. """ return word == word[::-1] def palindrome_pairs(words): """ Finds all pairs of indices (i, j) such that the concatenation of words[i] and words[j] is a palindrome. Returns the list of pairs sorted in lexicographical ord...
from solution import palindrome_pairs def test_example_case(): words = ["bat", "tab", "cat"] assert palindrome_pairs(words) == [[0, 1], [1, 0]] def test_no_pairs(): words = ["abc", "def", "ghi"] assert palindrome_pairs(words) == [] def test_single_letter_words(): words = ["a", "b", "c"] asser...
[ { "docstring": "Checks if a given word is a palindrome.", "function_declaration": "def is_palindrome(word):", "function_name": "is_palindrome", "parameter_list": "(word)" }, { "docstring": "Finds all pairs of indices (i, j) such that the concatenation of words[i] and words[j] is a palindrome...
[ 1, 1, 0, 1, 0, 0, 0, 0, 0, 1 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def find_palindrome_pairs(words):\n \"\"\"\n Returns list of pairs of indices (i, j) such that the concatenation of words[i] and words[j] is a palindrome.\n \"\"\"\n...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000025081", "row_id": 25081, "seed_ids": "['689', '1628', '933']" }
0.713938
Leetcode_25081
I
[ "is_palindrome", "palindrome_pairs" ]
2
[ [ "palindrome_pairs", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4c0b86ac700eac9fb1989051669a0f1b16dfbf70
545a3d1578c1543236ca014f6d481b3119088cee
v1.0
instruct
Leetcode
Leetcode_25098_I
You are given a string `colors` representing the colors of the houses on a street. The string consists of characters `'R'`, `'G'`, and `'B'` where `'R'` stands for a red house, `'G'` stands for a green house, and `'B'` stands for a blue house. No two adjacent houses should be painted the same color. You are allowed to ...
def min_repaints(colors): """ Returns the minimum number of repaints required such that no two adjacent houses have the same color, given a string colors. """ if not colors: return 0 n = len(colors) repaint_count1 = 0 # start with first house as 'R' repaint_count2 = 0 # start ...
from solution import min_repaints def test_min_repaints_alternating_colors(): assert min_repaints("RGRGRG") == 0 # No repaints needed def test_min_repaints_all_same_colors(): assert min_repaints("RRRR") == 2 # Need 2 repaints to RGRG or GRGR def test_min_repaints_two_same_adjacent(): assert min_repaint...
[ { "docstring": "Returns the minimum number of repaints required such that no two\nadjacent houses have the same color, given a string colors.", "function_declaration": "def min_repaints(colors):", "function_name": "min_repaints", "parameter_list": "(colors)" }, { "docstring": "Get the next c...
[ 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 min_repaints(colors):\n \"\"\"\n Returns the minimum number of repaints required to ensure no two adjacent houses are painted the same color.\n \"\"\"\n n = l...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000025098", "row_id": 25098, "seed_ids": "['1494', '2047', '2086']" }
0.657362
Leetcode_25098
I
[ "min_repaints", "get_next_color" ]
2
[ [ "min_repaints", "get_next_color" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0c9385764577e4ab3dc157cb409fc8bdec5c6757
c9bb8808f23c4d0d83eb09b68ef8c1a11139dfcc
v1.0
instruct
Leetcode
Leetcode_25114_I
You are given a list of strings `words`, where each string consists of lower-case English letters. Your task is to find and return the longest string in `words` that can be constructed using the letters of another string `target`. Each letter in `target` can only be used as many times as it appears in `target`. If ther...
from collections import Counter def can_construct_from_target(word, target_counter): word_counter = Counter(word) for letter in word_counter: if word_counter[letter] > target_counter.get(letter, 0): return False return True def longest_constructible_word(words, target): target_coun...
from solution import longest_constructible_word def test_longest_constructible_word_basic(): words = ["apple", "plea", "orange", "grape"] target = "aelppgr" assert longest_constructible_word(words, target) == "plea" or longest_constructible_word(words, target) == "apple" def test_longest_constructible_wor...
[ { "docstring": null, "function_declaration": "def can_construct_from_target(word, target_counter):", "function_name": "can_construct_from_target", "parameter_list": "(word, target_counter)" }, { "docstring": null, "function_declaration": "def longest_constructible_word(words, target):", ...
[ 1, 0, 0, 0, 0, 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": "from collections import Counter\n\ndef longest_string_constructed(words, target):\n \"\"\"\n Returns the longest string that can be constructed using letters of another...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000025114", "row_id": 25114, "seed_ids": "['1418', '1878', '1337']" }
0.691946
Leetcode_25114
I
[ "can_construct_from_target", "longest_constructible_word" ]
2
[ [ "longest_constructible_word", "can_construct_from_target" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0b0e73ea8fdf2332e8415ccf93df64a69352dc0e
44d5f61a515ad818a7cb9760f9a466de11274d62
v1.0
instruct
Leetcode
Leetcode_25194_I
You are given an integer array `nums` of length `n` and an integer `target`. Write a function that finds all unique combinations in `nums` where the elements sum up to `target`. Each number in `nums` may only be used once in the combination. The solution set must not contain duplicate combinations. Return a list of all...
def combinationSum2(nums, target): nums.sort() res = [] find_combinations(nums, target, 0, [], res) return res def find_combinations(nums, target, index, path, res): if target == 0: res.append(path) return for i in range(index, len(nums)): if i > index and nums[i] == num...
from solution import combinationSum2 def test_combinationSum2_example(): nums = [10,1,2,7,6,1,5] target = 8 expected_output = [ [1,1,6], [1,2,5], [1,7], [2,6] ] assert sorted(combinationSum2(nums, target)) == sorted(expected_output) def test_combinationSum2_no_combi...
[ { "docstring": null, "function_declaration": "def combinationSum2(nums, target):", "function_name": "combinationSum2", "parameter_list": "(nums, target)" }, { "docstring": null, "function_declaration": "def find_combinations(nums, target, index, path, res):", "function_name": "find_c...
[ 0, 0, 0, 0, 0, 0, 1, 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 combinationSum2(nums, target):\n \"\"\"\n Returns all unique combinations in nums where the elements sum to the target. \n Each number in nums may only be used o...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "0000025194", "row_id": 25194, "seed_ids": "['1630', '683', '2566']" }
0.673688
Leetcode_25194
I
[ "combinationSum2", "find_combinations" ]
2
[ [ "combinationSum2", "find_combinations" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c8025f37ff81eceb67523dd0a100704d61711a79
b38d1a175b99ea16beb6aecfb02008b928d21624
v1.0
instruct
Leetcode
Leetcode_25263_I
You are given a **0-indexed** array of integers `arr` of length `n` and an integer `k`. You need to determine if there exists a **subarray** of length exactly `k` that is a **perfect square** when considered as a whole number formed by concatenating its elements. A number is considered a perfect square if it is the pro...
import math def is_perfect_square(n): """ Checks if the given number n is a perfect square. """ sqrt_n = int(math.sqrt(n)) return sqrt_n * sqrt_n == n def subarray_has_perfect_square(arr, k): """ Determines if there exists a subarray of length exactly k that forms a number which is a p...
from solution import subarray_has_perfect_square def test_subarray_has_perfect_square_found(): assert subarray_has_perfect_square([1, 4, 1, 5, 9], 1) == True assert subarray_has_perfect_square([1, 4, 1, 6], 2) == True assert subarray_has_perfect_square([4, 0, 1, 6, 1, 4], 2) == True assert subarray_has...
[ { "docstring": "Checks if the given number n is a perfect square.", "function_declaration": "def is_perfect_square(n):", "function_name": "is_perfect_square", "parameter_list": "(n)" }, { "docstring": "Determines if there exists a subarray of length exactly k\nthat forms a number which is a ...
[ 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": "import math\n\ndef is_perfect_square(x):\n return int(math.sqrt(x)) ** 2 == x\n\ndef find_concatenated_subarray_as_perfect_square(arr, k):\n n = len(arr)\n \n # E...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "0000025263", "row_id": 25263, "seed_ids": "['2375', '589', '2365']" }
0.593088
Leetcode_25263
I
[ "is_perfect_square", "subarray_has_perfect_square" ]
2
[ [ "subarray_has_perfect_square", "is_perfect_square" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e97535583880c87886a2dab566eabc38e21015ce
2af8f178abc019a69dadf9f01f2f13e5af7b4b66
v1.0
instruct
Leetcode
Leetcode_25309_I
Given a list of integers `arr`, an integer `k`, and a positive integer `x`, divide the list into `x` contiguous subarrays such that the maximum sum of the subarrays is minimized. Each contiguous subarray must contain between `k` and `(n - k*x + k)` elements, where `n` is the length of `arr`. Return the minimized maximu...
def is_valid_division(arr, k, x, max_sum): current_sum = 0 count_subarrays = 1 for num in arr: if current_sum + num > max_sum: count_subarrays += 1 current_sum = num if count_subarrays > x: return False else: current_sum += num ...
from solution import minimize_max_sum def test_minimize_max_sum(): assert minimize_max_sum([7, 2, 5, 10, 8], 1, 2) == 18 assert minimize_max_sum([1, 2, 3, 4, 5], 1, 2) == 9 assert minimize_max_sum([1, 2, 3, 4, 5], 1, 3) == 6 assert minimize_max_sum([1, 4, 4], 1, 3) == 4 def test_minimize_max_sum_edge_...
[ { "docstring": null, "function_declaration": "def is_valid_division(arr, k, x, max_sum):", "function_name": "is_valid_division", "parameter_list": "(arr, k, x, max_sum)" }, { "docstring": null, "function_declaration": "def minimize_max_sum(arr, k, x):", "function_name": "minimize_max...
[ 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 minimize_max_subarray_sum(arr, k, x):\n def valid(mid):\n count = 0\n current_sum = 0\n for num in arr:\n if current_sum + num > mid:\n...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "0000025309", "row_id": 25309, "seed_ids": "['1448', '1273', '2407']" }
0.721515
Leetcode_25309
I
[ "is_valid_division", "minimize_max_sum" ]
2
[ [ "minimize_max_sum", "is_valid_division" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d12a0e08dd3adc9557f90ad79272c24703412ba9
7fba30f976587fbd783b2914afd32e6ce22b6c95
v1.0
instruct
Leetcode
Leetcode_25364_I
Given a string `text` and an array of words `queries`, check for each word in `queries` if it can be formed by deleting some characters of the string `text` without reordering the remaining characters. Return an array of boolean values indicating the results for each word in `queries`.
def can_form_by_deleting(text, word): """ Check if `word` can be formed by deleting some characters of `text` without reordering. """ it = iter(text) return all(char in it for char in word) def check_words_by_deleting(text, queries): """ Check for each word in `queries` if it can be formed ...
from solution import check_words_by_deleting def test_check_words_by_deleting(): text = "abpcplea" queries = ["apple", "monkey", "plea", "ale"] expected = [True, False, True, True] assert check_words_by_deleting(text, queries) == expected def test_check_words_by_deleting_empty_queries(): text = "a...
[ { "docstring": "Check if `word` can be formed by deleting some characters of `text` without reordering.", "function_declaration": "def can_form_by_deleting(text, word):", "function_name": "can_form_by_deleting", "parameter_list": "(text, word)" }, { "docstring": "Check for each word in `quer...
[ 1, 1, 0, 0, 0, 0, 1, 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 can_form_by_deleting(text, queries):\n \"\"\"\n Given a string `text` and a list of words `queries`, check for each word \n in `queries` if it can be formed by d...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "0000025364", "row_id": 25364, "seed_ids": "['880', '1967', '319']" }
0.666398
Leetcode_25364
I
[ "can_form_by_deleting", "check_words_by_deleting" ]
2
[ [ "check_words_by_deleting", "can_form_by_deleting" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6c32b268d34b856c1a1ae95fc561a3336df82bdf
d80077e3ee2e7dcd8ac4eecefc6506a653014a29
v1.0
instruct
Leetcode
Leetcode_25450_I
You are given a binary tree with `n` nodes, where each node has a unique value from `1` to `n`. The root of the tree is always `1`. Each node has at most two children. You are also given a 2D list `edges` where each `edges[i]` contains `[u, v, d]` denoting that there is an edge between node `u` and node `v`, and `d` is...
class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None def build_tree(edges): if not edges: return None tree_nodes = {} for u, v, d in edges: if u not in tree_nodes: tree_nodes[u] = TreeNode(u) if v not in ...
from solution import is_path_sum def test_is_path_sum_no_edges_tree(): assert is_path_sum([], 1) == False def test_is_path_sum_single_path_tree(): edges = [[1, 2, 0], [2, 3, 0], [3, 4, 0]] target_sum = 10 # 1 + 2 + 3 + 4 = 10 assert is_path_sum(edges, target_sum) == True def test_is_path_sum_multiple...
[]
[ 0, 1, 1, 0, 0, 0, 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": "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 build_tree(e...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "0000025450", "row_id": 25450, "seed_ids": "['1898', '1733', '62']" }
0.668679
Leetcode_25450
I
[ "build_tree", "has_path_sum", "is_path_sum" ]
3
[ [ "is_path_sum", "build_tree" ], [ "is_path_sum", "has_path_sum" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
c2c5b4f7c333345401ded98316e335c6f848b869
171b8543766f375fae4a62d40457dd80fcb85293
v1.0
instruct
Leetcode
Leetcode_25498_I
A **palindromic number** is a number that remains the same when its digits are reversed. For example, `121` is palindromic, whereas `123` is not. Given an integer `n`, return _a list of all palindromic numbers less than or equal to `n`._ Can you optimize your solution to handle large values of `n` efficiently?
def is_palindromic_number(x): """ Helper function to check if a number is palindromic. """ return str(x) == str(x)[::-1] def palindromic_numbers(n): """ Returns a list of all palindromic numbers less than or equal to n. """ return [i for i in range(n + 1) if is_palindromic_number(i)]
from solution import is_palindromic_number, palindromic_numbers def test_is_palindromic_number(): assert is_palindromic_number(121) == True assert is_palindromic_number(123) == False assert is_palindromic_number(0) == True # Single-digit numbers are palindromic def test_palindromic_numbers_small_range():...
[ { "docstring": "Helper function to check if a number is palindromic.", "function_declaration": "def is_palindromic_number(x):", "function_name": "is_palindromic_number", "parameter_list": "(x)" }, { "docstring": "Returns a list of all palindromic numbers less than or equal to n.", "funct...
[ 0, 0, 1, 1, 1, 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": "def get_palindromic_numbers(n):\n \"\"\"\n Returns a list of palindromic numbers less than or equal to n.\n \n :param n: int - Upper limit for palindromic numbers...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000025498", "row_id": 25498, "seed_ids": "['1672', '883', '1215']" }
0.778711
Leetcode_25498
I
[ "is_palindromic_number", "palindromic_numbers" ]
2
[ [ "palindromic_numbers", "is_palindromic_number" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a1e3779100cd80da6d594de9afb2a567ddd47841
07800c03500cec62563b0bf3983e918d213518eb
v1.0
instruct
Leetcode
Leetcode_25571_I
You are given an array of `UUIDs` represented as strings and a set of relations between different UUIDs. Each relation indicates that two UUIDs are considered equivalent (the same entity). Write a function that, given the list of relations and the UUIDs array, returns the UUIDs array with each element replaced by its s...
def find_parent(parent, u): if parent[u] != u: parent[u] = find_parent(parent, parent[u]) return parent[u] def union(parent, rank, u, v): root_u = find_parent(parent, u) root_v = find_parent(parent, v) if root_u != root_v: if rank[root_u] > rank[root_v]: parent[root_v] =...
from solution import smallest_equivalent_uuids def test_example_case(): uuids = ["uuid1", "uuid2", "uuid3", "uuid4"] relations = [["uuid1", "uuid2"], ["uuid3", "uuid4"], ["uuid2", "uuid3"]] assert smallest_equivalent_uuids(uuids, relations) == ["uuid1", "uuid1", "uuid1", "uuid1"] def test_no_relations(): ...
[ { "docstring": null, "function_declaration": "def find_parent(parent, u):", "function_name": "find_parent", "parameter_list": "(parent, u)" }, { "docstring": null, "function_declaration": "def union(parent, rank, u, v):", "function_name": "union", "parameter_list": "(parent, rank...
[ 1, 1, 1, 1, 1, 1, 1, 1, 0, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def find(x, parent):\n if parent[x] != x:\n parent[x] = find(parent[x], parent)\n return parent[x]\n\ndef union(x, y, parent, rank):\n root_x = find(x, parent...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "0000025571", "row_id": 25571, "seed_ids": "['1648', '13', '1936']" }
0.58777
Leetcode_25571
I
[ "find_parent", "union", "smallest_equivalent_uuids" ]
3
[ [ "smallest_equivalent_uuids", "find_parent" ], [ "smallest_equivalent_uuids", "union" ], [ "union", "find_parent" ] ]
3
[]
false
[]
false
pytest
true
[]
true
34da22af2e50f53bf367dac03de875cb3f93fca6
08ce30f6f8ba6b5426a8f3dcdb8f7c567d3593ae
v1.0
instruct
Leetcode
Leetcode_25697_I
You are given a 2D integer grid `grid` where each cell in the grid represents a **height above sea level**. A square is considered a **"peak"** if and only if it is **greater** than or **equal** to any of its 8 neighboring squares (or all the neighbors that exist, for edge and corner cells). Return _the number of peaks...
def is_peak(grid, i, j): """ Check if the cell (i, j) is a peak considering all valid neighbors. """ directions = [(-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 1), (1, -1), (1, 0), (1, 1)] for di, dj in directions: ni, nj = i + di, j + dj if 0 <= ni < len(grid) and 0 <= nj < len(grid[0])...
from solution import count_peaks def test_count_peaks_basic(): grid = [ [1, 2, 1], [2, 3, 2], [1, 2, 1] ] assert count_peaks(grid) == 1 def test_count_peaks_all_same(): grid = [ [1, 1, 1], [1, 1, 1], [1, 1, 1] ] assert count_peaks(grid) == 9 def...
[ { "docstring": "Check if the cell (i, j) is a peak considering all valid neighbors.", "function_declaration": "def is_peak(grid, i, j):", "function_name": "is_peak", "parameter_list": "(grid, i, j)" }, { "docstring": "Count the number of peaks in the given 2D grid.", "function_declaratio...
[ 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 count_peaks(grid):\n \"\"\"\n Returns the number of peaks in the grid.\n \n A square is considered a \"peak\" if and only if it is greater than or equal to an...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "0000025697", "row_id": 25697, "seed_ids": "['2092', '198', '665']" }
0.627438
Leetcode_25697
I
[ "is_peak", "count_peaks" ]
2
[ [ "count_peaks", "is_peak" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8b273629ad7c8a8a5ba00e13a20230d1b5c1e391
b4fcf05f88b8b4411d4cdcb26de42e31907de334
v1.0
instruct
Leetcode
Leetcode_25705_I
In a warehouse, you are tasked with organizing stacks of boxes. Each box has a unique weight given by an array `weights` such that `weights[i]` represents the weight of the `i`th box. You need to place these boxes in `m` stacks. The height of each stack should be as balanced as possible while maintaining the order of t...
def can_divide(weights, m, max_weight): current_weight = 0 count = 1 for weight in weights: if current_weight + weight > max_weight: count += 1 current_weight = weight if count > m: return False else: current_weight += weig...
from solution import minimize_max_weight_difference def test_case_1(): weights = [1, 2, 3, 4, 5, 6, 7, 8, 9] m = 3 assert minimize_max_weight_difference(weights, m) == 17 def test_case_2(): weights = [1, 2, 3, 4, 5] m = 2 assert minimize_max_weight_difference(weights, m) == 9 def test_cas...
[ { "docstring": null, "function_declaration": "def can_divide(weights, m, max_weight):", "function_name": "can_divide", "parameter_list": "(weights, m, max_weight)" }, { "docstring": null, "function_declaration": "def minimize_max_weight_difference(weights, m):", "function_name": "min...
[ 1, 0, 0, 1, 0, 1, 0, 0, 0, 1 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def minimize_max_weight_difference(weights, m):\n n = len(weights)\n if m == 1:\n return sum(weights)\n if m >= n:\n return max(weights)\n \n def...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000025705", "row_id": 25705, "seed_ids": "['2105', '1090', '863']" }
0.645401
Leetcode_25705
I
[ "can_divide", "minimize_max_weight_difference" ]
2
[ [ "minimize_max_weight_difference", "can_divide" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7a23a9855b6b4e69c4acdf5d92542e3464f86c9e
4747c00afc9b8b0a61f368c0d6b8f7129feccbba
v1.0
instruct
Leetcode
Leetcode_25873_I
You are given two integer arrays, `arr1` and `arr2`, each of length `n`. Both arrays are **guaranteed** to contain the same set of elements but in different orders. Write a function to determine the minimum number of adjacent swaps required to make `arr1` identical to `arr2`. Return _the minimum number of swaps needed_...
def min_swaps_to_make_identical(arr1, arr2): """ Returns the minimum number of adjacent swaps required to make arr1 identical to arr2. """ n = len(arr1) pos = {value: idx for idx, value in enumerate(arr2)} arr1_mapped = [pos[value] for value in arr1] return minimum_swaps(arr1_mappe...
from solution import min_swaps_to_make_identical def test_min_swaps_to_make_identical_example_1(): arr1 = [1, 3, 5, 2, 4] arr2 = [4, 1, 2, 3, 5] assert min_swaps_to_make_identical(arr1, arr2) == 4 def test_min_swaps_to_make_identical_example_2(): arr1 = [1, 2, 3, 4] arr2 = [4, 3, 2, 1] assert ...
[ { "docstring": "Returns the minimum number of adjacent swaps required to make arr1 identical to arr2.", "function_declaration": "def min_swaps_to_make_identical(arr1, arr2):", "function_name": "min_swaps_to_make_identical", "parameter_list": "(arr1, arr2)" }, { "docstring": null, "functi...
[ 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 min_swaps_to_make_identical(arr1, arr2):\n \"\"\"\n Returns the minimum number of adjacent swaps required to make arr1 identical to arr2.\n \"\"\"\n n = len(a...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "0000025873", "row_id": 25873, "seed_ids": "['2458', '47', '2355']" }
0.696317
Leetcode_25873
I
[ "min_swaps_to_make_identical", "minimum_swaps" ]
2
[ [ "min_swaps_to_make_identical", "minimum_swaps" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3030e9b79b8ee43c145d690728620f5d6e09ab23
3c510f3a4f7b6c50b6aa0ba8f56bed1a7714e528
v1.0
instruct
Leetcode
Leetcode_25883_I
You are given a binary tree where each node contains a value, determine if the tree is symmetric around its center. A tree is considered symmetric if the left subtree is a mirror reflection of the right subtree. Return _a boolean indicating whether the tree is symmetric_. ### Example: ``` 1 / \ 2 2 / \ / \...
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def is_mirror(left, right): if left is None and right is None: return True if left is None or right is None: return False return (left.val == righ...
from solution import TreeNode, is_symmetric def test_empty_tree(): assert is_symmetric(None) == True def test_single_node_tree(): root = TreeNode(1) assert is_symmetric(root) == True def test_symmetric_tree(): root = TreeNode(1) root.left = TreeNode(2) root.right = TreeNode(2) root.left.l...
[]
[ 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 is_symmetric(root:...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000025883", "row_id": 25883, "seed_ids": "['354', '1914', '2278']" }
0.676447
Leetcode_25883
I
[ "is_mirror", "is_symmetric" ]
2
[ [ "is_symmetric", "is_mirror" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
ef6632b520f1411f9a53a34eca0ea4238a0b825e
d5ecbc3f1e0c38679d5214e92016e030efc0d1b2
v1.0
instruct
Leetcode
Leetcode_26013_I
Given an array of strings `words`, where each string is composed of lowercase English letters. You need to find a way to arrange these strings in a sequence such that every two consecutive strings in the sequence have at least one common character. If there are multiple valid sequences, return any of them. If no valid ...
from collections import defaultdict def can_follow(a, b): """ Returns True if `a` and `b` share at least one common character. """ return any(char in a for char in b) def find_sequence(words): """ Returns a sequence of words such that every two consecutive words have at least one common ch...
from solution import find_sequence def test_valid_sequence(): words = ["apple", "peach", "chip", "berry"] sequence = find_sequence(words) for i in range(len(sequence) - 1): assert any(char in sequence[i] for char in sequence[i+1]) def test_no_valid_sequence(): words = ["apple", "banana", "cher...
[ { "docstring": "Returns True if `a` and `b` share at least one common character.", "function_declaration": "def can_follow(a, b):", "function_name": "can_follow", "parameter_list": "(a, b)" }, { "docstring": "Returns a sequence of words such that every two consecutive words\nhave at least on...
[ 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, deque\n\ndef can_chain_be_formed(words):\n \"\"\"\n Given a list of words, returns one of the valid sequences such that every two c...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000026013", "row_id": 26013, "seed_ids": "['1118', '2143', '2145']" }
0.691747
Leetcode_26013
I
[ "can_follow", "find_sequence" ]
2
[ [ "find_sequence", "can_follow" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0ff66adbcaf61eb51ce1d05541b3a270a51fa8cd
4e4ed5ecf5d373ea9d5384f2627a51596c579eb2
v1.0
instruct
Leetcode
Leetcode_26047_I
You are given a string `s` consisting of lowercase English letters. You have to perform the following operation _exactly_ once: choose any position in the string and remove the character at that position. Your task is to determine if it is possible to obtain a palindrome by removing exactly one character from the strin...
def is_palindrome(s): """ Helper function to check if a given string is a palindrome. """ return s == s[::-1] def valid_palindrome(s): """ Returns whether it is possible to obtain a palindrome by removing exactly one character from the string `s`. """ left, right = 0, len(s) - 1 ...
from solution import valid_palindrome def test_valid_palindrome(): assert valid_palindrome("abca") == True assert valid_palindrome("abc") == False assert valid_palindrome("deified") == True assert valid_palindrome("racecar") == True assert valid_palindrome("abccbfa") == True def test_single_charac...
[ { "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": "Returns whether it is possible to obtain a palindrome by removing\nexactly one character...
[ 1, 1, 0, 1, 0, 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 valid_palindrome_by_removing_one_char(s):\n \"\"\"\n Checks if it's possible to obtain a palindrome by removing exactly one character from the string.\n \n Ar...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "0000026047", "row_id": 26047, "seed_ids": "['362', '805', '1773']" }
0.788218
Leetcode_26047
I
[ "is_palindrome", "valid_palindrome" ]
2
[ [ "valid_palindrome", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5328a37ddc56209bc2c1ab6b46ce9456136d495d
4c02ca8a4977e787577020372d4ad1e1cc7cc5f9
v1.0
instruct
Leetcode
Leetcode_26341_I
You are given an array of integers `arr` and an integer `k`. You need to partition the array into exactly `k` subsets such that the sum of elements in each subset is unique. Return `True` if such a partition exists, otherwise return `False`.
from itertools import combinations def subsets_with_sum(arr, k, target_sum, used): """ Helper function to check if there exists a subset of `arr` (excluding used elements) that sums up to target_sum. """ for i in range(len(arr)): if not used[i] and arr[i] <= target_sum: used[i] ...
from solution import can_partition def test_can_partition_with_valid_partition(): arr = [4, 3, 2, 3, 5, 2, 1] k = 4 assert can_partition(arr, k) == True def test_can_partition_with_no_valid_partition(): arr = [1, 2, 3, 4] k = 3 assert can_partition(arr, k) == False def test_can_partition_all_...
[ { "docstring": "Helper function to check if there exists a subset of `arr` (excluding used elements)\nthat sums up to target_sum.", "function_declaration": "def subsets_with_sum(arr, k, target_sum, used):", "function_name": "subsets_with_sum", "parameter_list": "(arr, k, target_sum, used)" }, { ...
[ 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": "from itertools import combinations\n\ndef can_partition_into_unique_subsets(arr, k):\n \"\"\"\n Check if the array can be partitioned into exactly k subsets such that t...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "0000026341", "row_id": 26341, "seed_ids": "['1202', '2571', '1129']" }
0.6112
Leetcode_26341
I
[ "subsets_with_sum", "can_partition" ]
2
[ [ "can_partition", "subsets_with_sum" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3f0c527037580a7ac09a85f5b574c57c39ea9d9c
0573562d154808e4d4a85b8226025e4a8b9dfd4d
v1.0
instruct
Leetcode
Leetcode_26490_I
Write a function that takes an array of strings `words`, and returns the longest word in `words` that can be constructed by concatenating other words from the array. If there is a tie for the longest word, return the word that came first in the original array. If no such word exists, return an empty string. * The giv...
def can_form(word, words_set, memo): if word in memo: return memo[word] for i in range(1, len(word)): prefix = word[:i] suffix = word[i:] if prefix in words_set and (suffix in words_set or can_form(suffix, words_set, memo)): memo[word] = True return True ...
from solution import longest_concatenated_word def test_example_1(): assert longest_concatenated_word(["cat", "dog", "catdog"]) == "catdog" def test_example_2(): assert longest_concatenated_word(["cat", "dog", "catdog", "catdogcat"]) == "catdogcat" def test_no_concatenated_word(): assert longest_concaten...
[ { "docstring": null, "function_declaration": "def can_form(word, words_set, memo):", "function_name": "can_form", "parameter_list": "(word, words_set, memo)" }, { "docstring": null, "function_declaration": "def longest_concatenated_word(words):", "function_name": "longest_concatenate...
[ 0, 0, 0, 1, 1, 0, 0, 1, 1, 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_concatenated_word(words):\n words_set = set(words)\n memo = {}\n\n def can_form(word):\n if word in memo:\n return memo[word]\n ...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "0000026490", "row_id": 26490, "seed_ids": "['2578', '989', '2261']" }
0.697944
Leetcode_26490
I
[ "can_form", "longest_concatenated_word" ]
2
[ [ "longest_concatenated_word", "can_form" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ce29579f5560f3f02056a0e12e1d119d1e0a65e3
b691e095a177eaaa09467f1a09daeeef89f8ec4b
v1.0
instruct
Leetcode
Leetcode_26491_I
Given a list of distinct integers `arr`, determine whether there exists a pair of indices `(i, j)` such that `arr[i]` + `arr[j]` is a prime number. Return `true` if such a pair exists, and `false` otherwise.
import itertools import math def is_prime(n): """ Helper function to check if a number is prime. """ if n <= 1: return False for i in range(2, int(math.sqrt(n)) + 1): if n % i == 0: return False return True def has_prime_pair(arr): """ Determine if there exi...
from solution import has_prime_pair, is_prime def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(17) == True assert is_prime(18) == False def test_has_prime_pair_exists(): assert has_prime_pair([1, 4, 6, 7]) == True # (1, 6) ...
[ { "docstring": "Helper function to check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Determine if there exists a pair of indices (i, j) such that\narr[i] + arr[j] is a prime number.", "functio...
[ 0, 0, 0, 0, 1, 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": "from sympy import isprime\n\ndef has_prime_pair(arr):\n \"\"\"\n Determines if there exists a pair of distinct indices (i, j) such that arr[i] + arr[j] is a prime numbe...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "0000026491", "row_id": 26491, "seed_ids": "['724', '216', '2231']" }
0.666611
Leetcode_26491
I
[ "is_prime", "has_prime_pair" ]
2
[ [ "has_prime_pair", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8ea65289571db8c6a97027f613fc5761f453ae6f
20bca9dda3ee18230394a4d3b7c4f5f4619cd8b2
v1.0
instruct
Leetcode
Leetcode_26790_I
You are provided with an array `tasks` where each element represents the time required to complete a task. There are `k` identical workers available, and each worker can only work on one task at a time. Your goal is to assign the tasks to the workers such that the maximum amount of time any single worker spends working...
def canDistributeWithinMax(tasks, k, maxWorkload): """ Helper function to determine if it's possible to distribute all tasks among k workers without any worker exceeding the specified max workload. """ currentSum = 0 requiredWorkers = 1 for task in tasks: if currentSum + task > ...
def test_minimize_max_workload_example1(): tasks = [10, 20, 30, 40] k = 2 assert minimizeMaxWorkload(tasks, k) == 60 def test_minimize_max_workload_example2(): tasks = [1, 2, 3, 4, 5] k = 2 assert minimizeMaxWorkload(tasks, k) == 9 def test_minimize_max_workload_example3(): tasks = [10, 20...
[ { "docstring": "Helper function to determine if it's possible to distribute all tasks among k workers\nwithout any worker exceeding the specified max workload.", "function_declaration": "def canDistributeWithinMax(tasks, k, maxWorkload):", "function_name": "canDistributeWithinMax", "parameter_list":...
[ 0, 0, 1, 1, 0, 0, 0, 1, 0, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def canCompleteInTime(mid, tasks, k):\n workers = 1\n current_load = 0\n\n for task in tasks:\n if current_load + task <= mid:\n current_load += ta...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "0000026790", "row_id": 26790, "seed_ids": "['1547', '359', '1152']" }
0.724331
Leetcode_26790
I
[ "canDistributeWithinMax", "minimizeMaxWorkload" ]
2
[ [ "minimizeMaxWorkload", "canDistributeWithinMax" ] ]
1
[]
false
[]
false
pytest
false
[]
true
fdc5fbf38d00c19fb1f10b7fb9a4705809c2accf
10d775de152ffa133b87a962f3c3121c4336a068
v1.0
instruct
Leetcode
Leetcode_26828_I
Given a string `s`, return _the length of the shortest palindrome you can create by appending characters to the end of the string_. A palindrome is defined as a string that reads the same forwards and backwards.
def shortest_palindrome_length(s): """ Returns the length of the shortest palindrome that can be created by appending characters to the end of the string. """ # Find the longest palindromic prefix n = len(s) rev_s = s[::-1] for i in range(n): if s.startswith(rev_s[i:]): ...
from solution import make_shortest_palindrome def test_shortest_palindrome_empty(): assert make_shortest_palindrome("") == 0 def test_shortest_palindrome_single_char(): assert make_shortest_palindrome("a") == 1 def test_shortest_palindrome_no_append(): assert make_shortest_palindrome("racecar") == 7 def...
[ { "docstring": "Returns the length of the shortest palindrome that can be created by appending characters to the end of the string.", "function_declaration": "def shortest_palindrome_length(s):", "function_name": "shortest_palindrome_length", "parameter_list": "(s)" }, { "docstring": "Return...
[ 0, 1, 0, 0, 0, 1, 0, 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 shortest_palindrome_length(s):\n \"\"\"\n Returns the length of the shortest palindrome that can be created by appending characters to the end of the string.\n \...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "0000026828", "row_id": 26828, "seed_ids": "['2134', '766', '1924']" }
0.680833
Leetcode_26828
I
[ "shortest_palindrome_length", "make_shortest_palindrome" ]
2
[ [ "make_shortest_palindrome", "shortest_palindrome_length" ] ]
1
[]
false
[]
false
pytest
true
[]
true
49ec5965fae9ed7ec71351aec8cfc93a9695a81e
381fddb84126a5ef0fa3c0d7e9da72c0d4159ab5
v1.0
instruct
Leetcode
Leetcode_27048_I
You are given a **0-indexed** string array `words`, each word being a sequence of lowercase English letters. You are also given a string `s` made of lowercase English letters. Your task is to return the count of all the words in `words` which are **subsequences** of `s`. A string `t` is a subsequence of a string `s` i...
def is_subsequence(word, s): """ Function to check if 'word' is a subsequence of 's'. """ it = iter(s) return all(char in it for char in word) def count_subsequences(words, s): """ Returns the count of all words in 'words' which are subsequences of 's'. """ return sum(is_subsequence...
from solution import is_subsequence, count_subsequences def test_is_subsequence_with_subsequence(): assert is_subsequence("abc", "ahbgdc") == True def test_is_subsequence_with_non_subsequence(): assert is_subsequence("axc", "ahbgdc") == False def test_is_subsequence_with_empty_word(): assert is_subsequen...
[ { "docstring": "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 count of all words in 'words' which are subsequences of 's'.", "f...
[ 1, 0, 0, 1, 0, 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 num_matching_subseq(s, words):\n \"\"\"\n Returns the number of words in `words` that are subsequences of `s`.\n \"\"\"\n def is_subsequence(x, y):\n i...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000027048", "row_id": 27048, "seed_ids": "['2012', '137', '2400']" }
0.768319
Leetcode_27048
I
[ "is_subsequence", "count_subsequences" ]
2
[ [ "count_subsequences", "is_subsequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8f2622d4b6238331ae4d49e9ce9553931d1ed228
3f8fe3976157840a04b6f0126f11d0f94d382890
v1.0
instruct
Leetcode
Leetcode_27245_I
Given an integer array `numbers`, you need to determine the **minimum** number of adjacent swaps required to convert the array into a **non-decreasing order**. An array is in a non-decreasing order if for every `i` where `0 <= i < numbers.length - 1`, `numbers[i] <= numbers[i + 1]`. Return the minimum number of adjacen...
def count_inversions(numbers): """ Helper function to count inversions using merge sort. An inversion indicates an out-of-order pair which needs to be swapped to sort the array. """ # Merge sort and count inversions def merge_sort(arr, temp_arr, left, right): inv_count = 0 if le...
from solution import min_adjacent_swaps_to_sort def test_sorted_array(): assert min_adjacent_swaps_to_sort([1, 2, 3, 4, 5]) == 0 def test_reverse_sorted_array(): assert min_adjacent_swaps_to_sort([5, 4, 3, 2, 1]) == 10 def test_random_array(): assert min_adjacent_swaps_to_sort([3, 1, 2, 4, 5]) == 2 def ...
[ { "docstring": "Helper function to count inversions using merge sort. \nAn inversion indicates an out-of-order pair which needs to be swapped to sort the array.", "function_declaration": "def count_inversions(numbers):", "function_name": "count_inversions", "parameter_list": "(numbers)" }, { ...
[ 0, 0, 0, 1, 1, 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 min_adjacent_swaps_to_sort(numbers):\n \"\"\"\n Returns the minimum number of adjacent swaps required to sort\n the array in non-decreasing order.\n \"\"\"\n ...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "0000027245", "row_id": 27245, "seed_ids": "['1092', '523', '1846']" }
0.725399
Leetcode_27245
I
[ "count_inversions", "min_adjacent_swaps_to_sort" ]
2
[ [ "min_adjacent_swaps_to_sort", "count_inversions" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ce2928a25ce65c894ee210b56d76d3a039d231ce
d2558789d61eccfdc722d034cfa85f44165b738d
v1.0
instruct
Leetcode
Leetcode_27401_I
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 minimized. Each student must be assig...
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": "", "prompt_id": "0000027401", "row_id": 27401, "seed_ids": "['163', '2586', '1087']" }
0.650105
Leetcode_27401
I
[ "is_valid_distribution", "find_minimum_pages" ]
2
[ [ "find_minimum_pages", "is_valid_distribution" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3ada3f579626915c2b22d8ffadc81e4e51c6bc8e
3eacffcdd95fa1f6c831f24bd96143d2d76c4d1e
v1.0
instruct
Leetcode
Leetcode_27431_I
You are given a binary tree with `n` nodes, each node having a unique value from 1 to n. You are also given a list of queries where each query is represented as an integer `val`. For each query, find the lowest common ancestor (LCA) of the node with value `val` and the root of the binary tree. Return an array of intege...
class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None def make_tree(values): if not values: return None nodes = [TreeNode(val) if val is not None else None for val in values] for index in range(1, len(nodes)): if nodes[index]: ...
import pytest from solution import TreeNode, make_tree, query_LCA def test_make_tree(): values = [3, 5, 1, 6, 2, 0, 8, None, None, 7, 4] root = make_tree(values) assert root.val == 3 assert root.left.val == 5 assert root.right.val == 1 assert root.left.left.val == 6 assert root.left.right.v...
[]
[ 0, 0, 0, 1, 1, 1, 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": "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, val...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000027431", "row_id": 27431, "seed_ids": "['1794', '760', '985']" }
0.566699
Leetcode_27431
I
[ "make_tree", "lowest_common_ancestor", "query_LCA" ]
3
[ [ "query_LCA", "lowest_common_ancestor" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
1785b5c478dfc082e28fdeb09674a61a29511ef6
1357f07d5c016c0a1fbcbdedf1be4a5ccdda5b73
v1.0
instruct
Leetcode
Leetcode_27466_I
Given a string `s`, implement a function to determine if it is a valid palindrome, considering only alphanumeric characters and ignoring cases. For the purpose of this problem, an empty string is considered a valid palindrome. Note: Use the helper method `isAlphaNumeric(char c)` to reduce complexity. Your function s...
def isAlphaNumeric(c): """ Check if the character is alphanumeric (a-z, A-Z, 0-9). """ return c.isalnum() def isPalindrome(s): """ Determine if the string `s` is a valid palindrome, considering only alphanumeric characters and ignoring cases. """ # Initialize pointers for the start...
from solution import isPalindrome def test_empty_string(): assert isPalindrome("") == True def test_single_character(): assert isPalindrome("a") == True def test_simple_palindrome(): assert isPalindrome("A man, a plan, a canal: Panama") == True def test_non_palindrome(): assert isPalindrome("race a ...
[ { "docstring": "Check if the character is alphanumeric (a-z, A-Z, 0-9).", "function_declaration": "def isAlphaNumeric(c):", "function_name": "isAlphaNumeric", "parameter_list": "(c)" }, { "docstring": "Determine if the string `s` is a valid palindrome, \nconsidering only alphanumeric charact...
[ 1, 0, 1, 0, 1, 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": "def isAlphaNumeric(c):\n \"\"\"\n Helper function to check if a character is alphanumeric.\n \"\"\"\n return c.isalnum()\n\ndef isPalindrome(s):\n \"\"\"\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000027466", "row_id": 27466, "seed_ids": "['2413', '716', '27']" }
0.724226
Leetcode_27466
I
[ "isAlphaNumeric", "isPalindrome" ]
2
[ [ "isPalindrome", "isAlphaNumeric" ] ]
1
[]
false
[]
false
pytest
true
[]
true
74479164b570a80de2b8d8b7be4052d1e51ef1e7
043c582f9f472fd44e4f930ba0f832a4a4e3a72c
v1.0
instruct
Leetcode
Leetcode_27674_I
You are given a positive integer `num`. Divisors of `num` that are also prime numbers are called prime divisors. Return _an array of unique prime divisors of_ `num` _sorted in ascending order_. If `num` has no prime divisors, return _an empty array_.
def is_prime(n): """Check if a number is prime.""" if n <= 1: return False if n == 2: return True if n % 2 == 0: return False p = 3 while p * p <= n: if n % p == 0: return False p += 2 return True def prime_divisors(num): """Return an ...
from solution import is_prime, prime_divisors def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(11) == True assert is_prime(12) == False assert is_prime(1) == False def test_prime_divisors(): assert prime_divisors(10) == ...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Return an array of unique prime divisors of num sorted in ascending order.", "function_declaration": "def prime_divisors(num):...
[ 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_prime(n):\n \"\"\"Check if a number is prime.\"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n return F...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "0000027674", "row_id": 27674, "seed_ids": "['1385', '2028', '2565']" }
0.622018
Leetcode_27674
I
[ "is_prime", "prime_divisors" ]
2
[ [ "prime_divisors", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2ef71f09039ed8a323c7a7192056cd603dca428f
7c91ab293fe705d6399632d43c781f42a126ca55
v1.0
instruct
Leetcode
Leetcode_27770_I
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.
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": "", "prompt_id": "0000027770", "row_id": 27770, "seed_ids": "['1619', '44', '1800']" }
0.568198
Leetcode_27770
I
[ "max_sum_submatrix", "max_subarray_sum" ]
2
[ [ "max_sum_submatrix", "max_subarray_sum" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2d931f1d319e4e4eb8ee3a31917c15e66181562c
7b205c6d40310a7ac28d73476b0f600c6cd4d44a
v1.0
instruct
Leetcode
Leetcode_28004_I
Given a list of strings `words` where each word consists of lowercase letters and the length of each word is equal, determine if it's possible to rearrange the words such that each consecutive pair of words has exactly one character difference. Return `true` if such an arrangement is possible, otherwise return `false`.
def is_one_char_diff(word1, word2): """ Helper function to check if two words have exactly one character different. """ diff_count = 0 for c1, c2 in zip(word1, word2): if c1 != c2: diff_count += 1 if diff_count > 1: return False return diff_count =...
from solution import rearrange_words def test_permutation_exists(): words = ["abc", "acc", "bcc"] assert rearrange_words(words) == True def test_no_permutation(): words = ["abc", "def", "ghi"] assert rearrange_words(words) == False def test_single_word(): words = ["abc"] assert rearrange_word...
[ { "docstring": "Helper function to check if two words have exactly one character different.", "function_declaration": "def is_one_char_diff(word1, word2):", "function_name": "is_one_char_diff", "parameter_list": "(word1, word2)" }, { "docstring": null, "function_declaration": "def rearra...
[ 0, 0, 0, 0, 1, 1, 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": "from itertools import permutations\n\ndef differ_by_one_char(word1, word2):\n \"\"\"\n Returns True if word1 and word2 differ by exactly one character, otherwise False....
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000028004", "row_id": 28004, "seed_ids": "['2387', '1862', '2510']" }
0.781904
Leetcode_28004
I
[ "is_one_char_diff", "rearrange_words" ]
2
[ [ "rearrange_words", "is_one_char_diff" ] ]
1
[]
false
[]
false
pytest
true
[]
true
37c1830d81bfa20dabc495446b567c1990f099f1
da0af13c8120056acb542b598658ab482d29ef31
v1.0
instruct
Leetcode
Leetcode_28007_I
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. Return _the minimum number of adjacent swaps required to sort the list in non-decreasing order if it gets...
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": "", "prompt_id": "0000028007", "row_id": 28007, "seed_ids": "['1806', '1494', '646']" }
0.742461
Leetcode_28007
I
[ "count_inversions", "min_adjacent_swaps_to_sort" ]
2
[ [ "min_adjacent_swaps_to_sort", "count_inversions" ] ]
1
[]
false
[]
false
pytest
true
[]
true
353f41df6de5b19f847dd530d807a4d1bf77105f
2d6c16bc51d174c75d44f38b4fda2a6e0f60442e
v1.0
instruct
Leetcode
Leetcode_28352_I
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 the string `s` (index 1, 3, 5, etc.). Digits in the string wrap around...
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": "", "prompt_id": "0000028352", "row_id": 28352, "seed_ids": "['49', '2353', '2322']" }
0.698978
Leetcode_28352
I
[ "add_operation", "findLexSmallestString" ]
2
[ [ "findLexSmallestString", "add_operation" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f80c4dcf6a09887b9068b3fcfc3f1817f4d49e67
6f09e4206ff20635c8ba2a206c428f2fb356343c
v1.0
instruct
Leetcode
Leetcode_28432_I
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...end]` is inclusive at both ...
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": "", "prompt_id": "0000028432", "row_id": 28432, "seed_ids": "['1177', '899', '977']" }
0.734008
Leetcode_28432
I
[ "is_palindrome", "can_divide_substring" ]
2
[ [ "can_divide_substring", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e795461523ebd3101303c1777fdd901b7803edf3
7c2d770aed1ea0ca4f05f10274e7848502f24c66
v1.0
instruct
Leetcode
Leetcode_28466_I
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 other attended event. Return t...
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": "", "prompt_id": "0000028466", "row_id": 28466, "seed_ids": "['714', '1753', '410']" }
0.579493
Leetcode_28466
I
[ "binary_search", "max_value_events" ]
2
[ [ "max_value_events", "binary_search" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5bb7ad2606896071486359f030dd02115400af70
538c926e54095d00556eea8bf3c0bf6465a206fa
v1.0
instruct
Leetcode
Leetcode_28498_I
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.
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": "", "prompt_id": "0000028498", "row_id": 28498, "seed_ids": "['503', '1438', '1465']" }
0.625828
Leetcode_28498
I
[ "is_symmetric", "is_mirror" ]
2
[ [ "is_symmetric", "is_mirror" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
9d9179706439cb9ac7b46e4c3e5b48d4871578f4
b689ebe83577ed68ad943d58573fff37b6335783
v1.0
instruct
Leetcode
Leetcode_28569_I
You are given a binary tree where each node corresponds to a value. The path length between two nodes is defined as the number of edges. Write a function that takes the root of a binary tree and two integer values `p` and `q`, and returns the shortest path length between the nodes containing these values. If either of ...
class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None def findLCA(root, p, q): if root is None: return None if root.val == p or root.val == q: return root left = findLCA(root.left, p, q) right = findLCA(root.right, p, q) i...
import pytest from solution import TreeNode, shortestPathLength def test_shortest_path_length(): # Tree Structure: # 1 # / \ # 2 3 # / \ # 4 5 root = TreeNode(1) root.left = TreeNode(2) root.right = TreeNode(3) root.left.left = TreeNode(4) root.l...
[]
[ 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 find_lca(root, p, ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000028569", "row_id": 28569, "seed_ids": "['63', '994', '137']" }
0.580072
Leetcode_28569
I
[ "findLCA", "findDepth", "shortestPathLength" ]
3
[ [ "shortestPathLength", "findDepth" ], [ "shortestPathLength", "findLCA" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
7e3a718cb35954d90bd14c5f959109e48a9e22c2
2bc917936343c12fd24f3ba24fa848049c6ab05f
v1.0
instruct
Leetcode
Leetcode_28601_I
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 forward and backward. The **leng...
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": "", "prompt_id": "0000028601", "row_id": 28601, "seed_ids": "['888', '2021', '1823']" }
0.787844
Leetcode_28601
I
[ "longest_palindromic_subsequence_lengths", "longest_palindromic_subsequence" ]
2
[ [ "longest_palindromic_subsequence_lengths", "longest_palindromic_subsequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6e8fe10360b42417ab23f5de6360a6640c81f2b5
33198fda8c7c68293ed49751b219e140e7ce2aa7
v1.0
instruct
Leetcode
Leetcode_28689_I
You are given a binary tree with N nodes represented by a list of lists, where each element is of the form `[parent, child, is_left]`: - `parent` is the value of the parent node. - `child` is the value of the child node. - `is_left` is a boolean indicating whether the child is a left child (`true`) or a right child (`f...
class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None def build_tree_relations(relations): if not relations: return None node_map = {} for parent, child, is_left in relations: if parent not in node_map: node_map[...
from solution import find_max_depth def test_single_node_tree(): relations = [] assert find_max_depth(relations) == 0 # no nodes def test_only_root(): relations = [[1, 2, True]] assert find_max_depth(relations) == 2 # 2 nodes def test_small_tree(): relations = [ [1, 2, True], [1...
[]
[ 1, 0, 1, 1, 1, 1, 0, 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, value=0, left=None, right=None):\n self.value = value\n self.left = left\n self.right = right\n\ndef insert(root,...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000028689", "row_id": 28689, "seed_ids": "['1354', '946', '1665']" }
0.570378
Leetcode_28689
I
[ "build_tree_relations", "max_depth", "find_max_depth" ]
3
[ [ "find_max_depth", "build_tree_relations" ], [ "find_max_depth", "max_depth" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
4ae1bfe46c7d1daeb0cedf0d4af0eff0324616a2
6e7aaa6c06f59e4e4d7aa4a4ce84f3f2ee2a12d9
v1.0
instruct
Leetcode
Leetcode_28693_I
Given a **m x n** matrix `mat` where each element is an integer, write a function to find the **maximum sum** of any **submatrix** of `mat`. A submatrix is a rectangular part of the matrix which includes rows `i` to `j` and columns `k` to `l` where `0 <= i <= j < m` and `0 <= k <= l < n`. Return _the **maximum sum** of...
def max_submatrix_sum(mat): """ Finds the maximum sum of any submatrix of the given matrix `mat`. :param mat: List[List[int]], a 2D list where each element is an integer :return: int, the maximum sum of any submatrix """ if not mat or not mat[0]: return 0 m, n = len(mat), len(m...
from solution import max_submatrix_sum def test_max_submatrix_sum_single_element(): assert max_submatrix_sum([[5]]) == 5 assert max_submatrix_sum([[-5]]) == -5 def test_max_submatrix_sum_all_negative(): assert max_submatrix_sum([[-1, -2], [-3, -4]]) == -1 def test_max_submatrix_sum_all_positive(): as...
[ { "docstring": "Finds the maximum sum of any submatrix of the given matrix `mat`.\n\n:param mat: List[List[int]], a 2D list where each element is an integer\n:return: int, the maximum sum of any submatrix", "function_declaration": "def max_submatrix_sum(mat):", "function_name": "max_submatrix_sum", ...
[ 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 max_sum_submatrix(mat):\n def max_subarray(arr):\n max_ending_here = max_so_far = arr[0]\n for x in arr[1:]:\n max_ending_here = max(x, max_en...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000028693", "row_id": 28693, "seed_ids": "['2016', '1602', '255']" }
0.591531
Leetcode_28693
I
[ "max_submatrix_sum", "kadane" ]
2
[ [ "max_submatrix_sum", "kadane" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7c7de4510d8600c20779a113ac6deb4e4158e068
257b0ef80103baa0f9838260a48a1eb5c261eb12
v1.0
instruct
Leetcode
Leetcode_28760_I
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 that there exists an integer `k`...
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": "", "prompt_id": "0000028760", "row_id": 28760, "seed_ids": "['1842', '699', '802']" }
0.808691
Leetcode_28760
I
[ "is_power_of_2", "min_partitions" ]
2
[ [ "min_partitions", "is_power_of_2" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8818686f09e18eeff8a31e3b08cf0ecc3743e1c1
88f689ab972b49daf703aee0f864ee71471e63c0
v1.0
instruct
Leetcode
Leetcode_28937_I
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 `128 % 8 == 0`. Note that if ...
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": "", "prompt_id": "0000028937", "row_id": 28937, "seed_ids": "['1428', '1452', '2177']" }
0.620512
Leetcode_28937
I
[ "is_self_dividing", "self_dividing_numbers" ]
2
[ [ "self_dividing_numbers", "is_self_dividing" ] ]
1
[]
false
[]
false
pytest
true
[]
true
881a95164be15d62f8cc3c6bc3cb2e143e065efe
8cb765f9c0531e5a79a955749e5324fc60874685