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
Prefill
Prefill_39971_I
Write a python function to find the kth largest number in an unsorted array using the quickselect algorithm with a time complexity of O(n).
import random def partition(arr, left, right, pivot_index): pivot_value = arr[pivot_index] arr[pivot_index], arr[right] = arr[right], arr[pivot_index] store_index = left for i in range(left, right): if arr[i] < pivot_value: arr[store_index], arr[i] = arr[i], arr[store_index] ...
from solution import find_kth_largest def test_find_kth_largest(): assert find_kth_largest([3,2,1,5,6,4], 2) == 5 assert find_kth_largest([3,2,3,1,2,4,5,5,6], 4) == 4 assert find_kth_largest([3,2,1], 1) == 3 assert find_kth_largest([7,6,5,4,3,2,1], 7) == 1 assert find_kth_largest([5,5,5,5,5,5,5], 3...
[ { "docstring": null, "function_declaration": "def partition(arr, left, right, pivot_index):", "function_name": "partition", "parameter_list": "(arr, left, right, pivot_index)" }, { "docstring": null, "function_declaration": "def quickselect(arr, left, right, k):", "function_name": "q...
[ 1, 1, 1, 1, 0, 1, 1, 1, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def quickselect(arr, k):\n def partition(left, right, pivot_index):\n pivot_value = arr[pivot_index]\n arr[pivot_index], arr[right] = arr[right], arr[pivot_index] \n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00039971", "row_id": 39971, "seed_ids": "['magpie_prefill_39971']" }
0.622952
Prefill_39971
I
[ "partition", "quickselect", "find_kth_largest" ]
3
[ [ "find_kth_largest", "quickselect" ], [ "quickselect", "partition" ] ]
2
[]
false
[]
false
pytest
true
[]
true
3d85a9dc43566b7526f520a1e69f942ab6d12c79
8df6c07c9191e38e9ed6147074e02b20e739c5f7
v1.0
instruct
Prefill
Prefill_39984_I
Write a python function to extract emails from a given text file. The text files are in a directory named "Emails" in the user's home directory. The function should return a list of all emails found.
import os import re def extract_emails_from_file(file_path): """ Extracts emails from a given text file. Parameters: - file_path: str, the path to the text file. Returns: - List[str], a list of emails found in the text file. """ with open(file_path, 'r', encoding='utf-8') as file:...
import pytest import os from solution import extract_emails_from_file, extract_emails_from_directory # Setup directories and files for testing @pytest.fixture def setup_test_files(tmpdir): dir = tmpdir.mkdir('Emails') file1 = dir.join('file1.txt') file2 = dir.join('file2.txt') file1.write("Here ar...
[ { "docstring": "Extracts emails from a given text file.\n\nParameters:\n- file_path: str, the path to the text file.\n\nReturns:\n- List[str], a list of emails found in the text file.", "function_declaration": "def extract_emails_from_file(file_path):", "function_name": "extract_emails_from_file", "...
[ 1, 0, 0, 1, 1, 0, 1, 1, 1 ]
6
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import re\nimport os\n\ndef extract_emails_from_file(file_path):\n \"\"\"\n Extracts emails from a given text file and returns a list of emails found.\n \n :param file_path: Path ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00039984", "row_id": 39984, "seed_ids": "['magpie_prefill_39984']" }
0.549385
Prefill_39984
I
[ "extract_emails_from_file", "extract_emails_from_directory" ]
2
[ [ "extract_emails_from_directory", "extract_emails_from_file" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f50191f6d27db32ce6fc315e05bab8308b775a6c
7b79605a0eae5e32a8e4d6d321816d99d69952f1
v1.0
instruct
Prefill
Prefill_40013_I
Write a python function to solve the N-Queens puzzle using backtracking. The function should take an integer `n` as input and return all possible configurations of the Queen's positions.
def solve_n_queens(n): def is_valid(board, row, col): # Check this column for i in range(row): if board[i] == col or \ board[i] - i == col - row or \ board[i] + i == col + row: return False return True def solve(row, board): ...
from solution import solve_n_queens, solve_n_queens_boards def test_solve_n_queens_4(): result = solve_n_queens(4) assert sorted(result) == sorted([ [1, 3, 0, 2], [2, 0, 3, 1] ]) def test_solve_n_queens_boards_4(): result = solve_n_queens_boards(4) expected = [ ['.Q..', '...
[ { "docstring": null, "function_declaration": "def solve_n_queens(n):", "function_name": "solve_n_queens", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def generate_board(configuration):", "function_name": "generate_board", "parameter_list": "(configura...
[ 1, 1, 1, 0, 1, 1, 1, 1, 0, 0 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def solve_n_queens(n):\n \"\"\"\n Solves the n-queens puzzle and returns all unique solutions.\n Each solution contains one line for each queen.\n Each line contains the queen's c...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00040013", "row_id": 40013, "seed_ids": "['magpie_prefill_40013']" }
0.442877
Prefill_40013
I
[ "solve_n_queens", "generate_board", "solve_n_queens_boards" ]
3
[ [ "solve_n_queens_boards", "generate_board" ], [ "solve_n_queens_boards", "solve_n_queens" ] ]
2
[]
false
[]
false
pytest
true
[]
true
94ac7a4b063034b10c0982ec2aced5d32c483cca
558759116ceded1b9e3adcffa2820ef130b9c27b
v1.0
instruct
Prefill
Prefill_40052_I
Write a python function to sort an array in-place using both merge sort and quick sort. Both sorting algorithms should return the sorted array.
def merge_sort(arr): if len(arr) > 1: mid = len(arr) // 2 left_half = arr[:mid] right_half = arr[mid:] merge_sort(left_half) merge_sort(right_half) i = j = k = 0 while i < len(left_half) and j < len(right_half): if left_h...
from solution import merge_sort, quick_sort def test_merge_sort(): assert merge_sort([3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5]) == [1, 1, 2, 3, 3, 4, 5, 5, 5, 6, 9] assert merge_sort([0, -1, 5, 3, 8, -2]) == [-2, -1, 0, 3, 5, 8] assert merge_sort([]) == [] assert merge_sort([5]) == [5] assert merge_sort([1...
[ { "docstring": null, "function_declaration": "def merge_sort(arr):", "function_name": "merge_sort", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "def quick_sort(arr):", "function_name": "quick_sort", "parameter_list": "(arr)" }, { "docstring":...
[ 1, 0, 1, 1, 1, 1, 1, 1, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def merge_sort(arr):\n \"\"\"\n Sorts the array in-place using merge sort.\n \"\"\"\n def merge(left, right):\n result = []\n i = j = 0\n \n while i < ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00040052", "row_id": 40052, "seed_ids": "['magpie_prefill_40052']" }
0.685082
Prefill_40052
I
[ "merge_sort", "quick_sort", "_quick_sort", "partition" ]
4
[ [ "_quick_sort", "partition" ], [ "quick_sort", "_quick_sort" ] ]
2
[]
false
[]
false
pytest
true
[]
true
a6c557c3485340b15509e32dbffed6062c928526
6031d5a27475fc58d22f88261cc9db7e3c763885
v1.0
instruct
Prefill
Prefill_40070_I
Write a python function to find the product of all the prime numbers in a given list.
def is_prime(num): """ Helper function to determine if a number is prime. """ if num <= 1: return False for i in range(2, int(num**0.5) + 1): if num % i == 0: return False return True def product_of_primes(nums): """ Returns the product of all the prime numbe...
from solution import is_prime, product_of_primes def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(13) == True assert is_prime(1) == False assert is_prime(-7) == False def test_product_of_primes_no_primes(): assert produc...
[ { "docstring": "Helper function to determine if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns the product of all the prime numbers in the given list.\nIf there are no prime numbers, returns...
[ 1, 1, 1, 1, 1, 1, 0, 0, 1, 1 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"\n Checks if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n for i in range(2, int(num ** 0.5) + 1):\n if num % i == 0:\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00040070", "row_id": 40070, "seed_ids": "['magpie_prefill_40070']" }
0.680286
Prefill_40070
I
[ "is_prime", "product_of_primes" ]
2
[ [ "product_of_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4eeb5ef8d9c924db97d69fe19b34dfbbd40a9080
3ebb9e5ccc48fe2e2d4a3e5e0a9a767d8fe81283
v1.0
instruct
Prefill
Prefill_40168_I
Write a python function to print all the prime numbers between 100 and 200.
def is_prime(num): """ Helper function to check if a number is prime. """ if num <= 1: return False for i in range(2, int(num ** 0.5) + 1): if num % i == 0: return False return True def primes_between_100_and_200(): """ Returns a list of all prime numbers bet...
from solution import is_prime, primes_between_100_and_200 def test_is_prime(): assert is_prime(101) == True assert is_prime(102) == False assert is_prime(103) == True assert is_prime(1) == False assert is_prime(2) == True assert is_prime(200) == False assert is_prime(199) == True def test_...
[ { "docstring": "Helper function to check if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns a list of all prime numbers between 100 and 200.", "function_declaration": "def primes_between_...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def get_primes_between_100_and_200():\n \"\"\"\n Returns a list of all prime numbers between 100 and 200.\n \"\"\"\n def is_prime(n):\n \"\"\"Check if a number is prime.\"\...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00040168", "row_id": 40168, "seed_ids": "['magpie_prefill_40168']" }
0.695382
Prefill_40168
I
[ "is_prime", "primes_between_100_and_200" ]
2
[ [ "primes_between_100_and_200", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
04a7c6238876e83b5a9cb16e4a69e702b6279073
8c800647825044cdc0c1b05832245198007183e0
v1.0
instruct
Prefill
Prefill_40319_I
Write a python function to sort a list of integers in Ascending Order using the Quick Sort Algorithm. The function should also print the sorted array.
def quick_sort(arr): """ Sorts a list of integers in ascending order using the Quick Sort algorithm. Prints the sorted array. """ if len(arr) <= 1: return arr else: pivot = arr[0] less_than_pivot = [x for x in arr[1:] if x <= pivot] greater_than_pivot = [x for x i...
from solution import sort_and_print def test_sort_empty_list(): assert sort_and_print([]) == [] def test_sort_single_element(): assert sort_and_print([5]) == [5] def test_sort_sorted_list(): assert sort_and_print([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] def test_sort_reverse_sorted_list(): assert sort_an...
[ { "docstring": "Sorts a list of integers in ascending order using the Quick Sort algorithm.\nPrints the sorted array.", "function_declaration": "def quick_sort(arr):", "function_name": "quick_sort", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "def sort_and_p...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def quick_sort(arr):\n \"\"\"\n Sorts a list of integers in ascending order using the Quick Sort algorithm.\n \"\"\"\n if len(arr) <= 1:\n return arr\n else:\n pi...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00040319", "row_id": 40319, "seed_ids": "['magpie_prefill_40319']" }
0.667676
Prefill_40319
I
[ "quick_sort", "sort_and_print" ]
2
[ [ "sort_and_print", "quick_sort" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7e4c19e07cd41f95baf62af328bdd1aaaefe885f
db53ac546ad087d67dd5d901f5324579b9b95783
v1.0
instruct
Prefill
Prefill_40482_I
Write a python function to implement a basic feed-forward neural network from scratch using numpy. The function should take parameters for the number of input features, number of hidden layers, number of neurons in hidden layers, and number of output classes.
import numpy as np def sigmoid(x): return 1 / (1 + np.exp(-x)) def feed_forward_nn(input_features, hidden_layers, hidden_neurons, output_classes): np.random.seed(0) # Initialize weights and biases for the input to first hidden layer weights_hidden = [np.random.randn(input_features, hidden_neurons...
from solution import feed_forward_nn def test_single_input(): nn = feed_forward_nn(3, 2, 4, 2) X = np.array([1.0, 2.0, 3.0]) result = nn(X) assert result.shape == (2,) def test_multiple_inputs(): nn = feed_forward_nn(4, 3, 5, 3) X = np.array([[1.0, 2.0, 3.0, 4.0], [0.5, 0.6, 0.7, 0.8]]) re...
[ { "docstring": null, "function_declaration": "def sigmoid(x):", "function_name": "sigmoid", "parameter_list": "(x)" }, { "docstring": null, "function_declaration": "def feed_forward_nn(input_features, hidden_layers, hidden_neurons, output_classes):", "function_name": "feed_forward_nn...
[ 0, 1, 0, 1, 1, 1, 0, 1, 1, 0 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import numpy as np\n\ndef sigmoid(x):\n return 1 / (1 + np.exp(-x))\n\ndef sigmoid_derivative(x):\n return x * (1 - x)\n\ndef feed_forward_nn(input_features, hidden_layers, neurons_per_...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00040482", "row_id": 40482, "seed_ids": "['magpie_prefill_40482']" }
0.376813
Prefill_40482
I
[ "sigmoid", "feed_forward_nn" ]
2
[ [ "feed_forward_nn", "sigmoid" ] ]
1
[]
false
[]
false
pytest
true
[ "numpy" ]
false
77315a8b7e37b86768a194fddc1beff63e1a9a1c
ebc5b2b3708f6f299d6153ada02261cd706e653b
v1.0
instruct
Prefill
Prefill_40751_I
Write a python function to flatten a nested list. The function should take a list that may contain integers, strings, other lists, and dictionaries as elements, and return a flat list with no nested structures. Non-iterable elements should remain unchanged. Dictionaries will be unpacked into a sequence of key-value pai...
def is_non_iterable(element): """ Check if the element is non-iterable (besides strings). """ return isinstance(element, (int, float, complex, bool, bytes, type(None))) def flatten(nested_list): """ Flattens a nested list. Non-iterable elements are left unchanged. Dictionaries are unpacked into tup...
from solution import flatten def test_flatten_simple_list(): assert flatten([1, 2, 3]) == [1, 2, 3] def test_flatten_mixed_list(): assert flatten([1, [2, 3], 'a', {'k': 'v'}]) == [1, 2, 3, 'a', ('k', 'v')] def test_flatten_nested_list(): assert flatten([1, [2, [3, 4], 5], 6]) == [1, 2, 3, 4, 5, 6] def t...
[ { "docstring": "Check if the element is non-iterable (besides strings). ", "function_declaration": "def is_non_iterable(element):", "function_name": "is_non_iterable", "parameter_list": "(element)" }, { "docstring": "Flattens a nested list. Non-iterable elements are left unchanged.\nDictiona...
[ 0, 1, 0, 1, 1, 1, 1, 1, 0, 1 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def flatten(nested_list):\n \"\"\"\n Flattens a nested list. The function takes a list that may contain integers, strings, other lists,\n and dictionaries as elements, and returns a ...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00040751", "row_id": 40751, "seed_ids": "['magpie_prefill_40751']" }
0.781007
Prefill_40751
I
[ "is_non_iterable", "flatten" ]
2
[ [ "flatten", "is_non_iterable" ] ]
1
[]
false
[]
false
pytest
true
[]
true
fe5eb5fa8450b2412a2f06deff6aece7c0a9fba0
b7a569db85ebaf0ef318759ecb33bc6aa3c0306a
v1.0
instruct
Prefill
Prefill_40768_I
Write a python function to determine if a given number is prime or not, and iterate over all the numbers from 1 to 100 to print whether each number is prime or not.
def is_prime(n): """ Returns True if n is a prime number, otherwise False. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False ...
from solution import is_prime def test_is_prime_small_numbers(): assert is_prime(1) == False assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False def test_is_prime_larger_primes(): assert is_prime(29) == True assert is_prime(89) == True def test_is_prime_large...
[ { "docstring": "Returns True if n is a prime number, otherwise False.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Prints whether each number from 1 to 100 is prime or not.", "function_declaration": "def print_prime...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Determines if a given number n is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 =...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00040768", "row_id": 40768, "seed_ids": "['magpie_prefill_40768']" }
0.781003
Prefill_40768
I
[ "is_prime", "print_prime_status_up_to_100" ]
2
[ [ "print_prime_status_up_to_100", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d92a8e13391cc4e4e3df4912bc3169312ad21a5c
c781910e61f0929e614ed8281ae1371c61e6aa81
v1.0
instruct
Prefill
Prefill_40866_I
Write a python function to check if a given number is perfect or not. Write a script to test the function and print all perfect numbers between a user-input range.
def is_perfect_number(n): """ Check if the given number n is a perfect number. A perfect number is a positive integer that is equal to the sum of its proper divisors excluding itself. """ if n < 2: return False divisors_sum = sum(i for i in range(1, n) if n % i == 0) return divisors_...
from solution import is_perfect_number, find_perfect_numbers_in_range def test_is_perfect_number(): assert is_perfect_number(6) == True assert is_perfect_number(28) == True assert is_perfect_number(496) == True assert is_perfect_number(12) == False assert is_perfect_number(1) == False assert is...
[ { "docstring": "Check if the given number n is a perfect number.\nA perfect number is a positive integer that is equal to the sum of its proper divisors excluding itself.", "function_declaration": "def is_perfect_number(n):", "function_name": "is_perfect_number", "parameter_list": "(n)" }, { ...
[ 0, 1, 1, 0, 0, 1, 0, 1, 1, 0 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_perfect_number(n):\n \"\"\"\n Check if a given number is a perfect number.\n A perfect number is a positive integer that is equal to the sum of its proper divisors,\n exclu...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00040866", "row_id": 40866, "seed_ids": "['magpie_prefill_40866']" }
0.608266
Prefill_40866
I
[ "is_perfect_number", "find_perfect_numbers_in_range" ]
2
[ [ "find_perfect_numbers_in_range", "is_perfect_number" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3c482bac0076046cfb01b4fb79fd7332e8212bbb
f822717c0a26bcd1af3a837f0233e2f6b5f8e474
v1.0
instruct
Prefill
Prefill_40983_I
Write a python function to find the largest sum of contiguous subarray within a 2D array, following LeetCode problem 213. House Robber II.
def largest_contiguous_sum_2d(array): """ Function to find the largest sum of contiguous subarray within a 2D array. """ if not array or not array[0]: return 0 rows, cols = len(array), len(array[0]) max_sum = float('-inf') for left in range(cols): temp = [0] * rows ...
from solution import largest_contiguous_sum_2d def test_largest_contiguous_sum_2d(): assert largest_contiguous_sum_2d([ [1, 2, -1, -4, -20], [-8, -3, 4, 2, 1], [3, 8, 10, 1, 3], [-4, -1, 1, 7, -6] ]) == 29 assert largest_contiguous_sum_2d([ [-1, -2, -3], [-4...
[ { "docstring": "Function to find the largest sum of contiguous subarray within a 2D array.", "function_declaration": "def largest_contiguous_sum_2d(array):", "function_name": "largest_contiguous_sum_2d", "parameter_list": "(array)" }, { "docstring": "Helper function to find the largest sum o...
[ 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_subarray_sum(arr):\n def kadane_algorithm(lst):\n # Helper function for finding max sum of 1D array using Kadane's algorithm\n max_current = max_global = lst[0]\n ...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00040983", "row_id": 40983, "seed_ids": "['magpie_prefill_40983']" }
0.670139
Prefill_40983
I
[ "largest_contiguous_sum_2d", "max_sum_1d" ]
2
[ [ "largest_contiguous_sum_2d", "max_sum_1d" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1a8745378383671dbcad8c1314d9236f2ac8aed5
ab89f96c019bfb9f44ec1bcbf2650d7c15980d16
v1.0
instruct
Prefill
Prefill_41007_I
Write a python function to simulate the board game "Deuces Wild," a pinochle variant where the deck is composed of two full decks of cards (60 cards in total), and wild cards are treated as deuces (2s). The function should deal cards to a specified number of players and simulate a round of bidding where players bid on ...
import random from collections import Counter def create_deck(): """ Creates a deck of cards, doubling to make 120 cards (two full decks). """ suits = ['Hearts', 'Diamonds', 'Clubs', 'Spades'] ranks = ['2', '3', '4', '5', '6', '7', '8', '9', '10', 'Jack', 'Queen', 'King', 'Ace'] deck = [(rank, ...
from solution import create_deck, deal_cards, simulate_bidding, deuces_wild def test_create_deck(): deck = create_deck() assert len(deck) == 104 # 2 decks of 52 cards each def test_deal_cards(): deck = create_deck() hands = deal_cards(deck, 4) assert len(hands) == 4 assert all(len(hand) == 26...
[ { "docstring": "Creates a deck of cards, doubling to make 120 cards (two full decks).", "function_declaration": "def create_deck():", "function_name": "create_deck", "parameter_list": "()" }, { "docstring": "Shuffles the deck and deals cards to the specified number of players.", "functio...
[ 0, 1, 0, 1, 1, 1, 0, 1, 1, 1 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef generate_deck():\n \"\"\"\n Generates and returns a deck of pinochle cards including two decks combined.\n \"\"\"\n suits = ['hearts', 'diamonds', 'clubs', 's...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00041007", "row_id": 41007, "seed_ids": "['magpie_prefill_41007']" }
0.532153
Prefill_41007
I
[ "create_deck", "deal_cards", "simulate_bidding", "deuces_wild" ]
4
[ [ "deuces_wild", "create_deck" ], [ "deuces_wild", "deal_cards" ], [ "deuces_wild", "simulate_bidding" ] ]
3
[]
false
[]
false
pytest
true
[]
true
af6e47fbc2932eb4499e7171f83cb0ec2a132106
e19f019150be19d6bea1211a6082194afa56256a
v1.0
instruct
Prefill
Prefill_41058_I
Write a python function to convert a linked list to a binary tree, and then add an element to the binary tree, making sure the tree remains balanced.
class TreeNode: def __init__(self, value=0, left=None, right=None): self.value = value self.left = left self.right = right class ListNode: def __init__(self, value=0, next=None): self.value = value self.next = next def sorted_list_to_bst(head): """ Converts a so...
from solution import TreeNode, ListNode, linked_list_to_balanced_bst_with_insertion def test_linked_list_to_balanced_bst_with_insertion(): head = ListNode(1) head.next = ListNode(2) head.next.next = ListNode(3) head.next.next.next = ListNode(4) head.next.next.next.next = ListNode(5) new_va...
[]
[ 1, 1, 1, 1, 1, 0, 1, 0, 0, 1 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "class ListNode:\n def __init__(self, value=0, next=None):\n self.value = value\n self.next = next\n\nclass TreeNode:\n def __init__(self, value=0, left=None, right=None):\...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00041058", "row_id": 41058, "seed_ids": "['magpie_prefill_41058']" }
0.666428
Prefill_41058
I
[ "sorted_list_to_bst", "insert_into_bst", "balance_bst", "linked_list_to_balanced_bst_with_insertion" ]
4
[ [ "linked_list_to_balanced_bst_with_insertion", "balance_bst" ], [ "linked_list_to_balanced_bst_with_insertion", "insert_into_bst" ], [ "linked_list_to_balanced_bst_with_insertion", "sorted_list_to_bst" ] ]
3
[]
false
[ "TreeNode", "ListNode" ]
true
pytest
true
[]
true
8ecccb34a12776e1aff6177f79e37d30c2ae6317
744395474defb5f2a19ee64befef45ca80e5c918
v1.0
instruct
Prefill
Prefill_41127_I
Write a python function to check if a number is even or odd. How would you use this function in your code? Provide a sample usage scenario.
def is_even(number): """ Returns True if number is even, otherwise returns False. """ return number % 2 == 0 # Sample usage scenario: def filter_even_numbers(numbers): """ Filters out odd numbers from a list and returns only even numbers. """ return [num for num in numbers if is_even(nu...
from solution import is_even, filter_even_numbers def test_is_even_with_even_numbers(): assert is_even(2) == True assert is_even(0) == True assert is_even(100) == True def test_is_even_with_odd_numbers(): assert is_even(1) == False assert is_even(7) == False assert is_even(55) == False def te...
[ { "docstring": "Returns True if number is even, otherwise returns False.", "function_declaration": "def is_even(number):", "function_name": "is_even", "parameter_list": "(number)" }, { "docstring": "Filters out odd numbers from a list and returns only even numbers.", "function_declaratio...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_even_or_odd(number):\n \"\"\"\n Returns 'even' if the number is even, otherwise returns 'odd'.\n \"\"\"\n if number % 2 == 0:\n return 'even'\n else:\n ret...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00041127", "row_id": 41127, "seed_ids": "['magpie_prefill_41127']" }
0.776758
Prefill_41127
I
[ "is_even", "filter_even_numbers" ]
2
[ [ "filter_even_numbers", "is_even" ] ]
1
[]
false
[]
false
pytest
true
[]
true
302e0e20f4aa1b93a9b9d27cd9d9c96f8e6f8a07
5f60702e380569045690d506573589146b11ad30
v1.0
instruct
Prefill
Prefill_41269_I
Write a python function to find the nth Fibonacci number. The nth Fibonacci number is defined as the sum of the two preceding ones, usually starting with 0 and 1. Your function should be optimized to reduce its time complexity to logarithmic.
def multiply_matrices(A, B): """ Multiplies two matrices A and B. """ return [ [A[0][0] * B[0][0] + A[0][1] * B[1][0], A[0][0] * B[0][1] + A[0][1] * B[1][1]], [A[1][0] * B[0][0] + A[1][1] * B[1][0], A[1][0] * B[0][1] + A[1][1] * B[1][1]], ] def matrix_power(matrix, n): """ C...
from solution import fibonacci def test_fibonacci_base_cases(): assert fibonacci(0) == 0 assert fibonacci(1) == 1 def test_fibonacci_small_inputs(): assert fibonacci(2) == 1 assert fibonacci(3) == 2 assert fibonacci(4) == 3 assert fibonacci(5) == 5 def test_fibonacci_larger_inputs(): asse...
[ { "docstring": "Multiplies two matrices A and B.", "function_declaration": "def multiply_matrices(A, B):", "function_name": "multiply_matrices", "parameter_list": "(A, B)" }, { "docstring": "Computes the power of a 2x2 matrix using exponentiation by squaring.", "function_declaration": "d...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def fibonacci(n):\n \"\"\"\n Returns the nth Fibonacci number using matrix exponentiation.\n \"\"\"\n if n <= 0:\n return 0\n elif n == 1:\n return 1\n\n def m...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00041269", "row_id": 41269, "seed_ids": "['magpie_prefill_41269']" }
0.798545
Prefill_41269
I
[ "multiply_matrices", "matrix_power", "fibonacci" ]
3
[ [ "fibonacci", "matrix_power" ], [ "matrix_power", "multiply_matrices" ] ]
2
[]
false
[]
false
pytest
true
[]
true
a0345d7b73f57beff9a1f9d4548878731c41ba32
c69d51d28b24a3e96422a1c45a22818b3ae9365e
v1.0
instruct
Prefill
Prefill_41283_I
Write a python function to reverse a string using slicing, then write a function to check if the string is a palindrome or not.
def reverse_string(s): """ Returns the reversed string of 's' using slicing. """ return s[::-1] def is_palindrome(s): """ Returns True if the string 's' is a palindrome, False otherwise. A string is a palindrome if it reads the same forwards and backwards. """ return s == reverse_st...
from solution import reverse_string, is_palindrome def test_reverse_string(): assert reverse_string("hello") == "olleh" assert reverse_string("world") == "dlrow" assert reverse_string("a") == "a" assert reverse_string("") == "" assert reverse_string("madam") == "madam" def test_is_palindrome(): ...
[ { "docstring": "Returns the reversed string of 's' using slicing.", "function_declaration": "def reverse_string(s):", "function_name": "reverse_string", "parameter_list": "(s)" }, { "docstring": "Returns True if the string 's' is a palindrome, False otherwise.\nA string is a palindrome if it...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def reverse_string(s):\n \"\"\"\n Reverses the given string using slicing.\n \"\"\"\n return s[::-1]\n\ndef is_palindrome(s):\n \"\"\"\n Checks if the given string is a pali...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00041283", "row_id": 41283, "seed_ids": "['magpie_prefill_41283']" }
0.784272
Prefill_41283
I
[ "reverse_string", "is_palindrome" ]
2
[ [ "is_palindrome", "reverse_string" ] ]
1
[]
false
[]
false
pytest
true
[]
true
587cce52f8e74ef60c5c7344ad7d15199dbbf2ea
970a7e5915fb699a41e33c8b335b2dbfcb7683df
v1.0
instruct
Prefill
Prefill_41295_I
Write a python function to implement the find the closest pair of points in a 2D plane. The function should return the distance between the two closest points.
import math def distance(point1, point2): """ Returns the Euclidean distance between two points. """ return math.sqrt((point1[0] - point2[0]) ** 2 + (point1[1] - point2[1]) ** 2) def closest_pair_of_points(points): """ Returns the smallest distance between two closest points in a given list of...
from solution import closest_pair_of_points def test_closest_pair_basic(): points = [(0,0), (1,1), (4,5), (13,14)] assert math.isclose(closest_pair_of_points(points), math.sqrt(2), rel_tol=1e-9) def test_closest_pair_single(): points = [(0,0)] assert closest_pair_of_points(points) == float('inf') def...
[ { "docstring": "Returns the Euclidean distance between two points.", "function_declaration": "def distance(point1, point2):", "function_name": "distance", "parameter_list": "(point1, point2)" }, { "docstring": "Returns the smallest distance between two closest points in a given list of 2D po...
[ 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef euclidean_distance(point1, point2):\n \"\"\"\n Calculate the Euclidean distance between two points.\n \"\"\"\n return math.sqrt((point1[0] - point2[0]) ** 2 + (...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00041295", "row_id": 41295, "seed_ids": "['magpie_prefill_41295']" }
0.613449
Prefill_41295
I
[ "distance", "closest_pair_of_points" ]
2
[ [ "closest_pair_of_points", "distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
abd4f4f7c34528fbb032b942205ea4811d4f9ae8
4a949aa0820d60c226c614e5a4e2d9ef740caa0f
v1.0
instruct
Prefill
Prefill_41302_I
Write a python function to find and print all the pairs of prime numbers that sum up to N, where N is a given even number. If no such pairs exist, print "No such pair exists".
def is_prime(num): """ Helper function to check if a number is prime. """ if num <= 1: return False for i in range(2, int(num**(0.5)) + 1): if num % i == 0: return False return True def prime_pairs_sum(N): """ Returns a list of all pairs of prime numbers that...
from solution import prime_pairs_sum def test_prime_pairs_sum_with_valid_pairs(): assert prime_pairs_sum(10) == [(3, 7), (5, 5)] assert prime_pairs_sum(12) == [(5, 7)] assert prime_pairs_sum(26) == [(3, 23), (7, 19), (13, 13)] def test_prime_pairs_sum_no_pairs(): assert prime_pairs_sum(2) == "No such ...
[ { "docstring": "Helper function to check if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns a list of all pairs of prime numbers that sum up to N.\nIf no such pairs exist, returns an empty li...
[ 1, 0, 1, 0, 1, 1, 0, 1, 0, 1 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_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(num**(0.5)) + 1):\n if...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00041302", "row_id": 41302, "seed_ids": "['magpie_prefill_41302']" }
0.665993
Prefill_41302
I
[ "is_prime", "prime_pairs_sum" ]
2
[ [ "prime_pairs_sum", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
fdf0c4f3232fd205cc76bfaa530457d5cfbcd728
2e2b4e5d6d05aeaa7a43b0ee6ec0483f19dc7e40
v1.0
instruct
Prefill
Prefill_41446_I
Write a python function to find the biggest Fibonacci numbers that can be written as the sum of two smaller Fibonacci numbers.
def is_fibonacci_number(n): """ Check if a number is a Fibonacci number using the property that a number n is Fibonacci if and only if one or both of (5*n^2 + 4) or (5*n^2 - 4) is a perfect square. """ return is_perfect_square(5 * n * n + 4) or is_perfect_square(5 * n * n - 4) def is_perfect_squar...
from solution import largest_fibonacci_as_sum def test_largest_fibonacci_as_sum(): result = largest_fibonacci_as_sum() assert result == 832040, f"Expected 832040 but got {result}" def test_is_fibonacci_number(): assert is_fibonacci_number(8) == True assert is_fibonacci_number(13) == True assert is...
[ { "docstring": "Check if a number is a Fibonacci number using the property that a number n \nis Fibonacci if and only if one or both of (5*n^2 + 4) or (5*n^2 - 4) is a perfect square.", "function_declaration": "def is_fibonacci_number(n):", "function_name": "is_fibonacci_number", "parameter_list": "...
[ 0, 0, 1, 0, 0, 0, 1, 0, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def fibonacci_sum_max(limit):\n \"\"\"\n Returns the largest Fibonacci number that can be written as the sum of two smaller Fibonacci numbers, up to a given limit.\n \n Parameters...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00041446", "row_id": 41446, "seed_ids": "['magpie_prefill_41446']" }
0.651908
Prefill_41446
I
[ "is_fibonacci_number", "is_perfect_square", "generate_fibonacci_up_to", "largest_fibonacci_as_sum" ]
4
[ [ "is_fibonacci_number", "is_perfect_square" ], [ "largest_fibonacci_as_sum", "generate_fibonacci_up_to" ] ]
2
[]
false
[]
false
pytest
true
[]
true
e26a6824eddb37371eebb3b0eadd89010b874caf
156fbb2117e8a2e7c3f1006f8618fe81737f2fbe
v1.0
instruct
Prefill
Prefill_41526_I
Write a python function to print all prime numbers between two given numbers. The function should take two integers as arguments and print all the prime numbers that fall between the smaller number and the larger number, inclusive.
def is_prime(n): """ Helper function to check if a number is prime. """ if n <= 1: return False for i in range(2, int(n ** 0.5) + 1): if n % i == 0: return False return True def print_primes_between(a, b): """ Prints all prime numbers between two given number...
from solution import is_prime, print_primes_between def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(13) == True assert is_prime(1) == False assert is_prime(0) == False assert is_prime(-5) == False def test_print_primes_...
[ { "docstring": "Helper function to check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Prints all prime numbers between two given numbers a and b inclusive.", "function_declaration": "def print_...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def print_primes_between(a, b):\n \"\"\"\n Prints all prime numbers between two given numbers (inclusive).\n \"\"\"\n def is_prime(n):\n if n <= 1:\n return Fals...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00041526", "row_id": 41526, "seed_ids": "['magpie_prefill_41526']" }
0.696025
Prefill_41526
I
[ "is_prime", "print_primes_between" ]
2
[ [ "print_primes_between", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
cd1b26f02fa70b8d8b2bf9f9ae95e1358f23aec0
1935f7a403cabd7d3f130fb0967b55c4c3424715
v1.0
instruct
Prefill
Prefill_41530_I
Write a python function to calculate the sum of the prime numbers within a given range. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself.
def is_prime(n): """ Check if a number is a prime number. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 re...
from solution import is_prime, sum_of_primes_in_range 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(29) == True assert is_prime(1) == False assert is_prime(0) == False assert is_prime(-5)...
[ { "docstring": "Check if a number is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Calculate the sum of prime numbers within a given range [start, end].", "function_declaration": "def sum_of_primes_in...
[ 0, 0, 1, 0, 1, 1, 1, 0, 1, 1 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00041530", "row_id": 41530, "seed_ids": "['magpie_prefill_41530']" }
0.7196
Prefill_41530
I
[ "is_prime", "sum_of_primes_in_range" ]
2
[ [ "sum_of_primes_in_range", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5b7c6654a0cce4aace0a1fb7f28022f7209c6476
871a1435c4175fbf9b03ef7c148a90e7e77952ab
v1.0
instruct
Prefill
Prefill_41731_I
Write a python function to implement the mergesort algorithm. Merge sort is a divide-and-conquer algorithm that divides the input array into two halves, calls itself for the two halves, and then merges the two sorted halves. The merge() function is used for merging two halves.
def merge_sort(arr): """ Implements the merge sort algorithm on the input list. Parameters: - arr (list): The list of elements to be sorted. Returns: - list: A new sorted list. """ if len(arr) <= 1: return arr # Divide the array into two halves mid = len(ar...
from solution import merge_sort def test_merge_sort_empty(): assert merge_sort([]) == [] def test_merge_sort_single_element(): assert merge_sort([1]) == [1] def test_merge_sort_sorted_list(): assert merge_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] def test_merge_sort_reverse_list(): assert merge_sort(...
[ { "docstring": "Implements the merge sort algorithm on the input list.\n\nParameters:\n- arr (list): The list of elements to be sorted.\n\nReturns:\n- list: A new sorted list.", "function_declaration": "def merge_sort(arr):", "function_name": "merge_sort", "parameter_list": "(arr)" }, { "doc...
[ 1, 1, 1, 1, 1, 0, 1, 1, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def merge_sort(arr):\n \"\"\"\n Implement merge sort algorithm to sort an array.\n \n :param arr: List of integers\n :return: New sorted list of integers\n \"\"\"\n if le...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00041731", "row_id": 41731, "seed_ids": "['magpie_prefill_41731']" }
0.639274
Prefill_41731
I
[ "merge_sort", "merge" ]
2
[ [ "merge_sort", "merge" ] ]
1
[]
false
[]
false
pytest
true
[]
true
bb0f332fe998825b3a693591db53f6a1ad44ba6a
3f87e27ab4bda1c9bfaf1f4e0c55be50016359a4
v1.0
instruct
Prefill
Prefill_42088_I
Write a python function to find the largest palindrome which is a product of two n-digit numbers. For example, if n=2, the function should return the largest palindrome product of two 2-digit numbers (i.e., between 10 and 99).
def is_palindrome(num): return str(num) == str(num)[::-1] def largest_palindrome_product(n): """ Returns the largest palindrome made from the product of two n-digit numbers. """ if n < 1: raise ValueError("n must be greater than or equal to 1") start = 10 ** (n - 1) end = 10 **...
from solution import largest_palindrome_product def test_largest_palindrome_product_1_digit(): assert largest_palindrome_product(1) == 9 # 1 * 9 = 9 or 3 * 3 = 9 def test_largest_palindrome_product_2_digits(): assert largest_palindrome_product(2) == 9009 # 91 * 99 = 9009 def test_largest_palindrome_product...
[ { "docstring": null, "function_declaration": "def is_palindrome(num):", "function_name": "is_palindrome", "parameter_list": "(num)" }, { "docstring": "Returns the largest palindrome made from the product of two n-digit numbers.", "function_declaration": "def largest_palindrome_product(n)...
[ 1, 0, 1, 1, 1, 1, 0, 0, 0, 0 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_palindrome(number):\n \"\"\"\n Checks if a given number is a palindrome.\n \"\"\"\n return str(number) == str(number)[::-1]\n\ndef largest_palindrome_product(n):\n \"\"\...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00042088", "row_id": 42088, "seed_ids": "['magpie_prefill_42088']" }
0.737171
Prefill_42088
I
[ "is_palindrome", "largest_palindrome_product" ]
2
[ [ "largest_palindrome_product", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9bd4967cf5cf2a8299966739723863cba79f96fd
7a241959717a31db6e775421ed2f517f49c3d942
v1.0
instruct
Prefill
Prefill_42177_I
Write a python function to reverse the elements of a stack.
def reverse_stack(stack): """ Reverses the elements of the stack. Parameters: stack (list): A list representing the stack. Returns: list: The stack with its elements reversed. """ if not stack: return [] temp = stack.pop() reversed_stack = reverse_stack(stack) ...
from solution import reverse_stack def test_reverse_stack_empty(): assert reverse_stack([]) == [] def test_reverse_stack_single_element(): assert reverse_stack([1]) == [1] def test_reverse_stack_two_elements(): assert reverse_stack([1, 2]) == [2, 1] def test_reverse_stack_multiple_elements(): assert...
[ { "docstring": "Reverses the elements of the stack.\n\nParameters:\nstack (list): A list representing the stack.\n\nReturns:\nlist: The stack with its elements reversed.", "function_declaration": "def reverse_stack(stack):", "function_name": "reverse_stack", "parameter_list": "(stack)" }, { ...
[ 0, 1, 1, 0, 1, 1, 1, 1, 1, 1 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "class Stack:\n def __init__(self):\n self.items = []\n \n def is_empty(self):\n return len(self.items) == 0\n \n def push(self, item):\n self.items.append(...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00042177", "row_id": 42177, "seed_ids": "['magpie_prefill_42177']" }
0.607216
Prefill_42177
I
[ "reverse_stack", "insert_at_bottom" ]
2
[ [ "reverse_stack", "insert_at_bottom" ] ]
1
[]
false
[]
false
pytest
true
[]
true
232483806675c8a9090c58190279f247ce8181a2
9a38c89971a6fd6f770db7940b0c28f4d85b0093
v1.0
instruct
Prefill
Prefill_42191_I
Write a python function to find the k-th smallest element in an array using a divide and conquer approach.
def kth_smallest(arr, l, r, k): """ Finds the k-th smallest element in the array using the QuickSelect algorithm. """ if k > 0 and k <= r - l + 1: pos = partition(arr, l, r) if pos - l == k - 1: return arr[pos] if pos - l > k - 1: return kth_smallest(arr,...
from solution import kth_smallest def test_kth_smallest_basic(): arr = [12, 3, 5, 7, 19] assert kth_smallest(arr, 0, len(arr) - 1, 2) == 5 def test_kth_smallest_single_element(): arr = [10] assert kth_smallest(arr, 0, len(arr) - 1, 1) == 10 def test_kth_smallest_large_k(): arr = [4, 2, 6, 3, 9] ...
[ { "docstring": "Finds the k-th smallest element in the array using the QuickSelect algorithm.", "function_declaration": "def kth_smallest(arr, l, r, k):", "function_name": "kth_smallest", "parameter_list": "(arr, l, r, k)" }, { "docstring": null, "function_declaration": "def partition(ar...
[ 0, 1, 1, 1, 1, 1, 1, 1, 1 ]
8
easy
0.889
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def kth_smallest(arr, k):\n \"\"\"\n Returns the k-th smallest element in the array using the Quickselect algorithm.\n \"\"\"\n def partition(low, high):\n pivot = arr[high...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00042191", "row_id": 42191, "seed_ids": "['magpie_prefill_42191']" }
0.693017
Prefill_42191
I
[ "kth_smallest", "partition" ]
2
[ [ "kth_smallest", "partition" ] ]
1
[]
false
[]
false
pytest
true
[]
true
69c07b41a844a4718dd25ad41935526ffa86c24a
7da512420fe403d5bb804df39a6c2974cbde1e80
v1.0
instruct
Prefill
Prefill_42244_I
Write a python function to solve a known hard puzzle, such as the classic "Sudoku". Explain your code step-by-step.
def is_valid(board, row, col, num): """ Check if 'num' is not in the current row, column and 3x3 sub-board. """ # Check the row for x in range(9): if board[row][x] == num: return False # Check the column for x in range(9): if board[x][col] == num: ret...
def test_solve_sudoku(): board = [ [5, 3, 0, 0, 7, 0, 0, 0, 0], [6, 0, 0, 1, 9, 5, 0, 0, 0], [0, 9, 8, 0, 0, 0, 0, 6, 0], [8, 0, 0, 0, 6, 0, 0, 0, 3], [4, 0, 0, 8, 0, 3, 0, 0, 1], [7, 0, 0, 0, 2, 0, 0, 0, 6], [0, 6, 0, 0, 0, 0, 2, 8, 0], [0, 0, 0, 4, 1...
[ { "docstring": "Check if 'num' is not in the current row, column and 3x3 sub-board.", "function_declaration": "def is_valid(board, row, col, num):", "function_name": "is_valid", "parameter_list": "(board, row, col, num)" }, { "docstring": "Solves the Sudoku puzzle using backtracking.", "...
[ 1, 0, 0, 1, 1, 1, 1, 1, 1 ]
7
easy
0.778
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def solve_sudoku(board):\n \"\"\"\n Solves the given Sudoku puzzle using backtracking.\n \n Parameters:\n board (list of list of int): A 9x9 grid representing the Sudoku pu...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00042244", "row_id": 42244, "seed_ids": "['magpie_prefill_42244']" }
0.48957
Prefill_42244
I
[ "is_valid", "solve_sudoku" ]
2
[ [ "solve_sudoku", "is_valid" ] ]
1
[]
false
[]
false
pytest
false
[]
true
5713b4a9dfec32ccdb67d91960f87c8a9bcb4d2a
e71f44829d02a021e6077dd0da64f4353bb34b1b
v1.0
instruct
Prefill
Prefill_42280_I
Write a python function to solve the 8 puzzle problem using a breadth-first search algorithm.
from collections import deque # Representation of Puzzle Board (3x3) GOAL_STATE = (1, 2, 3, 4, 5, 6, 7, 8, 0) # Goal state represented in a 1D tuple with 0 as the blank space def get_possible_moves(state): """ Return a list of possible moves for the blank space. """ size = 3 # Since it's 8-puzzle, s...
from solution import bfs_solve_8_puzzle, GOAL_STATE def test_solved_puzzle(): start_state = GOAL_STATE assert bfs_solve_8_puzzle(start_state) == [] def test_one_move_to_solve(): start_state = (1, 2, 3, 4, 5, 6, 7, 0, 8) assert bfs_solve_8_puzzle(start_state) == [GOAL_STATE] def test_already_solved():...
[ { "docstring": "Return a list of possible moves for the blank space.", "function_declaration": "def get_possible_moves(state):", "function_name": "get_possible_moves", "parameter_list": "(state)" }, { "docstring": "Solve the 8-puzzle using Breadth-First Search Algorithm.\nReturn the sequence...
[ 0, 0, 1, 1, 0, 0, 1, 0, 1, 0 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef is_solvable(puzzle):\n \"\"\"\n Check if the 8-puzzle is solvable.\n \"\"\"\n puzzle = puzzle.replace(' ', '')\n inv_count = sum(\n ...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00042280", "row_id": 42280, "seed_ids": "['magpie_prefill_42280']" }
0.464787
Prefill_42280
I
[ "get_possible_moves", "bfs_solve_8_puzzle" ]
2
[ [ "bfs_solve_8_puzzle", "get_possible_moves" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e21c8eadb06350b2a3bc41188578e4fe16b78336
f6f5c4a78724da4c94f877c0a719d9f7efb6f3d2
v1.0
instruct
Prefill
Prefill_42480_I
Write a python function to Sum the first N prime numbers. Here N is an input to the function.
def is_prime(num): """ Returns True if the given number 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 sum_first_n_primes def test_sum_first_n_primes(): assert sum_first_n_primes(1) == 2 # First prime number is 2 assert sum_first_n_primes(2) == 5 # First two primes: 2 + 3 assert sum_first_n_primes(3) == 10 # First three primes: 2 + 3 + 5 assert sum_first_n_primes(4) == 17 # First ...
[ { "docstring": "Returns True if the given number is a prime number, otherwise False.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns the sum of the first N prime numbers.", "function_declaration": "def sum_...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_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 < 2:\n return False\n for i in range(2, int(num**0.5) + 1):\n if nu...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00042480", "row_id": 42480, "seed_ids": "['magpie_prefill_42480']" }
0.657388
Prefill_42480
I
[ "is_prime", "sum_first_n_primes" ]
2
[ [ "sum_first_n_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
977e864e208a66083119ed24347e7da1627ed787
44d5ba0d29a6510347b878f53cfa88512db55a5c
v1.0
instruct
Prefill
Prefill_42520_I
Write a python function to solve a given Sudoku puzzle. The Sudoku puzzle is provided as a 9x9 grid of integers, where 0 represents empty cells that need to be filled.
def is_valid(board, row, col, num): for x in range(9): if board[row][x] == num: return False for x in range(9): if board[x][col] == num: return False start_row, start_col = 3 * (row // 3), 3 * (col // 3) for i in range(3): for j in range(3): ...
from solution import solve_sudoku def test_solve_sudoku(): board = [ [5, 3, 0, 0, 7, 0, 0, 0, 0], [6, 0, 0, 1, 9, 5, 0, 0, 0], [0, 9, 8, 0, 0, 0, 0, 6, 0], [8, 0, 0, 0, 6, 0, 0, 0, 3], [4, 0, 0, 8, 0, 3, 0, 0, 1], [7, 0, 0, 0, 2, 0, 0, 0, 6], [0, 6, 0, 0, 0, ...
[ { "docstring": null, "function_declaration": "def is_valid(board, row, col, num):", "function_name": "is_valid", "parameter_list": "(board, row, col, num)" }, { "docstring": null, "function_declaration": "def solve_sudoku(board):", "function_name": "solve_sudoku", "parameter_list...
[ 1, 0, 1, 0, 1, 0, 0, 1, 0, 1 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_valid(board, row, col, num):\n \"\"\"\n Check if num can be placed at board[row][col].\n \"\"\"\n # check row\n for y in range(9):\n if board[row][y] == num:\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00042520", "row_id": 42520, "seed_ids": "['magpie_prefill_42520']" }
0.500295
Prefill_42520
I
[ "is_valid", "solve_sudoku", "find_empty_location" ]
3
[ [ "solve_sudoku", "find_empty_location" ], [ "solve_sudoku", "is_valid" ] ]
2
[]
false
[]
false
pytest
true
[]
true
4b227b09405a6c95f1f2226670f3d4497a61cbce
543bccb6a341a029aac839d2ac51c4af01a492bb
v1.0
instruct
Prefill
Prefill_42528_I
Write a python function to find all the substrings of a given string that contain all the letters from the alphabet at least once, also known as pangrams.
def is_pangram(s): """ Check if the string s is a pangram. A pangram contains every letter of the alphabet at least once. """ alphabet = set("abcdefghijklmnopqrstuvwxyz") return set(s.lower()) >= alphabet def find_pangram_substrings(s): """ Returns all substrings of s that are pangrams....
from solution import find_pangram_substrings, is_pangram def test_is_pangram(): assert is_pangram("The quick brown fox jumps over the lazy dog") assert not is_pangram("Hello World") def test_find_pangram_substrings(): result = find_pangram_substrings("The quick brown fox jumps over the lazy dog") asse...
[ { "docstring": "Check if the string s is a pangram.\nA pangram contains every letter of the alphabet at least once.", "function_declaration": "def is_pangram(s):", "function_name": "is_pangram", "parameter_list": "(s)" }, { "docstring": "Returns all substrings of s that are pangrams.", "...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import string\n\ndef find_pangram_substrings(s):\n \"\"\"\n Returns a list of substrings of the given string 's' which are pangrams.\n \"\"\"\n alphabet_set = set(string.ascii_low...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00042528", "row_id": 42528, "seed_ids": "['magpie_prefill_42528']" }
0.671986
Prefill_42528
I
[ "is_pangram", "find_pangram_substrings" ]
2
[ [ "find_pangram_substrings", "is_pangram" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0fb2d8b074a8fa8d3401d42fe9d08dd62c6f8094
572cf3043d3ee20cef0640c586783439fa985eaf
v1.0
instruct
Prefill
Prefill_42754_I
Write a python function to find the minimum value of the f[x] = (x^2) * sin(x) function in the range [0, pi].
import numpy as np from scipy.optimize import minimize_scalar def f(x): """ Function to evaluate f(x) = (x^2) * sin(x). """ return (x**2) * np.sin(x) def find_minimum_value(): """ Find the minimum value of the function f(x) = (x^2) * sin(x) in the range [0, pi]. """ # Define the range ...
from solution import find_minimum_value def test_minimum_value(): min_value = find_minimum_value() # The minimum value of f(x) = (x^2) * sin(x) in the range [0, pi] should be at the boundaries or at critical points. # After analyzing, the minimum value in the given range should be 0 when x = 0. as...
[ { "docstring": "Function to evaluate f(x) = (x^2) * sin(x).", "function_declaration": "def f(x):", "function_name": "f", "parameter_list": "(x)" }, { "docstring": "Find the minimum value of the function f(x) = (x^2) * sin(x) in the range [0, pi].", "function_declaration": "def find_minim...
[ 0, 0, 0, 1, 0, 0, 0, 1, 1, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import numpy as np\nfrom scipy.optimize import minimize_scalar\n\ndef f(x):\n \"\"\"\n Returns the value of the function f(x) = x^2 * sin(x)\n \"\"\"\n return (x**2) * np.sin(x)\n...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00042754", "row_id": 42754, "seed_ids": "['magpie_prefill_42754']" }
0.615961
Prefill_42754
I
[ "f", "find_minimum_value" ]
2
[ [ "find_minimum_value", "f" ] ]
1
[]
false
[]
false
pytest
true
[ "numpy", "scipy" ]
false
87e4efdc22f836e22967f1797a0fea8bee24a648
a2ae7667de9051de6d57a93b0f3b8ea8d9f233bb
v1.0
instruct
Prefill
Prefill_42828_I
Write a python function to find the N smallest elements in a list using the quicksort algorithm.
def quicksort(arr): """ Quicksort algorithm implementation to sort the list. """ if len(arr) <= 1: return arr pivot = arr[len(arr) // 2] left = [x for x in arr if x < pivot] middle = [x for x in arr if x == pivot] right = [x for x in arr if x > pivot] return quicksort(left) +...
from solution import find_n_smallest_elements def test_find_n_smallest_elements_typical_case(): assert find_n_smallest_elements([5, 2, 9, 1, 5, 6], 3) == [1, 2, 5] def test_find_n_smallest_elements_with_duplicates(): assert find_n_smallest_elements([5, 2, 9, 1, 5, 6, 2, 1], 4) == [1, 1, 2, 2] def test_find_n...
[ { "docstring": "Quicksort algorithm implementation to sort the list.", "function_declaration": "def quicksort(arr):", "function_name": "quicksort", "parameter_list": "(arr)" }, { "docstring": "Returns the N smallest elements in a list using the quicksort algorithm.", "function_declaratio...
[ 1, 1, 0, 0, 0, 1, 1, 1, 1, 1 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def quickselect(arr, n):\n \"\"\"\n Returns the N smallest elements in the list using a modified quicksort algorithm.\n \"\"\"\n if n <= 0:\n return []\n if n >= len(arr...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00042828", "row_id": 42828, "seed_ids": "['magpie_prefill_42828']" }
0.767517
Prefill_42828
I
[ "quicksort", "find_n_smallest_elements" ]
2
[ [ "find_n_smallest_elements", "quicksort" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4ee1697434f5deee63c17d4c4c20023c3e53049e
dd27c95a11470f5efa3678b7725987b370ba0a3a
v1.0
instruct
Prefill
Prefill_42949_I
Write a python function to find the sum of all the prime numbers in a given range from 1 to n (both inclusive).
def is_prime(num): """ Helper function to check if a number is prime. """ if num <= 1: return False if num <= 3: return True if num % 2 == 0 or num % 3 == 0: return False i = 5 while (i * i) <= num: if num % i == 0 or num % (i + 2) == 0: return...
from solution import sum_of_primes def test_sum_of_primes_within_10(): assert sum_of_primes(10) == 17 # Primes are 2, 3, 5, 7 def test_sum_of_primes_within_0(): assert sum_of_primes(0) == 0 # No primes in the range def test_sum_of_primes_within_1(): assert sum_of_primes(1) == 0 # No primes in the rang...
[ { "docstring": "Helper function to check if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns the sum of all the prime numbers from 1 to n (inclusive).", "function_declaration": "def sum_of...
[ 1, 1, 1, 1, 1, 1, 0, 1, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_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 if num <= 3:\n return True\n if num % 2 =...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00042949", "row_id": 42949, "seed_ids": "['magpie_prefill_42949']" }
0.711722
Prefill_42949
I
[ "is_prime", "sum_of_primes" ]
2
[ [ "sum_of_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b0dbf6324bf46d29f13beb79040fe38e7d0e1415
95513055abac3ebc0b655e562420ca817fad290f
v1.0
instruct
Prefill
Prefill_43024_I
Write a python function to iterate over a list and check if each number is a palindrome. If a number is not a palindrome, append it to a separate list. After the loop, return the list containing non-palindrome numbers.
def is_palindrome(n): """ Helper function to check if a number n is a palindrome """ s = str(n) return s == s[::-1] def find_non_palindromes(lst): """ Iterates over the given list lst and returns a list containing non-palindrome numbers. """ non_palindromes = [] for num in ...
from solution import find_non_palindromes, is_palindrome def test_is_palindrome(): assert is_palindrome(121) == True assert is_palindrome(123) == False assert is_palindrome(1) == True assert is_palindrome(22) == True assert is_palindrome(12321) == True assert is_palindrome(12345) == False def ...
[ { "docstring": "Helper function to check if a number n is a palindrome", "function_declaration": "def is_palindrome(n):", "function_name": "is_palindrome", "parameter_list": "(n)" }, { "docstring": "Iterates over the given list lst and returns a list containing \nnon-palindrome numbers.", ...
[ 1, 1, 1, 1, 1, 1, 0, 1, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_palindrome(number):\n \"\"\"\n Check if a given number is a palindrome.\n A number is a palindrome if it reads the same backward as forward.\n \"\"\"\n str_num = str(num...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00043024", "row_id": 43024, "seed_ids": "['magpie_prefill_43024']" }
0.758012
Prefill_43024
I
[ "is_palindrome", "find_non_palindromes" ]
2
[ [ "find_non_palindromes", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
35d0c101c774281d8ee51878ecf5c9d129a4ce8f
18019d618823a7d4b6c46b3545215de3a60f10b6
v1.0
complete
Leetcode
Leetcode_30_C
def is_prime(n: int) -> bool: """ Returns True if n is a prime number, otherwise False. """ pass def sum_of_primes(start: int, end: int) -> int: """ Returns the sum of all prime numbers in the inclusive range [start, end]. If there are no primes in the range, returns 0. >>> sum_of_prim...
def is_prime(n): """ Returns True if n is a prime number, otherwise False. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False ...
from solution import sum_of_primes def test_sum_of_primes_with_primes(): assert sum_of_primes(10, 20) == 60 # primes are 11, 13, 17, 19 def test_sum_of_primes_without_primes(): assert sum_of_primes(14, 16) == 0 # no primes in this range def test_sum_of_primes_with_large_range(): assert sum_of_primes(1...
[ { "docstring": "Returns True if n is a prime number, otherwise False.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns the sum of all prime numbers in the inclusive range [start, end].\nIf there are no primes in the...
[ 1, 0, 1, 1, 1, 1, 0, 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 is_prime(n):\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n return False\n i = 5\n while i * ...
trial_gpt4o_8
{ "original_instruction": "Write a function that receives two integers, `start` and `end`, and returns the **sum of all prime numbers** in the inclusive range `[start, end]`. If there are no prime numbers in the given range, the function should return `0`.", "prompt_id": "0000000030", "row_id": 30, "seed_ids": ...
0.762201
Leetcode_30
C
[ "is_prime", "sum_of_primes" ]
2
[ [ "sum_of_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
94ee149eb451d417e01c25277f774885ac555d91
bf2ed0282978810fc123ec748148dbb41fa753cc
v1.0
complete
Leetcode
Leetcode_31_C
class TreeNode: def __init__(self, value=0, left=None, right=None): self.value = value self.left = left self.right = right def find_lca(root, u, v): if root is None or root.value == u or root.value == v: return root left_lca = find_lca(root.left, u, v) right_lca = find_l...
class TreeNode: def __init__(self, value=0, left=None, right=None): self.value = value self.left = left self.right = right def find_lca(root, u, v): if root is None or root.value == u or root.value == v: return root left_lca = find_lca(root.left, u, v) right_lca = find_l...
from solution import TreeNode, path_sum def create_test_tree(): # Create a simple tree for testing: # 1 # / \ # 2 3 # /| |\ # 4 5 6 7 root = TreeNode(1) root.left = TreeNode(2) root.right = TreeNode(3) root.left.left = TreeNode(4) root.lef...
[]
[ 0, 0, 0, 0, 0, 1, 0, 0, 0, 1 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "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...
trial_gpt4o_9
{ "original_instruction": "You are given a binary tree with `n` nodes where each node has a value represented by an integer. You need to perform `q` queries on this tree. Each query consists of two integers, `u` and `v`, representing two nodes in the tree. For each query, find and return the sum of values of all node...
0.623484
Leetcode_31
C
[ "find_lca", "path_sum", "sum_values_on_path" ]
3
[ [ "path_sum", "find_lca" ], [ "path_sum", "sum_values_on_path" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
55f546329ce21b2795d0692ae739af13550a8f4e
256ad21511a10108f256ac83486876a1dfba659e
v1.0
complete
Leetcode
Leetcode_141_C
from typing import List def num_similar_groups(words: List[str], equiv: List[List[str]]) -> int: """Return the number of distinct equivalence classes within the list of words. >>> num_similar_groups(["abc", "def", "ghi"], []) == 3 >>> num_similar_groups(["abc", "def", "abf"], [['a', 'd'], ['b', 'e'], ['c',...
from collections import defaultdict def find_representative(graph, char): # Find the representative parent of the character if graph[char] != char: graph[char] = find_representative(graph, graph[char]) return graph[char] def union(graph, a, b): # Union the sets based on two characters a and b ...
from solution import num_similar_groups def test_no_equivalences(): words = ["abc", "def", "ghi"] equiv = [] assert num_similar_groups(words, equiv) == 3 def test_all_equivalent_chars(): words = ["abc", "def", "abf"] equiv = [['a', 'd'], ['b', 'e'], ['c', 'f']] assert num_similar_groups(words,...
[ { "docstring": null, "function_declaration": "def find_representative(graph, char):", "function_name": "find_representative", "parameter_list": "(graph, char)" }, { "docstring": null, "function_declaration": "def union(graph, a, b):", "function_name": "union", "parameter_list": "...
[ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "from collections import defaultdict\n\ndef find_representative(graph, char):\n # Find the representative parent of the character\n if graph[char] != char:\n grap...
trial_gpt4o_0
{ "original_instruction": "You are given a list of strings `words` where each string consists of lowercase English letters. Two strings `s1` and `s2` are said to be **similar** if: \n* They are of the same length.\n* For every letter at position `i` in `s1`, the letter at position `i` in `s2` is either the same ...
0.631205
Leetcode_141
C
[ "find_representative", "union", "num_similar_groups" ]
3
[ [ "num_similar_groups", "find_representative" ], [ "num_similar_groups", "union" ], [ "union", "find_representative" ] ]
3
[]
false
[]
false
pytest
true
[]
true
3465fafb5835d1505813ecedbfda2139b5ebba1f
57562604a30481052b4082066a2997f77d89920c
v1.0
complete
Leetcode
Leetcode_157_C
def find_longest_concatenated_word(words: List[str]) -> str: """ Find the longest string that can be constructed by concatenating other strings from the list. If there are multiple possible results, return the lexicographically smallest one. >>> find_longest_concatenated_word(["cat", "banana", "dog", "...
def can_construct(word, word_set): if word in word_set: return True for i in range(1, len(word)): prefix = word[:i] suffix = word[i:] if prefix in word_set and can_construct(suffix, word_set): return True return False def find_longest_concatenated_word(words): ...
from solution import find_longest_concatenated_word def test_basic_case(): words = ["cat", "banana", "dog", "nana", "walk", "walker", "dogwalker"] assert find_longest_concatenated_word(words) == "dogwalker" def test_multiple_possible_results(): words = ["rat", "bat", "cat", "ratbatcat", "batcatrat"] a...
[ { "docstring": null, "function_declaration": "def can_construct(word, word_set):", "function_name": "can_construct", "parameter_list": "(word, word_set)" }, { "docstring": null, "function_declaration": "def find_longest_concatenated_word(words):", "function_name": "find_longest_conca...
[ 1, 1, 1, 1, 0, 0, 1, 0, 1, 1 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def find_longest_concatenated_word(words):\n \"\"\"\n Finds the longest word that can be constructed by concatenating other words in the list.\n If there are multipl...
trial_gpt4o_8
{ "original_instruction": "You are given a list of strings `words` where each word consists of lowercase English letters. Your task is to find the longest string in `words` that can be constructed by concatenating other strings from the list. If there are multiple possible results, return the lexicographically smalle...
0.76457
Leetcode_157
C
[ "can_construct", "find_longest_concatenated_word" ]
2
[ [ "find_longest_concatenated_word", "can_construct" ] ]
1
[]
false
[]
false
pytest
true
[]
true
10fe2d898ed1ddacc8ad4f355a9573c8b71cb0fd
06927af33ed121ea9130817d05cb95c2405430f7
v1.0
complete
Leetcode
Leetcode_282_C
def is_one_edit_away(s: str, t: str) -> bool: """ Given two strings s and t consisting of only lowercase alphabets, determine if s can be transformed into t by performing at most one edit. An edit is defined as: 1. Inserting a character 2. Removing a character 3. Replacing a character >>> i...
def is_one_edit_away(s, t): """ Returns True if string s can be transformed into string t by performing at most one edit. An edit is defined as: inserting a character, removing a character, or replacing a character. """ len_s = len(s) len_t = len(t) # If the length difference is more th...
from solution import is_one_edit_away def test_no_edits_needed(): assert is_one_edit_away('abc', 'abc') == True assert is_one_edit_away('', '') == True def test_one_replacement(): assert is_one_edit_away('abc', 'abx') == True assert is_one_edit_away('abcd', 'abcf') == True def test_one_insertion(): ...
[ { "docstring": "Returns True if string s can be transformed into string t by performing at most one edit.\nAn edit is defined as: inserting a character, removing a character, or replacing a character.", "function_declaration": "def is_one_edit_away(s, t):", "function_name": "is_one_edit_away", "para...
[ 0, 0, 1, 0, 0, 0, 0, 1, 1, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_one_edit_distance(s, t):\n \"\"\"\n Returns True if string s can be transformed into string t by performing at most one edit, otherwise False.\n \"\"\"\n l...
trial_gpt4o_7
{ "original_instruction": "Given two strings `s` and `t` consisting of only lowercase alphabets, write a function to determine if `s` can be transformed into `t` by performing at most one edit. An edit is defined as:\n1. Inserting a character\n2. Removing a character\n3. Replacing a character", "prompt_id": "000000...
0.672811
Leetcode_282
C
[ "is_one_edit_away", "check_one_edit_insert_remove" ]
2
[ [ "is_one_edit_away", "check_one_edit_insert_remove" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6bf00afd203bdf516e4f86742374a503f71f1864
5ed14284146980785d1e2a6c63c66a783961546e
v1.0
complete
Leetcode
Leetcode_336_C
def max_sum_rectangle(grid: List[List[int]]) -> int: """ Returns the maximum sum of any rectangle within the given grid. >>> max_sum_rectangle([[2]]) == 2 >>> max_sum_rectangle([ ... [-1, -2], ... [-3, -4] ... ]) == -1 >>> max_sum_rectangle([ ... [2, 1, -3, -4, 5], ... [0, 6, 3, 4, 1...
def max_sum_rectangle(grid): """ Returns the maximum sum of any rectangle within the given grid. """ if not grid or not grid[0]: return 0 max_sum = float('-inf') rows, cols = len(grid), len(grid[0]) for left in range(cols): row_sum = [0] * rows for right in ...
from solution import max_sum_rectangle def test_single_element(): assert max_sum_rectangle([[2]]) == 2 def test_all_negative_elements(): grid = [ [-1, -2], [-3, -4] ] assert max_sum_rectangle(grid) == -1 def test_mixed_elements(): grid = [ [2, 1, -3, -4, 5], [0, 6,...
[ { "docstring": "Returns the maximum sum of any rectangle within the given grid.", "function_declaration": "def max_sum_rectangle(grid):", "function_name": "max_sum_rectangle", "parameter_list": "(grid)" }, { "docstring": "Helper function to find the maximum sum of any contiguous subarray.", ...
[ 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def max_sum_subgrid(grid):\n \"\"\"\n Given a m x n grid containing integers, find the maximum sum of any rectangle within the grid.\n \n :param grid: List[List[i...
trial_gpt4o_4
{ "original_instruction": "Given a `m x n` grid containing integers, you need to find the maximum sum of any rectangle within the grid. The rectangle must be made up of at least one element. Your task is to write a function that returns the maximum possible sum considering all possible rectangles that can be formed w...
0.706942
Leetcode_336
C
[ "max_sum_rectangle", "max_subarray_sum" ]
2
[ [ "max_sum_rectangle", "max_subarray_sum" ] ]
1
[]
false
[]
false
pytest
true
[]
true
da6344c9edee53c35f7ec1e7d3cbae319e0398ea
1e2b7d7e8270b526d5ffaa6647abda02b1959b13
v1.0
complete
Leetcode
Leetcode_468_C
from typing import List def is_balanced_word(word: str) -> bool: """ Checks if a word is balanced. A string is considered "balanced" if every letter it contains appears the same number of times. >>> is_balanced_word("aabbcc") True >>> is_balanced_word("abac") False >>> is_balanced_...
def is_balanced_word(word): """ Checks if a word is balanced. A word is balanced if each character appears the same number of times. """ from collections import Counter char_count = Counter(word) counts = list(char_count.values()) return all(count == counts[0] for count in counts) ...
from solution import check_balanced_words, is_balanced_word def test_is_balanced_word(): assert is_balanced_word("aabbcc") == True assert is_balanced_word("abac") == False assert is_balanced_word("xyzxyz") == True assert is_balanced_word("abcab") == False assert is_balanced_word("") == True # Empt...
[ { "docstring": "Checks if a word is balanced.\n\nA word is balanced if each character appears the same number of times.", "function_declaration": "def is_balanced_word(word):", "function_name": "is_balanced_word", "parameter_list": "(word)" }, { "docstring": "Given a list of words, this func...
[ 0, 1, 0, 1, 0, 0, 0, 0, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_balanced(word):\n \"\"\"\n Check if a word is balanced. A word is balanced if every letter it contains appears the same \n number of times.\n \"\"\"\n f...
trial_gpt4o_3
{ "original_instruction": "You are given a **0-indexed** array `words` of strings. A string is considered \"balanced\" if every letter it contains appears the same number of times. Return an array of the same length as `words` where each element is `true` if the corresponding string in `words` is balanced or `false` ...
0.643377
Leetcode_468
C
[ "is_balanced_word", "check_balanced_words" ]
2
[ [ "check_balanced_words", "is_balanced_word" ] ]
1
[]
false
[]
false
pytest
true
[]
true
76ce9b0f90d5ef79f0579cf0e5eecbecb8092cde
4f59cd776fd1a1cbb51ca3d7c218046ea62c79ac
v1.0
complete
Leetcode
Leetcode_598_C
from typing import List def is_subsequence(s: str, t: str) -> bool: """Check if t is a subsequence of s. >>> is_subsequence("abcde", "ace") True >>> is_subsequence("abcde", "aec") False """ def longest_subsequence(s: str, words: List[str]) -> int: """Return the length of the longest word i...
def is_subsequence(s, t): """ Check if t is a subsequence of s. """ it = iter(s) return all(char in it for char in t) def longest_subsequence(s, words): """ Returns the length of the longest word in the dictionary that is a subsequence of s. """ max_length = 0 for word in words:...
from solution import is_subsequence, longest_subsequence def test_is_subsequence(): assert is_subsequence("abcde", "ace") assert not is_subsequence("abcde", "aec") assert is_subsequence("abc", "abc") assert is_subsequence("abracadabra", "ada") def test_longest_subsequence(): s = "abcde" words ...
[ { "docstring": "Check if t is a subsequence of s.", "function_declaration": "def is_subsequence(s, t):", "function_name": "is_subsequence", "parameter_list": "(s, t)" }, { "docstring": "Returns the length of the longest word in the dictionary that is a subsequence of s.", "function_decla...
[ 1, 1, 0, 1, 1, 0, 0, 1, 1, 1 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_subsequence(s, word):\n \"\"\"\n Checks if `word` is a subsequence of `s`.\n \"\"\"\n it = iter(s)\n return all(char in it for char in word)\n\ndef long...
trial_gpt4o_9
{ "original_instruction": "You are given a string `s` consisting of lowercase alphabets and a dictionary of words `dict` consisting of unique lowercase words. Your task is to find and return the length of the longest word in the dictionary that is a subsequence of `s`. A subsequence is a sequence that can be derived ...
0.718273
Leetcode_598
C
[ "is_subsequence", "longest_subsequence" ]
2
[ [ "longest_subsequence", "is_subsequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
51ec0b4e0fa8a98f6fa45ec0970226be83eac0bd
831eb9f860b729d0d74e8d086bd143163a70227e
v1.0
complete
Leetcode
Leetcode_754_C
def minimum_moves_to_sort(heights: List[int]) -> int: """ Returns the minimum number of moves required to sort the list in increasing order by height. A move consists of picking any person from the list and moving them to any other position in the list. >>> minimum_moves_to_sort([1, 2, 3, 4, 5]) == 0 >...
def minimum_moves_to_sort(heights): """ Returns the minimum number of moves required to sort the list in increasing order by height. """ sorted_heights = sorted(heights) lcs_length = longest_common_subsequence(heights, sorted_heights) return len(heights) - lcs_length def longest_common_subseque...
from solution import minimum_moves_to_sort def test_sorted_list(): assert minimum_moves_to_sort([1, 2, 3, 4, 5]) == 0 def test_reverse_sorted_list(): assert minimum_moves_to_sort([5, 4, 3, 2, 1]) == 4 def test_unsorted_list(): assert minimum_moves_to_sort([3, 1, 2, 5, 4]) == 2 def test_single_element_li...
[ { "docstring": "Returns the minimum number of moves required to sort the list in increasing order by height.", "function_declaration": "def minimum_moves_to_sort(heights):", "function_name": "minimum_moves_to_sort", "parameter_list": "(heights)" }, { "docstring": "Helper function to find the...
[ 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 min_moves_to_sort_heights(heights):\n \"\"\"\n Returns the minimum number of moves required to arrange the list in increasing order by height.\n \"\"\"\n sort...
trial_gpt4o_8
{ "original_instruction": "Given a list of integers `heights`, where each element represents the height of a person, return the minimum number of moves required to arrange the list in increasing order by height. A **move** consists of picking any person from the list and moving them to any other position in the list....
0.611249
Leetcode_754
C
[ "minimum_moves_to_sort", "longest_common_subsequence" ]
2
[ [ "minimum_moves_to_sort", "longest_common_subsequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
68945d5e39a1abf0ce2a28ce0ec347e8d65ab0e1
c9b4b42c60f744cf56866eef8b93ce2ba71cdfe6
v1.0
complete
Leetcode
Leetcode_1326_C
from typing import List def is_pattern_in_all_words(words: List[str], pattern: str) -> List[bool]: """ Determine if the pattern appears as a subsequence in all of the strings within the list. >>> is_pattern_in_all_words(["abcde", "ace", "aec", "bdf"], "ace") [True, True, False, False] >>> is_...
def is_subsequence(pattern, word): """ Determine if the pattern is a subsequence of the word. """ it = iter(word) return all(char in it for char in pattern) def is_pattern_in_all_words(words, pattern): """ Determine if the pattern is a subsequence in each word in the words list. """ ...
from solution import is_pattern_in_all_words def test_is_pattern_in_all_words(): words = ["abcde", "ace", "aec", "bdf"] pattern = "ace" assert is_pattern_in_all_words(words, pattern) == [True, True, False, False] def test_is_pattern_in_all_words_empty_pattern(): words = ["abcde", "ace", "aec", "bdf"] ...
[ { "docstring": "Determine if the pattern is a subsequence of the word.", "function_declaration": "def is_subsequence(pattern, word):", "function_name": "is_subsequence", "parameter_list": "(pattern, word)" }, { "docstring": "Determine if the pattern is a subsequence in each word in the words...
[ 1, 1, 0, 1, 0, 0, 1, 1, 0 ]
5
medium
0.556
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_subsequence(pattern, word):\n \"\"\"\n Helper function that checks if pattern is a subsequence of word.\n \"\"\"\n iter_word = iter(word)\n return all(c...
trial_gpt4o_8
{ "original_instruction": "You are given a list of strings `words` and a string `pattern`. Determine if the pattern appears as a subsequence in all of the strings within the list. A subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the re...
0.678006
Leetcode_1326
C
[ "is_subsequence", "is_pattern_in_all_words" ]
2
[ [ "is_pattern_in_all_words", "is_subsequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
bbfa41c37dc85d2959784cdd8b9243d99bdcb900
fbe5e59b806744e6a6d680b93db3d3ae890cea34
v1.0
complete
Leetcode
Leetcode_1457_C
from typing import List from math import gcd from functools import reduce def gcd_of_list(lst: List[int]) -> int: return reduce(gcd, lst) def max_sum_subsequence_with_gcd(nums: List[int], k: int) -> int: """ Return the maximum possible sum of a non-empty subsequence of nums such that the greatest common ...
from math import gcd from functools import reduce def gcd_of_list(lst): return reduce(gcd, lst) def max_sum_subsequence_with_gcd(nums, k): valid_nums = [num for num in nums if num % k == 0] max_sum = 0 def helper(temp, index): nonlocal max_sum if temp and gcd_of_list(temp) == k: ...
from solution import max_sum_subsequence_with_gcd def test_case_1(): nums = [2, 4, 8, 16] k = 2 assert max_sum_subsequence_with_gcd(nums, k) == 30 # 2 + 4 + 8 + 16 = 30 def test_case_2(): nums = [12, 15, 18, 30, 27] k = 3 assert max_sum_subsequence_with_gcd(nums, k) == 102 # 12 + 15 + 18 + 3...
[ { "docstring": null, "function_declaration": "def gcd_of_list(lst):", "function_name": "gcd_of_list", "parameter_list": "(lst)" }, { "docstring": null, "function_declaration": "def max_sum_subsequence_with_gcd(nums, k):", "function_name": "max_sum_subsequence_with_gcd", "paramete...
[ 0, 0, 1, 0, 1, 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": "import math\nfrom typing import List\n\ndef max_sum_subsequence_with_gcd_k(nums: List[int], k: int) -> int:\n \"\"\"\n Returns the maximum possible sum of a non-empty s...
trial_gpt4o_9
{ "original_instruction": "You are given an array of integers `nums` and an integer `k`. Return the maximum possible sum of a non-empty subsequence of `nums` such that the greatest common divisor (GCD) of the elements of the subsequence is exactly `k`. A **subsequence** is a sequence derived from the array by deletin...
0.645424
Leetcode_1457
C
[ "gcd_of_list", "max_sum_subsequence_with_gcd" ]
2
[ [ "max_sum_subsequence_with_gcd", "gcd_of_list" ] ]
1
[]
false
[]
false
pytest
true
[]
true
086f6062692bf99e5fd601a7f2436b24931614a4
8e556a17348d60e0dc36ddceadb20c3dc4d6d0bf
v1.0
complete
Leetcode
Leetcode_1559_C
def min_moves_to_sort(nums: List[int], k: int) -> int: """ Calculate the minimum number of moves required to sort the array in non-decreasing order where each move consists of a person swapping their position with an adjacent person. Args: nums (List[int]): Array of integers, where nums[i] re...
def count_inversions_and_sort(nums): if len(nums) < 2: return nums, 0 mid = len(nums) // 2 left, left_inversions = count_inversions_and_sort(nums[:mid]) right, right_inversions = count_inversions_and_sort(nums[mid:]) merged, split_inversions = merge_and_count(left, right) total...
from solution import min_moves_to_sort def test_min_moves_to_sort_already_sorted(): assert min_moves_to_sort([1, 2, 3, 4], 1) == 0 def test_min_moves_to_sort_reverse_ordered(): assert min_moves_to_sort([4, 3, 2, 1], 1) == 6 def test_min_moves_to_sort_random_order(): assert min_moves_to_sort([3, 1, 2, 4, ...
[ { "docstring": null, "function_declaration": "def count_inversions_and_sort(nums):", "function_name": "count_inversions_and_sort", "parameter_list": "(nums)" }, { "docstring": null, "function_declaration": "def merge_and_count(left, right):", "function_name": "merge_and_count", "...
[ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def min_moves_to_sort(nums, k):\n \"\"\"\n Returns the minimum number of moves required to sort the array nums in non-decreasing order.\n Each move consists of swapp...
trial_gpt4o_5
{ "original_instruction": "You are given an array `nums` of integers, where `nums[i]` represents the position of the `i`-th person in a line. Each person can only move to a position such that the distance between the person's original and new positions is at most `k` units. Calculate the minimum number of moves requi...
0.65947
Leetcode_1559
C
[ "count_inversions_and_sort", "merge_and_count", "min_moves_to_sort" ]
3
[ [ "count_inversions_and_sort", "merge_and_count" ], [ "min_moves_to_sort", "count_inversions_and_sort" ] ]
2
[]
false
[]
false
pytest
true
[]
true
1c1fe7043c7d3a6a39ce6edcae7c891a628bf3f4
4dfeba03de573f83ef1c2f8e332fc9624f1ea39d
v1.0
complete
Leetcode
Leetcode_1816_C
class ListNode: def __init__(self, val=0, next=None): self.val = val self.next = next def merge_sort_linked_list(head: ListNode) -> ListNode: """ Sort a linked list using merge sort. The function should preserve the original structure and only rearrange the node values. >>> linked_list_...
class ListNode: def __init__(self, val=0, next=None): self.val = val self.next = next def merge_sort_linked_list(head): if not head or not head.next: return head # Find the middle of the linked list slow, fast = head, head.next while fast and fast.next: slow = slow....
from solution import ListNode, merge_sort_linked_list def list_to_linked_list(lst): dummy = ListNode() current = dummy for num in lst: current.next = ListNode(num) current = current.next return dummy.next def linked_list_to_list(node): lst = [] while node: lst.append(no...
[]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
9
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "class ListNode:\n def __init__(self, value=0, next=None):\n self.value = value\n self.next = next\n\ndef merge_sort_list(head):\n if not head or not head....
trial_gpt4o_7
{ "original_instruction": "You are given a linked list where each node contains an integer value. Write a function that returns the head of the linked list after sorting it in ascending order using merge sort. The function should preserve the original structure and only rearrange the node values.", "prompt_id": "00...
0.496411
Leetcode_1816
C
[ "merge_sort_linked_list", "merge" ]
2
[ [ "merge_sort_linked_list", "merge" ] ]
1
[]
false
[ "ListNode" ]
true
pytest
true
[]
true
d0091d076c6778f8a09c122f786b068e88b73b91
9ead42c90770bd61eb5d93069fbc14b745add91c
v1.0
complete
Leetcode
Leetcode_1819_C
from typing import List def min_max_pages(pages: List[int], n: int, k: int) -> int: """ You are given a list of `n` books, where each book has a unique integer `pages[i]` representing the number of pages in the `i`th book. You want to distribute these books to `k` students such that each student gets...
def is_feasible(pages, n, k, max_pages): students_required = 1 current_pages = 0 for i in range(n): if current_pages + pages[i] > max_pages: students_required += 1 current_pages = pages[i] if students_required > k: return False else: ...
from solution import min_max_pages def test_min_max_pages_case1(): pages = [12, 34, 67, 90] n = 4 k = 2 assert min_max_pages(pages, n, k) == 113 def test_min_max_pages_case2(): pages = [10, 20, 30, 40] n = 4 k = 2 assert min_max_pages(pages, n, k) == 60 def test_min_max_pages_case3():...
[ { "docstring": null, "function_declaration": "def is_feasible(pages, n, k, max_pages):", "function_name": "is_feasible", "parameter_list": "(pages, n, k, max_pages)" }, { "docstring": null, "function_declaration": "def min_max_pages(pages, n, k):", "function_name": "min_max_pages", ...
[ 1, 1, 1, 0, 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 is_valid_distribution(pages, n, k, max_pages):\n student_count = 1\n current_pages = 0\n \n for i in range(n):\n if current_pages + pages[i] > max_page...
trial_gpt4o_9
{ "original_instruction": "You are given a list of `n` books, where each book has a unique integer `pages[i]` representing the number of pages in the `i`th book. You want to distribute these books to `k` students such that each student gets at least one book and the maximum number of pages assigned to any student is ...
0.707829
Leetcode_1819
C
[ "is_feasible", "min_max_pages" ]
2
[ [ "min_max_pages", "is_feasible" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5af22c6ccdfb17d964298749fc50b5ece3cb08f3
bae09363c461b140241cf82ec583146ee0a18f3f
v1.0
complete
Leetcode
Leetcode_2622_C
from typing import List def is_valid_password_candidate(s: str) -> bool: """ Checks if the given string s is a valid password candidate. """ contains_digit = any(c.isdigit() for c in s) contains_uppercase = any(c.isupper() for c in s) contains_lowercase = any(c.islower() for c in s) contain...
def is_valid_password_candidate(s): """ Checks if the given string s is a valid password candidate. """ contains_digit = any(c.isdigit() for c in s) contains_uppercase = any(c.isupper() for c in s) contains_lowercase = any(c.islower() for c in s) contains_special = any(c in ['@', '#', '$', '...
from solution import valid_password_candidates def test_valid_password_candidates_with_all_valid(): assert valid_password_candidates(['Abc1@', 'Xyz2$', 'Pwd3!']) == ['Abc1@', 'Xyz2$', 'Pwd3!'] def test_valid_password_candidates_with_none_valid(): assert valid_password_candidates(['abc', 'XYZ123', 'password!',...
[ { "docstring": "Checks if the given string s is a valid password candidate.", "function_declaration": "def is_valid_password_candidate(s):", "function_name": "is_valid_password_candidate", "parameter_list": "(s)" }, { "docstring": "Returns the list of valid password candidates from the given...
[ 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": "def has_digit(s):\n return any(char.isdigit() for char in s)\n\ndef has_upper_and_lower(s):\n has_upper = any(char.isupper() for char in s)\n has_lower = any(char.is...
trial_gpt4o_9
{ "original_instruction": "You are given a list of strings `words`. A string `s` is called a **valid password candidate** if it meets the following criteria:\n- `s` contains at least one digit.\n- `s` contains both uppercase and lowercase letters.\n- `s` contains at least one special character from the set `['@', '#'...
0.60539
Leetcode_2622
C
[ "is_valid_password_candidate", "valid_password_candidates" ]
2
[ [ "valid_password_candidates", "is_valid_password_candidate" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7a73fa70a68f92a963af4a26f28f1a0aba685503
bec01c432470a205d391a6d3138e46b2cad2f4fc
v1.0
complete
Leetcode
Leetcode_3087_C
def largest_constructible_length(words: List[str], target: str) -> int: """ Returns the length of the largest word in the list that can be constructed using the letters of the target word exactly once. Each letter in the target word can only be used once per word construction. If no words can be constructed...
def can_construct(word, target): """ Helper function to check if a word can be constructed from the letters of the target word. """ from collections import Counter word_count = Counter(word) target_count = Counter(target) for char in word_count: if word_count[char] > target...
from solution import largest_constructible_length def test_largest_constructible_length_case_1(): words = ["apple", "plea", "ple", "dog"] target = "apple" assert largest_constructible_length(words, target) == 5 def test_largest_constructible_length_no_match(): words = ["cat", "dog", "elephant"] ta...
[ { "docstring": "Helper function to check if a word can be constructed from the letters of the target word.", "function_declaration": "def can_construct(word, target):", "function_name": "can_construct", "parameter_list": "(word, target)" }, { "docstring": "Returns the length of the largest w...
[ 0, 0, 0, 0, 0, 0, 1, 0, 1, 1 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def can_construct(word, target):\n \"\"\"\n Determines if a word can be constructed from the target letters.\n \"\"\"\n from collections import Counter\n \n ...
trial_gpt4o_9
{ "original_instruction": "Given a list of words `words` and a word `target`, return the length of the largest word in the list that can be constructed using the letters of the `target` word exactly once. Each letter in the `target` word can only be used once per word construction. If no words can be constructed, ret...
0.741314
Leetcode_3087
C
[ "can_construct", "largest_constructible_length" ]
2
[ [ "largest_constructible_length", "can_construct" ] ]
1
[]
false
[]
false
pytest
true
[]
true
694bfbb4c63fd7a2ef5b3601651a6a3c8efbdae4
bd6312956c5f3edcb83880795761a28a52600edd
v1.0
complete
Leetcode
Leetcode_3161_C
from typing import List def reverse_pairs(nums: List[int]) -> int: """ Given an integer array nums, return the number of reverse pairs in the array. A reverse pair is a pair (i, j) where 0 <= i < j < nums.length and nums[i] > 2 * nums[j]. >>> reverse_pairs([1, 3, 2, 3, 1]) 2 >>> reverse_pairs([1,...
def merge_count_rev_pairs(nums, left, mid, right): # Count the reverse pairs count = 0 j = mid + 1 for i in range(left, mid + 1): while j <= right and nums[i] > 2 * nums[j]: j += 1 count += (j - (mid + 1)) # Merge the two sorted halves temp = [] i, j = left, mid ...
from solution import reverse_pairs def test_reverse_pairs_example(): assert reverse_pairs([1, 3, 2, 3, 1]) == 2 def test_reverse_pairs_no_pairs(): assert reverse_pairs([1, 2, 3, 4, 5]) == 0 def test_reverse_pairs_all_pairs(): assert reverse_pairs([5, 4, 3, 2, 1]) == 4 def test_reverse_pairs_mixed_pairs(...
[ { "docstring": null, "function_declaration": "def merge_count_rev_pairs(nums, left, mid, right):", "function_name": "merge_count_rev_pairs", "parameter_list": "(nums, left, mid, right)" }, { "docstring": null, "function_declaration": "def count_reverse_pairs(nums, left, right):", "fu...
[ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def merge_count_rev_pairs(nums, left, mid, right):\n # Count the reverse pairs\n count = 0\n j = mid + 1\n for i in range(left, mid + 1):\n while j <= righ...
trial_gpt4o_0
{ "original_instruction": "Given an integer array `nums`, return the number of **reverse pairs** in the array. A reverse pair is a pair `(i, j)` where `0 <= i < j < nums.length` and `nums[i] > 2 * nums[j]`.\n\nFor example:\n- Input: `nums = [1,3,2,3,1]`\n- Output: `2`\nExplanation: The reverse pairs are `(1, 4)` and ...
0.693123
Leetcode_3161
C
[ "merge_count_rev_pairs", "count_reverse_pairs", "reverse_pairs" ]
3
[ [ "count_reverse_pairs", "merge_count_rev_pairs" ], [ "reverse_pairs", "count_reverse_pairs" ] ]
2
[]
false
[]
false
pytest
true
[]
true
f3f25475f2ae26edf640ded4846d2f015748d801
f57f361f96be40833d9c582b901adb6d1c085bf1
v1.0
complete
Leetcode
Leetcode_3188_C
def valid_ip_addresses(s: str) -> int: """ Given a string of digits, return the number of possible valid IP address combinations that can be formed by inserting exactly three dots into the string. An IP address consists of four sections of numbers separated by dots, and each section must be between 0 ...
def is_valid_section(section): """ Checks if a given section of an IP address is valid. A valid section must be an integer between 0 and 255 and cannot have leading zeros (except for the number 0 itself). """ if len(section) > 1 and section[0] == '0': return False return 0 <= int(sec...
def test_valid_ip_addresses(): assert valid_ip_addresses("25525511135") == 2 # Possible IPs: ["255.255.11.135", "255.255.111.35"] assert valid_ip_addresses("0000") == 1 # Possible IP: ["0.0.0.0"] assert valid_ip_addresses("1111") == 1 # Possible IP: ["1.1.1.1"] assert valid_ip_addresses...
[ { "docstring": "Checks if a given section of an IP address is valid.\nA valid section must be an integer between 0 and 255 and\ncannot have leading zeros (except for the number 0 itself).", "function_declaration": "def is_valid_section(section):", "function_name": "is_valid_section", "parameter_list...
[ 0, 0, 0, 1, 0, 0, 0, 1, 1, 1 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def validate_segment(segment):\n \"\"\"\n Validates if the given segment is a valid section of an IP address.\n \"\"\"\n if len(segment) > 1 and segment[0] == '0'...
trial_gpt4o_8
{ "original_instruction": "Given a string containing digits `0-9`, return the number of possible valid IP address combinations that can be formed by inserting exactly three dots into the string. Note that an IP address consists of four sections of numbers separated by dots, and each section must fall between `0` and ...
0.60068
Leetcode_3188
C
[ "is_valid_section", "valid_ip_addresses" ]
2
[ [ "valid_ip_addresses", "is_valid_section" ] ]
1
[]
false
[]
false
pytest
false
[]
true
c440cc5eedbb782693cd2f26ab07bf474c06c24f
c31b791e553b185831785d5b14a4a1832b7ab6c4
v1.0
complete
Leetcode
Leetcode_3427_C
def prune_binary_tree(parent: List[int], values: List[int]) -> List[int]: """ Prunes a binary tree with given node values and parent-child relationships, such that all nodes with value 0 that do not have a child with value 1 are removed. >>> prune_binary_tree([-1], [1]) [1] >>> prune_binary_tr...
class TreeNode: def __init__(self, value=0): self.value = value self.left = None self.right = None def build_tree(parent, values): n = len(parent) nodes = [TreeNode(values[i]) for i in range(n)] root = None for i in range(n): if parent[i] == -1: root...
from solution import prune_binary_tree def test_single_node_1(): assert prune_binary_tree([-1], [1]) == [1] def test_single_node_0(): assert prune_binary_tree([-1], [0]) == [] def test_tree_complex_case(): parent = [-1, 0, 0, 1, 1, 2, 2, 3] values = [1, 0, 1, 0, 0, 0, 1, 0] assert prune_binary_tr...
[]
[ 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": "class TreeNode:\n def __init__(self, value=0):\n self.value = value\n self.left = None\n self.right = None\n \n def __repr__(self):\n ...
trial_gpt4o_1
{ "original_instruction": "You are given a binary tree with `n` nodes labeled from `1` to `n`. Each node has a value assigned to it represented by a **0-indexed** integer array `values`, where `values[i]` is the value of the `i-th` node (0 <= values[i] <= 1). Your task is to prune the tree such that all the nodes wit...
0.55901
Leetcode_3427
C
[ "build_tree", "prune_tree", "level_order_traversal", "prune_binary_tree" ]
4
[ [ "prune_binary_tree", "build_tree" ], [ "prune_binary_tree", "level_order_traversal" ], [ "prune_binary_tree", "prune_tree" ] ]
3
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
7288cde3806da1a6e14858c9c80527f17e669375
e22c010bc6763e863e16e759b4a6069ae08648d7
v1.0
complete
Leetcode
Leetcode_3481_C
def submatrix_sum_target(matrix, target): """ Determines if there is a sub-matrix with a sum equal to the target. Args: matrix: List of lists of integers, representing the 2D grid. target: Integer, the target sum for the sub-matrix. Returns: A boolean indicating whether a sub-matri...
def submatrix_sum_target(matrix, target): """ Determines if there is a sub-matrix with a sum equal to the target. Args: matrix: List of lists of integers, representing the 2D grid. target: Integer, the target sum for the sub-matrix. Returns: A boolean indicating whether a sub-matri...
from solution import submatrix_sum_target def test_submatrix_sum_target_1(): matrix = [ [1, 2, -1], [-3, 4, 2], [2, -1, 3] ] target = 6 assert submatrix_sum_target(matrix, target) == True def test_submatrix_sum_target_2(): matrix = [ [1, 2], [3, 4] ] ...
[ { "docstring": "Determines if there is a sub-matrix with a sum equal to the target.\n\nArgs:\nmatrix: List of lists of integers, representing the 2D grid.\ntarget: Integer, the target sum for the sub-matrix.\n\nReturns:\nA boolean indicating whether a sub-matrix exists with sum equal to the target.", "funct...
[ 1, 1, 1, 0, 1, 0, 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 submatrix_sum(matrix, target):\n \"\"\"\n Determines if there is a sub-matrix within the given matrix such that the sum\n of all the integers in the sub-matrix i...
trial_gpt4o_9
{ "original_instruction": "You are given an **m x n** 2D grid of integers representing a matrix, and an integer `target`. Your task is to determine if there is a rectangular sub-matrix within the given matrix such that the sum of all the integers in the sub-matrix is equal to `target`. Return `true` if such a sub-mat...
0.591193
Leetcode_3481
C
[ "submatrix_sum_target", "find_subarray_with_sum" ]
2
[ [ "submatrix_sum_target", "find_subarray_with_sum" ] ]
1
[]
false
[]
false
pytest
true
[]
true
22ef493fe78ca0b1e63b1818a3d13793c6e12ee0
c95e220ffd9ba017b1cd0d58537585e79e5b549d
v1.0
complete
Leetcode
Leetcode_3637_C
from typing import List def valid_move(grid: List[List[int]], x: int, y: int, next_x: int, next_y: int, target: int) -> bool: """ Checks if the move from (x, y) to (next_x, next_y) is valid given the target elevation difference. """ def shortest_path(grid: List[List[int]], target: int) -> int: """ ...
from collections import deque import sys def valid_move(grid, x, y, next_x, next_y, target): """ Checks if the move from (x, y) to (next_x, next_y) is valid given the target elevation difference. """ if 0 <= next_x < len(grid) and 0 <= next_y < len(grid[0]) and abs(grid[next_x][next_y] - grid[x][y]) <=...
from solution import shortest_path def test_shortest_path_exists(): grid = [ [1, 3, 5], [2, 8, 3], [6, 2, 1] ] assert shortest_path(grid, 3) == 4 def test_no_path_due_to_elevation_difference(): grid = [ [1, 10, 1], [10, 10, 10], [1, 10, 1] ] asse...
[ { "docstring": "Checks if the move from (x, y) to (next_x, next_y) is valid given the target elevation difference.", "function_declaration": "def valid_move(grid, x, y, next_x, next_y, target):", "function_name": "valid_move", "parameter_list": "(grid, x, y, next_x, next_y, target)" }, { "do...
[ 0, 0, 1, 0, 0, 0, 1, 0, 1, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef shortest_path(grid, target):\n \"\"\"\n Finds the length of the shortest path from the top-left corner to the bottom-right corner\n...
trial_gpt4o_2
{ "original_instruction": "Given an integer matrix `grid`, where `grid[i][j]` represents the elevation of a cell `(i, j)`, and an integer `target`, write a function to find the length of the shortest path from the top-left corner to the bottom-right corner. The path must ensure that any elevation difference between t...
0.693532
Leetcode_3637
C
[ "valid_move", "shortest_path" ]
2
[ [ "shortest_path", "valid_move" ] ]
1
[]
false
[]
false
pytest
true
[]
true
deb87820fe4b0e49775e64c6a2803c71455cba96
ccd5769875d8c5c43cdcb0680f155cd83b90213c
v1.0
complete
Leetcode
Leetcode_3838_C
def heap_sort(arr): """ Given an array of integers, sort the array in ascending order using the heap sort algorithm. You should not use any built-in sort functions or libraries. Output the sorted array. >>> heap_sort([]) == [] True >>> heap_sort([1]) == [1] True >>> heap_sort([1, 2...
def heapify(arr, n, i): """ Converts a subtree rooted with node i into a max heap. n is the size of the heap i is the index in arr[] """ largest = i # Initialize largest as root left = 2 * i + 1 # left = 2*i + 1 right = 2 * i + 2 # right = 2*i + 2 # See if left child of root exist...
from solution import heap_sort def test_heap_sort_empty(): assert heap_sort([]) == [] def test_heap_sort_single_element(): assert heap_sort([1]) == [1] def test_heap_sort_sorted_array(): assert heap_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] def test_heap_sort_reverse_sorted_array(): assert heap_sort(...
[ { "docstring": "Converts a subtree rooted with node i into a max heap.\nn is the size of the heap\ni is the index in arr[]", "function_declaration": "def heapify(arr, n, i):", "function_name": "heapify", "parameter_list": "(arr, n, i)" }, { "docstring": "Performs heap sort on the input array...
[ 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 heapify(arr, n, i):\n \"\"\"\n To heapify a subtree rooted with node i which is an index in arr[]\n n is size of heap\n \"\"\"\n largest = i\n left = 2 ...
trial_gpt4o_9
{ "original_instruction": "Given an array of integers, sort the array in ascending order using the heap sort algorithm. You should not use any built-in sort functions or libraries. Output the sorted array.", "prompt_id": "0000003838", "row_id": 3838, "seed_ids": "['101', '2268', '2']" }
0.695786
Leetcode_3838
C
[ "heapify", "heap_sort" ]
2
[ [ "heap_sort", "heapify" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b452e22bcb17b78c1bbf7aa6ccd9af7ce07a9e24
ac1ad7e3f8da1bbe06c08ec1af320cda7c014e81
v1.0
complete
Leetcode
Leetcode_3998_C
from typing import List import random def find_kth_smallest(arr: List[int], k: int) -> int: """Find the kth smallest element in an unsorted array. Args: arr: List[int] - The array of integers. k: int - The order of the smallest element to find. Returns: int - The kth smallest element ...
import random def partition(arr, left, right, pivot_index): pivot_value = arr[pivot_index] # Move pivot to end arr[pivot_index], arr[right] = arr[right], arr[pivot_index] store_index = left # Move all smaller elements to the left for i in range(left, right): if arr[i] < pivot_value: ...
from solution import find_kth_smallest def test_single_element_array(): assert find_kth_smallest([1], 1) == 1 def test_small_array(): arr = [3, 1, 2, 5, 4] assert find_kth_smallest(arr, 1) == 1 assert find_kth_smallest(arr, 3) == 3 assert find_kth_smallest(arr, 5) == 5 def test_multiple_same_elem...
[ { "docstring": null, "function_declaration": "def partition(arr, left, right, pivot_index):", "function_name": "partition", "parameter_list": "(arr, left, right, pivot_index)" }, { "docstring": "Returns the k-th smallest element of list within left..right", "function_declaration": "def q...
[ 1, 1, 1, 1, 0, 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": "import random\n\ndef kth_smallest(arr, k):\n \"\"\"\n Returns the k-th smallest element in the unsorted array.\n Uses Quickselect algorithm to achieve average linear...
trial_gpt4o_9
{ "original_instruction": "You are given an unsorted integer array `arr` and a number `k`. 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 must implement a solution with a linear time complexity on average. Return ...
0.727123
Leetcode_3998
C
[ "partition", "quickselect", "find_kth_smallest" ]
3
[ [ "find_kth_smallest", "quickselect" ], [ "quickselect", "partition" ] ]
2
[]
false
[]
false
pytest
true
[]
true
40e53cfadc0c1d2f47ef68c34cc750d03c9581ab
8fe9933e416f1079d4c4d23492be10a931d470d1
v1.0
complete
Leetcode
Leetcode_4032_C
def rotate(arr: List[int], k: int) -> None: """ Rotates the array to the right by k steps in-place. """ pass def reverse(arr, start, end): pass # Example test cases def arrays_equal(arr1, arr2): return arr1 == arr2 def test_rotate_normal_case(): arr = [1, 2, 3, 4, 5, 6, 7] rotate(arr,...
def reverse(arr, start, end): while start < end: arr[start], arr[end] = arr[end], arr[start] start += 1 end -= 1 def rotate(arr, k): """ Rotates the array to the right by k steps in-place. """ n = len(arr) k = k % n # To handle cases where k > n reverse(arr, 0, n-1...
from solution import rotate def arrays_equal(arr1, arr2): return arr1 == arr2 def test_rotate_normal_case(): arr = [1, 2, 3, 4, 5, 6, 7] rotate(arr, 3) assert arrays_equal(arr, [5, 6, 7, 1, 2, 3, 4]) def test_rotate_zero(): arr = [1, 2, 3, 4, 5, 6, 7] rotate(arr, 0) assert arrays_equal(ar...
[ { "docstring": null, "function_declaration": "def reverse(arr, start, end):", "function_name": "reverse", "parameter_list": "(arr, start, end)" }, { "docstring": "Rotates the array to the right by k steps in-place.", "function_declaration": "def rotate(arr, k):", "function_name": "ro...
[ 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 rotate_array(arr, k):\n \"\"\"\n Rotates the array `arr` to the right by `k` steps.\n \"\"\"\n n = len(arr)\n k = k % n # in case k is greater than the le...
trial_gpt4o_9
{ "original_instruction": "Given an integer array `arr` and an integer `k`, shift the entire array to the right by `k` steps, where `k` is non-negative. Implement a function that achieves this in-place with O(1) extra space complexity. For example, given `arr = [1,2,3,4,5,6,7]` and `k = 3`, the array should be modifi...
0.628941
Leetcode_4032
C
[ "reverse", "rotate" ]
2
[ [ "rotate", "reverse" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b87c9f7e531d6395f8e13c2491caa4afdb188e45
715c6c38655e4cf164604f80aaac321601d0890f
v1.0
complete
Leetcode
Leetcode_4211_C
def count_reachable_cells(mat): """ Return the number of reachable cells in a matrix. A cell is reachable if it has a path on row or column comprised entirely of 1s that connects it to any edge of the matrix. >>> count_reachable_cells([ ... [1, 1], ... [1, 1] ... ]) == 4 >>> co...
def is_reachable(mat, i, j, m, n): # Check if cell mat[i][j] is reachable by moving horizontally or vertically to the matrix edge for c in range(n): if mat[i][c] == 1 and any(mat[i][k] == 1 for k in range(c+1)): return True for r in range(m): if mat[r][j] == 1 and any(mat[k][j] =...
from solution import count_reachable_cells def test_all_ones(): mat = [ [1, 1], [1, 1] ] assert count_reachable_cells(mat) == 4 def test_no_ones(): mat = [ [0, 0], [0, 0] ] assert count_reachable_cells(mat) == 0 def test_mixed_matrix(): mat = [ [1, ...
[ { "docstring": null, "function_declaration": "def is_reachable(mat, i, j, m, n):", "function_name": "is_reachable", "parameter_list": "(mat, i, j, m, n)" }, { "docstring": null, "function_declaration": "def count_reachable_cells(mat):", "function_name": "count_reachable_cells", "...
[ 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 count_reachable_cells(mat):\n \"\"\"\n Returns the number of \"reachable\" cells in the matrix.\n \n A cell is \"reachable\" if it has a path on row or column...
trial_gpt4o_7
{ "original_instruction": "You are given a matrix `mat` of integers with dimensions `m x n`. Each cell in the matrix contains either a 0 or a 1. A cell is called “reachable” if it has a path on row or column comprised entirely of 1s that connects it to any edge of the matrix. Return _the number of “reachable” cells i...
0.613529
Leetcode_4211
C
[ "is_reachable", "count_reachable_cells" ]
2
[ [ "count_reachable_cells", "is_reachable" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a298fe47207528894a89cc7b0ac6c0be287e5ba0
6f8461c59c90f6e7fe405344572f2609a9db4d89
v1.0
complete
Leetcode
Leetcode_4222_C
def min_swaps_to_make_palindrome(s: str) -> int: """ Returns the minimum number of swaps required to make the string a palindrome. If it is impossible to form a palindrome, returns -1. >>> min_swaps_to_make_palindrome("aabb") == 2 >>> min_swaps_to_make_palindrome("ab") == -1 >>> min_swaps_to_mak...
def min_swaps_to_make_palindrome(s): """ Returns the minimum number of swaps required to make the string a palindrome. If it is impossible to form a palindrome, returns -1. """ if not can_form_palindrome(s): return -1 s = list(s) n = len(s) swaps = 0 for i in range(...
from solution import min_swaps_to_make_palindrome def test_example_case_1(): assert min_swaps_to_make_palindrome("aabb") == 2 def test_example_case_2(): assert min_swaps_to_make_palindrome("ab") == -1 def test_example_case_3(): assert min_swaps_to_make_palindrome("aa") == 0 def test_palindrome_already()...
[ { "docstring": "Returns the minimum number of swaps required to make the string a palindrome.\nIf it is impossible to form a palindrome, returns -1.", "function_declaration": "def min_swaps_to_make_palindrome(s):", "function_name": "min_swaps_to_make_palindrome", "parameter_list": "(s)" }, { ...
[ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def min_swaps_to_palindrome(s):\n def can_form_palindrome(s):\n from collections import Counter\n freq = Counter(s)\n odd_count = sum(1 for count in f...
trial_gpt4o_5
{ "original_instruction": "You are given a string `s` consisting only of letters 'a' and 'b'. In one move, you can swap any two characters in the string. Your goal is to make the string a palindrome by swapping the minimum number of pairs of characters. Return _an integer_ representing the minimum number of swaps req...
0.781212
Leetcode_4222
C
[ "min_swaps_to_make_palindrome", "can_form_palindrome" ]
2
[ [ "min_swaps_to_make_palindrome", "can_form_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d048d32eba73deb4ed5c85015bd240fe647cd281
fb6197a78484a1fc6d6e55eb33ce481db2e6fc17
v1.0
complete
Leetcode
Leetcode_4360_C
def longest_non_palindromic_substring_length(s: str) -> int: """ Given a string `s` consisting of lowercase letters, return the length of the longest non-palindromic substring that can be obtained after removing at most one substring of characters that are consecutive and form a palindrome. >>> longest_...
def is_palindrome(s): return s == s[::-1] def longest_non_palindromic_substring_length(s): n = len(s) if not s or n == 1: return 0 if not is_palindrome(s): return n # Since s is a palindrome, the result is n - 1: return n - 1
from solution import longest_non_palindromic_substring_length def test_with_entire_palindrome(): assert longest_non_palindromic_substring_length("aaaa") == 3 assert longest_non_palindromic_substring_length("racecar") == 6 def test_with_non_palindrome(): assert longest_non_palindromic_substring_length("abc...
[ { "docstring": null, "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": null, "function_declaration": "def longest_non_palindromic_substring_length(s):", "function_name": "longest_non_palindromic_substring_leng...
[ 1, 0, 0, 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": "def longest_non_palindromic_substring(s):\n \"\"\"\n Given a string `s`, returns the length of the longest non-palindromic substring\n that can be obtained after rem...
trial_gpt4o_5
{ "original_instruction": "Given a string `s` consisting of lowercase letters, you are allowed to remove at most one substring of characters that are consecutive and form a palindrome. Return the length of the longest non-palindromic substring that can be obtained after making at most one such removal. \n\nA substrin...
0.794545
Leetcode_4360
C
[ "is_palindrome", "longest_non_palindromic_substring_length" ]
2
[ [ "longest_non_palindromic_substring_length", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d9dd99c624411d099f4021c6e7468337e2f756e1
f658188028fad8d07d8d29043f961628d6329cd0
v1.0
complete
Leetcode
Leetcode_4380_C
from typing import List, Optional class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def list_to_binary_tree(nodes: List[Optional[int]]) -> Optional[TreeNode]: if not nodes: return None n = len(nodes) ro...
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 list_to_binary_tree(nodes: List[Optional[int]]) -> Optional[TreeNode]: if not nodes: return None n = len(nodes) ...
from solution import get_level_order def test_get_level_order(): assert get_level_order([3, 9, 20, None, None, 15, 7]) == [[3], [9, 20], [15, 7]] assert get_level_order([1, 2, 3, 4, 5, 6, 7]) == [[1], [2, 3], [4, 5, 6, 7]] assert get_level_order([1]) == [[1]] assert get_level_order([1, None, 2, None, N...
[]
[ 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "from collections import deque\n\nclass TreeNode:\n def __init__(self, value=0, left=None, right=None):\n self.value = value\n self.left = left\n self....
trial_gpt4o_6
{ "original_instruction": "You are given a binary tree represented by a list of node values in level-order traversal where `None` represents a missing node. Implement a function that returns the level-order traversal of the binary tree as a list of lists. Each sub-list should contain the values of the tree nodes at ...
0.528795
Leetcode_4380
C
[ "list_to_binary_tree", "level_order_traversal", "get_level_order" ]
3
[ [ "get_level_order", "level_order_traversal" ], [ "get_level_order", "list_to_binary_tree" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
9dc49a6f41b1aec30cb577b9fd4f6a3651e5f38c
24a21a826c3a6059bd0fdb79c42ad53f3d0fa426
v1.0
complete
Leetcode
Leetcode_4791_C
def words_from_string(s: str, words: List[str]) -> List[str]: """ Returns the list of words from the input list that can be formed by characters from string s. The result list is sorted in lexicographical order. >>> words_from_string("a", ["a", "b"]) ['a'] >>> words_from_string("abc", ["a", "ab", "a...
def can_form_word(word, s): s_char_count = {} for char in s: if char in s_char_count: s_char_count[char] += 1 else: s_char_count[char] = 1 for char in word: if char in s_char_count and s_char_count[char] > 0: s_char_count[char] -= 1 el...
from solution import words_from_string def test_single_character_words(): assert words_from_string("a", ["a", "b"]) == ["a"] def test_multiple_character_words(): assert words_from_string("abc", ["a", "ab", "abc", "abcd"]) == ["a", "ab", "abc"] def test_no_matches(): assert words_from_string("xyz", ["a", ...
[ { "docstring": null, "function_declaration": "def can_form_word(word, s):", "function_name": "can_form_word", "parameter_list": "(word, s)" }, { "docstring": "Returns the list of words from the input list that can be formed by characters from string s.\nThe result list is sorted in lexicogra...
[ 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 can_form_word(word, available_chars):\n \"\"\"\n Helper function to check if a word can be formed from available characters.\n \"\"\"\n for char in word:\n ...
trial_gpt4o_8
{ "original_instruction": "You are given a string `s` and a list of words `words`. Your task is to find which words from the list `words` can be formed by characters from the string `s`. Each character in `s` can be used only once for each word. Return the list of all words that can be formed, sorted in lexicographic...
0.695882
Leetcode_4791
C
[ "can_form_word", "words_from_string" ]
2
[ [ "words_from_string", "can_form_word" ] ]
1
[]
false
[]
false
pytest
true
[]
true
38b0477af7a5691bbcfd2c939660f3affeaaa953
1bbb137d2f793bf5c5068b4afd32e7b112fbf5a8
v1.0
complete
Leetcode
Leetcode_5015_C
def findKthSmallest(nums: List[int], k: int) -> int: """ Given an array of integers `nums` and an integer `k`, 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. >>> findKthSmallest([3, 2, 1, 5, 6, 4], 2) 2 ...
def quickSelect(nums, low, high, k): if low == high: return nums[low] pivot_index = partition(nums, low, high) if k == pivot_index: return nums[k] elif k < pivot_index: return quickSelect(nums, low, pivot_index - 1, k) else: return quickSelect(nums, pivot_index + 1,...
from solution import findKthSmallest def test_findKthSmallest(): assert findKthSmallest([3, 2, 1, 5, 6, 4], 2) == 2 assert findKthSmallest([3, 2, 1, 5, 6, 4], 5) == 5 assert findKthSmallest([7, 10, 4, 3, 20, 15], 3) == 7 assert findKthSmallest([7, 10, 4, 3, 20, 15], 4) == 10 assert findKthSmallest(...
[ { "docstring": null, "function_declaration": "def quickSelect(nums, low, high, k):", "function_name": "quickSelect", "parameter_list": "(nums, low, high, k)" }, { "docstring": null, "function_declaration": "def partition(nums, low, high):", "function_name": "partition", "paramete...
[ 1, 1, 1, 1, 1, 1, 1, 1, 0, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "import heapq\n\ndef find_kth_smallest(nums, k):\n \"\"\"\n Returns the k-th smallest element in the array nums.\n \"\"\"\n # Use a min-heap to find the k-th small...
trial_gpt4o_9
{ "original_instruction": "Given an 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 asked to solve it in such a way that the time complexity is better t...
0.700862
Leetcode_5015
C
[ "quickSelect", "partition", "findKthSmallest" ]
3
[ [ "findKthSmallest", "quickSelect" ], [ "quickSelect", "partition" ] ]
2
[]
false
[]
false
pytest
true
[]
true
c1a2ab5878b5eab680ff4d213812948e81861275
d5a6993ecff44f1825123c2832ef33c627289765
v1.0
complete
Leetcode
Leetcode_5044_C
from typing import List def can_traverse(grid: List[List[int]], m: int, n: int, sr: int, sc: int, threshold: int) -> int: """ Helper function to check the number of cells that can be traversed starting from (sr, sc). """ pass def find_best_starting_point(grid: List[List[int]], m: int, n: int, height_threshold...
from collections import deque def can_traverse(grid, m, n, sr, sc, threshold): visited = [[False] * n for _ in range(m)] queue = deque([(sr, sc)]) visited[sr][sc] = True count = 1 directions = [(-1, 0), (1, 0), (0, -1), (0, 1)] while queue: r, c = queue.popleft() for dr, dc i...
def test_find_best_starting_point(): grid = [ [1, 2, 3], [6, 5, 4], [7, 8, 7], ] assert find_best_starting_point(grid, 3, 3, 5) == 5 grid = [ [10, 12, 10], [8, 9, 11], [7, 9, 9], ] assert find_best_starting_point(grid, 3, 3, 9) == 9 grid = [ ...
[ { "docstring": null, "function_declaration": "def can_traverse(grid, m, n, sr, sc, threshold):", "function_name": "can_traverse", "parameter_list": "(grid, m, n, sr, sc, threshold)" }, { "docstring": null, "function_declaration": "def find_best_starting_point(grid, m, n, height_threshold...
[ 0, 1, 0, 0, 1, 0, 1, 1, 0 ]
4
medium
0.444
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def find_starting_height(grid, height_threshold):\n \"\"\"\n Determines the smallest value in the grid that is greater than or equal to height_threshold which,\n if ...
trial_gpt4o_8
{ "original_instruction": "You are given a 2D grid `grid` of size `m x n`. Each cell of the grid contains a value representing the height of that cell. You're also given an integer `height_threshold`. You can move from a cell to its neighboring cell horizontally or vertically if and only if the height of the neighbor...
0.715187
Leetcode_5044
C
[ "can_traverse", "find_best_starting_point" ]
2
[ [ "find_best_starting_point", "can_traverse" ] ]
1
[]
false
[]
false
pytest
false
[]
true
e19c79fe7d541c0c8cc7f8b4d07fb266d6f91ad5
e9c01523de5e6f2bd6bf41a7a45f71b00a312f06
v1.0
complete
Leetcode
Leetcode_5197_C
from typing import List, Tuple import itertools def is_valid_permutation(perm: Tuple[int], k: int) -> bool: """ Check if the permutation is valid by ensuring the absolute difference between each adjacent element is at least k. >>> is_valid_permutation([1, 4, 7], 3) == True >>> is_valid_permutation...
import itertools def is_valid_permutation(perm, k): for i in range(1, len(perm)): if abs(perm[i] - perm[i - 1]) < k: return False return True def valid_permutations(nums, k): """ Returns all permutations of nums where the absolute difference between each adjacent element in th...
from solution import valid_permutations, is_valid_permutation def test_is_valid_permutation(): assert is_valid_permutation([1, 4, 7], 3) == True assert is_valid_permutation([1, 2, 3], 2) == False assert is_valid_permutation([5, 1, 8], 4) == True assert is_valid_permutation([6, 1, 3], 5) == False def t...
[ { "docstring": null, "function_declaration": "def is_valid_permutation(perm, k):", "function_name": "is_valid_permutation", "parameter_list": "(perm, k)" }, { "docstring": "Returns all permutations of nums where the absolute difference \nbetween each adjacent element in the permutation is at...
[ 0, 0, 0, 0, 1, 0, 0, 1, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "from itertools import permutations\n\ndef is_valid_permutation(permutation, k):\n \"\"\"\n Check if the permutation is valid based on the given k constraint.\n \"\"\...
trial_gpt4o_7
{ "original_instruction": "A permutation of an array of integers is an arrangement of its members into a sequence or linear order. Given an integer array `nums` of distinct integers and an integer `k`, return _all the permutations of the array_ `nums` _such that the absolute difference between each adjacent element i...
0.677233
Leetcode_5197
C
[ "is_valid_permutation", "valid_permutations" ]
2
[ [ "valid_permutations", "is_valid_permutation" ] ]
1
[]
false
[]
false
pytest
true
[]
true
027f5893f38c15d92ac25e41bcf37357fe6612eb
235839444a55e2037ec6d7918050d30d1fcd7b1a
v1.0
complete
Leetcode
Leetcode_5674_C
def gcd(a, b): """ Returns the greatest common divisor of a and b. """ while b: a, b = b, a % b return a def lcm(a, b): """ Returns the least common multiple of a and b. """ return abs(a * b) // gcd(a, b) def minimum_time_to_meet(n, d): """ Returns the minimum time...
import math def gcd(a, b): """ Returns the greatest common divisor of a and b. """ while b: a, b = b, a % b return a def lcm(a, b): """ Returns the least common multiple of a and b. """ return abs(a * b) // gcd(a, b) def minimum_time_to_meet(n, d): """ Returns the ...
from solution import minimum_time_to_meet def test_case_1(): assert minimum_time_to_meet(12, 3) == 12 def test_case_2(): assert minimum_time_to_meet(10, 4) == 20 def test_case_3(): assert minimum_time_to_meet(15, 5) == 15 def test_case_4(): assert minimum_time_to_meet(24, 6) == 24 def test_case...
[ { "docstring": "Returns the greatest common divisor of a and b.", "function_declaration": "def gcd(a, b):", "function_name": "gcd", "parameter_list": "(a, b)" }, { "docstring": "Returns the least common multiple of a and b.", "function_declaration": "def lcm(a, b):", "function_name":...
[ 0, 0, 1, 0, 0, 0, 0, 1, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "import math\nfrom functools import reduce\n\ndef min_time_to_meet(n, d, positions):\n \"\"\"\n Returns the minimum time required for all cars to meet at the same positi...
trial_gpt4o_7
{ "original_instruction": "Imagine you are given an array of positive integers representing the positions of cars on a circular track of length `n`. Each car can only move to a position ahead (wrap-around allowed), and the distance each car can move per unit time is fixed at `d` units. The cars race around the track ...
0.564287
Leetcode_5674
C
[ "gcd", "lcm", "minimum_time_to_meet" ]
3
[ [ "lcm", "gcd" ], [ "minimum_time_to_meet", "lcm" ] ]
2
[]
false
[]
false
pytest
true
[]
true
b331e5442ad76595cf917b66163832d9affe626e
a106df8e3558c5f77c2acae10a162446289bd3f3
v1.0
complete
Leetcode
Leetcode_5739_C
from typing import List def filter_tasks_by_prime_factors(tasks: List[int], k: int) -> List[int]: """ A company has a legacy software system with a list of tasks to complete, each of which is represented by an integer array `tasks`. A task can either be approved or denied based on a strict approval criterion....
from math import isqrt def prime_factors_count(n): """ Returns the count of unique prime factors of n. """ count = 0 i = 2 while i <= isqrt(n): if n % i == 0: count += 1 while n % i == 0: n //= i i += 1 if n > 1: count += 1 ...
from solution import filter_tasks_by_prime_factors def test_filter_tasks_no_tasks_meet_criterion(): assert filter_tasks_by_prime_factors([6, 10, 14, 15], 2) == [] def test_filter_tasks_all_tasks_meet_criterion(): assert filter_tasks_by_prime_factors([30, 42, 60, 70], 2) == [30, 42, 60, 70] def test_filter_ta...
[ { "docstring": "Returns the count of unique prime factors of n.", "function_declaration": "def prime_factors_count(n):", "function_name": "prime_factors_count", "parameter_list": "(n)" }, { "docstring": "Returns a list of tasks that have more than k unique prime factors.", "function_decl...
[ 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 math\n\ndef prime_factors(n):\n \"\"\"\n Returns a set of prime factors of the given number n.\n \"\"\"\n factors = set()\n \n # Check for number of ...
trial_gpt4o_8
{ "original_instruction": "A company has a legacy software system with a list of tasks to complete, each of which is represented by an integer array `tasks`. A task can either be approved or denied based on a strict approval criterion. Each task is approved only if it has more than `k` unique prime factors. The compa...
0.616904
Leetcode_5739
C
[ "prime_factors_count", "filter_tasks_by_prime_factors" ]
2
[ [ "filter_tasks_by_prime_factors", "prime_factors_count" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a233c977483c8cf102d55ed7487b526736422f6b
26c766e11139110b5631122448e8e0e38c0e9bb3
v1.0
complete
Leetcode
Leetcode_6108_C
def circularRob(houses: List[int]) -> int: """ Find the maximum amount of money you can rob tonight without alerting the police. Houses are arranged in a circular street. >>> circularRob([]) == 0 >>> circularRob([5]) == 5 >>> circularRob([2, 3]) == 3 >>> circularRob([2, 3, 2]) == 3 >>> circularR...
from typing import List def rob_linear(houses: List[int]) -> int: if not houses: return 0 if len(houses) == 1: return houses[0] if len(houses) == 2: return max(houses) dp = [0] * len(houses) dp[0] = houses[0] dp[1] = max(houses[0], houses[1]) for i in range(2, l...
from solution import circularRob def test_circular_rob_empty(): assert circularRob([]) == 0 def test_circular_rob_one_house(): assert circularRob([5]) == 5 def test_circular_rob_two_houses(): assert circularRob([2, 3]) == 3 def test_circular_rob_three_houses(): assert circularRob([2, 3, 2]) == 3 de...
[ { "docstring": null, "function_declaration": "def rob_linear(houses):", "function_name": "rob_linear", "parameter_list": "(houses)" }, { "docstring": null, "function_declaration": "def circularRob(houses):", "function_name": "circularRob", "parameter_list": "(houses)" } ]
[ 0, 0, 0, 0, 1, 0, 1, 0, 1, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef rob_linear(houses: List[int]) -> int:\n if not houses:\n return 0\n if len(houses) == 1:\n return houses[0]\n \n prev...
trial_gpt4o_6
{ "original_instruction": "You are given a list of non-negative integers representing the amount of money of each house. Each house is arranged in a circular street such that the first house is the neighbor of the last one. You can't rob two adjacent houses, meaning after you rob a house, the next adjacent house can'...
0.534103
Leetcode_6108
C
[ "rob_linear", "circularRob" ]
2
[ [ "circularRob", "rob_linear" ] ]
1
[]
false
[]
false
pytest
true
[]
true
85ba257155e1534592a23016e833fe0b7a54104d
b021afab74fecfa233a148e5b3c24060c7fc64c1
v1.0
complete
Leetcode
Leetcode_6130_C
from typing import List, Optional class TreeNode: def __init__(self, value=0, left=None, right=None): self.value = value self.left = left self.right = right def build_tree_from_level_order(values: List[Optional[int]]) -> Optional[TreeNode]: """ Build a binary tree from a list of values...
from collections import deque class TreeNode: def __init__(self, value=0, left=None, right=None): self.value = value self.left = left self.right = right def build_tree_from_level_order(values): if not values: return None root = TreeNode(values[0]) queue = deque([root])...
from solution import traverse_tree_from_array def test_empty_tree(): assert traverse_tree_from_array([]) == [] def test_single_node_tree(): assert traverse_tree_from_array([1]) == [[1]] def test_binary_tree(): values = [3, 9, 20, None, None, 15, 7] assert traverse_tree_from_array(values) == [[15, 7],...
[]
[ 1, 1, 0, 0, 1, 0, 0, 1, 1, 0 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "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": "Given a binary tree, implement an algorithm to return the level order traversal of its nodes' values but in reverse (from the bottom level to the top and from left to right within each level). The tree is represented as an array in level order where `null` indicates the absence of a node. R...
0.527344
Leetcode_6130
C
[ "build_tree_from_level_order", "reverse_level_order_traversal", "traverse_tree_from_array" ]
3
[ [ "traverse_tree_from_array", "build_tree_from_level_order" ], [ "traverse_tree_from_array", "reverse_level_order_traversal" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
ce9920dfe7a7d485f6cc0d0419cd116b6a709637
9a9e6aa8bf807eb2a74b6c1cffeccfb699629b95
v1.0
complete
Leetcode
Leetcode_6136_C
from typing import List from functools import cmp_to_key def largestNumber(arr: List[int]) -> str: """ Form the largest number possible by concatenating the elements of the array. >>> largestNumber([3, 30, 34, 5, 9]) '9534330' >>> largestNumber([10, 2]) '210' >>> largestNumber([1, 1, 1]) '1...
from typing import List from functools import cmp_to_key def compare(x, y): # Comparator function to decide the order based on concatenated string comparison if x + y > y + x: return -1 elif x + y < y + x: return 1 else: return 0 def largestNumber(arr: List[int]) -> str: # ...
from solution import largestNumber def test_single_digit_numbers(): assert largestNumber([3, 30, 34, 5, 9]) == '9534330' def test_all_equal_numbers(): assert largestNumber([1, 1, 1]) == '111' def test_large_numbers(): assert largestNumber([10, 2]) == '210' assert largestNumber([3, 30, 34, 5, 91]) == ...
[ { "docstring": null, "function_declaration": "def compare(x, y):", "function_name": "compare", "parameter_list": "(x, y)" }, { "docstring": null, "function_declaration": "def largestNumber(arr):", "function_name": "largestNumber", "parameter_list": "(arr)" } ]
[ 0, 1, 0, 1, 0, 0, 1, 0, 1, 0 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "from typing import List\nfrom functools import cmp_to_key\n\ndef custom_compare(x: str, y: str) -> int:\n \"\"\"\n Custom comparator for sorting the numbers.\n \"\"\...
trial_gpt4o_8
{ "original_instruction": "You are given an array of integers `arr` of length `n`. Your task is to form the largest number possible by concatenating the elements of the array. Write a function `largestNumber` which accepts an integer array `arr` and returns a string representing the largest number formed by concatena...
0.729776
Leetcode_6136
C
[ "compare", "largestNumber" ]
2
[ [ "largestNumber", "compare" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f973f523b91325754e8744f5a6d71119de07e11f
1bc5df48e192a89ba85e043787701456329e07e9
v1.0
complete
Leetcode
Leetcode_6275_C
from typing import List def minimize_max_sum_of_partitions(arr: List[int], m: int) -> int: """ Partition the array into m non-overlapping, contiguous subarrays such that the sum of the maximum subarray sum among all the partitions is minimized. Return the minimized sum of the maximum subarray sum of the pa...
def can_partition(arr, n, m, max_sum): count, current_sum = 1, 0 for num in arr: current_sum += num if current_sum > max_sum: count += 1 current_sum = num if count > m: return False return True def minimize_max_sum_of_partitions(arr, m): ...
from solution import minimize_max_sum_of_partitions def test_minimize_max_sum_of_partitions(): assert minimize_max_sum_of_partitions([7, 2, 5, 10, 8], 2) == 18 assert minimize_max_sum_of_partitions([1, 2, 3, 4, 5], 2) == 9 assert minimize_max_sum_of_partitions([1, 4, 4], 3) == 4 assert minimize_max_sum...
[ { "docstring": null, "function_declaration": "def can_partition(arr, n, m, max_sum):", "function_name": "can_partition", "parameter_list": "(arr, n, m, max_sum)" }, { "docstring": null, "function_declaration": "def minimize_max_sum_of_partitions(arr, m):", "function_name": "minimize_...
[ 1, 0, 0, 1, 0, 1, 0, 0, 0 ]
3
medium
0.333
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_1_results_combined.jsonl", "solution_code": "def splitArray(nums, m):\n def valid(mid):\n count, total = 1, 0\n for num in nums:\n total += num\n if total ...
trial_gpt4o_6
{ "original_instruction": "You are given an array `arr` of `n` integers and an integer `m`. You need to partition the array into **exactly** `m` non-overlapping, contiguous subarrays, such that the sum of the maximum subarray sum among all the partitions is minimized. Return _the minimized sum of the maximum subarray...
0.682512
Leetcode_6275
C
[ "can_partition", "minimize_max_sum_of_partitions" ]
2
[ [ "minimize_max_sum_of_partitions", "can_partition" ] ]
1
[]
false
[]
false
pytest
true
[]
true
80a9a2895b863f00899410415a05d6cac43a3341
57546262da1842dbc65ec774239819015d975e05
v1.0
complete
Leetcode
Leetcode_6427_C
class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None def shortestPath(root, a, b): """ Determine the length of the shortest path between the nodes labeled `a` and `b` in a binary tree with `n` nodes, where the tree is rooted at node `1`. >>...
class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None def findLCA(root, n1, n2): if root is None: return None if root.val == n1 or root.val == n2: return root left_lca = findLCA(root.left, n1, n2) right_lca = findLCA(root.righ...
from solution import TreeNode, shortestPath def test_shortest_path_basic(): root = TreeNode(1) root.left = TreeNode(2) root.right = TreeNode(3) root.left.left = TreeNode(4) root.left.right = TreeNode(5) root.right.left = TreeNode(6) root.right.right = TreeNode(7) assert shortestPat...
[]
[ 1, 1, 1, 0, 1, 1, 1, 1, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, x):\n self.val = x\n self.left = None\n self.right = None\n\ndef find_LCA(root, n1, n2):\n if root is None:\n ...
trial_gpt4o_9
{ "original_instruction": "You are given a binary tree with `n` nodes. Each node is labeled uniquely with integers from `1` to `n`. You are also given two integers, `a` and `b`. Your task is to determine the length of the shortest path between the nodes labeled `a` and `b`. You can assume that the tree is rooted at n...
0.574049
Leetcode_6427
C
[ "findLCA", "findLevel", "shortestPath" ]
3
[ [ "shortestPath", "findLCA" ], [ "shortestPath", "findLevel" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
20e95b9382714bc138016e8e81b4ff8b1eb2e8f2
fbd35cf95945a3923590140704afac5194fd8607
v1.0
complete
Leetcode
Leetcode_6648_C
from typing import List def min_max_pages(books: List[int], k: int) -> int: """ Given an array of integers representing the number of pages in each book, and an integer representing the number of students, return the minimum possible value of the maximum number of pages assigned to a student. >>> min_m...
def is_feasible(books, k, max_pages): students_required = 1 current_sum = 0 for pages in books: if current_sum + pages > max_pages: students_required += 1 current_sum = pages if students_required > k: return False else: curren...
from solution import min_max_pages def test_single_book(): assert min_max_pages([100], 1) == 100 def test_multiple_books_single_student(): assert min_max_pages([10, 20, 30, 40], 1) == 100 def test_multiple_books_multiple_students(): assert min_max_pages([10, 20, 30, 40], 2) == 60 assert min_max_pages...
[ { "docstring": null, "function_declaration": "def is_feasible(books, k, max_pages):", "function_name": "is_feasible", "parameter_list": "(books, k, max_pages)" }, { "docstring": null, "function_declaration": "def min_max_pages(books, k):", "function_name": "min_max_pages", "param...
[ 0, 1, 0, 0, 1, 0, 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 is_feasible(books, k, curr_min):\n students_required = 1\n curr_sum = 0\n \n for pages in books:\n if pages > curr_min:\n return False\n\n ...
trial_gpt4o_9
{ "original_instruction": "You are given an array `books` where `books[i]` represents the number of pages in the `i-th` book. You are also given an integer `k` which represents the number of students. The books need to be divided among the `k` students in such a way that each student gets at least one book and the ma...
0.67042
Leetcode_6648
C
[ "is_feasible", "min_max_pages" ]
2
[ [ "min_max_pages", "is_feasible" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a5c2d7136026453a857180e21d5230bb1207046d
ddeef97779657a5d48d08911a22af2614c85bfaf
v1.0
complete
Leetcode
Leetcode_7754_C
from collections import deque from typing import List, Tuple def bfs_farthest_node(start: int, graph: dict, n: int) -> Tuple[int, int]: """ Performs BFS to find the farthest node from the start node. """ pass # complete this function def max_distance(n: int, edges: List[Tuple[int, int]]) -> int: ...
from collections import deque def bfs_farthest_node(start, graph, n): """ Performs BFS to find the farthest node from the start node. """ visited = [False] * (n + 1) distance = [0] * (n + 1) queue = deque([start]) visited[start] = True farthest_node = start while queue: nod...
from solution import max_distance def test_single_node(): assert max_distance(1, []) == 0 def test_two_nodes(): assert max_distance(2, [[1, 2]]) == 1 def test_three_nodes_in_line(): assert max_distance(3, [[1, 2], [2, 3]]) == 2 def test_five_nodes_star(): assert max_distance(5, [[1, 2], [1, 3], [1, ...
[ { "docstring": "Performs BFS to find the farthest node from the start node.", "function_declaration": "def bfs_farthest_node(start, graph, n):", "function_name": "bfs_farthest_node", "parameter_list": "(start, graph, n)" }, { "docstring": "Finds the maximum distance between two nodes in a tr...
[ 0, 0, 0, 1, 1, 0, 0, 0, 1, 1 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def tree_diameter(n, edges):\n from collections import defaultdict, deque\n \n def bfs(start_node):\n visited = [-1] * (n + 1)\n queue = deque([(start_...
trial_gpt4o_9
{ "original_instruction": "You are given a tree, which is a connected and acyclic undirected graph, with `n` nodes labeled from `1` to `n` and `n-1` edges. You need to find **two nodes** such that their **distance** (defined as the number of edges in the shortest path connecting them) is maximized. Return _this maxim...
0.587879
Leetcode_7754
C
[ "bfs_farthest_node", "max_distance" ]
2
[ [ "max_distance", "bfs_farthest_node" ] ]
1
[]
false
[]
false
pytest
true
[]
true
eff88a5efd52ed8f7313480fa09190f07b932e2b
b17ed8ddb71de611a3a96b50f4601002d16417fd
v1.0
complete
Leetcode
Leetcode_7809_C
def can_partition(nums, m, max_sum): """ Helper function to determine if we can partition the list into m subarrays with the given maximum sum. """ pass def minimize_max_sum(nums, m): """ Given a list of integers `nums` and an integer `m`, partition the list into `m` contiguous subarrays su...
def can_partition(nums, m, max_sum): """ Helper function to determine if we can partition the list into m subarrays with the given maximum sum. """ current_sum = 0 count = 1 for num in nums: if current_sum + num > max_sum: count += 1 current_sum = num ...
from solution import minimize_max_sum def test_example_case(): nums = [7, 2, 5, 10, 8] m = 2 assert minimize_max_sum(nums, m) == 18 def test_single_element_partitions(): nums = [1, 2, 3, 4, 5] m = 5 assert minimize_max_sum(nums, m) == 5 def test_entire_array_one_partition(): nums = [1, 2,...
[ { "docstring": "Helper function to determine if we can partition the list into m subarrays\nwith the given maximum sum.", "function_declaration": "def can_partition(nums, m, max_sum):", "function_name": "can_partition", "parameter_list": "(nums, m, max_sum)" }, { "docstring": "Returns the mi...
[ 0, 0, 1, 0, 1, 1, 0, 1, 1, 1 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def can_partition(nums, m, max_sum):\n current_subarray_sum = 0\n subarray_count = 1\n \n for num in nums:\n if current_subarray_sum + num > max_sum:\n ...
trial_gpt4o_9
{ "original_instruction": "Given a list of integers `nums` and an integer `m`, partition the list into `m` contiguous subarrays such that the **maximum** sum of the subarrays is minimized. Return the minimized maximum sum. The partitioning must be non-empty and contiguous, and there must be exactly `m` subarrays.", ...
0.675488
Leetcode_7809
C
[ "can_partition", "minimize_max_sum" ]
2
[ [ "minimize_max_sum", "can_partition" ] ]
1
[]
false
[]
false
pytest
true
[]
true
35f6bd873d05d2f722c835658217aa1956cd0152
874252cd9fe4d8880db6df5dc93667195fc9515f
v1.0
complete
Leetcode
Leetcode_7979_C
class ListNode: def __init__(self, val=0, next=None): self.val = val self.next = next def reverseKGroup(head, k): """ Reverses nodes in the k-group chunks in the linked list. :param head: ListNode, the head of the linked list :param k: int, the size of the group to reverse :ret...
class ListNode: def __init__(self, val=0, next=None): self.val = val self.next = next def reverseKGroup(head, k): """ Reverses nodes in the k-group chunks in the linked list. :param head: ListNode, the head of the linked list :param k: int, the size of the group to reverse :retu...
from solution import ListNode, reverseKGroup def list_to_array(head): array = [] while head: array.append(head.val) head = head.next return array def array_to_list(array): dummy = ListNode(0) curr = dummy for val in array: curr.next = ListNode(val) curr = curr.n...
[]
[ 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": "class ListNode:\n def __init__(self, val=0, next=None):\n self.val = val\n self.next = next\n\ndef reverseKGroup(head, k):\n if k == 1 or not head:\n ...
trial_gpt4o_7
{ "original_instruction": "Write a function that takes the `head` of a singly linked list and reverses the nodes in `k`-group chunks, where `k` is a given positive integer. If the number of nodes is not a multiple of `k`, leave the last remaining nodes as they are. Return the modified head of the list.", "prompt_id...
0.584565
Leetcode_7979
C
[ "reverseKGroup", "reverse" ]
2
[ [ "reverseKGroup", "reverse" ] ]
1
[]
false
[ "ListNode" ]
true
pytest
true
[]
true
db61154aad9c66b9a4d83e4d745efffa67acc3d8
a44ec32d06f143a7f039301460ba7d82e08f0a68
v1.0
complete
Leetcode
Leetcode_8058_C
def is_palindrome(x: int) -> bool: """ Check if a given number x is a palindrome. """ pass def is_super_palindrome(n: int) -> bool: """ Determines whether a given positive integer n is a super palindrome. A super palindrome is an integer whose square is a palindrome. >>> is_super_palin...
def is_palindrome(x): """ Check if a given number x is a palindrome. """ return str(x) == str(x)[::-1] def is_super_palindrome(n): """ Determines whether a given positive integer n is a super palindrome. A super palindrome is an integer whose square is a palindrome. """ if n < 1: ...
from solution import is_super_palindrome def test_is_super_palindrome_positive_cases(): # 5^2 = 25 (not a palindrome) assert not is_super_palindrome(5) # 9^2 = 81 (not a palindrome) assert not is_super_palindrome(9) # 11^2 = 121 (a palindrome) assert is_super_palindrome(11) # 22^2 = 484 (a ...
[ { "docstring": "Check if a given number x is a palindrome.", "function_declaration": "def is_palindrome(x):", "function_name": "is_palindrome", "parameter_list": "(x)" }, { "docstring": "Determines whether a given positive integer n is a super palindrome.\nA super palindrome is an integer wh...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_palindrome(x):\n \"\"\"\n Checks if a given integer or string x is a palindrome.\n \"\"\"\n str_x = str(x)\n return str_x == str_x[::-1]\n\ndef is_super...
trial_gpt4o_9
{ "original_instruction": "Write a function that determines whether a given positive integer `n` is a super palindrome. A super palindrome is an integer whose square is a palindrome. Return `true` if `n` is a super palindrome and `false` otherwise.", "prompt_id": "0000008058", "row_id": 8058, "seed_ids": "['251...
0.756104
Leetcode_8058
C
[ "is_palindrome", "is_super_palindrome" ]
2
[ [ "is_super_palindrome", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
97835c6da9bd9c2139a3ee7c6861445ceafdd4db
c0c0bd22a02b2b885663ff20abbe1161b86e4364
v1.0
complete
Leetcode
Leetcode_8405_C
import math from typing import List, Tuple def distance(point1: Tuple[int, int], point2: Tuple[int, int]) -> float: """ Returns the Euclidean distance between two points. """ return math.sqrt((point1[0] - point2[0])**2 + (point1[1] - point2[1])**2) def max_length_line_segment(points: List[Tuple[int, i...
import math def distance(point1, point2): """ Returns the Euclidean distance between two points. """ return math.sqrt((point1[0] - point2[0])**2 + (point1[1] - point2[1])**2) def max_length_line_segment(points): """ Returns the pair of points that form the line segment with the maximum length....
from solution import distance, max_length_line_segment def test_distance(): assert distance((0, 0), (3, 4)) == 5.0 assert distance((1, 1), (4, 5)) == 5.0 assert distance((2, 3), (2, 3)) == 0.0 def test_max_length_line_segment(): points = [(0, 0), (1, 1), (2, 2)] assert max_length_line_segment(poin...
[ { "docstring": "Returns the Euclidean distance between two points.", "function_declaration": "def distance(point1, point2):", "function_name": "distance", "parameter_list": "(point1, point2)" }, { "docstring": "Returns the pair of points that form the line segment with the maximum length.\n\...
[ 1, 0, 1, 1, 1, 1, 1, 1, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "import math\n\ndef distance(point1, point2):\n \"\"\"\n Returns the Euclidean distance between two points on the 2D plane.\n \"\"\"\n return math.sqrt((point1[0] ...
trial_gpt4o_9
{ "original_instruction": "You are given an array `points` containing `n` elements where each element is a tuple representing the x and y coordinates of a point on a 2D plane. You are required to find the pair of points that forms the line segment with the maximum length. Return the coordinates of these two points. N...
0.736054
Leetcode_8405
C
[ "distance", "max_length_line_segment" ]
2
[ [ "max_length_line_segment", "distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6ddd457fd76211dad96cbef0d739b61689010abb
858d869560f771ea8be1989da53c1680ba143aa8
v1.0
complete
Leetcode
Leetcode_8797_C
def binary_to_int(binary_str: str) -> int: """ Convert a binary string to an integer. >>> binary_to_int("1101") == 13 >>> binary_to_int("0100") == 4 """ # Implementation here def max_xor_of_two_binaries(binaries: List[str]) -> int: """ Finds the maximum XOR value between any two binary numbers ...
def binary_to_int(binary_str): """ Convert a binary string to an integer. """ return int(binary_str, 2) def max_xor_of_two_binaries(binaries): """ Finds the maximum XOR value between any two binary numbers from the list. """ max_xor = 0 num_ints = [binary_to_int(b) for b in binaries...
from solution import max_xor_of_two_binaries def test_max_xor_of_two_binaries(): # Test with simple binary numbers assert max_xor_of_two_binaries(["1010", "0101"]) == 15 # Test where maximum XOR comes from the last pair assert max_xor_of_two_binaries(["0000", "1111", "0101"]) == 15 # Test where the...
[ { "docstring": "Convert a binary string to an integer.", "function_declaration": "def binary_to_int(binary_str):", "function_name": "binary_to_int", "parameter_list": "(binary_str)" }, { "docstring": "Finds the maximum XOR value between any two binary numbers from the list.", "function_d...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def find_maximum_xor(nums):\n \"\"\"\n Returns the maximum XOR value among any two binary numbers represented as strings in the list nums.\n \"\"\"\n # Convert ea...
trial_gpt4o_8
{ "original_instruction": "You are given `n` strings, each string representing a binary number. You need to find the maximum XOR value between any two of the given binary numbers. Return _the maximum XOR value that can be obtained by selecting exactly two of the given binary numbers_.", "prompt_id": "0000008797", ...
0.741473
Leetcode_8797
C
[ "binary_to_int", "max_xor_of_two_binaries" ]
2
[ [ "max_xor_of_two_binaries", "binary_to_int" ] ]
1
[]
false
[]
false
pytest
true
[]
true
cf5836c03b795a35dac38bf442347693de4547d6
187e328f34a183c2239f4d28ac6a163ed1fadf9b
v1.0
complete
Leetcode
Leetcode_8896_C
def split_array_into_subsets(arr, k): """ Split the integer array into exactly `k` non-empty subsets such that the maximum sum of any subset is as small as possible. Return the minimum possible value of the maximum sum of the `k` subsets. >>> split_array_into_subsets([1, 2, 3, 4], 3) == 4 >>> split_arr...
def can_partition(nums, k, max_sum): subset_sums = [0] * k return backtrack(0, nums, subset_sums, k, max_sum) def backtrack(index, nums, subset_sums, k, max_sum): if index == len(nums): return True for i in range(k): if subset_sums[i] + nums[index] <= max_sum: subset_su...
from solution import split_array_into_subsets def test_example_case(): assert split_array_into_subsets([1, 2, 3, 4], 3) == 4 def test_single_element_case(): assert split_array_into_subsets([10], 1) == 10 def test_equal_distribution_case(): assert split_array_into_subsets([1, 1, 1, 1], 2) == 2 def test_u...
[ { "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 backtrack(index, nums, subset_sums, k, max_sum):", "function_name": "back...
[ 0, 0, 0, 0, 1, 1, 1, 1, 0, 0 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def can_partition(arr, n, k, target):\n subset_sums = [0] * k\n arr.sort(reverse=True)\n\n def backtrack(index):\n if index == n:\n return True\n ...
trial_gpt4o_7
{ "original_instruction": "You are given an integer array `arr` of length `n` and an integer `k`. Split the integer array into exactly `k` non-empty subsets such that the maximum sum of any subset is as small as possible. Return the minimum possible value of the maximum sum of the `k` subsets.", "prompt_id": "00000...
0.663481
Leetcode_8896
C
[ "can_partition", "backtrack", "split_array_into_subsets" ]
3
[ [ "can_partition", "backtrack" ], [ "split_array_into_subsets", "can_partition" ] ]
2
[]
false
[]
false
pytest
true
[]
true
61591242c51edb3a6ab0b692e2514f8e0a699f15
f8a3293d5d6fc102d51c4c26bd37c3892cbea24b
v1.0
complete
Leetcode
Leetcode_9464_C
from typing import List, Tuple def is_balanced(edges: List[Tuple[int, int]], n: int) -> bool: """ Determines whether the binary tree represented by edges is balanced. A binary tree is defined to be balanced if, for any node, the height difference between its left and right subtrees is at most 1. ...
from collections import defaultdict class TreeNode: def __init__(self, val=0): self.val = val self.left = None self.right = None def build_tree(edges, n): if n == 0: return None nodes = {i: TreeNode(i) for i in range(1, n + 1)} children = defaultdict(list) for...
from solution import is_balanced def test_balanced_tree(): edges = [(1, 2), (1, 3), (2, 4), (2, 5)] n = 5 assert is_balanced(edges, n) def test_unbalanced_tree(): edges = [(1, 2), (1, 3), (2, 4), (4, 5)] n = 5 assert not is_balanced(edges, n) def test_single_node_tree(): edges = [] n ...
[]
[ 0, 1, 1, 0, 1, 1, 1, 1, 1, 1 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, x):\n self.val = x\n self.left = None\n self.right = None\n\ndef construct_tree(edges, n):\n from collections ...
trial_gpt4o_9
{ "original_instruction": "You are given a binary tree with `n` nodes, where each node is labeled from `1` to `n`. The tree is represented as a list of `n-1` pairs of integers, where each pair `(u, v)` denotes an edge between nodes `u` and `v`. Implement a function to determine whether the binary tree is balanced. A ...
0.78639
Leetcode_9464
C
[ "build_tree", "is_balanced_tree", "is_balanced" ]
3
[ [ "is_balanced", "build_tree" ], [ "is_balanced", "is_balanced_tree" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
f59db7266bdc16a54263bde2fcf634dbdb7bf1bc
32193c2fc0605c02919f11c7a7625b3e8ca5b225
v1.0
complete
Leetcode
Leetcode_9553_C
import math from typing import List def euclidean_distance(p1, p2): """ Calculate the Euclidean distance between two points p1 and p2. """ return math.sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2) def k_th_smallest_distance(points: List[List[int]], k: int) -> float: """Find the k-th smallest d...
import math def euclidean_distance(p1, p2): """ Calculate the Euclidean distance between two points p1 and p2. """ return math.sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2) def k_th_smallest_distance(points, k): """ Find the k-th smallest distance from a point to its nearest neighbor in th...
from solution import k_th_smallest_distance def test_basic_polygon(): points = [[0,0], [0,1], [1,1], [1,0]] k = 2 assert k_th_smallest_distance(points, k) == 1.0 def test_larger_polygon(): points = [[0,0], [0,2], [2,2], [2,0]] k = 2 assert k_th_smallest_distance(points, k) == 2.0 def test...
[ { "docstring": "Calculate the Euclidean distance between two points p1 and p2.", "function_declaration": "def euclidean_distance(p1, p2):", "function_name": "euclidean_distance", "parameter_list": "(p1, p2)" }, { "docstring": "Find the k-th smallest distance from a point to its nearest neigh...
[ 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": "import math\nfrom heapq import nsmallest\n\ndef euclidean_distance(p1, p2):\n \"\"\"\n Calculates the Euclidean distance between points p1 and p2.\n \"\"\"\n retu...
trial_gpt4o_9
{ "original_instruction": "You are given an array `points` containing the coordinates of some points on a 2D plane, where points[i] = [xi, yi]. The points form a simple polygon when joined sequentially by straight lines. You are also given an integer `k`. Your task is to find the k-th smallest distance from a point ...
0.662626
Leetcode_9553
C
[ "euclidean_distance", "k_th_smallest_distance" ]
2
[ [ "k_th_smallest_distance", "euclidean_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
dae7186e02ee4d7f92dd90f476bfebba6968981f
b5e1fcb0a1fc58e2d92b7059ab43cc613f582b6b
v1.0
complete
Leetcode
Leetcode_9690_C
def find_similar_word_sets(words: List[str]) -> int: """ Determine the number of distinct sets of similar words in the given list. A set of "similar" words is defined as a group of words where each word is similar to at least one other word in the group. Two words are considered to be "similar" if they can ...
def are_similar(word1, word2): """ Check if two words are similar by swapping at most two characters. """ if word1 == word2: return True if len(word1) != len(word2): return False # Finding the positions where the characters differ different_chars = [(w1, w2) for w1,...
from solution import find_similar_word_sets def test_find_similar_word_sets_basic(): assert find_similar_word_sets(["abc", "acb", "bac", "xyz", "xzy"]) == 2 def test_find_similar_word_sets_no_similar(): assert find_similar_word_sets(["abc", "def", "ghi"]) == 3 def test_find_similar_word_sets_identical_words(...
[ { "docstring": "Check if two words are similar by swapping at most two characters.", "function_declaration": "def are_similar(word1, word2):", "function_name": "are_similar", "parameter_list": "(word1, word2)" }, { "docstring": "Determine the number of distinct sets of similar words in the g...
[ 0, 1, 0, 1, 0, 0, 0, 0, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def are_similar(word1, word2):\n \"\"\"\n Check if two words are similar by the given definition.\n Two words are similar if they can be made identical by swapping a...
trial_gpt4o_3
{ "original_instruction": "You are given an array of strings `words` representing a list of words. Two words are considered to be \"similar\" if they can be made identical by swapping at most two characters within one word. Write a function to determine the number of distinct sets of \"similar\" words in the given li...
0.664625
Leetcode_9690
C
[ "are_similar", "find_similar_word_sets" ]
2
[ [ "find_similar_word_sets", "are_similar" ] ]
1
[]
false
[]
false
pytest
true
[]
true
471545c00c2febdd0ace0750ac1ea23d23b725bc
28547cec32277e6396fddded317008745bf0441f
v1.0
complete
Leetcode
Leetcode_9902_C
from typing import List def min_moves_to_water(heights: List[List[int]]) -> int: """ Find the minimum number of moves required to reach the water body starting from the highest peak. >>> min_moves_to_water([[0, 0, 0, 0], [0, 3, 2, 0], [0, 3, 1, 0], [0, 0, 0, 0]]) 1 >>> min_moves_to_water([[0, 0, 0...
from collections import deque def find_highest_peak(heights): """ Finds the highest peak and its coordinates in the matrix. """ max_height = float('-inf') peak_coords = [] for i in range(len(heights)): for j in range(len(heights[0])): if heights[i][j] > max_height: ...
from solution import min_moves_to_water def test_single_peak_single_path(): heights = [ [0, 0, 0, 0], [0, 3, 2, 0], [0, 3, 1, 0], [0, 0, 0, 0] ] assert min_moves_to_water(heights) == 1 def test_multiple_peaks_different_paths(): heights = [ [0, 0, 0, 0], ...
[ { "docstring": "Finds the highest peak and its coordinates in the matrix.", "function_declaration": "def find_highest_peak(heights):", "function_name": "find_highest_peak", "parameter_list": "(heights)" }, { "docstring": "Breadth-First Search (BFS) to find shortest path from the highest peak...
[ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef highest_peak_to_water(heights):\n \"\"\"\n Returns the minimum number of moves required to reach the water body starting from the h...
trial_gpt4o_7
{ "original_instruction": "You are given an m x n integer matrix `heights` representing the height of each unit cell in a continent. The continent is surrounded by a body of water represented by cells with height `0`. From any cell, you can travel to another if and only if the destination cell has a height equal to o...
0.587309
Leetcode_9902
C
[ "find_highest_peak", "bfs_to_water", "min_moves_to_water" ]
3
[ [ "min_moves_to_water", "bfs_to_water" ], [ "min_moves_to_water", "find_highest_peak" ] ]
2
[]
false
[]
false
pytest
true
[]
true
b586468962e1d289d2d0cee85de9f40f907900a7
27543dec453e25503062735e1ad7b10830f3ca25
v1.0
complete
Leetcode
Leetcode_9948_C
from typing import List def find_and_replace_pattern(words: List[str], pattern: str) -> List[str]: """ Find and return all strings from `words` that match the given `pattern`. A string matches the pattern if there is a bijective mapping between the characters of the `pattern` and the characters of the stri...
from typing import List def matches(word: str, pattern: str) -> bool: if len(word) != len(pattern): return False mapping_w2p = {} mapping_p2w = {} for w_char, p_char in zip(word, pattern): if w_char in mapping_w2p and mapping_w2p[w_char] != p_char: return False ...
from solution import find_and_replace_pattern def test_find_and_replace_pattern(): # Example test cases words = ["abc", "deq", "mee", "aqq", "dkd", "ccc"] pattern = "abb" result = find_and_replace_pattern(words, pattern) expected = ["mee", "aqq"] assert result == expected def test_all_mat...
[ { "docstring": null, "function_declaration": "def matches(word, pattern):", "function_name": "matches", "parameter_list": "(word, pattern)" }, { "docstring": null, "function_declaration": "def find_and_replace_pattern(words, pattern):", "function_name": "find_and_replace_pattern", ...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1, 1 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef find_and_replace_pattern(words: List[str], pattern: str) -> List[str]:\n def matches(word, pattern):\n if len(word) != len(pattern):\...
trial_gpt4o_8
{ "original_instruction": "You are given a list of strings `words` and a search query string `pattern`. Write a function to find and return all strings from `words` that match the pattern. A string matches the pattern if there is a bijective mapping between the characters of the pattern and the characters of the stri...
0.630814
Leetcode_9948
C
[ "matches", "find_and_replace_pattern" ]
2
[ [ "find_and_replace_pattern", "matches" ] ]
1
[]
false
[]
false
pytest
true
[]
true
fb27b3d22c38a1d0e4e7f62b9e63c7d07a2eb3d0
1efe3d98f7861e923a4c66ce6f860def3bd5ba51
v1.0
complete
Leetcode
Leetcode_10219_C
def minimize_max_time(arr, k): """ Distribute the tasks among the workers such that the worker who takes the longest time finishes their tasks in the shortest time possible. Args: arr (list of int): The array of integers representing the amount of time taken to complete each task. k (int): The ...
def can_assign_tasks_within_max_time(arr, k, max_time): assigned_workers = 1 current_time = 0 for task in arr: if current_time + task <= max_time: current_time += task else: assigned_workers += 1 current_time = task if assigned_workers > k...
from solution import minimize_max_time def test_minimize_max_time_single_task(): assert minimize_max_time([5], 1) == 5 def test_minimize_max_time_single_worker(): assert minimize_max_time([1, 2, 3, 4, 5], 1) == 15 def test_minimize_max_time_multiple_workers(): assert minimize_max_time([1, 2, 3, 4, 5], 2)...
[ { "docstring": null, "function_declaration": "def can_assign_tasks_within_max_time(arr, k, max_time):", "function_name": "can_assign_tasks_within_max_time", "parameter_list": "(arr, k, max_time)" }, { "docstring": null, "function_declaration": "def minimize_max_time(arr, k):", "funct...
[ 1, 0, 0, 0, 0, 0, 0, 1, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_valid(arr, k, mid):\n # Function to check if the tasks can be divided among workers such that\n # no worker takes more than 'mid' amount of time\n workers = 1...
trial_gpt4o_7
{ "original_instruction": "You are given an array of integers `arr` representing the amount of time taken to complete each task. Each task can be assigned to exactly one worker. However, each worker can only work on one task at a time. You have a limited number of workers, `k`, and you need to minimize the maximum ti...
0.714814
Leetcode_10219
C
[ "can_assign_tasks_within_max_time", "minimize_max_time" ]
2
[ [ "minimize_max_time", "can_assign_tasks_within_max_time" ] ]
1
[]
false
[]
false
pytest
true
[]
true
66d0fca8f0795c6205906b036251b5f03a62a6bf
3727e1d4479a21ccb010c38be2dada48f4dbb6c4
v1.0
complete
Leetcode
Leetcode_10305_C
def largest_connected_set(words: List[str]) -> int: """ Determines the size of the largest connected set of words. >>> largest_connected_set(["cat"]) 1 >>> largest_connected_set(["cat", "dog", "fish"]) 1 >>> largest_connected_set(["cat", "bat", "rat", "tat"]) 4 >>> largest_conne...
def differ_by_one_char(word1, word2): """ Returns True if word1 and word2 differ by exactly one character, otherwise False. """ if len(word1) != len(word2): return False differences = sum(1 for a, b in zip(word1, word2) if a != b) return differences == 1 def build_graph(words): ...
from solution import largest_connected_set def test_single_word(): assert largest_connected_set(["cat"]) == 1 def test_no_connections(): assert largest_connected_set(["cat", "dog", "fish"]) == 1 def test_all_connected(): assert largest_connected_set(["cat", "bat", "rat", "tat"]) == 4 def test_some_conne...
[ { "docstring": "Returns True if word1 and word2 differ by exactly one character, otherwise False.", "function_declaration": "def differ_by_one_char(word1, word2):", "function_name": "differ_by_one_char", "parameter_list": "(word1, word2)" }, { "docstring": "Builds an adjacency list for the w...
[ 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def differ_by_one_char(word1, word2):\n \"\"\"\n Helper function to check if two words differ by exactly one character.\n \"\"\"\n if len(word1) != len(word2):\n ...
trial_gpt4o_4
{ "original_instruction": "You are given a list of `n` words, `words`, where each word consists of lowercase English letters. Two words are considered connected if they differ by exactly one character. For example, \"bat\" and \"cat\" are connected, while \"bat\" and \"cats\" are not. Determine the _largest set of co...
0.66733
Leetcode_10305
C
[ "differ_by_one_char", "build_graph", "dfs", "largest_connected_set" ]
4
[ [ "build_graph", "differ_by_one_char" ], [ "largest_connected_set", "build_graph" ], [ "largest_connected_set", "dfs" ] ]
3
[]
false
[]
false
pytest
true
[]
true
b6bba53c89c8088c1477d5eefc8a439583cfa168
2aabd1c76bfdcddb24fe1a382173771e29658a31
v1.0
complete
Leetcode
Leetcode_10581_C
def min_operations_to_transform(a, b): """ Determines the minimum number of operations required to transform array a into array b. >>> min_operations_to_transform([1, 3, 2, 4], [1, 2, 3, 4]) 1 >>> min_operations_to_transform([1, 2, 3, 4], [1, 2, 3, 4]) 0 >>> min_operations_to_transform([4, 3, 2,...
def min_operations_to_transform(a, b): """ Determines the minimum number of operations required to transform array a into array b. """ n = len(a) position_in_b = {value: idx for idx, value in enumerate(b)} lis = [] for value in a: if value in position_in_b: index_b =...
from solution import min_operations_to_transform def test_example_case(): a = [1, 3, 2, 4] b = [1, 2, 3, 4] assert min_operations_to_transform(a, b) == 1 def test_already_identical(): a = [1, 2, 3, 4] b = [1, 2, 3, 4] assert min_operations_to_transform(a, b) == 0 def test_reverse_order(): ...
[ { "docstring": "Determines the minimum number of operations required to transform array a into array b.", "function_declaration": "def min_operations_to_transform(a, b):", "function_name": "min_operations_to_transform", "parameter_list": "(a, b)" }, { "docstring": "Helper function to perform...
[ 0, 0, 0, 0, 1, 0, 0, 0, 0 ]
1
hard
0.111
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def min_operations(a, b):\n \"\"\"\n Determines the minimum number of operations required to transform array `a` into array `b`\n by relocating marbles while preserv...
trial_gpt4o_4
{ "original_instruction": "You are given two arrays, `a` and `b`, both containing `n` unique integers. The arrays represent the initial and target arrangement of marbles on a table. You can perform the following operation any number of times:\n\n* Choose any marble from array `a` and relocate it to any valid position...
0.628379
Leetcode_10581
C
[ "min_operations_to_transform", "find_position_to_replace" ]
2
[ [ "min_operations_to_transform", "find_position_to_replace" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ba20455f7a9e42551b9f5b6646c134be171a3aaf
933d6647071a2e93df9829d05fbd5b670dab37e7
v1.0
complete
Leetcode
Leetcode_10739_C
def can_construct_from_chars(word, char_count): """ Helper function to check if a word can be constructed from the given characters. """ def longest_word_length(s: str, words: List[str]) -> int: """ Given a string `s` and an array of words `words`, return the length of the longest word in `words` that can ...
def can_construct_from_chars(word, char_count): """ Helper function to check if a word can be constructed from the given characters. """ word_count = {} for char in word: if char not in word_count: word_count[char] = 0 word_count[char] += 1 for char, count in wor...
from solution import longest_word_length def test_longest_word_length_all_words_constructible(): s = "abacadae" words = ["aa", "ab", "ba", "bad"] assert longest_word_length(s, words) == 3 def test_longest_word_length_some_words_constructible(): s = "abacadae" words = ["aa", "abc", "bad", "edc"] ...
[ { "docstring": "Helper function to check if a word can be constructed from the given characters.", "function_declaration": "def can_construct_from_chars(word, char_count):", "function_name": "can_construct_from_chars", "parameter_list": "(word, char_count)" }, { "docstring": "Returns the len...
[ 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 can_construct(word, s_chars):\n s_chars_copy = s_chars.copy()\n for char in word:\n if char in s_chars_copy:\n s_chars_copy.remove(char)\n ...
trial_gpt4o_8
{ "original_instruction": "Given a string `s` and an array of words `words`, return _the length of the longest word in_ `words` _that can be constructed from the characters in_ `s`. Each character in `s` can only be used once per word. If no word can be constructed, return 0.", "prompt_id": "0000010739", "row_id"...
0.757995
Leetcode_10739
C
[ "can_construct_from_chars", "longest_word_length" ]
2
[ [ "longest_word_length", "can_construct_from_chars" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2a2f1456b655cefebfa5c45aed5e375038821551
6e74d5fabc95ef206b7f97c639f7fb91209be2a9
v1.0
complete
Leetcode
Leetcode_10961_C
def merge_intervals(intervals): if not intervals: return [] intervals.sort(key=lambda x: x[0]) merged = [intervals[0]] for start, end in intervals[1:]: last_end = merged[-1][1] if start <= last_end + 1: merged[-1][1] = max(last_end, end) els...
def merge_intervals(intervals): if not intervals: return [] intervals.sort(key=lambda x: x[0]) merged = [intervals[0]] for start, end in intervals[1:]: last_end = merged[-1][1] if start <= last_end + 1: merged[-1][1] = max(last_end, end) els...
from solution import extract_string_using_intervals def test_single_interval(): assert extract_string_using_intervals("abcdef", [[1, 3]]) == "bcd" def test_multiple_overlapping_intervals(): assert extract_string_using_intervals("abcdef", [[1, 3], [2, 4]]) == "bcde" def test_multiple_non_overlapping_inter...
[ { "docstring": null, "function_declaration": "def merge_intervals(intervals):", "function_name": "merge_intervals", "parameter_list": "(intervals)" }, { "docstring": null, "function_declaration": "def extract_string_using_intervals(s, intervals):", "function_name": "extract_string_us...
[ 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def merge_intervals(intervals):\n if not intervals:\n return []\n\n # Sort intervals based on start times\n intervals.sort(key=lambda x: x[0])\n\n merged =...
trial_gpt4o_3
{ "original_instruction": "Given a string `s` and an array of intervals `[start, end]`, where each interval represents a pair of start and end indices (inclusive) within the string, return a new string with only the characters that are within the given intervals. If intervals overlap, they should be merged into a sin...
0.551145
Leetcode_10961
C
[ "merge_intervals", "extract_string_using_intervals" ]
2
[ [ "extract_string_using_intervals", "merge_intervals" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6cae63123a56802114d8857aea4db60732835bbe
49add938ad5cdbb63c1fc3b6b45926c6aed63c1e
v1.0
complete
Leetcode
Leetcode_11013_C
def make_palindrome(s: str) -> str: """ Given a string `s`, remove the minimum number of characters from `s` so that it becomes a valid palindrome. A string is a valid palindrome if it reads the same forward and backward. Return the result string after the minimum number of deletions. If there are multipl...
def longest_palindromic_subsequence(s): n = len(s) dp = [[0] * n for _ in range(n)] for i in range(n): dp[i][i] = 1 for cl in range(2, n + 1): for i in range(n - cl + 1): j = i + cl - 1 if s[i] == s[j]: dp[i][j] = dp[i + 1][j - 1] + 2 ...
from solution import make_palindrome def test_single_character(): assert make_palindrome("a") == "a" def test_already_palindrome(): assert make_palindrome("aba") == "aba" assert make_palindrome("abba") == "abba" def test_remove_one_character(): assert make_palindrome("abc") == "a" or make_palindrome(...
[ { "docstring": null, "function_declaration": "def longest_palindromic_subsequence(s):", "function_name": "longest_palindromic_subsequence", "parameter_list": "(s)" }, { "docstring": null, "function_declaration": "def build_palindrome(s, dp):", "function_name": "build_palindrome", ...
[ 0, 0, 1, 1, 0, 0, 0, 0, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def min_deletions_to_palindrome(s):\n \"\"\"\n Removes the minimum number of characters from `s` to make it a valid palindrome.\n Returns the result string after the...
trial_gpt4o_3
{ "original_instruction": "Given a string `s`, remove the minimum number of characters from `s` so that it becomes a valid palindrome. A string is a valid palindrome if it reads the same forward and backward. Return _the result string after the minimum number of deletions_. If there are multiple possible results, ret...
0.831371
Leetcode_11013
C
[ "longest_palindromic_subsequence", "build_palindrome", "make_palindrome" ]
3
[ [ "make_palindrome", "build_palindrome" ], [ "make_palindrome", "longest_palindromic_subsequence" ] ]
2
[]
false
[]
false
pytest
true
[]
true
4730163e0786ce2148b68fef56b9b8eb994d754b
ee3bb6b0b98f7f9df8c6fef14e835e83a257ca5e
v1.0
complete
Leetcode
Leetcode_11233_C
from typing import List, Tuple def is_palindrome(word: str) -> bool: """ Check if the given word is a palindrome. >>> is_palindrome("racecar") True >>> is_palindrome("level") True >>> is_palindrome("hello") False >>> is_palindrome("a") True >>> is_palindrome("") True """...
def is_palindrome(word): return word == word[::-1] def palindrome_pairs(words): pairs = [] for i in range(len(words)): for j in range(len(words)): if i != j: if is_palindrome(words[i] + words[j]): pairs.append((i, j)) return pairs
from solution import is_palindrome, palindrome_pairs def test_is_palindrome(): assert is_palindrome("racecar") == True assert is_palindrome("level") == True assert is_palindrome("hello") == False assert is_palindrome("a") == True assert is_palindrome("") == True def test_palindrome_pairs_case_1():...
[ { "docstring": null, "function_declaration": "def is_palindrome(word):", "function_name": "is_palindrome", "parameter_list": "(word)" }, { "docstring": null, "function_declaration": "def palindrome_pairs(words):", "function_name": "palindrome_pairs", "parameter_list": "(words)" ...
[ 0, 0, 0, 0, 0, 1, 0, 1, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_palindrome(word):\n \"\"\"\n Check if a given word is a palindrome.\n \"\"\"\n return word == word[::-1]\n\ndef palindrome_pairs(words):\n \"\"\"\n R...
trial_gpt4o_7
{ "original_instruction": "Given a list of `words`, find all pairs of distinct words that, when concatenated, form a palindrome. A palindrome is a word that reads the same backward as forward. Return a list of pairs `(i, j)`, such that the concatenation of `words[i]` and `words[j]` forms a palindrome. Each pair shoul...
0.771857
Leetcode_11233
C
[ "is_palindrome", "palindrome_pairs" ]
2
[ [ "palindrome_pairs", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
543c2818ab5c89f7430cbe32d8b25db7ced4d9bb
190e8527e9b0b3bb018640ded023daaea4f8fc81
v1.0
complete
Leetcode
Leetcode_11343_C
class TreeNode: def __init__(self, value): self.value = value self.left = None self.right = None def insert_into_bst(root, value): if root is None: return TreeNode(value) if value < root.value: root.left = insert_into_bst(root.left, value) else: root.righ...
class TreeNode: def __init__(self, value): self.value = value self.left = None self.right = None def insert_into_bst(root, value): if root is None: return TreeNode(value) if value < root.value: root.left = insert_into_bst(root.left, value) else: root.righ...
from solution import sum_of_k_distance_from_root def test_sum_of_k_distance_from_root(): assert sum_of_k_distance_from_root([3, 1, 4, 0, 2], 1) == 5 # 1 + 4 assert sum_of_k_distance_from_root([3, 1, 4, 0, 2], 2) == 2 # 0 + 2 assert sum_of_k_distance_from_root([3, 1, 4, 0, 2], 0) == 3 # 3 assert sum_...
[]
[ 0, 1, 1, 1, 1, 0, 1, 1, 0, 0 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, key):\n self.left = None\n self.right = None\n self.val = key\n\ndef insert(root, key):\n if root is None:\n ...
trial_gpt4o_7
{ "original_instruction": "You are given an array of integers `arr` and an integer `k`. Your task is to build a binary search tree (BST) from `arr` and determine the sum of all elements within the BST that are **k distance** away from the root. \n\nHere, the distance is defined as the number of edges between the root...
0.599581
Leetcode_11343
C
[ "insert_into_bst", "build_bst", "sum_at_k_distance", "sum_of_k_distance_from_root" ]
4
[ [ "build_bst", "insert_into_bst" ], [ "sum_of_k_distance_from_root", "build_bst" ], [ "sum_of_k_distance_from_root", "sum_at_k_distance" ] ]
3
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
ecbaa2d9bfb5a789afe942d1a5be7a7540c3c5b6
14362c5235a9eb52c7cd3b30da7bad93af928792
v1.0
complete
Leetcode
Leetcode_11357_C
from typing import List def maximal_rectangle(grid: List[List[int]]) -> int: """ Returns the maximum area of a rectangle filled with empty cells in a grid. :param grid: List[List[int]] - 2D grid where 0 represents an empty cell and 1 represents a wall. :return: int - Maximum area of a rectangle fi...
def maximal_rectangle(grid): """ Returns the maximum area of a rectangle filled with empty cells in a grid. :param grid: List[List[int]] - 2D grid where 0 represents an empty cell and 1 represents a wall. :return: int - Maximum area of a rectangle filled with empty cells. """ if not grid: r...
from solution import maximal_rectangle def test_maximal_rectangle_simple(): grid = [ [0, 1, 0, 0], [0, 1, 1, 0], [0, 0, 0, 0] ] assert maximal_rectangle(grid) == 4 def test_maximal_rectangle_single_cell(): grid = [ [0] ] assert maximal_rectangle(grid) == 1 def ...
[ { "docstring": "Returns the maximum area of a rectangle filled with empty cells in a grid.\n\n:param grid: List[List[int]] - 2D grid where 0 represents an empty cell and 1 represents a wall.\n:return: int - Maximum area of a rectangle filled with empty cells.", "function_declaration": "def maximal_rectangle...
[ 1, 1, 0, 0, 1, 1, 1, 0, 0, 0 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def max_histogram_area(heights):\n \"\"\"\n Helper function that calculates the maximum rectangular area in a histogram given its heights.\n \"\"\"\n stack = []\n...
trial_gpt4o_6
{ "original_instruction": "You are given a 2D list of integers `grid` representing a grid of size `m x n`, where each cell contains either a `0` (representing an empty cell) or a `1` (representing a wall). You need to find the maximum area of a rectangle that can be formed by empty cells. Return _an integer represent...
0.717608
Leetcode_11357
C
[ "maximal_rectangle", "largest_rectangle_area" ]
2
[ [ "maximal_rectangle", "largest_rectangle_area" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5cccae5f048a587986527889aa7ae6ba4a7c89c3
967bf2e2fc929374ef98c0faed682a08a79cdb56
v1.0
complete
Leetcode
Leetcode_11598_C
class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None def constructTree(arr): """Construct a binary tree from an integer array such that performing an in-order traversal of the tree returns the original array. >>> root = constructTree([1, 2, 3])...
class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None def constructTree(arr): def buildTree(arr, start, end): if start > end: return None # Find the middle index of the current subarray mid = (start + end) // ...
import pytest def test_constructTree(): root = constructTree([1, 2, 3]) assert isTreeValid(root, [1, 2, 3]) def test_constructTree_single_element(): root = constructTree([1]) assert isTreeValid(root, [1]) def test_constructTree_multiple_elements(): root = constructTree([1, 2, 3, 4, 5]) assert...
[]
[ 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": "class TreeNode:\n def __init__(self, x):\n self.val = x\n self.left = None\n self.right = None\n\ndef constructTree(arr):\n if not arr:\n re...
trial_gpt4o_7
{ "original_instruction": "You are given an integer array `arr` representing a sequence of integers. You want to create a binary tree from this sequence such that for any given node, one of its children (if any) has a value that is greater than or equal to the value of the node itself, and the other child (if any) ha...
0.574115
Leetcode_11598
C
[ "constructTree", "inorderTraversal", "isTreeValid" ]
3
[ [ "isTreeValid", "inorderTraversal" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
false
[]
true
e527554baf8d0e1cb61d2f67414c440021236e03
6031c253dd7216aa65d7d6dc22c2dc6aeced8c25
v1.0
complete
Leetcode
Leetcode_11655_C
from typing import List, Optional class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def build_tree_from_str(tree_str: str) -> Optional[TreeNode]: """ Build a binary tree from a string of comma-separated values represent...
from collections import deque class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def build_tree_from_str(tree_str): if not tree_str: return None nodes = tree_str.split(',') root = TreeNode(int(nodes[...
from solution import level_order_traversal, build_tree_from_str, TreeNode def test_level_order_traversal(): assert level_order_traversal("3,9,20,null,null,15,7") == [[3], [9, 20], [15, 7]] assert level_order_traversal("1") == [[1]] assert level_order_traversal("1,2,3,4,5,6,7") == [[1], [2, 3], [4, 5, 6, 7]...
[]
[ 0, 1, 1, 1, 1, 0, 1, 1, 1, 1 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "from typing import List, Optional\nimport collections\n\nclass TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = l...
trial_gpt4o_1
{ "original_instruction": "Given a binary tree, return the level order traversal of its nodes' values. (i.e., from left to right, level by level). The binary tree is represented by a string of comma-separated values, and nodes are given in a level-order format where 'null' represents an empty node. Write a function t...
0.582787
Leetcode_11655
C
[ "build_tree_from_str", "level_order_traversal" ]
2
[ [ "level_order_traversal", "build_tree_from_str" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
534fab0034c7e6f854f5687e4e3f431a9c085527
48e35fdec4443cf36a41035049abe5c59459af25
v1.0
complete
Leetcode
Leetcode_11693_C
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def max_depth(root): """Return the maximum depth of the binary tree. >>> root = TreeNode(1, TreeNode(2), TreeNode(3)) >>> max_depth(root) 2 >>> root = Tre...
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def max_depth(root): if not root: return 0 left_depth = max_depth(root.left) right_depth = max_depth(root.right) return max(left_depth, right_depth) +...
def test_max_depth(): root = TreeNode(1, TreeNode(2), TreeNode(3)) assert max_depth(root) == 2 root = TreeNode(1, TreeNode(2, TreeNode(3), TreeNode(4)), TreeNode(5)) assert max_depth(root) == 3 def test_find_all_nodes_at_depth(): root = TreeNode(1, TreeNode(2), TreeNode(3)) assert [node.val for...
[]
[ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\ndef find_farthest_valu...
trial_gpt4o_5
{ "original_instruction": "Given a binary tree, root of the tree is given to you along with an integer x. You need to find the maximum depth of the binary tree. Then consider all nodes at that maximum depth and return the value of the node which is the farthest from node with value x. If there are multiple nodes whic...
0.556454
Leetcode_11693
C
[ "max_depth", "find_all_nodes_at_depth", "distance_between_nodes", "farthest_node" ]
4
[ [ "farthest_node", "distance_between_nodes" ], [ "farthest_node", "find_all_nodes_at_depth" ], [ "farthest_node", "max_depth" ] ]
3
[]
false
[ "TreeNode" ]
true
pytest
false
[]
true
6a442bc363fdabc00c347b3dbe0aac0fbd0954b5
9bbad3b797e63bf0ff5d69713da87731c30150ff
v1.0
complete
Leetcode
Leetcode_12229_C
def maxMinDistance(positions: List[int], d: int) -> int: """ Given a list of positions and an integer d, return the maximum minimum distance between any two positions, where positions[i] represents the position of the ith house on a straight line. Place d houses such that the minimum distance between...
def canPlaceHouses(positions, d, min_dist): count = 1 last_pos = positions[0] for i in range(1, len(positions)): if positions[i] - last_pos >= min_dist: count += 1 last_pos = positions[i] if count == d: return True return False def maxMin...
from solution import maxMinDistance def test_case_1(): positions = [1, 2, 8, 4, 9] d = 3 assert maxMinDistance(positions, d) == 3 def test_case_2(): positions = [1, 2, 3, 4, 7] d = 3 assert maxMinDistance(positions, d) == 3 def test_case_3(): positions = [5, 5, 5, 5, 5] d = 2 asse...
[ { "docstring": null, "function_declaration": "def canPlaceHouses(positions, d, min_dist):", "function_name": "canPlaceHouses", "parameter_list": "(positions, d, min_dist)" }, { "docstring": null, "function_declaration": "def maxMinDistance(positions, d):", "function_name": "maxMinDis...
[ 1, 0, 1, 1, 0, 1, 1, 0, 1, 1 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_50000_combined_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def canPlaceHouses(positions, d, min_dist):\n count = 1 # Place the first house at the first position\n last_position = positions[0]\n \n for i in range(1, len(p...
trial_gpt4o_9
{ "original_instruction": "Given a list of `positions` and an integer `d`, return the maximum minimum distance between any two positions, where `positions[i]` represents the position of the ith house on a straight line. You are required to place `d` houses such that the minimum distance between any two houses is as l...
0.636787
Leetcode_12229
C
[ "canPlaceHouses", "maxMinDistance" ]
2
[ [ "maxMinDistance", "canPlaceHouses" ] ]
1
[]
false
[]
false
pytest
true
[]
true
633956a99afa6a4c938788d96608b064d43d9da4
93cacdd78b2afc7cf5b5058cf23873f7c5b00f0a