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_38185_I
A company is trying to optimize the performance of their network by minimizing the total communication time between different departments. The departments are connected by a certain number of bidirectional cables, and each cable has a specific time delay to send information. The company provides you with an integer `n`...
def find(parent, i): if parent[i] == i: return i return find(parent, parent[i]) def union(parent, rank, x, y): rootX = find(parent, x) rootY = find(parent, y) if rank[rootX] < rank[rootY]: parent[rootX] = rootY elif rank[rootX] > rank[rootY]: parent[rootY] = rootX ...
from solution import minimum_communication_time def test_minimum_communication_time_basic(): assert minimum_communication_time(4, [(0, 1, 1), (1, 2, 2), (2, 3, 1), (0, 3, 4)]) == 4 def test_minimum_communication_time_disconnected(): assert minimum_communication_time(4, [(0, 1, 1), (1, 2, 2)]) == -1 def test_...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 1, 0, 1, 0, 0, 1, 1, 1, 0 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n else:\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n root_x = find(parent,...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "0000038185", "row_id": 38185, "seed_ids": "['1416', '1051', '2317']" }
0.610434
Leetcode_38185
I
[ "find", "union", "minimum_communication_time" ]
3
[ [ "minimum_communication_time", "find" ], [ "minimum_communication_time", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
true
[]
true
332a633ffee356a7277ea25ec700d0e9898875c9
eb47dc719bf1e3024eaafc321c08da3dec05d22b
v1.0
instruct
Leetcode
Leetcode_38200_I
You are given a binary tree root representing a complete binary tree. Every level, except possibly the last, is completely filled, and all nodes are as far left as possible. Determine the number of nodes in the tree without traversing the entire tree. Return _an integer_ representing the number of nodes in the given bi...
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def countNodes(root): if not root: return 0 left_depth = get_depth(root, True) right_depth = get_depth(root, False) if left_depth == right_d...
from solution import TreeNode, countNodes def test_empty_tree(): assert countNodes(None) == 0 def test_single_node_tree(): root = TreeNode(1) assert countNodes(root) == 1 def test_complete_tree_height_2(): root = TreeNode(1, TreeNode(2), TreeNode(3)) assert countNodes(root) == 3 def test_complet...
[]
[ 1, 0, 0, 1, 0, 0, 1, 1, 1, 1 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, x):\n self.val = x\n self.left = None\n self.right = None\n\ndef countNodes(root):\n \"\"\"\n This function...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000038200", "row_id": 38200, "seed_ids": "['1735', '698', '1898']" }
0.545488
Leetcode_38200
I
[ "countNodes", "get_depth" ]
2
[ [ "countNodes", "get_depth" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
03a9529c0c21592c0bb955bd4af8d984fd0991d5
6096abf7557adfc2879290bbbd047adf1655d99c
v1.0
instruct
Leetcode
Leetcode_38216_I
You are given two string arrays `words1` and `words2`. A string `b` is a subset of string `a` if every letter in `b` occurs in `a` including multiplicity. For example, "wrr" is a subset of "warrior," but is not a subset of "world" or "elloworld." Return an array of all the strings in `words1` which are subsets of all t...
from collections import Counter def is_subset(a, b): """ Checks if string b is a subset of string a. """ counter_a = Counter(a) counter_b = Counter(b) for char, count in counter_b.items(): if counter_a[char] < count: return False return True def wordSubsets(words1, word...
from solution import wordSubsets def test_wordSubsets_simple_case(): assert wordSubsets(["amazon","apple","facebook","google","leetcode"], ["e","o"]) == ["facebook","google","leetcode"] def test_wordSubsets_empty_words1(): assert wordSubsets([], ["e","o"]) == [] def test_wordSubsets_empty_words2(): asser...
[ { "docstring": "Checks if string b is a subset of string a.", "function_declaration": "def is_subset(a, b):", "function_name": "is_subset", "parameter_list": "(a, b)" }, { "docstring": "Returns an array of all the strings in words1 which are subsets of all the strings in words2.", "funct...
[ 1, 1, 0, 0, 0, 0, 1, 1, 0, 0 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "from collections import Counter\n\ndef word_subset(words1, words2):\n \"\"\"\n Return an array of all the strings in words1 which are subsets of all the strings in word...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "0000038216", "row_id": 38216, "seed_ids": "['1836', '1463', '1751']" }
0.614892
Leetcode_38216
I
[ "is_subset", "wordSubsets" ]
2
[ [ "wordSubsets", "is_subset" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2e17b94f8de4473888d74139fe37ae7c96efc3ba
31887c5f4c148b46df72e9e85ce834b345b266b7
v1.0
instruct
Leetcode
Leetcode_38297_I
Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its area. A rectangle is defined as a group of contiguous cells arranged in a rectangular shape, where each cell contains a 1. The matrix is represented as a list of lists, where each inner list is a row of the m...
def maximalRectangle(matrix): """ Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its area. """ if not matrix or not matrix[0]: return 0 max_area = 0 num_cols = len(matrix[0]) heights = [0] * num_cols for r...
from solution import maximalRectangle def test_example_case(): matrix = [ [1, 0, 1, 0, 0], [1, 0, 1, 1, 1], [1, 1, 1, 1, 1], [1, 0, 0, 1, 0] ] assert maximalRectangle(matrix) == 6 def test_all_zeros(): matrix = [ [0, 0], [0, 0] ] assert maximalRe...
[ { "docstring": "Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and\nreturn its area.", "function_declaration": "def maximalRectangle(matrix):", "function_name": "maximalRectangle", "parameter_list": "(matrix)" }, { "docstring": "Helper functi...
[ 0, 1, 1, 1, 0, 1, 1, 0, 1, 0 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def maximalRectangle(matrix):\n if not matrix:\n return 0\n\n max_area = 0\n num_cols = len(matrix[0])\n heights = [0] * (num_cols + 1) # Extra element to ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000038297", "row_id": 38297, "seed_ids": "['1145', '1192', '2336']" }
0.723858
Leetcode_38297
I
[ "maximalRectangle", "largestRectangleArea" ]
2
[ [ "maximalRectangle", "largestRectangleArea" ] ]
1
[]
false
[]
false
pytest
true
[]
true
fb6c6dbe05db90d8ea46ed3f5cfb27a9fb348e04
d4e1af2c8c7a2e6789d88d0fde524e2977a0d2cc
v1.0
instruct
Leetcode
Leetcode_38314_I
Given a `2D` grid of size `m x n` and a list of `q` queries, each containing the coordinates of the top-left and bottom-right corners of a sub-grid, implement a function to return the sum of integers in each sub-grid for every query. You may assume that each integer in the grid is non-negative.
def preprocess_grid(grid): """ Preprocess the grid to calculate the prefix sum matrix. """ m = len(grid) n = len(grid[0]) prefix_sum = [[0] * (n + 1) for _ in range(m + 1)] for i in range(1, m + 1): for j in range(1, n + 1): prefix_sum[i][j] = grid[i - 1][j - 1] + pr...
import pytest from solution import preprocess_grid, sum_subgrid, grid_queries def test_preprocess_grid(): grid = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] expected_prefix_sum = [ [0, 0, 0, 0], [0, 1, 3, 6], [0, 5, 12, 21], [0, 12, 27, 45] ] assert p...
[ { "docstring": "Preprocess the grid to calculate the prefix sum matrix.", "function_declaration": "def preprocess_grid(grid):", "function_name": "preprocess_grid", "parameter_list": "(grid)" }, { "docstring": "Calculate the sum of integers in the sub-grid defined by the top-left and bottom-r...
[ 0, 1, 0, 1, 1, 1, 1, 1, 1, 1 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def preprocess_grid(grid):\n \"\"\"\n This function preprocesses the grid to create a sum matrix so that each element (i, j) \n in the sum matrix contains the sum of...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000038314", "row_id": 38314, "seed_ids": "['515', '83', '529']" }
0.626713
Leetcode_38314
I
[ "preprocess_grid", "sum_subgrid", "grid_queries" ]
3
[ [ "grid_queries", "preprocess_grid" ], [ "grid_queries", "sum_subgrid" ] ]
2
[]
false
[]
false
pytest
true
[]
true
7d3a1f960d82fc21331eb7982456187026371e8f
e727ba4eabcea5a211b36883708ed1a5ae02f092
v1.0
instruct
Leetcode
Leetcode_38453_I
A company operates several cargo ships for delivering goods internationally, and they need to determine the most efficient routes. A route is defined by a sequence of ports the cargo ship will visit. Each port is represented as a tuple of integers `(xi, yi)` indicating its coordinates on a 2D map. Due to some constrain...
from itertools import permutations import math def calculate_distance(port1, port2): """ Calculate the Euclidean distance between two ports. """ return math.sqrt((port1[0] - port2[0])**2 + (port1[1] - port2[1])**2) def total_distance(route): """ Calculate the total distance of a given route in...
from solution import minimum_travel_distance def test_minimum_travel_distance_single_port(): ports = [(0, 0)] assert minimum_travel_distance(ports) == 0 def test_minimum_travel_distance_two_ports(): ports = [(0, 0), (1, 1)] expected_distance = 2 * math.sqrt(2) # Distance (0,0) -> (1,1) -> (0,0) a...
[ { "docstring": "Calculate the Euclidean distance between two ports.", "function_declaration": "def calculate_distance(port1, port2):", "function_name": "calculate_distance", "parameter_list": "(port1, port2)" }, { "docstring": "Calculate the total distance of a given route including returnin...
[ 0, 1, 0, 0, 0, 1, 0, 0, 1, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "from itertools import permutations\nimport math\n\ndef calculate_distance(p1, p2):\n \"\"\"\n Calculate Euclidean distance between two points p1 and p2.\n \"\"\"\n ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000038453", "row_id": 38453, "seed_ids": "['849', '587', '1266']" }
0.727772
Leetcode_38453
I
[ "calculate_distance", "total_distance", "minimum_travel_distance" ]
3
[ [ "minimum_travel_distance", "total_distance" ], [ "total_distance", "calculate_distance" ] ]
2
[]
false
[]
false
pytest
true
[]
true
88b866e37c6e002bec3a8e9e711fb7aed6006a88
265c3e41db7e0fc1d4fbdb44cd8bafdbf8b7a871
v1.0
instruct
Leetcode
Leetcode_38688_I
Given a string `s` and an integer `k`, your task is to find the `k`-th lexicographically smallest palindrome string that can be obtained by rearranging the characters of `s`. If it is not possible to form such a palindrome, return an empty string. A palindrome is a string that reads the same backward as forward. For e...
from itertools import permutations def is_palindrome(s): return s == s[::-1] def kth_lexicographical_palindrome(s, k): """ Returns the k-th lexicographically smallest palindrome that can be formed by rearranging the characters of s, or an empty string if it's not possible. """ unique_perms = s...
from solution import kth_lexicographical_palindrome def test_palindrome_exists(): assert kth_lexicographical_palindrome("aabb", 1) == "abba" assert kth_lexicographical_palindrome("aabb", 2) == "baab" def test_no_palindrome(): assert kth_lexicographical_palindrome("abc", 1) == "" def test_single_c...
[ { "docstring": null, "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": "Returns the k-th lexicographically smallest palindrome that can be formed\nby rearranging the characters of s, or an empty string if it's not pos...
[ 0, 0, 0, 0, 1, 0, 0, 1, 1, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "from collections import Counter\nfrom itertools import permutations\n\ndef is_valid_palindrome(s):\n \"\"\"\n Check if a given string can form a palindrome.\n \"\"\"...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000038688", "row_id": 38688, "seed_ids": "['1176', '1644', '1727']" }
0.835333
Leetcode_38688
I
[ "is_palindrome", "kth_lexicographical_palindrome" ]
2
[ [ "kth_lexicographical_palindrome", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9dec981a376208ecfb3a9f0fe66be60944f3a2eb
22f625cfe1399055509c904e6c9956b2632ad291
v1.0
instruct
Leetcode
Leetcode_38708_I
You are given an unsorted array of integers `nums` and an integer `k`. Your task is to find the `k`-th smallest element in the array. Note that it is the k-th smallest element in the sorted order, not the k-th distinct element. You are required to solve this problem with an algorithm that has an average-case time compl...
import random def partition(nums, left, right, pivot_index): pivot_value = nums[pivot_index] nums[pivot_index], nums[right] = nums[right], nums[pivot_index] # Move pivot to end store_index = left for i in range(left, right): if nums[i] < pivot_value: nums[store_index], nums[i] = nu...
from solution import find_kth_smallest def test_find_kth_smallest(): assert find_kth_smallest([3, 2, 1, 5, 6, 4], 2) == 2 assert find_kth_smallest([3, 2, 3, 1, 2, 4, 5, 5, 6], 4) == 3 assert find_kth_smallest([7, 10, 4, 3, 20, 15], 3) == 7 assert find_kth_smallest([7, 10, 4, 3, 20, 15], 4) == 10 as...
[ { "docstring": null, "function_declaration": "def partition(nums, left, right, pivot_index):", "function_name": "partition", "parameter_list": "(nums, left, right, pivot_index)" }, { "docstring": null, "function_declaration": "def quickselect(nums, left, right, k):", "function_name":...
[ 1, 0, 0, 1, 1, 1, 1, 0, 0, 1 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def kth_smallest(nums, k):\n \"\"\"\n Returns the k-th smallest element in the array nums.\n \"\"\"\n def partition(arr, low, high):\n pivot = arr[high]\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000038708", "row_id": 38708, "seed_ids": "['927', '1932', '1073']" }
0.630586
Leetcode_38708
I
[ "partition", "quickselect", "find_kth_smallest" ]
3
[ [ "find_kth_smallest", "quickselect" ], [ "quickselect", "partition" ] ]
2
[]
false
[]
false
pytest
true
[]
true
9e85be9ef26f9e668052ca5eb699b15588b1a5a0
1a3067b52d7e01c3c59b6b776dfe7895b413a47d
v1.0
instruct
Leetcode
Leetcode_38753_I
You are given two strings `s1` and `s2`, both representing sequence of moves in a 2D plane where each move is one of the characters: 'U' (up), 'D' (down), 'L' (left), 'R' (right). Starting from the origin point (0, 0), determine if it is possible for these two sequences to make you end up at the same final position on ...
def final_position(s): """ Calculates the final position after performing the moves in s. """ x, y = 0, 0 for move in s: if move == 'U': y += 1 elif move == 'D': y -= 1 elif move == 'L': x -= 1 elif move == 'R': x += 1 ...
from solution import same_final_position def test_same_final_position(): assert same_final_position('UDLR', 'LRUD') == True assert same_final_position('UUDDLRR', 'UDLR') == False assert same_final_position('UUU', 'DDD') == False assert same_final_position('LLRR', 'RRLL') == True assert same_final_p...
[ { "docstring": "Calculates the final position after performing the moves in s.", "function_declaration": "def final_position(s):", "function_name": "final_position", "parameter_list": "(s)" }, { "docstring": "Determines if two sequences of moves s1 and s2 end up at the same final position.",...
[ 1, 0, 0, 0, 0, 1, 0, 1, 1, 0 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def end_up_at_same_position(s1, s2):\n \"\"\"\n Returns True if strings s1 and s2 result in the same final position on a 2D plane.\n \n Moves are:\n 'U' - up\n...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000038753", "row_id": 38753, "seed_ids": "['1354', '831', '1373']" }
0.651377
Leetcode_38753
I
[ "final_position", "same_final_position" ]
2
[ [ "same_final_position", "final_position" ] ]
1
[]
false
[]
false
pytest
true
[]
true
845c6964599f7eb33a5972a476e502cf11be0b4f
3018b8d1179c8712c7a00486b49d1eff749da0c5
v1.0
instruct
Leetcode
Leetcode_38801_I
You are given a **binary tree** in the form of an integer array `nodes`, where each element represents a node in the tree in level order traversal. The value `-1` represents a `null` node (i.e., no child). You are also given two node values `node1` and `node2` that are guaranteed to be present in the tree. Return _the ...
class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None def build_tree(nodes): if not nodes: return None root = TreeNode(nodes[0]) queue = [root] idx = 1 while queue and idx < len(nodes): node = queue.pop(0) if nodes...
from solution import lowest_common_ancestor def test_case_1(): nodes = [3, 5, 1, 6, 2, 0, 8, -1, -1, 7, 4] node1 = 5 node2 = 1 assert lowest_common_ancestor(nodes, node1, node2) == 3 def test_case_2(): nodes = [3, 5, 1, 6, 2, 0, 8, -1, -1, 7, 4] node1 = 5 node2 = 4 assert lowest_common...
[]
[ 1, 0, 1, 1, 1, 0, 1, 1, 0, 1 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, x):\n self.val = x\n self.left = None\n self.right = None\n\ndef build_tree(nodes):\n if not nodes:\n r...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "0000038801", "row_id": 38801, "seed_ids": "['1257', '2143', '2360']" }
0.569607
Leetcode_38801
I
[ "build_tree", "find_lca", "lowest_common_ancestor" ]
3
[ [ "lowest_common_ancestor", "build_tree" ], [ "lowest_common_ancestor", "find_lca" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
ce03ef1dfd44896f94d209e08ef5f360706fa468
95079123ee309c1e9e2de1db2410f4ee7736dc1f
v1.0
instruct
Leetcode
Leetcode_38989_I
Given a binary tree where each node contains a value. You are also given a list of target sums. Your task is to determine for each target sum whether there is a path in the tree that starts at the root and ends at any leaf, such that the sum of the values along that path is equal to the target sum. A path does not need...
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def hasPathSum(root, targetSum): if not root: return False if not root.left and not root.right and root.val == targetSum: return True return hasPa...
from solution import TreeNode, checkTargetSums def test_single_node_tree(): root = TreeNode(5) targetSums = [5, 10] expected = [True, False] assert checkTargetSums(root, targetSums) == expected def test_two_level_tree(): root = TreeNode(5, TreeNode(4), TreeNode(8)) targetSums = [9, 13] exp...
[]
[ 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": "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 has_path_sum(root,...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "0000038989", "row_id": 38989, "seed_ids": "['1444', '2467', '1828']" }
0.575909
Leetcode_38989
I
[ "hasPathSum", "checkTargetSums" ]
2
[ [ "checkTargetSums", "hasPathSum" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
bf2aedc2092b6a5b96ce2320d1e485aec2c61422
f85af361d310621fc7f9434d1228fb42e1f94c39
v1.0
instruct
Leetcode
Leetcode_38997_I
You are given a string `text` and an array of strings `words`. For each word in `words`, determine if it is a **subsequence** of `text`. Return an array of booleans, where the `i-th` boolean is `true` if `words[i]` is a subsequence of `text`, and `false` otherwise. A subsequence is a sequence that can be derived from a...
def is_subsequence(text, word): """ Helper function to check if a word is a subsequence of text. """ it = iter(text) return all(char in it for char in word) def subsequences_check(text, words): """ For each word in words, determine if it is a subsequence of text. Args: text (st...
from solution import subsequences_check def test_subsequences_check_all_true(): words = ["abc", "ace", "a"] text = "abcde" assert subsequences_check(text, words) == [True, True, True] def test_subsequences_check_all_false(): words = ["aec", "xyz", "abf"] text = "abcde" assert subsequences_chec...
[ { "docstring": "Helper function to check if a word is a subsequence of text.", "function_declaration": "def is_subsequence(text, word):", "function_name": "is_subsequence", "parameter_list": "(text, word)" }, { "docstring": "For each word in words, determine if it is a subsequence of text.\n...
[ 1, 0, 1, 0, 0, 0, 1, 1, 1, 1 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_subsequence(text, words):\n \"\"\"\n Determine if each word in words is a subsequence of text.\n \n Parameters:\n text (str): The main string.\n word...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000038997", "row_id": 38997, "seed_ids": "['2289', '400', '2516']" }
0.682336
Leetcode_38997
I
[ "is_subsequence", "subsequences_check" ]
2
[ [ "subsequences_check", "is_subsequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
392aaf39e4edc1d2b181d9e27adc377d198a5bdb
429a36982887d12f8a553908f1c40d122e4dd87c
v1.0
instruct
Leetcode
Leetcode_39229_I
Given a non-negative integer `n`, generate a list of all **self-dividing numbers** between 1 and `n` (inclusive). A **self-dividing number** is a number that is divisible by every digit it contains. For example, 128 is a self-dividing number because 128 % 1 == 0, 128 % 2 == 0, and 128 % 8 == 0. Note that `0` is not a s...
def is_self_dividing(num): """ Check if a number is self-dividing. """ original_num = num while num > 0: digit = num % 10 if digit == 0 or original_num % digit != 0: return False num //= 10 return True def self_dividing_numbers(n): """ Generate a list...
from solution import is_self_dividing, self_dividing_numbers def test_is_self_dividing(): assert is_self_dividing(1) == True assert is_self_dividing(128) == True assert is_self_dividing(12) == True assert is_self_dividing(120) == False assert is_self_dividing(101) == False def test_self_dividing_n...
[ { "docstring": "Check if a number is self-dividing.", "function_declaration": "def is_self_dividing(num):", "function_name": "is_self_dividing", "parameter_list": "(num)" }, { "docstring": "Generate a list of all self-dividing numbers between 1 and n (inclusive).", "function_declaration"...
[ 1, 1, 0, 1, 0, 1, 1, 1, 0, 1 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_self_dividing(number):\n \"\"\"\n Checks if a number is a self-dividing number.\n \"\"\"\n original_number = number\n while number > 0:\n digit =...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000039229", "row_id": 39229, "seed_ids": "['2278', '124', '2415']" }
0.583078
Leetcode_39229
I
[ "is_self_dividing", "self_dividing_numbers" ]
2
[ [ "self_dividing_numbers", "is_self_dividing" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1bcb083f4e60f278a42f59a97a07da05c1de19fe
d71dd83eb7d3fa8e0c6b2d96db98addb9408d06e
v1.0
instruct
Leetcode
Leetcode_39420_I
Given an integer `n`, generate all structurally unique **BST's** (Binary Search Trees) that store values `1 ... n`. For each generated BST, return its preorder traversal. Note that the preorder traversal is a process of visiting the root node first, then recursively visiting the left subtree, and finally the right subt...
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def generate_preorder(node): return [node.val] + generate_preorder(node.left) + generate_preorder(node.right) if node else [] def generate_trees(start, end): if star...
from solution import generate_all_bst_preorders def test_generate_all_bst_preorders_zero(): assert generate_all_bst_preorders(0) == [] def test_generate_all_bst_preorders_one(): assert generate_all_bst_preorders(1) == [[1]] def test_generate_all_bst_preorders_two(): assert generate_all_bst_preorders(2) =...
[]
[ 1, 1, 0, 0, 1, 0, 0, 1, 0, 0 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\ndef generate_trees(n):...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "0000039420", "row_id": 39420, "seed_ids": "['927', '1104', '1794']" }
0.499101
Leetcode_39420
I
[ "generate_preorder", "generate_trees", "generate_all_bst_preorders" ]
3
[ [ "generate_all_bst_preorders", "generate_preorder" ], [ "generate_all_bst_preorders", "generate_trees" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
3e2c53ea03313e79cfc072fd75534375cc338332
011b3d469e4f27cd9d44fba1d1673d90c74e0b60
v1.0
instruct
Leetcode
Leetcode_39555_I
You are given a string `s` consisting of lowercase English letters and a 2D list `pairs` of integers where `pairs[i] = [a, b]` indicates that you can swap the characters at index `a` and index `b` of the string. You can swap the characters at any pair of indices in `pairs` as many times as you want. Return _the **lexic...
def find(parent, x): if parent[x] != x: parent[x] = find(parent, parent[x]) return parent[x] def union(parent, x, y): rootX = find(parent, x) rootY = find(parent, y) if rootX != rootY: parent[rootY] = rootX def smallestStringWithSwaps(s, pairs): n = len(s) parent = list(ran...
from solution import smallestStringWithSwaps def test_example_case(): assert smallestStringWithSwaps("dcab", [[0,3],[1,2]]) == "bacd" def test_trivial_case(): assert smallestStringWithSwaps("dcab", []) == "dcab" def test_whole_string_swap(): assert smallestStringWithSwaps("dcab", [[0,1],[1,2],[2,3]]) == ...
[ { "docstring": null, "function_declaration": "def find(parent, x):", "function_name": "find", "parameter_list": "(parent, x)" }, { "docstring": null, "function_declaration": "def union(parent, x, y):", "function_name": "union", "parameter_list": "(parent, x, y)" }, { "doc...
[ 0, 0, 1, 0, 0, 1, 0, 0, 0 ]
2
hard
0.222
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def smallestStringWithSwaps(s, pairs):\n from collections import defaultdict\n import heapq\n\n # A helper function to perform a depth-first search\n def dfs(node...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "0000039555", "row_id": 39555, "seed_ids": "['458', '1053', '2192']" }
0.758151
Leetcode_39555
I
[ "find", "union", "smallestStringWithSwaps" ]
3
[ [ "smallestStringWithSwaps", "find" ], [ "smallestStringWithSwaps", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
true
[]
true
001ec0d5db13f77735a9608f578ce01c2ef7a2c2
3c0c6d2629a9af7394fe825534a6357a2dcb3760
v1.0
instruct
Leetcode
Leetcode_39626_I
Given a string `sequence` and an array of strings `words`, find the length of the longest string in `words` that is a subsequence of `sequence`. A subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. Implement a function that...
def is_subsequence(seq, word): """ Helper function to check if 'word' is a subsequence of 'seq'. """ it = iter(seq) return all(char in it for char in word) def longest_subsequence_length(sequence, words): """ Returns the length of the longest string in 'words' that is a subsequence of 'sequ...
from solution import longest_subsequence_length def test_longest_subsequence_length_no_subsequence(): assert longest_subsequence_length("abc", ["def", "ghi"]) == 0 def test_longest_subsequence_length_one_subsequence(): assert longest_subsequence_length("abcde", ["a", "ac", "ace"]) == 3 def test_longest_subse...
[ { "docstring": "Helper function to check if 'word' is a subsequence of 'seq'.", "function_declaration": "def is_subsequence(seq, word):", "function_name": "is_subsequence", "parameter_list": "(seq, word)" }, { "docstring": "Returns the length of the longest string in 'words' that is a subseq...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_subsequence(sequence, word):\n \"\"\" Check if word is a subsequence of sequence \"\"\"\n it = iter(sequence)\n return all(char in it for char in word)\n\ndef...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000039626", "row_id": 39626, "seed_ids": "['117', '1901', '2526']" }
0.737259
Leetcode_39626
I
[ "is_subsequence", "longest_subsequence_length" ]
2
[ [ "longest_subsequence_length", "is_subsequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0129e2de32858f67ae488f09e15ad4d5200a63dc
16fecf8dd58cecaf22063bcc4f408a47c4decbb2
v1.0
instruct
Leetcode
Leetcode_39720_I
You are given an array of integers `tasks` where each element represents the duration of a task in minutes. You are also given an integer `n` representing the number of workers. Each worker can perform exactly one task at a time, and once a worker starts a task, they must complete it without interruptions. Distribute...
def canDistributeWithinTime(tasks, n, maxTime): # Helper function to check if tasks can be distributed within given maxTime current_time = 0 workers_used = 1 for task in tasks: if current_time + task <= maxTime: current_time += task else: workers_used += 1 ...
from solution import distributeTasks def test_distribute_tasks_basic(): assert distributeTasks([1, 2, 3, 4, 5], 2) == 9 def test_distribute_tasks_equal_tasks(): assert distributeTasks([2, 2, 2, 2, 2, 2], 3) == 4 def test_distribute_tasks_single_worker(): assert distributeTasks([1, 2, 3, 4, 5], 1) == 15 ...
[ { "docstring": null, "function_declaration": "def canDistributeWithinTime(tasks, n, maxTime):", "function_name": "canDistributeWithinTime", "parameter_list": "(tasks, n, maxTime)" }, { "docstring": null, "function_declaration": "def distributeTasks(tasks, n):", "function_name": "dist...
[ 0, 1, 0, 1, 0, 1, 1, 1, 0, 0 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def distribute_tasks(tasks, n):\n \"\"\"\n Distribute the tasks among the workers such that the maximum time \n taken by any worker to complete their assigned tasks ...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "0000039720", "row_id": 39720, "seed_ids": "['484', '2478', '1105']" }
0.768804
Leetcode_39720
I
[ "canDistributeWithinTime", "distributeTasks" ]
2
[ [ "distributeTasks", "canDistributeWithinTime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4365b84c399469a8c24d9f41d0521d09d2d99e76
fb4b98c1894a3d716d2cc1cacda15b6cfd2350f3
v1.0
instruct
Leetcode
Leetcode_39733_I
Given a binary tree with `n` nodes, each node containing an integer value, determine the **lowest common ancestor** of two given nodes in the tree. The lowest common ancestor of two nodes `p` and `q` is defined as the deepest node that has both `p` and `q` as descendants (where we allow a node to be a descendant of its...
class TreeNode: def __init__(self, value=0, left=None, right=None): self.value = value self.left = left self.right = right def find_lca(root, p, q): """ Finds the lowest common ancestor of two nodes p and q in the binary tree with root. Returns the value of the LCA, or -1 if one...
import pytest from solution import TreeNode, lowest_common_ancestor def test_lca_common_case(): root = TreeNode(3) root.left = TreeNode(5) root.right = TreeNode(1) root.left.left = TreeNode(6) root.left.right = TreeNode(2) root.left.right.left = TreeNode(7) root.left.right.right = TreeNode...
[]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\ndef lowestCommonAncest...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000039733", "row_id": 39733, "seed_ids": "['2499', '1051', '750']" }
0.558205
Leetcode_39733
I
[ "find_lca", "node_exists", "lowest_common_ancestor" ]
3
[ [ "lowest_common_ancestor", "find_lca" ], [ "lowest_common_ancestor", "node_exists" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
fe5a9c11fd1cadc6f476eaac58f2c324fe994f18
9ba95ee33ede015b1615cbd9f8351e2db35a1246
v1.0
instruct
Leetcode
Leetcode_39745_I
You are given a list of non-negative integers `nums` representing the amount of money of each house arranged in a circular manner. Calculate the maximum amount of money you can rob tonight without alerting the police. Since it is a circular list, if you rob the first house, you cannot rob the last house, and if you rob...
def rob_linear(nums): """ Returns the maximum amount of money that can be robbed in a linear arrangement of houses.""" prev, curr = 0, 0 for num in nums: prev, curr = curr, max(curr, prev + num) return curr def maxRob(nums): """ Returns the maximum amount of money that can be robbed...
from solution import maxRob def test_single_house(): assert maxRob([5]) == 5 def test_two_houses(): assert maxRob([2, 3]) == 3 def test_three_houses(): assert maxRob([2, 3, 2]) == 3 def test_four_houses(): assert maxRob([1, 2, 3, 1]) == 4 def test_large_amounts(): assert maxRob([200, 3, 140...
[ { "docstring": "Returns the maximum amount of money that can be robbed\nin a linear arrangement of houses.", "function_declaration": "def rob_linear(nums):", "function_name": "rob_linear", "parameter_list": "(nums)" }, { "docstring": "Returns the maximum amount of money that can be robbed in...
[ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def rob_linear(nums):\n prev, curr = 0, 0\n for num in nums:\n prev, curr = curr, max(curr, prev + num)\n return curr\n\n\ndef maxRob(nums):\n if len(nums)...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "0000039745", "row_id": 39745, "seed_ids": "['36', '304', '1625']" }
0.609663
Leetcode_39745
I
[ "rob_linear", "maxRob" ]
2
[ [ "maxRob", "rob_linear" ] ]
1
[]
false
[]
false
pytest
true
[]
true
224c3422dfc695c27a2677a9d5b2eb308b4f2ee7
cdf3d56d2c933544f2c9da8cb60497cdd390890c
v1.0
instruct
Leetcode
Leetcode_39747_I
You are given a list of integers `nums` where each integer represents the number of pages in a book. You need to allocate these books to a certain number of students such that the maximum pages allocated to a student is minimized. You are also given an integer `students`, the number of students available to read the bo...
def is_feasible(books, students, max_pages): current_pages, needed_students = 0, 1 for pages in books: if current_pages + pages <= max_pages: current_pages += pages else: needed_students += 1 if needed_students > students or pages > max_pages: ...
from solution import min_pages def test_min_pages_example1(): books = [12, 34, 67, 90] students = 2 assert min_pages(books, students) == 113 def test_min_pages_example2(): books = [10, 20, 30, 40] students = 2 assert min_pages(books, students) == 60 def test_min_pages_only_one_student(): ...
[ { "docstring": null, "function_declaration": "def is_feasible(books, students, max_pages):", "function_name": "is_feasible", "parameter_list": "(books, students, max_pages)" }, { "docstring": "Returns the minimum possible maximum pages allocated to a student such that\neach student gets at l...
[ 1, 0, 1, 1, 0, 0, 1, 1, 0, 1 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_valid_allocation(nums, students, max_pages):\n current_sum, required_students = 0, 1\n \n for pages in nums:\n if pages > max_pages:\n retur...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000039747", "row_id": 39747, "seed_ids": "['2543', '1372', '2605']" }
0.697403
Leetcode_39747
I
[ "is_feasible", "min_pages" ]
2
[ [ "min_pages", "is_feasible" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a335d8ddad67c02fd11b639c64049cf70ab19574
2bead50760faee81798ae79b2ea3edea50c72271
v1.0
instruct
Leetcode
Leetcode_39796_I
You are given a list of strings `words` and a string `chars`. A string is considered "good" if it can be formed by characters from `chars` (each character can only be used once). Return the length of all good strings in `words`. For example: - If `words = ["cat","bt","hat","tree"]` and `chars = "atach"`, then the ans...
def can_form(word, chars_count): """ Check if the word can be formed by characters from chars_count. """ from collections import Counter word_count = Counter(word) for char, count in word_count.items(): if chars_count[char] < count: return False return True def tota...
from solution import total_length_of_good_strings def test_example_case_1(): words = ["cat", "bt", "hat", "tree"] chars = "atach" assert total_length_of_good_strings(words, chars) == 6 def test_example_case_2(): words = ["hello", "world", "students"] chars = "welldonehoneyr" assert total_lengt...
[ { "docstring": "Check if the word can be formed by characters from chars_count.", "function_declaration": "def can_form(word, chars_count):", "function_name": "can_form", "parameter_list": "(word, chars_count)" }, { "docstring": "Return the total length of all good strings.", "function_d...
[ 1, 0, 1, 0, 1, 0, 1, 1, 0, 1 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def count_good_strings_length(words, chars):\n \"\"\"\n Returns the total length of all good strings that can be formed by characters from chars.\n A string is consi...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000039796", "row_id": 39796, "seed_ids": "['289', '1730', '31']" }
0.730601
Leetcode_39796
I
[ "can_form", "total_length_of_good_strings" ]
2
[ [ "total_length_of_good_strings", "can_form" ] ]
1
[]
false
[]
false
pytest
true
[]
true
68ba5a7a970789b288bc36feec51d242ae2aef90
510351586e3e7883fc7a78316af0d1aceb2fb191
v1.0
instruct
Leetcode
Leetcode_39871_I
You are given a series of tasks represented as a list of integers where each entry corresponds to the amount of time required to complete that task. You are also given an integer `m`, representing the number of parallel workers available to complete these tasks. Each worker can take on one task at a time, and the tasks...
def can_complete(tasks, m, mid): required_workers = 1 current_load = 0 for task in tasks: if current_load + task > mid: required_workers += 1 current_load = task if required_workers > m: return False else: current_load += t...
from solution import min_max_time def test_single_worker(): assert min_max_time([1, 2, 3, 4, 5], 1) == 15 assert min_max_time([7, 2, 5, 10, 8], 1) == 32 def test_more_workers_than_tasks(): assert min_max_time([1, 2, 3], 5) == 3 assert min_max_time([10, 7, 8], 10) == 10 def test_equal_workers_and_task...
[ { "docstring": null, "function_declaration": "def can_complete(tasks, m, mid):", "function_name": "can_complete", "parameter_list": "(tasks, m, mid)" }, { "docstring": null, "function_declaration": "def min_max_time(tasks, m):", "function_name": "min_max_time", "parameter_list": ...
[ 0, 0, 0, 0, 1, 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 minimum_max_time(tasks, m):\n \"\"\"\n Determine the minimum possible maximum time required to complete all tasks with m workers.\n \"\"\"\n \n def can_fin...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "0000039871", "row_id": 39871, "seed_ids": "['2079', '329', '917']" }
0.727119
Leetcode_39871
I
[ "can_complete", "min_max_time" ]
2
[ [ "min_max_time", "can_complete" ] ]
1
[]
false
[]
false
pytest
true
[]
true
375ed14e387dd240a1fb95d395d83f008d9cbee6
e38c1d31a20785dbf4ba39bf77bf672d8cfabbc7
v1.0
instruct
Leetcode
Leetcode_39874_I
You are given a list of non-negative integers `nums`. Your task is to find the **maximum** number you can form by combining these numbers. You are allowed to rearrange the numbers in any order to create this combination. Return the maximum number as a string since the number may be too large to fit in a standard intege...
from functools import cmp_to_key def compare(x, y): # Custom comparator function to order numbers for creating the largest number if x+y > y+x: return -1 elif x+y < y+x: return 1 else: return 0 def largestNumber(nums): """ Forms the maximum number by rearranging non-neg...
from solution import largestNumber def test_example_case(): nums = [3, 30, 34, 5, 9] assert largestNumber(nums) == "9534330" def test_single_digit_numbers(): nums = [1, 2, 3, 4, 5, 6, 7, 8, 9] assert largestNumber(nums) == "987654321" def test_all_numbers_same(): nums = [1, 1, 1, 1] assert la...
[ { "docstring": null, "function_declaration": "def compare(x, y):", "function_name": "compare", "parameter_list": "(x, y)" }, { "docstring": "Forms the maximum number by rearranging non-negative integers in nums.\n\nParameters:\nnums (list): List of non-negative integers.\n\nReturns:\nstr: Th...
[ 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": "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_9
{ "original_instruction": "", "prompt_id": "0000039874", "row_id": 39874, "seed_ids": "['1858', '2144', '635']" }
0.669417
Leetcode_39874
I
[ "compare", "largestNumber" ]
2
[ [ "largestNumber", "compare" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4939dfe4009c1f48df81a920ab399e905e272c92
8b34f437f939b1d014623ddb681401bfb3b87c25
v1.0
instruct
Leetcode
Leetcode_39986_I
You are given a string `s` representing a mathematical equation of the form `A=B` where `A` and `B` are expressions containing only positive integers and the operators `+` and `-`. Evaluate whether the equation holds true. Return `True` if the equation is valid and `False` otherwise. The equation will not contain any p...
def evaluate_expression(expression): """ Evaluates a mathematical expression containing positive integers and the operators + and -. """ total = 0 current_value = 0 operator = '+' for char in expression: if char.isdigit(): current_value = current_value * 10 + int(cha...
from solution import is_equation_valid def test_simple_equality(): assert is_equation_valid("2+3=5") == True def test_simple_inequality(): assert is_equation_valid("2+3=6") == False def test_multiple_operations_valid(): assert is_equation_valid("10-2+3=11") == True def test_multiple_operations_invalid()...
[ { "docstring": "Evaluates a mathematical expression containing positive integers and the operators + and -.", "function_declaration": "def evaluate_expression(expression):", "function_name": "evaluate_expression", "parameter_list": "(expression)" }, { "docstring": "Evaluates if a given equat...
[ 1, 1, 0, 1, 0, 0, 1, 0, 0, 1 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def evaluate_expression(expr):\n \"\"\"\n Evaluates a mathematical expression containing only positive integers,\n and the operators `+` and `-`.\n \"\"\"\n re...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000039986", "row_id": 39986, "seed_ids": "['2448', '695', '150']" }
0.614936
Leetcode_39986
I
[ "evaluate_expression", "is_equation_valid" ]
2
[ [ "is_equation_valid", "evaluate_expression" ] ]
1
[]
false
[]
false
pytest
true
[]
true
fe9bb38da6fcfa377977705d8eed40001129e9b7
bab1911e78c6e3357040d02662c846e6e0ec233f
v1.0
instruct
Leetcode
Leetcode_40020_I
You are given a 2D integer grid `matrix` representing a battlefield where `0` represents empty cells and `1` represents obstacles. Two players want to start from the top-left corner and reach the bottom-right corner of the battlefield. Both players follow the shortest path and can move only one cell at a time in the fo...
from collections import deque def bfs(matrix, start, end): rows, cols = len(matrix), len(matrix[0]) visited = set() queue = deque([(start, 0)]) visited.add(start) while queue: (x, y), dist = queue.popleft() if (x, y) == end: return dist for...
from solution import shortest_path def test_both_reach(): assert shortest_path([[0, 0, 0], [0, 1, 0], [0, 1, 0]]) == [4, 4] def test_no_possible_way(): assert shortest_path([[0, 1], [1, 0]]) == -1 def test_single_element_obstacle(): assert shortest_path([[1]]) == -1 def test_single_element_open(): a...
[ { "docstring": null, "function_declaration": "def bfs(matrix, start, end):", "function_name": "bfs", "parameter_list": "(matrix, start, end)" }, { "docstring": null, "function_declaration": "def shortest_path(matrix):", "function_name": "shortest_path", "parameter_list": "(matrix...
[ 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": "from collections import deque\n\ndef bfs(matrix, start, end):\n rows, cols = len(matrix), len(matrix[0])\n directions = [(0, 1), (1, 0), (0, -1), (-1, 0)]\n \n qu...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000040020", "row_id": 40020, "seed_ids": "['1259', '2138', '2381']" }
0.760511
Leetcode_40020
I
[ "bfs", "shortest_path" ]
2
[ [ "shortest_path", "bfs" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ab9c4c54fa6451e7d20da9eb47e365950c6ed60e
bef25b9c96c0e785814e8f3ca58f821aeae305aa
v1.0
instruct
Leetcode
Leetcode_40037_I
Given a binary tree, return the bottom-up level order traversal of its nodes' values. (i.e., from left to right, level by level from leaf to root). Each node is guaranteed to have an integer value. The tree is represented in the input as an array where `null` represents absent nodes. Example: Input: [3, 9, 20, null, ...
from collections import deque class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None def levelOrderBottom(root): if not root: return [] result, queue = deque(), deque([root]) while queue: level = [] for _ in rang...
from solution import bottom_up_level_order_traversal def test_case_1(): input_data = [3, 9, 20, None, None, 15, 7] expected_output = [[15, 7], [9, 20], [3]] assert bottom_up_level_order_traversal(input_data) == expected_output def test_case_2(): input_data = [1] expected_output = [[1]] assert ...
[]
[ 0, 0, 1, 1, 0, 1, 0, 0, 0, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "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_5
{ "original_instruction": "", "prompt_id": "0000040037", "row_id": 40037, "seed_ids": "['859', '51', '2578']" }
0.505484
Leetcode_40037
I
[ "levelOrderBottom", "deserialize", "bottom_up_level_order_traversal" ]
3
[ [ "bottom_up_level_order_traversal", "deserialize" ], [ "bottom_up_level_order_traversal", "levelOrderBottom" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
3fead452ff6a342674da5e695c7ab328f4d4a86f
c9ac4493d2a2b143848cd8ca84d556a566aec0fb
v1.0
instruct
Leetcode
Leetcode_40071_I
Given a list of integers `nums`, where each integer represents a task with a certain duration, and an integer `k` representing the number of processors available, partition the list into `k` contiguous subarrays such that the maximum sum of any subarray is minimized. Return the minimized value.
def can_partition(nums, k, max_sum): current_sum = 0 partitions = 1 for num in nums: if current_sum + num > max_sum: partitions += 1 current_sum = num if partitions > k: return False else: current_sum += num return True def...
from solution import minimize_max_partition_sum def test_minimize_max_partition_sum(): assert minimize_max_partition_sum([10, 20, 30, 40, 50], 2) == 90 assert minimize_max_partition_sum([10, 20, 30, 40, 50], 3) == 60 assert minimize_max_partition_sum([10, 20, 30, 40, 50], 1) == 150 assert minimize_max_...
[ { "docstring": null, "function_declaration": "def can_partition(nums, k, max_sum):", "function_name": "can_partition", "parameter_list": "(nums, k, max_sum)" }, { "docstring": null, "function_declaration": "def minimize_max_partition_sum(nums, k):", "function_name": "minimize_max_par...
[ 1, 0, 0, 0, 0, 1, 1, 0, 1, 1 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def can_partition(nums, k, max_sum_limit):\n \"\"\"\n Check if it's possible to partition the `nums` list into `k` or fewer subarrays \n without any subarray having ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000040071", "row_id": 40071, "seed_ids": "['922', '1151', '1961']" }
0.714954
Leetcode_40071
I
[ "can_partition", "minimize_max_partition_sum" ]
2
[ [ "minimize_max_partition_sum", "can_partition" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2d745cccbd2d2b02d5007adbbc6ffa2566890833
8e5f58536494c481ae6896d4fb30d885b9c9d4f3
v1.0
instruct
Leetcode
Leetcode_40101_I
You are given an array of integers `piles` where `piles[i]` is the number of stones in the `i-th` pile, and an integer `H` representing the number of hours you have to finish eating all the stones. Each hour, you can decide to eat any number of stones from a single pile. After each hour, one pile may be selected to eat...
def can_finish(piles, H, K): """ Helper function to determine if we can finish eating all piles with speed K in H hours. """ time = 0 for pile in piles: time += (pile + K - 1) // K # Equivalent to ceil(pile / K) return time <= H def min_eating_speed(piles, H): """ Returns the m...
from solution import min_eating_speed def test_min_eating_speed_single_pile(): assert min_eating_speed([30], 30) == 1 assert min_eating_speed([30], 1) == 30 def test_min_eating_speed_equal_piles(): assert min_eating_speed([3, 3, 3], 3) == 3 assert min_eating_speed([4, 4, 4, 4], 4) == 4 def test_min_e...
[ { "docstring": "Helper function to determine if we can finish eating all piles with speed K in H hours.", "function_declaration": "def can_finish(piles, H, K):", "function_name": "can_finish", "parameter_list": "(piles, H, K)" }, { "docstring": "Returns the minimum integer K such that it is ...
[ 0, 1, 1, 0, 0, 0, 1, 1, 1, 0 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def can_finish(piles, H, K):\n hours = 0\n for pile in piles:\n hours += (pile + K - 1) // K # equivalent to ceiling(pile / K)\n if hours > H:\n ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000040101", "row_id": 40101, "seed_ids": "['354', '213', '1258']" }
0.617115
Leetcode_40101
I
[ "can_finish", "min_eating_speed" ]
2
[ [ "min_eating_speed", "can_finish" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3deecff10404423827fb78feec957948e766dd3f
5eaed04ae0b3ba0fcd9d5b10e7b6adc5a17bdd64
v1.0
instruct
Leetcode
Leetcode_40172_I
You are given two integers `n` (length of an array) and `k` (a number of unique elements). Your task is to construct an array `arr` of length `n` such that it contains `k` different integers from `1` to `k`, and the sum of elements in `arr` is maximized. The integers in the array can repeat but should not be greater th...
def max_sum_array(n, k): """ Constructs an array arr of length n such that it contains k different integers from 1 to k, and the sum of elements in arr is maximized. Parameters: n (int): Length of the array. k (int): Number of unique elements from 1 to k. Returns: list: An arr...
from solution import max_sum, max_sum_array def test_max_sum_array_conditions(): assert max_sum_array(5, 3) == [3, 3, 3, 3, 3] assert max_sum_array(3, 10) == [10, 10, 10] assert max_sum_array(1, 5) == [5] assert max_sum_array(7, 2) == [2, 2, 2, 2, 2, 2, 2] def test_max_sum(): assert max_sum(5, 3) ...
[ { "docstring": "Constructs an array arr of length n such that it contains k different integers from 1 to k,\nand the sum of elements in arr is maximized. \n\nParameters:\nn (int): Length of the array.\nk (int): Number of unique elements from 1 to k.\n\nReturns:\nlist: An array arr that meets the criteria.", ...
[ 0, 0, 1, 1, 0, 0, 1, 1, 1, 1 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def maximize_sum(n, k):\n \"\"\"\n Constructs an array of length n with k unique integers (1 to k) such that the sum of the array is maximized.\n \n Parameters:\n...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000040172", "row_id": 40172, "seed_ids": "['1231', '319', '748']" }
0.747296
Leetcode_40172
I
[ "max_sum_array", "max_sum" ]
2
[ [ "max_sum", "max_sum_array" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a55e941f584994e418ba70c15bbe05bbc6b05581
2d7b8a809cff9cae99586b23b14262d6d445aa7f
v1.0
instruct
Leetcode
Leetcode_40225_I
Given a binary tree, return the level order traversal of its nodes' values. (i.e., from left to right, level by level). Each node has a unique value. Here's an example binary tree that is serialized as `[3,9,20,null,null,15,7]`. The level order traversal of this tree is `[3, 9, 20, 15, 7]`. The provided input will be...
from typing import List, Optional class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def build_tree_from_list(lst: List[Optional[int]]) -> Optional[TreeNode]: if not lst: return None root = TreeNode(lst[...
from solution import levelOrderTraversalFromList def test_example(): assert levelOrderTraversalFromList([3, 9, 20, None, None, 15, 7]) == [3, 9, 20, 15, 7] def test_empty(): assert levelOrderTraversalFromList([]) == [] def test_single_node(): assert levelOrderTraversalFromList([1]) == [1] def test_left_...
[]
[ 0, 0, 1, 0, 0, 0, 1, 1, 1, 1 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "from collections import deque\n\nclass TreeNode:\n def __init__(self, x):\n self.val = x\n self.left = None\n self.right = None\n\ndef levelOrderTrave...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000040225", "row_id": 40225, "seed_ids": "['1506', '46', '1671']" }
0.478752
Leetcode_40225
I
[ "build_tree_from_list", "levelOrderTraversal", "levelOrderTraversalFromList" ]
3
[ [ "levelOrderTraversalFromList", "build_tree_from_list" ], [ "levelOrderTraversalFromList", "levelOrderTraversal" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
59ae0a96222de04bfeecf519e63f264ec797688d
a9efd098f05bb4bacd65c52788797c18d2fd9461
v1.0
instruct
Leetcode
Leetcode_40244_I
Given a list of `n` points, where each point is represented as a tuple `(x, y)` on a 2D plane, find the shortest path that visits all the points. The order of visiting the points does not matter. Implement the function `minPath(points)`, where `points` is a list of tuples. The function should return the length of the s...
import itertools import math def euclidean_distance(p1, p2): """ Calculates the Euclidean distance between two 2D points p1 and p2. """ return math.sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2) def minPath(points): """ Calculates the length of the shortest path that visits all points s...
from solution import minPath def test_minPath_single_point(): points = [(0, 0)] assert minPath(points) == 0 def test_minPath_two_points(): points = [(0, 0), (1, 1)] assert math.isclose(minPath(points), 2 * math.sqrt(2), rel_tol=1e-9) def test_minPath_three_points(): points = [(0, 0), (1, 0), (0, ...
[ { "docstring": "Calculates the Euclidean distance between two 2D points p1 and p2.", "function_declaration": "def euclidean_distance(p1, p2):", "function_name": "euclidean_distance", "parameter_list": "(p1, p2)" }, { "docstring": "Calculates the length of the shortest path that visits all po...
[ 0, 0, 0, 0, 1, 0, 0, 0, 1, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "import itertools\nimport math\n\ndef euclidean_distance(p1, p2):\n \"\"\"\n Calculate the Euclidean distance between two points.\n \"\"\"\n return math.sqrt((p1[0...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000040244", "row_id": 40244, "seed_ids": "['352', '1027', '327']" }
0.609881
Leetcode_40244
I
[ "euclidean_distance", "minPath" ]
2
[ [ "minPath", "euclidean_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a7ae5615db5944b36d2e348d732c64f86a0777d4
206aec56cb2efcc4a312cb0cf59dcd14c346eba6
v1.0
instruct
Leetcode
Leetcode_40300_I
Given an array `arr` of integers and an integer `k`, rearrange the array such that the element at the `kth` position in the array is in its final sorted position. You must do this in-place with O(n) average time complexity. Return the modified array where the element at index `k` is at its correct position and all othe...
def partition(arr, low, high): pivot = arr[high] i = low - 1 for j in range(low, high): if arr[j] <= pivot: i += 1 arr[i], arr[j] = arr[j], arr[i] arr[i + 1], arr[high] = arr[high], arr[i + 1] return i + 1 def quick_select(arr, low, high, k): if low < high: ...
from solution import rearrange_around_k def test_rearrange_with_middle_element(): arr = [3, 2, 1, 5, 4] k = 2 result = rearrange_around_k(arr, k) assert result[k] == sorted(arr)[k] assert result == [2, 1, 3, 5, 4] or result == [1, 2, 3, 4, 5] or result == [1, 2, 3, 5, 4] def test_rearrange_with_fi...
[ { "docstring": null, "function_declaration": "def partition(arr, low, high):", "function_name": "partition", "parameter_list": "(arr, low, high)" }, { "docstring": null, "function_declaration": "def quick_select(arr, low, high, k):", "function_name": "quick_select", "parameter_li...
[ 1, 1, 0, 1, 1, 1, 1, 1, 0, 0 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def partition(arr, low, high):\n pivot = arr[high]\n i = low - 1\n for j in range(low, high):\n if arr[j] <= pivot:\n i += 1\n arr[i], a...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "0000040300", "row_id": 40300, "seed_ids": "['1539', '1714', '537']" }
0.610317
Leetcode_40300
I
[ "partition", "quick_select", "rearrange_around_k" ]
3
[ [ "quick_select", "partition" ], [ "rearrange_around_k", "quick_select" ] ]
2
[]
false
[]
false
pytest
true
[]
true
1575dfcb3338a9ff6107e6949e051b9aecf9e2b4
a8257127c6223662803cd9cd3b350b10d5fd1d1d
v1.0
instruct
Leetcode
Leetcode_40324_I
You are given a list of non-negative integers `nums` and an integer `k`. You are required to distribute all integers in `nums` into `k` subsets in such a way that the maximum sum of integers in any subset is minimized. Return the minimized maximum sum of integers among all `k` subsets.
def can_partition(nums, k, max_sum): # Helper function to determine if it's possible to divide nums into k or fewer subsets # where the sum of each subset is less than or equal to `max_sum` current_sum, count = 0, 1 for num in nums: if current_sum + num > max_sum: count += 1 ...
from solution import distribute def test_distribute_simple_case(): assert distribute([1, 2, 3, 4, 5], 2) == 9 # [1, 2, 3] and [4, 5] def test_distribute_single_element(): assert distribute([1], 1) == 1 assert distribute([1, 2, 3, 4], 1) == 10 def test_distribute_more_subsets_than_elements(): assert ...
[ { "docstring": null, "function_declaration": "def can_partition(nums, k, max_sum):", "function_name": "can_partition", "parameter_list": "(nums, k, max_sum)" }, { "docstring": "Distribute the integers in nums into k subsets such that the maximum sum of integers \nin any subset is minimized. ...
[ 0, 0, 0, 1, 0, 0, 0, 0, 1, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def can_partition(nums, k, mid):\n \"\"\"\n Helper function to check if it's possible to partition the array into k subsets\n with each subset having a sum less than...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "0000040324", "row_id": 40324, "seed_ids": "['2186', '64', '863']" }
0.64273
Leetcode_40324
I
[ "can_partition", "distribute" ]
2
[ [ "distribute", "can_partition" ] ]
1
[]
false
[]
false
pytest
true
[]
true
508821bc708a0e1e5ce9c82fede41ef5f94eee63
292def06cbd76b668fad4afa8b857e9930d0dab9
v1.0
instruct
Leetcode
Leetcode_40333_I
You are given a string `s` containing only lowercase alphabetical characters and an integer `k`. A substring is called a **k-repeated substring** if it contains at least `k` different characters and all these characters appear the same number of times in the substring. Return _the length of the **longest k-repeated sub...
def is_k_repeated_substring(substr, k): """ Check if the given substring contains at least k different characters and all characters appear the same number of times. """ from collections import Counter counter = Counter(substr) if len(counter) < k: return False occurrences = list...
from solution import is_k_repeated_substring, longest_k_repeated_substring def test_is_k_repeated_substring(): assert is_k_repeated_substring("aabb", 2) == True assert is_k_repeated_substring("aab", 2) == False assert is_k_repeated_substring("aa", 2) == False assert is_k_repeated_substring("aabbcc", 3)...
[ { "docstring": "Check if the given substring contains at least k different characters\nand all characters appear the same number of times.", "function_declaration": "def is_k_repeated_substring(substr, k):", "function_name": "is_k_repeated_substring", "parameter_list": "(substr, k)" }, { "do...
[ 0, 0, 1, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "from collections import Counter\n\ndef is_k_repeated_substring(substring, k):\n \"\"\"\n Check if substring contains at least k different characters and all these chara...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "0000040333", "row_id": 40333, "seed_ids": "['523', '1499', '409']" }
0.774936
Leetcode_40333
I
[ "is_k_repeated_substring", "longest_k_repeated_substring" ]
2
[ [ "longest_k_repeated_substring", "is_k_repeated_substring" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2cf56c26a20f247629d0a0cc0f2f1bc044fb5c2f
2f879cdcd2b77e1ce5650f333c8c7e2a80d37551
v1.0
instruct
Leetcode
Leetcode_40416_I
You are given a two-dimensional grid `grid` of size `m x n` consisting of `'0'`s (representing water) and `'1'`s (representing land). An island is a maximal group of connected lands connected horizontally or vertically but not diagonally. The grid's boundary is surrounded by water. Convert all islands that are entirely...
def is_island_surrounded(grid, i, j, m, n): """ Helper function to check if island starting at position (i,j) is surrounded by water. It uses Depth-First Search (DFS) traversal to mark all the land ('1's) part of this island. It will return False immediately if it finds '1' at the border. """ st...
from solution import convert_surrounded_islands def test_convert_surrounded_islands_example1(): grid = [ ['1','0','0','0','1'], ['0','1','1','0','0'], ['0','0','0','1','1'], ['0','0','0','0','0'], ['0','1','0','0','0'], ] expected = [ ['1','0','0','0','1'], ...
[ { "docstring": "Helper function to check if island starting at position (i,j) is surrounded by water.\nIt uses Depth-First Search (DFS) traversal to mark all the land ('1's) part of this island.\nIt will return False immediately if it finds '1' at the border.", "function_declaration": "def is_island_surroun...
[ 0, 0, 1, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def convert_surrounded_islands_to_water(grid):\n if not grid or not grid[0]:\n return grid\n\n m, n = len(grid), len(grid[0])\n\n def dfs(i, j):\n if i...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "0000040416", "row_id": 40416, "seed_ids": "['2375', '1119', '1625']" }
0.588295
Leetcode_40416
I
[ "is_island_surrounded", "convert_surrounded_islands" ]
2
[ [ "convert_surrounded_islands", "is_island_surrounded" ] ]
1
[]
false
[]
false
pytest
true
[]
true
31d80ab92d3d7761b253f0148388bea37d9b5c40
451546123833da4fd9c6ddbf46152837f355d660
v1.0
instruct
Leetcode
Leetcode_40554_I
You are given an integer `X` representing an initial value and integer arrays `A` and `B` of the same length. Arrays `A` and `B` represent pairs of values that can be used in operations to transform the value. For each pair `(A[i], B[i])`, you can choose to either add or subtract `A[i]` from `X`, and multiply the resul...
def can_transform_to_zero(X, A, B): """ Determines if it's possible to make X equal to 0 by applying operations with pairs from A and B. For each pair (A[i], B[i]), you can either add or subtract A[i] from X and multiply the result by B[i]. Args: X: Initial value. A: List of integers. ...
from solution import can_transform_to_zero def test_no_operations_needed(): assert can_transform_to_zero(0, [], []) == True def test_simple_case(): assert can_transform_to_zero(1, [1], [1]) == True assert can_transform_to_zero(1, [2], [1]) == False def test_two_operations(): assert can_transf...
[ { "docstring": "Determines if it's possible to make X equal to 0 by applying operations\nwith pairs from A and B.\n\nFor each pair (A[i], B[i]), you can either add or subtract A[i] from X and\nmultiply the result by B[i].\n\nArgs:\nX: Initial value.\nA: List of integers.\nB: List of integers.\n\nReturns:\nTrue ...
[ 0, 0, 1, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def can_transform_to_zero(X, A, B):\n \"\"\"\n This function determines if it is possible to make `X` equal to 0 after using \n all pairs in `A` and `B` arrays. For ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "0000040554", "row_id": 40554, "seed_ids": "['2126', '1172', '1519']" }
0.664153
Leetcode_40554
I
[ "can_transform_to_zero", "_can_transform_helper" ]
2
[ [ "can_transform_to_zero", "_can_transform_helper" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c58aabb6bed74a72adfed69eaaad1297b78ecebe
86aa0933ea3b19312cc54b18e66cdbff51da9409
v1.0
instruct
Leetcode
Leetcode_40611_I
You are given an integer array `arr` of length `n` where `1 <= n <= 10^5` and `1 <= arr[i] <= 10^9`. You can perform the following operation at most `k` times where `k` is a given positive integer: - Select any element in the array and replace it with any positive integer. Your objective is to make the array strictly ...
def min_operations_to_make_strictly_increasing(arr, k): n = len(arr) # Find the longest increasing subsequence (LIS) length in arr. lis_len = lis_length(arr) # Calculate the minimum number of operations needed min_operations = n - lis_len # If the minimum number of operations needed is less th...
from solution import min_operations_to_make_strictly_increasing def test_case_1(): arr = [1, 2, 5, 3, 4] k = 1 assert min_operations_to_make_strictly_increasing(arr, k) == 1 def test_case_2(): arr = [1, 3, 2, 1, 5, 6] k = 2 assert min_operations_to_make_strictly_increasing(arr, k) == 2 def te...
[ { "docstring": null, "function_declaration": "def min_operations_to_make_strictly_increasing(arr, k):", "function_name": "min_operations_to_make_strictly_increasing", "parameter_list": "(arr, k)" }, { "docstring": null, "function_declaration": "def lis_length(arr):", "function_name":...
[ 0, 0, 0, 0, 1, 0, 0, 1, 0 ]
2
hard
0.222
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_1_results_combined.jsonl", "solution_code": "def min_operations_to_make_increasing(arr, k):\n \"\"\"\n Returns the minimum number of operations required to make the array strictly increasi...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "0000040611", "row_id": 40611, "seed_ids": "['1896', '664', '1737']" }
0.770155
Leetcode_40611
I
[ "min_operations_to_make_strictly_increasing", "lis_length" ]
2
[ [ "min_operations_to_make_strictly_increasing", "lis_length" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1e3b753eb54f880ab421a6f604ed9efeac97e3b1
326dd386b9f247d89faec342477ae696ce162fac
v1.0
instruct
Leetcode
Leetcode_40801_I
You are given a `matrix` of integers with `rows` and `columns`, where `matrix[i][j]` represents the value at the `i-th` row and `j-th` column. A **magic submatrix** is a square submatrix of size `k x k` (where `k > 1`) in which all the elements have the same sum for each of their rows, columns, and diagonals. Return _t...
def check_magic(matrix, row, col, k): """ Checks if the submatrix of size k x k starting at (row, col) is magic. """ sums = [] # Check rows and columns sums for i in range(k): sums.append(sum(matrix[row + i][col:col + k])) sums.append(sum(matrix[row + j][col + i] for j in range(k...
from solution import largest_magic_submatrix def test_single_element_submatrices(): assert largest_magic_submatrix([[1]]) == 0 def test_2_by_2_non_magic(): assert largest_magic_submatrix([[1, 2], [3, 4]]) == 0 def test_2_by_2_magic(): assert largest_magic_submatrix([[2, 2], [2, 2]]) == 2 def test_3_by_3...
[ { "docstring": "Checks if the submatrix of size k x k starting at (row, col) is magic.", "function_declaration": "def check_magic(matrix, row, col, k):", "function_name": "check_magic", "parameter_list": "(matrix, row, col, k)" }, { "docstring": "Returns the size k of the largest magic subma...
[ 0, 0, 0, 0, 0, 0, 1, 1, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_magic(submatrix):\n # Check if all the rows, columns and diagonals have the same sum\n size = len(submatrix)\n magic_sum = sum(submatrix[0])\n\n # Check al...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "0000040801", "row_id": 40801, "seed_ids": "['2489', '2548', '2508']" }
0.612864
Leetcode_40801
I
[ "check_magic", "largest_magic_submatrix" ]
2
[ [ "largest_magic_submatrix", "check_magic" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a36a022eb88cd417e4c35065b97f1fd9ec8d4db2
1e3a795e16255e8ddf7c70f139e73d94314acaf5
v1.0
instruct
Leetcode
Leetcode_40864_I
Implement a function `string mergeSort(string s)` that sorts the characters in the input string `s` using the merge sort algorithm. Merge sort is a divide-and-conquer algorithm that works as follows: 1. Divide the unsorted string into `n` partitions, each containing one character (an array of one character is considere...
def merge_sort(s): if len(s) <= 1: return s # Divide the string into two halves mid = len(s) // 2 left_half = merge_sort(s[:mid]) right_half = merge_sort(s[mid:]) # Conquer by merging the sorted halves return merge(left_half, right_half) def merge(left, right): sorted_...
from solution import merge_sort def test_merge_sort_simple_case(): assert merge_sort("dcba") == "abcd" def test_merge_sort_with_duplicates(): assert merge_sort("apple") == "aelpp" def test_merge_sort_already_sorted(): assert merge_sort("abc") == "abc" def test_merge_sort_reverse_sorted(): assert mer...
[ { "docstring": null, "function_declaration": "def merge_sort(s):", "function_name": "merge_sort", "parameter_list": "(s)" }, { "docstring": null, "function_declaration": "def merge(left, right):", "function_name": "merge", "parameter_list": "(left, right)" } ]
[ 0, 0, 1, 0, 1, 1, 1, 1, 0, 1 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def mergeSort(s):\n if len(s) <= 1:\n return s\n \n def merge(left, right):\n result = []\n i = j = 0\n \n while i < len(left) and...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000040864", "row_id": 40864, "seed_ids": "['1887', '288', '712']" }
0.651438
Leetcode_40864
I
[ "merge_sort", "merge" ]
2
[ [ "merge_sort", "merge" ] ]
1
[]
false
[]
false
pytest
true
[]
true
665a416aef3d08eadb6943f97267020ad1bdf3f0
805a288b3b8fa3dff3d4341cca67e6a54beedbac
v1.0
instruct
Leetcode
Leetcode_40870_I
Given an array of integers `arr`, return the number of **distinct pairs** `(i, j)` such that `arr[i] + arr[j]` is a perfect square, where `0 <= i < j < arr.length`. A **perfect square** is an integer that is the square of an integer, e.g., `1, 4, 9, 16`.
from itertools import combinations import math def is_perfect_square(num): """ Check if the given number is a perfect square. """ if num < 0: return False sqrt = int(math.sqrt(num)) return sqrt * sqrt == num def count_perfect_square_pairs(arr): """ Returns the number of distinc...
from solution import count_perfect_square_pairs def test_example_case(): arr = [1, 3, 6, 2, 7] assert count_perfect_square_pairs(arr) == 3 def test_no_pairs(): arr = [2, 3, 8, 11] assert count_perfect_square_pairs(arr) == 0 def test_all_elements_zero(): arr = [0, 0, 0, 0] assert count_perfect...
[ { "docstring": "Check if the given number is a perfect square.", "function_declaration": "def is_perfect_square(num):", "function_name": "is_perfect_square", "parameter_list": "(num)" }, { "docstring": "Returns the number of distinct pairs (i, j) such that\narr[i] + arr[j] is a perfect squar...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
1
hard
0.111
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "import math\n\ndef count_perfect_square_pairs(arr):\n \"\"\"\n Returns the number of distinct pairs (i, j) such that arr[i] + arr[j] is a perfect square.\n \"\"\"\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000040870", "row_id": 40870, "seed_ids": "['1100', '1088', '2031']" }
0.697157
Leetcode_40870
I
[ "is_perfect_square", "count_perfect_square_pairs" ]
2
[ [ "count_perfect_square_pairs", "is_perfect_square" ] ]
1
[]
false
[]
false
pytest
true
[]
true
bdce996a0a5137f0fabec650232e23f60367615c
2fa92ace733cdc1efc0e651683079bbf912ee4b5
v1.0
instruct
Leetcode
Leetcode_40936_I
Given an integer array `arr`, your task is to arrange the digits of the numbers to form the smallest possible number. The smallest number should be returned as a string to handle large numeric values. For example, given the input array `arr = [50, 2, 1, 9]`, the output should be "12509" as arranging these digits gives...
import functools def compare_digits(x, y): if x + y < y + x: return -1 else: return 1 def smallest_number(arr): """ Given an integer array `arr`, arranges the digits to form the smallest possible number. """ str_arr = list(map(str, arr)) str_arr.sort(key=functools.cmp_to_ke...
from solution import smallest_number def test_example_case(): assert smallest_number([50, 2, 1, 9]) == "12509" def test_all_single_digit_numbers(): assert smallest_number([5, 3, 2, 1, 9, 7, 8, 6, 4, 0]) == "0123456789" def test_mixed_length_numbers(): assert smallest_number([13, 32, 321]) == "1332132" ...
[ { "docstring": null, "function_declaration": "def compare_digits(x, y):", "function_name": "compare_digits", "parameter_list": "(x, y)" }, { "docstring": "Given an integer array `arr`, arranges the digits to form the smallest possible number.", "function_declaration": "def smallest_numbe...
[ 1, 1, 0, 1, 0, 0, 0, 0, 1, 0 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "from functools import cmp_to_key\n\ndef smallest_number(arr):\n \"\"\"\n Given an integer array arr, returns the smallest possible number by\n rearranging the digits...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000040936", "row_id": 40936, "seed_ids": "['1696', '958', '1213']" }
0.644812
Leetcode_40936
I
[ "compare_digits", "smallest_number" ]
2
[ [ "smallest_number", "compare_digits" ] ]
1
[]
false
[]
false
pytest
true
[]
true
02bc0f02ed3113368cc925bf3cc08dac475b6a83
7336af5f40cc3e2fc0220baed163b059200ad4bf
v1.0
instruct
Leetcode
Leetcode_41057_I
You are given a list of strings `words`, where each string is a word consisting of lowercase English letters only. Your task is to determine if there exists a pair of words `(word1, word2)` from the list, such that `word1 + word2` (concatenation of `word1` and `word2`) is a palindrome. A palindrome is a string that rea...
def is_palindrome(s): """ Helper function to check if a string is a palindrome. """ return s == s[::-1] def palindrome_pair(words): """ Function to determine if there exists a pair of words in the input list such that their concatenation is a palindrome. """ word_set = set(words) ...
from solution import palindrome_pair def test_palindrome_pair_true(): assert palindrome_pair(["bat", "tab", "cat"]) == True assert palindrome_pair(["abc", "cba", "xyz"]) == True assert palindrome_pair(["race", "car"]) == True def test_palindrome_pair_false(): assert palindrome_pair(["abc", "def", "ghi...
[ { "docstring": "Helper function to check if a string is a palindrome.", "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": "Function to determine if there exists a pair of words in the input list\nsuch that their conca...
[ 1, 0, 1, 1, 0, 1, 1, 0, 1, 1 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_palindrome(s):\n return s == s[::-1]\n\ndef check_palindrome_pair(words):\n \"\"\"\n This function checks if there exists a pair of words (word1, word2) such ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000041057", "row_id": 41057, "seed_ids": "['2019', '549', '642']" }
0.773276
Leetcode_41057
I
[ "is_palindrome", "palindrome_pair" ]
2
[ [ "palindrome_pair", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8977d72c129d5f7b6f2e3a16a9e61431d52aa0f9
06bbe0d997b573bfcd4103f82d5af5acb0057633
v1.0
instruct
Leetcode
Leetcode_41091_I
Given a string `s`, return _the length of the shortest palindromic subsequence that can be formed by adding at most one character to_ `s`. If the string is already a palindrome, return its length.
def is_palindrome(s): return s == s[::-1] def shortest_palindromic_subsequence_length(s): """ Returns the length of the shortest palindromic subsequence that can be formed by adding at most one character to s. If the string is already a palindrome, return its length. """ if is_palindrome(s): ...
from solution import shortest_palindromic_subsequence_length def test_already_palindrome(): assert shortest_palindromic_subsequence_length("racecar") == 7 assert shortest_palindromic_subsequence_length("madam") == 5 def test_one_addition_needed(): assert shortest_palindromic_subsequence_length("raceca") =...
[ { "docstring": null, "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": "Returns the length of the shortest palindromic subsequence that can be formed by adding at most one character to s.\nIf the string is already a p...
[ 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 is_palindrome(s):\n return s == s[::-1]\n\ndef shortest_palindromic_subsequence_length(s):\n if is_palindrome(s):\n return len(s)\n \n # Check if by ad...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "0000041091", "row_id": 41091, "seed_ids": "['1062', '395', '1509']" }
0.755313
Leetcode_41091
I
[ "is_palindrome", "shortest_palindromic_subsequence_length" ]
2
[ [ "shortest_palindromic_subsequence_length", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
76b1e80ad6896e3ce33679fe54b9e64129a22d2d
1b1720e32436dd6abdf381c9e171d347dc416405
v1.0
instruct
Leetcode
Leetcode_41556_I
Given two integers `m` and `n`, where `1 <= m <= n`, return _the sum of all prime numbers between_ `m` _and_ `n` _inclusive_. If there are no prime numbers in the given range, return `0`.
def is_prime(num): """ Check if a number is prime. """ if num < 2: return False for i in range(2, int(num**0.5) + 1): if num % i == 0: return False return True def sum_of_primes(m, n): """ Returns the sum of all prime numbers between m and n inclusive. ""...
from solution import sum_of_primes def test_sum_of_primes_within_range(): assert sum_of_primes(1, 10) == 17 # primes are 2, 3, 5, 7 def test_sum_of_primes_single_prime(): assert sum_of_primes(3, 3) == 3 # only 3 is prime def test_sum_of_primes_no_primes(): assert sum_of_primes(1, 1) == 0 # no primes i...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns the sum of all prime numbers between m and n inclusive.", "function_declaration": "def sum_of_primes(m, n):", ...
[ 0, 0, 0, 0, 0, 1, 0, 1, 1, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num == 2:\n return True\n if num % 2 == ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000041556", "row_id": 41556, "seed_ids": "['1314', '637', '795']" }
0.616256
Leetcode_41556
I
[ "is_prime", "sum_of_primes" ]
2
[ [ "sum_of_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7706a9d79b7a8b49b23721ba315815a2c30b0a51
bd6f6e821a5fc71b15608f0d0cae600a7b144510
v1.0
instruct
Leetcode
Leetcode_41593_I
You are given an array `nums` consisting of non-negative integers. The function `transform(arr)` is defined as follows: It takes an array of integers as input and returns an array where `arr[i]` is replaced with the **sum of all distinct** integers in the input array excluding `arr[i]`. For example, given the input ar...
def transform(nums): """ Transforms the input array such that each element is replaced by the sum of all distinct integers except for the element at the current position. """ total_sum = sum(set(nums)) return [total_sum - num for num in nums] def simulate_transform(nums, k): """ Simula...
from solution import transform, simulate_transform def test_transform_single_element(): assert transform([1]) == [0] def test_transform_two_elements(): assert transform([1, 2]) == [2, 1] def test_transform_distinct_elements(): assert transform([1, 2, 3]) == [5, 4, 3] assert transform([4, 5, 6]) =...
[ { "docstring": "Transforms the input array such that each element is replaced by the sum of all distinct integers \nexcept for the element at the current position.", "function_declaration": "def transform(nums):", "function_name": "transform", "parameter_list": "(nums)" }, { "docstring": "Si...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def transform(nums):\n \"\"\"\n Transform the input array such that each element at index i is replaced\n with the sum of all distinct integers in the input array ex...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000041593", "row_id": 41593, "seed_ids": "['2211', '638', '850']" }
0.635356
Leetcode_41593
I
[ "transform", "simulate_transform" ]
2
[ [ "simulate_transform", "transform" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0ae1d90f8b971b8d76562bf189ea09c1bf7ef811
f568accd722d347b7f36eef9535eec5dfb0ee7fe
v1.0
instruct
Leetcode
Leetcode_41631_I
You are given a binary tree in which each node contains a value. Design an algorithm to find the minimum value node that is a common ancestor of two given nodes `p` and `q`. The value of each node is unique and `p` and `q` refer to the values of the nodes you need to find the common ancestor for. A common ancestor is a...
class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None def find_lca(root, p, q): """ Function to find the minimum value node that is a common ancestor of nodes p and q. """ if root is None: return None # If either p or q m...
from solution import TreeNode, min_common_ancestor def create_sample_tree(): # Creating a sample tree: # 5 # / \ # 3 8 # / \ \ # 2 4 9 root = TreeNode(5) root.left = TreeNode(3) root.right = TreeNode(8) root.left.left = TreeNode(2) root....
[]
[ 1, 0, 1, 0, 0, 0, 0, 1, 0 ]
3
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, value=0, left=None, right=None):\n self.value = value\n self.left = left\n self.right = right\n\ndef find_min_com...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000041631", "row_id": 41631, "seed_ids": "['2537', '997', '920']" }
0.572046
Leetcode_41631
I
[ "find_lca", "min_common_ancestor" ]
2
[ [ "min_common_ancestor", "find_lca" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
29a81821a461706dc072276c52ebb52eab1ae300
b85d61e00630cccf5851a23e12cd8ea4c248e50e
v1.0
instruct
Leetcode
Leetcode_41947_I
You are given an array of integers `nums` representing a permutation of numbers from `1` to `n`. You need to build a binary tree by inserting the elements of the array in the given order. After constructing the binary tree, return the level-order traversal of the tree as a 2D array, where each inner array represents a ...
class TreeNode: def __init__(self, value=0, left=None, right=None): self.value = value self.left = left self.right = right def insert_node(root, value): if not root: return TreeNode(value) if value < root.value: root.left = insert_node(root.left, value) else: ...
from solution import level_order def test_level_order_single_element(): assert level_order([1]) == [[1]] def test_level_order_two_elements(): assert level_order([2, 1]) == [[2], [1]] assert level_order([1, 2]) == [[1], [2]] def test_level_order_multiple_elements(): assert level_order([3, 1, 2, 4, 5])...
[]
[ 1, 1, 1, 0, 1, 0, 1, 0, 1, 0 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "from collections import deque\n\nclass TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000041947", "row_id": 41947, "seed_ids": "['455', '2509', '515']" }
0.555179
Leetcode_41947
I
[ "insert_node", "build_tree", "level_order_traversal", "level_order" ]
4
[ [ "build_tree", "insert_node" ], [ "level_order", "build_tree" ], [ "level_order", "level_order_traversal" ] ]
3
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
53d8d077bc2d8db62b96980484aa2dbe8bc5ad1d
18eeba5eeeea398ea09e12763f2270b400f9a517
v1.0
instruct
Leetcode
Leetcode_41956_I
You are given an integer array `nums` and an integer `target`. You need to find all **unique pairs** `(nums[i], nums[j])` such that their sum is equal to `target`, and `i` is not equal to `j`. A pair `(nums[i], nums[j])` is considered unique if there are no other pairs with the same elements, even if the order is diffe...
def find_unique_pairs(nums, target): """ Finds all unique pairs in nums that sum up to the target. """ nums.sort() seen = set() pairs = set() for num in nums: complement = target - num if complement in seen: pair = (min(num, complement), max(num, complement))...
from solution import find_pairs_and_scaling_factor def test_find_pairs_and_scaling_factor_no_pairs(): result = find_pairs_and_scaling_factor([1, 2, 3], 7, 3) assert result == ([], 1) def test_find_pairs_and_scaling_factor_single_pair(): result = find_pairs_and_scaling_factor([1, 2, 3, 4], 5, 3) assert...
[ { "docstring": "Finds all unique pairs in nums that sum up to the target.", "function_declaration": "def find_unique_pairs(nums, target):", "function_name": "find_unique_pairs", "parameter_list": "(nums, target)" }, { "docstring": "Determines the scaling factor required to fit all the pairs ...
[ 0, 0, 0, 0, 0, 0, 0, 1, 0, 1 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "from typing import List, Tuple\n\ndef find_unique_pairs(nums: List[int], target: int) -> List[Tuple[int, int]]:\n # Use a set to track unique pairs and seen numbers\n p...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000041956", "row_id": 41956, "seed_ids": "['2445', '909', '495']" }
0.678953
Leetcode_41956
I
[ "find_unique_pairs", "determine_scaling_factor", "find_pairs_and_scaling_factor" ]
3
[ [ "find_pairs_and_scaling_factor", "determine_scaling_factor" ], [ "find_pairs_and_scaling_factor", "find_unique_pairs" ] ]
2
[]
false
[]
false
pytest
true
[]
true
74dc33f3b474f858b7893b944abebda79bc09d78
031b09edb76291b4bc40437868ce11829277601f
v1.0
instruct
Leetcode
Leetcode_42004_I
You are given a 2D grid `grid` of size `m x n` where each cell represents a different block of land or water. The grid has '1's (land) and '0's (water). A block of land is considered a secluded island if all the land blocks are completely surrounded by water and there are no adjacent land blocks connected vertically or...
def is_secluded(grid, x, y): """Helper function to determine if a position (x, y) in the grid is a secluded island.""" m, n = len(grid), len(grid[0]) for dx, dy in [(-1, 0), (1, 0), (0, -1), (0, 1)]: nx, ny = x + dx, y + dy if 0 <= nx < m and 0 <= ny < n and grid[nx][ny] == '1': ...
from solution import count_secluded_islands def test_no_secluded_islands(): grid = [ ['0', '0', '0', '0'], ['0', '1', '1', '0'], ['0', '1', '1', '0'], ['0', '0', '0', '0'] ] assert count_secluded_islands(grid) == 0 def test_one_secluded_island(): grid = [ ['0', ...
[ { "docstring": "Helper function to determine if a position (x, y) in the grid is a secluded island.", "function_declaration": "def is_secluded(grid, x, y):", "function_name": "is_secluded", "parameter_list": "(grid, x, y)" }, { "docstring": "Returns the number of secluded islands in the give...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def num_secluded_islands(grid):\n m, n = len(grid), len(grid[0])\n isolated_islands = 0\n \n def is_isolated(i, j):\n if i < 0 or i >= m or j < 0 or j >= n...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000042004", "row_id": 42004, "seed_ids": "['1762', '1790', '2411']" }
0.602653
Leetcode_42004
I
[ "is_secluded", "count_secluded_islands" ]
2
[ [ "count_secluded_islands", "is_secluded" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9d706f984a981f05428b6b0744376be45959c054
2100f9452c7d50972f5be1176a2959a0fc51c889
v1.0
instruct
Leetcode
Leetcode_42019_I
You are given an integer array `nums` of length `n` which may contain both positive and negative integers. Your task is to modify the array by applying the following transformation rules exactly once. The transformation rules are: - If the number is positive, replace it with the sum of its digits. - If the number is ne...
def sum_of_digits(n): """ Return the sum of the digits of a positive number n. """ return sum(int(digit) for digit in str(n)) def product_of_digits(n): """ Return the product of the digits of a positive number n. """ product = 1 for digit in str(n): product *= int(digit) ...
from solution import transform def test_transform_positive_numbers(): assert transform([12, 34]) == [3, 7] # 1+2 = 3, 3+4 = 7 def test_transform_negative_numbers(): assert transform([-23, -45]) == [6, 20] # 2*3 = 6, 4*5 = 20 def test_transform_zero(): assert transform([0, 0]) == [0, 0] def test_transf...
[ { "docstring": "Return the sum of the digits of a positive number n.", "function_declaration": "def sum_of_digits(n):", "function_name": "sum_of_digits", "parameter_list": "(n)" }, { "docstring": "Return the product of the digits of a positive number n.", "function_declaration": "def pro...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def transform_array(nums):\n def sum_of_digits(num):\n return sum(int(digit) for digit in str(num))\n\n def product_of_digits(num):\n product = 1\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000042019", "row_id": 42019, "seed_ids": "['1652', '1566', '388']" }
0.674472
Leetcode_42019
I
[ "sum_of_digits", "product_of_digits", "transform" ]
3
[ [ "transform", "product_of_digits" ], [ "transform", "sum_of_digits" ] ]
2
[]
false
[]
false
pytest
true
[]
true
283cd38a1fb6b8ba17a780661118e897374d4457
3ac2726254324cb4936b9a31dac17073bdfbbe1a
v1.0
instruct
Leetcode
Leetcode_42021_I
Given a string `s` and an integer `k`, you need to construct a new string by rearranging the characters of the string such that no two adjacent characters are the same. If it is not possible to construct such a string, return an empty string `""`. You are only allowed to rearrange the characters if it can be done using...
from collections import Counter import heapq def reorganize_string(s, k): if k == 0: return s if can_rearrange(s) else "" length = len(s) char_count = Counter(s) max_heap = [(-count, char) for char, count in char_count.items()] heapq.heapify(max_heap) if any(-count > (length + 1) // 2...
from solution import reorganize_string def test_reorganize_with_possible_k_swaps(): assert reorganize_string("aabbcc", 2) != "" # Can be rearranged, not validating specific arrangements assert reorganize_string("aaabbc", 2) != "" # Can be rearranged, not validating specific arrangements def test_reorganize_...
[ { "docstring": null, "function_declaration": "def reorganize_string(s, k):", "function_name": "reorganize_string", "parameter_list": "(s, k)" }, { "docstring": null, "function_declaration": "def can_rearrange(s):", "function_name": "can_rearrange", "parameter_list": "(s)" } ]
[ 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 heapq import heappop, heappush\nfrom collections import Counter\n\ndef rearrange_string(s, k):\n if k == 0:\n return s\n\n counter = Counter(s)\n max_hea...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "0000042021", "row_id": 42021, "seed_ids": "['422', '1707', '2123']" }
0.705945
Leetcode_42021
I
[ "reorganize_string", "can_rearrange" ]
2
[ [ "reorganize_string", "can_rearrange" ] ]
1
[]
false
[]
false
pytest
true
[]
true
494d42e0711dc97b3b21d266d857d45ff3997e9f
61ab1cb282f57cfabda5efa31ba5f000637840ff
v1.0
instruct
Leetcode
Leetcode_42033_I
You are given a list of strings `words` and an input string `s`. Your task is to determine the length of the longest subsequence in the list of strings `words` that can be formed by deleting some (or no) characters from the input string `s` so that the ordering of characters in the input string is preserved. Two string...
def is_subsequence(s, word): """ Helper function to check if 'word' is a subsequence of 's'. """ it = iter(s) return all(char in it for char in word) def longest_subsequence_length(words, s): """ Returns the length of the longest subsequence from words that can be formed by deleting so...
from solution import longest_subsequence_length def test_longest_subsequence_length_all_subsequences(): assert longest_subsequence_length(["a", "b", "c"], "abc") == 1 def test_longest_subsequence_length_empty_words(): assert longest_subsequence_length([], "abc") == 0 def test_longest_subsequence_length_singl...
[ { "docstring": "Helper function to check if 'word' is a subsequence of 's'.", "function_declaration": "def is_subsequence(s, word):", "function_name": "is_subsequence", "parameter_list": "(s, word)" }, { "docstring": "Returns the length of the longest subsequence from words that can be \nfor...
[ 0, 0, 0, 0, 0, 1, 1, 1, 0, 1 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_subsequence(word, s):\n \"\"\"\n Check if 'word' is subsequence of 's'\n \"\"\"\n it = iter(s)\n return all(char in it for char in word)\n\ndef longest_...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000042033", "row_id": 42033, "seed_ids": "['1710', '2593', '742']" }
0.70387
Leetcode_42033
I
[ "is_subsequence", "longest_subsequence_length" ]
2
[ [ "longest_subsequence_length", "is_subsequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9eedf447ed8b1baf99882c6ea6d453297a81d285
ff132232cc2398dbc91a901b0992a3b32fecb94e
v1.0
instruct
Leetcode
Leetcode_42125_I
You are given a list of strings `textQuoteStore` containing short quotes from various books and a string `quote` representing the text of a new quote. Your task is to determine if the new quote is a *subsequence* of any of the existing quotes in `textQuoteStore`. A `subsequence` is a sequence that can be derived from a...
def is_subsequence(s, t): """ Helper function to determine if the string s is a subsequence of t. """ iter_t = iter(t) return all(char in iter_t for char in s) def subsequence_indexes(textQuoteStore, quote): """ Returns a list of indexes of the quotes in textQuoteStore where 'quote' is a su...
from solution import subsequence_indexes def test_basic(): textQuoteStore = ["hello world", "herb", "hhooo"] quote = "ho" assert subsequence_indexes(textQuoteStore, quote) == [0, 2] def test_no_match(): textQuoteStore = ["abc", "def", "ghi"] quote = "z" assert subsequence_indexes(textQuoteStor...
[ { "docstring": "Helper function to determine if the string s is a subsequence of t.", "function_declaration": "def is_subsequence(s, t):", "function_name": "is_subsequence", "parameter_list": "(s, t)" }, { "docstring": "Returns a list of indexes of the quotes in textQuoteStore where 'quote' ...
[ 0, 0, 0, 0, 1, 1, 1, 1, 1, 1 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_subsequence(quote, text):\n \"\"\"Helper function that checks if `quote` is a subsequence of `text`.\"\"\"\n it = iter(text)\n return all(c in it for c in quo...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000042125", "row_id": 42125, "seed_ids": "['1942', '1104', '657']" }
0.666172
Leetcode_42125
I
[ "is_subsequence", "subsequence_indexes" ]
2
[ [ "subsequence_indexes", "is_subsequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3442e01bb2f2fb30232f9488f22d40eaa1375861
ebdae85ea5719205b9a83cde08d2917b4f346aba
v1.0
instruct
Leetcode
Leetcode_42257_I
Given two integers `n` and `m`, you have to find all possible unique binary trees with `n` nodes that can be formed such that the sum of the values of the nodes in the tree is equal to `m`. Return _a list of such possible binary trees_, where each tree is represented by its root node. Each node is represented as a valu...
from typing import List, Optional class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def find_trees(n, m, start=1): if n == 0 and m == 0: return [None] if n <= 0 or m <= 0: return [] trees = [] ...
from solution import binary_trees_with_sum from solution import TreeNode def test_single_node(): result = binary_trees_with_sum(1, 1) assert len(result) == 1 assert result[0].val == 1 assert result[0].left == None assert result[0].right == None def test_two_nodes(): result = binary_trees_with_...
[]
[ 0, 0, 0, 1, 0, 0, 0, 1, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "from typing import List, Optional\n\nclass TreeNode:\n def __init__(self, val: int, left: Optional['TreeNode'] = None, right: Optional['TreeNode'] = None):\n self.v...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "0000042257", "row_id": 42257, "seed_ids": "['32', '1487', '609']" }
0.558174
Leetcode_42257
I
[ "find_trees", "binary_trees_with_sum" ]
2
[ [ "binary_trees_with_sum", "find_trees" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
fa206a6dd2c8e64b337b368f206e5ef68bd93b74
8ef1073aef9f9e9ecd8434af4c351a58045f9511
v1.0
instruct
Leetcode
Leetcode_42311_I
You are given an integer array `projects` where `projects[i]` represents the time required to complete the `i`-th project. You are also given an integer `k` representing the number of workers available. Each worker can be assigned to any project, but each project must be completed by one worker. Your goal is to minimiz...
def is_valid(workloads, k, max_workload): current_sum = 0 workers_needed = 1 for workload in workloads: if current_sum + workload > max_workload: workers_needed += 1 current_sum = workload if workers_needed > k: return False else: ...
from solution import minimize_maximum_time def test_case_1(): projects = [10, 20, 30] k = 2 assert minimize_maximum_time(projects, k) == 30 def test_case_2(): projects = [10, 5, 10] k = 2 assert minimize_maximum_time(projects, k) == 15 def test_case_3(): projects = [7, 2, 5, 10, 8] k ...
[ { "docstring": null, "function_declaration": "def is_valid(workloads, k, max_workload):", "function_name": "is_valid", "parameter_list": "(workloads, k, max_workload)" }, { "docstring": null, "function_declaration": "def minimize_maximum_time(projects, k):", "function_name": "minimiz...
[ 0, 1, 0, 1, 0, 0, 0, 0, 0 ]
2
hard
0.222
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def canComplete(projects, k, mid):\n workers = [0] * k\n \n for time in projects:\n if time > mid:\n return False\n min_worker = workers.ind...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "0000042311", "row_id": 42311, "seed_ids": "['1598', '517', '392']" }
0.706453
Leetcode_42311
I
[ "is_valid", "minimize_maximum_time" ]
2
[ [ "minimize_maximum_time", "is_valid" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c56b257ab5c131d94f474514651f660ab396661e
a1da3aa9e0075b0a759324e3a55948f086784506
v1.0
instruct
Leetcode
Leetcode_42340_I
Given an array of integers `arr` and an integer `k`, return the _k_ closest integers to the median of `arr`. **Note**: If there is a tie, return the smaller integers first. The median is computed as follows: 1. If the array length is odd, the median is the middle element after sorting the array. 2. If the array length...
def find_median(arr): arr_sorted = sorted(arr) n = len(arr) if n % 2 == 1: return float(arr_sorted[n // 2]) else: return (arr_sorted[n // 2 - 1] + arr_sorted[n // 2]) / 2.0 def k_closest_to_median(arr, k): median = find_median(arr) arr_sorted = sorted(arr, key=lambda x: (ab...
from solution import find_median, k_closest_to_median def test_find_median_odd_length(): assert find_median([1, 2, 3]) == 2.0 assert find_median([3, 1, 2]) == 2.0 def test_find_median_even_length(): assert find_median([1, 2, 3, 4]) == 2.5 assert find_median([4, 3, 2, 1]) == 2.5 def test_find_median_s...
[ { "docstring": null, "function_declaration": "def find_median(arr):", "function_name": "find_median", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "def k_closest_to_median(arr, k):", "function_name": "k_closest_to_median", "parameter_list": "(arr, k)"...
[ 0, 1, 0, 0, 0, 0, 0, 0, 0, 1 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def find_median(arr):\n \"\"\"\n Finds the median of the array.\n \"\"\"\n arr.sort()\n length = len(arr)\n \n if length % 2 == 1:\n return arr[le...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000042340", "row_id": 42340, "seed_ids": "['2351', '905', '75']" }
0.826349
Leetcode_42340
I
[ "find_median", "k_closest_to_median" ]
2
[ [ "k_closest_to_median", "find_median" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8ed87d28e83d699f761e258da64a7526abbbc234
0932aa305e4408bfc18d12022168c07d70d1bdc0
v1.0
instruct
Leetcode
Leetcode_42648_I
You are given an `n x n` integer matrix `mat`. You need to determine if there is a **magic square** of size `3 x 3` anywhere in the matrix. A **magic square** is a `3 x 3` grid filled with distinct integers from 1 to 9 such that each row, each column, and both diagonals all have the same sum. You should determine if th...
def is_magic_square(submatrix): s = 15 # Sum of each row/column/diagonal in a 3x3 magic square of 1-9 return ( sum(submatrix[0]) == s and sum(submatrix[1]) == s and sum(submatrix[2]) == s and sum(submatrix[i][0] for i in range(3)) == s and sum(submatrix[i][1] for i in ra...
from solution import contains_magic_square def test_no_magic_square(): matrix = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] assert contains_magic_square(matrix) == False def test_one_magic_square(): matrix = [ [4, 9, 2], [3, 5, 7], [8, 1, 6] ] assert con...
[ { "docstring": null, "function_declaration": "def is_magic_square(submatrix):", "function_name": "is_magic_square", "parameter_list": "(submatrix)" }, { "docstring": null, "function_declaration": "def contains_magic_square(matrix):", "function_name": "contains_magic_square", "par...
[ 0, 0, 1, 0, 0, 0, 1, 1, 1, 0 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_magic_square(grid):\n # Check if the 3x3 grid is a magic square\n s = set()\n for i in range(3):\n for j in range(3):\n s.add(grid[i][j])\n\...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "0000042648", "row_id": 42648, "seed_ids": "['1066', '1914', '2071']" }
0.622005
Leetcode_42648
I
[ "is_magic_square", "contains_magic_square" ]
2
[ [ "contains_magic_square", "is_magic_square" ] ]
1
[]
false
[]
false
pytest
true
[]
true
87eb0fca29cdfba3aa5b39b205625e2dc137cfb5
cea89283b22ebb848d3fb6874af75260f7823689
v1.0
instruct
Leetcode
Leetcode_42684_I
A company is developing an employee time-tracking application. Each employee has an associated list of timestamps that indicate their log-ins and log-outs throughout the day. You are given a list of strings `logTimes` where each element is in the format "HH:MM-HH:MM" (e.g., "09:00-17:00") representing an employee's log...
def time_diff_in_minutes(time1, time2): """ Returns the difference in minutes between two time strings formatted as "HH:MM". """ h1, m1 = map(int, time1.split(':')) h2, m2 = map(int, time2.split(':')) return (h2 - h1) * 60 + (m2 - m1) def calculate_total_minutes(logTimes): """ Given a l...
from solution import calculate_total_minutes, time_diff_in_minutes def test_single_log_period(): assert calculate_total_minutes(["09:00-10:30"]) == [90] def test_multiple_log_periods(): assert calculate_total_minutes(["09:00-10:30", "13:45-14:15", "16:00-17:00"]) == [90, 30, 60] def test_multiple_same_period...
[ { "docstring": "Returns the difference in minutes between two time strings formatted as \"HH:MM\".", "function_declaration": "def time_diff_in_minutes(time1, time2):", "function_name": "time_diff_in_minutes", "parameter_list": "(time1, time2)" }, { "docstring": "Given a list of log-in/log-ou...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def calculate_total_minutes(logTimes):\n \"\"\"\n Calculates the total log-in duration in minutes for each time period in logTimes.\n \n Args:\n logTimes (list...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000042684", "row_id": 42684, "seed_ids": "['1427', '1289', '1471']" }
0.618593
Leetcode_42684
I
[ "time_diff_in_minutes", "calculate_total_minutes" ]
2
[ [ "calculate_total_minutes", "time_diff_in_minutes" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6ca883a7b499df19aecb6b07a6be7f8c54f62193
158647dd3c67d6b108acf386ab591266684c3061
v1.0
instruct
Leetcode
Leetcode_42753_I
Given an array of integers `arr`, find the **length** of the longest subsequence such that every element in the subsequence is a power of two. A power of two is a number of the form `2^k` where `k` is a non-negative integer (e.g., `1`, `2`, `4`, `8`, etc.). You may assume that all elements in `arr` are positive integer...
def is_power_of_two(n): """ Check if a number is a power of two. """ return (n & (n - 1)) == 0 and n > 0 def longest_power_of_two_subsequence(arr): """ Returns the length of the longest subsequence such that every element in the subsequence is a power of two. """ longest_subseq = [num f...
from solution import is_power_of_two, longest_power_of_two_subsequence def test_is_power_of_two(): assert is_power_of_two(1) == True assert is_power_of_two(2) == True assert is_power_of_two(3) == False assert is_power_of_two(4) == True assert is_power_of_two(0) == False assert is_power_of_two(1...
[ { "docstring": "Check if a number is a power of two.", "function_declaration": "def is_power_of_two(n):", "function_name": "is_power_of_two", "parameter_list": "(n)" }, { "docstring": "Returns the length of the longest subsequence such that every element in the subsequence is a power of two....
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_power_of_two(n):\n \"\"\"\n Checks if a number is a power of two.\n \"\"\"\n return (n & (n - 1)) == 0 and n > 0\n\ndef longest_power_of_two_subsequence(ar...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000042753", "row_id": 42753, "seed_ids": "['1754', '279', '270']" }
0.704005
Leetcode_42753
I
[ "is_power_of_two", "longest_power_of_two_subsequence" ]
2
[ [ "longest_power_of_two_subsequence", "is_power_of_two" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a68033b090a26251e72ba13a67e12aab163ff241
fd0f893534fffd068fff99acb81e854d1a792184
v1.0
instruct
Leetcode
Leetcode_42886_I
Given an integer array `nums`, implement a function to determine if it's possible to rearrange the elements of `nums` such that all adjacent elements have a different parity (one is odd, the other is even). If it's possible, return any valid rearrangement of the array. If not, return `[]`. For example, if `nums = [3, ...
def rearrange_array(nums): """ Determine if it's possible to rearrange the elements such that all adjacent elements have different parity (one is odd, the other is even). If it's possible, return any valid rearrangement of the array. Otherwise, return []. """ evens = [x for x in nums if x % 2 ==...
from solution import rearrange_array def test_rearrange_possible_case_1(): assert sorted(rearrange_array([3, 1, 4, 2])) == [1, 2, 3, 4] def test_rearrange_possible_case_2(): result = rearrange_array([3, 1, 4, 2]) assert all((result[i] % 2 != result[i+1] % 2) for i in range(len(result) - 1)) def test_rear...
[ { "docstring": "Determine if it's possible to rearrange the elements such that all adjacent\nelements have different parity (one is odd, the other is even). If it's\npossible, return any valid rearrangement of the array. Otherwise, return [].", "function_declaration": "def rearrange_array(nums):", "func...
[ 0, 0, 1, 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 rearrange_elements(nums):\n \"\"\"\n Determines if it's possible to rearrange the elements such that all adjacent elements have different parity.\n If possible, ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "0000042886", "row_id": 42886, "seed_ids": "['2000', '410', '2048']" }
0.665569
Leetcode_42886
I
[ "rearrange_array", "interleave" ]
2
[ [ "rearrange_array", "interleave" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6b1e8c0005b0ce8b10dfca05704d18af70ed9d7d
84618703c3298a017a55ec8c80db3316feb5ea41
v1.0
instruct
Leetcode
Leetcode_42977_I
Given a `m x n` binary matrix `mat`, return _the **maximum area** of a rectangle that contains only `1`s_. A rectangle is defined as a contiguous block of cells that all have the value `1` and can span over multiple rows and columns. The area of the rectangle is given by the number of cells within it.
def maximalRectangle(matrix): if not matrix: return 0 max_area = 0 dp = [0] * len(matrix[0]) for row in matrix: for index, val in enumerate(row): dp[index] = dp[index] + 1 if val == '1' else 0 max_area = max(max_area, largestRectangleArea(dp)) return max_are...
from solution import maximalRectangle def test_single_row_matrix(): matrix = [["1","0","1","0","0"], ["1","0","1","1","1"], ["1","1","1","1","1"], ["1","0","0","1","0"]] assert maximalRectangle(matrix) == 6 def test_all_zeros(): matrix = [["0","0","0"], ...
[ { "docstring": null, "function_declaration": "def maximalRectangle(matrix):", "function_name": "maximalRectangle", "parameter_list": "(matrix)" }, { "docstring": null, "function_declaration": "def largestRectangleArea(heights):", "function_name": "largestRectangleArea", "paramete...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def maximal_rectangle(matrix):\n \"\"\"\n Returns the maximum area of a rectangle containing only 1's in a given binary matrix.\n \"\"\"\n if not matrix or not ma...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000042977", "row_id": 42977, "seed_ids": "['2170', '1759', '1918']" }
0.728468
Leetcode_42977
I
[ "maximalRectangle", "largestRectangleArea" ]
2
[ [ "maximalRectangle", "largestRectangleArea" ] ]
1
[]
false
[]
false
pytest
true
[]
true
608e8ecbd921f2d4460fd9a763be9bcb12c52174
3c4cf6272706ae39223ef6b81341dd4a0cc54b33
v1.0
instruct
Leetcode
Leetcode_43121_I
You are given a positive integer `num`. Write a function that returns a string representation of all the numbers from 1 to `num` in lexicographical order. For example, if `num = 13`, your function should return: ["1", "10", "11", "12", "13", "2", "3", "4", "5", "6", "7", "8", "9"]. The solution must be efficient and ha...
def lexical_order(num): """ Returns a list of numbers from 1 to num in lexicographical order. """ return [str(i) for i in range(1, num + 1)] def sort_lexicographically(nums): """ Sorts a list of numbers (in string format) lexicographically. """ return sorted(nums) def lexicographical_n...
from solution import lexical_order, sort_lexicographically, lexicographical_numbers def test_lexical_order(): assert lexical_order(5) == ['1', '2', '3', '4', '5'] assert lexical_order(13) == ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13'] def test_sort_lexicographically(): assert sor...
[ { "docstring": "Returns a list of numbers from 1 to num in lexicographical order.", "function_declaration": "def lexical_order(num):", "function_name": "lexical_order", "parameter_list": "(num)" }, { "docstring": "Sorts a list of numbers (in string format) lexicographically.", "function_...
[ 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 lexical_order(num):\n \"\"\"\n Returns a list of numbers from 1 to num in lexicographical order.\n \"\"\"\n return sorted(map(str, range(1, num + 1)))", "...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000043121", "row_id": 43121, "seed_ids": "['119', '1569', '942']" }
0.574252
Leetcode_43121
I
[ "lexical_order", "sort_lexicographically", "lexicographical_numbers" ]
3
[ [ "lexicographical_numbers", "lexical_order" ], [ "lexicographical_numbers", "sort_lexicographically" ] ]
2
[]
false
[]
false
pytest
true
[]
true
445f3ea4c88910a89cd229523bfb2acc5c0428ac
12c5926588c4d5c38d1b7f6d9976976081c60a8b
v1.0
instruct
Leetcode
Leetcode_43228_I
You are given a string `s` and an integer `k`. A substring is called a **k-palin** if it is k-palindromic, meaning the substring can be rearranged to form a palindrome. Return _the **number** of k-palin substrings in the string `s`._ A substring is a **contiguous** part of a string. For instance, in the string "aabb", ...
from collections import Counter def is_k_palin(substring, k): """ Helper function to check if the substring can be rearranged to form a k-palindrome. A string can be rearranged to form a palindrome if at most one character has an odd count. For k-palindrome, it's allowed to have up to k characters with...
from solution import count_k_palin_substrings def test_empty_string(): assert count_k_palin_substrings("", 1) == 0 def test_single_character_string(): assert count_k_palin_substrings("a", 1) == 1 def test_all_characters_same(): assert count_k_palin_substrings("aaaa", 0) == 10 # All substrings are palind...
[ { "docstring": "Helper function to check if the substring can be rearranged to form a k-palindrome.\nA string can be rearranged to form a palindrome if at most one character has an odd count.\nFor k-palindrome, it's allowed to have up to k characters with odd counts.", "function_declaration": "def is_k_pali...
[ 0, 1, 0, 0, 0, 0, 0, 0, 1, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "from collections import Counter\n\ndef is_k_palin(substring, k):\n \"\"\"\n Check if a substring is k-palindromic.\n \"\"\"\n freq = Counter(substring)\n odd_c...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000043228", "row_id": 43228, "seed_ids": "['2444', '1697', '1879']" }
0.771458
Leetcode_43228
I
[ "is_k_palin", "count_k_palin_substrings" ]
2
[ [ "count_k_palin_substrings", "is_k_palin" ] ]
1
[]
false
[]
false
pytest
true
[]
true
524dd4d7f7e057c2909775bf584172f1eda49ec7
54c28f11b971b10280058d1501fd249a2ebdf5a4
v1.0
instruct
Leetcode
Leetcode_43265_I
Given a string `s` and an array of strings `dict`, return _the longest string in_ `dict` _that can be formed by deleting some of the characters of_ `s`. If there are multiple strings with the same length, return the lexicographically smallest one. If there is no possible result, return an empty string. Here is how the...
def is_subsequence(x, y): it = iter(y) return all(c in it for c in x) def find_longest_word(s, dict): dict.sort(key=lambda x: (-len(x), x)) for word in dict: if is_subsequence(word, s): return word return ""
from solution import find_longest_word def test_find_longest_word_no_subsequence(): s = "abc" dictionary = ["def", "ghi"] assert find_longest_word(s, dictionary) == "" def test_find_longest_word_single_matching(): s = "abpcplea" dictionary = ["ale", "apple", "monkey", "plea"] assert find_longe...
[ { "docstring": null, "function_declaration": "def is_subsequence(x, y):", "function_name": "is_subsequence", "parameter_list": "(x, y)" }, { "docstring": null, "function_declaration": "def find_longest_word(s, dict):", "function_name": "find_longest_word", "parameter_list": "(s, ...
[ 0, 1, 1, 1, 0, 0, 0, 1, 0, 1 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def find_longest_word(s, dict):\n def is_subsequence(x, y):\n it = iter(y)\n return all(c in it for c in x)\n\n longest_word = \"\"\n for word in sorte...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000043265", "row_id": 43265, "seed_ids": "['1967', '2511', '1526']" }
0.665293
Leetcode_43265
I
[ "is_subsequence", "find_longest_word" ]
2
[ [ "find_longest_word", "is_subsequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f11c0b76138764c897bed91e4a33464a8ed8378a
25ddcd2869277e225fb9124e021aa2575c45cf67
v1.0
instruct
Leetcode
Leetcode_43314_I
You are given a string `s` consisting of lowercase English letters and a list of operations. Each operation is characterized by swapping two characters at given indices `i` and `j`. After performing all given operations, a string is considered to be lexicographically smallest if no permutation of the string, by perform...
def find(parent, i): if parent[i] == i: return i return find(parent, parent[i]) def union(parent, rank, x, y): rootX = find(parent, x) rootY = find(parent, y) if rootX != rootY: if rank[rootX] > rank[rootY]: parent[rootY] = rootX elif rank[rootX] < rank[root...
from solution import find, union, smallestStringWithSwaps def test_find_union(): parent = [0, 1, 2, 3] rank = [0, 0, 0, 0] union(parent, rank, 0, 1) union(parent, rank, 1, 2) assert find(parent, 2) == find(parent, 0) == 0 or find(parent, 2) == find(parent, 0) == 2 def test_smallest_string_with_swa...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "from collections import defaultdict\n\ndef smallestStringWithSwaps(s, pairs):\n def find(x):\n if parent[x] != x:\n parent[x] = find(parent[x])\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000043314", "row_id": 43314, "seed_ids": "['1566', '2364', '999']" }
0.852384
Leetcode_43314
I
[ "find", "union", "smallestStringWithSwaps" ]
3
[ [ "smallestStringWithSwaps", "find" ], [ "smallestStringWithSwaps", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
true
[]
true
d99ac69edcad76e8e16c1f65b1501cabdbeb1e66
32f7e54e0a8edf1f69f1920dc22f5a5e68f1a19a
v1.0
instruct
Leetcode
Leetcode_43535_I
You are given an array `arr` of integers and an integer `k`. The array `arr` contains at least two distinct elements. Your task is to find the `k`-th smallest number in the array using the Quickselect algorithm, an optimization of the QuickSort algorithm. The Quickselect algorithm works by choosing a pivot and partiti...
import random def partition(arr, low, high): pivot = arr[high] i = low - 1 for j in range(low, high): if arr[j] <= pivot: i += 1 arr[i], arr[j] = arr[j], arr[i] arr[i + 1], arr[high] = arr[high], arr[i + 1] return i + 1 def quickselect(arr, low, high, k): if low...
from solution import kthSmallest def test_kth_smallest_general(): assert kthSmallest([7, 10, 4, 3, 20, 15], 3) == 7 assert kthSmallest([7, 10, 4, 3, 20, 15], 2) == 4 def test_kth_smallest_edge_cases(): assert kthSmallest([1, 2], 1) == 1 assert kthSmallest([1, 2], 2) == 2 def test_kth_smallest_negativ...
[ { "docstring": null, "function_declaration": "def partition(arr, low, high):", "function_name": "partition", "parameter_list": "(arr, low, high)" }, { "docstring": null, "function_declaration": "def quickselect(arr, low, high, k):", "function_name": "quickselect", "parameter_list...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def partition(arr, low, high):\n pivot = arr[high]\n i = low\n for j in range(low, high):\n if arr[j] <= pivot:\n arr[i], arr[j] = arr[j], arr[i]\n...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000043535", "row_id": 43535, "seed_ids": "['2045', '1625', '482']" }
0.67231
Leetcode_43535
I
[ "partition", "quickselect", "kthSmallest" ]
3
[ [ "kthSmallest", "quickselect" ], [ "quickselect", "partition" ] ]
2
[]
false
[]
false
pytest
true
[]
true
24ddd9afe5038b11369d64b6dcacb913712f9c8b
ee1224f6dd7b685cf1221fecf03525405d786aa9
v1.0
instruct
Leetcode
Leetcode_43602_I
You are given an array `schedule` representing the schedule of a group of employees, where `schedule[i]` is a list of intervals representing the working hours of the ith employee.Each interval is represented as a light `[start, end]` where `start` is the start time of the interval and `end` is the end time of the inter...
from typing import List import itertools def merge_intervals(intervals: List[List[int]]) -> List[List[int]]: if not intervals: return [] # Sort intervals by starting time intervals.sort(key=lambda x: x[0]) merged = [intervals[0]] for current in intervals[1:]: last_merged =...
from solution import find_free_time def test_find_free_time_single_employee(): schedule = [[["09:00", "12:00"], ["13:00", "15:00"]]] assert find_free_time(schedule) == [["12:00", "13:00"]] def test_find_free_time_multiple_employees(): schedule = [ [["09:00", "12:00"], ["13:00", "16:00"]], ...
[ { "docstring": null, "function_declaration": "def merge_intervals(intervals):", "function_name": "merge_intervals", "parameter_list": "(intervals)" }, { "docstring": null, "function_declaration": "def find_free_time(schedule):", "function_name": "find_free_time", "parameter_list"...
[ 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def find_free_time(schedule):\n from heapq import merge\n \n # Convert time \"HH:MM\" to minutes\n def to_minutes(time):\n h, m = map(int, time.split(\":\"...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "0000043602", "row_id": 43602, "seed_ids": "['1996', '1417', '35']" }
0.724518
Leetcode_43602
I
[ "merge_intervals", "find_free_time" ]
2
[ [ "find_free_time", "merge_intervals" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2f67b2a0dfea1d10bd5d2efa212017dfda1b60f5
561ab9da421f67785c068a84da7598fd543cf5bb
v1.0
instruct
Leetcode
Leetcode_43750_I
You have been provided with a list of integers `nums` and a positive integer `k`. You need to divide the list into `k` contiguous non-empty subarrays such that the maximum sum of elements among all subarrays is minimized. Return _the minimized maximum sum of the subarrays_.
def can_partition(nums, k, max_sum): current_sum = 0 required_parts = 1 for num in nums: if current_sum + num > max_sum: required_parts += 1 current_sum = num if required_parts > k: return False else: current_sum += num ...
from solution import split_array def test_split_array_case1(): nums = [7, 2, 5, 10, 8] k = 2 result = split_array(nums, k) assert result == 18, f"Expected 18 but got {result}" def test_split_array_case2(): nums = [1, 2, 3, 4, 5] k = 2 result = split_array(nums, k) assert result == 9, f...
[ { "docstring": null, "function_declaration": "def can_partition(nums, k, max_sum):", "function_name": "can_partition", "parameter_list": "(nums, k, max_sum)" }, { "docstring": null, "function_declaration": "def split_array(nums, k):", "function_name": "split_array", "parameter_li...
[ 1, 1, 0, 0, 0, 1, 1, 0, 0, 0 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def splitArray(nums, k):\n \"\"\"\n Splits the given list nums into k contiguous subarrays such that the maximum sum \n of elements among all subarrays is minimized....
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "0000043750", "row_id": 43750, "seed_ids": "['774', '1652', '922']" }
0.790538
Leetcode_43750
I
[ "can_partition", "split_array" ]
2
[ [ "split_array", "can_partition" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9c75b17fb80b1246a2544887843803737145b3fe
c9ecccf59e83b3de98b7dd3dbc9f5c85736748b9
v1.0
instruct
Leetcode
Leetcode_43791_I
Given a binary matrix `grid` where `grid[i][j]` can be either `0` or `1`, return the largest rectangle containing only `1's` and return the area of that rectangle. You may assume that the input grid will always have at least one element. The rectangle can be constructed using adjacent 1's in the grid.
def maximalRectangle(matrix): if not matrix: return 0 max_area = 0 dp = [0] * len(matrix[0]) for row in matrix: for j in range(len(row)): dp[j] = dp[j] + 1 if row[j] == '1' else 0 max_area = max(max_area, largestRectangleArea(dp)) return max_area d...
from solution import maximalRectangle def test_empty_matrix(): assert maximalRectangle([]) == 0 def test_single_element_matrix(): assert maximalRectangle([["0"]]) == 0 assert maximalRectangle([["1"]]) == 1 def test_two_by_two_matrix(): assert maximalRectangle([ ["1", "0"], ["1", "1"] ...
[ { "docstring": null, "function_declaration": "def maximalRectangle(matrix):", "function_name": "maximalRectangle", "parameter_list": "(matrix)" }, { "docstring": null, "function_declaration": "def largestRectangleArea(heights):", "function_name": "largestRectangleArea", "paramete...
[ 1, 0, 1, 0, 1, 1, 1, 1, 1, 0 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def maximalRectangle(grid):\n if not grid or not grid[0]:\n return 0\n \n max_area = 0\n cols = len(grid[0])\n height = [0] * (cols + 1)\n \n for ...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "0000043791", "row_id": 43791, "seed_ids": "['1153', '1640', '788']" }
0.804459
Leetcode_43791
I
[ "maximalRectangle", "largestRectangleArea" ]
2
[ [ "maximalRectangle", "largestRectangleArea" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2d8eb30f4f0b4577f8b593dc0f92bdbcef079943
5d7a6611db9b908438374b2ca61ef6216cab5bba
v1.0
instruct
Leetcode
Leetcode_43959_I
You are given a list of `n` integers `nums`, and an integer `threshold`. Your task is to find the minimum possible largest sum of the subarrays that the list can be divided into, such that the sum of each subarray does not exceed `threshold`. You need to perform the split in such a way that minimizes this largest sum. ...
from typing import List def can_split(nums: List[int], max_sum: int, threshold: int) -> bool: current_sum = 0 count_splits = 1 for num in nums: if current_sum + num <= max_sum: current_sum += num else: count_splits += 1 current_sum = num if c...
from solution import minimizeLargestSum def test_case_1(): assert minimizeLargestSum([7, 2, 5, 10, 8], 2) == 18 def test_case_2(): assert minimizeLargestSum([1, 2, 3, 4, 5], 2) == 9 def test_case_3(): assert minimizeLargestSum([1, 4, 4], 3) == 4 def test_case_4(): assert minimizeLargestSum([1, 2, 3,...
[ { "docstring": null, "function_declaration": "def can_split(nums, max_sum, threshold):", "function_name": "can_split", "parameter_list": "(nums, max_sum, threshold)" }, { "docstring": null, "function_declaration": "def minimizeLargestSum(nums, threshold):", "function_name": "minimize...
[ 0, 1, 0, 0, 1, 1, 1, 1, 1, 0 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def minimizeLargestSum(nums, threshold):\n def isValid(mid):\n current_sum = 0\n count = 1\n for num in nums:\n if current_sum + num > mid:...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000043959", "row_id": 43959, "seed_ids": "['361', '732', '302']" }
0.756862
Leetcode_43959
I
[ "can_split", "minimizeLargestSum" ]
2
[ [ "minimizeLargestSum", "can_split" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3a46622a3b9e1540b0f85dd08b37fcb6c7691bb5
17e084f79ac0340900c6db174d6502a025a9af7d
v1.0
instruct
Leetcode
Leetcode_44249_I
Write a function `findWordSquares(words)` that returns all unique word squares you can build from the provided list of words. A sequence of words forms a valid word square if the k-th row and column read the exact same string, and there is exactly the same number of rows and columns. For example, if `input` words list ...
from collections import defaultdict from typing import List def build_prefix_dict(words: List[str]): prefix_dict = defaultdict(list) for word in words: for i in range(len(word)): prefix_dict[word[:i]].append(word) return prefix_dict def findWordSquares(words): def backtrack(step): ...
from solution import findWordSquares def test_findWordSquares_basic(): words = ["area", "lead", "wall", "lady", "ball"] output = findWordSquares(words) expected = [ ["ball", "area", "lead", "lady"], ["wall", "area", "lead", "lady"] ] assert len(output) == len(expected) ...
[ { "docstring": null, "function_declaration": "def build_prefix_dict(words):", "function_name": "build_prefix_dict", "parameter_list": "(words)" }, { "docstring": null, "function_declaration": "def findWordSquares(words):", "function_name": "findWordSquares", "parameter_list": "(w...
[ 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 build_trie(words):\n trie = {}\n for word in words:\n node = trie\n for char in word:\n if char not in node:\n node[char] = ...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "0000044249", "row_id": 44249, "seed_ids": "['2484', '770', '1670']" }
0.550746
Leetcode_44249
I
[ "build_prefix_dict", "findWordSquares" ]
2
[ [ "findWordSquares", "build_prefix_dict" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c62a66c72bb11b9ee332f3dfa1a103d0947d9a55
68d23bbef7f0a442cd137a78415d5e6532d1d07a
v1.0
instruct
Leetcode
Leetcode_44316_I
You are given a string `s` representing a sentence, where each word is separated by a single space. Each letter in the string is either an uppercase English letter or a lowercase English letter. We define the "word score" of a word as the sum of the position values of its characters (`'a'`=1, `'b'`=2, ..., `'z'`=26). T...
def word_score(word): """ Calculate the word score for a given word. Each letter ('a'-'z' or 'A'-'Z') has a value which is its position in the alphabet case-insensitive ('a' = 1, 'b' = 2, ..., 'z' = 26). """ return sum((ord(char.lower()) - ord('a') + 1) for char in word) def sort_sentence_by_word_s...
from solution import sort_sentence_by_word_scores, word_score def test_single_word(): assert sort_sentence_by_word_scores("hello") == ["hello"] def test_multiple_words_same_score(): assert sort_sentence_by_word_scores("abc cba") == ["abc", "cba"] def test_different_scores(): assert sort_sentence_by_word_...
[ { "docstring": "Calculate the word score for a given word.\nEach letter ('a'-'z' or 'A'-'Z') has a value which is its position in the alphabet case-insensitive ('a' = 1, 'b' = 2, ..., 'z' = 26).", "function_declaration": "def word_score(word):", "function_name": "word_score", "parameter_list": "(wor...
[ 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 word_score(word):\n \"\"\"\n Calculate the score of the word based on the sum of character positions.\n \"\"\"\n return sum((ord(char.lower()) - ord('a') + 1)...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000044316", "row_id": 44316, "seed_ids": "['1366', '810', '1548']" }
0.74125
Leetcode_44316
I
[ "word_score", "sort_sentence_by_word_scores" ]
2
[ [ "sort_sentence_by_word_scores", "word_score" ] ]
1
[]
false
[]
false
pytest
true
[]
true
72f324b1e278ba64419306f7907bc88b30abc97d
81673e261f3f0961f79fcf3b30feef7e3e8a2b06
v1.0
instruct
Leetcode
Leetcode_44364_I
Suppose you have a function `mysteryFunction` that you want to test. This function takes an integer input `n` and returns a transformed version of the number by reversing the digits and adding it to the original number until the number becomes a palindrome or it reaches a maximum of 25 iterations. Write a function to t...
def is_palindrome(num): """ Checks if a given number is a palindrome. """ return str(num) == str(num)[::-1] def reverse_number(num): """ Reverses the digits of an integer. """ return int(str(num)[::-1]) def mysteryFunction(n): """ Transforms a number by reversing it and adding ...
from solution import mysteryFunction, is_palindrome def test_mystery_function_palindrome(): assert mysteryFunction(56) == (True, 121) # 56 + 65 = 121, which is a palindrome def test_mystery_function_no_palindrome(): result, final_num = mysteryFunction(196) assert result == False # Known to never reach a...
[ { "docstring": "Checks if a given number is a palindrome.", "function_declaration": "def is_palindrome(num):", "function_name": "is_palindrome", "parameter_list": "(num)" }, { "docstring": "Reverses the digits of an integer.", "function_declaration": "def reverse_number(num):", "func...
[ 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 reverse_number(n):\n \"\"\"\n Returns the reversed version of the number n.\n \"\"\"\n return int(str(n)[::-1])\n\ndef is_palindrome(n):\n \"\"\"\n Chec...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "0000044364", "row_id": 44364, "seed_ids": "['1272', '297', '1078']" }
0.646201
Leetcode_44364
I
[ "is_palindrome", "reverse_number", "mysteryFunction" ]
3
[ [ "mysteryFunction", "is_palindrome" ], [ "mysteryFunction", "reverse_number" ] ]
2
[]
false
[]
false
pytest
true
[]
true
5ba520956b28e3e206fccc2aa8c6f527b0cd8c82
d88abac726090f3f03e7a4eb72b40b557d262d3e
v1.0
instruct
Leetcode
Leetcode_44411_I
You are given a string `s` that consists of lowercase English letters and a list of pairs of indices in the string `pairs` where each pair `[a, b]` can be swapped. You can swap any number of times the pairs in the list. Return _the lexicographically smallest string_ that `s` can be transformed into after using the swap...
def find(parent, x): if parent[x] != x: parent[x] = find(parent, parent[x]) return parent[x] def union(parent, rank, x, y): rootX = find(parent, x) rootY = find(parent, y) if rootX != rootY: if rank[rootX] > rank[rootY]: parent[rootY] = rootX elif rank[rootX...
def test_no_swaps(): assert smallestStringWithSwaps("abc", []) == "abc" def test_single_pair(): assert smallestStringWithSwaps("acb", [[1, 2]]) == "abc" def test_multiple_pairs(): assert smallestStringWithSwaps("dcab", [[0, 3], [1, 2]]) == "bacd" def test_interconnected_pairs(): assert smallestString...
[ { "docstring": null, "function_declaration": "def find(parent, x):", "function_name": "find", "parameter_list": "(parent, x)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def smallestStringWithSwaps(s, pairs):\n \"\"\"\n Returns the lexicographically smallest string that can be formed\n by swaps described in pairs.\n\n Args:\n s...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "0000044411", "row_id": 44411, "seed_ids": "['1492', '317', '2203']" }
0.786291
Leetcode_44411
I
[ "find", "union", "smallestStringWithSwaps" ]
3
[ [ "smallestStringWithSwaps", "find" ], [ "smallestStringWithSwaps", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
false
[]
true
43d8799d5d602af8b511954d4bdd0acba8576944
17991e60a202600e34d14fc78a87860c2936e6a1
v1.0
instruct
Leetcode
Leetcode_44469_I
You are given a binary tree with `n` nodes where each node is uniquely labeled from `0` to `n - 1`. The tree is represented as an integer array `parent`, where `parent[i]` denotes the parent of the `i-th` node. The root of the tree has `parent[root] == -1`. Each node also has a corresponding value in the integer array ...
from collections import defaultdict def build_tree(parent): tree = defaultdict(list) root = -1 n = len(parent) for i in range(n): if parent[i] == -1: root = i else: tree[parent[i]].append(i) return tree, root def count_nodes_greater_than_x(tree, values, u, x...
from solution import query_subtree_greater_than_x def test_single_query(): parent = [-1, 0, 0, 1, 1] value = [3, 2, 1, 4, 5] queries = [(1, 2)] assert query_subtree_greater_than_x(parent, value, queries) == [2] def test_multiple_queries(): parent = [-1, 0, 0, 1, 1, 2] value = [7, 2, 5, 3, 4, 6...
[ { "docstring": null, "function_declaration": "def build_tree(parent):", "function_name": "build_tree", "parameter_list": "(parent)" }, { "docstring": null, "function_declaration": "def count_nodes_greater_than_x(tree, values, u, x):", "function_name": "count_nodes_greater_than_x", ...
[ 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 collections import defaultdict\n\nclass TreeNode:\n def __init__(self, value):\n self.value = value\n self.children = []\n\ndef build_tree(n, parent, va...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "0000044469", "row_id": 44469, "seed_ids": "['1938', '810', '2603']" }
0.580267
Leetcode_44469
I
[ "build_tree", "count_nodes_greater_than_x", "query_subtree_greater_than_x" ]
3
[ [ "query_subtree_greater_than_x", "build_tree" ], [ "query_subtree_greater_than_x", "count_nodes_greater_than_x" ] ]
2
[]
false
[]
false
pytest
true
[]
true
cb64986993f6b493c0859c32fcdaac54bd8d34d1
9947940721b0ecc3c0f0bef730718be2ee962389
v1.0
instruct
Apps
Apps_54_I
In the bustling city of Techville, there are n interconnected computer servers. The servers are set up in such a way that there's only one unique path between any two servers. The city's cybersecurity team has recently discovered a malware threat that could target and disable these servers. Their ultimate goal is to is...
def calculate_tree_depths(n, edges): from collections import deque, defaultdict tree = defaultdict(list) for u, v in edges: tree[u].append(v) tree[v].append(u) depths = [-1] * (n + 1) queue = deque([(1, 0)]) depths[1] = 0 while queue: node, depth = queue.poplef...
def test_calculate_tree_depths(): n = 5 edges = [(1, 2), (1, 3), (3, 4), (3, 5)] expected_depths = [-1, 0, 1, 1, 2, 2] assert calculate_tree_depths(n, edges) == expected_depths def test_minimum_servers_to_isolate(): n = 5 edges = [(1, 2), (1, 3), (3, 4), (3, 5)] scenarios = [3, 4, 5] ex...
[ { "docstring": null, "function_declaration": "def calculate_tree_depths(n, edges):", "function_name": "calculate_tree_depths", "parameter_list": "(n, edges)" }, { "docstring": null, "function_declaration": "def minimum_servers_to_isolate(n, edges, scenarios):", "function_name": "mini...
[ 0, 0, 0, 0, 1, 0, 0, 0, 0 ]
1
hard
0.111
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def minimum_servers_to_disable(n, edges, scenarios):\n from collections import defaultdict, deque\n\n # Building the adjacency list of the tree\n tree = de...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00000054", "row_id": 54, "seed_ids": "[2234]" }
0.627278
Apps_54
I
[ "calculate_tree_depths", "minimum_servers_to_isolate" ]
2
[ [ "minimum_servers_to_isolate", "calculate_tree_depths" ] ]
1
[]
false
[]
false
pytest
false
[]
true
f7f4996ccace67cb48d06ae5de29eb1585517ad8
42d30c67d063a2b66c6fbf658078f1553e85461e
v1.0
instruct
Apps
Apps_111_I
You are given an array `a` consisting of `n` integers between `1` and `m` inclusive. Your task is to find an array `b` of length `m`, where each element `b[i]` represents the number of elements in `a` that are less than or equal to `i`. If there are no elements in `a` that are less than or equal to `i`, then `b[i]` sho...
def count_elements_less_equal(a, m): """ This function takes a list 'a' of integers and a maximum value 'm'. It returns a list 'b' where each element 'b[i]' represents the number of elements in 'a' that are less than or equal to 'i'. """ # Create a list to store the count of elements except init...
import pytest from solution import count_elements_less_equal, solve, parse_input def test_count_elements_less_equal(): assert count_elements_less_equal([1, 2, 1, 3, 2], 5) == [2, 4, 5, 5, 5] assert count_elements_less_equal([1, 3, 3, 2], 3) == [1, 2, 4] def test_solve(): input_data = [ (5, 5, [1, ...
[ { "docstring": "This function takes a list 'a' of integers and a maximum value 'm'.\nIt returns a list 'b' where each element 'b[i]' represents the number\nof elements in 'a' that are less than or equal to 'i'.", "function_declaration": "def count_elements_less_equal(a, m):", "function_name": "count_ele...
[ 1, 1, 0, 1, 1, 1, 1, 1, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_b_arrays(t, test_cases):\n results = []\n \n for n, m, a in test_cases:\n b = [0] * m\n \n # Count occurrences of each number...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00000111", "row_id": 111, "seed_ids": "[91]" }
0.755642
Apps_111
I
[ "count_elements_less_equal", "solve", "parse_input" ]
3
[ [ "solve", "count_elements_less_equal" ] ]
1
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
aacaabe53e4c5d4b0ad5f6f6847e38ef8dc10a54
5ed69b6ba11094fa35a8104638c15b972a510cfe
v1.0
instruct
Apps
Apps_171_I
You are holding a charity raffle where you will sell tickets to attendees. Each ticket has a unique number, and the sum of their digits represents potential lucky numbers. You wish to distribute the tickets such that ticket buyers have an equal chance of winning based on the sum of ticket digits. The task is to determ...
def digit_sum(n): """ Returns the sum of the digits of the number n. """ return sum(int(digit) for digit in str(n)) def minimum_tickets_needed() -> int: """ Returns the minimum number of tickets needed to ensure that each sum of digits value is equally represented at least once. """ ...
from solution import minimum_tickets_needed def test_minimum_tickets_needed(): assert minimum_tickets_needed() == 999 # NOTE: For testing purposes more unit tests can be added with mock implementations. # This is a base test reflecting the decision logic of the problem.
[ { "docstring": "Returns the sum of the digits of the number n.", "function_declaration": "def digit_sum(n):", "function_name": "digit_sum", "parameter_list": "(n)" }, { "docstring": "Returns the minimum number of tickets needed to ensure that each \nsum of digits value is equally represented...
[ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def sum_of_digits(number):\n \"\"\"Returns the sum of digits of a given number.\"\"\"\n return sum(int(digit) for digit in str(number))\n\ndef minimum_tickets...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00000171", "row_id": 171, "seed_ids": "[3454]" }
0.512881
Apps_171
I
[ "digit_sum", "minimum_tickets_needed" ]
2
[ [ "minimum_tickets_needed", "digit_sum" ] ]
1
[]
false
[]
false
pytest
true
[]
true
78729e586a0e9c83feb2bd7564ae90a5584ea8c6
cc82af04f06c15141e793792167a5b278d333021
v1.0
instruct
Apps
Apps_334_I
Write a function that takes a list of integers and returns a list containing only the prime numbers from the input list. For example, if the input list is: [10, 15, 3, 7, 8, 19, 23, 6] the function should return: [3, 7, 19, 23] The input list can contain any integer values, and the function should handle ...
def is_prime(n): """ Helper function to check if the given number n is a prime number. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: retur...
from solution import filter_primes def test_filter_primes_with_primes_and_non_primes(): assert filter_primes([10, 15, 3, 7, 8, 19, 23, 6]) == [3, 7, 19, 23] def test_filter_primes_with_all_non_primes(): assert filter_primes([4, 6, 8, 9, 10]) == [] def test_filter_primes_with_all_primes(): assert filter_p...
[ { "docstring": "Helper function to check if the given number n is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list containing only the prime numbers from the input list.", "function_declar...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
9
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Helper function to determine if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n retu...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00000334", "row_id": 334, "seed_ids": "[4594]" }
0.67551
Apps_334
I
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7eee20b884eb878f2b5eb2b91308656c02ab1c36
04743b28062b1a828438a9e2d015b560853ee002
v1.0
instruct
Apps
Apps_450_I
Lena loves numbers and recently discovered an interesting property of palindromic numbers. A palindromic number is a number that remains the same when its digits are reversed. She wants to explore the sum of all palindromic numbers within a given range [A, B]. You are Lena's friend, and you want to help her in solving...
def is_palindromic(n): """ Check if the number n is a palindromic number. """ s = str(n) return s == s[::-1] def sum_palindromic_numbers_in_range(A, B): """ Calculate the sum of all palindromic numbers within the inclusive range [A, B]. """ return sum(n for n in range(A, B+1) if is_...
from solution import is_palindromic, sum_palindromic_numbers_in_range, process_test_cases def test_is_palindromic(): assert is_palindromic(121) assert is_palindromic(12321) assert not is_palindromic(123) assert not is_palindromic(12345) def test_sum_palindromic_numbers_in_range(): assert sum_palin...
[ { "docstring": "Check if the number n is a palindromic number.", "function_declaration": "def is_palindromic(n):", "function_name": "is_palindromic", "parameter_list": "(n)" }, { "docstring": "Calculate the sum of all palindromic numbers within the inclusive range [A, B].", "function_dec...
[ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def sum_palindromes_in_range(A, B):\n \"\"\"\n Calculate the sum of all palindromic numbers within the range [A, B].\n \"\"\"\n return sum(num for num i...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00000450", "row_id": 450, "seed_ids": "[662]" }
0.676386
Apps_450
I
[ "is_palindromic", "sum_palindromic_numbers_in_range", "process_test_cases" ]
3
[ [ "process_test_cases", "sum_palindromic_numbers_in_range" ], [ "sum_palindromic_numbers_in_range", "is_palindromic" ] ]
2
[ "process_test_cases" ]
false
[]
false
pytest
true
[]
true
5f6b06027be431c54b449366ec88507aced92cce
23567bdddd66d0cbd1a1735bfbbf00ddde683110
v1.0
instruct
Apps
Apps_505_I
You are given an array of integers representing the number of pages in $n$ books. You need to distribute these books among $k$ students in such a way that each student gets a contiguous segment of the books. The goal is to minimize the maximum number of pages that a student can receive. For example, consider the array...
def is_possible(pages, n, k, max_pages): student_count = 1 current_sum = 0 for page in pages: current_sum += page if current_sum > max_pages: student_count += 1 current_sum = page if student_count > k: return Fals...
from solution import find_min_max_pages def test_example_case(): assert find_min_max_pages(4, [10, 20, 30, 40], 2) == 60 def test_single_book(): assert find_min_max_pages(1, [100], 1) == 100 def test_equal_partition(): assert find_min_max_pages(4, [10, 10, 10, 10], 4) == 10 def test_large_number_of_book...
[ { "docstring": null, "function_declaration": "def is_possible(pages, n, k, max_pages):", "function_name": "is_possible", "parameter_list": "(pages, n, k, max_pages)" }, { "docstring": null, "function_declaration": "def find_min_max_pages(n, pages, k):", "function_name": "find_min_max...
[ 1, 0, 1, 1, 0, 1, 1, 0, 0, 0 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def canDistributeBooks(books, n, k, maxPages):\n students = 1\n current_sum = 0\n\n for pages in books:\n if pages > maxPages:\n return F...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00000505", "row_id": 505, "seed_ids": "[7]" }
0.71344
Apps_505
I
[ "is_possible", "find_min_max_pages" ]
2
[ [ "find_min_max_pages", "is_possible" ] ]
1
[]
false
[]
false
pytest
true
[]
true
15fe42663a04777ab45f5d3f6ea1d2f7da48723f
e582bae9f302250744dbe155070682a4395aa34a
v1.0
instruct
Apps
Apps_509_I
Write a function to find the smallest prime number greater than a given number $N$. A prime number is a natural number greater than 1 that cannot be formed by multiplying two smaller natural numbers. -----Input:----- - First-line will contain $T$, the number of test cases. Then the test cases follow. - Each test case ...
def is_prime(num): """ Returns True if num is a prime number, otherwise False. """ 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: ...
from solution import is_prime, smallest_prime_greater_than, process_test_cases def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(10) == False assert is_prime(11) == True assert is_prime(15) == Fa...
[ { "docstring": "Returns True if num is a prime number, otherwise False.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns the smallest prime number greater than N.", "function_declaration": "def smallest_prim...
[ 1, 1, 1, 1, 0, 1, 0, 1, 1, 1 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"\n Returns True if num is a prime number, otherwise False.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00000509", "row_id": 509, "seed_ids": "[703]" }
0.633845
Apps_509
I
[ "is_prime", "smallest_prime_greater_than", "process_test_cases" ]
3
[ [ "process_test_cases", "smallest_prime_greater_than" ], [ "smallest_prime_greater_than", "is_prime" ] ]
2
[ "process_test_cases" ]
false
[]
false
pytest
true
[]
true
d6e45115f34af37e3ed2b5fc614b0e62f9544a6d
b91bdc502d8227dd5784787cc79a706e908e3b2d
v1.0
instruct
Apps
Apps_516_I
Dr. Chan is working on a research project involving prime numbers. He has a machine that can conduct multiple experiments in parallel as long as the numbers used in these experiments are "scientifically distinct." Numbers are scientifically distinct if they share no common factors other than 1 - in other words, they ar...
from math import gcd from functools import reduce from itertools import combinations def gcd_pairs(numbers): """ Calculate the gcd of each pair in list of numbers. """ return all(gcd(a, b) == 1 for a, b in combinations(numbers, 2)) def max_pairwise_coprime_subset(a): """ Return the size of lar...
from solution import solve def test_example1(): T = 2 test_cases = [ (5, [3, 5, 7, 11, 13]), (4, [6, 10, 15, 21]) ] assert solve(T, test_cases) == [5, 2] def test_single_element(): T = 1 test_cases = [(1, [10])] assert solve(T, test_cases) == [1] def test_all_ones(): T...
[ { "docstring": "Calculate the gcd of each pair in list of numbers.", "function_declaration": "def gcd_pairs(numbers):", "function_name": "gcd_pairs", "parameter_list": "(numbers)" }, { "docstring": "Return the size of largest subset of a such that all elements are pairwise coprime.", "fu...
[ 0, 1, 0, 0, 0, 0, 1, 0, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\nfrom collections import defaultdict\n\ndef gcd(a, b):\n while b:\n a, b = b, a % b\n return a\n\ndef max_pairwise_coprime_subset_size(n, a...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00000516", "row_id": 516, "seed_ids": "[1463]" }
0.609209
Apps_516
I
[ "gcd_pairs", "max_pairwise_coprime_subset", "solve" ]
3
[ [ "max_pairwise_coprime_subset", "gcd_pairs" ], [ "solve", "max_pairwise_coprime_subset" ] ]
2
[]
false
[]
false
pytest
true
[]
true
5c64a95387a11e48a20b74239c0041c7e32b7fe3
e90955ed21793b0c63346fb043059191ed6b4a51
v1.0
instruct
Apps
Apps_545_I
You are given a sequence of numbers. Your task is to determine if the sequence can become non-decreasing by modifying at most one element. A sequence is non-decreasing if for every $i \leq j$, the element at position $i$ is less than or equal to the element at position $j$. -----Input:----- - First line will contain $...
def can_be_non_decreasing_by_modifying_one(seq): count = 0 for i in range(1, len(seq)): if seq[i] < seq[i - 1]: if count == 1: return "No" count += 1 if i == 1 or seq[i] >= seq[i - 2]: seq[i - 1] = seq[i - 2] if i - 2 >= 0 else seq[i] ...
from solution import process_input, can_be_non_decreasing_by_modifying_one def test_can_be_non_decreasing_by_modifying_one(): assert can_be_non_decreasing_by_modifying_one([4, 2, 3, 4, 5]) == "Yes" assert can_be_non_decreasing_by_modifying_one([4, 2, 1, 3]) == "No" assert can_be_non_decreasing_by_modifying...
[ { "docstring": null, "function_declaration": "def can_be_non_decreasing_by_modifying_one(seq):", "function_name": "can_be_non_decreasing_by_modifying_one", "parameter_list": "(seq)" }, { "docstring": null, "function_declaration": "def determine_sequences(sequences):", "function_name"...
[ 1, 1, 1, 0, 0, 1, 0, 1, 0, 0 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def can_be_non_decreasing_by_modifying_one(seq):\n count = 0\n for i in range(1, len(seq)):\n if seq[i] < seq[i - 1]:\n if count == 1:\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00000545", "row_id": 545, "seed_ids": "[702]" }
0.866357
Apps_545
I
[ "can_be_non_decreasing_by_modifying_one", "determine_sequences", "process_input" ]
3
[ [ "determine_sequences", "can_be_non_decreasing_by_modifying_one" ], [ "process_input", "determine_sequences" ] ]
2
[ "process_input" ]
false
[]
false
pytest
true
[]
true
753f00125026cb60ae976cfc3d8de81e46efa178
ee6a5857faf807b4d8455c9c15c589701f3694dd
v1.0
instruct
Apps
Apps_559_I
In a certain country, there are n cities connected by roads. Each city can be represented as a point on a 2D plane with coordinates (x, y). Some cities have established telecom towers while others do not. The goal is to provide telecom coverage to all the cities using the shortest possible cable length. The cables can ...
import math import heapq def calc_distance(x1, y1, x2, y2): return math.sqrt((x1 - x2)**2 + (y1 - y2)**2) def minimum_cable_length(n, tower_status, cities): # Using Prim's algorithm to calculate the Minimum Spanning Tree (MST) # List to check if the city is already in the MST or not in_mst = [Fal...
from solution import calc_distance, minimum_cable_length, solve_telecom_coverage def test_calc_distance(): assert calc_distance(0, 0, 3, 4) == 5.0 assert calc_distance(1, 1, 1, 1) == 0.0 assert calc_distance(-1, -1, 1, 1) == math.sqrt(8) def test_minimum_cable_length(): n = 3 tower_status = "100" ...
[ { "docstring": null, "function_declaration": "def calc_distance(x1, y1, x2, y2):", "function_name": "calc_distance", "parameter_list": "(x1, y1, x2, y2)" }, { "docstring": null, "function_declaration": "def minimum_cable_length(n, tower_status, cities):", "function_name": "minimum_ca...
[ 0, 0, 1, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\nimport heapq\n\ndef min_cable_length(T, test_cases):\n results = []\n\n def distance(p1, p2):\n return math.sqrt((p1[0] - p2[0]) ** 2 + (p...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00000559", "row_id": 559, "seed_ids": "[751]" }
0.755268
Apps_559
I
[ "calc_distance", "minimum_cable_length", "solve_telecom_coverage", "main" ]
4
[ [ "minimum_cable_length", "calc_distance" ], [ "solve_telecom_coverage", "minimum_cable_length" ] ]
2
[]
false
[]
false
pytest
true
[]
true
0e15a67b945b060259440796aabd3ba09fc8dd20
c264a2772d64bf9b68ddf6228a2e04be22faee0b
v1.0
instruct
Apps
Apps_574_I
In a town, there are $N$ houses lined up in a straight row on a 1D number line. The position of each house is represented by an integer $x_i$. To ensure safety and simplification of mail delivery, the town council has decided to establish a number of security outposts in such a way that every house is monitored by at l...
def min_outposts(test_cases): results = [] for case in test_cases: N, r, houses = case houses.sort() outposts = 0 i = 0 while i < N: outposts += 1 loc = houses[i] + r while i < N and houses[i] <= loc: i += 1 ...
from solution import outpost_finder def test_example_case_1(): input_string = "2\n5 2\n1 2 5 6 7\n3 1\n3 5 6\n" output = outpost_finder(input_string) assert output == [2, 2] def test_single_house(): input_string = "1\n1 1\n1\n" output = outpost_finder(input_string) assert output == [1] def te...
[ { "docstring": null, "function_declaration": "def min_outposts(test_cases):", "function_name": "min_outposts", "parameter_list": "(test_cases)" }, { "docstring": null, "function_declaration": "def parse_input(input_string):", "function_name": "parse_input", "parameter_list": "(in...
[ 0, 0, 1, 1, 0, 1, 0, 1, 0 ]
4
medium
0.444
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def min_outposts(T, test_cases):\n results = []\n \n for case in test_cases:\n N, r, positions = case\n positions.sort()\n outposts = ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00000574", "row_id": 574, "seed_ids": "[1364]" }
0.720851
Apps_574
I
[ "min_outposts", "parse_input", "outpost_finder" ]
3
[ [ "outpost_finder", "min_outposts" ], [ "outpost_finder", "parse_input" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
c461e91876f144511032a1ebb3fcbc2dab2d450e
c95376e0e06ffa375ee6f3c8292b0d2a9cc4a155
v1.0
instruct
Apps
Apps_584_I
This problem is about finding subsequences in a sequence of positive integers. A subsequence is defined by deleting some or no elements from the original sequence while maintaining the order of the remaining elements. For example, $3,7,11$ is a subsequence of $6,3,11,5,7,4,3,11,5$, but $3,7,5$ is not a subsequence of $...
def longest_increasing_subsequence(sequence): """ Returns the length of the longest strictly increasing subsequence in the provided sequence of integers. """ if not sequence: return 0 # Initialize DP array where dp[i] stores the length of the longest increasing subsequence that ends wit...
import pytest from solution import longest_increasing_subsequence, find_lis_length_from_input def test_longest_increasing_subsequence_sample1(): sequence = [2, 5, 1, 8, 3] assert longest_increasing_subsequence(sequence) == 3 def test_longest_increasing_subsequence_sample2(): sequence = [10, 22, 9, 33, 21,...
[ { "docstring": "Returns the length of the longest strictly increasing subsequence\nin the provided sequence of integers.", "function_declaration": "def longest_increasing_subsequence(sequence):", "function_name": "longest_increasing_subsequence", "parameter_list": "(sequence)" }, { "docstrin...
[ 0, 1, 1, 0, 0, 0, 1, 1, 0 ]
4
medium
0.444
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def longest_increasing_subsequence_length(seq):\n \"\"\"\n Returns the length of the longest strictly increasing subsequence in the sequence.\n \"\"\"\n ...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00000584", "row_id": 584, "seed_ids": "[985]" }
0.835797
Apps_584
I
[ "longest_increasing_subsequence", "parse_input", "find_lis_length_from_input" ]
3
[ [ "find_lis_length_from_input", "longest_increasing_subsequence" ], [ "find_lis_length_from_input", "parse_input" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
422a99bc4be7db48b55c414560319d4f8933ceef
0c0e00757dd1ec0a5a542a5fd4e6c39afc77774d
v1.0
instruct
Apps
Apps_636_I
You are given an integer array `A`. Create an array `B` such that for each element `B[i]`, the value is equal to the number of elements in `A` that are less than or equal to `A[i]`. -----Input----- The first line contains an integer `n` (1 ≤ n ≤ 10^5), the number of elements in array `A`. The second line contains `n...
def count_less_equal_elements(A): """ Returns an array B such that for each element B[i], the value is equal to the number of elements in A that are less than or equal to A[i]. """ sorted_A = sorted(A) B = [] for num in A: count = binary_search_find_count(sorted_A, num) B.app...
from solution import count_less_equal_elements def test_sample_case_1(): assert count_less_equal_elements([4, 2, 9, 1, 7]) == [3, 2, 5, 1, 4] def test_sample_case_2(): assert count_less_equal_elements([3, 3, 3]) == [3, 3, 3] def test_single_element(): assert count_less_equal_elements([5]) == [1] def tes...
[ { "docstring": "Returns an array B such that for each element B[i], the value is equal to the number\nof elements in A that are less than or equal to A[i].", "function_declaration": "def count_less_equal_elements(A):", "function_name": "count_less_equal_elements", "parameter_list": "(A)" }, { ...
[ 1, 1, 0, 1, 1, 1, 0, 0, 0, 1 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def calculate_b(A):\n \"\"\"\n Given an array A, calculate array B such that each B[i] is the number of elements in A that are less than or equal to A[i].\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00000636", "row_id": 636, "seed_ids": "[2197]" }
0.736082
Apps_636
I
[ "count_less_equal_elements", "binary_search_find_count" ]
2
[ [ "count_less_equal_elements", "binary_search_find_count" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6647b864e7c7656dc82d50e4cf23cdb188580d00
3a94ae695e09a73988f46eec0f428cd3c8314911
v1.0
instruct
Apps
Apps_669_I
Richard is planning a vacation and wants to visit several cities. He has a list of cities and the distances between each pair of cities. Richard wants to find a route that will allow him to visit all cities exactly once and return to the starting city with the minimum total distance traveled. This is a classical Travel...
from itertools import permutations def calculate_tsp(n, matrix): def calculate_path_length(path): total_length = 0 for i in range(len(path) - 1): total_length += matrix[path[i]][path[i+1]] total_length += matrix[path[-1]][path[0]] return total_length cities = list(r...
from solution import tsp_solver def test_example_case(): input_str = "2\n4\n0 10 15 20\n10 0 35 25\n15 35 0 30\n20 25 30 0\n3\n0 5 9\n5 0 10\n9 10 0\n" expected_output = [80, 24] assert tsp_solver(input_str) == expected_output def test_single_case(): input_str = "1\n3\n0 1 2\n1 0 3\n2 3 0\n" expec...
[ { "docstring": null, "function_declaration": "def calculate_tsp(n, matrix):", "function_name": "calculate_tsp", "parameter_list": "(n, matrix)" }, { "docstring": null, "function_declaration": "def find_min_tsp_distances(T, test_cases):", "function_name": "find_min_tsp_distances", ...
[ 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "import itertools\n\ndef traveling_salesman(matrix, n):\n min_path = float('inf')\n cities = list(range(n))\n \n for perm in itertools.permutations(citie...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00000669", "row_id": 669, "seed_ids": "[1602]" }
0.702411
Apps_669
I
[ "calculate_tsp", "find_min_tsp_distances", "parse_input", "tsp_solver" ]
4
[ [ "find_min_tsp_distances", "calculate_tsp" ], [ "tsp_solver", "find_min_tsp_distances" ], [ "tsp_solver", "parse_input" ] ]
3
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
57400b0fd9d3f684d49f027873518ac3d5058e9c
c3d8b86ca2fac1e7efa175136c103fda3f46d8a3
v1.0
instruct
Apps
Apps_694_I
You are given a grid with $n$ rows and $m$ columns. Each cell in the grid is either empty, contains an obstacle, or contains a treasure. You need to find the shortest path from the top-left corner of the grid to the bottom-right corner, collecting as many treasures as possible on your way. You can move in four directi...
from collections import deque def find_shortest_path(n, m, grid): # Directions for moving up, down, left, right directions = [(-1, 0), (1, 0), (0, -1), (0, 1)] def is_valid(x, y): return 0 <= x < n and 0 <= y < m and grid[x][y] != '#' visited = [[[False, 0] for _ in range(m)] for _ in...
import pytest from solution import shortest_path_with_treasures def test_example_case(): n, m = 5, 5 grid = [ "T...T", ".#.#.", "T.....", ".#.#.", "T...T" ] assert shortest_path_with_treasures(n, m, grid) == "8 3" def test_no_path(): n, m = 3, 3 grid = [...
[ { "docstring": null, "function_declaration": "def find_shortest_path(n, m, grid):", "function_name": "find_shortest_path", "parameter_list": "(n, m, grid)" }, { "docstring": null, "function_declaration": "def shortest_path_with_treasures(n, m, grid):", "function_name": "shortest_path...
[ 0, 0, 1, 1, 0, 0, 0, 0, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef bfs(grid, n, m):\n if grid[0][0] == '#' or grid[n-1][m-1] == '#':\n return -1, 0\n \n directions = [(-1, 0), (1...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00000694", "row_id": 694, "seed_ids": "[91]" }
0.676315
Apps_694
I
[ "find_shortest_path", "shortest_path_with_treasures" ]
2
[ [ "shortest_path_with_treasures", "find_shortest_path" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4ac8cb31b095876afaa0795b2d2c5ee466c9d5a0
f075cd58f6bd79448232b3eee3a34181b4ceb521
v1.0
instruct
Apps
Apps_773_I
A common cryptography technique involves encoding messages in unexpected places. For this task, you will use a set of dominoes to encode and decode messages. A standard set of dominoes includes 28 tiles, each representing a pair of numbers between 0 and 6. For example, a domino tile might represent the pair (0,0), (3...
import math from functools import reduce def message_to_number(message): """ Convert message to a number base 36 """ base_36 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" number = 0 for char in message: number = number * 36 + base_36.index(char) return number def number_to_message(number): ...
from solution import encode, decode def test_encode_valid_message(): message = "HELLO" encoded = encode(message) assert isinstance(encoded, list) assert len(encoded) == 28 assert all(isinstance(tile, tuple) for tile in encoded) assert all(0 <= a <= 6 and 0 <= b <= 6 and a <= b for a, b in encod...
[ { "docstring": "Convert message to a number base 36 ", "function_declaration": "def message_to_number(message):", "function_name": "message_to_number", "parameter_list": "(message)" }, { "docstring": "Convert a number to a message base 36 ", "function_declaration": "def number_to_message...
[ 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\nfrom string import ascii_uppercase, digits\n\n# All unique tiles in a standard domino set\nALL_TILES = [(i, j) for i in range(7) for j in range(i, 7)]\...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00000773", "row_id": 773, "seed_ids": "[1793]" }
0.538919
Apps_773
I
[ "message_to_number", "number_to_message", "factorial", "encode", "decode" ]
5
[ [ "decode", "number_to_message" ], [ "encode", "factorial" ], [ "encode", "message_to_number" ] ]
3
[]
false
[]
false
pytest
true
[]
true
d44a1ef3a4528f3de59d36eb435cf54f0277de4e
5c857b01d6a6efea30756cc7d554817d23369e89
v1.0
instruct
Apps
Apps_808_I
## Circular Prime Checker A circular prime is a prime number that, in any cyclic permutation of its digits, results in a prime number. For example, 197 is a circular prime because 197, 971, and 719 are all primes. You need to write a function to determine if a given number is a circular prime. ### Input - An intege...
def is_prime(n): """ Check if a number is a prime. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False for i in range(3, int(n**0.5) + 1, 2): if n % i == 0: return False return True def rotate_number(n): ...
from solution import is_circular_prime def test_single_digit_prime(): assert is_circular_prime(2) == True assert is_circular_prime(3) == True assert is_circular_prime(5) == True assert is_circular_prime(7) == True def test_single_digit_non_prime(): assert is_circular_prime(1) == False assert i...
[ { "docstring": "Check if a number is a prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Generate all rotations of a number.", "function_declaration": "def rotate_number(n):", "function_name": "rotate_number",...
[ 0, 1, 0, 0, 1, 0, 0, 1, 1, 1 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n if num <= 1:\n return False\n if num == 2:\n return True\n if num % 2 == 0:\n return False\n for i in range(3,...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00000808", "row_id": 808, "seed_ids": "[1757]" }
0.702839
Apps_808
I
[ "is_prime", "rotate_number", "is_circular_prime" ]
3
[ [ "is_circular_prime", "is_prime" ], [ "is_circular_prime", "rotate_number" ] ]
2
[]
false
[]
false
pytest
true
[]
true
5b8e3d91bb1bcc765d9205c3d2d72ff10c00ebe1
63c9bd6cf40f47e2e8d8488eb5a7d0b29a82cb1a
v1.0
instruct
Apps
Apps_820_I
# Task Joe and Sam love playing card games. They are particularly fascinated by a game that involves a special sequence in the deck. The deck contains cards numbered from 1 to `n`. Joe and Sam noticed that the cards form an interesting pattern when divided into separate parts. The game begins with separating the cards...
def is_prime(x): """ Helper function that determines if a number is prime. """ if x <= 1: return False if x <= 3: return True if x % 2 == 0 or x % 3 == 0: return False i = 5 while i * i <= x: if x % i == 0 or x % (i + 2) == 0: return False ...
from solution import is_prime, has_prime_in_parts def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(29) == True assert is_prime(1) == False assert is_prime(-3) == False def test_has_prime_in_parts(): assert has_prime_in_p...
[ { "docstring": "Helper function that determines if a number is prime.", "function_declaration": "def is_prime(x):", "function_name": "is_prime", "parameter_list": "(x)" }, { "docstring": "Determine if there is at least one part containing a prime number \nwhen the cards numbered 1 to n are d...
[ 0, 1, 0, 1, 1, 0, 1, 0, 1, 1 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef is_prime(x):\n if x <= 1:\n return False\n if x <= 3:\n return True\n if x % 2 == 0 or x % 3 == 0:\n return False\n...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00000820", "row_id": 820, "seed_ids": "[4182]" }
0.583216
Apps_820
I
[ "is_prime", "has_prime_in_parts" ]
2
[ [ "has_prime_in_parts", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
877222bf72bb8faafc33f16402bccd38d1e68be2
7e150c160557dd269ed2b53311fb105036f9fe32
v1.0
instruct
Apps
Apps_847_I
You are required to implement a function that takes a list of integers and returns a list consisting of all the prime numbers found within the given list. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. ### Tests ```python filter_primes([10, 15, 3, 7, 9]) # => [...
def is_prime(n): """ Helper function to check if a number n is prime. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False for i in range(3, int(n**0.5) + 1, 2): if n % i == 0: return False return True def filter_prim...
from solution import is_prime, filter_primes def test_is_prime(): assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(1) == False assert is_prime(2) == True assert is_prime(29) == True assert is_prime(0) == False assert is_prime(-3) == False...
[ { "docstring": "Helper function to check if a number n is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Filters the prime numbers from the given list lst.", "function_declaration": "def filter_primes(lst):", ...
[ 1, 1, 1, 1, 1, 1, 1, 1, 0, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n for i in range(2, int(nu...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00000847", "row_id": 847, "seed_ids": "[4881]" }
0.705416
Apps_847
I
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a4df44c3c367b1eeaf127dd29421eaed1ab115fa
9e100676bd1e977fa1878975acee8f950aeae5a3
v1.0
instruct
Apps
Apps_858_I
# Task You are given a list of integers. Your task is to find the smallest positive integer that is a multiple of every number in the list. Write a function that takes a list of integers and returns this smallest positive integer. # Example ``` For the input list [2, 3, 4], the output should be 12. Explanation: 12 i...
import math from functools import reduce def lcm(a, b): """ Returns the Least Common Multiple (LCM) of two integers a and b. """ return abs(a * b) // math.gcd(a, b) def smallest_multiple(numbers): """ Returns the smallest positive integer that is a multiple of every number in the list. """...
import pytest from solution import smallest_multiple def test_example_case(): assert smallest_multiple([2, 3, 4]) == 12 def test_same_numbers(): assert smallest_multiple([5, 5, 5]) == 5 def test_prime_numbers(): assert smallest_multiple([2, 3, 5, 7]) == 210 def test_mixed_numbers(): assert smallest_...
[ { "docstring": "Returns the Least Common Multiple (LCM) of two integers a and b.", "function_declaration": "def lcm(a, b):", "function_name": "lcm", "parameter_list": "(a, b)" }, { "docstring": "Returns the smallest positive integer that is a multiple of every number in the list.", "func...
[ 1, 0, 1, 1, 1, 1, 1, 1, 0, 1 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef smallest_multiple(numbers):\n \"\"\"\n Returns the smallest positive integer that is a multiple of every number in the list.\n \"\"\"\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00000858", "row_id": 858, "seed_ids": "[4544]" }
0.682838
Apps_858
I
[ "lcm", "smallest_multiple" ]
2
[ [ "smallest_multiple", "lcm" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a19b04b9b49760a6dab754545eef6f095d7d28f4
aa193f553df71224708d8aab8dff148d87c74904
v1.0
instruct
Apps
Apps_876_I
John is attempting to create a program that checks whether a given string is a palindrome. A palindrome is a word that reads the same backward as forward. However, his program should ignore case and non-alphanumeric characters while checking for palindromes. Write a function to determine if a given string is a palindr...
import re def is_palindrome(S): """ Determines if the given string S is a palindrome, ignoring case and non-alphanumeric characters. """ # Clean the string, keep only alphanumeric characters and convert to lowercase clean_s = re.sub(r'[^A-Za-z0-9]', '', S).lower() # Check if the cleaned string ...
from solution import is_palindrome, check_palindromes def test_is_palindrome(): assert is_palindrome("A man, a plan, a canal: Panama") == True assert is_palindrome("race a car") == False assert is_palindrome("No lemon, no melon") == True assert is_palindrome("Madam In Eden, I’m Adam") == True asser...
[ { "docstring": "Determines if the given string S is a palindrome, ignoring case and non-alphanumeric characters.", "function_declaration": "def is_palindrome(S):", "function_name": "is_palindrome", "parameter_list": "(S)" }, { "docstring": "Given T strings, determines for each if it is a pal...
[ 1, 0, 1, 1, 1, 1, 1, 1, 0, 1 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "import re\n\ndef is_palindrome(s):\n \"\"\"\n Checks if the given string s is a palindrome, considering only alphanumeric characters and ignoring cases.\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00000876", "row_id": 876, "seed_ids": "[661]" }
0.7717
Apps_876
I
[ "is_palindrome", "check_palindromes" ]
2
[ [ "check_palindromes", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
760678701c54e04247d45e0f816547c548f7397d
5e45b23416b70c9efa530b527f16cccbfc9b47f9
v1.0
instruct
Apps
Apps_984_I
A large distribution company stores a vast array of products in its warehouses, each product identified by a SKU (Stock Keeping Unit) and stored in specific quantities. The management wants to optimize their storage by identifying products with quantities above a certain threshold quickly. This way, products needing re...
def products_above_threshold(test_cases): results = [] for test_case in test_cases: N, quantities, Q, queries = test_case quantities.sort() for threshold in queries: count = len(quantities) - binary_search(quantities, threshold) results.append(count) ...
from solution import parse_input, products_above_threshold, binary_search def test_parse_input(): input_string = "1\n5\n10 20 15 5 30\n3\n10 15 25" test_cases = parse_input(input_string) assert test_cases == [(5, [10, 20, 15, 5, 30], 3, [10, 15, 25])] def test_binary_search(): arr = [5, 10, 15, 20, 30...
[ { "docstring": null, "function_declaration": "def products_above_threshold(test_cases):", "function_name": "products_above_threshold", "parameter_list": "(test_cases)" }, { "docstring": null, "function_declaration": "def binary_search(arr, x):", "function_name": "binary_search", ...
[ 1, 1, 0, 1, 1, 1, 0, 0, 1, 1 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def optimize_storage_for_queries(T, test_cases):\n results = []\n \n for i in range(T):\n N = test_cases[i]['N']\n quantities = test_cases[i]...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00000984", "row_id": 984, "seed_ids": "[615]" }
0.710154
Apps_984
I
[ "products_above_threshold", "binary_search", "parse_input" ]
3
[ [ "products_above_threshold", "binary_search" ] ]
1
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
69f689c411ec77618a54e3002a24371980b823b9
c09f313e1b40dcd55f076a7337bbd0bd4b4142f5
v1.0
instruct
Apps
Apps_998_I
In a world of virtual cities, there are N cities connected by M bidirectional roads. Each road has a length associated with it. The task is to help travelers find the shortest path from one city to another, given that they have a list of travel queries. -----Input----- - The first line of the input contains two intege...
import heapq def dijkstra(graph, start, n): distances = [float('inf')] * (n + 1) distances[start] = 0 priority_queue = [(0, start)] while priority_queue: current_distance, current_city = heapq.heappop(priority_queue) if current_distance > distances[current_city]: continue ...
def test_example_case(): n = 5 roads = [ (1, 2, 3), (1, 3, 5), (2, 3, 2), (3, 4, 4), (2, 4, 6), (4, 5, 1) ] queries = [ (1, 5), (2, 4), (3, 1) ] expected_output = [10, 6, 5] assert shortest_paths(n, roads, queries) == ex...
[ { "docstring": null, "function_declaration": "def dijkstra(graph, start, n):", "function_name": "dijkstra", "parameter_list": "(graph, start, n)" }, { "docstring": null, "function_declaration": "def shortest_paths(n, roads, queries):", "function_name": "shortest_paths", "paramete...
[ 1, 0, 1, 1, 1, 1, 0, 1, 1, 1 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef dijkstra(graph, start, n):\n distances = [float('inf')] * (n + 1)\n distances[start] = 0\n priority_queue = [(0, start)]\n \n whi...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00000998", "row_id": 998, "seed_ids": "[1478]" }
0.836068
Apps_998
I
[ "dijkstra", "shortest_paths" ]
2
[ [ "shortest_paths", "dijkstra" ] ]
1
[]
false
[]
false
pytest
false
[]
true
cfb42591d4ba6f486630ab4e1c94db7c2e27d0db
b229b4d853277bad51bfba970f6a04e5a4a094e3
v1.0
instruct
Apps
Apps_1027_I
Write a function that receives a list of integers and returns a list of booleans where each boolean represents if the corresponding integer in the input list is a prime number. The input to the function will be a list of positive integers. For example: is_prime_list([2, 3, 4, 5, 10]) => [True, True, False, True,...
def is_prime(n): """ Helper function that checks if a number n is prime. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False for i in range(3, int(n**0.5) + 1, 2): if n % i == 0: return False return True def is_prime...
def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(10) == False assert is_prime(0) == False assert is_prime(1) == False assert is_prime(17) == True def test_is_prime_list(): assert is_prim...
[ { "docstring": "Helper function that checks if a number n is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list of booleans where each boolean indicates if the corresponding number in the input list is p...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 =...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00001027", "row_id": 1027, "seed_ids": "[2725]" }
0.754009
Apps_1027
I
[ "is_prime", "is_prime_list" ]
2
[ [ "is_prime_list", "is_prime" ] ]
1
[]
false
[]
false
pytest
false
[]
true
d91374cec8bf4138afc1d81c230a81412e55641c
4e96e917ae3d37628f237f9e949c0f6c487de21e
v1.0
instruct
Apps
Apps_1051_I
Sarah loves to organize her bookshelf. She has a list of book titles and she wants to sort them alphabetically. However, she prefers to see the book titles in a way that each alternate word in the title is capitalized, starting from the first word. Write a function that takes a list of book titles and returns a new lis...
def alternate_capitalization(title): words = title.split() formatted_words = [word.capitalize() if i % 2 == 0 else word.lower() for i, word in enumerate(words)] return ' '.join(formatted_words) def format_books(titles): sorted_titles = sorted(titles) formatted_titles = [alternate_capitalization(tit...
from solution import format_books, alternate_capitalization def test_alternate_capitalization(): assert alternate_capitalization("the great gatsby") == "The great Gatsby" assert alternate_capitalization("to kill a mockingbird") == "To kill A mockingbird" assert alternate_capitalization("pride and prejudice...
[ { "docstring": null, "function_declaration": "def alternate_capitalization(title):", "function_name": "alternate_capitalization", "parameter_list": "(title)" }, { "docstring": null, "function_declaration": "def format_books(titles):", "function_name": "format_books", "parameter_l...
[ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def alternate_capitalization(title):\n words = title.split()\n formatted_words = [word.capitalize() if i % 2 == 0 else word.lower() for i, word in enumerate(w...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00001051", "row_id": 1051, "seed_ids": "[4067]" }
0.58316
Apps_1051
I
[ "alternate_capitalization", "format_books" ]
2
[ [ "format_books", "alternate_capitalization" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1aa6d795422c0b41ce1663fc0e5b6672e92428bf
10d6c165f23c3241928e994cf75d026eaf7942f2