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_10902_I
Given an array of integers `arr` where the ith element represents the amount of time needed to process a job, and an integer `k` representing the number of available processors, distribute the jobs to the processors such that the maximum processing time of the jobs assigned to any processor is minimized. Return the min...
def canDistribute(arr, k, maxTime): current_sum = 0 required_processors = 1 for time in arr: if current_sum + time <= maxTime: current_sum += time else: required_processors += 1 current_sum = time if required_processors > k: r...
def test_canDistribute(): assert canDistribute([1, 2, 3, 4, 5], 2, 9) == True assert canDistribute([1, 2, 3, 4, 5], 2, 6) == False assert canDistribute([1, 2, 3, 4, 5], 3, 6) == True assert canDistribute([1, 2, 3, 4, 5], 3, 5) == False def test_minProcessingTime(): assert minProcessingTime([1, 2, 3...
[ { "docstring": null, "function_declaration": "def canDistribute(arr, k, maxTime):", "function_name": "canDistribute", "parameter_list": "(arr, k, maxTime)" }, { "docstring": null, "function_declaration": "def minProcessingTime(arr, k):", "function_name": "minProcessingTime", "par...
[ 0, 1, 1, 0, 0, 0, 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 minimize_max_processing_time(arr, k):\n def canDistribute(mid):\n count = 1\n current_sum = 0\n for time in arr:\n if current_sum + tim...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000010902", "row_id": 10902, "seed_ids": "['961', '1642', '604']" }
0.783014
Leetcode_10902
I
[ "canDistribute", "minProcessingTime" ]
2
[ [ "minProcessingTime", "canDistribute" ] ]
1
[]
false
[]
false
pytest
false
[]
true
4310ff53d5baf328a0e85c4782aa8494de6d60ca
3f64bbfadb96cd60ff882666414edea626856e9e
v1.0
instruct
Leetcode
Leetcode_10961_I
Given a string `s` and an array of intervals `[start, end]`, where each interval represents a pair of start and end indices (inclusive) within the string, return a new string with only the characters that are within the given intervals. If intervals overlap, they should be merged into a single interval. For example, if...
def merge_intervals(intervals): if not intervals: return [] intervals.sort(key=lambda x: x[0]) merged = [intervals[0]] for start, end in intervals[1:]: last_end = merged[-1][1] if start <= last_end + 1: merged[-1][1] = max(last_end, end) els...
from solution import extract_string_using_intervals def test_single_interval(): assert extract_string_using_intervals("abcdef", [[1, 3]]) == "bcd" def test_multiple_overlapping_intervals(): assert extract_string_using_intervals("abcdef", [[1, 3], [2, 4]]) == "bcde" def test_multiple_non_overlapping_inter...
[ { "docstring": null, "function_declaration": "def merge_intervals(intervals):", "function_name": "merge_intervals", "parameter_list": "(intervals)" }, { "docstring": null, "function_declaration": "def extract_string_using_intervals(s, intervals):", "function_name": "extract_string_us...
[ 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def merge_intervals(intervals):\n if not intervals:\n return []\n\n # Sort intervals based on start times\n intervals.sort(key=lambda x: x[0])\n\n merged =...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "0000010961", "row_id": 10961, "seed_ids": "['1182', '2296', '533']" }
0.631794
Leetcode_10961
I
[ "merge_intervals", "extract_string_using_intervals" ]
2
[ [ "extract_string_using_intervals", "merge_intervals" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6e202aa4fe7b03fe63b3f4f332352e0e88a48570
49add938ad5cdbb63c1fc3b6b45926c6aed63c1e
v1.0
instruct
Leetcode
Leetcode_11013_I
Given a string `s`, remove the minimum number of characters from `s` so that it becomes a valid palindrome. A string is a valid palindrome if it reads the same forward and backward. Return _the result string after the minimum number of deletions_. If there are multiple possible results, return any of them.
def longest_palindromic_subsequence(s): n = len(s) dp = [[0] * n for _ in range(n)] for i in range(n): dp[i][i] = 1 for cl in range(2, n + 1): for i in range(n - cl + 1): j = i + cl - 1 if s[i] == s[j]: dp[i][j] = dp[i + 1][j - 1] + 2 ...
from solution import make_palindrome def test_single_character(): assert make_palindrome("a") == "a" def test_already_palindrome(): assert make_palindrome("aba") == "aba" assert make_palindrome("abba") == "abba" def test_remove_one_character(): assert make_palindrome("abc") == "a" or make_palindrome(...
[ { "docstring": null, "function_declaration": "def longest_palindromic_subsequence(s):", "function_name": "longest_palindromic_subsequence", "parameter_list": "(s)" }, { "docstring": null, "function_declaration": "def build_palindrome(s, dp):", "function_name": "build_palindrome", ...
[ 0, 0, 1, 1, 0, 0, 0, 0, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def min_deletions_to_palindrome(s):\n \"\"\"\n Removes the minimum number of characters from `s` to make it a valid palindrome.\n Returns the result string after the...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "0000011013", "row_id": 11013, "seed_ids": "['1353', '1950', '2015']" }
0.779129
Leetcode_11013
I
[ "longest_palindromic_subsequence", "build_palindrome", "make_palindrome" ]
3
[ [ "make_palindrome", "build_palindrome" ], [ "make_palindrome", "longest_palindromic_subsequence" ] ]
2
[]
false
[]
false
pytest
true
[]
true
9bf5ac48dcea2d373ecdd5ffd73f05a1396a282e
ee3bb6b0b98f7f9df8c6fef14e835e83a257ca5e
v1.0
instruct
Leetcode
Leetcode_11232_I
You are given a `n`-ary tree, which is a tree in which a node can have at most `n` children. Each node is represented as a triple `(val, children, parent)` where `val` is the node's value, `children` is a list of child nodes, and `parent` is the node's parent node. Implement a function to find the lowest common ancest...
class Node: def __init__(self, val, children=None, parent=None): self.val = val self.children = children if children is not None else [] self.parent = parent def lowest_common_ancestor(p, q): """ Finds the lowest common ancestor (LCA) of two given nodes p and q in an n-ary tree. ...
from solution import Node, lowest_common_ancestor def test_single_node_tree(): root = Node(1) assert lowest_common_ancestor(root, root) == root def test_two_node_tree(): root = Node(1) child1 = Node(2, parent=root) root.children.append(child1) assert lowest_common_ancestor(root, child1) == roo...
[]
[ 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 Node:\n def __init__(self, val, children=None, parent=None):\n self.val = val\n self.children = children if children is not None else []\n self....
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "0000011232", "row_id": 11232, "seed_ids": "['1463', '366', '2174']" }
0.580001
Leetcode_11232
I
[ "lowest_common_ancestor", "get_path_to_root" ]
2
[ [ "lowest_common_ancestor", "get_path_to_root" ] ]
1
[]
false
[ "Node" ]
true
pytest
true
[]
true
128312f4a94308dab2370a99ce2cff4b295ee445
a1c56a463d4c116bbab047ed41a109c9912c372d
v1.0
instruct
Leetcode
Leetcode_11233_I
Given a list of `words`, find all pairs of distinct words that, when concatenated, form a palindrome. A palindrome is a word that reads the same backward as forward. Return a list of pairs `(i, j)`, such that the concatenation of `words[i]` and `words[j]` forms a palindrome. Each pair should be listed only once, with t...
def is_palindrome(word): return word == word[::-1] def palindrome_pairs(words): pairs = [] for i in range(len(words)): for j in range(len(words)): if i != j: if is_palindrome(words[i] + words[j]): pairs.append((i, j)) return pairs
from solution import is_palindrome, palindrome_pairs def test_is_palindrome(): assert is_palindrome("racecar") == True assert is_palindrome("level") == True assert is_palindrome("hello") == False assert is_palindrome("a") == True assert is_palindrome("") == True def test_palindrome_pairs_case_1():...
[ { "docstring": null, "function_declaration": "def is_palindrome(word):", "function_name": "is_palindrome", "parameter_list": "(word)" }, { "docstring": null, "function_declaration": "def palindrome_pairs(words):", "function_name": "palindrome_pairs", "parameter_list": "(words)" ...
[ 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 is_palindrome(word):\n \"\"\"\n Check if a given word is a palindrome.\n \"\"\"\n return word == word[::-1]\n\ndef palindrome_pairs(words):\n \"\"\"\n R...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "0000011233", "row_id": 11233, "seed_ids": "['386', '1469', '458']" }
0.703808
Leetcode_11233
I
[ "is_palindrome", "palindrome_pairs" ]
2
[ [ "palindrome_pairs", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
db51f5182232e3379c1611d0a148ac50e63813e0
190e8527e9b0b3bb018640ded023daaea4f8fc81
v1.0
instruct
Leetcode
Leetcode_11343_I
You are given an array of integers `arr` and an integer `k`. Your task is to build a binary search tree (BST) from `arr` and determine the sum of all elements within the BST that are **k distance** away from the root. Here, the distance is defined as the number of edges between the root and the node. For example, if ...
class TreeNode: def __init__(self, value): 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.righ...
from solution import sum_of_k_distance_from_root def test_sum_of_k_distance_from_root(): assert sum_of_k_distance_from_root([3, 1, 4, 0, 2], 1) == 5 # 1 + 4 assert sum_of_k_distance_from_root([3, 1, 4, 0, 2], 2) == 2 # 0 + 2 assert sum_of_k_distance_from_root([3, 1, 4, 0, 2], 0) == 3 # 3 assert sum_...
[]
[ 0, 1, 1, 1, 1, 0, 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, key):\n self.left = None\n self.right = None\n self.val = key\n\ndef insert(root, key):\n if root is None:\n ...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "0000011343", "row_id": 11343, "seed_ids": "['214', '1782', '2581']" }
0.560526
Leetcode_11343
I
[ "insert_into_bst", "build_bst", "sum_at_k_distance", "sum_of_k_distance_from_root" ]
4
[ [ "build_bst", "insert_into_bst" ], [ "sum_of_k_distance_from_root", "build_bst" ], [ "sum_of_k_distance_from_root", "sum_at_k_distance" ] ]
3
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
c54aacf2f56ffd8f674ddbd85cad54cd136304da
14362c5235a9eb52c7cd3b30da7bad93af928792
v1.0
instruct
Leetcode
Leetcode_11357_I
You are given a 2D list of integers `grid` representing a grid of size `m x n`, where each cell contains either a `0` (representing an empty cell) or a `1` (representing a wall). You need to find the maximum area of a rectangle that can be formed by empty cells. Return _an integer representing the maximum area of the r...
def maximal_rectangle(grid): """ Returns the maximum area of a rectangle filled with empty cells in a grid. :param grid: List[List[int]] - 2D grid where 0 represents an empty cell and 1 represents a wall. :return: int - Maximum area of a rectangle filled with empty cells. """ if not grid: r...
from solution import maximal_rectangle def test_maximal_rectangle_simple(): grid = [ [0, 1, 0, 0], [0, 1, 1, 0], [0, 0, 0, 0] ] assert maximal_rectangle(grid) == 4 def test_maximal_rectangle_single_cell(): grid = [ [0] ] assert maximal_rectangle(grid) == 1 def ...
[ { "docstring": "Returns the maximum area of a rectangle filled with empty cells in a grid.\n\n:param grid: List[List[int]] - 2D grid where 0 represents an empty cell and 1 represents a wall.\n:return: int - Maximum area of a rectangle filled with empty cells.", "function_declaration": "def maximal_rectangle...
[ 1, 1, 0, 0, 1, 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 max_histogram_area(heights):\n \"\"\"\n Helper function that calculates the maximum rectangular area in a histogram given its heights.\n \"\"\"\n stack = []\n...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "0000011357", "row_id": 11357, "seed_ids": "['2587', '1363', '2341']" }
0.693862
Leetcode_11357
I
[ "maximal_rectangle", "largest_rectangle_area" ]
2
[ [ "maximal_rectangle", "largest_rectangle_area" ] ]
1
[]
false
[]
false
pytest
true
[]
true
fb8c2180b460211fb051850581c64d6a8beefb7d
967bf2e2fc929374ef98c0faed682a08a79cdb56
v1.0
instruct
Leetcode
Leetcode_11603_I
Given a list of `n` strings where each string represents a unique user email address, determine whether any two email addresses are considered equivalent. Email addresses are equivalent if they are identical when both the local name and domain name are disregarded. The local name is the part before the '@' and the doma...
def standardize_email(email): """ Standardizes the email address based on the rules: 1. The local part is considered the part before the '@' symbol. 2. Ignore any portion of the local part from '+' onwards. 3. Ignore all '.' characters in the local part. """ local, domain = email.split('@') ...
from solution import find_equivalent_emails, standardize_email def test_standardize_email(): assert standardize_email('test.email+alex@leetcode.com') == 'testemail@leetcode.com' assert standardize_email('test.e.mail+bob.cathy@leetcode.com') == 'testemail@leetcode.com' assert standardize_email('testemail+da...
[ { "docstring": "Standardizes the email address based on the rules:\n1. The local part is considered the part before the '@' symbol.\n2. Ignore any portion of the local part from '+' onwards.\n3. Ignore all '.' characters in the local part.", "function_declaration": "def standardize_email(email):", "func...
[ 0, 0, 0, 1, 0, 0, 0, 1, 1 ]
3
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def find_equivalent_emails(emails):\n \"\"\"\n Finds all equivalent email addresses from a list of email addresses.\n \"\"\"\n normalized_map = {}\n \n def ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000011603", "row_id": 11603, "seed_ids": "['1207', '517', '1557']" }
0.633244
Leetcode_11603
I
[ "standardize_email", "find_equivalent_emails" ]
2
[ [ "find_equivalent_emails", "standardize_email" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ea32418b47800524bcfe9ced8e79ffe5f287f954
147de4196d2f1f6e47f65fbe6a80b867336f0777
v1.0
instruct
Leetcode
Leetcode_11655_I
Given a binary tree, return the level order traversal of its nodes' values. (i.e., from left to right, level by level). The binary tree is represented by a string of comma-separated values, and nodes are given in a level-order format where 'null' represents an empty node. Write a function that constructs the binary tre...
from collections import deque class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def build_tree_from_str(tree_str): if not tree_str: return None nodes = tree_str.split(',') root = TreeNode(int(nodes[...
from solution import level_order_traversal, build_tree_from_str, TreeNode def test_level_order_traversal(): assert level_order_traversal("3,9,20,null,null,15,7") == [[3], [9, 20], [15, 7]] assert level_order_traversal("1") == [[1]] assert level_order_traversal("1,2,3,4,5,6,7") == [[1], [2, 3], [4, 5, 6, 7]...
[]
[ 0, 1, 1, 1, 1, 0, 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": "from typing import List, Optional\nimport collections\n\nclass TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = l...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "0000011655", "row_id": 11655, "seed_ids": "['306', '1444', '416']" }
0.502916
Leetcode_11655
I
[ "build_tree_from_str", "level_order_traversal" ]
2
[ [ "level_order_traversal", "build_tree_from_str" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
41688c71d44bc2b9da45a1f4d91902b0d8260b14
48e35fdec4443cf36a41035049abe5c59459af25
v1.0
instruct
Leetcode
Leetcode_11693_I
Given a binary tree, root of the tree is given to you along with an integer x. You need to find the maximum depth of the binary tree. Then consider all nodes at that maximum depth and return the value of the node which is the farthest from node with value x. If there are multiple nodes which are the same distance from ...
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def max_depth(root): if not root: return 0 left_depth = max_depth(root.left) right_depth = max_depth(root.right) return max(left_depth, right_depth) +...
def test_max_depth(): root = TreeNode(1, TreeNode(2), TreeNode(3)) assert max_depth(root) == 2 root = TreeNode(1, TreeNode(2, TreeNode(3), TreeNode(4)), TreeNode(5)) assert max_depth(root) == 3 def test_find_all_nodes_at_depth(): root = TreeNode(1, TreeNode(2), TreeNode(3)) assert [node.val for...
[]
[ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "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_farthest_valu...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "0000011693", "row_id": 11693, "seed_ids": "['1900', '2498', '1526']" }
0.530649
Leetcode_11693
I
[ "max_depth", "find_all_nodes_at_depth", "distance_between_nodes", "farthest_node" ]
4
[ [ "farthest_node", "distance_between_nodes" ], [ "farthest_node", "find_all_nodes_at_depth" ], [ "farthest_node", "max_depth" ] ]
3
[]
false
[ "TreeNode" ]
true
pytest
false
[]
true
4d527e94aaca48afba0c748312104dd9fb782bbd
9bbad3b797e63bf0ff5d69713da87731c30150ff
v1.0
instruct
Leetcode
Leetcode_12229_I
Given a list of `positions` and an integer `d`, return the maximum minimum distance between any two positions, where `positions[i]` represents the position of the ith house on a straight line. You are required to place `d` houses such that the minimum distance between any two houses is as large as possible.
def canPlaceHouses(positions, d, min_dist): count = 1 last_pos = positions[0] for i in range(1, len(positions)): if positions[i] - last_pos >= min_dist: count += 1 last_pos = positions[i] if count == d: return True return False def maxMin...
from solution import maxMinDistance def test_case_1(): positions = [1, 2, 8, 4, 9] d = 3 assert maxMinDistance(positions, d) == 3 def test_case_2(): positions = [1, 2, 3, 4, 7] d = 3 assert maxMinDistance(positions, d) == 3 def test_case_3(): positions = [5, 5, 5, 5, 5] d = 2 asse...
[ { "docstring": null, "function_declaration": "def canPlaceHouses(positions, d, min_dist):", "function_name": "canPlaceHouses", "parameter_list": "(positions, d, min_dist)" }, { "docstring": null, "function_declaration": "def maxMinDistance(positions, d):", "function_name": "maxMinDis...
[ 1, 0, 1, 1, 0, 1, 1, 0, 1, 1 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def canPlaceHouses(positions, d, min_dist):\n count = 1 # Place the first house at the first position\n last_position = positions[0]\n \n for i in range(1, len(p...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000012229", "row_id": 12229, "seed_ids": "['1452', '1449', '81']" }
0.655661
Leetcode_12229
I
[ "canPlaceHouses", "maxMinDistance" ]
2
[ [ "maxMinDistance", "canPlaceHouses" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ba78421053e2c4cb9181c57ff2f418d45f19a12f
93cacdd78b2afc7cf5b5058cf23873f7c5b00f0a
v1.0
instruct
Leetcode
Leetcode_12263_I
You are given a string `s` and a list of strings `words`. Your task is to find the **maximum** number of strings in `words` that are subsequences of `s`. A subsequence of a string is a new string that is formed from the original string by deleting some (can be none) of the characters without disturbing the relative pos...
def is_subsequence(s, word): it = iter(s) return all(char in it for char in word) def max_subsequences_count(s, words): count = 0 for word in words: if is_subsequence(s, word): count += 1 return count
from solution import max_subsequences_count, is_subsequence def test_max_subsequences_count_basic(): s = "abracadabra" words = ["abra", "bara", "cd", "xyz"] assert max_subsequences_count(s, words) == 3 def test_max_subsequences_count_no_subsequences(): s = "abracadabra" words = ["xyz", "mnop"] ...
[ { "docstring": null, "function_declaration": "def is_subsequence(s, word):", "function_name": "is_subsequence", "parameter_list": "(s, word)" }, { "docstring": null, "function_declaration": "def max_subsequences_count(s, words):", "function_name": "max_subsequences_count", "param...
[ 1, 1, 1, 1, 0, 1, 0, 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_subsequence(s, word):\n \"\"\"\n Helper function to check if `word` is a subsequence of `s`.\n \"\"\"\n it = iter(s)\n return all(char in it for char in...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000012263", "row_id": 12263, "seed_ids": "['1608', '1516', '2558']" }
0.786843
Leetcode_12263
I
[ "is_subsequence", "max_subsequences_count" ]
2
[ [ "max_subsequences_count", "is_subsequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
48ad06fb2bdc346fb047973a03cc6a5ca292fde6
79c7fe6262c5c86c092f721c256426be26a28d61
v1.0
instruct
Leetcode
Leetcode_12480_I
You are given an **unsorted** integer array `arr` and an integer `k`. Your task is to find the **kth largest** element in the array without sorting the entire array. Use the **Quickselect** algorithm to solve this problem. The function should return the `kth` largest element in the array. ### Example: ```python arr =...
def quickselect(arr, left, right, k): """ Helper function to perform the Quickselect operation. """ if left == right: return arr[left] pivot_index = partition(arr, left, right) if k == pivot_index: return arr[k] elif k < pivot_index: return quickselect(arr, ...
from solution import find_kth_largest def test_kth_largest_example1(): arr = [3, 2, 1, 5, 6, 4] k = 2 assert find_kth_largest(arr, k) == 5 def test_kth_largest_example2(): arr = [3, 2, 1, 5, 6, 4] k = 1 assert find_kth_largest(arr, k) == 6 def test_kth_largest_empty_list(): arr = [] k...
[ { "docstring": "Helper function to perform the Quickselect operation.", "function_declaration": "def quickselect(arr, left, right, k):", "function_name": "quickselect", "parameter_list": "(arr, left, right, k)" }, { "docstring": "Helper function to partition the array around the pivot.", ...
[ 1, 0, 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": "import random\n\ndef quickselect(arr, left, right, k):\n if left == right:\n return arr[left]\n \n pivot_index = random.randint(left, right)\n \n pivot_...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000012480", "row_id": 12480, "seed_ids": "['2361', '1968', '1001']" }
0.673553
Leetcode_12480
I
[ "quickselect", "partition", "find_kth_largest" ]
3
[ [ "find_kth_largest", "quickselect" ], [ "quickselect", "partition" ] ]
2
[]
false
[]
false
pytest
true
[]
true
d1a0499f9d63500ebcf31b581806ab86ae3ef374
0a6be3753a9c56f9c45e51c94088c4b71c03709a
v1.0
instruct
Leetcode
Leetcode_12540_I
You are given a string `s` consisting of lowercase English letters, which represents a text document. A **substring** is repeated if it appears more than once in the string. Write a program to find the longest repeated substring in `s`. If there are multiple longest repeated substrings with the same length, return the ...
def longest_repeated_substring(s): """ Returns the longest repeated substring in `s`. If no repeated substring is found, returns an empty string. """ n = len(s) lrs = "" # Create the suffix array suffixes = sorted([s[i:] for i in range(n)]) # Compare adjacent suffixes to find t...
from solution import longest_repeated_substring def test_longest_repeated_substring_example(): assert longest_repeated_substring("banana") == "ana" def test_no_repeated_substring(): assert longest_repeated_substring("abcdef") == "" def test_entire_string_repeated(): assert longest_repeated_substring("aba...
[ { "docstring": "Returns the longest repeated substring in `s`. If no repeated substring is found, returns an empty string.", "function_declaration": "def longest_repeated_substring(s):", "function_name": "longest_repeated_substring", "parameter_list": "(s)" }, { "docstring": "Returns the lon...
[ 1, 1, 0, 0, 1, 1, 1, 0, 0 ]
5
medium
0.556
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_1_results_combined.jsonl", "solution_code": "def longest_repeated_substring(s):\n \"\"\"\n Finds the longest repeated substring in the given string s.\n If no such substring is found, r...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "0000012540", "row_id": 12540, "seed_ids": "['2125', '1057', '2313']" }
0.760208
Leetcode_12540
I
[ "longest_repeated_substring", "_longest_common_prefix" ]
2
[ [ "longest_repeated_substring", "_longest_common_prefix" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c80867fa4c835ed8bd06b7c59d9a4ffc8b324d31
b55f918a10ee30066e4c4f81cb1583562e43e0db
v1.0
instruct
Leetcode
Leetcode_12541_I
Given an integer array `nums` containing unique elements, construct a binary search tree by inserting the elements in the order given by `nums`. Return the root of the binary search tree. Implement a function that will construct and return the root node of the BST, where a class `TreeNode` is defined as: ```python cla...
class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None def insert_into_bst(root, val): # If the root is None, we create and return a new TreeNode with the value if root is None: return TreeNode(val) if val < root.val: # Insert...
from solution import TreeNode, bst_from_preorder def tree_to_list_preorder(root): # Helper function to convert tree to list in preorder traversal if root is None: return [] return [root.val] + tree_to_list_preorder(root.left) + tree_to_list_preorder(root.right) def test_bst_from_preorder_single_el...
[]
[ 1, 1, 1, 1, 1, 0, 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, x):\n self.val = x\n self.left = None\n self.right = None\n\ndef insert_into_bst(root, val):\n \"\"\"\n Hel...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000012541", "row_id": 12541, "seed_ids": "['767', '2145', '1734']" }
0.528049
Leetcode_12541
I
[ "insert_into_bst", "bst_from_preorder" ]
2
[ [ "bst_from_preorder", "insert_into_bst" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
c0e357a65ee86504b802c22664bb450ec3b9961a
4583980bd1ccd33a2e85e430143532f678f12554
v1.0
instruct
Leetcode
Leetcode_12568_I
You are given a string `s` made up of lowercase alphabets. You need to find the longest substring that can be formed by removing at most one character from `s` such that the remaining characters are in alphabetical order. Return the length of this longest alphabetical substring.
def longest_alphabetical_substring(s): """ Returns the length of the longest substring (with at most one character removed) where the remaining characters are in alphabetical order. """ n = len(s) if n == 0: return 0 max_length = 0 for i in range(n): # Check the sub...
from solution import longest_alphabetical_substring def test_longest_alphabetical_substring_without_removal(): assert longest_alphabetical_substring("abcde") == 5 # Already in order def test_longest_alphabetical_substring_remove_one_character(): assert longest_alphabetical_substring("abzcde") == 5 # Removin...
[ { "docstring": "Returns the length of the longest substring (with at most one character removed) \nwhere the remaining characters are in alphabetical order.", "function_declaration": "def longest_alphabetical_substring(s):", "function_name": "longest_alphabetical_substring", "parameter_list": "(s)" ...
[ 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 longest_alphabetical_substring(s):\n \"\"\"\n Returns the length of the longest substring that can be formed by \n removing at most one character from the string...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "0000012568", "row_id": 12568, "seed_ids": "['2553', '2338', '864']" }
0.76936
Leetcode_12568
I
[ "longest_alphabetical_substring", "calculate_length" ]
2
[ [ "longest_alphabetical_substring", "calculate_length" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ca8803937fd7d5550e01ce96666292263970d1c6
1ff567e697e848bfd148ce0f7ecbb272ea93882d
v1.0
instruct
Leetcode
Leetcode_12598_I
You are given a list of integers `nums`. For each integer in the list, check if it is a palindrome. A palindrome is a number that reads the same forwards and backwards (e.g., 121 or 1331). Return a new list containing only the integers from `nums` that are palindromes.
def is_palindrome(n): """ Check if the given integer n is a palindrome. """ return str(n) == str(n)[::-1] def filter_palindromes(nums): """ Given a list of integers, return a list of palindromes. """ return [num for num in nums if is_palindrome(num)]
from solution import is_palindrome, filter_palindromes def test_is_palindrome_true_cases(): assert is_palindrome(121) == True assert is_palindrome(1331) == True assert is_palindrome(1) == True assert is_palindrome(0) == True def test_is_palindrome_false_cases(): assert is_palindrome(123) == False ...
[ { "docstring": "Check if the given integer n is a palindrome.", "function_declaration": "def is_palindrome(n):", "function_name": "is_palindrome", "parameter_list": "(n)" }, { "docstring": "Given a list of integers, return a list of palindromes.", "function_declaration": "def filter_pali...
[ 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_palindrome(n):\n \"\"\"\n Helper function to check if a number is a palindrome.\n \"\"\"\n return str(n) == str(n)[::-1]\n\ndef filter_palindromes(nums):\n...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000012598", "row_id": 12598, "seed_ids": "['2185', '839', '1984']" }
0.691176
Leetcode_12598
I
[ "is_palindrome", "filter_palindromes" ]
2
[ [ "filter_palindromes", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
75435c71cdd73e8e0e6b64c9b9d6f92795e682fb
e1ca4d25b02eed3cd9b1347c1d619598278f8044
v1.0
instruct
Leetcode
Leetcode_12633_I
Given two integers `a` and `b`, their **Hamming distance** is the number of positions at which the corresponding bits are different. Write a function that, given an integer array `nums`, returns the sum of Hamming distances between all pairs of the integers in `nums`.
def hamming_distance(a, b): """ Calculate the Hamming distance between two integers. """ return bin(a ^ b).count('1') def total_hamming_distance(nums): """ Calculate the sum of Hamming distances between all pairs of integers in the array nums. """ total_distance = 0 n = len(nums) ...
from solution import hamming_distance, total_hamming_distance def test_hamming_distance(): assert hamming_distance(1, 4) == 2, "Test Case 1 Failed" assert hamming_distance(0, 15) == 4, "Test Case 2 Failed" assert hamming_distance(0, 0) == 0, "Test Case 3 Failed" assert hamming_distance(2, 3) == 1, "Tes...
[ { "docstring": "Calculate the Hamming distance between two integers.", "function_declaration": "def hamming_distance(a, b):", "function_name": "hamming_distance", "parameter_list": "(a, b)" }, { "docstring": "Calculate the sum of Hamming distances between all pairs of integers in the array n...
[ 1, 1, 0, 0, 0, 0, 0, 1, 1, 0 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def totalHammingDistance(nums):\n \"\"\"\n Given an integer array `nums`, returns the sum of Hamming distances between all pairs of the integers in `nums`.\n \"\"\"\...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000012633", "row_id": 12633, "seed_ids": "['775', '244', '385']" }
0.72626
Leetcode_12633
I
[ "hamming_distance", "total_hamming_distance" ]
2
[ [ "total_hamming_distance", "hamming_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
79ceaba6c57ad4202b07df672e88199c4f0f0350
ab45b6d4e1a60e6407d4014a2b7445efd4035432
v1.0
instruct
Leetcode
Leetcode_12699_I
You are given a 2D list of integers `matrix` where the shape of the matrix is `mxn`. A **magic square** is a `3x3` grid of distinct integers from 1 to 9 where the sum of the numbers in each row, column, and diagonal is equal. Write a function to count all magic squares inside the given `m x n` matrix. * A magic squar...
def is_magic(square): """ Check if a 3x3 grid is a magic square. """ s = list(set([square[i][j] for i in range(3) for j in range(3)])) if sorted(s) != list(range(1, 10)): return False rows = [sum(square[i]) for i in range(3)] cols = [sum([square[i][j] for i in range(3)]) for j i...
from solution import num_magic_squares_inside def test_no_magic_squares(): grid = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] assert num_magic_squares_inside(grid) == 0 def test_one_magic_square(): grid = [ [4, 3, 8, 4], [9, 5, 1, 9], [2, 7, 6, 2] ] asse...
[ { "docstring": "Check if a 3x3 grid is a magic square.", "function_declaration": "def is_magic(square):", "function_name": "is_magic", "parameter_list": "(square)" }, { "docstring": "Count all 3x3 magic squares inside the given grid.", "function_declaration": "def num_magic_squares_insid...
[ 1, 1, 0, 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": "def is_magic(square):\n \"\"\"\n Check if a 3x3 square is a magic square.\n \"\"\"\n # Magic square values must be from 1 to 9, and all of them distinct\n vali...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000012699", "row_id": 12699, "seed_ids": "['1797', '1022', '2178']" }
0.719094
Leetcode_12699
I
[ "is_magic", "num_magic_squares_inside" ]
2
[ [ "num_magic_squares_inside", "is_magic" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d60566ef731aa3b12f3fb4c2acd8b53f42c2f998
e60a60668f799405207ddbbb4f8b667e5f72b8c7
v1.0
instruct
Leetcode
Leetcode_12756_I
You are given an integer array `nums`. An array is considered beautiful if there is no index `i` such that `nums[i]` is divisible by any preceding element `nums[j]` where `j < i`. Write a function that modifies the given array by rearranging elements to form a beautiful array if possible. If it is not possible, return ...
def beautiful_array(nums): def construct(l): if len(l) <= 1: return l odds = construct(l[::2]) evens = construct(l[1::2]) return odds + evens nums.sort() result = construct(nums) return result if is_beautiful(result) else [] def is_beautiful(nums): for i...
from solution import beautiful_array, is_beautiful def test_beautiful_array_example(): nums = [2, 3, 4, 5, 6] result = beautiful_array(nums) assert is_beautiful(result) def test_beautiful_array_impossible(): nums = [1, 2] result = beautiful_array(nums) assert result == [] def test_beautiful_a...
[ { "docstring": null, "function_declaration": "def beautiful_array(nums):", "function_name": "beautiful_array", "parameter_list": "(nums)" }, { "docstring": null, "function_declaration": "def is_beautiful(nums):", "function_name": "is_beautiful", "parameter_list": "(nums)" }, ...
[ 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def beautiful_array(nums):\n def construct(l):\n if len(l) <= 1:\n return l\n odds = construct(l[::2])\n evens = construct(l[1::2])\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "0000012756", "row_id": 12756, "seed_ids": "['2609', '1036', '661']" }
0.638891
Leetcode_12756
I
[ "beautiful_array", "is_beautiful" ]
2
[ [ "beautiful_array", "is_beautiful" ] ]
1
[]
false
[]
false
pytest
true
[]
true
bd791e36b7c94ed5b937209898361a9632c6d49e
0ac2a9f53f5ff25dbb18878f04b429e7b4e455d0
v1.0
instruct
Leetcode
Leetcode_13093_I
You are given a list of strings `words` where each word is exactly the same length. Create a function that finds all pairs of indices `(i, j)` such that the concatenation of `words[i]` and `words[j]` forms a palindrome. Return a list of all the pairs of indices. A string is considered a palindrome if it reads the same ...
def is_palindrome(s): """ Check if a given string s is a palindrome. """ return s == s[::-1] def palindrome_pairs(words): """ Finds all pairs of indices (i, j) such that the concatenation of words[i] and words[j] forms a palindrome. Parameters: words (list of str): A list of eq...
from solution import palindrome_pairs def test_single_pair(): words = ["bat", "tab", "cat"] result = palindrome_pairs(words) expected = [(0, 1), (1, 0)] assert result == expected def test_no_palindrome(): words = ["abc", "def", "ghi"] result = palindrome_pairs(words) expected = [] asse...
[ { "docstring": "Check if a given string s is a palindrome.", "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": "Finds all pairs of indices (i, j) such that the concatenation of words[i]\nand words[j] forms a palindrom...
[ 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 palindrome_pairs(words):\n \"\"\"\n Finds pairs of indices such that the concatenation of words[i] and words[j] forms a palindrome.\n\n Parameters:\n words (L...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "0000013093", "row_id": 13093, "seed_ids": "['80', '1162', '2459']" }
0.738342
Leetcode_13093
I
[ "is_palindrome", "palindrome_pairs" ]
2
[ [ "palindrome_pairs", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
aaeebb13aa2aa0efc6d6b3d504fd12f10efef484
83be753075e5d28608fdfe20cf4233accf7e2400
v1.0
instruct
Leetcode
Leetcode_13141_I
You are given a string `s` and an array of intervals `intervals`. Each interval represents a pair of integer indices `[start, end]` with `0 <= start <= end < len(s)`. Merge overlapping intervals and use them to extract a combined substring from `s`. Return _the lexicographically smallest substring that can be obtained ...
def merge_intervals(intervals): """ Merges overlapping intervals. """ intervals.sort() merged = [] for interval in intervals: if not merged or merged[-1][1] < interval[0]: merged.append(interval) else: merged[-1][1] = max(merged[-1][1], interval[1]) re...
from solution import get_lexicographically_smallest_substring def test_single_interval(): s = "abracadabra" intervals = [[0, 3]] assert get_lexicographically_smallest_substring(s, intervals) == "abra" def test_non_overlapping_intervals(): s = "abracadabra" intervals = [[0, 3], [4, 7]] assert g...
[ { "docstring": "Merges overlapping intervals.", "function_declaration": "def merge_intervals(intervals):", "function_name": "merge_intervals", "parameter_list": "(intervals)" }, { "docstring": "Extracts substrings from the merged intervals and returns the lexicographically smallest substring...
[ 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 lexicographically_smallest_substring(s, intervals):\n \"\"\"\n Given a string s and array of intervals, returns the lexicographically smallest substring \n after...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "0000013141", "row_id": 13141, "seed_ids": "['1486', '768', '466']" }
0.66901
Leetcode_13141
I
[ "merge_intervals", "extract_substrings", "get_lexicographically_smallest_substring" ]
3
[ [ "extract_substrings", "merge_intervals" ], [ "get_lexicographically_smallest_substring", "extract_substrings" ] ]
2
[]
false
[]
false
pytest
true
[]
true
4b8cdb4ffb2b2d3781ca80b507486d33dd34cd50
50367fadc065c7cbe135c2e36f55f20757526c50
v1.0
instruct
Leetcode
Leetcode_13479_I
You are given a 2D grid `grid` of size `m x n` consisting of non-negative integers, where `grid[i][j]` represents the height of a point `(i, j)` in a certain area. You can start from any point in the first row and try to reach any point in the last row. At each step, you can move to the cell directly below, to the cell...
def can_reach_last_row(grid, m, n, row, col, prev_height): if row >= m: return False if grid[row][col] > prev_height: return False if row == m - 1: return True down = right_diag = left_diag = False if row + 1 < m: down = can_reach_last_row(grid, m, n, row + 1, col, g...
def test_can_reach_last_row(): grid = [ [4, 3, 2, 1], [3, 2, 1, 0], [2, 1, 0, 0], [1, 0, 0, 0] ] assert can_reach_last_row(grid, 4, 4, 0, 0, 4) == True assert can_reach_last_row(grid, 4, 4, 0, 1, 3) == True assert can_reach_last_row(grid, 4, 4, 0, 2, 2) == True as...
[ { "docstring": null, "function_declaration": "def can_reach_last_row(grid, m, n, row, col, prev_height):", "function_name": "can_reach_last_row", "parameter_list": "(grid, m, n, row, col, prev_height)" }, { "docstring": null, "function_declaration": "def max_height_to_reach_last_row(grid...
[ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def max_start_height(grid):\n \"\"\"\n Returns the maximum height from the first row to reach the last row in the given grid.\n \"\"\"\n if not grid or not grid[0...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "0000013479", "row_id": 13479, "seed_ids": "['2105', '2076', '2027']" }
0.715503
Leetcode_13479
I
[ "can_reach_last_row", "max_height_to_reach_last_row" ]
2
[ [ "max_height_to_reach_last_row", "can_reach_last_row" ] ]
1
[]
false
[]
false
pytest
false
[]
true
9f0ee6ba04e59d5409e5b7f39a2d503f0cfb24fa
c83d44f4fa474d755f63802d34d5473272c2d196
v1.0
instruct
Leetcode
Leetcode_13495_I
Given the root of a binary search tree (BST), return a balanced BST that has the same node values. A balanced BST is defined as a binary tree in which the depth of the two subtrees of every node never differs by more than 1. If there are multiple solutions, return any of them.
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def sorted_array_to_bst(nums): """ Converts a sorted array to a balanced BST. """ if not nums: return None mid = len(nums) // 2 root = Tr...
from solution import TreeNode, balance_bst, inorder_traversal def is_balanced(root): """ Helper function to check if a binary tree is balanced. """ def check(root): if not root: return 0, True left_height, left_balanced = check(root.left) right_height, right...
[]
[ 1, 1, 0, 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 balanceBST(root):\...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000013495", "row_id": 13495, "seed_ids": "['894', '1609', '464']" }
0.685503
Leetcode_13495
I
[ "sorted_array_to_bst", "inorder_traversal", "balance_bst" ]
3
[ [ "balance_bst", "inorder_traversal" ], [ "balance_bst", "sorted_array_to_bst" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
8305a5cce30be23397c0de458272f647bbd6b751
2d5f57ea0e7d020b4c77e5fbf8f1a952539969d8
v1.0
instruct
Leetcode
Leetcode_13578_I
Given a 2D grid of characters representing a **maze** and a pair of coordinates representing the start and end positions `(x_start, y_start)` and `(x_end, y_end)`, write an algorithm to determine if there is a path from start to end. Each character in the grid is either a `' '`, meaning an open cell, or a `'#'`, meanin...
def is_valid_move(maze, x, y): """ Check if the move is within the maze and on an open cell. """ return 0 <= x < len(maze) and 0 <= y < len(maze[0]) and maze[x][y] == ' ' def find_path(maze, x_start, y_start, x_end, y_end): """ Returns whether there is a path from (x_start, y_start) to (x_end, ...
from solution import find_path def test_maze_no_walls(): maze = [ [' ', ' ', ' '], [' ', ' ', ' '], [' ', ' ', ' '] ] assert find_path(maze, 0, 0, 2, 2) == True assert find_path(maze, 0, 0, 1, 1) == True def test_maze_with_walls(): maze = [ [' ', ' ', '#'], ...
[ { "docstring": "Check if the move is within the maze and on an open cell.", "function_declaration": "def is_valid_move(maze, x, y):", "function_name": "is_valid_move", "parameter_list": "(maze, x, y)" }, { "docstring": "Returns whether there is a path from (x_start, y_start) to (x_end, y_end...
[ 0, 1, 0, 0, 1, 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 has_path(maze, start, end):\n \"\"\"\n Determine if there is a path from start to end in the maze.\n \n :param maze: List[List[str]] - A 2D list representing ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000013578", "row_id": 13578, "seed_ids": "['1952', '417', '428']" }
0.65538
Leetcode_13578
I
[ "is_valid_move", "find_path" ]
2
[ [ "find_path", "is_valid_move" ] ]
1
[]
false
[]
false
pytest
true
[]
true
23a36e5f97a527c09648cbe8e864a109a8a4be5d
13c34278541f51b55ef8c04910c26a3172e904e0
v1.0
instruct
Leetcode
Leetcode_13654_I
Given an integer `n`, return the smallest prime number that is greater than `n`. To solve the problem, you need to implement a function that efficiently checks for the next prime number beyond the given integer `n`. A prime number is a positive integer greater than 1 that has no positive integer divisors other than 1...
def is_prime(num): """ Helper function to check if a number is prime. """ if num <= 1: return False if num <= 3: return True if num % 2 == 0 or num % 3 == 0: return False i = 5 while i * i <= num: if num % i == 0 or num % (i + 2) == 0: return F...
from solution import next_prime def test_next_prime_small_numbers(): assert next_prime(1) == 2 assert next_prime(2) == 3 assert next_prime(3) == 5 assert next_prime(4) == 5 assert next_prime(5) == 7 def test_next_prime_larger_numbers(): assert next_prime(10) == 11 assert next_prime(11) == ...
[ { "docstring": "Helper function to check if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns the smallest prime number that is greater than n.", "function_declaration": "def next_prime(n):...
[ 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 is_prime(num):\n \"\"\"\n Returns True if the given number is a prime number, False otherwise.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000013654", "row_id": 13654, "seed_ids": "['408', '533', '1520']" }
0.624805
Leetcode_13654
I
[ "is_prime", "next_prime" ]
2
[ [ "next_prime", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
487006d474aa679be577d870553d04bfcf2eb9a9
6fe321dd4b027c0bfc91120f987d8748ce7a1785
v1.0
instruct
Leetcode
Leetcode_13666_I
You are given a string `s` which only consists of characters 'a', 'b', and 'c'. You can replace any character in `s` with any other character 'a', 'b', or 'c' at most once. Return the length of the longest substring of `s` that contains at most one distinct character after performing any allowed transformation.
def longest_substring_with_one_distinct_char(s): """ Returns the length of the longest substring with at most one distinct character after performing at most one character replacement in the input string. """ max_length = 0 for i in range(len(s)): for char in 'abc': mod...
def test_longest_substring_with_one_distinct_char(): assert longest_substring_with_one_distinct_char("aab") == 3 assert longest_substring_with_one_distinct_char("abc") == 2 assert longest_substring_with_one_distinct_char("aaacb") == 4 assert longest_substring_with_one_distinct_char("cbbc") == 3 asse...
[ { "docstring": "Returns the length of the longest substring with at most one distinct character \nafter performing at most one character replacement in the input string.", "function_declaration": "def longest_substring_with_one_distinct_char(s):", "function_name": "longest_substring_with_one_distinct_ch...
[ 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 longest_one_distinct_transformation(s):\n \"\"\"\n Transforms the string up to 1 character modification and finds the length \n of the longest substring containi...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000013666", "row_id": 13666, "seed_ids": "['2470', '1505', '338']" }
0.78449
Leetcode_13666
I
[ "longest_substring_with_one_distinct_char", "longest_one_char_segment" ]
2
[ [ "longest_substring_with_one_distinct_char", "longest_one_char_segment" ] ]
1
[]
false
[]
false
pytest
false
[]
true
1deaf36d9536202b559bacd5e405964cf36241ad
5eba3e2638c5775cf4f62045b467c277e18e50d9
v1.0
instruct
Leetcode
Leetcode_13785_I
Given a string `s` containing only lowercase letters, you need to find and return all possible **palindrome partitions** of `s`. A palindrome partitioning of a string is a decomposition of the string into substrings such that each substring is a palindrome. Each substring must be a contiguous block of characters from t...
def is_palindrome(s): """ Determines if a given string s is a palindrome. """ return s == s[::-1] def backtrack(start, s, path, result): """ Uses backtracking to find all palindrome partitions from the start index. """ if start == len(s): result.append(path[:]) return ...
from solution import palindrome_partitions def test_single_character(): assert palindrome_partitions("a") == [["a"]] def test_two_characters_palindrome(): assert palindrome_partitions("aa") == [["a", "a"], ["aa"]] def test_two_characters_non_palindrome(): assert palindrome_partitions("ab") == [["a", "b"]...
[ { "docstring": "Determines if a given string s is a palindrome.", "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": "Uses backtracking to find all palindrome partitions from the start index.", "function_declaratio...
[ 1, 0, 1, 1, 0, 0, 1, 1, 0, 0 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_palindrome(s):\n return s == s[::-1]\n\ndef partition(s):\n def dfs(start, path, res):\n if start >= len(s):\n res.append(path.copy())\n ...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "0000013785", "row_id": 13785, "seed_ids": "['425', '976', '861']" }
0.713646
Leetcode_13785
I
[ "is_palindrome", "backtrack", "palindrome_partitions" ]
3
[ [ "backtrack", "is_palindrome" ], [ "palindrome_partitions", "backtrack" ] ]
2
[]
false
[]
false
pytest
true
[]
true
5337675dbb55dd0ac9f8341a3f1d6392ec0787ec
723bb2e8adcccf75c4aba0963928b12d8a656683
v1.0
instruct
Leetcode
Leetcode_13787_I
You are given a list of strings `words` containing lowercase English letters. A word is called **universal** if all the letters in a given string `chars` appear in it at least as many times as they appear in `chars`. Return _a list of all **universal** words in_ `words`. The output list should be sorted in lexicographi...
from collections import Counter def is_universal_word(word, chars_count): word_count = Counter(word) for char, count in chars_count.items(): if word_count[char] < count: return False return True def universal_words(words, chars): chars_count = Counter(chars) universal_list = [w...
from solution import universal_words def test_basic(): words = ["apple", "banana", "cherry", "date"] chars = "an" assert universal_words(words, chars) == ["banana"] def test_multiple_universals(): words = ["apple", "banana", "ananas", "date"] chars = "an" assert universal_words(words, chars) =...
[ { "docstring": null, "function_declaration": "def is_universal_word(word, chars_count):", "function_name": "is_universal_word", "parameter_list": "(word, chars_count)" }, { "docstring": null, "function_declaration": "def universal_words(words, chars):", "function_name": "universal_wo...
[ 1, 0, 0, 1, 1, 0, 0, 0, 0, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def count_characters(word):\n \"\"\"\n Returns a dictionary with character counts in the given word.\n \"\"\"\n char_count = {}\n for char in word:\n if...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "0000013787", "row_id": 13787, "seed_ids": "['1647', '419', '1736']" }
0.658331
Leetcode_13787
I
[ "is_universal_word", "universal_words" ]
2
[ [ "universal_words", "is_universal_word" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d926e9992a553b2b4145ce0903c9b287eaae5a1d
50b5c8bde92b05d60bd19aea7442d12b1a75954d
v1.0
instruct
Leetcode
Leetcode_13803_I
You are given a binary tree with `n` nodes. Each node has a unique value in the range `[1, n]`. You need to perform the following operations on the tree: 1. Query the number of nodes in the subtree rooted at a given node. 2. Compute the depth of a given node in the tree. Implement a function that accepts the tree str...
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def count_subtree_nodes(root): if not root: return 0 return 1 + count_subtree_nodes(root.left) + count_subtree_nodes(root.right) def find_node(root, val, dep...
from solution import TreeNode, process_queries def test_count_subtree_nodes(): root = TreeNode(1) root.left = TreeNode(2) root.right = TreeNode(3) root.left.left = TreeNode(4) root.left.right = TreeNode(5) root.right.left = TreeNode(6) root.right.right = TreeNode(7) assert process_...
[]
[ 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": "class TreeNode:\n def __init__(self, value):\n self.value = value\n self.children = []\n\ndef count_subtree_nodes(node):\n \"\"\" Helper function to count...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000013803", "row_id": 13803, "seed_ids": "['163', '2612', '1250']" }
0.552846
Leetcode_13803
I
[ "count_subtree_nodes", "find_node", "process_queries" ]
3
[ [ "process_queries", "count_subtree_nodes" ], [ "process_queries", "find_node" ] ]
2
[ "process_queries" ]
false
[ "TreeNode" ]
true
pytest
true
[]
true
9ca11612c4778580ccf30d56522b39d974ec56fc
a759e137b9bb511a3c439b94135c08309d8289a8
v1.0
instruct
Leetcode
Leetcode_13819_I
You are given a list of `n` files where each file is represented by its path as a string in a list called `files`. Each file contains a string of lowercase alphabets. Two files are said to be **similar** if they have at least one common subsequence of length `k` (where `k` is a given positive integer). Your task is to ...
from collections import defaultdict import itertools def find_common_subsequences(s1, s2, length): """ Returns True if there is at least one common subsequence of given length `length` between strings `s1` and `s2`. """ s1_subsequences = {s1[i:i+length] for i in range(len(s1) - length + 1)} s2_subs...
from solution import find_group_count def test_no_files(): assert find_group_count([], 3) == 0 def test_single_file(): assert find_group_count(["abc"], 2) == 1 def test_all_files_similar(): assert find_group_count(["abc", "bcd", "cde"], 2) == 1 def test_no_files_similar(): assert find_group_count(["...
[ { "docstring": "Returns True if there is at least one common subsequence of given length `length` between strings `s1` and `s2`.", "function_declaration": "def find_common_subsequences(s1, s2, length):", "function_name": "find_common_subsequences", "parameter_list": "(s1, s2, length)" }, { "...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "from itertools import combinations\nfrom collections import defaultdict\n\ndef has_common_subsequence(file1, file2, k):\n \"\"\"\n Check if two files have at least one ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000013819", "row_id": 13819, "seed_ids": "['924', '452', '2548']" }
0.564138
Leetcode_13819
I
[ "find_common_subsequences", "find_group_count" ]
2
[ [ "find_group_count", "find_common_subsequences" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8a569f3f77b5200f025e53ef14421aad54a678b9
6e496c292ac8281578907bf001e96c027534129f
v1.0
instruct
Leetcode
Leetcode_13877_I
Given an integer `n`, generate a list of the first `n` prime numbers in ascending order.
def is_prime(num): """ Checks if a number is prime. """ if num <= 1: return False if num == 2: return True if num % 2 == 0: return False p = 3 while p * p <= num: if num % p == 0: return False p += 2 return True def generate_primes...
from solution import generate_primes, is_prime def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(17) == True assert is_prime(18) == False assert is_prime(19) == True assert is_prime(1) == False assert is_prime(-5) == F...
[ { "docstring": "Checks if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Generates a list of the first `n` prime numbers in ascending order.", "function_declaration": "def generate_primes(n):", ...
[ 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(num):\n \"\"\"\n Check if a number is a prime.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 =...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000013877", "row_id": 13877, "seed_ids": "['59', '1100', '2133']" }
0.64656
Leetcode_13877
I
[ "is_prime", "generate_primes" ]
2
[ [ "generate_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0309cd8d336adc8d1428037ea409d3b44f13458e
220cb740ae1c45d07cf0b5104d08245332af4c4a
v1.0
instruct
Leetcode
Leetcode_13889_I
A company has a network that consists of a mixture of wired and wireless connections between servers. Each connection between two servers has a latency (in milliseconds). You are given a list of connections, where each connection is represented as a tuple `(server1, server2, latency)`. A network administrator wants to ...
def find(parent, i): if parent[i] == i: return i else: return find(parent, parent[i]) def union(parent, rank, x, y): root_x = find(parent, x) root_y = find(parent, y) if root_x != root_y: if rank[root_x] > rank[root_y]: parent[root_y] = root_x ...
def test_minimumLatency_full_connectivity(): assert minimumLatency(4, [(0, 1, 1), (1, 2, 2), (2, 3, 1), (0, 2, 2)]) == 4 def test_minimumLatency_one_connection(): assert minimumLatency(2, [(0, 1, 10)]) == 10 def test_minimumLatency_no_connection(): assert minimumLatency(4, [(0, 1, 1), (2, 3, 2)]) == -1 d...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 0, 0, 0, 0, 0, 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 minimumLatency(n, connections):\n \"\"\"\n Returns the minimum total latency required to connect all servers.\n \"\"\"\n # Helper function to find the parent ...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "0000013889", "row_id": 13889, "seed_ids": "['1604', '575', '991']" }
0.567631
Leetcode_13889
I
[ "find", "union", "minimumLatency" ]
3
[ [ "minimumLatency", "find" ], [ "minimumLatency", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
false
[]
true
5b566369f9aca3bd3d188a31fcb6f56ec42ec5a0
ccf7a698ed690538dc9690eec0850ff31c0f32ce
v1.0
instruct
Leetcode
Leetcode_13941_I
You are given an integer array `nums` where each element is unique. You want to construct a binary search tree (BST) from `nums` where the following two conditions are met: * The root node is `nums[0]`. * If there is a node in the tree with a value `nums[j]`, then `nums[j]` appears in the right subtree of `num...
class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None def insert_into_bst(root, val): if root is None: return TreeNode(val) if val < root.val: root.left = insert_into_bst(root.left, val) else: root.right = insert_into_bst(...
from solution import constructBST def test_constructBST_example(): assert constructBST([8, 5, 10, 1, 7, 12]) == [1, 5, 7, 8, 10, 12] def test_constructBST_single_element(): assert constructBST([5]) == [5] def test_constructBST_two_elements(): assert constructBST([5, 3]) == [3, 5] assert constructBST(...
[]
[ 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, 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_8
{ "original_instruction": "", "prompt_id": "0000013941", "row_id": 13941, "seed_ids": "['38', '292', '2596']" }
0.599819
Leetcode_13941
I
[ "insert_into_bst", "inorder_traversal", "constructBST" ]
3
[ [ "constructBST", "inorder_traversal" ], [ "constructBST", "insert_into_bst" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
c48ee923d127e5771f438275cf98bcc5f378d665
a8ef26a5b023fb42a2f68f78d31e47535d26fbdf
v1.0
instruct
Leetcode
Leetcode_13998_I
You are given a matrix `mat` of size `m x n` consisting of **positive** integers. You can **rotate** the matrix 90 degrees clockwise. Return _the **maximum** sum of the elements in any row of the matrix after performing any number of rotations._
def rotate_matrix_90_degrees_clockwise(matrix): """ Rotate the matrix 90 degrees clockwise. """ return [list(row) for row in zip(*matrix[::-1])] def max_row_sum_after_rotations(matrix): """ Return the maximum sum of the elements in any row of the matrix after performing any number of 90 deg...
from solution import max_row_sum_after_rotations, rotate_matrix_90_degrees_clockwise def test_rotate_matrix_90_degrees_clockwise(): assert rotate_matrix_90_degrees_clockwise([[1, 2], [3, 4]]) == [[3, 1], [4, 2]] assert rotate_matrix_90_degrees_clockwise([[1, 2, 3], [4, 5, 6]]) == [[4, 1], [5, 2], [6, 3]] def ...
[ { "docstring": "Rotate the matrix 90 degrees clockwise.", "function_declaration": "def rotate_matrix_90_degrees_clockwise(matrix):", "function_name": "rotate_matrix_90_degrees_clockwise", "parameter_list": "(matrix)" }, { "docstring": "Return the maximum sum of the elements in any row of the...
[ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def rotate_matrix_90_degrees_clockwise(matrix):\n \"\"\"\n Rotate the matrix 90 degrees clockwise.\n \"\"\"\n return [list(row) for row in zip(*matrix[::-1])]\n\n...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "0000013998", "row_id": 13998, "seed_ids": "['2111', '2594', '2393']" }
0.520799
Leetcode_13998
I
[ "rotate_matrix_90_degrees_clockwise", "max_row_sum_after_rotations" ]
2
[ [ "max_row_sum_after_rotations", "rotate_matrix_90_degrees_clockwise" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9e0547ad9bd37db19c3a69d948ea693fed1df387
6d4c4ef561a2231e342fdd36f6e726c2d8400838
v1.0
instruct
Leetcode
Leetcode_14160_I
You are given a binary tree where each node has a value `val` from `0` to `4`. Each step, you can choose one or multiple nodes at the current level and swap their subtrees. Distance between two nodes is the number of edges along the shortest path connecting them. Your task is to determine the minimum number of swaps re...
def min_swaps_to_sort(arr): """ Helper function to count the minimum number of swaps required to sort an array. """ n = len(arr) arrpos = [(val, idx) for idx, val in enumerate(arr)] arrpos.sort() visited = {k: False for k in range(n)} ans = 0 for i in range(n): if visite...
from solution import TreeNode, min_swaps_binary_tree def test_single_node(): root = TreeNode(1) assert min_swaps_binary_tree(root) == 0 def test_already_sorted(): root = TreeNode(1, TreeNode(2), TreeNode(3)) assert min_swaps_binary_tree(root) == 0 def test_unsorted(): root = TreeNode(1, TreeNode(...
[]
[ 0, 1, 0, 0, 0, 0, 1, 0, 0 ]
2
hard
0.222
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "from collections import defaultdict, deque\n\nclass TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "0000014160", "row_id": 14160, "seed_ids": "['1192', '2217', '1805']" }
0.548743
Leetcode_14160
I
[ "min_swaps_to_sort", "level_order_traversal", "min_swaps_binary_tree" ]
3
[ [ "min_swaps_binary_tree", "level_order_traversal" ], [ "min_swaps_binary_tree", "min_swaps_to_sort" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
960334b5515e99e724801015b49a8d55a7f303fd
b0f4de8be128bf7cd7d83c3c9978fa5fbc5b07a5
v1.0
instruct
Leetcode
Leetcode_14416_I
Given a `matrix` of `n` x `m` dimensions filled with positive integers, implement a function to find the maximum sum of any rectangle inside the matrix. The rectangle inside the matrix is defined by selecting a row pair and a column pair that forms a contiguous sub-matrix. Return the highest possible sum of any such su...
def max_sum_submatrix(matrix): """ Finds the maximum sum of any rectangle inside the given matrix. :param matrix: List of List of positive integers representing the matrix :return: Maximum sum of sub-matrix """ if not matrix or not matrix[0]: return 0 n, m = len(matrix), le...
from solution import max_sum_submatrix def test_max_sum_submatrix_basic(): matrix = [ [1, 2, -1, -4, -20], [-8, -3, 4, 2, 1], [3, 8, 10, 1, 3], [-4, -1, 1, 7, -6] ] assert max_sum_submatrix(matrix) == 29 # The submatrix from (1, 1) to (3, 3) def test_max_sum_submatrix_sing...
[ { "docstring": "Finds the maximum sum of any rectangle inside the given matrix.\n\n:param matrix: List of List of positive integers representing the matrix\n:return: Maximum sum of sub-matrix", "function_declaration": "def max_sum_submatrix(matrix):", "function_name": "max_sum_submatrix", "parameter...
[ 1, 1, 1, 0, 1, 0, 1, 0, 1, 0 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def max_submatrix_sum(matrix):\n \"\"\"\n Returns the maximum sum of any rectangle inside the matrix.\n \"\"\"\n if not matrix or not matrix[0]:\n return 0...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "0000014416", "row_id": 14416, "seed_ids": "['514', '1409', '509']" }
0.689219
Leetcode_14416
I
[ "max_sum_submatrix", "kadane" ]
2
[ [ "max_sum_submatrix", "kadane" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1ef35b7dcda3688d343d9343002bab59c678be5e
8c283c76e97eedc2e5d2797e75b7c98f3324a237
v1.0
instruct
Leetcode
Leetcode_14447_I
Given two integers `a` and `b`, find the maximum number of consecutive integers that can be evenly divided by either `a` or `b`. Note that the integers must be positive and start from 1. Return the maximum count of such consecutive integers.
def max_divisible_sequence(a, b): """ Returns the maximum number of consecutive integers that can be evenly divided by either a or b starting from 1. """ if a <= 0 or b <= 0: raise ValueError("Both a and b should be positive integers.") lcm_ab = (a * b) // gcd(a, b) return...
from solution import max_divisible_sequence def test_max_divisible_sequence(): assert max_divisible_sequence(2, 3) == 6 assert max_divisible_sequence(1, 2) == 2 assert max_divisible_sequence(5, 7) == 35 assert max_divisible_sequence(6, 8) == 24 assert max_divisible_sequence(3, 4) == 12 def test_ma...
[ { "docstring": "Returns the maximum number of consecutive integers that can be evenly divided \nby either a or b starting from 1.", "function_declaration": "def max_divisible_sequence(a, b):", "function_name": "max_divisible_sequence", "parameter_list": "(a, b)" }, { "docstring": "Computes t...
[ 1, 1, 1, 1, 1, 0, 1, 0, 0, 0 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def max_consecutive_divisible(a, b):\n \"\"\"\n Returns the maximum number of consecutive integers that can be evenly divided \n by either a or b.\n \"\"\"\n l...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "0000014447", "row_id": 14447, "seed_ids": "['1243', '1111', '976']" }
0.592505
Leetcode_14447
I
[ "max_divisible_sequence", "gcd" ]
2
[ [ "max_divisible_sequence", "gcd" ] ]
1
[]
false
[]
false
pytest
true
[]
true
26e256197c732a20065da021b0435756d1fd2d20
59df3e4387b912157932d7d07bfe386fe1b462be
v1.0
instruct
Leetcode
Leetcode_14473_I
You have been tasked with implementing a simplified version of a spell checker. Given a list of words in a dictionary and a string containing a single word, determine whether the given word is spelled correctly. A word is considered correctly spelled if it exactly matches one of the words in the dictionary (case-sens...
def edit_distance(word1, word2): """ Compute the edit distance between two words. """ len1, len2 = len(word1), len(word2) dp = [[0] * (len2 + 1) for _ in range(len1 + 1)] for i in range(len1 + 1): for j in range(len2 + 1): if i == 0: dp[i][j] = j ...
from solution import spell_checker def test_word_in_dictionary(): dictionary = ["solution", "solver", "testing", "example"] assert spell_checker(dictionary, "solution") == "solution" assert spell_checker(dictionary, "testing") == "testing" def test_word_not_in_dictionary(): dictionary = ["solution", "...
[ { "docstring": "Compute the edit distance between two words.", "function_declaration": "def edit_distance(word1, word2):", "function_name": "edit_distance", "parameter_list": "(word1, word2)" }, { "docstring": "Check the spelling of a given word against a dictionary.", "function_declarat...
[ 0, 1, 1, 0, 0, 1, 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": "def edit_distance(word1, word2):\n len1, len2 = len(word1), len(word2)\n dp = [[0] * (len2 + 1) for _ in range(len1 + 1)]\n\n for i in range(len1 + 1):\n for ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000014473", "row_id": 14473, "seed_ids": "['190', '445', '1165']" }
0.623956
Leetcode_14473
I
[ "edit_distance", "spell_checker" ]
2
[ [ "spell_checker", "edit_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4b6ba1531f6b4d416d6f93aeabfaad75ebe4c7df
a6f529602d9a197461e5088f0210be3cf00b5ac7
v1.0
instruct
Leetcode
Leetcode_14649_I
You are given two arrays `words1` and `words2`. A string `b` is a **universal string** of an array of strings `words` if for every string `a` in `words`, every letter in `a` appears in `b` at least as many times as it appears in `a`. For example, "abca" is a universal string for ["a", "abc"], but "abc" is not because t...
from collections import Counter def is_universal(b, words): """ Helper function to determine if string b is a universal string for the array words. """ b_counter = Counter(b) for word in words: word_counter = Counter(word) for char, count in word_counter.items(): if b_co...
from solution import universal_strings def test_universal_strings_1(): words1 = ["a"] words2 = ["a", "b", "ab", "abc"] assert universal_strings(words1, words2) == ["a", "ab", "abc"] def test_universal_strings_2(): words1 = ["abc"] words2 = ["a", "b", "ab", "abc"] assert universal_strings(words...
[ { "docstring": "Helper function to determine if string b is a universal string for the array words.", "function_declaration": "def is_universal(b, words):", "function_name": "is_universal", "parameter_list": "(b, words)" }, { "docstring": "Returns an array of strings in words2 that are unive...
[ 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 max_frequency(words):\n \"\"\"\n Calculate the maximum frequency of each character across all words.\n \"\"\"\n max_freq = ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000014649", "row_id": 14649, "seed_ids": "['291', '1545', '1266']" }
0.702249
Leetcode_14649
I
[ "is_universal", "universal_strings" ]
2
[ [ "universal_strings", "is_universal" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8e3d97921d460db425524a4756620c2051d94d35
e52196903fd829ed0f52d23b21c566fbb764397d
v1.0
instruct
Leetcode
Leetcode_14677_I
Given a list of non-negative integers `nums`, arrange them such that they form the largest number. Return the largest number you can form as a string. **Example:** ```python Input: nums = [10, 2] Output: "210" ``` **Example:** ```python Input: nums = [3, 30, 34, 5, 9] Output: "9534330" ``` **Note:** - The result...
from functools import cmp_to_key def custom_compare(x, y): """ Custom comparator function which compares two strings a and b by comparing the concatenated result in both possible orders. """ if x + y > y + x: return -1 elif x + y < y + x: return 1 else: return 0 def...
import pytest from solution import largest_number def test_largest_number_one_digit(): assert largest_number([1, 2, 3]) == "321" def test_largest_number_mixed_digits(): assert largest_number([10, 2]) == "210" assert largest_number([3, 30, 34, 5, 9]) == "9534330" def test_largest_number_with_zeros(): ...
[ { "docstring": "Custom comparator function which compares two strings a and b by comparing\nthe concatenated result in both possible orders.", "function_declaration": "def custom_compare(x, y):", "function_name": "custom_compare", "parameter_list": "(x, y)" }, { "docstring": "Given a list of...
[ 0, 0, 0, 0, 1, 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": "from functools import cmp_to_key\n\ndef largest_number(nums):\n \"\"\"\n Returns the largest number that can be formed by arranging the list of non-negative integers.\n...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000014677", "row_id": 14677, "seed_ids": "['58', '1672', '158']" }
0.718114
Leetcode_14677
I
[ "custom_compare", "largest_number" ]
2
[ [ "largest_number", "custom_compare" ] ]
1
[]
false
[]
false
pytest
true
[]
true
233c6fefb9b13ccb44c6aca7b2910d19364fe1f4
54775765b42a7af5c69d0f38dab8b245a021dd91
v1.0
instruct
Leetcode
Leetcode_15043_I
You are given a connected graph with `n` vertices and `m` edges represented as an edge list `connections`. Each edge in the graph has a weight denoted by `connections[i] = [u, v, w]` where `u` and `v` are vertices and `w` is the weight of the edge connecting them. The graph is **not guaranteed to be simple**, meaning i...
def find(parent, i): if parent[i] == i: return i else: return find(parent, parent[i]) def union(parent, rank, x, y): root_x = find(parent, x) root_y = find(parent, y) if rank[root_x] < rank[root_y]: parent[root_x] = root_y elif rank[root_x] > rank[root_y]: parent...
from solution import kruskals_mst def test_kruskals_mst_case1(): n = 4 connections = [ [0, 1, 1], [1, 2, 2], [0, 2, 4], [2, 3, 3], [1, 3, 5] ] expected = 6 # MST includes edges (0-1), (1-2), and (2-3) assert kruskals_mst(n, connections) == expected def test...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 1, 1, 1, 0, 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 find(parent, i):\n if parent[i] == i:\n return i\n else:\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n root_x = find(parent,...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000015043", "row_id": 15043, "seed_ids": "['2045', '952', '1335']" }
0.796545
Leetcode_15043
I
[ "find", "union", "kruskals_mst" ]
3
[ [ "kruskals_mst", "find" ], [ "kruskals_mst", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
true
[]
true
586e18f3dff3137602dc86c089f857e1e79973d7
92755bcb7836adb6975cc20dbe0bdae416424782
v1.0
instruct
Leetcode
Leetcode_15093_I
You are given an array `nums` consisting of `n` integers, where `nums[i]` represents the value at the `i-th` position. The array can be rotated by placing an element from the back to the front. For example, rotating `[1, 2, 3]` once would result in `[3, 1, 2]`. You are also given a positive integer `k`, which denotes t...
def max_subarray_sum(nums): """ Helper function that returns the maximum sum of a subarray using Kadane's Algorithm. """ max_sum = nums[0] current_sum = nums[0] for num in nums[1:]: current_sum = max(num, current_sum + num) max_sum = max(max_sum, current_sum) return...
from solution import max_value_after_rotations def test_no_rotation(): assert max_value_after_rotations([1, -2, 3, 4, -1], 0) == 7 assert max_value_after_rotations([-2, 1, -3, 4, -1, 2, 1, -5, 4], 0) == 6 def test_single_rotation(): assert max_value_after_rotations([1, -2, 3, 4, -1], 1) == 7 assert ma...
[ { "docstring": "Helper function that returns the maximum sum of a subarray using Kadane's Algorithm.", "function_declaration": "def max_subarray_sum(nums):", "function_name": "max_subarray_sum", "parameter_list": "(nums)" }, { "docstring": "Returns the maximum value of maxSubarraySum after p...
[ 1, 0, 1, 0, 0, 0, 1, 0, 0, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def maxSubarraySumAfterRotations(nums, k):\n \"\"\"\n Returns the maximum subarray sum after at most k rotations.\n \"\"\"\n def maxSubarraySum(arr):\n max...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "0000015093", "row_id": 15093, "seed_ids": "['2473', '828', '1782']" }
0.744584
Leetcode_15093
I
[ "max_subarray_sum", "max_value_after_rotations" ]
2
[ [ "max_value_after_rotations", "max_subarray_sum" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a6d8bc89249b88c6e9ed074296e1a9f07747fa51
7c42e435facf812c87901e6eeafaa0c882efcbd3
v1.0
instruct
Leetcode
Leetcode_15098_I
Given a binary tree, root-to-leaf paths are paths from the root node to any leaf node. A leaf node is defined as a node with no children. Write a function that returns _the number of distinct root-to-leaf paths in which the sum of the values of the nodes on the path is equal to a given target sum_. Your function shou...
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def path_sum_helper(node, targetSum, current_sum): if node is None: return 0 current_sum += node.val # If it's a leaf node and sum match...
from solution import TreeNode, count_paths_with_sum def test_single_node_equal_to_target(): # Tree: [5] root = TreeNode(5) assert count_paths_with_sum(root, 5) == 1 def test_single_node_not_equal_to_target(): # Tree: [5] root = TreeNode(5) assert count_paths_with_sum(root, 10) == 0 def test_m...
[]
[ 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, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\ndef pathSum(root, targ...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "0000015098", "row_id": 15098, "seed_ids": "['532', '1823', '2359']" }
0.585825
Leetcode_15098
I
[ "path_sum_helper", "count_paths_with_sum" ]
2
[ [ "count_paths_with_sum", "path_sum_helper" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
9009c21f76b3708f23361ba7774b5c6a7ac53819
264765a5f2dfeb0efe103fcefabdcd9d90be99fc
v1.0
instruct
Leetcode
Leetcode_15213_I
You are given a list of strings `words` and a string `s`. Find and return _all the strings 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 characte...
def is_subsequence(s, subseq): it = iter(s) return all(c in it for c in subseq) def find_subsequences(words, s): """ Finds and returns all the strings in `words` that are subsequences of `s`. """ return [word for word in words if is_subsequence(s, word)]
from solution import find_subsequences def test_find_subsequences_single_letter_words(): words = ['a', 'b', 'c'] s = 'abc' assert find_subsequences(words, s) == ['a', 'b', 'c'] def test_find_subsequences_substrings(): words = ['abc', 'ab', 'bc', 'ac', 'a', 'b', 'c'] s = 'abc' assert find_s...
[ { "docstring": null, "function_declaration": "def is_subsequence(s, subseq):", "function_name": "is_subsequence", "parameter_list": "(s, subseq)" }, { "docstring": "Finds and returns all the strings in `words` that are subsequences of `s`.", "function_declaration": "def find_subsequences...
[ 1, 1, 1, 1, 0, 1, 0, 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_subsequence(word, s):\n it = iter(s)\n return all(char in it for char in word)\n\ndef find_subsequences(words, s):\n return [word for word in words if is_subs...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000015213", "row_id": 15213, "seed_ids": "['334', '654', '1624']" }
0.68259
Leetcode_15213
I
[ "is_subsequence", "find_subsequences" ]
2
[ [ "find_subsequences", "is_subsequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8d1c14f62a80061f786e76420a3985871577b9f0
87bcebdc0ad9c2be9f143f2901f540b282b1ada8
v1.0
instruct
Leetcode
Leetcode_15231_I
Given a `words` array of strings, where a word can be transformed into a target word if it can be obtained by changing exactly one character, determine the shortest transformation sequence from a start word to an end word. You need to return the length of the sequence if such a transformation sequence exists, otherwise...
from collections import deque def is_one_letter_diff(word1, word2): """ Check if word1 can be transformed to word2 by changing exactly one character. """ diff_count = sum(1 for a, b in zip(word1, word2) if a != b) return diff_count == 1 def shortest_transformation_sequence(start, end, words): ...
from solution import shortest_transformation_sequence def test_example_case(): start, end, words = "hit", "cog", ["hot","dot","dog","lot","log","cog"] assert shortest_transformation_sequence(start, end, words) == 5 def test_no_transformation_possible(): start, end, words = "hit", "cog", ["hot","dot","dog"...
[ { "docstring": "Check if word1 can be transformed to word2 by changing exactly one character.", "function_declaration": "def is_one_letter_diff(word1, word2):", "function_name": "is_one_letter_diff", "parameter_list": "(word1, word2)" }, { "docstring": "Returns the length of the shortest tra...
[ 1, 0, 1, 1, 0, 0, 0, 0, 0, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef is_one_char_diff(word1, word2):\n \"\"\"\n Check if two words differ by exactly one character.\n \"\"\"\n if len(word1) != le...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "0000015231", "row_id": 15231, "seed_ids": "['2249', '734', '1733']" }
0.656497
Leetcode_15231
I
[ "is_one_letter_diff", "shortest_transformation_sequence" ]
2
[ [ "shortest_transformation_sequence", "is_one_letter_diff" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7c1ec594cceb189e3a44a71b5fa86dfddda9b4a9
9d992ffb56364dfade83ff3612b32f34e79a4c9b
v1.0
instruct
Leetcode
Leetcode_15258_I
You are given a **0-indexed** integer array `nums` of length `n` where all values are unique. A binary tree `T` is generated in the following way: 1. Use `nums[0]` as the root node. 2. Repeat the following steps for each `element` in `nums` following the order of the array: - Insert `element` as a child of the dee...
class TreeNode: def __init__(self, value): self.value = value self.left = None self.right = None def insert_node(root, value): from collections import deque queue = deque([root]) while queue: node = queue.popleft() if node.left is None: node.le...
from solution import inorder_traversal def test_inorder_traversal_single(): assert inorder_traversal([1]) == [1] def test_inorder_traversal_two(): assert inorder_traversal([1, 2]) == [2, 1] def test_inorder_traversal_three(): assert inorder_traversal([1, 2, 3]) == [2, 1, 3] def test_inorder_traversal_mu...
[]
[ 0, 1, 1, 1, 1, 0, 0, 1, 0, 1 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\ndef insert_into_tree(r...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000015258", "row_id": 15258, "seed_ids": "['2323', '1123', '1410']" }
0.640381
Leetcode_15258
I
[ "insert_node", "build_tree", "in_order_traversal", "inorder_traversal" ]
4
[ [ "build_tree", "insert_node" ], [ "inorder_traversal", "build_tree" ], [ "inorder_traversal", "in_order_traversal" ] ]
3
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
f7633653f0ffa59a7f037219d2a2560bc4c3aab8
6dd3a0d5dd9e75b20442b536ef29012dea4a3b6d
v1.0
instruct
Leetcode
Leetcode_15303_I
Given a list of non-negative integers `arr` and an integer `m`, partition the list into `m` non-empty contiguous subarrays such that the difference between the largest sum of any subarray and the smallest sum of any subarray is minimized. Return the minimum difference.
def can_partition(arr, m, max_sum): """ Helper function to check if the array can be partitioned into m subarrays with the given max_sum or not. """ current_sum = 0 count = 1 # Starting with one subarray for num in arr: if current_sum + num > max_sum: count += 1 ...
from solution import minimize_max_subarray_sum_difference def test_minimize_max_subarray_sum_difference_example_1(): arr = [7, 2, 5, 10, 8] m = 2 assert minimize_max_subarray_sum_difference(arr, m) == 18 def test_minimize_max_subarray_sum_difference_example_2(): arr = [1, 2, 3, 4, 5] m = 2 ass...
[ { "docstring": "Helper function to check if the array can be partitioned\ninto m subarrays with the given max_sum or not.", "function_declaration": "def can_partition(arr, m, max_sum):", "function_name": "can_partition", "parameter_list": "(arr, m, max_sum)" }, { "docstring": "Function to pa...
[ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def min_difference_partition(arr, m):\n \"\"\"\n Partition the list into `m` subarrays such that the difference between the largest and smallest\n sum of any subarra...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "0000015303", "row_id": 15303, "seed_ids": "['1214', '2037', '1838']" }
0.696966
Leetcode_15303
I
[ "can_partition", "minimize_max_subarray_sum_difference" ]
2
[ [ "minimize_max_subarray_sum_difference", "can_partition" ] ]
1
[]
false
[]
false
pytest
true
[]
true
481ef4d27e2d1ce1f1dbf50605dac5785c923fb4
f7b815e5d328d0a5f5106a52260e35c49cc1d02d
v1.0
instruct
Leetcode
Leetcode_15393_I
You are given a dice rolling simulation where a die has six faces numbered from 1 to 6. The function `simulateRolls(n)` rolls the die `n` times and returns a list of the outcomes. Write the function `simulateRollsProbabilities(n)` that returns a dictionary with the face values (1 through 6) as keys and their respective...
import random def simulateRolls(n): """ Rolls the die n times and returns a list of the outcomes. """ return [random.randint(1, 6) for _ in range(n)] def count_occurrences(results, face_value): """ Counts how many times a face value appears in the results list. """ return results.count...
from solution import simulateRollsProbabilities def test_probabilities_sum_to_one(): probabilities = simulateRollsProbabilities(1000) total_probability = sum(probabilities.values()) assert round(total_probability, 2) == 1.00 def test_probabilities_with_no_rolls(): probabilities = simulateRollsProbabil...
[ { "docstring": "Rolls the die n times and returns a list of the outcomes.", "function_declaration": "def simulateRolls(n):", "function_name": "simulateRolls", "parameter_list": "(n)" }, { "docstring": "Counts how many times a face value appears in the results list.", "function_declaratio...
[ 1, 1, 1, 0, 0, 0, 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": "import random\n\ndef simulateRolls(n):\n \"\"\"\n Rolls a die with six faces n times and returns a list of the outcomes.\n \"\"\"\n outcomes = []\n for _ in ra...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "0000015393", "row_id": 15393, "seed_ids": "['465', '2126', '171']" }
0.606149
Leetcode_15393
I
[ "simulateRolls", "count_occurrences", "simulateRollsProbabilities" ]
3
[ [ "simulateRollsProbabilities", "count_occurrences" ], [ "simulateRollsProbabilities", "simulateRolls" ] ]
2
[]
false
[]
false
pytest
true
[]
true
7b6fe103e3be78db4cfc899d9f31d15ba1a140d9
bdd481d5e6aaadcfadea2b8d3c1f794575ab6529
v1.0
instruct
Leetcode
Leetcode_15396_I
Given a list of strings `words`, find the longest string `s` that is a universal subsequence for all strings in the list. A string `s` is a universal subsequence of another string `t` if `s` can be formed by deleting some (or none) characters of `t` without changing the order of the remaining characters. If there are m...
def is_subsequence(s, t): """ Helper function to check if s is a subsequence of t. """ it = iter(t) return all(char in it for char in s) def find_longest_universal_subsequence(words): """ Finds the longest string that is a universal subsequence for all strings in the list. Paramete...
from solution import find_longest_universal_subsequence def test_universal_subsequence_basic(): words = ["abc", "def", "ghi"] assert find_longest_universal_subsequence(words) == "" def test_universal_subsequence_single_word(): words = ["a"] assert find_longest_universal_subsequence(words) == "a" def ...
[ { "docstring": "Helper function to check if s is a subsequence of t.", "function_declaration": "def is_subsequence(s, t):", "function_name": "is_subsequence", "parameter_list": "(s, t)" }, { "docstring": "Finds the longest string that is a universal subsequence for all strings in the list.\n...
[ 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_subsequence(s, t):\n \"\"\"\n Check if s is a subsequence of t.\n \"\"\"\n it = iter(t)\n return all(char in it for char in s)\n\ndef longest_universal_...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000015396", "row_id": 15396, "seed_ids": "['490', '1534', '926']" }
0.681313
Leetcode_15396
I
[ "is_subsequence", "find_longest_universal_subsequence" ]
2
[ [ "find_longest_universal_subsequence", "is_subsequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
931818a0a2cf3b23e8e451273c86e1f8375451a6
aaeaa389f87b1e82023e2df34287d74ee508ab48
v1.0
instruct
Leetcode
Leetcode_15423_I
Given a string `s` and an integer `k`, you need to split the string into `k` non-empty palindromic substrings. Return _a list of_ `k` _palindromic substrings if such a split is possible, or an empty list if it is not._ A string is a **palindrome** if it reads the same forward and backward.
def is_palindrome(s): return s == s[::-1] def split_into_palindromes(s, k): n = len(s) result = [] def backtrack(start, cut): if cut == 0: if start == n: return True return False for end in range(start + 1, n + 1): sub_str = s[start:...
from solution import split_into_palindromes def test_split_into_palindromes_basic(): assert split_into_palindromes("racecarannakayak", 3) == ["racecar", "anna", "kayak"] def test_split_into_palindromes_one_partition(): assert split_into_palindromes("level", 1) == ["level"] def test_split_into_palindromes_mul...
[ { "docstring": null, "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": null, "function_declaration": "def split_into_palindromes(s, k):", "function_name": "split_into_palindromes", "parameter_list": "(s, k...
[ 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 is_palindrome(s):\n \"\"\"\n Helper function to check if a string is a palindrome.\n \"\"\"\n return s == s[::-1]\n\ndef split_into_palindromes(s, k):\n \"...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "0000015423", "row_id": 15423, "seed_ids": "['2261', '2310', '1756']" }
0.713176
Leetcode_15423
I
[ "is_palindrome", "split_into_palindromes" ]
2
[ [ "split_into_palindromes", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6c7a9bddc0f4d88eed6356403e5e9096afec94f1
abec8d2ccdb619a78a0bce7125cbde82ea3a08dc
v1.0
instruct
Leetcode
Leetcode_15464_I
You are given a string `s` and an array of strings `dict`. The array of strings `dict` contains a list of words. Your task is to determine the **longest** word in `dict` that can be formed by deleting some characters of the given string `s`. If there is more than one possible result, return the word that appears first ...
def is_subsequence(str1, str2): it = iter(str1) return all(char in it for char in str2) def find_longest_word(s, dictionary): longest_word = "" for word in dictionary: if is_subsequence(s, word): if len(word) > len(longest_word) or (len(word) == len(longest_word) and dictionary.inde...
from solution import find_longest_word def test_find_longest_word(): s = "abpcplea" dictionary = ["ale", "apple", "monkey", "plea"] assert find_longest_word(s, dictionary) == "apple" def test_find_longest_word_no_possible_word(): s = "abpcplea" dictionary = ["x", "xy", "xyz"] assert find_longe...
[ { "docstring": null, "function_declaration": "def is_subsequence(str1, str2):", "function_name": "is_subsequence", "parameter_list": "(str1, str2)" }, { "docstring": null, "function_declaration": "def find_longest_word(s, dictionary):", "function_name": "find_longest_word", "para...
[ 0, 0, 1, 1, 1, 0, 0, 0, 0, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_subsequence(s, word):\n it = iter(s)\n return all(char in it for char in word)\n\ndef findLongestWord(s, dict):\n longest_word = \"\"\n for word in dict:\n...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "0000015464", "row_id": 15464, "seed_ids": "['687', '727', '2541']" }
0.67513
Leetcode_15464
I
[ "is_subsequence", "find_longest_word" ]
2
[ [ "find_longest_word", "is_subsequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
92e752cfbf2838ac7fa1a6204e5ba8e1f249510f
85888e35f07b47b13091430dac0752bf9efac740
v1.0
instruct
Leetcode
Leetcode_15629_I
Given a `root` of a binary tree, each node in the tree has a unique value. You are to choose `k` nodes from the tree such that the sum of their values is minimized and the chosen nodes cover all levels of the tree. A node is said to cover a level if there exists a path from the node to any other node at that level with...
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def dfs(node, depth, nodes_by_level): if not node: return if depth in nodes_by_level: nodes_by_level[depth].append(node.val) else: nodes_b...
from solution import TreeNode, min_sum_covering_levels def test_min_sum_covering_levels_single_node(): root = TreeNode(1) assert min_sum_covering_levels(root, 1) == 1 def test_min_sum_covering_levels_two_levels(): root = TreeNode(1, TreeNode(2), TreeNode(3)) assert min_sum_covering_levels(root, 2) == ...
[]
[ 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": "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 minimum_sum_of_k_n...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000015629", "row_id": 15629, "seed_ids": "['2097', '1520', '1284']" }
0.638339
Leetcode_15629
I
[ "dfs", "min_sum_covering_levels" ]
2
[ [ "min_sum_covering_levels", "dfs" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
2ef64064b3a576653c61ca47728c6a7ce91b7098
6ffde8570bb78c3c87db3e14eea653cad6eb59d4
v1.0
instruct
Leetcode
Leetcode_15670_I
You are given a list of strings `wordlist`. A person types a word and misses out on some (possibly zero) letters, and types the remaining letters in order. A typed word qualifies to match `wordlist[i]` if and only if `wordlist[i]` is a subsequence of the typed word. Find all words in `wordlist` that are subsequences of...
def is_subsequence(word, typed_word): """ Helper function to check if `word` is a subsequence of `typed_word`. """ it = iter(typed_word) return all(char in it for char in word) def find_matching_words(wordlist, typed_word): """ Find all words in `wordlist` that are subsequences of the `type...
from solution import find_matching_words def test_find_matching_words(): wordlist = ["apple", "app", "apricot", "banana", "grape"] typed_word = "app" assert find_matching_words(wordlist, typed_word) == ["app"] wordlist = ["dog", "cat", "bat"] typed_word = "dcaotg" assert find_matching_word...
[ { "docstring": "Helper function to check if `word` is a subsequence of `typed_word`.", "function_declaration": "def is_subsequence(word, typed_word):", "function_name": "is_subsequence", "parameter_list": "(word, typed_word)" }, { "docstring": "Find all words in `wordlist` that are subsequen...
[ 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 is_subsequence(word, typed_word):\n \"\"\"\n Checks if `word` is a subsequence of `typed_word`.\n \"\"\"\n it = iter(typed_word)\n return all(char in it fo...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000015670", "row_id": 15670, "seed_ids": "['555', '768', '2451']" }
0.663796
Leetcode_15670
I
[ "is_subsequence", "find_matching_words" ]
2
[ [ "find_matching_words", "is_subsequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
eea4bc955458e30f9e1bd4b015052d6b0172b7a3
5b5e89063dbad87f6dcf0feb30bd3d5a191d1006
v1.0
instruct
Leetcode
Leetcode_15816_I
You are given an integer array `arr` and an integer `k`. You need to find the **kth** largest element in the array. Implement a function that returns this element without using any built-in sorting algorithms. You can assume that `k` is always a valid index in the context of the array. Example: ``` arr = [3,2,1,5,6,4...
def partition(arr, low, high): pivot = arr[high] i = low - 1 for j in range(low, high): if arr[j] >= pivot: # Changed to >= to find kth largest instead of kth smallest i += 1 arr[i], arr[j] = arr[j], arr[i] arr[i + 1], arr[high] = arr[high], arr[i + 1] return i + 1 ...
from solution import find_kth_largest def test_find_kth_largest(): assert find_kth_largest([3, 2, 1, 5, 6, 4], 2) == 5 def test_kth_largest_one_element(): assert find_kth_largest([10], 1) == 10 def test_kth_largest_all_equal(): assert find_kth_largest([2, 2, 2, 2], 3) == 2 def test_kth_largest_same_numb...
[ { "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, 0, 1, 1, 1, 1, 0, 1, 0 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def kth_largest(arr, k):\n \"\"\"\n Returns the kth largest element in the array without using built-in sorting algorithms.\n \"\"\"\n def partition(left, right, ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000015816", "row_id": 15816, "seed_ids": "['1844', '2509', '123']" }
0.776471
Leetcode_15816
I
[ "partition", "quickselect", "find_kth_largest" ]
3
[ [ "find_kth_largest", "quickselect" ], [ "quickselect", "partition" ] ]
2
[]
false
[]
false
pytest
true
[]
true
93886d6d95fafbae978005d645341c1485f84fc2
bf6a13264020f2a2d5196edea2f6efa28fbfeddb
v1.0
instruct
Leetcode
Leetcode_15823_I
You are given an integer array `nums` and an integer `k`. You need to distribute all the integers into `k` baskets such that the maximum sum of the integers in any basket is minimized. Return _the minimized maximum sum of the integers in the `k` baskets_. Each basket must contain at least one integer, and the sum of t...
def canDistribute(nums, k, maxSum): baskets = 1 currentSum = 0 for num in nums: if currentSum + num > maxSum: baskets += 1 currentSum = num if baskets > k: return False else: currentSum += num return True def minimize_...
from solution import minimize_max_sum def test_sample_case(): assert minimize_max_sum([1, 2, 3, 4, 5], 2) == 9 # (1,2,3) and (4,5) def test_single_element(): assert minimize_max_sum([7], 1) == 7 # Only one basket def test_equal_distribution(): assert minimize_max_sum([5, 5, 5, 5], 4) == 5 # Each eleme...
[ { "docstring": null, "function_declaration": "def canDistribute(nums, k, maxSum):", "function_name": "canDistribute", "parameter_list": "(nums, k, maxSum)" }, { "docstring": null, "function_declaration": "def minimize_max_sum(nums, k):", "function_name": "minimize_max_sum", "para...
[ 0, 1, 0, 0, 1, 1, 0, 0, 0, 1 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def distribute_to_baskets(nums, k):\n \"\"\"\n Distributes the integers into k baskets such that the maximum sum of integers in any basket is minimized.\n \"\"\"\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000015823", "row_id": 15823, "seed_ids": "['329', '1840', '1605']" }
0.68107
Leetcode_15823
I
[ "canDistribute", "minimize_max_sum" ]
2
[ [ "minimize_max_sum", "canDistribute" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7216e04eb4977caffc328aad6c315c8cde07bb87
749e8eb3ed07a1813017fff57bfaafe92e8fdf53
v1.0
instruct
Leetcode
Leetcode_15975_I
You are given a **0-indexed** matrix `grid` of integers where each cell represents the elevation at that point. A lake is defined as a contiguous group of cells that are all at the same elevation. The lake is surrounded by cells of higher elevation (or the boundary of the grid). The size of a lake is the number of cell...
def explore_lake(grid, visited, i, j, elevation): """ Helper function to explore the lake and return its size """ directions = [(-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 1), (1, -1), (1, 0), (1, 1)] stack = [(i, j)] lake_size = 0 while stack: ...
from solution import largest_lake def test_lake_in_single_row(): grid = [[1, 1, 1, 2, 2, 2]] assert largest_lake(grid) == 3 def test_lake_in_single_column(): grid = [[3], [3], [4], [4], [4]] assert largest_lake(grid) == 3 def test_lake_in_corner(): grid = [ [1, 1, 1], [1, 2, 1], ...
[ { "docstring": "Helper function to explore the lake and return its size ", "function_declaration": "def explore_lake(grid, visited, i, j, elevation):", "function_name": "explore_lake", "parameter_list": "(grid, visited, i, j, elevation)" }, { "docstring": "Returns the size of the largest lak...
[ 0, 0, 0, 0, 0, 1, 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 largest_lake(grid):\n \"\"\"\n Returns the size of the largest lake in the grid.\n \"\"\"\n if not grid:\n return 0\n\n rows, cols = len(grid), len(...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "0000015975", "row_id": 15975, "seed_ids": "['328', '1958', '2453']" }
0.56026
Leetcode_15975
I
[ "explore_lake", "largest_lake" ]
2
[ [ "largest_lake", "explore_lake" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b7d732abef19b244c79a9364a6073fc5b6b0d461
58378f799c3fe96b18945aacda260f79dc2cd9d3
v1.0
instruct
Leetcode
Leetcode_16172_I
Given an array of integers `arr`, split the array into `n` consecutive subarrays such that the sum of the maximum element of each subarray is minimized. Return _the minimum possible sum of the maximum elements of the subarrays_. Note that each element of the original array must be included in exactly one subarray and s...
def can_partition(arr, mid, n): """ Helper function to determine if the array can be partitioned into n subarrays with maximum subarray sum less than or equal to mid. """ count, total_sum = 1, 0 for num in arr: if total_sum + num > mid: total_sum = num count += 1...
from solution import minimize_max_sum_of_subarrays def test_case_1(): assert minimize_max_sum_of_subarrays([7, 2, 5, 10, 8], 2) == 18 def test_case_2(): assert minimize_max_sum_of_subarrays([1, 2, 3, 4, 5], 2) == 9 def test_case_3(): assert minimize_max_sum_of_subarrays([1, 4, 4], 3) == 4 def test_case_...
[ { "docstring": "Helper function to determine if the array can be partitioned into n subarrays\nwith maximum subarray sum less than or equal to mid.", "function_declaration": "def can_partition(arr, mid, n):", "function_name": "can_partition", "parameter_list": "(arr, mid, n)" }, { "docstring...
[ 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 split_array_minimize_sum_max(arr, n):\n def can_split(max_sum):\n subarray_count = 1\n current_sum = 0\n for num in arr:\n if current_s...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "0000016172", "row_id": 16172, "seed_ids": "['2405', '960', '2435']" }
0.759572
Leetcode_16172
I
[ "can_partition", "minimize_max_sum_of_subarrays" ]
2
[ [ "minimize_max_sum_of_subarrays", "can_partition" ] ]
1
[]
false
[]
false
pytest
true
[]
true
bda636e4b73786a1e3eebbb636a95685227b9dde
47b7e207686a8bbe4b10a622c76b972f44820468
v1.0
instruct
Leetcode
Leetcode_16394_I
A string `sentence` is given which consists of words separated by spaces. Each word is a permutation of a word found in a given list of `valid_words`. Write a function that returns a list of words in `sentence` which are valid permutations found in `valid_words`. Each word in the result list should appear in the same o...
def is_permutation(word, valid_word): return sorted(word) == sorted(valid_word) def find_valid_words(sentence, valid_words): """ Returns a list of words in `sentence` which are valid permutations found in `valid_words`. """ words = sentence.split() result = [] for word in words: fo...
from solution import find_valid_words def test_find_valid_words_basic(): sentence = "god dog cat" valid_words = ["dog", "cat"] expected_result = ["god", "dog", "cat"] assert find_valid_words(sentence, valid_words) == expected_result def test_find_valid_words_no_permutations(): sentence = "fish bir...
[ { "docstring": null, "function_declaration": "def is_permutation(word, valid_word):", "function_name": "is_permutation", "parameter_list": "(word, valid_word)" }, { "docstring": "Returns a list of words in `sentence` which are valid permutations found in `valid_words`.", "function_declar...
[ 0, 0, 1, 1, 0, 1, 0, 0, 1, 0 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "from collections import Counter\n\ndef valid_permutations(sentence, valid_words):\n \"\"\"\n Returns a list of valid permutations found in the sentence.\n\n :param s...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000016394", "row_id": 16394, "seed_ids": "['1507', '395', '753']" }
0.727154
Leetcode_16394
I
[ "is_permutation", "find_valid_words" ]
2
[ [ "find_valid_words", "is_permutation" ] ]
1
[]
false
[]
false
pytest
true
[]
true
eaf13e86be1b735492cd7f435797a88b60bfdf21
04f2d9c526dad49aeaeb3a12cc7b0ad8e91c2a17
v1.0
instruct
Leetcode
Leetcode_16476_I
You are given a list of strings `words`. Each word is in lowercase and may contain duplicate letters. You need to find out if there is any subset of two words such that their concatenation results in a palindrome. Return true if at least one such subset exists, otherwise return false.
def is_palindrome(s): """ Helper function to check if a string is a palindrome. """ return s == s[::-1] def can_form_palindrome(words): """ Returns True if any subset of two words can form a palindrome upon concatenation. """ for i in range(len(words)): for j in range(i + 1, le...
from solution import can_form_palindrome def test_can_form_palindrome_true_cases(): assert can_form_palindrome(["ab", "ba"]) == True assert can_form_palindrome(["abc", "cba"]) == True assert can_form_palindrome(["xyz", "zyx", "abc"]) == True def test_can_form_palindrome_false_cases(): assert can_form_...
[ { "docstring": "Helper function to check if a string is a palindrome.", "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": "Returns True if any subset of two words can form a palindrome upon concatenation.", "funct...
[ 1, 1, 0, 1, 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": "def can_form_palindrome(words):\n \"\"\"\n Returns true if there is at least one pair of words whose concatenation is a palindrome.\n \"\"\"\n \n def is_palind...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000016476", "row_id": 16476, "seed_ids": "['645', '1301', '1678']" }
0.758291
Leetcode_16476
I
[ "is_palindrome", "can_form_palindrome" ]
2
[ [ "can_form_palindrome", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4cdd3b75784b41feccc2acbbfe99dcb079356134
a75a78344b0c880e184ddd395d38938018e89018
v1.0
instruct
Leetcode
Leetcode_16523_I
Given an integer array `arr`, determine whether there exists a subarray, whose sum of the elements is equal to a prime number. If such a subarray exists, return `true`; otherwise, return `false`. A **subarray** is a contiguous part of an array. ### Constraints: - The number of subarrays to be considered is a large eno...
def is_prime(n): """ Checks 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 i += 6 return T...
from solution import has_prime_sum_subarray def test_no_elements(): assert not has_prime_sum_subarray([]) def test_single_prime_element(): assert has_prime_sum_subarray([3]) def test_single_non_prime_element(): assert not has_prime_sum_subarray([4]) def test_multiple_elements_with_prime_sum(): asser...
[ { "docstring": "Checks if a number n is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Determines whether there exists a subarray in arr whose sum is prime.", "function_declaration": "def has_prime_sum_subarray...
[ 1, 0, 1, 1, 1, 1, 0, 1, 1, 1 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "import math\n\ndef is_prime(n):\n \"\"\"\n Checks if a number n is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return Tru...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "0000016523", "row_id": 16523, "seed_ids": "['2419', '891', '1177']" }
0.590112
Leetcode_16523
I
[ "is_prime", "has_prime_sum_subarray" ]
2
[ [ "has_prime_sum_subarray", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
79fb9a4363e3b1380112813c9fffab1e33fbd69b
930c3f435038620cd6d26416a359237587f0a2c5
v1.0
instruct
Leetcode
Leetcode_16714_I
You are given a list of integers `nums` representing a binary tree in level order traversal. Some nodes are empty (null) and are represented by `-1`. You need to construct the binary tree and then return the level order traversal of the tree but with the levels reflected around the center. For example, if the binary t...
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def construct_tree(nums): if not nums: return None from collections import deque root = TreeNode(nums[0]) queue = deque([root]) i = 1 ...
from solution import reflected_level_order def test_example_1(): nums = [1, 2, 3, -1, 5, -1, -1] expected = [ [1], [3, 2], [5] ] assert reflected_level_order(nums) == expected def test_example_2(): nums = [1, 2, 3, 4, 5, 6, 7] expected = [ [1], [3, 2], ...
[]
[ 0, 0, 0, 0, 1, 1, 1, 0, 0, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "from collections import deque\n\nclass TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right ...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "0000016714", "row_id": 16714, "seed_ids": "['2554', '1943', '1960']" }
0.561124
Leetcode_16714
I
[ "construct_tree", "reflect_levels", "level_order_traversal", "reflected_level_order" ]
4
[ [ "reflected_level_order", "construct_tree" ], [ "reflected_level_order", "level_order_traversal" ], [ "reflected_level_order", "reflect_levels" ] ]
3
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
f3da1abcb9fcfaa0ff435968e039ada990792978
69e6d6554368d8b686aa82f257e6300c6343a888
v1.0
instruct
Leetcode
Leetcode_16715_I
Given a binary tree, write a function to find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node. A leaf is a node with no children. The binary tree is represented as follows using a list where the elements are filled in level order trav...
from typing import List, Optional class TreeNode: def __init__(self, val: int = 0, left: 'TreeNode' = None, right: 'TreeNode' = None): self.val = val self.left = left self.right = right def build_tree_from_list(values: List[Optional[int]]) -> Optional[TreeNode]: if not values: ...
import pytest from solution import find_max_depth, TreeNode, build_tree_from_list, max_depth def test_find_max_depth_single_node(): assert find_max_depth([1]) == 1 def test_find_max_depth_full(): assert find_max_depth([3, 9, 20, None, None, 15, 7]) == 3 def test_find_max_depth_empty(): assert find_max_de...
[]
[ 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": "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 list_to_tree(lst):...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000016715", "row_id": 16715, "seed_ids": "['1219', '154', '1363']" }
0.583312
Leetcode_16715
I
[ "build_tree_from_list", "max_depth", "find_max_depth" ]
3
[ [ "find_max_depth", "build_tree_from_list" ], [ "find_max_depth", "max_depth" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
afdd9ae54df774c59b20adb9523c18af9ed69a1e
05af708593ad48bcbf9da2c7c1313ed042ef2aea
v1.0
instruct
Leetcode
Leetcode_16749_I
You are given two non-empty binary trees `root1` and `root2`. Write a function to determine if `root2` is a **subtree** of `root1`. A subtree of a binary tree `tree` is a tree that consists of a node in `tree` and all of this node's descendants. The tree `root1` could be an empty tree, in which case it cannot have any ...
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def is_subtree(root1, root2): if not root2: return True if not root1: return False if is_same_tree(root1, root2): return True return i...
from solution import TreeNode, is_subtree def test_is_subtree_found(): # Tree 1 root1 = TreeNode(3) root1.left = TreeNode(4) root1.right = TreeNode(5) root1.left.left = TreeNode(1) root1.left.right = TreeNode(2) # Tree 2 root2 = TreeNode(4) root2.left = TreeNode(1) root2.ri...
[]
[ 0, 0, 1, 1, 1, 1, 0, 1, 1, 1 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\ndef is_equal(tree1, tr...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000016749", "row_id": 16749, "seed_ids": "['2566', '97', '624']" }
0.611633
Leetcode_16749
I
[ "is_subtree", "is_same_tree" ]
2
[ [ "is_subtree", "is_same_tree" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
19d849925ba8fa4312091528aa87ef241907a085
a57e2026fb5ab931ba18afa6ce1c08611bd4895b
v1.0
instruct
Leetcode
Leetcode_16777_I
Given a list of unique words `words`, return _all the pairs of different indices `(i, j)` such that the concatenation of the two words `words[i] + words[j]` is a palindrome_. A string is a **palindrome** if it reads the same backward as forward. For example, given `words = ["abcd", "dcba", "lls", "s", "sssll"]`, the o...
def is_palindrome(s): """ Helper function to check if a string is a palindrome. """ return s == s[::-1] def palindrome_pairs(words): """ Given a list of unique words, return all pairs of different indices (i, j) such that the concatenation of the two words words[i] + words[j] is a palin...
from solution import palindrome_pairs def test_palindrome_pairs_example(): words = ["abcd", "dcba", "lls", "s", "sssll"] result = palindrome_pairs(words) expected = [[0, 1], [1, 0], [3, 2], [2, 4]] assert sorted(result) == sorted(expected) def test_palindrome_pairs_no_pairs(): words = ["abc", "def...
[ { "docstring": "Helper function to check if a string is a palindrome.", "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": "Given a list of unique words, return all pairs of different indices\n(i, j) such that the conc...
[ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_palindrome(s):\n \"\"\"\n Helper function to check if a string is a palindrome.\n \"\"\"\n return s == s[::-1]\n\ndef palindrome_pairs(words):\n \"\"\"\...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "0000016777", "row_id": 16777, "seed_ids": "['811', '1637', '1557']" }
0.729406
Leetcode_16777
I
[ "is_palindrome", "palindrome_pairs" ]
2
[ [ "palindrome_pairs", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ad0cb431a8aaa4c377b6e361b5b51ca0ab43b9d4
a83941dabfe0117d1a5fef0b76e6f9648a51c7e9
v1.0
instruct
Leetcode
Leetcode_16940_I
You are given a list of strings, `words`, where each word consists of lowercase English letters. Find the longest string in the list that can be formed by concatenating other words from the list exactly once each (each word can be used only once). If there is a tie, return the lexicographically smallest string. If no s...
def get_candidates(words): # This helper function generates all possible concatenations of the given words. candidates = set() for i in range(len(words)): for j in range(len(words)): if i != j: candidates.add(words[i] + words[j]) return candidates def longest_concat_...
from solution import longest_concat_word def test_example_case(): words = ["cat", "bat", "rat", "catbat"] assert longest_concat_word(words) == "catbat" def test_no_concatenated_words(): words = ["cat", "dog", "fish"] assert longest_concat_word(words) == "" def test_all_words_single_character(): w...
[ { "docstring": null, "function_declaration": "def get_candidates(words):", "function_name": "get_candidates", "parameter_list": "(words)" }, { "docstring": "Returns the longest string in the list that can be formed by concatenating other words from the list exactly once.\nIn case of a tie, t...
[ 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def can_form_by_concatenation(word, words_set):\n \"\"\"\n Check if the `word` can be formed by concatenating other words from `words_set`.\n `word` should not be us...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "0000016940", "row_id": 16940, "seed_ids": "['1197', '689', '535']" }
0.736078
Leetcode_16940
I
[ "get_candidates", "longest_concat_word" ]
2
[ [ "longest_concat_word", "get_candidates" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ee1ca2baf774e413d6229363f8bc30e37c0412b7
5ea572f57240ed8a43ce266f26082ecb4eab1d81
v1.0
instruct
Leetcode
Leetcode_17051_I
Given a list of non-negative integers `nums`, represented as strings, return the smallest number possible when these numbers are concatenated together. If the result starts with zeroes (e.g., "00032"), the leading zeroes should be removed, and only "32" should be returned. If the final result is "0", return "0".
from functools import cmp_to_key def compare(x, y): """ Custom comparator function to order strings based on their concatenated result. If 'xy' < 'yx', then 'x' should come before 'y', otherwise 'y' should come before 'x'. """ if x + y < y + x: return -1 elif x + y > y + x: retu...
from solution import smallest_number def test_single_number(): assert smallest_number(["5"]) == "5" assert smallest_number(["0"]) == "0" def test_multiple_numbers(): assert smallest_number(["3", "30", "34", "5", "9"]) == "3033459" assert smallest_number(["10", "2"]) == "102" assert smallest_number...
[ { "docstring": "Custom comparator function to order strings based on their concatenated result.\nIf 'xy' < 'yx', then 'x' should come before 'y', otherwise 'y' should come before 'x'.", "function_declaration": "def compare(x, y):", "function_name": "compare", "parameter_list": "(x, y)" }, { ...
[ 0, 1, 0, 0, 1, 0, 0, 0, 1, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "from functools import cmp_to_key\n\ndef compare(x, y):\n if x + y < y + x:\n return -1\n elif x + y > y + x:\n return 1\n else:\n return 0\n\nde...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000017051", "row_id": 17051, "seed_ids": "['1131', '1007', '76']" }
0.640095
Leetcode_17051
I
[ "compare", "smallest_number" ]
2
[ [ "smallest_number", "compare" ] ]
1
[]
false
[]
false
pytest
true
[]
true
26839d6fc5c244e4974e0970b64e6d49b46212ce
38b27eed287c346092c420bf9f171709341cdb36
v1.0
instruct
Leetcode
Leetcode_17078_I
You are given an array of strings `words`. Each string is a word, and it consists of lowercase English letters. Return the total number of pairs `(i, j)` where `0 <= i < j < words.length`, and the concatenation of `words[i] + words[j]` or `words[j] + words[i]` forms a palindrome. For example, given `words = ["bat", "...
def is_palindrome(word): """ Helper function to check if a word is a palindrome. """ return word == word[::-1] def palindromePairs(words): """ Returns the total number of pairs (i, j) where 0 <= i < j < words.length, and the concatenation of words[i] + words[j] or words[j] + words[i] forms ...
from solution import palindromePairs, is_palindrome def test_is_palindrome(): assert is_palindrome("level") assert not is_palindrome("hello") assert is_palindrome("radar") assert not is_palindrome("world") def test_palindromePairs(): assert palindromePairs(["bat", "tab", "cat"]) == 2 # "battab" a...
[ { "docstring": "Helper function to check if a word is a palindrome.", "function_declaration": "def is_palindrome(word):", "function_name": "is_palindrome", "parameter_list": "(word)" }, { "docstring": "Returns the total number of pairs (i, j) where 0 <= i < j < words.length,\nand the concate...
[ 0, 0, 0, 0, 0, 1, 0, 1, 0, 1 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def palindromePairs(words):\n \"\"\"\n Returns the total number of pairs (i, j) where the concatenation of words[i] + words[j]\n or words[j] + words[i] forms a palin...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000017078", "row_id": 17078, "seed_ids": "['901', '2366', '1266']" }
0.77402
Leetcode_17078
I
[ "is_palindrome", "palindromePairs" ]
2
[ [ "palindromePairs", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
440732baa8b7bc930c76d5a213b4d2cc7306d513
1ffb1b1db872201a38fe4bdef140a4c820f2607a
v1.0
instruct
Leetcode
Leetcode_17112_I
A company's internal case tracking system marks incidents with unique identifiers. Each identifier consists of a combination of lowercase alphabetic characters and digits. The combination always starts with a letter and must be at least 3 characters long. Any incidents that fail to meet these criteria are considered in...
def is_valid_identifier(identifier): """ Checks if an incident identifier is valid. A valid identifier: - Starts with a lowercase alphabetic character - Is at least 3 characters long - Consists only of lowercase alphabetic characters and digits Args: identifier (str): The incid...
from solution import count_valid_identifiers def test_count_valid_identifiers(): assert count_valid_identifiers(["a123", "ab1", "1abc", "abcd", "ab"]) == 3 def test_count_no_identifiers(): assert count_valid_identifiers([]) == 0 def test_count_all_valid_identifiers(): assert count_valid_identifiers(["abc...
[ { "docstring": "Checks if an incident identifier is valid.\n\nA valid identifier:\n- Starts with a lowercase alphabetic character\n- Is at least 3 characters long\n- Consists only of lowercase alphabetic characters and digits\n\nArgs:\nidentifier (str): The incident identifier to validate.\n\nReturns:\nbool: Tr...
[ 0, 0, 0, 1, 0, 1, 0, 1, 1, 0 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_valid_identifier(identifier):\n \"\"\"\n Determines whether the given identifier is valid based on the criteria\n of starting with a lowercase letter and bein...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000017112", "row_id": 17112, "seed_ids": "['929', '1712', '1011']" }
0.655503
Leetcode_17112
I
[ "is_valid_identifier", "count_valid_identifiers" ]
2
[ [ "count_valid_identifiers", "is_valid_identifier" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0b02ed44244b6c9e2938917b64fbb502bdb40a27
052d07c6991149a0dd4a0bd1a150b36ad4054d8e
v1.0
instruct
Leetcode
Leetcode_17179_I
Given a `target` string and a list of `wordlist` strings, find the longest common subsequence (LCS) between the `target` string and each string in the `wordlist`. The LCS is the longest sequence that appears in both strings in the same order, but not necessarily consecutively. Return an array `answer` where `answer[i]`...
def lcs_length(target, word): """ Returns the length of the longest common subsequence (LCS) between target and word. """ m, n = len(target), len(word) dp = [[0] * (n + 1) for _ in range(m + 1)] for i in range(1, m + 1): for j in range(1, n + 1): if target[i - 1] == word...
from solution import lcs_lengths def test_lcs_lengths(): assert lcs_lengths("abcde", ["ace", "aec", "bd"]) == [3, 2, 2] assert lcs_lengths("abcdef", ["abc", "def", "xyz"]) == [3, 3, 0] assert lcs_lengths("xyz", ["a", "b", "c"]) == [0, 0, 0] assert lcs_lengths("qwerty", ["wert", "wer", "ty"]) == [4, 3, ...
[ { "docstring": "Returns the length of the longest common subsequence (LCS) between target and word.", "function_declaration": "def lcs_length(target, word):", "function_name": "lcs_length", "parameter_list": "(target, word)" }, { "docstring": "Returns a list where each element is the length ...
[ 0, 1, 1, 1, 1, 1, 1, 0, 1, 1 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def lcs_length(s1, s2):\n \"\"\"\n Helper function to calculate the length of the longest common subsequence between two strings.\n \"\"\"\n m, n = len(s1), len(s...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000017179", "row_id": 17179, "seed_ids": "['966', '2217', '1370']" }
0.769653
Leetcode_17179
I
[ "lcs_length", "lcs_lengths" ]
2
[ [ "lcs_lengths", "lcs_length" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9a23213683dc74fc1e4e7b7054f874e452c03de4
39b52df0bc7394ce9180d7e7c133172321f74198
v1.0
instruct
Leetcode
Leetcode_17182_I
You are given a list of `logs`, where each element is a string formatted as `"ID Process_Start_Time Process_End_Time"`. Each `Process_Start_Time` and `Process_End_Time` is in the format `HH:MM`. Calculate the total execution time for all processes combined and return the result in the format `HH:MM`. Note that the time...
def time_difference(start, end): """ Calculate the difference between two times given in the format "HH:MM". Returns the difference in minutes. """ start_hour, start_minute = map(int, start.split(":")) end_hour, end_minute = map(int, end.split(":")) start_total_minutes = start_hour * 60 + st...
from solution import total_execution_time def test_total_execution_time_single_process(): logs = ["1 09:00 10:00"] assert total_execution_time(logs) == "01:00" def test_total_execution_time_multiple_processes(): logs = ["1 09:00 09:40", "2 10:00 11:10", "3 18:30 20:00"] assert total_execution_time(log...
[ { "docstring": "Calculate the difference between two times given in the format \"HH:MM\".\nReturns the difference in minutes.", "function_declaration": "def time_difference(start, end):", "function_name": "time_difference", "parameter_list": "(start, end)" }, { "docstring": "Convert a total ...
[ 0, 1, 1, 0, 1, 0, 1, 0, 1, 0 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def calculate_total_execution_time(logs):\n \"\"\"\n Calculate the total execution time for all processes combined given a list of logs.\n Each log is in the format ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000017182", "row_id": 17182, "seed_ids": "['1135', '1507', '317']" }
0.672622
Leetcode_17182
I
[ "time_difference", "convert_minutes_to_HHMM", "total_execution_time" ]
3
[ [ "total_execution_time", "convert_minutes_to_HHMM" ], [ "total_execution_time", "time_difference" ] ]
2
[]
false
[]
false
pytest
true
[]
true
cea1296a9e90c85a509d454c4e4fffb2292088af
19e88b2948d9b5f776653bdb09eddaef827c7015
v1.0
instruct
Leetcode
Leetcode_17336_I
You are given a **0-indexed** 2D integer array `grid` of size `m x n` representing a grid of land and water. An entry `grid[i][j]` is `0` if it represents water, and `1` if it represents land. A **connected component** in the grid is a set of `1`s (land) connected by `4-directional` (horizontal or vertical) connection...
from collections import deque # Define direction vectors for 4-directional movement (up, down, left, right) directions = [(-1, 0), (1, 0), (0, -1), (0, 1)] def bfs(x, y, grid, visited): m, n = len(grid), len(grid[0]) queue = deque([(x, y)]) visited[x][y] = True while queue: cx, cy = queue...
from solution import min_operations_to_one_component def test_already_one_component(): grid = [[1, 1, 0], [1, 1, 0], [0, 0, 0]] assert min_operations_to_one_component(grid) == 0 def test_no_land(): grid = [[0, 0], [0, 0]] assert min_operations_to_one_component(gr...
[ { "docstring": null, "function_declaration": "def bfs(x, y, grid, visited):", "function_name": "bfs", "parameter_list": "(x, y, grid, visited)" }, { "docstring": null, "function_declaration": "def count_components(grid):", "function_name": "count_components", "parameter_list": "(...
[ 0, 0, 0, 0, 0, 1, 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 count_components(grid):\n \"\"\"\n Counts the number of connected components of land (1's) in the grid.\n \"\"\"\n def dfs(i, j):\n if 0 <= i < len(gri...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "0000017336", "row_id": 17336, "seed_ids": "['2188', '2089', '958']" }
0.612762
Leetcode_17336
I
[ "bfs", "count_components", "min_operations_to_one_component" ]
3
[ [ "count_components", "bfs" ], [ "min_operations_to_one_component", "count_components" ] ]
2
[]
false
[]
false
pytest
true
[]
true
e9f146f1dfb886dfdc49aae634ef0e79b5d09e41
927b237e9dc1d10233b807ac1a0809caf54a6fd8
v1.0
instruct
Leetcode
Leetcode_17413_I
Given an array `positions` of size `n`, where `positions[i]` is the position of the `i-th` ball on a number line, create a function that places `m` balls into different positions from the array such that the minimum distance between any two of the balls is maximized. Return the maximum possible minimum distance between...
def canPlaceBalls(positions, m, minDist): """ Helper function to check if we can place `m` balls with at least `minDist` apart. """ count = 1 # place the first ball at the first position last_position = positions[0] for i in range(1, len(positions)): if positions[i] - last_position...
from solution import maxDistance def test_maxDistance(): assert maxDistance([1, 2, 8, 4, 9], 3) == 3 assert maxDistance([1, 2, 4, 8, 9], 3) == 3 assert maxDistance([1, 2, 3, 4, 5, 6], 3) == 2 assert maxDistance([1, 3, 7, 9], 2) == 8 assert maxDistance([1, 5, 9, 13], 4) == 4 assert maxDistance([...
[ { "docstring": "Helper function to check if we can place `m` balls with at least `minDist` apart.", "function_declaration": "def canPlaceBalls(positions, m, minDist):", "function_name": "canPlaceBalls", "parameter_list": "(positions, m, minDist)" }, { "docstring": "Returns the maximum possib...
[ 1, 0, 0, 1, 0, 0, 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 is_feasible(positions, m, distance):\n \"\"\"\n Helper function to check if it's possible to place 'm' balls with at least 'distance' between any two of them.\n ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000017413", "row_id": 17413, "seed_ids": "['230', '1813', '716']" }
0.630157
Leetcode_17413
I
[ "canPlaceBalls", "maxDistance" ]
2
[ [ "maxDistance", "canPlaceBalls" ] ]
1
[]
false
[]
false
pytest
true
[]
true
249e7f2efa0e0c51c1991a93e7689e325113f3a8
64caac721181803e14052e939d377bdd6bfb3114
v1.0
instruct
Leetcode
Leetcode_17417_I
You are given a `0-indexed` integer array `nums` of even length `n`. Split this array into two equal parts: a left part and a right part. The left part is the first `n/2` elements of the array, and the right part is the last `n/2` elements. A function `calculate(part)` is defined to calculate the product of non-zero ...
def calculate(part): """ Calculate the product of non-zero elements in the part. If the part has no non-zero elements, its product is considered to be 1. """ product = 1 has_non_zero = False for num in part: if num != 0: product *= num has_non_zero = True ...
from solution import calculate, compare_products def test_calculate(): assert calculate([1, 2]) == 2 assert calculate([0, 3, 4]) == 12 assert calculate([0, 0]) == 1 assert calculate([5]) == 5 assert calculate([]) == 1 def test_compare_products(): assert compare_products([1, 2, 0, 3, 4, 0]) == ...
[ { "docstring": "Calculate the product of non-zero elements in the part.\nIf the part has no non-zero elements, its product is considered to be 1.", "function_declaration": "def calculate(part):", "function_name": "calculate", "parameter_list": "(part)" }, { "docstring": "Returns true if the ...
[ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def calculate(part):\n \"\"\"\n Calculate the product of non-zero elements in the part. \n If there are no non-zero elements, return 1.\n \"\"\"\n product = 1\...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "0000017417", "row_id": 17417, "seed_ids": "['489', '1754', '1470']" }
0.641955
Leetcode_17417
I
[ "calculate", "compare_products" ]
2
[ [ "compare_products", "calculate" ] ]
1
[]
false
[]
false
pytest
true
[]
true
53397c3b82b20c26b50fdf7a559c5b58adf522a5
e42cb9bba5d9e7e1c8633463c7f6e94cc165ccf5
v1.0
instruct
Leetcode
Leetcode_17627_I
You are given a string `s` consisting of lowercase letters, and an array of strings `words` where each string in `words` is a subsequence of `s`. A subsequence is derived from another string by deleting some or none of the characters without changing the order of the remaining characters. Return _the length of the **lo...
def is_subsequence(sub, s): """ Helper function to determine if 'sub' is a subsequence of 's'. """ it = iter(s) return all(char in it for char in sub) def longest_subsequence_length(s, words): """ Returns the length of the longest string in words that is a subsequence of s. """ max_...
from solution import is_subsequence, longest_subsequence_length def test_is_subsequence(): assert is_subsequence("abc", "ahbgdc") == True assert is_subsequence("axc", "ahbgdc") == False assert is_subsequence("", "ahbgdc") == True assert is_subsequence("ahbgdc", "ahbgdc") == True def test_longest_subse...
[ { "docstring": "Helper function to determine if 'sub' is a subsequence of 's'.", "function_declaration": "def is_subsequence(sub, s):", "function_name": "is_subsequence", "parameter_list": "(sub, s)" }, { "docstring": "Returns the length of the longest string in words that is a subsequence o...
[ 1, 1, 0, 1, 1, 1, 0, 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_subsequence(s, sub):\n \"\"\"\n Helper function to check if 'sub' is a subsequence of 's'.\n \"\"\"\n it = iter(s)\n return all(char in it for char in s...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000017627", "row_id": 17627, "seed_ids": "['2275', '1779', '1078']" }
0.798201
Leetcode_17627
I
[ "is_subsequence", "longest_subsequence_length" ]
2
[ [ "longest_subsequence_length", "is_subsequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f279fe6f5d3da68a26a1d28d74b26a3adc54db60
156aa057e0c65788278ba6e68ad2350322b27725
v1.0
instruct
Leetcode
Leetcode_17821_I
Given an integer array `nums`, return _the minimum difference between the largest and smallest values in any subtree_ of the binary tree formed by the elements of `nums` if inserted in the given order. A binary tree is constructed such that each element of the array becomes a node, and child nodes are added by followin...
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 root is None: return TreeNode(val) if val < root.val: root.left = insert_into_bst(root.left, val) else: ...
from solution import min_diff_in_subtree def test_single_element(): assert min_diff_in_subtree([1]) == 0 def test_two_elements(): assert min_diff_in_subtree([1, 2]) == 0 def test_three_elements(): assert min_diff_in_subtree([4, 2, 7]) == 0 def test_multiple_elements(): assert min_diff_in_subtree([5,...
[]
[ 1, 1, 0, 0, 0, 0, 0, 0, 1, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "class Node:\n def __init__(self, key):\n self.left = None\n self.right = None\n self.val = key\n\ndef insert(root, key):\n if root is None:\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "0000017821", "row_id": 17821, "seed_ids": "['241', '47', '1819']" }
0.692918
Leetcode_17821
I
[ "insert_into_bst", "construct_bst", "find_min_max_diff", "min_diff_in_subtree" ]
4
[ [ "construct_bst", "insert_into_bst" ], [ "min_diff_in_subtree", "construct_bst" ], [ "min_diff_in_subtree", "find_min_max_diff" ] ]
3
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
63214516cd7638bbe7e87e52319e84656c16a43b
c94d6bbcfb218ed484e91715904a044b2a4bb203
v1.0
instruct
Leetcode
Leetcode_17839_I
Given an integer `n`, return the `nth` Fibonacci number. The sequence starts with `0, 1` and each subsequent number is the sum of the previous two. You need to compute this value efficiently using matrix exponentiation. Return the `nth` Fibonacci number modulo `1000000007` to avoid large numbers.
def matrix_mult(A, B, mod): return [ [(A[0][0] * B[0][0] + A[0][1] * B[1][0]) % mod, (A[0][0] * B[0][1] + A[0][1] * B[1][1]) % mod], [(A[1][0] * B[0][0] + A[1][1] * B[1][0]) % mod, (A[1][0] * B[0][1] + A[1][1] * B[1][1]) % mod] ] def matrix_pow(matrix, n, mod): result = [[1, 0], [0, 1]] ...
def test_nth_fibonacci_0(): assert nth_fibonacci(0) == 0 def test_nth_fibonacci_1(): assert nth_fibonacci(1) == 1 def test_nth_fibonacci_2(): assert nth_fibonacci(2) == 1 def test_nth_fibonacci_3(): assert nth_fibonacci(3) == 2 def test_nth_fibonacci_10(): assert nth_fibonacci(10) == 55 def tes...
[ { "docstring": null, "function_declaration": "def matrix_mult(A, B, mod):", "function_name": "matrix_mult", "parameter_list": "(A, B, mod)" }, { "docstring": null, "function_declaration": "def matrix_pow(matrix, n, mod):", "function_name": "matrix_pow", "parameter_list": "(matrix...
[ 1, 0, 0, 0, 1, 0, 0, 1, 0, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def matrix_multiply(A, B):\n \"\"\"\n Multiplies two 2x2 matrices A and B\n \"\"\"\n return [\n [(A[0][0] * B[0][0] + A[0][1] * B[1][0]) % 1000000007, (A[0...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "0000017839", "row_id": 17839, "seed_ids": "['2117', '252', '119']" }
0.69955
Leetcode_17839
I
[ "matrix_mult", "matrix_pow", "nth_fibonacci" ]
3
[ [ "matrix_pow", "matrix_mult" ], [ "nth_fibonacci", "matrix_pow" ] ]
2
[]
false
[]
false
pytest
false
[]
true
beb79087e1e4467e5549587c8f33aa6191a3ce19
9b14edf7c0d45674ec8e6f228b27935ba011ea1d
v1.0
instruct
Leetcode
Leetcode_17977_I
You are given a list of `n` video timestamps in the format `hours:minutes:seconds`, and a target duration `d` in seconds. Write a function to find pairs of timestamps where the absolute difference in their durations is less than or equal to `d` seconds. Return a list of tuples, where each tuple contains the indices of ...
def timestamp_to_seconds(timestamp): hours, minutes, seconds = map(int, timestamp.split(':')) return hours * 3600 + minutes * 60 + seconds def find_timestamp_pairs(timestamps, d): """ Returns a list of tuples where each tuple contains the indices of two timestamps with durations that differ by les...
from solution import find_timestamp_pairs def test_find_timestamp_pairs_simple_case(): timestamps = ["00:00:05", "00:00:10", "00:00:15"] d = 5 assert find_timestamp_pairs(timestamps, d) == [(0, 1), (1, 2)] def test_find_timestamp_pairs_with_large_difference(): timestamps = ["01:00:00", "02:00:00", "03...
[ { "docstring": null, "function_declaration": "def timestamp_to_seconds(timestamp):", "function_name": "timestamp_to_seconds", "parameter_list": "(timestamp)" }, { "docstring": "Returns a list of tuples where each tuple contains the indices of two timestamps \nwith durations that differ by le...
[ 1, 1, 1, 0, 1, 0, 1, 0, 1, 0 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "from typing import List, Tuple\n\ndef time_to_seconds(time: str) -> int:\n hours, minutes, seconds = map(int, time.split(':'))\n return hours * 3600 + minutes * 60 + se...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000017977", "row_id": 17977, "seed_ids": "['1530', '689', '1030']" }
0.563415
Leetcode_17977
I
[ "timestamp_to_seconds", "find_timestamp_pairs" ]
2
[ [ "find_timestamp_pairs", "timestamp_to_seconds" ] ]
1
[]
false
[]
false
pytest
true
[]
true
14d29d730b0775b07c4bde00593d4034d2a494d5
a9309c2b56c106278ac8d90313d9eafb5e6b6f52
v1.0
instruct
Leetcode
Leetcode_18141_I
You are given a string `s`, and your task is to determine if it is possible to partition the string into one or more substrings such that every substring is a palindrome. Return `True` if such a partitioning is possible, otherwise return `False`. For example, given the string `s = "aab"`, the output should be `True` s...
def is_palindrome(s: str) -> bool: """ Helper function to determine if a given string is a palindrome. """ return s == s[::-1] def can_partition_palindromes(s: str) -> bool: """ Determines if it is possible to partition the string `s` into one or more substrings each of which is a palindrome. ...
from solution import can_partition_palindromes def test_single_character(): assert can_partition_palindromes("a") == True def test_all_characters_same(): assert can_partition_palindromes("aaaa") == True def test_two_character_palindrome(): assert can_partition_palindromes("aa") == True def test_two_char...
[ { "docstring": "Helper function to determine if a given string is a palindrome.", "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": "Determines if it is possible to partition the string `s` into one or more substrings...
[ 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 can_partition_to_palindromes(s):\n \"\"\"\n Returns whether it's possible to partition the string s into one or more substrings such that\n every substring is a ...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "0000018141", "row_id": 18141, "seed_ids": "['48', '420', '587']" }
0.745476
Leetcode_18141
I
[ "is_palindrome", "can_partition_palindromes" ]
2
[ [ "can_partition_palindromes", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
fc880fd53a9e9547020d50aa7e78ed85381efe66
b10d076b4c9d6e735631583cfb76823258faed2c
v1.0
instruct
Leetcode
Leetcode_18202_I
You are given a `0-indexed` integer array `tasks` where `tasks[i]` represents the time taken to complete the `i-th` task. There are two workers available to complete these tasks. You want to assign tasks to the workers in such a way that the maximum time taken by either worker to complete their assigned tasks is minimi...
from typing import List def canCompleteTasks(tasks: List[int], max_time: int, num_workers: int) -> bool: current_worker_time = 0 workers_used = 1 for task in tasks: if current_worker_time + task <= max_time: current_worker_time += task else: workers_used += 1 ...
from solution import minimizedMaxTaskTime def test_example_case(): tasks = [1, 3, 5, 2, 4, 6] assert minimizedMaxTaskTime(tasks) == 11 def test_all_equal_tasks(): tasks = [3, 3, 3, 3] assert minimizedMaxTaskTime(tasks) == 6 def test_two_tasks(): tasks = [7, 3] assert minimizedMaxTaskTime(task...
[ { "docstring": null, "function_declaration": "def canCompleteTasks(tasks, max_time, num_workers):", "function_name": "canCompleteTasks", "parameter_list": "(tasks, max_time, num_workers)" }, { "docstring": null, "function_declaration": "def minimizedMaxTaskTime(tasks):", "function_na...
[ 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": "from typing import List\n\ndef minimizedMaxTaskTime(tasks: List[int]) -> int:\n def canFinishWithinMaxTime(maxTime):\n current_sum = 0\n worker_count = 1\n ...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "0000018202", "row_id": 18202, "seed_ids": "['2055', '518', '2212']" }
0.788572
Leetcode_18202
I
[ "canCompleteTasks", "minimizedMaxTaskTime" ]
2
[ [ "minimizedMaxTaskTime", "canCompleteTasks" ] ]
1
[]
false
[]
false
pytest
true
[]
true
82d2dca34f7bbc0775edf6680ff9cb808484f6de
c9738e133165d89bf7d5098b93bd34c2f0d80aa6
v1.0
instruct
Leetcode
Leetcode_18282_I
Given an undirected graph with `n` vertices labeled from `0` to `n-1`, represented by a 2D array `edges` where `edges[i] = [u, v, w]` denotes an edge between nodes `u` and `v` with weight `w`, find the weight of the second minimum spanning tree (SMST). A second minimum spanning tree (SMST) is a spanning tree that has t...
import heapq from collections import defaultdict def find_parent(parents, node): if parents[node] == node: return node parents[node] = find_parent(parents, parents[node]) return parents[node] def union(parents, ranks, node1, node2): root1 = find_parent(parents, node1) root2 = find_parent(p...
from solution import second_minimum_spanning_tree def test_no_edges(): assert second_minimum_spanning_tree(3, []) == -1 def test_single_edge(): assert second_minimum_spanning_tree(2, [[0, 1, 1]]) == -1 def test_simple_case(): assert second_minimum_spanning_tree(3, [[0, 1, 1], [1, 2, 1], [0, 2, 2]]) == 3 ...
[ { "docstring": null, "function_declaration": "def find_parent(parents, node):", "function_name": "find_parent", "parameter_list": "(parents, node)" }, { "docstring": null, "function_declaration": "def union(parents, ranks, node1, node2):", "function_name": "union", "parameter_lis...
[ 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": "import heapq\nfrom collections import defaultdict\n\ndef find_parent(parents, node):\n if parents[node] == node:\n return node\n parents[node] = find_parent(pare...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "0000018282", "row_id": 18282, "seed_ids": "['2508', '797', '1489']" }
0.728328
Leetcode_18282
I
[ "find_parent", "union", "kruskal", "second_minimum_spanning_tree" ]
4
[ [ "kruskal", "find_parent" ], [ "kruskal", "union" ], [ "second_minimum_spanning_tree", "kruskal" ], [ "union", "find_parent" ] ]
4
[]
false
[]
false
pytest
true
[]
true
0c97db01838a0d6bb0e1b5b181082cf28d866125
b3aacbc757dd9ef10b3c735c11f0711f79cad6b5
v1.0
instruct
Leetcode
Leetcode_18307_I
Given a list of unique words, find all pairs of distinct indices `(i, j)` in the given list such that the concatenation of the two words `words[i] + words[j]` is a palindrome. Implement the function `findPalindromePairs` that returns a list of all such pairs `[(i, j)]`. Each pair should be sorted in lexicographical ord...
def is_palindrome(word): """ Helper function to check if a word is a palindrome. """ return word == word[::-1] def findPalindromePairs(words): """ Returns a list of all pairs of distinct indices (i, j) such that the concatenation of words[i] + words[j] is a palindrome. """ palindrom...
from solution import findPalindromePairs def test_findPalindromePairs_no_pairs(): words = ["abc", "def", "ghi"] assert findPalindromePairs(words) == [] def test_findPalindromePairs_single_pair(): words = ["bat", "tab", "cat"] assert findPalindromePairs(words) == [(0, 1), (1, 0)] def test_findPalindro...
[ { "docstring": "Helper function to check if a word is a palindrome.", "function_declaration": "def is_palindrome(word):", "function_name": "is_palindrome", "parameter_list": "(word)" }, { "docstring": "Returns a list of all pairs of distinct indices (i, j) such that\nthe concatenation of wor...
[ 0, 0, 1, 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 findPalindromePairs(words):\n \"\"\"\n Finds all pairs of distinct indices (i, j) in the given list such that the\n concatenation of words[i] + words[j] is a pal...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "0000018307", "row_id": 18307, "seed_ids": "['478', '1034', '1343']" }
0.741883
Leetcode_18307
I
[ "is_palindrome", "findPalindromePairs" ]
2
[ [ "findPalindromePairs", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
127c9833fd162b41db3420b0ec30d654f8f52bed
779399401506f949c876316a48b2ff2683d1f5d1
v1.0
instruct
Leetcode
Leetcode_18507_I
A **subtree** of a binary tree `T` is a tree consisting of a node in `T` and all of its descendants in `T`. Given the roots of two binary trees, `root` and `subRoot`, return _true if there is a subtree of_ `root` _with the same structure and node values as_ `subRoot` _and false otherwise_. A subtree of `root` is a tree...
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def is_same_tree(s, t): if not s and not t: return True if not s or not t: return False if s.val != t.val: return False return is_same...
from solution import TreeNode, is_subtree def test_is_subtree_true(): # Construct tree [3, 4, 5, 1, 2] root = TreeNode(3) root.left = TreeNode(4) root.right = TreeNode(5) root.left.left = TreeNode(1) root.left.right = TreeNode(2) # Construct subtree [4, 1, 2] subRoot = TreeNode(4) ...
[]
[ 1, 1, 1, 0, 0, 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 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 isSubtree(root, su...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000018507", "row_id": 18507, "seed_ids": "['2134', '2309', '173']" }
0.534706
Leetcode_18507
I
[ "is_same_tree", "is_subtree" ]
2
[ [ "is_subtree", "is_same_tree" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
d02a1d2bfd2a18b9bb77011bac32f51d49942771
d2a3375b3806a3594a1917f462410a85903255d0
v1.0
instruct
Leetcode
Leetcode_18533_I
You are given an array of strings `words` and an integer `k`. A string `s` is called k-odd symmetric if it reads the same backward when observed every k-th character starting from the first character. For example, given the string "abcdefg" and k=2, the k-odd symmetric view would be "aceg", which reads the same forward...
def is_k_odd_symmetric(s, k): """ Check if the string `s` is k-odd symmetric. """ k_odd_str = s[::k] return k_odd_str == k_odd_str[::-1] def find_k_odd_symmetric_indices(words, k): """ Identify and return indices of k-odd symmetric strings in the given `words` array. """ result = []...
from solution import find_k_odd_symmetric_indices def test_find_k_odd_symmetric_indices_general_cases(): words = ["racecar", "abcdefg", "aabbcc", "kayak"] k = 2 assert find_k_odd_symmetric_indices(words, k) == [0, 3] words = ["abc", "xyz", "aba", "12321", "aaxaa"] k = 1 assert find_k_odd_s...
[ { "docstring": "Check if the string `s` is k-odd symmetric.", "function_declaration": "def is_k_odd_symmetric(s, k):", "function_name": "is_k_odd_symmetric", "parameter_list": "(s, k)" }, { "docstring": "Identify and return indices of k-odd symmetric strings in the given `words` array.", ...
[ 0, 0, 0, 0, 1, 0, 1, 0, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_k_odd_symmetric(s, k):\n \"\"\"\n Check if the string s is k-odd symmetric.\n \"\"\"\n filtered_string = s[::k]\n return filtered_string == filtered_str...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "0000018533", "row_id": 18533, "seed_ids": "['971', '2607', '156']" }
0.59988
Leetcode_18533
I
[ "is_k_odd_symmetric", "find_k_odd_symmetric_indices" ]
2
[ [ "find_k_odd_symmetric_indices", "is_k_odd_symmetric" ] ]
1
[]
false
[]
false
pytest
true
[]
true
826054a05eabc93b2cac7e536bd9e11d27901b96
13d4f2889adaed37ce1be563b709a3ebe4adac51
v1.0
instruct
Leetcode
Leetcode_18708_I
You are given a string `s` consisting only of characters 'A', 'B', and 'C'. You are allowed to replace exactly one character in the string with any other character ('A', 'B', or 'C'). Your task is to determine if it's possible to make the string alternating, where no two adjacent characters are the same, i.e., there ar...
def can_be_made_alternating(s): """ Determines if the given string s can be made alternating with exactly one replacement. """ if len(s) < 2: return True # A string of length 1 is already alternating # Check all possible single replacements by modifying each character for i in range(le...
from solution import can_be_made_alternating def test_can_be_made_alternating(): # Test cases with example strings that can be solved with one replacement assert can_be_made_alternating("AAB") == True assert can_be_made_alternating("BCC") == True assert can_be_made_alternating("CACA") == True asser...
[ { "docstring": "Determines if the given string s can be made alternating with exactly one replacement.", "function_declaration": "def can_be_made_alternating(s):", "function_name": "can_be_made_alternating", "parameter_list": "(s)" }, { "docstring": "Checks if the given string s is alternati...
[ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def can_make_alternating(s):\n \"\"\"\n Determines if the string can be made alternating by replacing exactly one character.\n \"\"\"\n if len(s) <= 1:\n r...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "0000018708", "row_id": 18708, "seed_ids": "['658', '388', '1431']" }
0.650746
Leetcode_18708
I
[ "can_be_made_alternating", "is_alternating" ]
2
[ [ "can_be_made_alternating", "is_alternating" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e1b1c4cf6e6b31a3c1bbb0caedcfa8d5bbe591e8
ecb382335f918d89c7bae344f092a178adee26d7
v1.0
instruct
Leetcode
Leetcode_18736_I
Given a string `s`, write a function that determines if it can be broken down into exactly `k` non-overlapping substrings, each of which is a palindrome. Return `true` if such a partitioning is possible, and `false` otherwise.
def is_palindrome(s): return s == s[::-1] def can_partition_to_k_palindromes(s, k): def dfs(index, k): if index == len(s): return k == 0 if k == 0: return False for i in range(index + 1, len(s) + 1): if is_palindrome(s[index:i]): if df...
from solution import can_partition_to_k_palindromes def test_partition_possible(): assert can_partition_to_k_palindromes("aab", 2) == True def test_partition_not_possible(): assert can_partition_to_k_palindromes("abc", 2) == False def test_single_palindrome(): assert can_partition_to_k_palindromes("racec...
[ { "docstring": null, "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": null, "function_declaration": "def can_partition_to_k_palindromes(s, k):", "function_name": "can_partition_to_k_palindromes", "paramet...
[ 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(s):\n return s == s[::-1]\n\ndef can_partition_into_k_palindromes(s, k):\n def backtrack(start, k):\n if start == len(s) and k == 0:\n ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000018736", "row_id": 18736, "seed_ids": "['22', '125', '2256']" }
0.80029
Leetcode_18736
I
[ "is_palindrome", "can_partition_to_k_palindromes" ]
2
[ [ "can_partition_to_k_palindromes", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0e0fddff81321b6b9813d3640ef745887604e597
1802e3d9eb1932f5b6b2d877f579efbf7308032b
v1.0
instruct
Leetcode
Leetcode_18755_I
Write a function that takes a list of strings and returns the longest string that can be made by concatenating a subsequence of strings from the list such that no two consecutive strings in the sequence are anagrams of each other. If there are multiple valid results, return any one. If no valid string exists, return an...
def are_anagrams(s1, s2): """ Helper function to check if two strings are anagrams. """ return sorted(s1) == sorted(s2) def concatenate_strings_without_anagrams(strings): """ Function that returns the longest string by concatenating a subsequence of strings from the list such that no two co...
from solution import concatenate_strings_without_anagrams def test_concatenate_strings_without_anagrams_basic(): assert concatenate_strings_without_anagrams(["the", "is", "theta", "het", "at"]) == "thetheta" or "thetahis" or "ists" or "iettahis" def test_concatenate_with_only_anagrams(): assert concatenate_st...
[ { "docstring": "Helper function to check if two strings are anagrams.", "function_declaration": "def are_anagrams(s1, s2):", "function_name": "are_anagrams", "parameter_list": "(s1, s2)" }, { "docstring": "Function that returns the longest string by concatenating a subsequence of\nstrings fr...
[ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "from itertools import permutations\n\ndef are_anagrams(s1, s2):\n return sorted(s1) == sorted(s2)\n\ndef longest_non_anagram_sequence(strings):\n n = len(strings)\n ...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "0000018755", "row_id": 18755, "seed_ids": "['1365', '1146', '95']" }
0.743981
Leetcode_18755
I
[ "are_anagrams", "concatenate_strings_without_anagrams" ]
2
[ [ "concatenate_strings_without_anagrams", "are_anagrams" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c045b1ecff8fbd905fd597e2e460c8c102d3ffa7
13fff87e8276f20b79198969f477bdada022a3c0
v1.0
instruct
Leetcode
Leetcode_18787_I
You are given a string `s` and an array of strings `words` containing distinct strings. You need to find all unique words in `words` that are subsequences of `s`. Return _the list of all such unique words_. A subsequence of a string is a new string generated from the original string by deleting some (can be none) of th...
def is_subsequence(s, word): """ Helper function to check if word is a subsequence of s. """ it = iter(s) return all(char in it for char in word) def find_subsequences(s, words): """ Returns the list of all unique words in 'words' that are subsequences of 's'. """ return [word for w...
from solution import is_subsequence, find_subsequences def test_is_subsequence(): assert is_subsequence("abcde", "ace") == True assert is_subsequence("abcde", "aec") == False assert is_subsequence("abc", "abc") == True assert is_subsequence("abc", "abcd") == False assert is_subsequence("abcde", "ab...
[ { "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 list of all unique words in 'words' that are subsequences of 's'."...
[ 1, 0, 1, 1, 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": "def is_subsequence(s, word):\n \"\"\"\n Helper function to check if 'word' is a subsequence of 's'.\n \"\"\"\n it = iter(s)\n return all(char in it for char in...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "0000018787", "row_id": 18787, "seed_ids": "['1793', '1552', '2594']" }
0.668531
Leetcode_18787
I
[ "is_subsequence", "find_subsequences" ]
2
[ [ "find_subsequences", "is_subsequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
168cc5f437957761f4c8af4af4d3e8f99b7b663e
71386821d6965d2c945c5efc08d88d8a92505a4b
v1.0
instruct
Leetcode
Leetcode_18829_I
Given a list of strings `email_list` where each string is an email address, write a function to **filter** out all the valid email addresses. A valid email address follows these rules: - It has exactly one '@' symbol. - The local part (the part before the '@') does not start or end with a dot ('.') and also does not h...
import re def is_valid_email(email): """ Helper function to check if an email address is valid based on the defined rules. """ # Regular expression pattern for validating an email pattern = re.compile(r"^(?!.*[.]{2})(?!.*[@]{2})[A-Za-z0-9]+([._A-Za-z0-9-])*[A-Za-z0-9]+@[A-Za-z0-9]+([._A-Za-z0-9-])*...
from solution import filter_valid_emails def test_filter_valid_emails(): assert filter_valid_emails(["valid.email@example.com", "invalid.email..address@example.com", ".invalid.email@example.com", "invalid.email.@examp...
[ { "docstring": "Helper function to check if an email address is valid based on the defined rules.", "function_declaration": "def is_valid_email(email):", "function_name": "is_valid_email", "parameter_list": "(email)" }, { "docstring": "Returns a list containing all the valid email addresses ...
[ 1, 1, 0, 1, 0, 0, 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": "import re\n\ndef is_valid_email(email):\n \"\"\"\n Checks if the provided email is valid based on the given rules.\n \"\"\"\n email_pattern = re.compile(\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "0000018829", "row_id": 18829, "seed_ids": "['1287', '2129', '1848']" }
0.531115
Leetcode_18829
I
[ "is_valid_email", "filter_valid_emails" ]
2
[ [ "filter_valid_emails", "is_valid_email" ] ]
1
[]
false
[]
false
pytest
true
[]
true
48677fe9992478bd32d8e90e7af12b26a9ad4c3d
15257045625d606e4b240fd4f9fd8b096214330b
v1.0
instruct
Leetcode
Leetcode_18912_I
You are given a list of words and a pattern. Return a list of words from the given list that match the pattern. A word matches the pattern if there exists a permutation of letters p so that after replacing every letter `x` in the pattern with `p(x)`, we get the desired word. Implement the function `List<String> findAnd...
def match(word, pattern): """ Helper function to check if the word matches the pattern. """ mapping = {} reverse_mapping = {} for w_char, p_char in zip(word, pattern): if w_char in mapping: if mapping[w_char] != p_char: return False else: m...
from solution import findAndReplacePattern, match def test_match_basic(): assert match("abc", "xyz") == True assert match("abc", "xxy") == False def test_findAndReplacePattern_basic(): words = ["abc", "deq", "mee", "aqq", "dkd", "ccc"] pattern = "abb" assert findAndReplacePattern(words, pattern) =...
[ { "docstring": "Helper function to check if the word matches the pattern.", "function_declaration": "def match(word, pattern):", "function_name": "match", "parameter_list": "(word, pattern)" }, { "docstring": "Find and return the list of words matching the given pattern.", "function_decl...
[ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def find_and_replace_pattern(words, pattern):\n \"\"\"\n Returns a list of words from the given list that match the pattern.\n \"\"\"\n\n def matches(word, patter...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "0000018912", "row_id": 18912, "seed_ids": "['384', '96', '2605']" }
0.60033
Leetcode_18912
I
[ "match", "findAndReplacePattern" ]
2
[ [ "findAndReplacePattern", "match" ] ]
1
[]
false
[]
false
pytest
true
[]
true
57e4c236051a544bc619e65c15328c1d96c09ff6
6b08584351f03b87628a0d98a2279179fceecc96
v1.0
instruct
Leetcode
Leetcode_19026_I
You are given a matrix `grid` of size `m x n` consisting of integers. You can perform an operation where you select an integer in the matrix and increase or decrease it by 1. Return _the minimum number of operations needed to make all the elements in the matrix equal_. If it is not possible to make all elements equal t...
def min_operations_to_equal_elements(grid): """ Calculate the minimum number of operations to make all elements in a matrix equal, where each operation consists of incrementing or decrementing an element by 1. If it's not possible to make all elements equal, return -1. """ m, n = len(grid), len...
from solution import min_operations def test_all_elements_equal(): assert min_operations([[2, 2], [2, 2]]) == 0 def test_possible_to_make_equal(): assert min_operations([[1, 3], [5, 7]]) == 8 assert min_operations([[2, 4], [6, 8]]) == 8 def test_not_possible_to_make_equal(): assert min_operations([[1...
[ { "docstring": "Calculate the minimum number of operations to make all elements in a matrix equal,\nwhere each operation consists of incrementing or decrementing an element by 1.\n\nIf it's not possible to make all elements equal, return -1.", "function_declaration": "def min_operations_to_equal_elements(gr...
[ 0, 1, 0, 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_operations_to_equal_matrix(grid):\n \"\"\"\n Return the minimum number of operations needed to make all elements in the matrix equal,\n or -1 if it is not po...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "0000019026", "row_id": 19026, "seed_ids": "['1619', '2172', '1780']" }
0.703971
Leetcode_19026
I
[ "min_operations_to_equal_elements", "can_make_all_elements_equal", "min_operations" ]
3
[ [ "min_operations", "can_make_all_elements_equal" ], [ "min_operations", "min_operations_to_equal_elements" ] ]
2
[]
false
[]
false
pytest
true
[]
true
d9b6a64837ec078c38e2a3bc554c9c44a7967357
8b93d8b6c17dca08ec245958a76ddf3d2d7db60c
v1.0
instruct
Leetcode
Leetcode_19120_I
Given a binary tree with `n` nodes, each node has a unique value from `1` to `n`. The binary tree is represented by a 2D integer array `tree` where each element `tree[i] = [parenti, childi, isLeft]` representing: - `parenti` is the value of the parent node, - `childi` is the value of the child node, and - `isLeft` is `...
class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None def build_tree(tree): if not tree: return None nodes = {} for parent, child, isLeft in tree: if parent not in nodes: nodes[parent] = TreeNode(parent) ...
from solution import find_deepest_node_value def test_example_case(): tree = [ [1, 2, 1], [1, 3, 0], [2, 4, 1], [2, 5, 0], [3, 6, 0] ] assert find_deepest_node_value(tree) == 4 def test_all_left_children(): tree = [ [1, 2, 1], [2, 3, 1], ...
[]
[ 1, 1, 0, 1, 1, 0, 0, 1, 0, 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 buildTree(tree):\n nodes = {}\n \n # Cr...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "0000019120", "row_id": 19120, "seed_ids": "['2432', '1621', '527']" }
0.6164
Leetcode_19120
I
[ "build_tree", "find_deepest_node", "find_deepest_node_value" ]
3
[ [ "find_deepest_node_value", "build_tree" ], [ "find_deepest_node_value", "find_deepest_node" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
703fd04b9fec245ff3158d6e151e10cd954e560b
1f2dfb1615f0ff81be7c48258ac351005f0639d7
v1.0
instruct
Leetcode
Leetcode_19175_I
Given a matrix of size `m x n` filled with non-negative integers, return the length of the **shortest path** from the top-left cell to the bottom-right cell, such that you can move only in the four cardinal directions (up, down, left, right), and the sum of all numbers along the path must be **even**. If there is no su...
from collections import deque def is_valid(i, j, m, n): """ Check if the coordinates (i, j) are within the matrix bounds. """ return 0 <= i < m and 0 <= j < n def shortest_even_sum_path(matrix): """ Returns the length of the shortest path from the top-left to the bottom-right cell of t...
from solution import shortest_even_sum_path def test_example_case(): matrix = [ [1, 3, 1], [2, 8, 4], [1, 2, 4] ] assert shortest_even_sum_path(matrix) == 4 # 1 -> 2 -> 8 -> 4 = 15 (Odd) def test_single_cell_even(): matrix = [ [2] ] assert shortest_even_sum_pat...
[ { "docstring": "Check if the coordinates (i, j) are within the matrix bounds.", "function_declaration": "def is_valid(i, j, m, n):", "function_name": "is_valid", "parameter_list": "(i, j, m, n)" }, { "docstring": "Returns the length of the shortest path from the top-left to the bottom-right\...
[ 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": "from collections import deque\n\ndef is_valid_move(x, y, m, n):\n return 0 <= x < m and 0 <= y < n\n\ndef shortest_even_sum_path(matrix):\n \"\"\"\n Returns the leng...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "0000019175", "row_id": 19175, "seed_ids": "['55', '2241', '2168']" }
0.686663
Leetcode_19175
I
[ "is_valid", "shortest_even_sum_path" ]
2
[ [ "shortest_even_sum_path", "is_valid" ] ]
1
[]
false
[]
false
pytest
true
[]
true
fcd60109493d4b99c4e2939b580e0857d8f98ee6
4f33fb30a8649b083ff69b7e0d65d68f51a25a6a
v1.0
instruct
Leetcode
Leetcode_19227_I
You are given a list of tasks represented by an array of integers `tasks`, where each integer represents the time required to complete a task. You are also given an integer `k` representing the number of workers available to complete these tasks. Each task can only be assigned to one worker, and each worker can only wo...
from typing import List def canComplete(tasks: List[int], k: int, mid: int) -> bool: workers_needed = 1 current_worker_time = 0 for task in tasks: if current_worker_time + task <= mid: current_worker_time += task else: workers_needed += 1 current_wor...
from solution import assignTasks def test_assign_tasks_equal_distribution(): assert assignTasks([3, 3, 3, 3], 2) == 6 def test_assign_tasks_single_task(): assert assignTasks([5, 2, 4], 3) == 5 def test_assign_tasks_all_equal_tasks(): assert assignTasks([3, 3, 3, 3, 3, 3], 3) == 6 def test_assign_tasks_l...
[ { "docstring": null, "function_declaration": "def canComplete(tasks, k, mid):", "function_name": "canComplete", "parameter_list": "(tasks, k, mid)" }, { "docstring": null, "function_declaration": "def assignTasks(tasks, k):", "function_name": "assignTasks", "parameter_list": "(ta...
[ 0, 0, 0, 1, 0, 1, 1, 0, 0, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def canCompleteInTime(tasks, k, mid):\n workers = 1\n current_time = 0\n \n for task in tasks:\n if current_time + task > mid:\n workers += 1\n ...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "0000019227", "row_id": 19227, "seed_ids": "['379', '663', '1368']" }
0.739175
Leetcode_19227
I
[ "canComplete", "assignTasks" ]
2
[ [ "assignTasks", "canComplete" ] ]
1
[]
false
[]
false
pytest
true
[]
true
bd9c22f34ca003533258aff69d7f5298450df336
a2d6122bc8060b0e6315abd97467dbf3db6b9a42
v1.0
instruct
Leetcode
Leetcode_19329_I
You are given a binary tree with `n` nodes. Each node is assigned a unique value from `1` to `n`. You need to write a program to determine if the tree can be split into two subtrees such that the sum of values in both subtrees is equal. Return `true` if such a split is possible, otherwise return `false`.
class TreeNode: def __init__(self, value=0, left=None, right=None): self.value = value self.left = left = left self.right = right def sum_tree(node): if node is None: return 0 return node.value + sum_tree(node.left) + sum_tree(node.right) def check_equal_partition(node, tot...
from solution import TreeNode, canPartition def test_can_partition(): # Test with a simple binary tree that can be split into two equal sum subtrees # Tree structure: # 1 # / \ # 2 3 root = TreeNode(1) root.left = TreeNode(2) root.right = TreeNode(3) assert canPa...
[]
[ 0, 0, 0, 0, 0, 0, 1, 1, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "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 can_split_tr...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "0000019329", "row_id": 19329, "seed_ids": "['1278', '775', '242']" }
0.601519
Leetcode_19329
I
[ "sum_tree", "check_equal_partition", "canPartition" ]
3
[ [ "canPartition", "check_equal_partition" ], [ "canPartition", "sum_tree" ], [ "check_equal_partition", "sum_tree" ] ]
3
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
4857ebb2cab48fd82f3a5f11cf1442d5180746f1
f40ff9d632df5d2ce8c5f0aee9c059da97edf35d
v1.0
instruct
Leetcode
Leetcode_19367_I
You are given a list of `n` integers which represents the number of pages in `n` different books respectively, and an integer `m` which denotes the number of students. You have to allocate all the books to the students such that each student gets at least one book and the maximum number of pages assigned to a student i...
def is_possible(arr, n, m, curr_min): students_required = 1 curr_sum = 0 for i in range(n): if arr[i] > curr_min: return False if curr_sum + arr[i] > curr_min: students_required += 1 curr_sum = arr[i] if students_required > m: ...
from solution import find_pages def test_example_case(): assert find_pages([12, 34, 67, 90], 4, 2) == 113 def test_single_book(): assert find_pages([100], 1, 1) == 100 def test_single_student(): assert find_pages([10, 20, 30, 40], 4, 1) == 100 def test_students_more_than_books(): assert find_pages([...
[ { "docstring": null, "function_declaration": "def is_possible(arr, n, m, curr_min):", "function_name": "is_possible", "parameter_list": "(arr, n, m, curr_min)" }, { "docstring": null, "function_declaration": "def find_pages(arr, n, m):", "function_name": "find_pages", "parameter_...
[ 1, 0, 0, 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": "def is_possible(arr, n, m, curr_min):\n students_required = 1\n curr_sum = 0\n \n for i in range(n):\n if arr[i] > curr_min:\n return False\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "0000019367", "row_id": 19367, "seed_ids": "['856', '1306', '568']" }
0.681464
Leetcode_19367
I
[ "is_possible", "find_pages" ]
2
[ [ "find_pages", "is_possible" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5ff7978f279195a9a0132418d816d09e30d8a534
8a5bc0ccb0d16cf0f3640f7e68707b6b8df5a0e0
v1.0
instruct
Leetcode
Leetcode_19370_I
You are given two arrays `workers` and `bikes` of equal length, where `workers[i]` represents the `i-th` worker's location and `bikes[j]` represents the `j-th` bike's location on a grid. Your task is to assign each worker to a bike such that the sum of the Manhattan distances between each worker and their assigned bike...
from itertools import permutations def calculate_manhattan_distance(p1, p2): """ Returns the Manhattan distance between points p1 and p2. """ return abs(p1[0] - p2[0]) + abs(p1[1] - p2[1]) def assign_bikes(workers, bikes): """ Assigns each worker to a bike such that the sum of the Manhattan di...
from solution import assign_bikes, calculate_manhattan_distance def test_single_worker_bike(): workers = [(0, 0)] bikes = [(1, 1)] assert assign_bikes(workers, bikes) == 2 def test_two_workers_bikes(): workers = [(0, 0), (2, 2)] bikes = [(1, 1), (3, 3)] assert assign_bikes(workers, bikes) == 4...
[ { "docstring": "Returns the Manhattan distance between points p1 and p2.", "function_declaration": "def calculate_manhattan_distance(p1, p2):", "function_name": "calculate_manhattan_distance", "parameter_list": "(p1, p2)" }, { "docstring": "Assigns each worker to a bike such that the sum of ...
[ 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 itertools import permutations\n\ndef min_total_distance(workers, bikes):\n \"\"\"\n Assign workers to bikes to minimize the total Manhattan distance.\n \n Ar...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "0000019370", "row_id": 19370, "seed_ids": "['1705', '362', '1064']" }
0.651215
Leetcode_19370
I
[ "calculate_manhattan_distance", "assign_bikes" ]
2
[ [ "assign_bikes", "calculate_manhattan_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
596ffdd22e0abe65aa849afa017e02e7a7593cda
d2e67768c2cc31685802ce3438192957cef2e461
v1.0
instruct
Leetcode
Leetcode_19428_I
You are given a string `s` consisting of lowercase English letters, and a string array `words` where each element is a unique word. Your task is to determine which words from the array can be formed by deleting some (or none) of the characters of `s` without changing the order of the remaining characters. Return _a lis...
def can_form_word(s, word): it = iter(s) return all(char in it for char in word) def find_matching_words(s, words): """ Returns a sorted list of words from the array that can be formed by deleting some (or none) of the characters of `s` without changing the order of the remaining characters. ...
from solution import can_form_word, find_matching_words def test_can_form_word(): assert can_form_word("abpcplea", "apple") == True assert can_form_word("abpcplea", "ale") == True assert can_form_word("abpcplea", "monkey") == False assert can_form_word("abpcplea", "aplea") == True def test_find_matchi...
[ { "docstring": null, "function_declaration": "def can_form_word(s, word):", "function_name": "can_form_word", "parameter_list": "(s, word)" }, { "docstring": "Returns a sorted list of words from the array that can be formed by deleting\nsome (or none) of the characters of `s` without changin...
[ 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": "def can_form_by_deleting(s, word):\n \"\"\"\n Helper function to check if word can be formed from s by deleting some characters\n without changing the order of the r...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000019428", "row_id": 19428, "seed_ids": "['2201', '2363', '152']" }
0.690645
Leetcode_19428
I
[ "can_form_word", "find_matching_words" ]
2
[ [ "find_matching_words", "can_form_word" ] ]
1
[]
false
[]
false
pytest
true
[]
true
28275d884384baf9feba210fbe0b5de857d148b1
ad8a7bf7aa11d1c61ed90e127beed1a7531413dd
v1.0
instruct
Leetcode
Leetcode_19884_I
[Question]: Given two integers `start` and `end`, return a list of all the integers within that range (inclusive) that are self-dividing. An integer is considered self-dividing if it is divisible by every digit it contains and does not contain the digit `0`. For instance, `128` is a self-dividing number because `128 % ...
from typing import List def is_self_dividing(number: int) -> bool: """ Helper function that checks if a number is self-dividing. """ original_number = number while number > 0: digit = number % 10 if digit == 0 or original_number % digit != 0: return False number ...
from solution import self_dividing_numbers def test_self_dividing_numbers_basic(): assert self_dividing_numbers(1, 22) == [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 15, 22] def test_self_dividing_numbers_single_digit(): assert self_dividing_numbers(1, 9) == [1, 2, 3, 4, 5, 6, 7, 8, 9] def test_self_div...
[ { "docstring": "Helper function that checks if a number is self-dividing.", "function_declaration": "def is_self_dividing(number):", "function_name": "is_self_dividing", "parameter_list": "(number)" }, { "docstring": "Returns a list of all self-dividing numbers between start and end (inclusi...
[ 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef is_self_dividing(number: int) -> bool:\n \"\"\"\n Helper function to check if a number is self-dividing.\n \"\"\"\n original_number...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "0000019884", "row_id": 19884, "seed_ids": "['1619', '2266', '661']" }
0.613555
Leetcode_19884
I
[ "is_self_dividing", "self_dividing_numbers" ]
2
[ [ "self_dividing_numbers", "is_self_dividing" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8d7ad00503071e45ad33285f625067ad3937e0ac
2f27830cfb11189ac43b8dd7169401a90f1c38bc
v1.0
instruct
Leetcode
Leetcode_19913_I
You are given a list of integers `nums` representing a heap (not necessarily balanced) and you need to implement a function to convert it into a **max-heap**. A max-heap is a complete binary tree where the value of each node is greater than or equal to the values of its children. Return the list representing the max-he...
def max_heapify(nums, n, i): """ Ensures that the subtree rooted at index `i` in the `nums` list is a max-heap. """ largest = i left = 2 * i + 1 right = 2 * i + 2 if left < n and nums[left] > nums[largest]: largest = left if right < n and nums[right] > nums[largest]: la...
from solution import build_max_heap def test_already_max_heap(): assert build_max_heap([9, 5, 6, 2, 3]) == [9, 5, 6, 2, 3] def test_simple_case(): assert build_max_heap([3, 9, 2, 1, 4, 5]) == [9, 4, 5, 1, 3, 2] def test_empty_list(): assert build_max_heap([]) == [] def test_single_element(): assert ...
[ { "docstring": "Ensures that the subtree rooted at index `i` in the `nums` list is a max-heap.", "function_declaration": "def max_heapify(nums, n, i):", "function_name": "max_heapify", "parameter_list": "(nums, n, i)" }, { "docstring": "Converts the input list `nums` into a max-heap.", "...
[ 1, 0, 0, 1, 1, 1, 1, 0, 0 ]
5
medium
0.556
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def max_heapify(nums, n, i):\n \"\"\"\n Helper function to maintain the max-heap property.\n \"\"\"\n largest = i # Initialize largest as root\n left = 2 * i ...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "0000019913", "row_id": 19913, "seed_ids": "['1791', '2107', '1186']" }
0.583835
Leetcode_19913
I
[ "max_heapify", "build_max_heap" ]
2
[ [ "build_max_heap", "max_heapify" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5901b1396a7efa596749744ce615e11ff11cbf8a
5d8c94ba7c089e97414310af1b039027904471f0