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_29026_I
You are given a `2D` grid of dimensions `n x m`, where each cell contains either a `0` or a `1`. A position `(x, y)` in the grid is termed as **valid** if it contains a `1`. You need to determine the largest rectangle (axis-aligned) area composed entirely of `1's` in this grid. Return _an integer representing the area...
def maximalRectangle(matrix): """ Returns the area of the largest rectangle containing only 1's in a 2D binary grid. """ if not matrix or not matrix[0]: return 0 n = len(matrix) m = len(matrix[0]) max_area = 0 heights = [0] * m for row in matrix: for i in ra...
from solution import maximalRectangle def test_maximalRectangle_base_cases(): matrix = [ [1, 0, 1, 0, 0], [1, 0, 1, 1, 1], [1, 1, 1, 1, 1], [1, 0, 0, 1, 0] ] assert maximalRectangle(matrix) == 6 def test_maximalRectangle_single_row(): matrix = [[1, 0, 1, 1, 1]] asse...
[ { "docstring": "Returns the area of the largest rectangle containing only 1's in a 2D binary grid.", "function_declaration": "def maximalRectangle(matrix):", "function_name": "maximalRectangle", "parameter_list": "(matrix)" }, { "docstring": "Helper function to find the largest rectangle are...
[ 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 maximalRectangle(matrix):\n \"\"\"\n Returns the area of the largest rectangle composed entirely of 1's.\n :param matrix: List[List[int]]\n :return: int\n ...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "0000029026", "row_id": 29026, "seed_ids": "['2318', '558', '1639']" }
0.769071
Leetcode_29026
I
[ "maximalRectangle", "largestRectangleArea" ]
2
[ [ "maximalRectangle", "largestRectangleArea" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4a666d52f96d8e90699054a4d153d1e987fa9c2d
39f57a4e586a7187e77e03e692f96209a3afee62
v1.0
instruct
Leetcode
Leetcode_29050_I
Given an array of strings `words`, return _the longest string in `words` that can be constructed by concatenating other strings from `words`_. If there is no such string, return an empty string. Each string in `words` is unique.
def can_form_word(word, words_set, memo): """ Helper function to determine if a word can be formed by concatenating other words in the set. """ if word in memo: return memo[word] for i in range(1, len(word)): prefix = word[:i] suffix = word[i:] if prefix in w...
from solution import longest_concatenated_word def test_longest_concatenated_word(): assert longest_concatenated_word(["cat","dog","catdog"]) == "catdog" assert longest_concatenated_word(["cat","dog","catdog","dogcatdog"]) == "dogcatdog" assert longest_concatenated_word(["rat","ratcat","cat","dog","catdog"...
[ { "docstring": "Helper function to determine if a word can be formed by concatenating\nother words in the set.", "function_declaration": "def can_form_word(word, words_set, memo):", "function_name": "can_form_word", "parameter_list": "(word, words_set, memo)" }, { "docstring": "Returns the l...
[ 1, 0, 0, 1, 0, 1, 1, 1, 0, 0 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "from collections import defaultdict\n\ndef longest_concatenated_word(words):\n \"\"\"\n Returns the longest string in `words` that can be constructed by concatenating o...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "0000029050", "row_id": 29050, "seed_ids": "['704', '1091', '590']" }
0.718406
Leetcode_29050
I
[ "can_form_word", "longest_concatenated_word" ]
2
[ [ "longest_concatenated_word", "can_form_word" ] ]
1
[]
false
[]
false
pytest
true
[]
true
820ffe7a65740134d39273fc78d023c409ca93e3
17c6fc01b39257c884364064f5902df32b5b61c1
v1.0
instruct
Leetcode
Leetcode_29057_I
You are given a **0-indexed** integer array `nums` with length `n` and an integer `k`. Your task is to partition the array into exactly `k` non-empty subsets such that the maximum sum of any subset is minimized. Return the minimized maximum sum.
def can_partition(nums, k, max_sum): """ Helper function to check if we can partition the array into k subsets with each subset having a sum less than or equal to max_sum. """ current_sum = 0 subsets = 1 for num in nums: if current_sum + num > max_sum: subsets += 1 ...
from solution import minimized_maximum_sum def test_example_case(): assert minimized_maximum_sum([1, 2, 3, 4, 5], 3) == 6 def test_single_element(): assert minimized_maximum_sum([10], 1) == 10 def test_all_elements_equal(): assert minimized_maximum_sum([5, 5, 5, 5], 2) == 10 def test_increasing_elements...
[ { "docstring": "Helper function to check if we can partition the array into k subsets\nwith each subset having a sum less than or equal to max_sum.", "function_declaration": "def can_partition(nums, k, max_sum):", "function_name": "can_partition", "parameter_list": "(nums, k, max_sum)" }, { ...
[ 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
1
hard
0.111
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def can_partition(nums, k, max_sum):\n subset_sums = [0] * k\n if backtrack(nums, len(nums) - 1, subset_sums, max_sum):\n return True\n return False\n\ndef ba...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000029057", "row_id": 29057, "seed_ids": "['600', '74', '1964']" }
0.70644
Leetcode_29057
I
[ "can_partition", "minimized_maximum_sum" ]
2
[ [ "minimized_maximum_sum", "can_partition" ] ]
1
[]
false
[]
false
pytest
true
[]
true
57e2e01b55b8250587415bab007adbc137f8d9e6
bf8fa60e4856cc114aa1d86326097ce54b1a9933
v1.0
instruct
Leetcode
Leetcode_29486_I
You are given an integer array `nums` of length `n` representing the weight of `n` items. You are also given an integer `k` representing the number of components that you need to divide these items into. Each component should contain at least one item, and the total weight of items in each component is the sum of the w...
def is_valid_partition(nums, k, max_weight): """ Helper function to determine if we can partition nums into k components with max weight max_weight. """ current_sum = 0 count = 1 # We start with 1 component for weight in nums: if current_sum + weight <= max_weight: current_...
from solution import min_max_weight_partition def test_example_case(): nums = [1, 2, 3, 4, 5] k = 2 assert min_max_weight_partition(nums, k) == 9 def test_single_partition(): nums = [7, 2, 5, 10, 8] k = 1 assert min_max_weight_partition(nums, k) == 32 # Sum of all elements def test_max_parti...
[ { "docstring": "Helper function to determine if we can partition nums into k components with max weight max_weight.", "function_declaration": "def is_valid_partition(nums, k, max_weight):", "function_name": "is_valid_partition", "parameter_list": "(nums, k, max_weight)" }, { "docstring": "Re...
[ 0, 0, 0, 0, 0, 1, 0, 0, 0, 1 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def valid_partition(nums, k):\n def can_partition(nums, k, max_weight):\n current_sum = 0\n components = 1\n for num in nums:\n current_sum...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000029486", "row_id": 29486, "seed_ids": "['1902', '1761', '2538']" }
0.680687
Leetcode_29486
I
[ "is_valid_partition", "min_max_weight_partition" ]
2
[ [ "min_max_weight_partition", "is_valid_partition" ] ]
1
[]
false
[]
false
pytest
true
[]
true
792800ca0423b59c8e5692f0d6e61481966a0c40
c6a544e62d06a13df52f2976203a248840cca8cd
v1.0
instruct
Leetcode
Leetcode_29544_I
Given a list of strings, return the length of the **longest substring** that is a palindrome. A palindrome is a string that reads the same backward as forward.
def longest_palindromic_substring_length(s): """ Returns the length of the longest palindromic substring in a given string. """ if not s: return 0 n = len(s) longest = 1 # Create a 2D array to keep track of palindromes dp = [[False] * n for _ in range(n)] # Every single ch...
from solution import find_longest_palindromic_substring_length def test_single_string(): assert find_longest_palindromic_substring_length(["babad"]) == 3 assert find_longest_palindromic_substring_length(["cbbd"]) == 2 def test_multiple_strings(): assert find_longest_palindromic_substring_length(["babad", ...
[ { "docstring": "Returns the length of the longest palindromic substring in a given string.", "function_declaration": "def longest_palindromic_substring_length(s):", "function_name": "longest_palindromic_substring_length", "parameter_list": "(s)" }, { "docstring": "Given a list of strings, re...
[ 1, 0, 1, 0, 1, 1, 0, 0, 0, 0 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def longest_palindromic_substring_length(s):\n \"\"\"\n Return the length of the longest palindromic substring in the given string.\n \"\"\"\n n = len(s)\n if ...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "0000029544", "row_id": 29544, "seed_ids": "['1295', '1622', '1145']" }
0.806118
Leetcode_29544
I
[ "longest_palindromic_substring_length", "find_longest_palindromic_substring_length" ]
2
[ [ "find_longest_palindromic_substring_length", "longest_palindromic_substring_length" ] ]
1
[]
false
[]
false
pytest
true
[]
true
83c60ace86acccc44ec791e0601b89676ae320dd
94f6f72e0663445894f22ee74d4317c98f6d9bc1
v1.0
instruct
Leetcode
Leetcode_29642_I
You are given a `matrix` of integers where each integer represents the height of a bar in a histogram. Each bar is of width 1. You need to find the area of the largest rectangle that can be formed using the bars in the histogram. The rectangle must be aligned between the bars, and the height of the rectangle is determi...
def largestRectangleArea(heights): stack = [] max_area = 0 heights.append(0) # Ensure the stack is emptied at the end for i, h in enumerate(heights): while stack and heights[stack[-1]] > h: height = heights[stack.pop()] width = i if not stack else i - stack[-1] - 1 ...
from solution import maximalRectangle def test_maximalRectangle_single_row(): matrix = [ [1, 0, 1, 1, 1] ] assert maximalRectangle(matrix) == 3 def test_maximalRectangle_all_ones(): matrix = [ [1, 1, 1], [1, 1, 1], [1, 1, 1] ] assert maximalRectangle(matrix) == ...
[ { "docstring": null, "function_declaration": "def largestRectangleArea(heights):", "function_name": "largestRectangleArea", "parameter_list": "(heights)" }, { "docstring": null, "function_declaration": "def maximalRectangle(matrix):", "function_name": "maximalRectangle", "paramet...
[ 1, 0, 1, 1, 1, 0, 1, 0, 1, 1 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def largest_rectangle_area(heights):\n \"\"\"\n Helper function to calculate the largest rectangle area in a histogram.\n Args:\n heights - A List of integers rep...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000029642", "row_id": 29642, "seed_ids": "['76', '1223', '499']" }
0.712086
Leetcode_29642
I
[ "largestRectangleArea", "maximalRectangle" ]
2
[ [ "maximalRectangle", "largestRectangleArea" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0761492c0128dcc4354e6c9aa71e2ccd168eb2a7
e04276c4ed3e03e5766b0a329bcf41a92924ad83
v1.0
instruct
Leetcode
Leetcode_29845_I
You are given an array of strings `words` and an integer `k`. Each string consists of exactly `k` characters in the range `['a', 'z']`. A shift on a string means replacing each character by the next one in the alphabet (with 'z' shifting to 'a'). For example, a shift on `"abc"` results in `"bcd"`. Write a function ...
def shift_string(word, k): """ Shifts the characters in the word k times. """ shifted = [] for char in word: shifted.append(chr((ord(char) - ord('a') + k) % 26 + ord('a'))) return ''.join(shifted) def shift_strings(words, k): """ Returns an array of strings where each string is ...
from solution import shift_string, shift_strings # Test for shift_string function def test_shift_string_single_shift(): assert shift_string("abc", 1) == "bcd" assert shift_string("xyz", 1) == "yza" def test_shift_string_multiple_shift(): assert shift_string("abc", 3) == "def" assert shift_string("xyz"...
[ { "docstring": "Shifts the characters in the word k times.", "function_declaration": "def shift_string(word, k):", "function_name": "shift_string", "parameter_list": "(word, k)" }, { "docstring": "Returns an array of strings where each string is shifted from 1 to k times.", "function_dec...
[ 1, 1, 0, 0, 0, 0, 0, 0, 0, 1 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def shift_string_by_k_times(string, k):\n \"\"\"\n Shifts the characters of the string by k positions.\n \"\"\"\n shifted_string = \"\"\n for character in stri...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000029845", "row_id": 29845, "seed_ids": "['537', '659', '1992']" }
0.688157
Leetcode_29845
I
[ "shift_string", "shift_strings" ]
2
[ [ "shift_strings", "shift_string" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e5981078574f25c20ef72c9006dc2ec5a5ec1259
d1be12db908a1414331ce429dea2ba156c5859c6
v1.0
instruct
Leetcode
Leetcode_29961_I
You are given an array of integers `nums` and an integer `k`. Your task is to rotate the array to the right by `k` steps, where `k` is non-negative. Implement a function to perform this rotation without using extra space for another array. For example, if the array is `[1, 2, 3, 4, 5, 6, 7]` and `k` is `3`, the array s...
def rotate(nums, k): """ Rotates the array `nums` to the right by `k` steps in-place. Parameters: nums (List[int]): The input array of integers. k (int): The number of steps to rotate the array. Returns: None """ n = len(nums) k %= n reverse(nums, 0,...
from solution import rotate, reverse def test_rotate_example_case(): nums = [1, 2, 3, 4, 5, 6, 7] rotate(nums, 3) assert nums == [5, 6, 7, 1, 2, 3, 4] def test_rotate_zero_steps(): nums = [1, 2, 3, 4, 5, 6, 7] rotate(nums, 0) assert nums == [1, 2, 3, 4, 5, 6, 7] def test_rotate_full_cycle(): ...
[ { "docstring": "Rotates the array `nums` to the right by `k` steps in-place.\n\nParameters:\n nums (List[int]): The input array of integers.\n k (int): The number of steps to rotate the array.\n \nReturns:\n None", "function_declaration": "def rotate(nums, k):", "function_name": "rotate", ...
[ 1, 1, 0, 1, 0, 1, 1, 0, 1, 1 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def rotate(nums, k):\n \"\"\"\n Rotates the array nums to the right by k steps.\n \"\"\"\n n = len(nums)\n k = k % n # In case k is greater than n\n nums[:...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000029961", "row_id": 29961, "seed_ids": "['1182', '2529', '710']" }
0.653883
Leetcode_29961
I
[ "rotate", "reverse" ]
2
[ [ "rotate", "reverse" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9407b0d8db78a76f0ca6171c9f38d3ce7d406547
6346216943b48bf81fb3d6e698f7a249b6bf9c45
v1.0
instruct
Leetcode
Leetcode_30087_I
Given a string `s` and an integer `k`, return the length of the longest substring of `s` that can be transformed into a palindrome by inserting at most `k` characters.
def longest_palindrome_subseq(s: str) -> int: """ Helper function to find the length of the longest palindromic subsequence in s. """ n = len(s) dp = [[0] * n for _ in range(n)] for i in range(n - 1, -1, -1): dp[i][i] = 1 for j in range(i + 1, n): if s[i] == s[j]: ...
def test_longest_substring_transformed_palindrome_1(): assert longest_substring_transformed_palindrome("abcdeca", 2) == 7 def test_longest_substring_transformed_palindrome_2(): assert longest_substring_transformed_palindrome("aabbc", 1) == -1 def test_longest_substring_transformed_palindrome_3(): assert l...
[ { "docstring": "Helper function to find the length of the longest palindromic subsequence in s.", "function_declaration": "def longest_palindrome_subseq(s):", "function_name": "longest_palindrome_subseq", "parameter_list": "(s)" }, { "docstring": "Returns the length of the longest substring ...
[ 0, 1, 0, 1, 0, 0, 0, 0, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def longest_palin_subseq(s):\n n = len(s)\n dp = [[0] * n for _ in range(n)]\n \n for i in range(n):\n dp[i][i] = 1\n \n for l in range(2, n + 1):\n ...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "0000030087", "row_id": 30087, "seed_ids": "['1344', '1099', '1124']" }
0.776219
Leetcode_30087
I
[ "longest_palindrome_subseq", "longest_substring_transformed_palindrome" ]
2
[ [ "longest_substring_transformed_palindrome", "longest_palindrome_subseq" ] ]
1
[]
false
[]
false
pytest
false
[]
true
1457dfb55f8bebf4a544fbbee350a87dc5e6f93e
a7d5fd2f3de50c8fa57b23bbc14c0bd6a9547bd8
v1.0
instruct
Leetcode
Leetcode_30135_I
Given a 2D matrix `mat` of size `m x n` where each cell contains an integer, write a function to determine the maximum sum of any rectangle from the matrix. A rectangle is defined by its top-left and bottom-right corners, and it should contain at least one element. The function should return the highest possible sum yo...
def max_sum_submatrix(mat): """ Returns the maximum sum of any rectangle in a 2D matrix. :param mat: List of List of integers representing the matrix :return: Integer representing the maximum rectangle sum """ if not mat or not mat[0]: return 0 m, n = len(mat), len(mat[0]) ...
from solution import max_sum_submatrix def test_max_sum_submatrix_all_positive(): mat = [ [1, 2, -1, -4, -20], [-8, -3, 4, 2, 1], [3, 8, 10, 1, 3], [-4, -1, 1, 7, -6] ] assert max_sum_submatrix(mat) == 29 # Rectangle from (1,2) to (3,3) def test_max_sum_submatrix_mixed_va...
[ { "docstring": "Returns the maximum sum of any rectangle in a 2D matrix.\n\n:param mat: List of List of integers representing the matrix\n:return: Integer representing the maximum rectangle sum", "function_declaration": "def max_sum_submatrix(mat):", "function_name": "max_sum_submatrix", "parameter_...
[ 0, 0, 0, 0, 0, 1, 0, 0, 1, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def max_sum_submatrix(mat):\n \"\"\"\n Returns the maximum sum of any rectangle in the 2D matrix mat.\n \"\"\"\n if not mat or not mat[0]:\n return 0\n\n ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000030135", "row_id": 30135, "seed_ids": "['870', '2138', '225']" }
0.714779
Leetcode_30135
I
[ "max_sum_submatrix", "max_sum_subarray" ]
2
[ [ "max_sum_submatrix", "max_sum_subarray" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3c2ceca9c5ba84778f5dde0d4151de0650da186d
acb6bace979e566f6bdf7cd80b66e8353f5cd20b
v1.0
instruct
Leetcode
Leetcode_30289_I
Given a list of non-negative integers representing the amount of time taken by each task, and an integer `k` representing the number of workers available to complete these tasks, return the minimum possible maximum workload whenever the tasks are distributed optimally among the workers. Each worker must be assigned at ...
def canDistribute(tasks, k, max_workload): current_workers = 1 current_load = 0 for task in tasks: if current_load + task <= max_workload: current_load += task else: current_workers += 1 current_load = task if current_workers > k: ...
from solution import minimizeMaxWorkload def test_minimizeMaxWorkload_basic(): assert minimizeMaxWorkload([10, 20, 30, 40], 2) == 60 def test_minimizeMaxWorkload_single_task(): assert minimizeMaxWorkload([15], 1) == 15 def test_minimizeMaxWorkload_equal_tasks(): assert minimizeMaxWorkload([10, 10, 10, 10...
[ { "docstring": null, "function_declaration": "def canDistribute(tasks, k, max_workload):", "function_name": "canDistribute", "parameter_list": "(tasks, k, max_workload)" }, { "docstring": null, "function_declaration": "def minimizeMaxWorkload(tasks, k):", "function_name": "minimizeMa...
[ 0, 0, 0, 0, 1, 0, 0, 1, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def canDistribute(tasks, k, max_workload):\n \"\"\"\n Helper function to check if tasks can be distributed among \n k workers with each worker having no more than ma...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "0000030289", "row_id": 30289, "seed_ids": "['1120', '795', '143']" }
0.681534
Leetcode_30289
I
[ "canDistribute", "minimizeMaxWorkload" ]
2
[ [ "minimizeMaxWorkload", "canDistribute" ] ]
1
[]
false
[]
false
pytest
true
[]
true
bcd8ddc12dccd9589c5a3e9f41db447e33950298
ff6e6f2f803ccaa8b90cb8880fdd09d5fc3526e1
v1.0
instruct
Leetcode
Leetcode_30496_I
You are given a string `s` representing a list of words separated by spaces. Each word consists of lowercase letters only. We define a "clique" as a group of words where each word shares at least one common letter with every other word in the group. Your task is to find the size of the largest "clique" in the string. R...
def share_common_letter(word1, word2): """ Check if two words share at least one common letter. """ return bool(set(word1) & set(word2)) def largest_clique_size(s): """ Find the size of the largest clique where each word shares at least one common letter with every other word in the group. ...
from solution import largest_clique_size def test_largest_clique_size(): # Test cases assert largest_clique_size("a b c d e") == 1 # each word is its own clique assert largest_clique_size("ab cd ef gh") == 1 # each word is its own clique assert largest_clique_size("abc bde efg fgh hij") == 5 # all w...
[ { "docstring": "Check if two words share at least one common letter.", "function_declaration": "def share_common_letter(word1, word2):", "function_name": "share_common_letter", "parameter_list": "(word1, word2)" }, { "docstring": "Find the size of the largest clique where each word shares\na...
[ 0, 0, 0, 1, 0, 0, 0, 0, 1, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def largest_clique_size(s):\n \"\"\"\n Returns the size of the largest clique in the given string of words.\n A \"clique\" is defined as a group of words where each ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000030496", "row_id": 30496, "seed_ids": "['841', '1381', '1053']" }
0.610362
Leetcode_30496
I
[ "share_common_letter", "largest_clique_size" ]
2
[ [ "largest_clique_size", "share_common_letter" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7a42fed50d6c6ba37fa70daee16744923ced3932
828f955ac78eb57b807e207ffa116ded81c22b6f
v1.0
instruct
Leetcode
Leetcode_30629_I
You are given a string `s` and an array of strings `patterns`. Your task is to determine for each pattern in `patterns`, whether it is a subsequence of the string `s`. A subsequence of a string is a new string generated from the original string with some characters (can be none) deleted without changing the relative or...
def is_subsequence(s, pattern): """ Helper function to determine if a pattern is a subsequence of s. """ it = iter(s) return all(char in it for char in pattern) def check_patterns(s, patterns): """ Determines for each pattern in patterns whether it is a subsequence of the string s. ...
from solution import check_patterns def test_single_pattern(): s = "abcdef" patterns = ["abc"] assert check_patterns(s, patterns) == [True] def test_multiple_patterns(): s = "abcdef" patterns = ["abc", "def", "acf", "af"] assert check_patterns(s, patterns) == [True, True, True, True] def test...
[ { "docstring": "Helper function to determine if a pattern is a subsequence of s.", "function_declaration": "def is_subsequence(s, pattern):", "function_name": "is_subsequence", "parameter_list": "(s, pattern)" }, { "docstring": "Determines for each pattern in patterns whether it is a subsequ...
[ 1, 1, 1, 0, 0, 1, 0, 0, 1, 0 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_subsequence(s, patterns):\n \"\"\"\n Determines whether each pattern in patterns is a subsequence of the string s.\n \n Args:\n s (str): The string to c...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000030629", "row_id": 30629, "seed_ids": "['2452', '2206', '2476']" }
0.712071
Leetcode_30629
I
[ "is_subsequence", "check_patterns" ]
2
[ [ "check_patterns", "is_subsequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
56fb8c2f97e92f851d74367e242626988a7dfe5a
3cb8449f2c4a3254785aa57b1968f0a217c41582
v1.0
instruct
Leetcode
Leetcode_30710_I
You are given a list `s` of `n` strings, where each string `s[i]` consists of lowercase English letters. Your task is to find all the pairs of strings `(s[i], s[j])` such that `i < j` and the concatenation of the two strings, i.e., 's[i] + s[j]', is a palindrome. A palindrome is a string that reads the same forward and...
def is_palindrome(s): """ Check if the input string s is a palindrome. """ return s == s[::-1] def palindrome_pairs(s): """ Return list of pairs (i, j) where i < j and s[i] + s[j] is a palindrome. :param s: List of strings :return: List of tuples (i, j) """ n = len(s) pairs...
from solution import is_palindrome, palindrome_pairs def test_is_palindrome(): assert is_palindrome("racecar") assert not is_palindrome("hello") assert is_palindrome("a") assert is_palindrome("") def test_palindrome_pairs_basic(): assert palindrome_pairs(["a", "ba", "ab", "abc"]) == [(0, 1), (1, 2...
[ { "docstring": "Check if the input string s is a palindrome.", "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": "Return list of pairs (i, j) where i < j and s[i] + s[j] is a palindrome.\n\n:param s: List of strings\n...
[ 0, 0, 0, 0, 1, 1, 0, 0, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_palindrome(s):\n \"\"\"\n Checks if the given string s is a palindrome.\n \"\"\"\n return s == s[::-1]\n\ndef find_palindrome_pairs(s):\n \"\"\"\n Re...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "0000030710", "row_id": 30710, "seed_ids": "['2194', '1140', '2132']" }
0.82838
Leetcode_30710
I
[ "is_palindrome", "palindrome_pairs" ]
2
[ [ "palindrome_pairs", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
60d725eb494edc9f6bb449585991c064f19accbf
f7a6f0e6d7de7ca9aceaa74ccf15e9cb7a190769
v1.0
instruct
Leetcode
Leetcode_30811_I
Given a binary tree, represented as a list of lists where each list contains three elements `[parent, child, is_left]`, write a function to determine if it is height-balanced. A binary tree is height-balanced if for each node in the tree, the absolute difference in height between its left and right subtrees is at most ...
class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None def build_tree(relations): if not relations: return None nodes = {} for parent, child, is_left in relations: if parent not in nodes: nodes[parent] = Tr...
from solution import is_balanced_binary_tree def test_empty_tree(): assert is_balanced_binary_tree([]) == True def test_single_node_tree(): assert is_balanced_binary_tree([[None, 1, True]]) == True def test_balanced_tree(): assert is_balanced_binary_tree([[1, 2, True], [1, 3, False]]) == True assert ...
[]
[ 0, 0, 1, 0, 1, 0, 1, 1, 0, 0 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "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 is_b...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "0000030811", "row_id": 30811, "seed_ids": "['1278', '310', '1323']" }
0.747895
Leetcode_30811
I
[ "build_tree", "is_balanced_binary_tree" ]
2
[ [ "is_balanced_binary_tree", "build_tree" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
47abb6bc844f0efdfc9cddb50a80350030d7fc5e
b1791992f24a4e118c412f4d4216086d9e6a8b1e
v1.0
instruct
Leetcode
Leetcode_30841_I
Given a binary tree, find the length of the shortest path between two nodes. The length is defined as the number of edges between the two nodes. You may assume that both nodes exist within the tree. Return the length of the shortest path between the two specified nodes.
class TreeNode: def __init__(self, value=0, left=None, right=None): self.value = value self.left = left self.right = right def find_lca(root, node1, node2): if root is None: return None if root == node1 or root == node2: return root left_lca = find_lca(root.left...
from solution import TreeNode, shortest_path_length def test_shortest_path_length(): # Example tree # 1 # / \ # 2 3 # / \ # 4 5 # Tree Node Declaration node5 = TreeNode(5) node4 = TreeNode(4) node3 = TreeNode(3) node2 = TreeNode(2, left=node...
[]
[ 1, 0, 1, 0, 1, 1, 0, 1, 1, 0 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\ndef find_lca(root: Tre...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "0000030841", "row_id": 30841, "seed_ids": "['9', '533', '1061']" }
0.569268
Leetcode_30841
I
[ "find_lca", "find_distance_from_ancestor", "shortest_path_length" ]
3
[ [ "shortest_path_length", "find_distance_from_ancestor" ], [ "shortest_path_length", "find_lca" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
50ecf1d7f07a220f598168da41c05846d333acac
bc0e51cd27ff4bb0bfd64c89ac2aeef703ce4b07
v1.0
instruct
Leetcode
Leetcode_31060_I
You are given a linked list, where the `head` node is at index 0 and each node contains an integer value and a reference to the next node. You are also given a list `queries` where each query contains two integers: the start index `start` and the end index `end`. For each query, you need to compute the sum of the value...
class ListNode: def __init__(self, val=0, next=None): self.val = val self.next = next def compute_prefix_sums(head): prefix_sums = [] current = head index = 0 current_sum = 0 while current is not None: current_sum += current.val prefix_sums.append(current_su...
import pytest from solution import ListNode, sum_queries def test_sum_queries_single_node(): head = ListNode(5) queries = [(0, 0)] assert sum_queries(head, queries) == [5] def test_sum_queries_multiple_nodes(): head = ListNode(1, ListNode(2, ListNode(3, ListNode(4, ListNode(5))))) queries = [(0, 2...
[]
[ 0, 1, 0, 1, 1, 1, 1, 1, 1, 0 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "class ListNode:\n def __init__(self, value=0, next=None):\n self.value = value\n self.next = next\n\ndef linked_list_sum_for_queries(head, queries):\n \"\...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000031060", "row_id": 31060, "seed_ids": "['636', '812', '778']" }
0.55451
Leetcode_31060
I
[ "compute_prefix_sums", "sum_queries" ]
2
[ [ "sum_queries", "compute_prefix_sums" ] ]
1
[]
false
[ "ListNode" ]
true
pytest
true
[]
true
20d12ad43999158e4f84135625e263bac32430bb
9a15ccd3155e78620d5c4c22b3304d9e2d774a5a
v1.0
instruct
Leetcode
Leetcode_31066_I
You are given a list of strings `words` and a dictionary string `dictionary` which contains words separated by spaces. Your task is to identify all the words from the input `words` list that are subsequences of any word in the `dictionary`. A string `A` is a subsequence of string `B` if `A` can be derived from `B` by d...
def is_subsequence(word, dict_word): """ Check if `word` is a subsequence of `dict_word`. """ it = iter(dict_word) return all(char in it for char in word) def find_subsequences(words, dictionary): """ Given a list of strings `words` and a dictionary string `dictionary`, returns all the ...
from solution import find_subsequences def test_find_subsequences_all_match(): words = ["a", "ab", "abc"] dictionary = "abc abc abc" assert find_subsequences(words, dictionary) == ["a", "ab", "abc"] def test_find_subsequences_some_match(): words = ["a", "ax", "abc", "xyz"] dictionary = "abc xyz" ...
[ { "docstring": "Check if `word` is a subsequence of `dict_word`.", "function_declaration": "def is_subsequence(word, dict_word):", "function_name": "is_subsequence", "parameter_list": "(word, dict_word)" }, { "docstring": "Given a list of strings `words` and a dictionary string `dictionary`,...
[ 1, 0, 1, 0, 0, 1, 0, 1, 1, 0 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_subsequence(sub, full):\n \"\"\"\n Check if sub is a subsequence of full.\n \"\"\"\n it = iter(full)\n return all(char in it for char in sub)\n\ndef fin...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000031066", "row_id": 31066, "seed_ids": "['553', '354', '2227']" }
0.679045
Leetcode_31066
I
[ "is_subsequence", "find_subsequences" ]
2
[ [ "find_subsequences", "is_subsequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e2255073111ce301ec8099ac307d305c43dfa593
b69626b37af1aa62b3076214d5befb2a8763ca31
v1.0
instruct
Leetcode
Leetcode_31094_I
Given a 2D grid `matrix` consisting of `0`'s (representing water) and `1`'s (representing land), determine the size of the largest island. An island is a group of connected 1's (connected horizontally or vertically). You may assume all four edges of the grid are surrounded by water. The function should return _the are...
from typing import List def dfs(matrix: List[List[int]], i: int, j: int, visited: List[List[bool]]) -> int: if i < 0 or i >= len(matrix) or j < 0 or j >= len(matrix[0]) or visited[i][j] or matrix[i][j] == 0: return 0 visited[i][j] = True area = 1 # include current cell # check all four possible...
from solution import largest_island def test_single_island(): matrix = [ [1, 1, 0, 0], [1, 1, 0, 0], [0, 0, 1, 1], [0, 0, 1, 1] ] assert largest_island(matrix) == 4 def test_multiple_islands(): matrix = [ [1, 0, 0, 0], [0, 1, 1, 0], [0, 1, 0, 0],...
[ { "docstring": null, "function_declaration": "def dfs(matrix, i, j, visited):", "function_name": "dfs", "parameter_list": "(matrix, i, j, visited)" }, { "docstring": null, "function_declaration": "def largest_island(matrix):", "function_name": "largest_island", "parameter_list": ...
[ 0, 0, 1, 0, 0, 0, 0, 1, 0 ]
2
hard
0.222
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def largest_island(matrix):\n if not matrix or not matrix[0]:\n return 0\n \n def dfs(x, y):\n if x < 0 or x >= len(matrix) or y < 0 or y >= len(matrix...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000031094", "row_id": 31094, "seed_ids": "['2309', '2048', '2043']" }
0.606142
Leetcode_31094
I
[ "dfs", "largest_island" ]
2
[ [ "largest_island", "dfs" ] ]
1
[]
false
[]
false
pytest
true
[]
true
594f8b14e89ced5fb55067e5619fd0baa0c7c4dc
8899870dea666cf668f9eaa8a13661355017981b
v1.0
instruct
Leetcode
Leetcode_31165_I
Given a `2D` grid of `m x n` size representing a maze where some cells are empty (`0`) and some cells have obstacles (`1`), and a starting point `(startRow, startCol)` and a destination `(destRow, destCol)`, return `true` if there is a path from the start to the destination without moving diagonally, otherwise return `...
from collections import deque def is_valid_move(grid, visited, row, col): """ Check if the move to (row, col) is valid. """ if row >= 0 and row < len(grid) and col >= 0 and col < len(grid[0]) and not visited[row][col] and grid[row][col] == 0: return True return False def has_path(grid, sta...
from solution import has_path def test_path_exists_simple(): grid = [ [0, 0, 0], [1, 0, 1], [0, 0, 0], ] assert has_path(grid, 0, 0, 2, 0) == True def test_path_exists_complex(): grid = [ [0, 1, 0, 0, 0], [0, 1, 0, 1, 0], [0, 0, 0, 1, 0], [0, 1, ...
[ { "docstring": "Check if the move to (row, col) is valid.", "function_declaration": "def is_valid_move(grid, visited, row, col):", "function_name": "is_valid_move", "parameter_list": "(grid, visited, row, col)" }, { "docstring": "Determines if there is a path from start to destination in the...
[ 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 has_path(grid, startRow, startCol, destRow, destCol):\n \"\"\"\n Determines if there is a path from the starting point to the destination in the given grid.\n \n...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000031165", "row_id": 31165, "seed_ids": "['1437', '539', '1706']" }
0.67499
Leetcode_31165
I
[ "is_valid_move", "has_path" ]
2
[ [ "has_path", "is_valid_move" ] ]
1
[]
false
[]
false
pytest
true
[]
true
222bd32235bf613268acafb76540d742725bd073
709bb9c8cbb4f306d247298beed3d89c38349e9f
v1.0
instruct
Leetcode
Leetcode_31302_I
You are given a list of strings `words` and a list of characters `chips`. Each character in `chips` can be used once to form a subsequence of any word in `words`. Return _the length of the longest word_ that can be formed using characters from `chips`. If no words can be formed, return `0`. **Note:** A subsequence of a...
def can_form_word(word, chips_count): word_count = {} for char in word: if char not in chips_count: return False word_count[char] = word_count.get(char, 0) + 1 if word_count[char] > chips_count[char]: return False return True def longest_word(words, chips): ...
from solution import longest_word def test_longest_word_case1(): words = ["apple", "banana", "kiwi"] chips = ["a", "p", "p", "l", "e", "k", "i", "w", "i"] assert longest_word(words, chips) == 5 def test_longest_word_case2(): words = ["apple", "banana", "kiwi"] chips = ["b", "a", "n", "a", "n", "a"...
[ { "docstring": null, "function_declaration": "def can_form_word(word, chips_count):", "function_name": "can_form_word", "parameter_list": "(word, chips_count)" }, { "docstring": null, "function_declaration": "def longest_word(words, chips):", "function_name": "longest_word", "par...
[ 1, 0, 1, 1, 0, 1, 1, 1, 0, 1 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def longest_word(words, chips):\n \"\"\"\n Returns the length of the longest word that can be formed using the characters in chips.\n \"\"\"\n from collections im...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000031302", "row_id": 31302, "seed_ids": "['1022', '515', '2093']" }
0.717395
Leetcode_31302
I
[ "can_form_word", "longest_word" ]
2
[ [ "longest_word", "can_form_word" ] ]
1
[]
false
[]
false
pytest
true
[]
true
eeea3f359693f5be5292b3bc841336d58c40f1b2
859bdc5d267e14fb9ae6fa4d9c40c2b6916ab788
v1.0
instruct
Leetcode
Leetcode_31334_I
You are given a **directed graph** with `n` nodes and `m` edges, where each edge has a **weight**. The nodes are numbered from `1` to `n`. You need to find the length of the **shortest path** from a given source node `s` to a target node `t`. If there is no path from `s` to `t`, return `-1`. Note that the graph can con...
import heapq def dijkstra(graph, start): # Implementation of Dijkstra's algorithm to find shortest paths from a single source n = len(graph) dist = [float('inf')] * n dist[start] = 0 pq = [(0, start)] while pq: current_distance, current_vertex = heapq.heappop(pq) i...
from solution import shortest_path def test_shortest_path_case1(): n = 4 edges = [(1, 2), (2, 3), (3, 4), (1, 4)] weights = [1, 2, 3, 10] queries = [(1, 4), (1, 3)] assert shortest_path(n, edges, weights, queries) == [6, 3] def test_shortest_path_no_path(): n = 3 edges = [(1, 2), (2, 3)] ...
[ { "docstring": null, "function_declaration": "def dijkstra(graph, start):", "function_name": "dijkstra", "parameter_list": "(graph, start)" }, { "docstring": null, "function_declaration": "def shortest_path(n, edges, weights, queries):", "function_name": "shortest_path", "paramet...
[ 0, 0, 0, 0, 1, 0, 0, 1, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "import heapq\n\ndef dijkstra(n, adj, start, end):\n \"\"\"\n Finds the shortest path length from start to end using Dijkstra's algorithm.\n \"\"\"\n dist = [float...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "0000031334", "row_id": 31334, "seed_ids": "['2458', '1351', '1153']" }
0.713567
Leetcode_31334
I
[ "dijkstra", "shortest_path" ]
2
[ [ "shortest_path", "dijkstra" ] ]
1
[]
false
[]
false
pytest
true
[]
true
68d08061de71c232e5e4cc76a5884a92e8819746
af272cbf66c36b4a7ac1714242efc1d49f53d2af
v1.0
instruct
Leetcode
Leetcode_31339_I
You are given a **0-indexed** array `arr` of `n` integers. The **range sum query** on the array is defined as the sum of all integers between two given indices `left` and `right`, inclusive (i.e., `arr[left] + arr[left + 1] + ... + arr[right]`). You need to process multiple queries of this type efficiently. Each query ...
def preprocess_array(arr): """ Preprocess the input array to create a prefix sum array. """ n = len(arr) prefix_sum = [0] * (n + 1) for i in range(n): prefix_sum[i + 1] = prefix_sum[i] + arr[i] return prefix_sum def range_sum_queries(arr, queries): """ Process the range sum ...
def test_preprocess_array(): assert preprocess_array([1, 2, 3, 4, 5]) == [0, 1, 3, 6, 10, 15] def test_range_sum_queries(): arr = [1, 2, 3, 4, 5] queries = [(0, 2), (1, 3), (2, 4)] assert range_sum_queries(arr, queries) == [6, 9, 12] def test_single_element_array(): arr = [10] queries = [(0, 0...
[ { "docstring": "Preprocess the input array to create a prefix sum array.", "function_declaration": "def preprocess_array(arr):", "function_name": "preprocess_array", "parameter_list": "(arr)" }, { "docstring": "Process the range sum queries using the prefix sum array.\n\nParameters:\narr (li...
[ 1, 0, 0, 0, 0, 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": "def preprocess(arr):\n \"\"\"\n Preprocess the input array to create a prefix sum array.\n \"\"\"\n prefix_sum = [0] * (len(arr) + 1)\n for i in range(len(arr)...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000031339", "row_id": 31339, "seed_ids": "['1420', '2246', '2090']" }
0.670015
Leetcode_31339
I
[ "preprocess_array", "range_sum_queries" ]
2
[ [ "range_sum_queries", "preprocess_array" ] ]
1
[]
false
[]
false
pytest
false
[]
true
347996c341e22addf01f7b9354fb2cc5de1b48ee
6986a3fa4de20639a2ac907221cff11ff4585f18
v1.0
instruct
Leetcode
Leetcode_31402_I
You are given an array `s` of strings representing a collection of words in a dictionary. Each element in `s` consists of lowercase English letters. You need to find out if one word can be converted into another word by changing exactly one character. Return a boolean matrix where `matrix[i][j]` is `true` if the `i-th`...
def can_convert_by_one_char(word1, word2): """ Returns True if word1 can be converted to word2 by changing exactly one character, otherwise False. """ if len(word1) != len(word2): return False diff_count = 0 for char1, char2 in zip(word1, word2): if char1 != char2: ...
from solution import can_convert_by_one_char, conversion_matrix def test_can_convert_by_one_char(): assert can_convert_by_one_char("abc", "abd") == True assert can_convert_by_one_char("abc", "aac") == True assert can_convert_by_one_char("abc", "bcd") == False assert can_convert_by_one_char("abc", "abcd...
[ { "docstring": "Returns True if word1 can be converted to word2 by changing exactly one character, otherwise False.", "function_declaration": "def can_convert_by_one_char(word1, word2):", "function_name": "can_convert_by_one_char", "parameter_list": "(word1, word2)" }, { "docstring": "Return...
[ 0, 1, 1, 1, 0, 1, 1, 0, 0, 0 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def can_convert_by_one_char(word1, word2):\n \"\"\"\n Helper function to determine if two words can be converted into each other by changing exactly one character.\n ...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "0000031402", "row_id": 31402, "seed_ids": "['976', '2140', '1733']" }
0.659298
Leetcode_31402
I
[ "can_convert_by_one_char", "conversion_matrix" ]
2
[ [ "conversion_matrix", "can_convert_by_one_char" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d169dd2209b7d28982aefbc7b92dca75db507fb3
4ca309aa7fa7e0d652e116d4d96c41d94a48e5cc
v1.0
instruct
Leetcode
Leetcode_31619_I
You are given a **0-indexed** 1D integer array `houses`, where `houses[i]` represents the position of the ith house along a street. You are also given an integer `k`, the number of heaters you can place. You can place heaters at any integer position along the street. Each heater covers all houses within a distance of `...
def can_cover_with_d(houses, k, d): """ Helper function to check if all houses can be covered by k heaters with a given radius d. """ heaters_count = 0 i = 0 while i < len(houses): heaters_count += 1 if heaters_count > k: return False # Place the heater t...
from solution import minimum_heater_radius def test_minimum_heater_radius_all_houses_at_same_position(): houses = [5, 5, 5, 5] k = 1 assert minimum_heater_radius(houses, k) == 0 def test_minimum_heater_radius_example_1(): houses = [1, 2, 3, 4, 5] k = 1 assert minimum_heater_radius(houses, k) =...
[ { "docstring": "Helper function to check if all houses can be covered by k heaters with a given radius d.", "function_declaration": "def can_cover_with_d(houses, k, d):", "function_name": "can_cover_with_d", "parameter_list": "(houses, k, d)" }, { "docstring": "Returns the minimum heater rad...
[ 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def min_distance_to_cover_houses(houses, k):\n def can_cover_all_houses(d):\n heaters_used = 0\n i = 0\n while i < len(houses):\n heaters_u...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "0000031619", "row_id": 31619, "seed_ids": "['2290', '2028', '635']" }
0.62852
Leetcode_31619
I
[ "can_cover_with_d", "minimum_heater_radius" ]
2
[ [ "minimum_heater_radius", "can_cover_with_d" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ae425515c3a548e3817a53cf071f6bcddcc274ee
88baa26c539bf12db4d0a7d101056d34029684d6
v1.0
instruct
Leetcode
Leetcode_31620_I
You are given a positive integer `n`. Write a function to determine the number of valid parentheses strings of length `2n`. A valid parentheses string is defined as a string of length `2n` that consists only of characters '(' and ')', and is balanced such that every open parenthesis '(' has a matching close parenthesis ...
def catalan_number(n): """ Returns the nth Catalan number. """ if n == 0: return 1 catalan = [0] * (n + 1) catalan[0] = 1 for i in range(1, n + 1): for j in range(i): catalan[i] += catalan[j] * catalan[i - 1 - j] return catalan[n] def num_valid_parentheses(n)...
from solution import num_valid_parentheses def test_num_valid_parentheses(): assert num_valid_parentheses(0) == 1 assert num_valid_parentheses(1) == 1 assert num_valid_parentheses(2) == 2 assert num_valid_parentheses(3) == 5 assert num_valid_parentheses(4) == 14 assert num_valid_parentheses(5) ...
[ { "docstring": "Returns the nth Catalan number.", "function_declaration": "def catalan_number(n):", "function_name": "catalan_number", "parameter_list": "(n)" }, { "docstring": "Returns the number of valid parentheses strings of length 2n.", "function_declaration": "def num_valid_parenth...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def count_valid_parentheses_strings(n):\n \"\"\"\n Returns the number of valid parentheses strings of length 2n.\n \"\"\"\n if n == 0:\n return 1\n \n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000031620", "row_id": 31620, "seed_ids": "['2311', '255', '2345']" }
0.737596
Leetcode_31620
I
[ "catalan_number", "num_valid_parentheses" ]
2
[ [ "num_valid_parentheses", "catalan_number" ] ]
1
[]
false
[]
false
pytest
true
[]
true
61f60e08e8dc53aaa80ed79763bab52c9919dcdd
b94e45c42c6b6a7cc64fa660419e47bef92b921a
v1.0
instruct
Leetcode
Leetcode_31647_I
You are given a string `s` and a list of words `words`. Determine the **number of words** in `words` that are **subsequences** of `s`. A subsequence of a string is a new string generated from the original string with some characters (can be none) deleted without changing the relative order of the remaining characters. ...
def is_subsequence(s, word): """ Helper function to check if word is a subsequence of s """ it = iter(s) return all(char in it for char in word) def num_matching_subseq(s, words): """ Returns the number of words that are subsequences of s """ count = 0 for word in words: ...
from solution import is_subsequence, num_matching_subseq def test_is_subsequence(): assert is_subsequence("abcde", "ace") == True assert is_subsequence("abcde", "aec") == False assert is_subsequence("abcde", "abcde") == True assert is_subsequence("abcde", "") == True assert is_subsequence("abcde", ...
[ { "docstring": "Helper function to check if word is a subsequence of s", "function_declaration": "def is_subsequence(s, word):", "function_name": "is_subsequence", "parameter_list": "(s, word)" }, { "docstring": "Returns the number of words that are subsequences of s", "function_declarat...
[ 0, 0, 0, 0, 1, 0, 1, 0, 1, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def num_matching_subseq(s, words):\n \"\"\"\n Returns the number of words in the list which are subsequences of the string s.\n \"\"\"\n def is_subsequence(word, ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000031647", "row_id": 31647, "seed_ids": "['1309', '2318', '1271']" }
0.802847
Leetcode_31647
I
[ "is_subsequence", "num_matching_subseq" ]
2
[ [ "num_matching_subseq", "is_subsequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ef92a4d55553e5e42f955fae19b63a6acbbc306b
e7b2fba3b1dd8fd70ce00224827db480cac9ad41
v1.0
instruct
Leetcode
Leetcode_31674_I
Given a list of non-negative integers, each representing the amount of some resource from a list `resources` and an integer `k`, determine the maximum value of the minimum amount of resource each person can get if you distribute the resources among `k` people. Each person should get at least one unit of resource. Retur...
def can_distribute(resources, k, minimum_amount): """ Helper function to check if it's possible to distribute resources such that each person gets at least `minimum_amount` resources. """ count = 0 for resource in resources: count += resource // minimum_amount return count >= k def ...
from solution import maximum_minimum_distribution def test_example_case(): assert maximum_minimum_distribution([5, 9, 7], 3) == 5 def test_smaller_case(): assert maximum_minimum_distribution([5, 9, 7], 4) == 4 def test_single_resource(): assert maximum_minimum_distribution([10], 5) == 2 def test_lar...
[ { "docstring": "Helper function to check if it's possible to distribute resources such that\neach person gets at least `minimum_amount` resources.", "function_declaration": "def can_distribute(resources, k, minimum_amount):", "function_name": "can_distribute", "parameter_list": "(resources, k, minim...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
1
hard
0.111
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def canDistribute(resources, k, min_amount):\n count = 0\n for r in resources:\n count += r // min_amount\n return count >= k\n\ndef max_min_resources(resourc...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000031674", "row_id": 31674, "seed_ids": "['2333', '799', '1905']" }
0.632806
Leetcode_31674
I
[ "can_distribute", "maximum_minimum_distribution" ]
2
[ [ "maximum_minimum_distribution", "can_distribute" ] ]
1
[]
false
[]
false
pytest
true
[]
true
37dce28bad52945a478fbe704c4885993dba8d72
b28fdb477d82709628b9814f505def1cb51bbb07
v1.0
instruct
Leetcode
Leetcode_31734_I
You have a `binary search tree` (BST) with `n` nodes. Each node in the BST contains a unique integer value. We define the `distance` between two nodes as the number of edges in the shortest path connecting them. You are given references to two nodes, `node1` and `node2` in the BST. Write a function to find the distanc...
class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None def find_lca(root, node1, node2): if not root: return None # If either node1 or node2 is equal to root, then root is LCA if root == node1 or root == node2: return root # Re...
from solution import TreeNode, find_distance_between_nodes def test_distance_between_nodes(): # Create the BST root = TreeNode(5) root.left = TreeNode(3) root.right = TreeNode(8) root.left.left = TreeNode(2) root.left.right = TreeNode(4) root.right.left = TreeNode(7) root.right.right = ...
[]
[ 0, 1, 1, 1, 0, 1, 0, 0, 1, 0 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, x):\n self.val = x\n self.left = None\n self.right = None\n\ndef find_distance(root, node1, node2):\n \"\"\"\n...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "0000031734", "row_id": 31734, "seed_ids": "['1533', '1290', '121']" }
0.56276
Leetcode_31734
I
[ "find_lca", "find_distance_from_lca", "find_distance_between_nodes" ]
3
[ [ "find_distance_between_nodes", "find_distance_from_lca" ], [ "find_distance_between_nodes", "find_lca" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
53f0f44bb5a41b2346af51039285164816272f6c
63142bd03dc47d319ea7b52a473a672a593da172
v1.0
instruct
Leetcode
Leetcode_31803_I
You are provided a list of words, `words`, and a string `s`. Write a function that returns the largest word in `words` that can be formed by deleting some characters of `s` without reordering the characters in `s`. If there is more than one possible result, return the word that appears first in `words`. If no words in ...
def is_subsequence(word, s): """ Helper function to check if `word` is a subsequence of `s`. """ it = iter(s) return all(char in it for char in word) def find_longest_word(words, s): """ Returns the largest word in 'words' that can be formed by deleting some characters of 's' without r...
from solution import find_longest_word def test_case1(): words = ["apple", "plea", "ale"] s = "abpcplea" assert find_longest_word(words, s) == "apple" def test_case2(): words = ["a", "b", "c"] s = "abpcplea" assert find_longest_word(words, s) == "a" def test_case3(): words = ["ab", "ba"] ...
[ { "docstring": "Helper function to check if `word` is a subsequence of `s`.", "function_declaration": "def is_subsequence(word, s):", "function_name": "is_subsequence", "parameter_list": "(word, s)" }, { "docstring": "Returns the largest word in 'words' that can be formed by deleting \nsome ...
[ 0, 0, 1, 0, 0, 1, 0, 0, 1, 1 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_subsequence(word, s):\n # Helper function to check if 'word' is a subsequence of 's'\n it = iter(s)\n return all(char in it for char in word)\n\ndef find_larg...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000031803", "row_id": 31803, "seed_ids": "['2304', '17', '1282']" }
0.78587
Leetcode_31803
I
[ "is_subsequence", "find_longest_word" ]
2
[ [ "find_longest_word", "is_subsequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
76d0c750e8bf0d29e155ef7dd60aca760f8585b0
f7da5480ea8838189d0f43fbd94683e85ed8c86c
v1.0
instruct
Leetcode
Leetcode_31825_I
You are given an array `books` where each element represents the number of pages in a particular book. A group of friends wants to divide these books among themselves such that each friend gets a contiguous segment of books. However, they want to minimize the maximum number of pages any friend has to read. You need to ...
def is_valid(books, n, k, curr_min): current_sum = 0 required_students = 1 for i in range(n): if (books[i] > curr_min): return False if (current_sum + books[i] > curr_min): required_students += 1 current_sum = books[i] if required_students...
from solution import max_pages def test_single_book(): assert max_pages([50], 1) == 50 def test_equal_books(): assert max_pages([10, 10, 10, 10], 2) == 20 def test_books_division(): assert max_pages([10, 20, 30, 40, 50], 2) == 90 assert max_pages([10, 20, 30, 40, 50], 3) == 60 assert max_pages([1...
[ { "docstring": null, "function_declaration": "def is_valid(books, n, k, curr_min):", "function_name": "is_valid", "parameter_list": "(books, n, k, curr_min)" }, { "docstring": null, "function_declaration": "def max_pages(books, k):", "function_name": "max_pages", "parameter_list"...
[ 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def minimize_max_pages(books, k):\n def is_valid(books, k, mid):\n num_students = 1\n current_sum = 0\n for pages in books:\n if current_su...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "0000031825", "row_id": 31825, "seed_ids": "['2304', '2325', '1202']" }
0.610367
Leetcode_31825
I
[ "is_valid", "max_pages" ]
2
[ [ "max_pages", "is_valid" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7e8981d407aa2b9a2770908283b4467d99cf96e6
2c4752b368c08d79b0e2eb4872c2d2639318dd2b
v1.0
instruct
Leetcode
Leetcode_31942_I
You are given an array of `words` and a string `letters`. Each word consists of lowercase English letters and the string `letters` contains distinct lowercase English letters. Return _the longest word from the array that can be constructed using letters from_ `letters` without repeating any letter. If there is a tie, r...
def can_construct(word, letters): """ Helper function to determine if a word can be constructed from given letters. """ # Create a set of available letters available_letters = set(letters) # Try to construct the word for letter in word: if letter not in available_letters: ...
from solution import longest_word def test_single_word_constructible(): assert longest_word(["apple"], "aplinfre") == "apple" def test_multiple_options(): assert longest_word(["apple", "bat", "cat", "car"], "aplinfre") == "apple" def test_no_words_constructible(): assert longest_word(["apple", "bat", "ca...
[ { "docstring": "Helper function to determine if a word can be constructed from given letters.", "function_declaration": "def can_construct(word, letters):", "function_name": "can_construct", "parameter_list": "(word, letters)" }, { "docstring": "Returns the longest word that can be construct...
[ 0, 0, 1, 0, 0, 0, 0, 0, 1, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def longest_word(words, letters):\n \"\"\"\n Returns the longest word from the array `words` that can be constructed using letters from `letters`\n without repeating...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000031942", "row_id": 31942, "seed_ids": "['937', '1979', '209']" }
0.692374
Leetcode_31942
I
[ "can_construct", "longest_word" ]
2
[ [ "longest_word", "can_construct" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3a03d0b49288c03e3c91dd88f1b73a403af35817
19d54fbc00ab40ae2ea4f6542e6ce56642ce92b0
v1.0
instruct
Leetcode
Leetcode_32091_I
You are given a **0-indexed** binary matrix `board` with dimensions `m x n` representing a rectangular board game. Each cell in the board can either be `0` (empty) or `1` (occupied by a game piece). You are also given a piece represented as a list of coordinates `piece`, where `piece[i] = [xi, yi]` indicates the coordi...
def rotate_piece(piece): """ Rotate piece coordinates by 90 degrees clockwise. """ return [[y, -x] for x, y in piece] def normalize_piece(piece): """ Normalize piece coordinates to make the minimum x and y as 0. """ min_x = min(x for x, y in piece) min_y = min(y for x, y in piece) ...
from solution import can_place_piece def test_no_rotation_needed(): board = [ [0, 0, 0], [0, 0, 0], [0, 0, 0] ] piece = [[0, 0], [0, 1], [1, 0], [1, 1]] assert can_place_piece(board, piece) == True def test_rotation_needed(): board = [ [0, 0, 0], [0, 0, 0], ...
[ { "docstring": "Rotate piece coordinates by 90 degrees clockwise.", "function_declaration": "def rotate_piece(piece):", "function_name": "rotate_piece", "parameter_list": "(piece)" }, { "docstring": "Normalize piece coordinates to make the minimum x and y as 0.", "function_declaration": ...
[ 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 rotate_piece(piece):\n \"\"\"\n Rotates the given piece (list of coordinates) by 90 degrees clockwise.\n :param piece: List of coordinates.\n :return: Rotated...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "0000032091", "row_id": 32091, "seed_ids": "['2596', '2588', '2092']" }
0.658694
Leetcode_32091
I
[ "rotate_piece", "normalize_piece", "can_place_piece" ]
3
[ [ "can_place_piece", "normalize_piece" ], [ "can_place_piece", "rotate_piece" ] ]
2
[]
false
[]
false
pytest
true
[]
true
0d675dad655bfa8349087a3d8762c3a6ca6ba927
c59761e13e8ebfc383aa0124b11215ef98caf1f8
v1.0
instruct
Leetcode
Leetcode_32094_I
Given a linked list, rotate the list to the right by `k` places, where `k` is a non-negative integer. Return _the head of the rotated linked list_. Here is the definition for the singly linked list node: class ListNode { int val; ListNode next; ListNode(int x) { val = x; next = null; }...
class ListNode: def __init__(self, x): self.val = x self.next = None def get_list_length(head): length = 0 current = head while current: length += 1 current = current.next return length def rotateRight(head, k): if not head or k == 0: return head ...
from solution import ListNode, rotateRight def linked_list_to_list(head): result = [] current = head while current: result.append(current.val) current = current.next return result def list_to_linked_list(lst): if not lst: return None head = ListNode(lst[0]) current ...
[]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "class ListNode:\n def __init__(self, val=0, next=None):\n self.val = val\n self.next = next\n\ndef rotateRight(head, k):\n if not head or not head.next or...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000032094", "row_id": 32094, "seed_ids": "['16', '874', '510']" }
0.600684
Leetcode_32094
I
[ "get_list_length", "rotateRight" ]
2
[ [ "rotateRight", "get_list_length" ] ]
1
[]
false
[ "ListNode" ]
true
pytest
true
[]
true
ec035780b7720dd6611ea4399f7a96de6b7ba9e4
9096299f853c52c2bca6f1557d09b60cb9b71ce6
v1.0
instruct
Leetcode
Leetcode_32138_I
A **prime number** is a natural number greater than 1 that has no positive divisors other than 1 and itself. A prime number `p` is called an **emirp** if the reverse of its digits is also a prime. Given an integer `k`, return _the **largest emirp** number **less than or equal to**_ `k`_. If no such number exists, retur...
def is_prime(n): """ Check if a number is prime. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 return True...
from solution import is_prime, reverse_number, largest_emirp def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(11) == True def test_reverse_number(): assert reverse_number(123) == 321 assert reverse_number(400) == 4 asser...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Reverse the digits of a number.", "function_declaration": "def reverse_number(n):", "function_name": "reverse_number", ...
[ 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_prime(n):\n if n <= 1:\n return False\n if n == 2:\n return True \n if n % 2 == 0:\n return False\n for i in range(3, int(n**0.5) + 1,...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "0000032138", "row_id": 32138, "seed_ids": "['2048', '2168', '1275']" }
0.588152
Leetcode_32138
I
[ "is_prime", "reverse_number", "largest_emirp" ]
3
[ [ "largest_emirp", "is_prime" ], [ "largest_emirp", "reverse_number" ] ]
2
[]
false
[]
false
pytest
true
[]
true
bd1f2294b29f50780841f944ccccd2b5ab2ebeda
80fe6a84f9fa2eb66da56b5f1cd868ab878bb566
v1.0
instruct
Leetcode
Leetcode_32347_I
You are given a **doubly linked list** where each node contains an integer value and a pointer to the next node and the previous node. Write a function to merge a group of `k` sorted doubly linked lists into a single sorted doubly linked list. The function should efficiently merge the lists by repeatedly merging pairs ...
class ListNode: def __init__(self, val=0, prev=None, next=None): self.val = val self.prev = prev self.next = next def merge_two_lists(l1, l2): dummy = ListNode() curr = dummy while l1 and l2: if l1.val < l2.val: curr.next = l1 l1.prev = curr ...
from solution import ListNode, merge_k_lists def list_to_doubly_linked_list(lst): if not lst: return None head = ListNode(lst[0]) current = head for val in lst[1:]: new_node = ListNode(val) current.next = new_node new_node.prev = current current = new_node re...
[]
[ 1, 1, 0, 1, 1, 1, 1, 1, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "class ListNode:\n def __init__(self, value=0, next=None, prev=None):\n self.value = value\n self.next = next\n self.prev = prev\n\ndef merge_two_lists...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000032347", "row_id": 32347, "seed_ids": "['1932', '1678', '912']" }
0.541353
Leetcode_32347
I
[ "merge_two_lists", "merge_k_lists" ]
2
[ [ "merge_k_lists", "merge_two_lists" ] ]
1
[]
false
[ "ListNode" ]
true
pytest
true
[]
true
d177ee6058f7efc8cd9283f78e3f641a22b3257a
d6bc9fceda044c8095201d540625eb1f5889f138
v1.0
instruct
Leetcode
Leetcode_32598_I
You are given a binary tree with `n` nodes. Each node is uniquely assigned a value from `1` to `n`. All left and right child pointers in the tree are initially `null`. You are provided with a **0-indexed** 2D integer array `relations` where `relations[i] = [parenti, childi, isLefti]` indicates that `childi` is a left c...
class TreeNode: def __init__(self, value): self.value = value self.left = None self.right = None def add_child(parent, child, is_left, nodes): if is_left: parent.left = child else: parent.right = child nodes[child.value - 1] = child def find_max_depth_node(relat...
from solution import find_max_depth_node def test_single_node_tree(): relations = [] assert find_max_depth_node(relations) == -1 def test_two_node_tree(): relations = [[1, 2, 1]] assert find_max_depth_node(relations) == 2 def test_left_heavy_tree(): relations = [[1, 2, 1], [2, 3, 1], [3, 4, 1]] ...
[]
[ 1, 1, 1, 0, 1, 1, 0, 0, 0, 1 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, value):\n self.value = value\n self.left = None\n self.right = None\n\ndef findNodeWithMaxDepth(n, relations):\n ...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "0000032598", "row_id": 32598, "seed_ids": "['2201', '1872', '836']" }
0.570543
Leetcode_32598
I
[ "add_child", "find_max_depth_node" ]
2
[ [ "find_max_depth_node", "add_child" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
54e04dea466b1f76aa98400ff332829c810c2797
9996cd977f67e488797c0f1418213e4129764ded
v1.0
instruct
Leetcode
Leetcode_32648_I
You are given a binary tree where each node has a unique value. In one operation, you can swap the values of any two nodes in the tree. Your task is to determine the minimum number of swaps required to convert the binary tree into a Binary Search Tree (BST). Note that a BST is a binary tree where for each node, the va...
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def inorder_traversal(root): """ Performs in-order traversal on the binary tree and returns a list of node values. """ values = [] def traverse(node): ...
from solution import TreeNode, min_swaps_to_convert_to_bst def test_empty_tree(): assert min_swaps_to_convert_to_bst(None) == 0 def test_single_node_tree(): root = TreeNode(1) assert min_swaps_to_convert_to_bst(root) == 0 def test_already_bst_tree(): root = TreeNode(2, TreeNode(1), TreeNode(3)) a...
[]
[ 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 inorder_traversal(node, result):\n if node:\n inorder_traversal(node['left'], result)\n result.append(node['val'])\n inorder_traversal(node['right...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000032648", "row_id": 32648, "seed_ids": "['1819', '520', '670']" }
0.490271
Leetcode_32648
I
[ "inorder_traversal", "minimum_swaps_to_sort", "min_swaps_to_convert_to_bst" ]
3
[ [ "min_swaps_to_convert_to_bst", "inorder_traversal" ], [ "min_swaps_to_convert_to_bst", "minimum_swaps_to_sort" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
6fdff46a5bc6999bce8820b787222a413c47323a
a45f59b3019b90fd516161688c5e299d4dc20df4
v1.0
instruct
Leetcode
Leetcode_32864_I
You are given a string `s` that consists of only digits. We want to find the maximum sum of its substrings such that no two substrings overlap and each substring is a palindrome. Return the maximum sum you can achieve. A substring `s[i:j]` is a palindrome if it reads the same backward as forward.
def is_palindrome(s): return s == s[::-1] def max_sum_of_palindromic_substrings(s): n = len(s) dp = [0] * (n + 1) for i in range(1, n + 1): for j in range(i): if is_palindrome(s[j:i]): dp[i] = max(dp[i], dp[j] + int(s[j:i])) return dp[n]
from solution import max_sum_of_palindromic_substrings def test_single_digit(): assert max_sum_of_palindromic_substrings("5") == 5 def test_no_palindromes(): assert max_sum_of_palindromic_substrings("12345") == 15 # summing all individual digits def test_all_palindromes(): assert max_sum_of_palindromic_...
[ { "docstring": null, "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": null, "function_declaration": "def max_sum_of_palindromic_substrings(s):", "function_name": "max_sum_of_palindromic_substrings", "para...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_palindrome(s):\n return s == s[::-1]\n\ndef max_palindrome_sum(s):\n n = len(s)\n dp = [0] * (n + 1)\n \n for i in range(1, n + 1):\n for j in ra...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000032864", "row_id": 32864, "seed_ids": "['556', '765', '1145']" }
0.789441
Leetcode_32864
I
[ "is_palindrome", "max_sum_of_palindromic_substrings" ]
2
[ [ "max_sum_of_palindromic_substrings", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
151aba4db62a8af06e292e9609e70f3a4f1541bf
5a0e34ce6eda00e0fcbc3dae09a7143db607a4d5
v1.0
instruct
Leetcode
Leetcode_32934_I
You are given a binary tree where each node contains an integer value. The integer value of each node is unique. Remove the node with the specified value from the tree and return the root of the modified tree. If the node to be removed is not found, return the original tree. Note that the removal of a node may require ...
class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None def find_min(node): while node.left: node = node.left return node def delete_node(root, key): if root is None: return root if key < root.val: root.left = dele...
from solution import TreeNode, delete_node def build_tree(nodes): """ Helper function to build a tree from a list of tuples (parent_val, left_val, right_val) """ val_node_map = {} for parent_val, left_val, right_val in nodes: if parent_val not in val_node_map: val_node_map[parent_val] =...
[]
[ 1, 0, 1, 0, 1, 1, 1, 1, 0, 0 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\ndef find_min(node):\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "0000032934", "row_id": 32934, "seed_ids": "['391', '403', '2508']" }
0.599388
Leetcode_32934
I
[ "find_min", "delete_node" ]
2
[ [ "delete_node", "find_min" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
1c2b5511701aaa8b233ed8f2477a80605f905318
f27434ad55fb1edfbdd133595ee83986f91d5e57
v1.0
instruct
Leetcode
Leetcode_32943_I
You are given a list of strings, `words`, where each word can be considered a subword of another word if, after deleting some characters (possibly none) of the longer word, you get the shorter word. The goal is to find the longest possible sequence of words such that each successive word is a subword of the next word i...
def is_subword(shorter, longer): it = iter(longer) return all(char in it for char in shorter) def longest_subword_sequence(words): words.sort(key=len) dp = [1] * len(words) for i in range(len(words)): for j in range(i): if is_subword(words[j], words[i]) and dp[j] + 1 > dp[i]: ...
from solution import longest_subword_sequence def test_simple_case(): assert longest_subword_sequence(["a", "b", "ba", "bca", "bda", "bdca"]) == 4 def test_no_subwords(): assert longest_subword_sequence(["cat", "dog", "bird"]) == 1 def test_all_subwords(): assert longest_subword_sequence(["a", "at", "cat...
[ { "docstring": null, "function_declaration": "def is_subword(shorter, longer):", "function_name": "is_subword", "parameter_list": "(shorter, longer)" }, { "docstring": null, "function_declaration": "def longest_subword_sequence(words):", "function_name": "longest_subword_sequence", ...
[ 0, 0, 1, 0, 0, 1, 0, 0, 1, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def longest_subsequence(words):\n \"\"\"\n Find the length of the longest possible sequence such that each successive word is a subword of the next word in the sequence...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000032943", "row_id": 32943, "seed_ids": "['1688', '2171', '1059']" }
0.726002
Leetcode_32943
I
[ "is_subword", "longest_subword_sequence" ]
2
[ [ "longest_subword_sequence", "is_subword" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d73f45dd8490196d3e8eabb8bfad160eea615542
ed583aaa11fcbaedf0d5ea0b62d6bdfbe2fbc364
v1.0
instruct
Leetcode
Leetcode_33013_I
Given an integer array `arr`, your task is to modify the array such that all elements that are not powers of two are removed. Return the modified array sorted in ascending order. An integer is a power of two if it can be expressed as `2^k` where `k` is a non-negative integer. Note: - You may assume that the array con...
def is_power_of_two(n): """ Check if a number is a power of two. """ return (n != 0) and ((n & (n - 1)) == 0) def filter_powers_of_two(arr): """ Return a new list containing only the elements from the input list `arr` that are powers of two, sorted in ascending order. """ return sorted(...
from solution import filter_powers_of_two, is_power_of_two def test_is_power_of_two(): assert is_power_of_two(1) == True assert is_power_of_two(2) == True assert is_power_of_two(3) == False assert is_power_of_two(4) == True assert is_power_of_two(5) == False assert is_power_of_two(16) == True ...
[ { "docstring": "Check if a number is a power of two.", "function_declaration": "def is_power_of_two(n):", "function_name": "is_power_of_two", "parameter_list": "(n)" }, { "docstring": "Return a new list containing only the elements from the input list `arr` that are powers of two, sorted in ...
[ 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_power_of_two(n):\n \"\"\"\n Checks if the given number n is a power of two.\n \"\"\"\n return (n > 0) and (n & (n - 1) == 0)\n\ndef filter_and_sort_powers_...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000033013", "row_id": 33013, "seed_ids": "['98', '1220', '2256']" }
0.626325
Leetcode_33013
I
[ "is_power_of_two", "filter_powers_of_two" ]
2
[ [ "filter_powers_of_two", "is_power_of_two" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d0a9a02d9d5d47667c5ae16c480a2b9a8244b75c
6f538c41aa3f0d99f2e031f2471e1ece37c1fbaf
v1.0
instruct
Leetcode
Leetcode_33120_I
You have a list of non-negative integers, `nums`, and you are tasked with forming a string by concatenating the integers in such a way that it yields the largest possible numerical value. Return the largest numerical value that can be obtained from concatenating the integers in `nums`. For example, given `nums = [3, ...
from functools import cmp_to_key def compare(x, y): """ Custom comparator to decide the order of numbers based on concatenation result. """ if x + y > y + x: return -1 elif x + y < y + x: return 1 else: return 0 def largest_number(nums): """ Returns the largest ...
from solution import largest_number def test_largest_number_example(): assert largest_number([3, 30, 34, 5, 9]) == "9534330" def test_largest_number_single_digit(): assert largest_number([1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) == "9876543210" def test_largest_number_identical_numbers(): assert largest_number([1,...
[ { "docstring": "Custom comparator to decide the order of numbers based on concatenation result.", "function_declaration": "def compare(x, y):", "function_name": "compare", "parameter_list": "(x, y)" }, { "docstring": "Returns the largest numerical value that can be obtained from concatenatin...
[ 0, 1, 1, 0, 1, 0, 0, 0, 1, 0 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "from functools import cmp_to_key\n\ndef largest_number(nums):\n \"\"\"\n Forms the largest possible numerical value by concatenating the integers in the list `nums`.\n ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000033120", "row_id": 33120, "seed_ids": "['265', '406', '301']" }
0.699321
Leetcode_33120
I
[ "compare", "largest_number" ]
2
[ [ "largest_number", "compare" ] ]
1
[]
false
[]
false
pytest
true
[]
true
bb0ca7e151ab541285516c8fb18b53bcd8f52e07
00f0b921bb7fd60bdcbcaac2dffd150ac70b1b2c
v1.0
instruct
Leetcode
Leetcode_33179_I
You are given a list of strings `patterns` and a single string `s`. A string is considered a subsequence of another string if it can be derived from the other string by deleting some characters without changing the order of the remaining characters. Your task is to determine how many strings in `patterns` are subsequen...
def is_subsequence(small, large): it = iter(large) return all(char in it for char in small) def count_subsequences(patterns, s): count = 0 for pattern in patterns: if is_subsequence(pattern, s): count += 1 return count
from solution import is_subsequence, count_subsequences def test_is_subsequence(): assert is_subsequence("abc", "aabbcc") == True assert is_subsequence("abc", "acb") == False assert is_subsequence("abc", "abacbc") == True assert is_subsequence("", "anything") == True assert is_subsequence("longsequ...
[ { "docstring": null, "function_declaration": "def is_subsequence(small, large):", "function_name": "is_subsequence", "parameter_list": "(small, large)" }, { "docstring": null, "function_declaration": "def count_subsequences(patterns, s):", "function_name": "count_subsequences", "...
[ 0, 1, 0, 0, 0, 1, 0, 0, 1, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_subsequence(pattern, s):\n \"\"\"\n Helper function to check if `pattern` is a subsequence of `s`.\n \"\"\"\n it = iter(s)\n return all(char in it for c...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000033179", "row_id": 33179, "seed_ids": "['1820', '1599', '594']" }
0.779158
Leetcode_33179
I
[ "is_subsequence", "count_subsequences" ]
2
[ [ "count_subsequences", "is_subsequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e7e2750990e4723af593ea9a4154f85ac2fd26ff
2fda68d61089681f6c210ada452e36355eb5a803
v1.0
instruct
Leetcode
Leetcode_33261_I
You have a string `s` consisting of lowercase alphabets and a list of words `words` where each word is a substring of `s`. Your task is to find the number of words in the list that can be formed by deleting some (possibly none) characters of `s` without reordering the remaining characters. Return _the **count** of suc...
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 count_matching_subsequences(s, words): """ Returns count of words in 'words' list that can be formed by deleting some characters of '...
from solution import count_matching_subsequences def test_example_case(): assert count_matching_subsequences("abcde", ["a", "bb", "acd", "aces"]) == 2 def test_no_matching_words(): assert count_matching_subsequences("abcdef", ["gh", "ij", "kl"]) == 0 def test_empty_string(): assert count_matching_subsequ...
[ { "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 count of words in 'words' list that can be formed\nby deleting som...
[ 1, 0, 0, 1, 1, 1, 0, 0, 0, 0 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def num_matching_subseq(s, words):\n \"\"\"\n Returns the count of words in the list that can be formed by deleting some (possibly none) \n characters of the string ...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "0000033261", "row_id": 33261, "seed_ids": "['1354', '2235', '2284']" }
0.732038
Leetcode_33261
I
[ "is_subsequence", "count_matching_subsequences" ]
2
[ [ "count_matching_subsequences", "is_subsequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e7d5a41a3e29c91cae6750d459a7948191219af5
f123c371efe8e8e0d21d251a3ef9e110bf287654
v1.0
instruct
Leetcode
Leetcode_33410_I
You are given an array of strings `words` and a string `target`. Each word in `words` matches the pattern of the `target` if replacing all instances of one character in the `target` with another character consistently throughout the string results in one of the commands in `words`. For example, with the target "abb", "...
def matches_pattern(word: str, pattern: str) -> bool: if len(word) != len(pattern): return False char_map_word = {} char_map_pattern = {} for w_char, p_char in zip(word, pattern): if w_char in char_map_word: if char_map_word[w_char] != p_char: return...
from solution import find_and_replace_pattern def test_find_and_replace_pattern(): assert find_and_replace_pattern(["abc", "deq", "mee", "aqq", "dkd", "ccc"], "abb") == ["mee", "aqq"] assert find_and_replace_pattern(["xyz", "apa", "opq"], "aba") == ["apa"] assert find_and_replace_pattern(["aa", "bb", "cc"]...
[ { "docstring": null, "function_declaration": "def matches_pattern(word, pattern):", "function_name": "matches_pattern", "parameter_list": "(word, pattern)" }, { "docstring": "Returns an array of words that match the target pattern.", "function_declaration": "def find_and_replace_pattern(...
[ 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 find_and_replace_pattern(words, target):\n \"\"\"\n Returns a list of words that match the pattern of the target string.\n \"\"\"\n \n def matches_pattern(...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000033410", "row_id": 33410, "seed_ids": "['506', '155', '253']" }
0.669187
Leetcode_33410
I
[ "matches_pattern", "find_and_replace_pattern" ]
2
[ [ "find_and_replace_pattern", "matches_pattern" ] ]
1
[]
false
[]
false
pytest
true
[]
true
23c0a1af02eb507c1bf1798f0eb463f098876a2f
9481b3225227b12ae8864b2b8c8ac3081bec0e51
v1.0
instruct
Leetcode
Leetcode_33432_I
Given a list of integers `nums` and an integer `k`, return the root of a binary search tree (BST) constructed from `nums` such that the tree contains exactly `k` nodes and the sum of the values of all nodes in the tree is as close as possible to the sum of the first `k` elements of the sorted version of `nums`. If ther...
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def build_balanced_bst(sorted_nums, start, end): if start > end: return None mid = (start + end) // 2 node = TreeNode(sorted_nums[mid]) node.left = bu...
from solution import closest_bst, TreeNode def in_order_traversal(root): return (in_order_traversal(root.left) if root.left else []) + [root.val] + (in_order_traversal(root.right) if root.right else []) def find_sum(root): if not root: return 0 return root.val + find_sum(root.left) + find_sum(root...
[]
[ 1, 0, 1, 0, 1, 0, 0, 1, 1, 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 \"\"\"\n Definition for a binary tree node.\n \"\"\"\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.l...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000033432", "row_id": 33432, "seed_ids": "['1368', '298', '1228']" }
0.519427
Leetcode_33432
I
[ "build_balanced_bst", "closest_bst" ]
2
[ [ "closest_bst", "build_balanced_bst" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
de4912d18dba003f6aa9d23a980458a420a16501
6f26d71983c2a19a48b71d4b15df3bbb76bdf3d6
v1.0
instruct
Leetcode
Leetcode_33484_I
You are given a **0-indexed** matrix `mat` of `m` rows and `n` columns consisting of non-negative integers. A magic square is a `3x3` square submatrix such that the sum of each row, column, and both diagonals are equal. Your task is to determine the number of `3x3` magic squares present in the given matrix `mat`. Ret...
def is_magic(square): s = sum(square[0]) return all(sum(row) == s for row in square) and \ all(sum(square[i][j] for i in range(3)) == s for j in range(3)) and \ sum(square[i][i] for i in range(3)) == s and \ sum(square[i][2-i] for i in range(3)) == s def numMagicSquaresInside(g...
from solution import numMagicSquaresInside def test_no_magic_square(): assert numMagicSquaresInside([ [5, 5, 5], [5, 5, 5], [5, 5, 5] ]) == 0 def test_one_magic_square(): assert numMagicSquaresInside([ [4, 3, 8, 4], [9, 5, 1, 9], [2, 7, 6, 2], [1, 5,...
[ { "docstring": null, "function_declaration": "def is_magic(square):", "function_name": "is_magic", "parameter_list": "(square)" }, { "docstring": null, "function_declaration": "def numMagicSquaresInside(grid):", "function_name": "numMagicSquaresInside", "parameter_list": "(grid)"...
[ 0, 0, 0, 0, 0, 1, 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 numMagicSquaresInside(mat):\n def isMagic(square):\n s = sum(square[0])\n return (all(sum(row) == s for row in square)\n and all(sum(squar...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "0000033484", "row_id": 33484, "seed_ids": "['1960', '2601', '761']" }
0.658384
Leetcode_33484
I
[ "is_magic", "numMagicSquaresInside" ]
2
[ [ "numMagicSquaresInside", "is_magic" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7672c8afaf2d34836c294b49f53fbd73d9c73ff4
b1c85d4ba9806de01ca759a6856b7766557a0412
v1.0
instruct
Leetcode
Leetcode_33578_I
You are given a list of strings `wordList` of length `n` and a target string `targetWord`. Each word in `wordList` has the same length as `targetWord`. You need to transform `targetWord` into another word by changing exactly one character at a time. Each transformed word must exist in `wordList`. Your task is to deter...
from collections import deque def is_one_char_different(word1, word2): """ Helper function to determine if two words differ by exactly one character. """ if len(word1) != len(word2): return False diff_count = sum(1 for a, b in zip(word1, word2) if a != b) return diff_count == 1 def min...
import pytest from solution import minTransformations def test_no_possible_transformation(): wordList = ["hot", "dot", "dog", "lot", "log"] targetWord = "hit" assert minTransformations(wordList, targetWord) == -1 def test_single_transformation(): wordList = ["hot", "dot", "dog", "lot", "log"] targ...
[ { "docstring": "Helper function to determine if two words differ by exactly one character.", "function_declaration": "def is_one_char_different(word1, word2):", "function_name": "is_one_char_different", "parameter_list": "(word1, word2)" }, { "docstring": "Returns the minimum number of trans...
[ 0, 0, 1, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "import collections\nfrom typing import List\n\ndef minTransformations(wordList: List[str], targetWord: str) -> int:\n wordSet = set(wordList)\n if targetWord not in wor...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "0000033578", "row_id": 33578, "seed_ids": "['799', '924', '641']" }
0.672643
Leetcode_33578
I
[ "is_one_char_different", "minTransformations" ]
2
[ [ "minTransformations", "is_one_char_different" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a6c227695546e51d3c0279ae8486f142338a1248
62e93fcc45643fcccd66b4cc054cd97b527461e2
v1.0
instruct
Leetcode
Leetcode_33620_I
You are given an array of positive integers representing job durations, `jobs`, where `jobs[i]` is the duration of the `i-th` job in hours. Additionally, you are given an integer `days`, which represents the number of days you have to complete all the jobs. Each day, you can decide the order in which you tackle the job...
def canComplete(jobs, days, max_hours): current_hours = 0 required_days = 1 for job in jobs: if current_hours + job > max_hours: required_days += 1 current_hours = 0 current_hours += job return required_days <= days def minMaxHours(jobs, days): left, right = ...
from solution import minMaxHours def test_minMaxHours_single_job_per_day(): assert minMaxHours([3, 3, 3], 3) == 3 def test_minMaxHours_multiple_jobs_single_day(): assert minMaxHours([1, 2, 3, 4, 5], 1) == 15 def test_minMaxHours_jobs_distribution(): assert minMaxHours([7, 2, 5, 10, 8], 2) == 18 asser...
[ { "docstring": null, "function_declaration": "def canComplete(jobs, days, max_hours):", "function_name": "canComplete", "parameter_list": "(jobs, days, max_hours)" }, { "docstring": null, "function_declaration": "def minMaxHours(jobs, days):", "function_name": "minMaxHours", "par...
[ 0, 0, 0, 1, 0, 1, 0, 0 ]
2
hard
0.25
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def min_max_workload(jobs, days):\n \"\"\"\n Returns the minimum possible maximum number of hours worked on any single day to complete all jobs within given days.\n ...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "0000033620", "row_id": 33620, "seed_ids": "['1996', '2187', '921']" }
0.696414
Leetcode_33620
I
[ "canComplete", "minMaxHours" ]
2
[ [ "minMaxHours", "canComplete" ] ]
1
[]
false
[]
false
pytest
true
[]
true
250cec25698bf0c8c2c0a3d46ac28caaedd6d9c2
206dcdf81b6d7c6a81a683995b01e8ad654c4473
v1.0
instruct
Leetcode
Leetcode_33649_I
You are given an array of strings `words` and a prefix string `pref`. You may perform the following operation any number of times: * Choose any word `w` from `words` and remove a single character from `w`. Your goal is to determine if it is possible to make at least one of the words start with the prefix `pref` a...
def can_form_prefix(words, pref): """ Checks if it is possible to make at least one of the words start with the prefix `pref` after removing any number of characters from the words. """ # Sorting the prefix itself due to the operation: Letters are arbitrary in positions pref_sorted = sorted(pre...
from solution import can_form_prefix def test_can_form_prefix_true_case(): assert can_form_prefix(["apple", "banana", "cherry"], "ape") == True def test_can_form_prefix_false_case(): assert can_form_prefix(["apple", "banana", "cherry"], "xyz") == False def test_can_form_prefix_prefix_longer_than_word(): ...
[ { "docstring": "Checks if it is possible to make at least one of the words start with the prefix `pref` \nafter removing any number of characters from the words.", "function_declaration": "def can_form_prefix(words, pref):", "function_name": "can_form_prefix", "parameter_list": "(words, pref)" }, ...
[ 0, 1, 0, 0, 0, 0, 0, 1, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def can_form_prefix(words, pref):\n \"\"\"\n Determines if it is possible to make at least one of the words start with the prefix `pref`\n after removing a single ch...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "0000033649", "row_id": 33649, "seed_ids": "['1969', '2565', '2452']" }
0.691538
Leetcode_33649
I
[ "can_form_prefix", "can_form_from" ]
2
[ [ "can_form_prefix", "can_form_from" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ddaf54a9c6a50889bd302221fd9ebd2f04c63987
803603f5a6d8ea5b27d6916e3cdbd527c61f1539
v1.0
instruct
Leetcode
Leetcode_33761_I
You are given a list of integers `arr` representing a set of targets and an integer `k`. You can perform the following operation any number of times: choose two indices `i` and `j` (i ≠ j) and replace `arr[i]` with `arr[i] + arr[j]`. The goal is to determine whether you can reach exactly `k` using these operations. If ...
def can_reach_k(arr, k): """ Determines whether it is possible to reach exactly `k` by choosing two indices `i` and `j` and replacing `arr[i]` with `arr[i] + arr[j]` any number of times. """ if k in arr: return True return k % gcd_list(arr) == 0 def gcd(a, b): while b: a, b ...
from solution import can_reach_k def test_can_reach_k_case1(): arr = [2, 6] k = 8 assert can_reach_k(arr, k) == True def test_can_reach_k_case2(): arr = [2, 4] k = 7 assert can_reach_k(arr, k) == False def test_can_reach_k_case3(): arr = [3, 9, 27] k = 6 assert can_reach_k(arr, k)...
[ { "docstring": "Determines whether it is possible to reach exactly `k` by choosing two indices `i` and `j`\nand replacing `arr[i]` with `arr[i] + arr[j]` any number of times.", "function_declaration": "def can_reach_k(arr, k):", "function_name": "can_reach_k", "parameter_list": "(arr, k)" }, { ...
[ 0, 0, 0, 0, 0, 0, 1, 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_reach_target(arr, k):\n \"\"\"\n Determines if we can reach exactly k using the given operations on the list arr.\n \n Args:\n arr (list of int): List ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000033761", "row_id": 33761, "seed_ids": "['1391', '1496', '1125']" }
0.67715
Leetcode_33761
I
[ "can_reach_k", "gcd", "gcd_list" ]
3
[ [ "can_reach_k", "gcd_list" ], [ "gcd_list", "gcd" ] ]
2
[]
false
[]
false
pytest
true
[]
true
0edd0a13b084523ed1f135d929e40c2b2b4bd4b9
fc832a2b41a1a53bcfb8bf8194085e49b1f86c57
v1.0
instruct
Leetcode
Leetcode_33765_I
You are given an array `positions` where `positions[i] = [xi, yi]` represents a position on a 2D plane. Your task is to determine the maximum number of non-overlapping squares that can be formed using these positions as their vertices. A square is formed by four positions `(x1, y1)`, `(x2, y2)`, `(x3, y3)`, and `(x4, y...
def distance(p1, p2): return (p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2 def is_square(p1, p2, p3, p4): d = [distance(p1, p2), distance(p1, p3), distance(p1, p4), distance(p2, p3), distance(p2, p4), distance(p3, p4)] d.sort() return d[0] > 0 and d[0] == d[1] and d[2] == d[3] and d[4] == d[5] a...
from solution import max_non_overlapping_squares def test_max_non_overlapping_squares_no_squares(): positions = [[0, 0], [1, 1], [2, 2], [3, 3]] assert max_non_overlapping_squares(positions) == 0 def test_max_non_overlapping_squares_one_square(): positions = [[0, 0], [0, 1], [1, 0], [1, 1]] assert max...
[ { "docstring": null, "function_declaration": "def distance(p1, p2):", "function_name": "distance", "parameter_list": "(p1, p2)" }, { "docstring": null, "function_declaration": "def is_square(p1, p2, p3, p4):", "function_name": "is_square", "parameter_list": "(p1, p2, p3, p4)" }...
[ 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 count_squares(positions):\n \"\"\"\n Returns the maximum number of non-overlapping squares that can be formed using the positions as vertices.\n\n :param positio...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "0000033765", "row_id": 33765, "seed_ids": "['587', '2522', '1705']" }
0.654144
Leetcode_33765
I
[ "distance", "is_square", "max_non_overlapping_squares" ]
3
[ [ "is_square", "distance" ], [ "max_non_overlapping_squares", "is_square" ] ]
2
[]
false
[]
false
pytest
true
[]
true
7910f4bf93961fdc417e653723f70dae5588e893
ead42c9353f6443af763b8573eefd35606abd061
v1.0
instruct
Leetcode
Leetcode_33772_I
You are given an integer array `arr` and an integer `k`. The task is to determine whether there exists a subarray of length exactly `k` such that the sum of the elements in the subarray is a prime number. Return _true_ if such a subarray exists, and _false_ otherwise. A **subarray** is a contiguous part of the array.
def is_prime(n): if n <= 1: return False if n == 2: return True if n % 2 == 0: return False for i in range(3, int(n**0.5) + 1, 2): if n % i == 0: return False return True def subarray_sum_is_prime(arr, k): n = len(arr) if k > n: return Fal...
from solution import subarray_sum_is_prime def test_prime_sum_exists(): assert subarray_sum_is_prime([2, 3, 1, 6, 4], 2) == True def test_prime_sum_not_exists(): assert subarray_sum_is_prime([8, 8, 8, 8, 8], 3) == False def test_single_element_prime(): assert subarray_sum_is_prime([7], 1) == True def te...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def subarray_sum_is_prime(arr, k):", "function_name": "subarray_sum_is_prime", "parameter_list": "(arr, k)" } ]
[ 0, 1, 0, 0, 0, 1, 0, 0, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"Helper function to check if a number is prime.\"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "0000033772", "row_id": 33772, "seed_ids": "['310', '2607', '1061']" }
0.587674
Leetcode_33772
I
[ "is_prime", "subarray_sum_is_prime" ]
2
[ [ "subarray_sum_is_prime", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e8ff555c44ef11320c58eb45221035eb1f579f21
01d65f9e417232326703d5badd9a16e5e51b80dc
v1.0
instruct
Leetcode
Leetcode_33794_I
Given an integer `n`, return the smallest prime number that is greater than `n`. A prime number is a natural number greater than 1 that is not divisible by any number other than 1 and itself. Use an efficient algorithm to handle large values of `n`.
def is_prime(n): """ Returns True if n is a prime number, otherwise False. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False ...
def test_next_prime(): assert next_prime(1) == 2 assert next_prime(2) == 3 assert next_prime(3) == 5 assert next_prime(10) == 11 assert next_prime(14) == 17 assert next_prime(20) == 23 assert next_prime(30) == 31 assert next_prime(100) == 101 assert next_prime(200) == 211 def test_i...
[ { "docstring": "Returns True if n is a prime number, otherwise False.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns the smallest prime number greater than n.", "function_declaration": "def next_prime(n):", ...
[ 1, 1, 1, 1, 1, 1, 1, 0, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"\n Helper function to determine if a number is a prime number.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n ...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "0000033794", "row_id": 33794, "seed_ids": "['1855', '853', '1400']" }
0.583923
Leetcode_33794
I
[ "is_prime", "next_prime" ]
2
[ [ "next_prime", "is_prime" ] ]
1
[]
false
[]
false
pytest
false
[]
true
129a003eda4fe46258a0efb7acd13e88e46d8a3c
e755c8807e857c378f54ea2a3650f36989e22380
v1.0
instruct
Leetcode
Leetcode_33918_I
You are given two string arrays `words1` and `words2`. A string `b` is a **subsequence** of a string `a` if `b` can be obtained from `a` by deleting some number of characters (possibly zero), without rearranging the remaining characters. Determine the count of strings in `words1` that are subsequences of any string in ...
def is_subsequence(small, large): """ Helper function to determine if 'small' is a subsequence of 'large'. """ it = iter(large) return all(char in it for char in small) def count_subsequences(words1, words2): """ Counts the number of strings in words1 which are subsequences of any strings i...
from solution import count_subsequences def test_example_case(): words1 = ["abc", "de", "f", "gh"] words2 = ["abcd", "efghi"] assert count_subsequences(words1, words2) == 3 def test_empty_words1(): words1 = [] words2 = ["abcd", "efghi"] assert count_subsequences(words1, words2) == 0 def test_...
[ { "docstring": "Helper function to determine if 'small' is a subsequence of 'large'.", "function_declaration": "def is_subsequence(small, large):", "function_name": "is_subsequence", "parameter_list": "(small, large)" }, { "docstring": "Counts the number of strings in words1 which are subseq...
[ 0, 0, 0, 0, 1, 1, 0, 0, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_subsequence(s, t):\n \"\"\"\n Helper function to determine if string `s` is a subsequence of string `t`.\n \"\"\"\n it = iter(t)\n return all(char in it...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "0000033918", "row_id": 33918, "seed_ids": "['1889', '1537', '1426']" }
0.719583
Leetcode_33918
I
[ "is_subsequence", "count_subsequences" ]
2
[ [ "count_subsequences", "is_subsequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ff6ee38ac4fdbc31538a9de550ac8edf5dda939f
6b8b44624f0f1c82ea4ee5f827dc52fa4372d4a6
v1.0
instruct
Leetcode
Leetcode_33954_I
You are given a list of `n` friends numbered from `0` to `n-1`. Each friend is represented by a pair `(xi, yi)` which indicates their position on a 2D grid. You are also given an integer `k`. The goal is to find the **k-th closest pair** of friends based on the **Euclidean distance** between each pair. If there are mul...
import math from itertools import combinations def euclidean_distance(p1, p2): """ Calculate the Euclidean distance between two points p1 and p2. """ return math.sqrt((p1[0] - p2[0])**2 + (p1[1] - p2[1])**2) def kth_closest_pair(friends, k): """ Find the k-th closest pair of friends based on t...
from solution import kth_closest_pair def test_kth_closest_pair_case_1(): friends = [(0, 0), (1, 1), (2, 2)] assert kth_closest_pair(friends, 1) == [0, 1] def test_kth_closest_pair_case_2(): friends = [(0, 0), (1, 1), (2, 2)] assert kth_closest_pair(friends, 2) == [1, 2] def test_kth_closest_pair_cas...
[ { "docstring": "Calculate the Euclidean distance between two points p1 and p2.", "function_declaration": "def euclidean_distance(p1, p2):", "function_name": "euclidean_distance", "parameter_list": "(p1, p2)" }, { "docstring": "Find the k-th closest pair of friends based on the Euclidean dist...
[ 0, 0, 1, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "import math\nfrom itertools import combinations\n\ndef euclidean_distance(pos1, pos2):\n \"\"\"\n Calculate the Euclidean distance between two points pos1 and pos2.\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "0000033954", "row_id": 33954, "seed_ids": "['1057', '1208', '2320']" }
0.628282
Leetcode_33954
I
[ "euclidean_distance", "kth_closest_pair" ]
2
[ [ "kth_closest_pair", "euclidean_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
16f172a4308feda465e4b756dde039b1f929b911
71781ecc29d169133ee0ed7eaffe1af5a39d0e89
v1.0
instruct
Leetcode
Leetcode_34048_I
You are given a binary tree where each node represents a different unique integer value. The distance between two nodes in the tree is defined as the number of edges in the path connecting them. Given the root of the tree and two integers `x` and `y`, find the minimum distance between the nodes with these values. If ei...
class TreeNode: def __init__(self, value=0, left=None, right=None): self.value = value self.left = left self.right = right def find_lca(root, x, y): if not root: return None if root.value == x or root.value == y: return root left_lca = find_lca(root.left, x, y) ...
def test_find_minimum_distance(): # Create the tree # 1 # / \ # 2 3 # / \ \ # 4 5 6 root = TreeNode(1) root.left = TreeNode(2) root.right = TreeNode(3) root.left.left = TreeNode(4) root.left.right = TreeNode(5) root.right.right = TreeNode(6) ...
[]
[ 1, 1, 1, 0, 1, 1, 1, 1, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\ndef findDistance(root,...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "0000034048", "row_id": 34048, "seed_ids": "['2364', '2461', '1222']" }
0.609626
Leetcode_34048
I
[ "find_lca", "find_distance_from_lca", "find_minimum_distance" ]
3
[ [ "find_minimum_distance", "find_distance_from_lca" ], [ "find_minimum_distance", "find_lca" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
false
[]
true
45f1d26a8f961aa1d36fe401a48296a119f77e30
a3b5c8c69299c5a0d6e5e0e6803db47fe12c1e19
v1.0
instruct
Leetcode
Leetcode_34127_I
There are `n` distinct points on a 2D plane, each represented by an array `points` where `points[i] = [xi, yi]` indicates that there is a point at coordinates `(xi, yi)`. Your task is to determine the pair of points that are closest to each other, and return the **Manhattan distance** between these points. The **Manhat...
def manhattan_distance(point1, point2): """ Returns the Manhattan distance between two points. """ return abs(point1[0] - point2[0]) + abs(point1[1] - point2[1]) def closest_pair(points): """ Returns the Manhattan distance of the closest pair of points. """ min_distance = float('inf') ...
from solution import closest_pair def test_closest_pair_basic(): points = [[1, 2], [4, 6], [1, 3]] assert closest_pair(points) == 1 def test_closest_pair_multiple_points(): points = [[0, 0], [0, 2], [0, 4], [2, 0]] assert closest_pair(points) == 2 def test_closest_pair_same_points(): points = [[1...
[ { "docstring": "Returns the Manhattan distance between two points.", "function_declaration": "def manhattan_distance(point1, point2):", "function_name": "manhattan_distance", "parameter_list": "(point1, point2)" }, { "docstring": "Returns the Manhattan distance of the closest pair of points....
[ 1, 0, 1, 0, 1, 0, 0, 0, 1, 0 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def manhattan_distance(point1, point2):\n \"\"\"\n Helper function to calculate the Manhattan distance between two points.\n \"\"\"\n return abs(point1[0] - point...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "0000034127", "row_id": 34127, "seed_ids": "['1894', '345', '767']" }
0.774419
Leetcode_34127
I
[ "manhattan_distance", "closest_pair" ]
2
[ [ "closest_pair", "manhattan_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f2fa8e5156808e7a9740b01801c2205c6833112b
5f6cb342d60993c15cb35c2f47d99adcd4b48bac
v1.0
instruct
Leetcode
Leetcode_34133_I
Given a non-negative integer `n`, your task is to generate a list of all possible **unique palindrome permutations** of the string representation of `n`. A palindrome is a string that reads the same backward as forward, and a permutation is a rearrangement of its characters. Return the list of palindrome permutations i...
from collections import Counter from itertools import permutations def can_form_palindrome(s): """ Returns True if the string s can be rearranged into a palindrome, False otherwise. """ counts = Counter(s) odd_count = sum(1 for count in counts.values() if count % 2 == 1) return odd_count <= 1 ...
from solution import generate_palindrome_permutations def test_no_palindrome_permutations(): assert generate_palindrome_permutations(123) == [] def test_single_digit(): assert generate_palindrome_permutations(1) == ['1'] def test_two_same_digits(): assert generate_palindrome_permutations(11) == ['11'] d...
[ { "docstring": "Returns True if the string s can be rearranged into a palindrome, False otherwise.", "function_declaration": "def can_form_palindrome(s):", "function_name": "can_form_palindrome", "parameter_list": "(s)" }, { "docstring": "Given a non-negative integer n, returns a list of all...
[ 0, 0, 1, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "from collections import Counter\nfrom itertools import permutations\n\ndef palindrome_permutations(n):\n def can_form_palindrome(counter):\n odd_count = sum(1 for c...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "0000034133", "row_id": 34133, "seed_ids": "['2596', '272', '173']" }
0.707405
Leetcode_34133
I
[ "can_form_palindrome", "generate_palindrome_permutations" ]
2
[ [ "generate_palindrome_permutations", "can_form_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f90aa83927f1ba294ed5d2dac40c80d9f33d1980
22386b0ec179bf729c1355406cd305c0a9d137b2
v1.0
instruct
Leetcode
Leetcode_34152_I
Given a list of integers `nums` and an integer `k`, where `k` is guaranteed to be smaller than the length of the list, find the `k`-th largest element in the list. Note that it is the `k`-th largest element in the sorted order, not the `k`-th distinct element. You must solve it in `O(n)` average time complexity.
import random def partition(nums, left, right): pivot_index = random.randint(left, right) pivot_value = nums[pivot_index] nums[pivot_index], nums[right] = nums[right], nums[pivot_index] store_index = left for i in range(left, right): if nums[i] < pivot_value: nums[i], nums[store...
from solution import find_kth_largest def test_example_case(): assert find_kth_largest([3, 2, 1, 5, 6, 4], 2) == 5 def test_single_element(): assert find_kth_largest([1], 1) == 1 def test_sorted_array(): assert find_kth_largest([1, 2, 3, 4, 5], 4) == 2 def test_reversed_array(): assert find_kth_larg...
[ { "docstring": null, "function_declaration": "def partition(nums, left, right):", "function_name": "partition", "parameter_list": "(nums, left, right)" }, { "docstring": null, "function_declaration": "def quick_select(nums, left, right, k):", "function_name": "quick_select", "par...
[ 1, 1, 1, 0, 1, 1, 1, 1, 0 ]
7
easy
0.778
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "import random\n\ndef partition(nums, left, right, pivot_index):\n pivot_value = nums[pivot_index]\n nums[pivot_index], nums[right] = nums[right], nums[pivot_index]\n ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000034152", "row_id": 34152, "seed_ids": "['1397', '333', '1124']" }
0.650579
Leetcode_34152
I
[ "partition", "quick_select", "find_kth_largest" ]
3
[ [ "find_kth_largest", "quick_select" ], [ "quick_select", "partition" ] ]
2
[]
false
[]
false
pytest
true
[]
true
835b80cb0f1f08c34676a35411a7d2a467a1ef16
54002933978f52dd4512a2d8386a3a8ae4328e52
v1.0
instruct
Leetcode
Leetcode_34449_I
You are given an integer array `nums` where each element is unique and represents a node value in a binary search tree (BST). Construct the BST by inserting the values in the order they appear in `nums`, and then calculate the height of the BST. The height of a BST is the number of edges in the longest path from the ro...
class TreeNode: def __init__(self, value=0): self.value = value self.left = None self.right = None def insert_into_bst(root, value): if root is None: return TreeNode(value) if value < root.value: root.left = insert_into_bst(root.left, value) else: root.ri...
from solution import bst_height def test_bst_height_single_element(): assert bst_height([10]) == 0 def test_bst_height_sorted_ascending(): assert bst_height([1, 2, 3, 4, 5]) == 4 def test_bst_height_sorted_descending(): assert bst_height([5, 4, 3, 2, 1]) == 4 def test_bst_height_mixed_order(): asser...
[]
[ 1, 1, 0, 1, 1, 1, 1, 1, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, value):\n self.value = value\n self.left = None\n self.right = None\n\ndef insert_into_bst(root, value):\n if ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000034449", "row_id": 34449, "seed_ids": "['2222', '949', '2477']" }
0.570583
Leetcode_34449
I
[ "insert_into_bst", "calculate_height", "bst_height" ]
3
[ [ "bst_height", "calculate_height" ], [ "bst_height", "insert_into_bst" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
b2ed769734f7f39217588c11d1b0a4ceb787c0cd
0c188c0dedeb44bdcff5b3b9c78b0eff303594c4
v1.0
instruct
Leetcode
Leetcode_34481_I
Given an array of integers `nums`, where `nums[i]` represents a different job's duration, and an integer `d` which represents the maximum number of days you have to complete all the jobs. Your goal is to minimize the maximum job duration that you need to work over the days. Return the minimum possible maximum job durat...
from typing import List def is_valid(nums: List[int], days: int, max_job_duration: int) -> bool: day_count = 1 current_duration = 0 for num in nums: if current_duration + num > max_job_duration: day_count += 1 current_duration = 0 current_duration += num if d...
from solution import min_job_duration def test_min_job_duration_single_day(): assert min_job_duration([7, 2, 5, 10, 8], 1) == 32 # Sum of all jobs def test_min_job_duration_multiple_days(): assert min_job_duration([7, 2, 5, 10, 8], 2) == 18 assert min_job_duration([7, 2, 5, 10, 8], 3) == 14 assert mi...
[ { "docstring": null, "function_declaration": "def is_valid(nums, days, max_job_duration):", "function_name": "is_valid", "parameter_list": "(nums, days, max_job_duration)" }, { "docstring": null, "function_declaration": "def min_job_duration(nums, days):", "function_name": "min_job_d...
[ 0, 0, 0, 0, 1, 0, 0, 1, 1, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def min_max_job_duration(nums, d):\n def possible(max_job_duration):\n days_needed = 1\n current_total = 0\n for duration in nums:\n if cur...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000034481", "row_id": 34481, "seed_ids": "['1790', '366', '823']" }
0.677501
Leetcode_34481
I
[ "is_valid", "min_job_duration" ]
2
[ [ "min_job_duration", "is_valid" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b458bc07272aa4679ae02d03bc1d1a623601e233
5b0c8c68307835ca38ab29c67627972c62009f69
v1.0
instruct
Leetcode
Leetcode_34551_I
You are given an array `houses` and an integer `heaters`. Each element in `houses` represents the position of a house along a street, and each element in `heaters` represents the position of a heater along the street. Both arrays are sorted in ascending order. Every house can only be warmed by the nearest heater. Retur...
def find_closest_heater(house, heaters): """ Returns the minimum distance from the house to the nearest heater using binary search. """ left, right = 0, len(heaters) - 1 while left < right: mid = (left + right) // 2 if heaters[mid] < house: left = mid + 1 else: ...
from solution import find_min_radius def test_example_case_1(): houses = [1, 2, 3] heaters = [2] assert find_min_radius(houses, heaters) == 1 def test_example_case_2(): houses = [1, 2, 3, 4] heaters = [1, 4] assert find_min_radius(houses, heaters) == 1 def test_houses_between_heaters(): h...
[ { "docstring": "Returns the minimum distance from the house to the nearest heater using binary search.", "function_declaration": "def find_closest_heater(house, heaters):", "function_name": "find_closest_heater", "parameter_list": "(house, heaters)" }, { "docstring": "Returns the minimum rad...
[ 0, 1, 0, 0, 0, 0, 0, 1, 1, 1 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def findRadius(houses, heaters):\n \"\"\"\n Finds the minimum radius required to cover all houses using the provided heaters.\n \n Args:\n houses (List[int]): ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000034551", "row_id": 34551, "seed_ids": "['1255', '2532', '63']" }
0.591923
Leetcode_34551
I
[ "find_closest_heater", "find_min_radius" ]
2
[ [ "find_min_radius", "find_closest_heater" ] ]
1
[]
false
[]
false
pytest
true
[]
true
867ef28a38a19427262308d883ea8fd3c43c5ccb
0665d787004fcfdc11becdd8b31fddd4fb5a4ca4
v1.0
instruct
Leetcode
Leetcode_34575_I
Given an array of integers `nums` and an integer `k`, where the array represents the number of books and each integer in the array represents the time required to read a book. You want to split the books into `k` contiguous subarrays (each subarray represents a set of books assigned to one reader) in such a way that th...
def can_split(nums, k, max_time): current_sum = 0 required_splits = 1 for num in nums: if current_sum + num > max_time: required_splits += 1 current_sum = num if required_splits > k: return False else: current_sum += num ret...
from solution import splitArray def test_split_array_simple_case(): assert splitArray([7, 2, 5, 10, 8], 2) == 18 def test_split_array_all_equal(): assert splitArray([1, 1, 1, 1], 2) == 2 def test_split_array_single_subarray(): assert splitArray([1, 2, 3, 4, 5], 1) == 15 def test_split_array_large_k(): ...
[ { "docstring": null, "function_declaration": "def can_split(nums, k, max_time):", "function_name": "can_split", "parameter_list": "(nums, k, max_time)" }, { "docstring": "Returns the minimum possible maximum reading time to split the array into k subarrays.", "function_declaration": "def...
[ 0, 1, 0, 1, 1, 1, 1, 0, 0, 1 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def splitArray(nums, k):\n def valid(mid):\n current_sum, splits = 0, 1\n for num in nums:\n if current_sum + num > mid:\n splits +...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000034575", "row_id": 34575, "seed_ids": "['1583', '668', '2414']" }
0.705701
Leetcode_34575
I
[ "can_split", "splitArray" ]
2
[ [ "splitArray", "can_split" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9bf2052acfd4c818548eac01036b689516d49b68
49a205bd105f36a9ed0f23c5f370981ed418d1f2
v1.0
instruct
Leetcode
Leetcode_34583_I
Given a binary tree, find the longest path where each node in the path has the same value. This path may or may not pass through the root. The length of the path is the number of edges between the nodes in the path. You need to return the length of this longest path. The tree is represented as an array where each eleme...
class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None def array_to_tree(arr): if not arr: return None nodes = [None if val is None else TreeNode(val) for val in arr] kid = nodes[::-1] root = kid.pop() for node in nodes: ...
from solution import longest_univalue_path def test_longest_univalue_path_single_value(): assert longest_univalue_path([5, 5, 5, 5, 5, None, 5]) == 4 def test_longest_univalue_path_no_univalue_paths(): assert longest_univalue_path([1, 2, 3, 4, 5]) == 0 def test_longest_univalue_path_single_node(): assert...
[]
[ 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, x):\n self.val = x\n self.left = None\n self.right = None\n\ndef longestUnivaluePath(root):\n \"\"\"\n Give...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "0000034583", "row_id": 34583, "seed_ids": "['1283', '1489', '1684']" }
0.543506
Leetcode_34583
I
[ "array_to_tree", "longest_univalue_path" ]
2
[ [ "longest_univalue_path", "array_to_tree" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
a253e916961150e4977c06c667705c2419142ac4
418c7a47ddeba696eb9a8d373bd76409c3ae90e8
v1.0
instruct
Leetcode
Leetcode_34635_I
You are given an array of strings `words` and an integer `k`. Each string in the array `words` consists of lowercase English letters. A string is called **k-anagram** of another string if you can form the second string by rearranging the characters of the first string, and each pair of strings `words[i]` and `words[j]`...
def are_k_anagrams(word1, word2, k): """ Determine if word1 can be transformed into word2 by at most k swaps. """ if len(word1) != len(word2): return False diff_count = 0 counter_word1 = [0] * 26 counter_word2 = [0] * 26 for i in range(len(word1)): counter_word1[ord...
from solution import k_anagram_pairs def test_basic_cases(): assert k_anagram_pairs(["abcd", "bcda", "dcba", "abcd"], 2) == [(0, 1), (0, 2), (0, 3), (1, 2), (1, 3), (2, 3)] assert k_anagram_pairs(["hello", "olelh", "world", "dlrow"], 1) == [(0, 1), (2, 3)] def test_no_pairs(): assert k_anagram_pairs(["abc...
[ { "docstring": "Determine if word1 can be transformed into word2 by at most k swaps.", "function_declaration": "def are_k_anagrams(word1, word2, k):", "function_name": "are_k_anagrams", "parameter_list": "(word1, word2, k)" }, { "docstring": null, "function_declaration": "def k_anagram_p...
[ 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 Counter\n\ndef are_k_anagrams(word1, word2, k):\n \"\"\"\n Determine if two words are k-anagrams of each other.\n \"\"\"\n if len(word1) !...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000034635", "row_id": 34635, "seed_ids": "['473', '1968', '1762']" }
0.662868
Leetcode_34635
I
[ "are_k_anagrams", "k_anagram_pairs" ]
2
[ [ "k_anagram_pairs", "are_k_anagrams" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6471c95f9fc789905628e788a7fd467ab48009ec
00050b4e7a8749e5b8ec9fc270325975471b3f9d
v1.0
instruct
Leetcode
Leetcode_34636_I
Given an array of integers `arr` of size `n`, implement a function to find and return the length of the longest **unique path** in a binary tree structured from the `arr` elements such that each node in this path has a unique value. Here, unique path means each node's value appears only once in the path (i.e., there ar...
class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None def build_tree(arr): if not arr: return None nodes = [TreeNode(val) if val is not None else None for val in arr] root = nodes[0] child_index = 1 for node in nodes: ...
import pytest from solution import TreeNode, build_tree, longest_unique_path_from_array def test_empty_array(): assert longest_unique_path_from_array([]) == 0 def test_single_element_array(): assert longest_unique_path_from_array([1]) == 1 def test_unique_elements(): assert longest_unique_path_from_array...
[]
[ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, x):\n self.val = x\n self.left = None\n self.right = None\n\ndef build_tree(arr):\n if not arr:\n retur...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "0000034636", "row_id": 34636, "seed_ids": "['1458', '1139', '1019']" }
0.583698
Leetcode_34636
I
[ "build_tree", "longest_unique_path", "longest_unique_path_from_array" ]
3
[ [ "longest_unique_path_from_array", "build_tree" ], [ "longest_unique_path_from_array", "longest_unique_path" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
b8ade66dbcf3065319e504bbeab2a19688b63bce
f8dc825adecf5e58a33ec9da4695763cde56aec6
v1.0
instruct
Leetcode
Leetcode_34724_I
Given an integer `n`, return an array `answer` such that for each `i` (1 ≤ i ≤ n), `answer[i - 1]` is the number of integers `1, 2, ..., i` that are divisible by at least one prime number less than or equal to `i`. Make sure you optimize for performance, especially for larger values of `n`.
def sieve_of_eratosthenes(n): """ Returns a list of primes less than or equal to n """ is_prime = [True] * (n + 1) is_prime[0] = is_prime[1] = False # 0 and 1 are not primes p = 2 while (p * p <= n): if (is_prime[p] == True): for i in range(p * p, n + 1, p): is_pr...
from solution import count_divisibles_by_primes def test_single_element(): assert count_divisibles_by_primes(1) == [0] def test_small_numbers(): assert count_divisibles_by_primes(5) == [0, 1, 2, 3, 4] def test_medium_number(): assert count_divisibles_by_primes(10) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] def t...
[ { "docstring": "Returns a list of primes less than or equal to n ", "function_declaration": "def sieve_of_eratosthenes(n):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def count_divisibles_by_primes(n):", "functi...
[ 0, 0, 1, 1, 0, 0, 0, 0, 0, 1 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "from sympy import primerange\n\ndef count_divisibles_by_primes(n):\n \"\"\"\n Returns an array where each element at index i-1 is the number of integers\n 1, 2, ...,...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000034724", "row_id": 34724, "seed_ids": "['1676', '1154', '537']" }
0.704698
Leetcode_34724
I
[ "sieve_of_eratosthenes", "count_divisibles_by_primes" ]
2
[ [ "count_divisibles_by_primes", "sieve_of_eratosthenes" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0500cf4da179685ff9fb846e0fe5b07367d40f36
465fd7ce1aacbcceb5e1b60f17662444a097aaf0
v1.0
instruct
Leetcode
Leetcode_34811_I
There is an array of integers where the `ith` integer represents the time it takes to execute the `i`th task. A task can be assigned to any machine but there is a restriction: a machine will not start a new task until it finishes its current task. You need to distribute the tasks into `k` machines in such a way that th...
def can_distribute(tasks, k, max_time): """ Helper function to check if tasks can be distributed among k machines such that no machine takes more than max_time to complete its assigned tasks. """ current_time = 0 machines_required = 1 for task in tasks: if current_time + task <=...
def test_min_time_to_complete_tasks_basic(): assert min_time_to_complete_tasks([1,2,3,4,5], 2) == 9 def test_min_time_to_complete_tasks_single_machine(): assert min_time_to_complete_tasks([1,2,3,4,5], 1) == 15 def test_min_time_to_complete_tasks_more_machines_than_tasks(): assert min_time_to_complete_task...
[ { "docstring": "Helper function to check if tasks can be distributed among k machines\nsuch that no machine takes more than max_time to complete its assigned tasks.", "function_declaration": "def can_distribute(tasks, k, max_time):", "function_name": "can_distribute", "parameter_list": "(tasks, k, m...
[ 1, 0, 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 min_time_to_complete_tasks(tasks, k):\n def is_feasible(time):\n count, total = 1, 0\n for task in tasks:\n total += task\n if tota...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "0000034811", "row_id": 34811, "seed_ids": "['851', '802', '2452']" }
0.790624
Leetcode_34811
I
[ "can_distribute", "min_time_to_complete_tasks" ]
2
[ [ "min_time_to_complete_tasks", "can_distribute" ] ]
1
[]
false
[]
false
pytest
false
[]
true
6423461cbc61c64d44ff71a8d66fe5db826ea469
c7d4e4525cd8c649128d658c460cb69fac3a037c
v1.0
instruct
Leetcode
Leetcode_34839_I
You are given an array of strings `words` and a string `target`. Each string in the array `words` is sorted. A string is considered a valid subsequence of `target` if it contains all characters of `target` in the same order, but not necessarily contiguously. Write a function to return the count of strings in `words` th...
def is_subsequence(word, target): it = iter(target) return all(char in it for char in word) def count_valid_subsequences(words, target): return sum(is_subsequence(word, target) for word in words)
from solution import count_valid_subsequences def test_count_valid_subsequences_all_valid(): assert count_valid_subsequences(["abc", "a", "b", "ac"], "abc") == 4 def test_count_valid_subsequences_some_valid(): assert count_valid_subsequences(["abc", "ax", "bc"], "abc") == 2 def test_count_valid_subsequences_...
[ { "docstring": null, "function_declaration": "def is_subsequence(word, target):", "function_name": "is_subsequence", "parameter_list": "(word, target)" }, { "docstring": null, "function_declaration": "def count_valid_subsequences(words, target):", "function_name": "count_valid_subseq...
[ 1, 0, 0, 0, 0, 0, 1, 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 is_subsequence(word, target):\n \"\"\"\n Helper function to check if 'word' is a subsequence of 'target'.\n \"\"\"\n it = iter(target)\n return all(char in...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "0000034839", "row_id": 34839, "seed_ids": "['1243', '1505', '1287']" }
0.706143
Leetcode_34839
I
[ "is_subsequence", "count_valid_subsequences" ]
2
[ [ "count_valid_subsequences", "is_subsequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4f2099422bb5e402c33f95679e59e6f78b894948
b30637ebfb8cc515dee876375f28baf4bde04f69
v1.0
instruct
Leetcode
Leetcode_34870_I
You are given a singly linked list `head` which represents the head of the linked list. Each node in the list contains an integer value. Write a function to reverse every consecutive group of `k` nodes in the linked list. If the number of nodes is not a multiple of `k`, then reverse the last remaining nodes as is. Retu...
class ListNode: def __init__(self, val=0, next=None): self.val = val self.next = next def reverseKGroup(head, k): if not head or k == 1: return head dummy = ListNode(0) dummy.next = head prev_group_end = dummy while True: k_end = prev_group_end for _ in...
from solution import ListNode, reverseKGroup def list_to_linkedlist(items): if not items: return None head = ListNode(items[0]) current = head for item in items[1:]: current.next = ListNode(item) current = current.next return head def linkedlist_to_list(head): items = [...
[]
[ 0, 0, 1, 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": "class ListNode:\n def __init__(self, val=0, next=None):\n self.val = val\n self.next = next\n\ndef reverseKGroup(head, k):\n \"\"\"\n Reverse every gro...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000034870", "row_id": 34870, "seed_ids": "['1094', '1005', '122']" }
0.633263
Leetcode_34870
I
[ "reverseKGroup", "reverse" ]
2
[ [ "reverseKGroup", "reverse" ] ]
1
[]
false
[ "ListNode" ]
true
pytest
true
[]
true
d808972c0c38f6470c6f01381053588fb94ff7c8
5b5feccb9761f54f835fac648813d14741a5e6d2
v1.0
instruct
Leetcode
Leetcode_34884_I
A **special subsequence** of an integer array `nums` is defined as a sequence derived by deleting some or no elements of `nums` without changing the order of the remaining elements, and having a length that is a **prime number**. Given an integer array `nums`, return _the length of the longest special subsequence_. Two...
def is_prime(n): if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 return True def longest_special_subsequence_length(nums): ...
from solution import is_prime, longest_special_subsequence_length def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(5) == True assert is_prime(10) == False assert is_prime(11) == True assert is_prime(1) == False assert is_prime(-3) == False def test...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def longest_special_subsequence_length(nums):", "function_name": "longest_special_subsequence_length", "parameter...
[ 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 is_prime(n):\n \"\"\"\n Check if a number is a prime.\n \"\"\"\n if n <= 1:\n return False\n for i in range(2, int(n ** 0.5) + 1):\n if n % i...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "0000034884", "row_id": 34884, "seed_ids": "['996', '2326', '2528']" }
0.764617
Leetcode_34884
I
[ "is_prime", "longest_special_subsequence_length" ]
2
[ [ "longest_special_subsequence_length", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c5a92c00f6c360a6086da0b270b02960a7ea60b5
96325ae1bad9ebde839cae3068f6ce8487d28765
v1.0
instruct
Leetcode
Leetcode_34936_I
You are given a list of `points` in the 2D plane. Each point is represented as a coordinate pair `[x, y]`. Your task is to determine if a set of four of these points can form a square. A square is defined as a quadrilateral with four equal sides and four right angles. Write a function `isValidSquare(points: List[List...
from typing import List from itertools import combinations def distance_squared(p1, p2): return (p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2 def is_square(p1, p2, p3, p4): distances = [ distance_squared(p1, p2), distance_squared(p1, p3), distance_squared(p1, p4), distance_square...
from solution import isValidSquare def test_no_points(): assert not isValidSquare([]) def test_less_than_four_points(): assert not isValidSquare([[0, 0], [1, 1]]) assert not isValidSquare([[0, 0], [1, 1], [1, 0]]) def test_four_collinear_points(): assert not isValidSquare([[0, 0], [1, 1], [2, 2],...
[ { "docstring": null, "function_declaration": "def distance_squared(p1, p2):", "function_name": "distance_squared", "parameter_list": "(p1, p2)" }, { "docstring": null, "function_declaration": "def is_square(p1, p2, p3, p4):", "function_name": "is_square", "parameter_list": "(p1, ...
[ 1, 0, 0, 0, 0, 1, 1, 1, 1, 1 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "import itertools\nimport math\nfrom typing import List\n\ndef distance_sq(p1, p2):\n \"\"\"\n Calculate squared distance between two points p1 and p2.\n \"\"\"\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000034936", "row_id": 34936, "seed_ids": "['458', '1411', '1628']" }
0.536786
Leetcode_34936
I
[ "distance_squared", "is_square", "isValidSquare" ]
3
[ [ "isValidSquare", "is_square" ], [ "is_square", "distance_squared" ] ]
2
[]
false
[]
false
pytest
true
[]
true
9bb8f046165280dbf9d89fd49d71216e458e645f
0af2aa6109373e520cac57a01e15323b43ffe40d
v1.0
instruct
Leetcode
Leetcode_35035_I
You are given a string `s` and an integer `k`. Your task is to split `s` into **at most** `k` non-empty substrings such that each substring is a palindrome. Return `true` _if it is possible to split the string this way, or_ `false` _otherwise_. A **palindrome** is a string that reads the same forward and backward. Subs...
def is_palindrome(s: str) -> bool: return s == s[::-1] def can_split_into_palindromes(s: str, k: int) -> bool: def dfs(start, k): if start == len(s) and k == 0: return True if k == 0: return False for end in range(start + 1, len(s) + 1): if is_palindr...
from solution import can_split_into_palindromes def test_example_case(): assert can_split_into_palindromes("abac", 2) == True def test_single_character_string(): assert can_split_into_palindromes("a", 1) == True def test_k_equals_length_of_string(): assert can_split_into_palindromes("abc", 3) == True de...
[ { "docstring": null, "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": null, "function_declaration": "def can_split_into_palindromes(s, k):", "function_name": "can_split_into_palindromes", "parameter_list"...
[ 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": "def is_palindrome(s):\n return s == s[::-1]\n\ndef can_split_into_palindromes(s, k):\n n = len(s)\n \n if k > n:\n return False\n\n dp = [[False] * n fo...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000035035", "row_id": 35035, "seed_ids": "['2312', '2076', '1933']" }
0.783188
Leetcode_35035
I
[ "is_palindrome", "can_split_into_palindromes" ]
2
[ [ "can_split_into_palindromes", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
719e5d76cde8645e87febb639cf8de038450fd2b
8204b4c9fc73374934ed9a6b3fd1925eeae15eaa
v1.0
instruct
Leetcode
Leetcode_35177_I
Given an integer array `arr`, you need to count the number of elements that have **exactly** three divisors. A number `x` is said to have exactly `3` divisors if there exist exactly three distinct integers `a`, `b`, and `c` such that `a * b * c = x`. Return _the **count** of such elements in the array_. If no such elem...
import math def is_prime(n): """Helper function to determine if a number `n` is prime.""" if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False ...
from solution import count_elements_with_three_divisors def test_single_element_with_three_divisors(): assert count_elements_with_three_divisors([4]) == 1 def test_multiple_elements_with_three_divisors(): assert count_elements_with_three_divisors([4, 9, 25]) == 3 def test_no_elements_with_three_divisors(): ...
[ { "docstring": "Helper function to determine if a number `n` is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Counts the number of elements in the array `arr` that have exactly three divisors.", "function_decl...
[ 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "import math\n\ndef is_prime(n):\n if n <= 1:\n return False\n if n == 2 or n == 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n return False\n...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "0000035177", "row_id": 35177, "seed_ids": "['2334', '564', '1839']" }
0.649338
Leetcode_35177
I
[ "is_prime", "count_elements_with_three_divisors" ]
2
[ [ "count_elements_with_three_divisors", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5ef9ef6d77f3da8650c6c7ec9b3ef3bd41aeb632
e9411d36d282c82a1c23d550af5c42792d704cee
v1.0
instruct
Leetcode
Leetcode_35187_I
You are given an integer array `nums` and an integer `k`. Your task is to split `nums` into `k` consecutive subarrays such that the difference between the maximum sum of any subarray and the minimum sum of any subarray is minimized. Return _the minimum difference between the maximum and minimum subarray sums achieved ...
def can_partition(nums, k, max_sum): current_sum = 0 required_subarrays = 1 for num in nums: if current_sum + num > max_sum: required_subarrays += 1 current_sum = num if required_subarrays > k: return False else: current_su...
def test_minimize_difference_example(): nums = [7, 2, 5, 10, 8] k = 2 assert minimize_difference(nums, k) == 18 def test_minimize_difference_single_element(): nums = [10] k = 1 assert minimize_difference(nums, k) == 10 def test_minimize_difference_all_same_elements(): nums = [5, 5, 5, 5, 5...
[ { "docstring": null, "function_declaration": "def can_partition(nums, k, max_sum):", "function_name": "can_partition", "parameter_list": "(nums, k, max_sum)" }, { "docstring": null, "function_declaration": "def minimize_difference(nums, k):", "function_name": "minimize_difference", ...
[ 1, 0, 0, 0, 0, 1, 1, 0, 1, 0 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def splitArray(nums, k):\n \"\"\"\n Returns the minimum difference between the maximum and minimum subarray sums \n achieved by any way of splitting the array into k...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000035187", "row_id": 35187, "seed_ids": "['1029', '677', '2052']" }
0.78225
Leetcode_35187
I
[ "can_partition", "minimize_difference" ]
2
[ [ "minimize_difference", "can_partition" ] ]
1
[]
false
[]
false
pytest
false
[]
true
25ed71333c0d8c08090de5ada991c448986f4a51
61d76d93f71dfd92868a85cc42e06c3e2ee1bf74
v1.0
instruct
Leetcode
Leetcode_35341_I
We define a **smooth number** as a positive integer whose prime factors are all less than or equal to `p`. Given a positive integer `n` and a prime number `p`, return _the number of smooth numbers that are less than or equal to_ `n`.
def sieve_of_eratosthenes(max_number): is_prime = [True] * (max_number + 1) p = 2 while p * p <= max_number: if is_prime[p]: for i in range(p * p, max_number + 1, p): is_prime[i] = False p += 1 return [p for p in range(2, max_number + 1) if is_prime[p]] def c...
from solution import count_smooth_numbers def test_example_1(): assert count_smooth_numbers(10, 3) == 6 def test_example_2(): # n = 20, p = 5, smooth numbers <= 20 are: 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, 16, 18, 20. Total: 13 (excluding 1) assert count_smooth_numbers(20, 5) == 13 def test_small_n_large_...
[ { "docstring": null, "function_declaration": "def sieve_of_eratosthenes(max_number):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(max_number)" }, { "docstring": null, "function_declaration": "def count_smooth_numbers(n, p):", "function_name": "count_smooth_numbers"...
[ 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": "from sympy import isprime\n\ndef prime_factors(n):\n \"\"\" Helper function to determine the prime factors of `n`. \"\"\"\n i = 2\n factors = set()\n while i * i ...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "0000035341", "row_id": 35341, "seed_ids": "['2376', '2148', '1611']" }
0.465815
Leetcode_35341
I
[ "sieve_of_eratosthenes", "count_smooth_numbers" ]
2
[ [ "count_smooth_numbers", "sieve_of_eratosthenes" ] ]
1
[]
false
[]
false
pytest
true
[]
true
121f69453e1b08004be7548960d58f820398b7f2
53c313e8e29e1420a7c96ae35fdb5352af766375
v1.0
instruct
Leetcode
Leetcode_35357_I
Given an integer `n` representing the number of nodes in a **binary search tree (BST)** and an array `preorder` of length `n` containing the preorder traversal of the BST, construct the BST and return _the inorder traversal of its nodes' values_.
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def bstFromPreorder(preorder): if not preorder: return None def buildBST(preorder, lower, upper): if not preorder or preorder[0] < lower or preorder[...
from solution import bstFromPreorderInorderTraversal def test_empty_preorder(): assert bstFromPreorderInorderTraversal([]) == [] def test_single_node(): assert bstFromPreorderInorderTraversal([5]) == [5] def test_two_nodes(): assert bstFromPreorderInorderTraversal([5, 3]) == [3, 5] def test_three_nodes(...
[]
[ 0, 1, 1, 1, 0, 1, 1, 1, 1, 1 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\ndef bst_from_preorder(...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000035357", "row_id": 35357, "seed_ids": "['1273', '145', '2203']" }
0.502875
Leetcode_35357
I
[ "bstFromPreorder", "inorderTraversal", "bstFromPreorderInorderTraversal" ]
3
[ [ "bstFromPreorderInorderTraversal", "bstFromPreorder" ], [ "bstFromPreorderInorderTraversal", "inorderTraversal" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
63664e9895c6f70d22a09d10a6913797513e41a6
cff245e39166061b077a815a418b0740332aa03e
v1.0
instruct
Leetcode
Leetcode_35497_I
You are given an integer array `arr` consisting of `n` elements, and an integer `k`. Your task is to divide the array into **k** non-empty continuous subarrays such that the sum of each subarray is as large as possible while still having the smallest of these sums be as large as possible. Return _the **largest minimum ...
def can_split(nums, k, mid): """ Helper function to check if we can split `nums` into `k` parts with each part's sum being at least `mid`. """ current_sum = 0 parts_count = 1 for num in nums: current_sum += num if current_sum > mid: parts_count += 1 ...
from solution import max_min_sum def test_max_min_sum_single_subarray(): assert max_min_sum([1, 2, 3, 4, 5], 1) == 15 def test_max_min_sum_equal_parts(): assert max_min_sum([1, 2, 3, 4, 5], 5) == 5 def test_max_min_sum_simple_case(): assert max_min_sum([7, 2, 5, 10, 8], 2) == 18 def test_max_min_sum_mor...
[ { "docstring": "Helper function to check if we can split `nums` into `k` parts \nwith each part's sum being at least `mid`.", "function_declaration": "def can_split(nums, k, mid):", "function_name": "can_split", "parameter_list": "(nums, k, mid)" }, { "docstring": "Returns the largest minimu...
[ 1, 1, 0, 0, 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 largest_min_sum(arr, k):\n def is_valid(mid):\n current_sum = 0\n subarray_count = 1\n for num in arr:\n if current_sum + num > mid:\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000035497", "row_id": 35497, "seed_ids": "['310', '1463', '1785']" }
0.790481
Leetcode_35497
I
[ "can_split", "max_min_sum" ]
2
[ [ "max_min_sum", "can_split" ] ]
1
[]
false
[]
false
pytest
true
[]
true
41a1367ac4aa8d8a5c71b9692f9caf40ffb775f7
6f7232d30eab4021fbc62436156048c84861a029
v1.0
instruct
Leetcode
Leetcode_35790_I
You are given two strings `s1` and `s2`, both consisting of lowercase English letters. Define the **score** of a substring as the sum of the positions of its characters in the English alphabet (`a` is 1, `b` is 2, ..., `z` is 26). A **substring** is a contiguous segment of a string. * For example, the score of the ...
def get_char_score(c): return ord(c) - ord('a') + 1 def get_substring_score(s): return sum(get_char_score(c) for c in s) def max_score_common_substring(s1, s2): max_score = 0 s2_substrings = set() for i in range(len(s2)): for j in range(i + 1, len(s2) + 1): s2_substrings.a...
from solution import max_score_common_substring def test_max_score_common_substring(): assert max_score_common_substring("abc", "cde") == 3 # "c": 3 assert max_score_common_substring("abcd", "defg") == 4 # "d": 4 assert max_score_common_substring("abacaba", "bacabac") == 10 # "bacab": 2+1+3+1+2 = 10 ...
[ { "docstring": null, "function_declaration": "def get_char_score(c):", "function_name": "get_char_score", "parameter_list": "(c)" }, { "docstring": null, "function_declaration": "def get_substring_score(s):", "function_name": "get_substring_score", "parameter_list": "(s)" }, ...
[ 1, 0, 0, 0, 0, 0, 1, 0, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def get_char_score(c):\n \"\"\"\n Returns the position score of the character in the English alphabet.\n \"\"\"\n return ord(c) - ord('a') + 1\n\ndef maximum_comm...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "0000035790", "row_id": 35790, "seed_ids": "['1018', '2551', '2223']" }
0.770978
Leetcode_35790
I
[ "get_char_score", "get_substring_score", "max_score_common_substring" ]
3
[ [ "get_substring_score", "get_char_score" ], [ "max_score_common_substring", "get_substring_score" ] ]
2
[]
false
[]
false
pytest
true
[]
true
f7005f9bfc22be01bce3d43f167e91840288a736
efd231b4e9b145c128bb6ec49185d793a667bb42
v1.0
instruct
Leetcode
Leetcode_35857_I
You are given a list of `n` different tasks, where each task has a specific duration in minutes. Tasks are represented as an array of integers `tasks`, where `tasks[i]` is the duration of the `ith` task. You have `two` workers who can work simultaneously on tasks. Your objective is to assign the tasks to the two work...
def can_assign_tasks(tasks, max_time): # Start with two workers worker1_time, worker2_time = 0, 0 for task in sorted(tasks, reverse=True): if worker1_time + task <= max_time: worker1_time += task elif worker2_time + task <= max_time: worker2_time += task else...
from solution import minimize_max_task_duration def test_example_case(): tasks = [5, 8, 1, 4] assert minimize_max_task_duration(tasks) == 9 def test_single_task(): tasks = [10] assert minimize_max_task_duration(tasks) == 10 def test_multiple_tasks_equal(): tasks = [3, 3, 3, 3] assert minimize...
[ { "docstring": null, "function_declaration": "def can_assign_tasks(tasks, max_time):", "function_name": "can_assign_tasks", "parameter_list": "(tasks, max_time)" }, { "docstring": null, "function_declaration": "def minimize_max_task_duration(tasks):", "function_name": "minimize_max_t...
[ 0, 0, 1, 0, 0, 0, 0, 0, 0 ]
1
hard
0.111
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def min_max_task_duration(tasks):\n def can_assign(tasks, mid, k):\n current_sum = 0\n required_workers = 1\n for task in tasks:\n if curre...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "0000035857", "row_id": 35857, "seed_ids": "['2268', '1850', '2019']" }
0.752923
Leetcode_35857
I
[ "can_assign_tasks", "minimize_max_task_duration" ]
2
[ [ "minimize_max_task_duration", "can_assign_tasks" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d9efefc3191d98cceab9c1c7a9e5ffbaca1d2fbf
7718d496caf184d71b4e2cc1e4d87f5927606211
v1.0
instruct
Leetcode
Leetcode_36258_I
Given an array of integers `arr` and an integer `m`, determine if you can partition the array into `m` subarrays (continuous subarrays) such that the maximum sum of any subarray is minimized. Return this minimized maximum sum. For example, if `arr = [7, 2, 5, 10, 8]` and `m = 2`, you can partition the array into `[7, ...
def can_partition(arr, m, max_sum): count, current_sum = 1, 0 for num in arr: if current_sum + num > max_sum: count += 1 current_sum = num if count > m: return False else: current_sum += num return True def minimize_max_sum(arr...
from solution import can_partition, minimize_max_sum def test_can_partition(): assert can_partition([7, 2, 5, 10, 8], 2, 18) == True assert can_partition([7, 2, 5, 10, 8], 2, 17) == False assert can_partition([1, 2, 3, 4, 5], 5, 5) == True assert can_partition([1, 2, 3, 4, 5], 1, 15) == True def test_...
[ { "docstring": null, "function_declaration": "def can_partition(arr, m, max_sum):", "function_name": "can_partition", "parameter_list": "(arr, m, max_sum)" }, { "docstring": null, "function_declaration": "def minimize_max_sum(arr, m):", "function_name": "minimize_max_sum", "param...
[ 1, 0, 1, 1, 0, 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 can_partition(arr, m, max_sum):\n current_sum = 0\n required_partitions = 1\n \n for num in arr:\n if current_sum + num > max_sum:\n require...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000036258", "row_id": 36258, "seed_ids": "['1969', '86', '2555']" }
0.749561
Leetcode_36258
I
[ "can_partition", "minimize_max_sum" ]
2
[ [ "minimize_max_sum", "can_partition" ] ]
1
[]
false
[]
false
pytest
true
[]
true
443f28d59a615e58f67dac3468fbf731df1f2b65
ca1c63c0296c4c01ab3b38f67364fa235d4b2cea
v1.0
instruct
Leetcode
Leetcode_36263_I
Given an integer array `arr` of non-negative integers, you are tasked to form the largest possible integer by concatenating the array elements. Return _the largest integer you can form as a string._ Note that the result may be very large, so you should avoid any integer overflow and return the output as a string.
from functools import cmp_to_key def compare(x, y): if x + y > y + x: return -1 elif x + y < y + x: return 1 else: return 0 def largest_number(arr): """ Returns the largest possible integer (as a string) that can be formed by concatenating elements of the array. """...
from solution import largest_number def test_largest_number_single_digit(): assert largest_number([3, 30, 34, 5, 9]) == '9534330' def test_largest_number_all_same_digits(): assert largest_number([1, 1, 1, 1]) == '1111' def test_largest_number_with_zeros(): assert largest_number([0, 0]) == '0' assert ...
[ { "docstring": null, "function_declaration": "def compare(x, y):", "function_name": "compare", "parameter_list": "(x, y)" }, { "docstring": "Returns the largest possible integer (as a string) that can be formed\nby concatenating elements of the array.", "function_declaration": "def large...
[ 0, 0, 0, 1, 1, 1, 1, 1, 0, 1 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "from functools import cmp_to_key\n\ndef largest_number(arr):\n \"\"\"\n Form the largest possible integer by concatenating the array elements.\n \n :param arr: Li...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000036263", "row_id": 36263, "seed_ids": "['1086', '962', '1837']" }
0.649552
Leetcode_36263
I
[ "compare", "largest_number" ]
2
[ [ "largest_number", "compare" ] ]
1
[]
false
[]
false
pytest
true
[]
true
94d4fdd8c659df605ce0469470b61ffebb4cde9e
d0cd3e7be927eccccc223048acf340c7facff125
v1.0
instruct
Leetcode
Leetcode_36280_I
You are given an integer array of unique positive integers `nums` representing `n` nodes labeled from `1` to `n`. You need to construct a binary search tree (BST) from these integers. Then, perform an in-order traversal of the BST. Return the in-order traversal of the binary search tree as an array. The in-order traver...
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def insert_into_bst(root, val): if not root: return TreeNode(val) if val < root.val: root.left = insert_into_bst(root.left, val) else: roo...
from solution import bst_inorder_traversal def test_bst_inorder_single_element(): assert bst_inorder_traversal([5]) == [5] def test_bst_inorder_sorted_elements(): assert bst_inorder_traversal([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] def test_bst_inorder_unsorted_elements(): assert bst_inorder_traversal([3, 1,...
[]
[ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "class 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 insert_into_bst(ro...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000036280", "row_id": 36280, "seed_ids": "['2182', '725', '1986']" }
0.569615
Leetcode_36280
I
[ "insert_into_bst", "bst_from_list", "inorder_traversal", "inorder_helper", "bst_inorder_traversal" ]
5
[ [ "bst_from_list", "insert_into_bst" ], [ "bst_inorder_traversal", "bst_from_list" ], [ "bst_inorder_traversal", "inorder_traversal" ], [ "inorder_traversal", "inorder_helper" ] ]
4
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
0bc1f028abde6a7d4c14a1f51d05aec96e760c51
347cc5eb584dd397bafac5245fb04f08487d44be
v1.0
instruct
Leetcode
Leetcode_36458_I
You are given a list of non-negative integers `nums`. A subarray is a contiguous portion of the array. The **product** of a subarray is the product of all the elements within it. Determine whether the array contains a subarray whose product is a **perfect square**. A perfect square is an integer that is the square of a...
def is_perfect_square(num): """ Helper function to check if a number is a perfect square. """ if num < 0: return False root = int(num**0.5) return root * root == num def has_subarray_with_perfect_square_product(nums): """ Function to check if there exists a subarray whose produc...
from solution import has_subarray_with_perfect_square_product def test_single_element_perfect_square(): assert has_subarray_with_perfect_square_product([4]) == True def test_single_element_not_perfect_square(): assert has_subarray_with_perfect_square_product([3]) == False def test_multiple_elements_with_perf...
[ { "docstring": "Helper function to check if a number is a perfect square.", "function_declaration": "def is_perfect_square(num):", "function_name": "is_perfect_square", "parameter_list": "(num)" }, { "docstring": "Function to check if there exists a subarray whose product is a perfect square...
[ 1, 0, 0, 0, 1, 1, 1, 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 math import sqrt\n\ndef perfect_square_subarray(nums):\n \"\"\"\n Determine if there exists a subarray whose product is a perfect square.\n \"\"\"\n n = len(...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "0000036458", "row_id": 36458, "seed_ids": "['2092', '756', '888']" }
0.603169
Leetcode_36458
I
[ "is_perfect_square", "has_subarray_with_perfect_square_product" ]
2
[ [ "has_subarray_with_perfect_square_product", "is_perfect_square" ] ]
1
[]
false
[]
false
pytest
true
[]
true
129ad03245a79d112978296ffefb4ad52aff54b8
4e794f061955bb88da029b9675f7207ce08a6101
v1.0
instruct
Leetcode
Leetcode_36604_I
You are given the head node of a singly linked list where each node contains a positive integer value. Write a function to determine whether the linked list is a "happy" linked list. A linked list is considered "happy" if the sequence of values it contains forms a "happy number." A number is defined as "happy" if, star...
class ListNode: def __init__(self, val=0, next=None): self.val = val self.next = next def is_happy_number(n): def sum_of_squares(num): return sum(int(digit) ** 2 for digit in str(num)) seen = set() while n != 1 and n not in seen: seen.add(n) n = sum_of_squar...
from solution import ListNode, is_happy_linked_list def test_is_happy_linked_list_happy(): head = ListNode(1, ListNode(9, ListNode(7))) assert is_happy_linked_list(head) == False # Linked list 791 which is not happy def test_is_happy_linked_list_unhappy(): head = ListNode(1) assert is_happy_linked_li...
[]
[ 0, 1, 0, 0, 1, 0, 1, 1, 0, 1 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "class ListNode:\n def __init__(self, val=0, next=None):\n self.val = val\n self.next = next\n\ndef square_sum(n):\n \"\"\"\n Helper function to calcula...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000036604", "row_id": 36604, "seed_ids": "['2540', '1900', '1427']" }
0.546497
Leetcode_36604
I
[ "is_happy_number", "linked_list_to_number", "is_happy_linked_list" ]
3
[ [ "is_happy_linked_list", "is_happy_number" ], [ "is_happy_linked_list", "linked_list_to_number" ] ]
2
[]
false
[ "ListNode" ]
true
pytest
true
[]
true
e9231c6829b77ac24ac44a297e7959f751b78418
71ce60a8be145d31f0a8b0eb73bddc2678a25370
v1.0
instruct
Leetcode
Leetcode_36692_I
A palindromic number is a number that remains the same when its digits are reversed. For example, `121` is a palindromic number as it remains `121` after reversing, while `123` is not a palindromic number as it becomes `321` after reversing. Given an integer `num`, find the closest palindromic number. If there are mult...
def is_palindrome(n): """ Helper function to check if a number is a palindrome. """ return str(n) == str(n)[::-1] def closest_palindromic_number(num): """ Returns the closest palindromic number to the given number. If the number is already a palindrome, it returns the number itself. """...
from solution import is_palindrome, closest_palindromic_number def test_is_palindrome(): assert is_palindrome(121) is True assert is_palindrome(123) is False assert is_palindrome(1) is True assert is_palindrome(1221) is True assert is_palindrome(10) is False def test_closest_palindromic_number(): ...
[ { "docstring": "Helper function to check if a number is a palindrome.", "function_declaration": "def is_palindrome(n):", "function_name": "is_palindrome", "parameter_list": "(n)" }, { "docstring": "Returns the closest palindromic number to the given number.\nIf the number is already a palind...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_palindrome(n):\n return str(n) == str(n)[::-1]\n\ndef closest_palindromic_number(num):\n if is_palindrome(num):\n return num\n \n lower_palindrome =...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000036692", "row_id": 36692, "seed_ids": "['824', '537', '2119']" }
0.791612
Leetcode_36692
I
[ "is_palindrome", "closest_palindromic_number" ]
2
[ [ "closest_palindromic_number", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8d9996cf1ffaf6be42b3ecfd37e76e8cfb45e572
6b7ce9249bf424efaa3a37da8edb242ddab679b8
v1.0
instruct
Leetcode
Leetcode_36932_I
You are given a string `s` consisting of lowercase English letters, and an array of strings `words`. You need to select a non-empty subsequence from `s` and determine if it can form one of the strings in `words` when concatenated in order without reordering the characters. Return the length of the longest such subseque...
def is_subsequence(s, word): """ Checks if word is a subsequence of s. """ it = iter(s) return all(char in it for char in word) def longest_subseq_length(s, words): """ Finds the length of the longest subsequence from s that can form one of the words in words. """ longest_length = 0...
from solution import longest_subseq_length, is_subsequence def test_is_subsequence(): assert is_subsequence("abcde", "ace") == True assert is_subsequence("abcde", "aec") == False assert is_subsequence("abcde", "abcde") == True assert is_subsequence("abcde", "") == True def test_longest_subseq_length()...
[ { "docstring": "Checks if word is a subsequence of s.", "function_declaration": "def is_subsequence(s, word):", "function_name": "is_subsequence", "parameter_list": "(s, word)" }, { "docstring": "Finds the length of the longest subsequence from s that can form one of the words in words.", ...
[ 0, 1, 1, 1, 1, 1, 1, 1, 1 ]
8
easy
0.889
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_1_results_combined.jsonl", "solution_code": "def is_subsequence(s, sub):\n \"\"\"\n Checks if sub is a subsequence of s.\n \"\"\"\n it = iter(s)\n return all(char in it for char i...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000036932", "row_id": 36932, "seed_ids": "['1981', '2323', '529']" }
0.767891
Leetcode_36932
I
[ "is_subsequence", "longest_subseq_length" ]
2
[ [ "longest_subseq_length", "is_subsequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
403d996dde58483fbaa458aae005495dd60b736e
5d68687631d7417d338001a7239ae8d9634ff307
v1.0
instruct
Leetcode
Leetcode_36997_I
You are given a **balanced binary tree** represented as a list where parent nodes are listed before their children and `None` signifies missing nodes. Your task is to find and return the **lowest common ancestor** (LCA) of two given nodes in the binary tree. The LCA of two nodes `p` and `q` is defined as the lowest nod...
class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None def build_tree(index, tree_list): if index >= len(tree_list) or tree_list[index] is None: return None node = TreeNode(tree_list[index]) node.left = build_tree(2*index + 1, tree_list) ...
def test_lca_example_case(): # Tree: [3, 5, 1, 6, 2, 0, 8, None, None, 7, 4] assert lowest_common_ancestor([3, 5, 1, 6, 2, 0, 8, None, None, 7, 4], 5, 1) == 3 def test_lca_node_is_one_of_the_nodes(): # Tree: [3, 5, 1, 6, 2, 0, 8, None, None, 7, 4] assert lowest_common_ancestor([3, 5, 1, 6, 2, 0, 8, Non...
[]
[ 1, 0, 0, 0, 1, 0, 1, 0, 1 ]
4
medium
0.444
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def find_lowest_common_ancestor(tree, p, q):\n \"\"\"\n Returns the lowest common ancestor of p and q in the binary tree.\n \n :param tree: List representing the ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000036997", "row_id": 36997, "seed_ids": "['163', '656', '106']" }
0.60272
Leetcode_36997
I
[ "build_tree", "find_lca", "lowest_common_ancestor" ]
3
[ [ "lowest_common_ancestor", "build_tree" ], [ "lowest_common_ancestor", "find_lca" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
false
[]
true
379e60b7c12fccce7cabc1aa7afedd9d7546520b
431ddc1c524baafb33548f740825d67dc5eb61aa
v1.0
instruct
Leetcode
Leetcode_37302_I
You are managing a warehouse and need to optimize space usage. The warehouse is represented as a 2D grid of dimensions `m x n`, where each cell in the grid can either be empty (represented by `0`) or occupied by an item (represented by `1`). You want to find the largest rectangle that contains only empty cells (0s) in ...
def maximalRectangle(matrix): """ :param matrix: List[List[int]] - 2D grid of dimensions m x n :return: int - area of the largest rectangle containing only empty cells (0s) """ if not matrix: return 0 m, n = len(matrix), len(matrix[0]) heights = [0] * n max_area = 0 ...
from solution import maximalRectangle def test_empty_grid(): assert maximalRectangle([]) == 0 def test_grid_with_no_empty_cells(): assert maximalRectangle([[1, 1], [1, 1]]) == 0 def test_grid_with_only_empty_cells(): assert maximalRectangle([[0, 0], [0, 0]]) == 4 def test_mixed_grid(): grid = [ ...
[ { "docstring": ":param matrix: List[List[int]] - 2D grid of dimensions m x n\n:return: int - area of the largest rectangle containing only empty cells (0s)", "function_declaration": "def maximalRectangle(matrix):", "function_name": "maximalRectangle", "parameter_list": "(matrix)" }, { "docst...
[ 0, 1, 0, 0, 1, 1, 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 maximal_rectangle(matrix):\n \"\"\"\n Returns the area of the largest rectangle containing only 0's in a 2D grid.\n \"\"\"\n if not matrix or not matrix[0]:\n...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000037302", "row_id": 37302, "seed_ids": "['624', '2565', '1686']" }
0.696087
Leetcode_37302
I
[ "maximalRectangle", "largestRectangleArea" ]
2
[ [ "maximalRectangle", "largestRectangleArea" ] ]
1
[]
false
[]
false
pytest
true
[]
true
eaf82d5363d9344b4a2fc19518531d5221380c67
2cfc226d33851dd16a6fc4bf986e6ca946fd6782
v1.0
instruct
Leetcode
Leetcode_37543_I
You are given an integer array `nums` sorted in non-decreasing order. You need to remove some duplicates in-place such that each unique element appears at most twice, and return the new length. Do not allocate extra space for another array; you must do this by modifying the input array in-place with O(1) extra memory. ...
def remove_duplicates(nums): """ Remove duplicates in-place such that each unique element appears at most twice. :param nums: List[int] - sorted integer array :return: int - the new length of the array """ if not nums: return 0 # Use two pointers approach insert_pos = 1...
from solution import check_array_length def test_case_1(): nums = [1,1,1,2,2,3] k = 5 assert check_array_length(nums, k) == True def test_case_2(): nums = [0,0,1,1,1,1,2,3,3] k = 7 assert check_array_length(nums, k) == True def test_case_3(): nums = [1,1,2,2,2,3,3,4] k = 8 assert ...
[ { "docstring": "Remove duplicates in-place such that each unique element appears at most twice.\n\n:param nums: List[int] - sorted integer array\n:return: int - the new length of the array", "function_declaration": "def remove_duplicates(nums):", "function_name": "remove_duplicates", "parameter_list...
[ 1, 0, 1, 1, 1, 1, 0, 1, 1 ]
7
easy
0.778
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def remove_duplicates(nums, k):\n \"\"\"\n Function to modify the array such that each unique element appears at most twice in place\n and return True if the new len...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000037543", "row_id": 37543, "seed_ids": "['1725', '60', '1059']" }
0.712318
Leetcode_37543
I
[ "remove_duplicates", "check_array_length" ]
2
[ [ "check_array_length", "remove_duplicates" ] ]
1
[]
false
[]
false
pytest
true
[]
true
063605edee7b8f239d189fd224a8073e16439fcb
b63e5bee3b0ad7fa3fe3505e4fbed55d6c540f6f
v1.0
instruct
Leetcode
Leetcode_37607_I
Write a function that takes a list of integers as input and returns a new list containing all the prime numbers from the given list. A prime number is a number greater than 1 that has no positive divisors other than 1 and itself. Ensure that your solution is efficient in terms of time complexity.
def is_prime(n): """ Check if a number n is a prime number. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 ...
from solution import is_prime, primes_from_list def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(29) == True assert is_prime(35) == False assert is_prime(1) == False assert is_prime(-5) == False def test_primes_from_list...
[ { "docstring": "Check if a number n is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list of prime numbers from the given list.", "function_declaration": "def primes_from_list(lst):", "f...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n %...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000037607", "row_id": 37607, "seed_ids": "['378', '214', '346']" }
0.645376
Leetcode_37607
I
[ "is_prime", "primes_from_list" ]
2
[ [ "primes_from_list", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c60ec4e9bd4c3c9d6d2c3cee631b8723c60ab49c
6d72878a8fb41e45239a058c9f40fe665a188cb1
v1.0
instruct
Leetcode
Leetcode_37649_I
Given a string `s`, you need to split `s` into at most two palindromic substrings. Return `true` if it is possible to split `s` such that both substrings are palindromes and `false` otherwise. A string is a palindrome if it reads the same forward and backward.
def is_palindrome(s): """ Helper function to check if a given string is a palindrome. """ return s == s[::-1] def can_split_into_two_palindromes(s): """ Checks if the string 's' can be split into at most two palindromic substrings. """ n = len(s) for i in range(1, n): # We ite...
from solution import can_split_into_two_palindromes def test_simple_true_cases(): assert can_split_into_two_palindromes("abba") == True assert can_split_into_two_palindromes("racecar") == True def test_simple_false_cases(): assert can_split_into_two_palindromes("abcd") == False assert can_split_into_t...
[ { "docstring": "Helper function to check if a given string is a palindrome.", "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": "Checks if the string 's' can be split into at most two palindromic substrings.", "fu...
[ 0, 0, 0, 1, 0, 0, 0, 0, 0, 1 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def can_split_into_two_palindromes(s):\n \"\"\"\n Returns true if the provided string can be split into exactly two substrings that are both palindromes.\n \"\"\"\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000037649", "row_id": 37649, "seed_ids": "['805', '506', '1256']" }
0.775322
Leetcode_37649
I
[ "is_palindrome", "can_split_into_two_palindromes" ]
2
[ [ "can_split_into_two_palindromes", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
eb4f380aee180d07b6c65a8178deff6f0f155fe9
b2bc3202c3118ba834092bc45bccda17e2e03c6b
v1.0
instruct
Leetcode
Leetcode_37949_I
You are given a list of `edges` representing the connections between nodes in an undirected graph. Each `edge` is a pair `[u, v]` indicating a connection between node `u` and node `v`. Write a function to detect if there is a cycle in the graph. If a cycle exists, return `true`. Otherwise, return `false`. Each node in ...
def find_parent(parent, i): if parent[i] == -1: return i if parent[i] != -1: return find_parent(parent, parent[i]) def union(parent, x, y): x_set = find_parent(parent, x) y_set = find_parent(parent, y) if x_set != y_set: parent[x_set] = y_set def has_cycle(edges, n): ""...
from solution import has_cycle def test_no_cycle(): edges = [[0, 1], [1, 2], [2, 3]] n = 4 assert not has_cycle(edges, n) def test_with_cycle(): edges = [[0, 1], [1, 2], [2, 0]] n = 3 assert has_cycle(edges, n) def test_disconnected_graph_with_no_cycle(): edges = [[0, 1], [2, 3]] n = ...
[ { "docstring": null, "function_declaration": "def find_parent(parent, i):", "function_name": "find_parent", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, x, y):", "function_name": "union", "parameter_list": "(parent, x, y)" }...
[ 1, 1, 1, 0, 1, 1, 1, 1, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def hasCycle(n, edges):\n \"\"\"\n Determines if there is a cycle in the given undirected graph.\n \n :param int n: The number of nodes in the graph.\n :param ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "0000037949", "row_id": 37949, "seed_ids": "['2468', '974', '207']" }
0.648728
Leetcode_37949
I
[ "find_parent", "union", "has_cycle" ]
3
[ [ "has_cycle", "find_parent" ], [ "has_cycle", "union" ], [ "union", "find_parent" ] ]
3
[]
false
[]
false
pytest
true
[]
true
0483907523ae341af70a79ea24ff329bbc83dcfd
97eda2bc6f4c45ad26158154759762f783da6716
v1.0
instruct
Leetcode
Leetcode_37950_I
Given an array of integers `arr` and an integer `k`, partition the array into `k` subsets such that the sum of integers in each subset is maximized. Return _the minimized sum of the largest subset_. You may assume that both the array and `k` are such that a valid partitioning is always possible. For example, given `arr...
def can_partition(nums, k, max_sum): # This helper function checks if we can partition the array into `k` or fewer parts # so that no part has a sum greater than `max_sum`. current_sum = 0 required_parts = 1 for num in nums: if current_sum + num > max_sum: required_parts += 1 ...
from solution import minimized_largest_sum def test_case_1(): assert minimized_largest_sum([1, 2, 3, 4, 5], 2) == 9 def test_case_2(): assert minimized_largest_sum([1, 2, 3, 4, 5], 3) == 6 def test_case_3(): assert minimized_largest_sum([1, 2, 3, 4, 5], 1) == 15 def test_case_4(): assert minimized_l...
[ { "docstring": null, "function_declaration": "def can_partition(nums, k, max_sum):", "function_name": "can_partition", "parameter_list": "(nums, k, max_sum)" }, { "docstring": null, "function_declaration": "def minimized_largest_sum(arr, k):", "function_name": "minimized_largest_sum"...
[ 1, 1, 0, 0, 1, 0, 0, 0, 0 ]
3
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def can_partition(arr, k, max_sum):\n current_sum = 0\n partitions = 1\n \n for num in arr:\n if current_sum + num > max_sum:\n partitions += 1\...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "0000037950", "row_id": 37950, "seed_ids": "['671', '2250', '1197']" }
0.731674
Leetcode_37950
I
[ "can_partition", "minimized_largest_sum" ]
2
[ [ "minimized_largest_sum", "can_partition" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1b8af5e73f6d9eb606343505a433f430d91a8baa
ad6e4d5ccbbfb69e30c3d94a234d49a9f7ffe241
v1.0
instruct
Leetcode
Leetcode_38010_I
Given an array of integers `arr` and an integer `k`, find the _kth smallest element_ in the array. You must solve it with a worst-case time complexity better than O(n^2). Return _the **kth smallest element** in the array._
def partition(arr, low, high): pivot = arr[high] i = low for j in range(low, high): if arr[j] < pivot: arr[i], arr[j] = arr[j], arr[i] i += 1 arr[i], arr[high] = arr[high], arr[i] return i def quickselect(arr, low, high, k): if low == high: return arr[low...
from solution import kth_smallest def test_kth_smallest_positive_numbers(): assert kth_smallest([7, 10, 4, 3, 20, 15], 3) == 7 def test_kth_smallest_with_duplicates(): assert kth_smallest([7, 10, 4, 3, 20, 15, 7, 7], 3) == 7 def test_kth_smallest_with_negative_numbers(): assert kth_smallest([-10, -20, -3...
[ { "docstring": null, "function_declaration": "def partition(arr, low, high):", "function_name": "partition", "parameter_list": "(arr, low, high)" }, { "docstring": null, "function_declaration": "def quickselect(arr, low, high, k):", "function_name": "quickselect", "parameter_list...
[ 1, 1, 1, 1, 1, 1, 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 kth_smallest(arr, k):\n \"\"\"\n Returns the k-th smallest element in the array `arr`.\n Uses the Quickselect algorithm which has an average time complexity of O...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000038010", "row_id": 38010, "seed_ids": "['1885', '429', '1960']" }
0.605558
Leetcode_38010
I
[ "partition", "quickselect", "kth_smallest" ]
3
[ [ "kth_smallest", "quickselect" ], [ "quickselect", "partition" ] ]
2
[]
false
[]
false
pytest
true
[]
true
6ceade71832b26039564af9b199d20ba023b0365
b700c3c0cdb75d61b8519eff42762bf60521c08b
v1.0
instruct
Leetcode
Leetcode_38081_I
You have a list of points on a 2D plane, each represented as a tuple `(x, y)`, with `x` and `y` being integers. There is also a start point `(sx, sy)` and an end point `(ex, ey)`. You need to determine the minimum number of moves required to travel from the start point to the end point, while only being allowed to move...
from collections import deque, defaultdict def min_moves(points, start, end): """ Calculates the minimum number of moves required to travel from the start point to the end point. """ graph = build_graph(points) return bfs(graph, start, end) def build_graph(points): """ Build graph where ea...
from solution import min_moves def test_min_moves_simple_adjacent(): points = [(1, 1), (1, 2)] start = (1, 1) end = (1, 2) assert min_moves(points, start, end) == 1 def test_min_moves_simple_not_possible(): points = [(1, 1), (2, 2)] start = (1, 1) end = (2, 2) assert min_moves(points, ...
[ { "docstring": "Calculates the minimum number of moves required to travel from the start point to the end point.", "function_declaration": "def min_moves(points, start, end):", "function_name": "min_moves", "parameter_list": "(points, start, end)" }, { "docstring": "Build graph where each po...
[ 0, 0, 1, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef min_moves(points, start, end):\n \"\"\"\n Determines the minimum number of moves required to travel from start to end.\n \n P...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "0000038081", "row_id": 38081, "seed_ids": "['790', '782', '2163']" }
0.676622
Leetcode_38081
I
[ "min_moves", "build_graph", "bfs" ]
3
[ [ "min_moves", "bfs" ], [ "min_moves", "build_graph" ] ]
2
[]
false
[]
false
pytest
true
[]
true
42daf97348365eea204401dff54fcaf4b4608ea8
a54f8e7ad90c94f14c68a8a4ce4a81311ffa8f4b
v1.0
instruct
Leetcode
Leetcode_38165_I
You are given a set of `n` points on a 2D plane represented as an array `points` of size `n x 2`, where `points[i] = [xi, yi]` is the coordinate of the `i`-th point. You need to find the pair of points that are the closest to each other and return the Euclidean distance between them. The Euclidean distance between two ...
import math def euclidean_distance(point1, point2): """ Calculate the Euclidean distance between two points in 2D space. """ x1, y1 = point1 x2, y2 = point2 return math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2) def find_closest_pair(points): """ Find the closest pair of points in the given...
from solution import find_closest_pair def test_single_closest_pair(): points = [[1, 2], [2, 3], [4, 5]] assert math.isclose(find_closest_pair(points), 1.4142135623730951, rel_tol=1e-5) def test_multiple_points(): points = [[1, 2], [3, 4], [6, 8], [7, 1]] assert math.isclose(find_closest_pair(points),...
[ { "docstring": "Calculate the Euclidean distance between two points in 2D space.", "function_declaration": "def euclidean_distance(point1, point2):", "function_name": "euclidean_distance", "parameter_list": "(point1, point2)" }, { "docstring": "Find the closest pair of points in the given li...
[ 0, 0, 0, 1, 0, 1, 1, 1, 1, 1 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "import math\nfrom itertools import combinations\n\ndef closest_pair_of_points(points):\n \"\"\"\n Find the pair of points that are the closest to each other and return ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000038165", "row_id": 38165, "seed_ids": "['1810', '1353', '47']" }
0.712658
Leetcode_38165
I
[ "euclidean_distance", "find_closest_pair" ]
2
[ [ "find_closest_pair", "euclidean_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
08700a69a1125b5dc31c78e80314195e2e18c827
9c22191901fb0b5e400cdb25b6b2f4b25b0e9ee7
v1.0
instruct
Leetcode
Leetcode_38183_I
You are given an array of strings `words` where each string consists of lowercase English letters and each word is unique. A word `W` is considered to be 'special' if it contains all the vowels `a`, `e`, `i`, `o`, `u` at least once. Write a function that returns the total count of 'special' words in the `words` array.
def is_special(word): """ Checks if the word contains all the vowels 'a', 'e', 'i', 'o', 'u' at least once. """ required_vowels = set('aeiou') return required_vowels.issubset(set(word)) def count_special_words(words): """ Returns the count of 'special' words in the words array. A word i...
from solution import is_special, count_special_words def test_is_special_with_all_vowels(): assert is_special("education") == True assert is_special("sequoia") == True def test_is_special_without_all_vowels(): assert is_special("python") == False assert is_special("quick") == False def test_is_specia...
[ { "docstring": "Checks if the word contains all the vowels 'a', 'e', 'i', 'o', 'u' at least once.", "function_declaration": "def is_special(word):", "function_name": "is_special", "parameter_list": "(word)" }, { "docstring": "Returns the count of 'special' words in the words array.\nA word i...
[ 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": "def is_special_word(word):\n \"\"\"\n Check if a word is 'special' by verifying it contains all vowels: a, e, i, o, u.\n \"\"\"\n vowels = {'a', 'e', 'i', 'o', 'u...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "0000038183", "row_id": 38183, "seed_ids": "['2535', '1018', '840']" }
0.805456
Leetcode_38183
I
[ "is_special", "count_special_words" ]
2
[ [ "count_special_words", "is_special" ] ]
1
[]
false
[]
false
pytest
true
[]
true
aca1ac9f443922c00e3b5737bcba707e6804fd6f
58ac85f65a9f2fff37b152c38d2d90c4d97fa80d