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 | complete | Taco | Taco_17039_C | def is_valid_path(path: str) -> bool:
"""
Determines if a path is valid, i.e., it returns to the starting point.
>>> is_valid_path('UDLR')
True
>>> is_valid_path('UUDDLLRR')
True
>>> is_valid_path('UUDLRR')
False
>>> is_valid_path('UU')
False
>>> is_valid_path('')
True
... | def is_valid_path(path):
"""
Determines if a path is valid, i.e., it returns to the starting point.
"""
vertical = 0
horizontal = 0
for move in path:
if move == 'U':
vertical += 1
elif move == 'D':
vertical -= 1
elif move == 'L':
horiz... | from solution import is_valid_path, check_paths
def test_is_valid_path():
assert is_valid_path('UDLR') == True
assert is_valid_path('UUDDLLRR') == True
assert is_valid_path('UUDLRR') == False
assert is_valid_path('UU') == False
assert is_valid_path('') == True
def test_check_paths():
paths = [... | [
{
"docstring": "Determines if a path is valid, i.e., it returns to the starting point.",
"function_declaration": "def is_valid_path(path):",
"function_name": "is_valid_path",
"parameter_list": "(path)"
},
{
"docstring": "Checks multiple paths to determine their validity.",
"function_decl... | [
0,
0,
0,
1,
0
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_path_valid(path):\n \"\"\"\n Determines if the given path returns to the starting point.\n \n A path is valid if the number of 'U's equals the n... | trial_gpt4o_3 | {
"original_instruction": "A well-known university is organizing a programming competition, and the organizers have decided they need a method to determine if the contestants' paths through campus meet certain requirements. Each path consists of a series of vertical and horizontal movements specified as up (U), down ... | 0.628154 | Taco_17039 | C | [
"is_valid_path",
"check_paths"
] | 2 | [
[
"check_paths",
"is_valid_path"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f68d14a39d2b2ab2c246d02646c36195155f288c | de65f3eeae769184cccaef25cc46fff8708673c9 | |||
v1.0 | complete | Taco | Taco_16974_C | from typing import List
def prime_product(lst: List[int]) -> int:
""" Write a function that takes a list of integers and returns the product of all the prime numbers in the list. If the list contains no prime numbers, return 1.
>>> prime_product([2, 3, 5, 7])
210
>>> prime_product([1, 4, 6, 8, 9])
... | from typing import List
def is_prime(n: int) -> bool:
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
max_divisor = int(n ** 0.5) + 1
for d in range(3, max_divisor, 2):
if n % d == 0:
return False
return True
def prime_prod... | from solution import prime_product
def test_prime_product_with_primes():
assert prime_product([2, 3, 5, 7]) == 210
assert prime_product([11, 13, 17]) == 2431
def test_prime_product_with_no_primes():
assert prime_product([1, 4, 6, 8, 9]) == 1
assert prime_product([0, 1, 15, 16, 18]) == 1
def test_prim... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def prime_product(lst):",
"function_name": "prime_product",
"parameter_list": "(lst)"
}
] | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from typing import List\n\ndef is_prime(n: int) -> bool:\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n re... | trial_gpt4o_0 | {
"original_instruction": "Write a function that takes a list of integers and returns the product of all the prime numbers in the list. If the list contains no prime numbers, return 1.\n\nRules:\n- A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself.\n- Your functio... | 0.708758 | Taco_16974 | C | [
"is_prime",
"prime_product"
] | 2 | [
[
"prime_product",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 36c0ebb2f61fd69101a19918b0c0971605e9a7cb | 98b1dd096acc3a4704243168d719b47c56fdf401 | |||
v1.0 | complete | Taco | Taco_16646_C | from typing import List, Tuple
def can_form_triangle(arr: List[int]) -> str:
""" Determine if there exist three numbers in the list that can form the sides of a triangle with a positive area.
>>> can_form_triangle([1, 2, 3, 4])
'YES'
>>> can_form_triangle([10, 20, 30])
'NO'
>>> can_form_triang... | def can_form_triangle(arr):
arr.sort()
for i in range(len(arr) - 2):
if arr[i] + arr[i + 1] > arr[i + 2]:
return "YES"
return "NO"
def solve(triangle_list):
results = []
for triangle_data in triangle_list:
N, arr = triangle_data
results.append(can_form_triangle(a... | import pytest
from solution import can_form_triangle, solve, parse_input, main
def test_can_form_triangle():
assert can_form_triangle([1, 2, 3, 4]) == "YES"
assert can_form_triangle([10, 20, 30]) == "NO"
assert can_form_triangle([6, 1, 6, 9, 8]) == "YES"
assert can_form_triangle([2, 2, 2]) == "YES"
... | [
{
"docstring": null,
"function_declaration": "def can_form_triangle(arr):",
"function_name": "can_form_triangle",
"parameter_list": "(arr)"
},
{
"docstring": null,
"function_declaration": "def solve(triangle_list):",
"function_name": "solve",
"parameter_list": "(triangle_list)"
... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def can_form_triangle(sides):\n sides.sort()\n n = len(sides)\n for i in range(n - 2):\n if sides[i] + sides[i + 1] > sides[i + 2]:\n re... | trial_gpt4o_2 | {
"original_instruction": "Read problems statements in Mandarin Chinese, Russian, and Vietnamese as well.\n\nYou are given a list of integers. Determine if there exist three numbers in the list that can form the sides of a triangle with a positive area.\n\n------ Input ------ \n\nThe first line contains a single inte... | 0.684213 | Taco_16646 | C | [
"can_form_triangle",
"solve",
"parse_input",
"main"
] | 4 | [
[
"solve",
"can_form_triangle"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | e84d576648e4b45f2c46d35f4779d360c794500f | 3e80e490b44a896205494b72412772ba40cc3ff4 | |||
v1.0 | complete | Taco | Taco_16439_C | def min_cost_and_length_to_connect_locations(N: int, M: int, edges: List[Tuple[int, int, int]]) -> int:
""" Ensure that all locations in Neoterica are connected with minimum total length and cost.
:param N: the number of locations
:param M: the number of potential roads
:param edges: a list of tuples ea... | def find(parent, i):
if parent[i] == i:
return i
else:
return find(parent, parent[i])
def union(parent, rank, x, y):
root_x = find(parent, x)
root_y = find(parent, y)
if rank[root_x] < rank[root_y]:
parent[root_x] = root_y
elif rank[root_x] > rank[root_y]:
p... | from solution import min_cost_and_length_to_connect_locations
def test_example():
assert min_cost_and_length_to_connect_locations(4, 5, [(1, 2, 4), (1, 3, 1), (1, 4, 3), (2, 3, 2), (3, 4, 5)]) == 6
def test_single_edge():
assert min_cost_and_length_to_connect_locations(2, 1, [(1, 2, 10)]) == 10
def test_mult... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class UnionFind:\n def __init__(self, n):\n self.parent = list(range(n))\n self.rank = [0] * n\n\n def find(self, u):\n if self.parent[u... | trial_gpt4o_4 | {
"original_instruction": "You are a newly appointed architect of a futuristic city, Neoterica. As part of an infrastructure project, you are responsible for laying down a series of roads that connect various pivotal locations throughout the city. The city has a total of $N$ locations, and you are provided with $M$ p... | 0.717482 | Taco_16439 | C | [
"find",
"union",
"min_cost_and_length_to_connect_locations"
] | 3 | [
[
"min_cost_and_length_to_connect_locations",
"find"
],
[
"min_cost_and_length_to_connect_locations",
"union"
],
[
"union",
"find"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 9bc2253aa785f36532b6930873eb0fe2b966723c | 37dd120e77e07a1b2a3e9fc506be741641dc0630 | |||
v1.0 | complete | Taco | Taco_16820_C | import math
from typing import List, Tuple
def lcm(a: int, b: int) -> int:
"""Calculate the least common multiple of two integers."""
return abs(a * b) // math.gcd(a, b)
def earliest_time_for_lights(n: int, cycle_times: List[int], queries: List[Tuple[int, ...]]) -> List[int]:
"""Determine the earliest tim... | import math
def lcm(a, b):
"""
Returns the least common multiple of a and b.
"""
return abs(a * b) // math.gcd(a, b)
def earliest_time_for_lights(n, cycle_times, queries):
results = []
for query in queries:
m = query[0]
intersections = query[1:]
if m == 0:
r... | import pytest
from solution import earliest_time_for_lights
def test_example_case():
n = 5
cycle_times = [4, 6, 8, 12, 15]
queries = [
(2, 1, 2),
(3, 1, 3, 5),
(2, 2, 4)
]
expected = [12, 120, 12]
assert earliest_time_for_lights(n, cycle_times, queries) == expected
def ... | [
{
"docstring": "Returns the least common multiple of a and b.",
"function_declaration": "def lcm(a, b):",
"function_name": "lcm",
"parameter_list": "(a, b)"
},
{
"docstring": null,
"function_declaration": "def earliest_time_for_lights(n, cycle_times, queries):",
"function_name": "ear... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from math import gcd\nfrom functools import reduce\n\ndef lcm(x, y):\n \"\"\"\n Compute the Least Common Multiple of x and y\n \"\"\"\n return (x * y) ... | trial_gpt4o_1 | {
"original_instruction": "In a small city, the traffic lights are controlled by a smart system. There are $n$ intersections in the city, each with its own traffic light. Each traffic light has a cycle time of $c_i$ seconds, which means it takes $c_i$ seconds for the light at the $i$-th intersection to return to gree... | 0.560199 | Taco_16820 | C | [
"lcm",
"earliest_time_for_lights"
] | 2 | [
[
"earliest_time_for_lights",
"lcm"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 88fdcfcb94a8f183068e0d0a861b527120265400 | 075d9e47bde39215f397392c9854db7a6b669dea | |||
v1.0 | complete | Taco | Taco_15990_C | def can_deliver_all_packages(D: int, E: int, connections: List[Tuple[int, int, int]], P: int, packages: List[Tuple[int, int, int]]) -> str:
""" Determines if all packages can be delivered within their respective time limits.
:param D: Number of destinations
:param E: Number of connections between desti... | import sys
import heapq
def dijkstra(graph, start, D):
"""
Performs Dijkstra's algorithm to find the shortest path from start to
all other nodes in the graph.
:param graph: Dictionary representation of graph where key is node and
value is list of tuples (neighbor, travel time)
... | def test_example1():
D = 5
E = 5
connections = [(1, 2, 3), (1, 3, 5), (2, 4, 2), (3, 5, 2), (4, 5, 3)]
P = 3
packages = [(1, 4, 5), (2, 5, 6), (1, 5, 8)]
assert can_deliver_all_packages(D, E, connections, P, packages) == "YES"
def test_example2():
D = 4
E = 4
connections = [(1, ... | [
{
"docstring": "Performs Dijkstra's algorithm to find the shortest path from start to \nall other nodes in the graph.\n\n:param graph: Dictionary representation of graph where key is node and \n value is list of tuples (neighbor, travel time)\n:param start: Starting node for Dijkstra's algorithm\n:... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import sys\nimport heapq\n\ndef dijkstra(graph, start, D):\n \"\"\"\n Performs Dijkstra's algorithm to find the shortest path from start to \n all other n... | trial_gpt4o_0 | {
"original_instruction": "You are asked to design a logistics system for delivering packages. Each package has to be delivered to a specific destination within a predetermined time limit. Each destination can be reached directly from other destinations, but the travel time between destinations can vary. The main goa... | 0.593917 | Taco_15990 | C | [
"dijkstra",
"can_deliver_all_packages"
] | 2 | [
[
"can_deliver_all_packages",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 13b9915ab6ddf37adaf1340a8042830b7701f203 | 502339cae0cb84695379148e80a4f8d0834619fe | |||
v1.0 | complete | Taco | Taco_17101_C | def next_prime(N: int) -> int:
"""
Write a function to identify the next prime number.
Input
The input consists of a single line containing an integer N.
Output
Your function should output the smallest prime number that is greater than N.
Constraints
1 ≤ N ≤ 10^6
... | def is_prime(num):
"""
Helper function to check if num is a prime number.
"""
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:
re... | from solution import next_prime
def test_next_prime_after_14():
assert next_prime(14) == 17
def test_next_prime_after_1():
assert next_prime(1) == 2
def test_next_prime_after_17():
assert next_prime(17) == 19
def test_next_prime_after_10():
assert next_prime(10) == 11
def test_next_prime_large_inpu... | [
{
"docstring": "Helper function to check if num is a prime number.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns the smallest prime number that is greater than N.",
"function_declaration": "def next_prime... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Helper function to check if num is a prime number.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n ... | trial_gpt4o_0 | {
"original_instruction": "Write a function to identify the next prime number.\n\nInput\n\nThe input consists of a single line containing an integer N.\n\nOutput\n\nYour function should output the smallest prime number that is greater than N.\n\nConstraints\n\n1 ≤ N ≤ 10^6\n\nSAMPLE INPUT\n14\n\nSAMPLE OUTPUT\n17",
... | 0.776041 | Taco_17101 | C | [
"is_prime",
"next_prime"
] | 2 | [
[
"next_prime",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 1ba7e441d1cb6452c64e6a50268f334304880a83 | d36926208de24f9b53b1779d29cf3a5fc7dd58ef | |||
v1.0 | complete | Taco | Taco_16933_C | def max_length_even_sum_subarray(arr):
"""
This function returns the maximum length of a contiguous subarray
such that the sum of its elements is even.
>>> max_length_even_sum_subarray([1, 2, 3, 4, 5]) == 4
>>> max_length_even_sum_subarray([1, 3, 5]) == 2
>>> max_length_even_sum_subarray([2, 4, ... | def max_length_even_sum_subarray(arr):
"""
This function returns the maximum length of a contiguous subarray
such that the sum of its elements is even.
"""
current_sum = 0
max_length = 0
first_odd_index = -1
for i, num in enumerate(arr):
current_sum += num
if current_su... | import pytest
from solution import max_length_even_sum_subarray, solve
def test_max_length_even_sum_subarray():
assert max_length_even_sum_subarray([1, 2, 3, 4, 5]) == 4
assert max_length_even_sum_subarray([1, 3, 5]) == 2
assert max_length_even_sum_subarray([2, 4, 6, 8]) == 4
assert max_length_even_sum... | [
{
"docstring": "This function returns the maximum length of a contiguous subarray\nsuch that the sum of its elements is even.",
"function_declaration": "def max_length_even_sum_subarray(arr):",
"function_name": "max_length_even_sum_subarray",
"parameter_list": "(arr)"
},
{
"docstring": null,... | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_even_sum_subarray_length(n, arr):\n \"\"\"\n Returns the maximum length of a contiguous subarray with an even sum.\n \"\"\"\n max_length = 0\n ... | trial_gpt4o_4 | {
"original_instruction": "You are given an array of integers. Your task is to find the maximum length of a contiguous subarray, such that the sum of its elements is even.\n\nInput\n\nThe first line contains an integer n (1 ≤ n ≤ 300,000) – the number of elements in the array.\nThe second line contains n integers a1,... | 0.69172 | Taco_16933 | C | [
"max_length_even_sum_subarray",
"solve"
] | 2 | [
[
"solve",
"max_length_even_sum_subarray"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4ac01e6b2995e6f425c1752d4de46ae91436e755 | 590b2347b435476cb5b1c42592c2da5de48c04ba | |||
v1.0 | complete | Taco | Taco_15303_C | def find_parent(parent, i):
""" Find the representative of the set that element i is a part of.
"""
pass
def union(parent, rank, x, y):
""" Union of two subsets x and y based on the rank.
"""
pass
def connected_components(n, edges):
""" Find the number of connected components in the graph.... | def find_parent(parent, i):
if parent[i] == i:
return i
return find_parent(parent, parent[i])
def union(parent, rank, x, y):
xroot = find_parent(parent, x)
yroot = find_parent(parent, y)
if rank[xroot] < rank[yroot]:
parent[xroot] = yroot
elif rank[xroot] > rank[yroot]:
... | def test_find_parent_and_union():
parent = [0, 1, 2, 3, 4]
rank = [0, 0, 0, 0, 0]
union(parent, rank, 0, 1)
assert find_parent(parent, 0) == find_parent(parent, 1)
union(parent, rank, 1, 2)
assert find_parent(parent, 0) == find_parent(parent, 2)
def test_connected_components():
n1 = 5
e... | [
{
"docstring": null,
"function_declaration": "def find_parent(parent, i):",
"function_name": "find_parent",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_parent(parent, i):\n if parent[i] == i:\n return i\n return find_parent(parent, parent[i])\n\ndef union(parent, rank, x, y):\n xroot = fin... | trial_gpt4o_0 | {
"original_instruction": "Imagine you are working with a system of connected computers in a network. Each computer needs periodic updates and these updates can be transmitted from one computer to another directly if there is a direct cable connection between them. However, setting up direct cable connections between... | 0.611621 | Taco_15303 | C | [
"find_parent",
"union",
"connected_components",
"min_connections_to_make_connected",
"process_input"
] | 5 | [
[
"connected_components",
"find_parent"
],
[
"connected_components",
"union"
],
[
"min_connections_to_make_connected",
"connected_components"
],
[
"process_input",
"min_connections_to_make_connected"
],
[
"union",
"find_parent"
]
] | 5 | [
"process_input"
] | false | [] | false | pytest | false | [] | true | b1e6af84f002736a5119324452045fa5cb2f38cf | 612f445ac2240517496d8fc516aabfb52cf5b49e | |||
v1.0 | complete | Taco | Taco_16420_C | from typing import List
def maximalRectangle(matrix: List[List[str]]) -> int:
""" Calculate the area of the largest rectangle containing only `1`s in a given 2D grid of `0`s and `1`s.
>>> maximalRectangle([
... ['1', '0', '1', '0', '0'],
... ['1', '0', '1', '1', '1'],
... ['1', '1', '1', '1', '1'],... | def maximalRectangle(matrix):
if not matrix or not matrix[0]:
return 0
max_area = 0
dp = [0] * len(matrix[0])
for row in matrix:
for idx, val in enumerate(row):
dp[idx] = dp[idx] + 1 if val == '1' else 0
max_area = max(max_area, largestRectangleArea(dp))
... | from solution import maximalRectangle
def test_maximalRectangle():
matrix = [
['1', '0', '1', '0', '0'],
['1', '0', '1', '1', '1'],
['1', '1', '1', '1', '1'],
['1', '0', '0', '1', '0']
]
assert maximalRectangle(matrix) == 6
matrix = [
['0', '0', '0'],
['... | [
{
"docstring": null,
"function_declaration": "def maximalRectangle(matrix):",
"function_name": "maximalRectangle",
"parameter_list": "(matrix)"
},
{
"docstring": null,
"function_declaration": "def largestRectangleArea(heights):",
"function_name": "largestRectangleArea",
"paramete... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def maximalRectangle(matrix):\n if not matrix or not matrix[0]:\n return 0\n \n max_area = 0\n dp = [0] * len(matrix[0])\n \n for row in m... | trial_gpt4o_0 | {
"original_instruction": "You are a game developer working on a puzzle game where players can form different types of shapes using square tiles. One of the shapes that players can create is a rectangle. However, you want to implement a feature that detects only the largest rectangle that consists of `1`s in a given ... | 0.645576 | Taco_16420 | C | [
"maximalRectangle",
"largestRectangleArea"
] | 2 | [
[
"maximalRectangle",
"largestRectangleArea"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e2cb2785a593f2f3a3f74250639b25b51b538480 | a6d22d4c8b7bbb2ce75f83f0526b42527582076a | |||
v1.0 | complete | Taco | Taco_16760_C | def solution(N: int, M: int, roads: List[Tuple[int, int]], Q: int, queries: List[Tuple[int, int]]) -> List[int]:
""" In a kingdom, there are N cities connected by M bidirectional roads.
Each road connects two cities, and it is guaranteed that there is a unique path between any pair of cities (i.e., the cities ... | import sys
import collections
sys.setrecursionlimit(200000)
def preprocess_tree(n, graph):
# BFS to find out the depth and the immediate parent (2^0) parent
depth = [-1] * (n + 1)
parent = [-1] * (n + 1)
root = 1
depth[root] = 0
queue = collections.deque([root])
while queue:
n... | def test_solution():
N, M = 5, 4
roads = [(1, 2), (1, 3), (3, 4), (3, 5)]
Q = 3
queries = [(2, 4), (5, 4), (1, 5)]
expected_output = [1, 3, 1]
assert solution(N, M, roads, Q, queries) == expected_output
def test_solution_large_case():
N, M = 6, 5
roads = [(1, 2), (1, 3), (2, 4), (2, 5),... | [
{
"docstring": null,
"function_declaration": "def preprocess_tree(n, graph):",
"function_name": "preprocess_tree",
"parameter_list": "(n, graph)"
},
{
"docstring": null,
"function_declaration": "def lca(a, b, depth, parent):",
"function_name": "lca",
"parameter_list": "(a, b, dep... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import sys\nfrom collections import defaultdict, deque\n\ninput = sys.stdin.read\n\ndef preprocess_lca(n, adj):\n LOG = 17 # As 2^17 > 100000\n\n depth = [0... | trial_gpt4o_2 | {
"original_instruction": "In a kingdom, there are N cities connected by M bidirectional roads. Each road connects two cities, and it is guaranteed that there is a unique path between any pair of cities (i.e., the cities and roads form a tree). The kingdom's ruler wants to monitor the traffic between cities to ensure... | 0.755816 | Taco_16760 | C | [
"preprocess_tree",
"lca",
"solution"
] | 3 | [
[
"solution",
"lca"
],
[
"solution",
"preprocess_tree"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 14937d030b0653231cb1bbf76a0a7e7a228a9af0 | 109f6b166562a6c5f500865aaee1a199e6e1554d | |||
v1.0 | complete | Taco | Taco_16801_C | def shortest_travel_times(number_of_cities: int, number_of_roads: int, central_hub_city: int, roads: List[Tuple[int, int, int]], target_cities: List[int]) -> List[Union[int, str]]:
""" Determine the shortest travel time from the central hub city to each of the target cities.
Args:
number_of_cities (int... | import heapq
import sys
def dijkstra(n, edges, start):
graph = {i: [] for i in range(1, n + 1)}
for u, v, w in edges:
graph[u].append((v, w))
graph[v].append((u, w))
distances = {i: sys.maxsize for i in range(1, n + 1)}
distances[start] = 0
priority_queue = [(0, start)]
wh... | def test_shortest_travel_times():
number_of_cities = 6
number_of_roads = 7
central_hub_city = 1
roads = [
(1, 2, 4),
(1, 3, 2),
(2, 3, 5),
(2, 4, 10),
(3, 5, 3),
(5, 4, 4),
(4, 6, 11)
]
target_cities = [4, 5, 6]
assert shortest_travel_t... | [
{
"docstring": null,
"function_declaration": "def dijkstra(n, edges, start):",
"function_name": "dijkstra",
"parameter_list": "(n, edges, start)"
},
{
"docstring": null,
"function_declaration": "def shortest_travel_times(number_of_cities, number_of_roads, central_hub_city, roads, target_... | [
0,
0,
0,
0,
0,
0,
0,
0,
1,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef shortest_travel_times(num_cities, num_roads, central_hub, roads, targets):\n graph = {i: [] for i in range(1, num_cities + 1)}\n \n fo... | trial_gpt4o_8 | {
"original_instruction": "Problem\n\nAt Tech Express, there is a need to optimize the delivery routes for its delivery vans. Each city is represented as a node in a graph, and the direct roads between the cities are represented as edges with associated travel time. The goal is to find the shortest travel time requir... | 0.745122 | Taco_16801 | C | [
"dijkstra",
"shortest_travel_times"
] | 2 | [
[
"shortest_travel_times",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | a66a70840d9c0ef08f2962a9f43c8a03250fc836 | f9f116cc78df3434ee0d236524cce9464d2eec5b | |||
v1.0 | complete | Taco | Taco_16951_C | def is_valid_octet(s: str) -> bool:
"""
Checks if the provided string is a valid IP address octet.
>>> is_valid_octet("255") True
>>> is_valid_octet("0") True
>>> is_valid_octet("00") False
>>> is_valid_octet("256") False
>>> is_valid_octet("1") True
"""
def generate_ip_addresses(S:... | def is_valid_octet(s):
"""
Checks if the provided string is a valid IP address octet.
"""
if s == "" or (len(s) > 1 and s[0] == '0') or int(s) > 255:
return False
return True
def generate_ip_addresses(S):
"""
Generates all possible valid IP addresses from the given string S.
"""... | from solution import is_valid_octet, generate_ip_addresses
def test_is_valid_octet():
assert is_valid_octet("255") == True
assert is_valid_octet("0") == True
assert is_valid_octet("00") == False
assert is_valid_octet("256") == False
assert is_valid_octet("1") == True
assert is_valid_octet("") =... | [
{
"docstring": "Checks if the provided string is a valid IP address octet.",
"function_declaration": "def is_valid_octet(s):",
"function_name": "is_valid_octet",
"parameter_list": "(s)"
},
{
"docstring": "Generates all possible valid IP addresses from the given string S.",
"function_decl... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def valid_ip_addresses(s):\n \"\"\"\n Given a string of digits, returns all valid IP addresses.\n \"\"\"\n def is_valid(segment):\n # Check if t... | trial_gpt4o_2 | {
"original_instruction": "Your task is to generate all possible valid IP addresses from a given string S of digits. The function should output each possible IP address in the standard dot-decimal form. An IP address consists of four octets, and each octet is a number between 0 and 255, inclusive. The octets are sepa... | 0.643729 | Taco_16951 | C | [
"is_valid_octet",
"generate_ip_addresses",
"print_ip_addresses"
] | 3 | [
[
"generate_ip_addresses",
"is_valid_octet"
],
[
"print_ip_addresses",
"generate_ip_addresses"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 7136be7dcce0536d8b74d9ef8299e2acea37cbb3 | 44ba5b012438a29ab56efa019c773fbf798590c1 | |||
v1.0 | complete | Taco | Taco_17187_C | import math
from heapq import heappop, heappush
from typing import List, Tuple
def solve():
""" Find the minimum distance Rika needs to travel to exit the maze.
The input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_N y_N
x_start y_start x_goal y_goal
... | import math
from heapq import heappop, heappush
def euclidean_distance(p1, p2):
return math.sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2)
def is_interior(polygon, point):
x, y = point
n = len(polygon)
inside = False
px, py = polygon[0]
for i in range(n + 1):
p_next_x, p_next_y = po... | def test_sample_case():
import sys
from io import StringIO
sys.stdin = StringIO("4\n0 0\n4 0\n4 4\n0 4\n0 0 4 4\n")
solve()
def test_no_route():
import sys
from io import StringIO
sys.stdin = StringIO("4\n0 0\n4 0\n4 4\n0 4\n-1 -1 5 5\n")
solve()
def test_small_polygon():
impor... | [
{
"docstring": null,
"function_declaration": "def euclidean_distance(p1, p2):",
"function_name": "euclidean_distance",
"parameter_list": "(p1, p2)"
},
{
"docstring": null,
"function_declaration": "def is_interior(polygon, point):",
"function_name": "is_interior",
"parameter_list"... | [
0,
0,
0,
0,
0,
1,
0,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\nimport math\n\ndef distance(p1, p2):\n return math.sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2)\n\ndef is_inside_polygon(polygon, x, y):\n ... | trial_gpt4o_5 | {
"original_instruction": "On the xy-plane, Rika is going to navigate through a polygonal maze. The maze has N vertices, defined by their Cartesian coordinates. To get out of the maze, Rika must start from the entrance vertex and travel to the exit vertex. She can move in straight lines from one vertex to any other v... | 0.586749 | Taco_17187 | C | [
"euclidean_distance",
"is_interior",
"dijkstra",
"shortest_route",
"solve"
] | 5 | [
[
"dijkstra",
"euclidean_distance"
],
[
"dijkstra",
"is_interior"
],
[
"shortest_route",
"dijkstra"
],
[
"shortest_route",
"is_interior"
],
[
"solve",
"shortest_route"
]
] | 5 | [] | false | [] | false | pytest | false | [] | true | f3de5383b83aa78d2f02f583a8f36af1c6e9f4c5 | a004e0ba9c52a2ba858f635b68a7a8d5ae628858 | |||
v1.0 | complete | Taco | Taco_17237_C | def task_order(input_str: str) -> str:
"""
Determine the order in which tasks should be completed so that all dependencies are satisfied.
If there are multiple valid orders, any one of them is acceptable.
If no valid order exists due to a circular dependency, indicate that the tasks cannot be complet... | def find_order(tasks):
from collections import defaultdict, deque
# Initialize graph and in-degree count
graph = defaultdict(list)
in_degree = defaultdict(int)
for task, dep in tasks.items():
for d in dep:
graph[d].append(task)
in_degree[task] += 1
# Initia... | from solution import task_order
def test_case_1():
input_str = "3\na: b c.\nb: c.\nc: ."
assert task_order(input_str) == "c b a"
def test_case_2():
input_str = "3\na: b.\nb: a.\nc: ."
assert task_order(input_str) == "Cyclic dependency detected."
def test_case_3():
input_str = "1\na: ."
assert... | [
{
"docstring": null,
"function_declaration": "def find_order(tasks):",
"function_name": "find_order",
"parameter_list": "(tasks)"
},
{
"docstring": null,
"function_declaration": "def parse_input(input_str):",
"function_name": "parse_input",
"parameter_list": "(input_str)"
},
... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_order(tasks):\n from collections import defaultdict, deque\n\n # Initialize graph and in-degree count\n graph = defaultdict(list)\n in_degree ... | trial_gpt4o_0 | {
"original_instruction": "Clara is organizing a team-building event for her company and she has come up with a unique idea called \"Chain Reaction\". In this game, each participant is assigned a task to accomplish. Each task will have a list of dependencies, meaning the participant can only perform their task after ... | 0.535293 | Taco_17237 | C | [
"find_order",
"parse_input",
"task_order"
] | 3 | [
[
"task_order",
"find_order"
],
[
"task_order",
"parse_input"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 77446b0a9fdfcceaa0cc9bf8377cf3a5143b7949 | f396f5831b11c6350f45ccf5456954d2643bbe61 | |||
v1.0 | complete | Taco | Taco_16522_C | def calculate_subtree_data_sum(n: int, edges: List[Tuple[int, int]], data_sizes: List[int], target_id: int) -> int:
"""
Calculate the sum of all data sizes in the subtree rooted at the given target node ID.
n: number of nodes in the tree
edges: list of tuples representing the edges of the tree
... | class TreeNode:
def __init__(self, node_id, data_size):
self.node_id = node_id
self.data_size = data_size
self.children = []
def build_tree(n, edges, data_sizes):
nodes = {i + 1: TreeNode(i + 1, data_sizes[i]) for i in range(n)}
for parent_id, child_id in edges:
nodes[p... | def test_calculate_subtree_data_sum():
assert calculate_subtree_data_sum(7, [(1, 2), (1, 3), (2, 4), (2, 5), (3, 6), (3, 7)], [10, 5, 15, 2, 3, 20, 25], 2) == 10
assert calculate_subtree_data_sum(7, [(1, 2), (1, 3), (2, 4), (2, 5), (3, 6), (3, 7)], [10, 5, 15, 2, 3, 20, 25], 3) == 60
assert calculate_subtre... | [] | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, node_id, data_size):\n self.node_id = node_id\n self.data_size = data_size\n self.children = []\n\ndef... | trial_gpt4o_0 | {
"original_instruction": "Anna is building a file storage system for a small startup. Each file in the system can be identified by a unique ID and is stored in memory as a binary tree, where each node represents a chunk of data. Each chunk has an integer value, representing the size of data it holds. \n\nAnna wants ... | 0.573542 | Taco_16522 | C | [
"build_tree",
"subtree_sum",
"calculate_subtree_data_sum"
] | 3 | [
[
"calculate_subtree_data_sum",
"build_tree"
],
[
"calculate_subtree_data_sum",
"subtree_sum"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | false | [] | true | 9c65878d7819997f8ebdffaa2c39ea7fc1dee8fd | 9f6294a28e93cca9644cd21132da569ee852167f | |||
v1.0 | complete | Taco | Taco_17182_C | def path_exists_in_binary_tree(test_cases):
"""
Determines if there exists a path from the root to any leaf in a given binary tree such that the sum of the values along the path equals the target integer.
The parameter `test_cases` is a list of tuples where each tuple contains:
1. A list of tree n... | from collections import deque, namedtuple
class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def build_tree(values):
if not values or values[0] == 'null':
return None
root = TreeNode(int(values[0]))
queue... | def test_case_1():
test_cases = [
(['5', '4', '8', '11', 'null', '13', '4', '7', '2', 'null', 'null', 'null', '1'], 22),
(['1', '2', '3'], 5)
]
expected = [1, 0]
assert path_exists_in_binary_tree(test_cases) == expected
def test_case_all_null():
test_cases = [
(['null'], 0)
... | [] | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def has_path_sum_from_root_to_leaf(root, target_sum):\n if not root:\n return False\n\n # If it's a leaf node\n if not root.left and not root.right... | trial_gpt4o_1 | {
"original_instruction": "You are given a binary tree and a target integer value. Write a function to determine if there exists a path from the root to any leaf such that the sum of the values along the path equals the target integer. A leaf is a node with no children.\n\n----- Input -----\n\nThe first line of input... | 0.606103 | Taco_17182 | C | [
"build_tree",
"has_path_sum",
"path_exists_in_binary_tree"
] | 3 | [
[
"path_exists_in_binary_tree",
"build_tree"
],
[
"path_exists_in_binary_tree",
"has_path_sum"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | false | [] | true | 2715c01a062d847be20b5dd5700d5c40b8c4b791 | a98e83c6ad749c4ff67864db13fb78772e6aaf66 | |||
v1.0 | complete | Taco | Taco_16281_C | def graph_coloring(n: int, m: int, k: int, edges: List[Tuple[int, int]]) -> Union[List[int], int]:
""" Determine whether it's possible to color the graph using exactly k distinct colors such that no two adjacent vertices share the same color.
Parameters:
n (int): The number of vertices.
m (int): Th... | def is_valid_coloring(graph, colors, v, c):
for i in range(len(graph)):
if graph[v][i] == 1 and colors[i] == c:
return False
return True
def graph_coloring_util(graph, m, colors, v, k):
if v == m:
return True
for c in range(1, k + 1):
if is_valid_coloring(graph,... | from solution import graph_coloring
def test_graph_coloring_possible_3_colors():
n, m, k = 3, 3, 3
edges = [(1, 2), (2, 3), (3, 1)]
result = graph_coloring(n, m, k, edges)
assert result != -1
assert len(set(result)) == 3
def test_graph_coloring_possible_3_colors_5_vertices():
n, m, k = 5, 4, 3... | [
{
"docstring": null,
"function_declaration": "def is_valid_coloring(graph, colors, v, c):",
"function_name": "is_valid_coloring",
"parameter_list": "(graph, colors, v, c)"
},
{
"docstring": null,
"function_declaration": "def graph_coloring_util(graph, m, colors, v, k):",
"function_na... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def graph_coloring(n, m, k, edges):\n def is_valid(vertex, color):\n for neighbor in adj[vertex]:\n if colors[neighbor] == color:\n ... | trial_gpt4o_2 | {
"original_instruction": "You are given a connected undirected graph with `n` vertices and `m` edges. Each vertex has a unique ID ranging from 1 to n. Your task is to determine whether it's possible to color the graph using exactly `k` distinct colors such that no two adjacent vertices share the same color.\n\nIf su... | 0.524732 | Taco_16281 | C | [
"is_valid_coloring",
"graph_coloring_util",
"graph_coloring"
] | 3 | [
[
"graph_coloring",
"graph_coloring_util"
],
[
"graph_coloring_util",
"is_valid_coloring"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | fbb17d2801f85d9190954cf9faf50cd90e076be6 | 1efbba15176b656b71886471b1340eca20d5f027 | |||
v1.0 | complete | Taco | Taco_17597_C | def execute_operations(Q: int, operations: List[str]) -> List[int]:
""" Process a list of operations on a dynamic array and return the results of sum operations.
>>> execute_operations(5, ["Insert 3", "Insert 1", "Sum 1", "Insert 4", "Sum 3"])
[3, 8]
>>> execute_operations(4, ["Insert 5", "Insert 10", "... | def process_operations(operations):
array = []
result = []
for op in operations:
if op.startswith('Insert'):
_, x = op.split()
array.append(int(x))
elif op.startswith('Sum'):
_, k = op.split()
k = int(k)
result.append(sum(array... | from solution import execute_operations
def test_insert_and_sum_operations():
operations = [
"Insert 3",
"Insert 1",
"Sum 1",
"Insert 4",
"Sum 3"
]
result = execute_operations(5, operations)
assert result == [3, 8]
def test_multiple_sums():
operations = [
... | [
{
"docstring": null,
"function_declaration": "def process_operations(operations):",
"function_name": "process_operations",
"parameter_list": "(operations)"
},
{
"docstring": null,
"function_declaration": "def execute_operations(Q, operations):",
"function_name": "execute_operations",... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def dynamic_array_operations(operations):\n \"\"\"\n Processes a list of operations on a dynamic array and returns the results of 'Sum' operations.\n \"\"... | trial_gpt4o_2 | {
"original_instruction": "Smith is a software developer working on a new project that requires efficient storage and retrieval of user data. He is considering using various data structures to optimize these operations. To analyze the system performance, Smith needs to calculate the time complexity for different oper... | 0.598965 | Taco_17597 | C | [
"process_operations",
"execute_operations"
] | 2 | [
[
"execute_operations",
"process_operations"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0c511950771269897e8ee5c111d579b9ce8e049a | 2316dbabc2ab6ab6ea0ab75f936944ac41bddf08 | |||
v1.0 | complete | Taco | Taco_17315_C | def enchanted_forest_solution(input_str: str) -> int:
""" Calculate the maximum magical energy that can be collected starting from any node and following the portals.
>>> enchanted_forest_solution("4\n10 20 30 40\n4\n0 1\n1 2\n2 3\n0 3")
100
>>> enchanted_forest_solution("5\n2 4 6 8 10\n6\n0 1\n1 2\n2 3... | def maximum_magical_energy(nodes, energies, edges):
from collections import defaultdict, deque
# Construct the graph
graph = defaultdict(list)
indegree = [0] * nodes
for u, v in edges:
graph[u].append(v)
indegree[v] += 1
# Find all the starting nodes (nodes with indegre... | from solution import enchanted_forest_solution
def test_example_1():
input_str = "4\n10 20 30 40\n4\n0 1\n1 2\n2 3\n0 3"
assert enchanted_forest_solution(input_str) == 100
def test_example_2():
input_str = "5\n2 4 6 8 10\n6\n0 1\n1 2\n2 3\n3 4\n0 3\n1 4"
assert enchanted_forest_solution(input_str) == ... | [
{
"docstring": null,
"function_declaration": "def maximum_magical_energy(nodes, energies, edges):",
"function_name": "maximum_magical_energy",
"parameter_list": "(nodes, energies, edges)"
},
{
"docstring": null,
"function_declaration": "def enchanted_forest_solution(input_str):",
"fu... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def maximum_magical_energy(nodes, energies, edges):\n from collections import defaultdict, deque\n \n # Construct the graph\n graph = defaultdict(list)... | trial_gpt4o_0 | {
"original_instruction": "Enchanted Forest\n\nIn an enchanted forest, there is a special path consisting of several nodes connected with directional edges. Each node contains a unique item, and collecting these items provides magical energy. The forest has a unique property where some nodes have a one-way portal to ... | 0.610535 | Taco_17315 | C | [
"maximum_magical_energy",
"enchanted_forest_solution"
] | 2 | [
[
"enchanted_forest_solution",
"maximum_magical_energy"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 361e3f9c155cf7ae5ab7cb3dbb8e8ef52191f070 | 5ae29ca24f123ed9ef885f20adc65731fa59b54b | |||
v1.0 | complete | Taco | Taco_17604_C | def next_prime(n: int) -> int:
""" Given an integer as input, return the smallest prime number greater than or equal to the input value.
If the input is a negative integer, return the smallest prime number, which is 2.
Examples:
>>> next_prime(12)
13
>>> next_prime(24)
29
>>> next_p... | def is_prime(n):
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return True
def next_prime(n):
if n < 2:
retur... | from solution import next_prime
def test_next_prime_with_positive_numbers():
assert next_prime(12) == 13
assert next_prime(24) == 29
assert next_prime(2) == 2
assert next_prime(17) == 17
assert next_prime(18) == 19
def test_next_prime_with_negative_numbers():
assert next_prime(-5) == 2
ass... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def next_prime(n):",
"function_name": "next_prime",
"parameter_list": "(n)"
}
] | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_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 ... | trial_gpt4o_0 | {
"original_instruction": "The next prime number\n---------------------\n\nWrite a function that takes an integer as input and returns the smallest prime number greater than or equal to the input value. The function should handle both positive and negative integers. For negative integers, return the smallest prime nu... | 0.717525 | Taco_17604 | C | [
"is_prime",
"next_prime"
] | 2 | [
[
"next_prime",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6bafb89890d1f9ff07e2f20c791dfa4e67c43a15 | baf9b4fd42f4131eda15e484ef7a924d12e04e44 | |||
v1.0 | complete | Taco | Taco_17307_C | def process_queries(n: int, queries: List[List[int]]) -> List[str]:
""" Given an undirected graph with n nodes and q queries, process each query to either add an edge or check connectivity.
Args:
n : int : Number of nodes
queries : List[List[int]] : List of queries, each query is of the form [ti, a... | def find(parent, i):
if parent[i] == i:
return i
else:
parent[i] = find(parent, parent[i])
return parent[i]
def union(parent, rank, x, y):
rootx = find(parent, x)
rooty = find(parent, y)
if rootx != rooty:
if rank[rootx] > rank[rooty]:
parent[rooty] = ro... | def test_process_queries():
assert process_queries(5, [[1, 1, 2], [1, 2, 3], [1, 3, 4], [2, 1, 4], [2, 1, 5], [1, 4, 5], [2, 1, 5]]) == ["YES", "NO", "YES"]
assert process_queries(4, [[2, 1, 2], [1, 1, 2], [2, 1, 2], [1, 2, 3], [2, 1, 3]]) == ["NO", "YES", "YES"]
def test_no_edges():
assert process_queries... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n else:\n parent[i] = find(parent, parent[i])\n return parent[i]\n\ndef union(paren... | trial_gpt4o_0 | {
"original_instruction": "Given an undirected graph with n (1 ≤ n ≤ 200,000) nodes and m (0 ≤ m ≤ 200,000) edges, and q (1 ≤ q ≤ 100,000) queries, answer each query efficiently. The graph is initially empty (contains no edges).\n\nEach query consists of a number ti (ti = 1, 2), which indicates the type of the query,... | 0.698037 | Taco_17307 | C | [
"find",
"union",
"process_queries"
] | 3 | [
[
"process_queries",
"find"
],
[
"process_queries",
"union"
],
[
"union",
"find"
]
] | 3 | [
"process_queries"
] | false | [] | false | pytest | false | [] | true | 8aea0ffee2d363e0eb0cf238a98f075b81298036 | 1e192952012a8e6b5d1652633df6f7ceb45bd707 | |||
v1.0 | complete | Taco | Taco_17742_C | def smallest_product_number(n: int) -> int:
"""
Finds the smallest positive integer x such that the product of the digits of x is equal to n.
>>> smallest_product_number(12) 26
>>> smallest_product_number(36) 49
>>> smallest_product_number(1) 1
>>> smallest_product_number(7) 7
>>> smallest_p... | def smallest_product_number(n):
"""
Finds the smallest positive integer x such that the product of the digits of x is equal to n.
"""
if n == 1:
return 1
# Handle the cases where n is a single digit
if 1 <= n <= 9:
return n
# Start checking from 10 upwards
x = 10
wh... | from solution import smallest_product_number
def test_smallest_product_number_12():
assert smallest_product_number(12) == 26
def test_smallest_product_number_36():
assert smallest_product_number(36) == 49
def test_smallest_product_number_1():
assert smallest_product_number(1) == 1
def test_smallest_prod... | [
{
"docstring": "Finds the smallest positive integer x such that the product of the digits of x is equal to n.",
"function_declaration": "def smallest_product_number(n):",
"function_name": "smallest_product_number",
"parameter_list": "(n)"
},
{
"docstring": "Calculates the product of the digi... | [
0,
0,
0,
1,
1
] | 2 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def smallest_product_number(n):\n \"\"\"\n Given a positive integer n, determine the smallest positive integer x \n such that the product of the digits of... | trial_gpt4o_4 | {
"original_instruction": "You are given a positive integer `n`. Your task is to determine the smallest positive integer `x` such that the product of the digits of `x` is equal to `n`.\n\nExample 1:\n\n`\nsmallest_product_number(12) returns 26`\n\nExplanation:\n\nThe product of the digits of 26 is 2 * 6 = 12, and the... | 0.721471 | Taco_17742 | C | [
"smallest_product_number",
"product_of_digits"
] | 2 | [
[
"smallest_product_number",
"product_of_digits"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 15164f41995e919f0e451a3e8d0ffc0b19c050ba | cbfaaba07a79e0f80371f1fc89d72318dfe66155 | |||
v1.0 | complete | Taco | Taco_17513_C | def prime_factors(n):
"""
Returns the prime factors of a given number n in ascending order.
>>> prime_factors(18) == [2, 3, 3]
>>> prime_factors(29) == [29]
>>> prime_factors(60) == [2, 2, 3, 5]
>>> prime_factors(2) == [2]
>>> prime_factors(1) == []
>>> prime_factors(15) == [3, 5]
""... | def prime_factors(n):
"""
Returns the prime factors of a given number n in ascending order.
"""
if n <= 1:
return []
factors = []
# Check for number of 2s in n
while n % 2 == 0:
factors.append(2)
n //= 2
# Check for odd factors from 3 upwards
factor = 3
... | import pytest
from solution import prime_factors, process_serial_numbers
def test_prime_factors():
assert prime_factors(18) == [2, 3, 3]
assert prime_factors(29) == [29]
assert prime_factors(60) == [2, 2, 3, 5]
assert prime_factors(2) == [2]
assert prime_factors(1) == []
assert prime_factors(15... | [
{
"docstring": "Returns the prime factors of a given number n in ascending order.",
"function_declaration": "def prime_factors(n):",
"function_name": "prime_factors",
"parameter_list": "(n)"
},
{
"docstring": "Processes a list of serial numbers to produce the desired output format.",
"fu... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def prime_factors(n):\n \"\"\"\n Returns the list of prime factors of n in ascending order.\n \"\"\"\n i = 2\n factors = []\n while i * i <= n:\n... | trial_gpt4o_2 | {
"original_instruction": "Sarah is an enthusiastic collector of rare stamps. She has recently acquired a new set and wants to catalog them in a unique way. Instead of sorting them by their year of issue, Sarah decides to organize them by the prime factors of their unique serial number.\n\nEach stamp in Sarah's colle... | 0.76785 | Taco_17513 | C | [
"prime_factors",
"process_serial_numbers"
] | 2 | [
[
"process_serial_numbers",
"prime_factors"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 392f67bdb69a52a2abd039a230b9a23a95d8f216 | 8d84d797a0d65597668b491f159d028fdec6b4c1 | |||
v1.0 | complete | Taco | Taco_16773_C | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def build_tree(nodes) -> TreeNode:
"""
Build a binary tree from a list of node values using level order traversal.
"""
if not nodes or nodes[0] == 'null':
... | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def build_tree(nodes):
if not nodes or nodes[0] == 'null':
return None
root = TreeNode(int(nodes[0]))
queue = [root]
i = 1
while queue and i < len... | from solution import build_tree, sum_even_levels, process_test_cases
def test_sum_even_levels():
tree_nodes = "1 2 3 null null 4 5".split()
root = build_tree(tree_nodes)
assert sum_even_levels(root) == 10
tree_nodes = "10 20 30 40 50 null null 60".split()
root = build_tree(tree_nodes)
assert s... | [] | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\n# Definition for a binary tree node.\nclass TreeNode:\n def __init__(self, x):\n self.val = x\n self.left = None\... | trial_gpt4o_1 | {
"original_instruction": "Violet loves solving complex puzzles using her favorite data structure, the binary tree. One day, while analyzing a specific binary tree, she stumbled upon an interesting challenge. Given a binary tree, determine the sum of all node values that are at even levels in the tree. The root of th... | 0.602523 | Taco_16773 | C | [
"build_tree",
"sum_even_levels",
"process_test_cases",
"main"
] | 4 | [
[
"process_test_cases",
"build_tree"
],
[
"process_test_cases",
"sum_even_levels"
]
] | 2 | [
"process_test_cases"
] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 2ccf077ffa673d102a4128055b4cf93b2389ead9 | 9c131fe59926caf727b6947a96ea3a7bbd461993 | |||
v1.0 | complete | Taco | Taco_16495_C | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def buildTreeFromInorderPostorder(inorder, postorder):
""" Helper function to build the binary tree from inorder and postorder traversals."""
# Implementation goes he... | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def buildTreeFromInorderPostorder(inorder, postorder):
if not inorder:
return None
root_val = postorder.pop()
root = TreeNode(root_val)
inorder_index... | from solution import reconstructTree, treeToList, TreeNode
def test_example1():
s = "9,3,15,20,7 9,15,7,20,3"
expected_output = [3, 9, 20, None, None, 15, 7]
root = reconstructTree(s)
assert treeToList(root) == expected_output
def test_example2():
s = "2,1,3 2,3,1"
expected_output = [1, 2, 3]
... | [] | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "# Definition for a binary tree node.\nclass TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n ... | trial_gpt4o_1 | {
"original_instruction": "Given an input string representation of the inorder and postorder traversal of a binary tree, reconstruct the original binary tree and return its root.\n\nThe input consists of two parts:\n1. An inorder traversal of the tree (comma-separated values).\n2. A postorder traversal of the tree (c... | 0.540082 | Taco_16495 | C | [
"buildTreeFromInorderPostorder",
"reconstructTree",
"treeToList"
] | 3 | [
[
"reconstructTree",
"buildTreeFromInorderPostorder"
]
] | 1 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 33d2e33667065fb9b21a5fbee07f81a61feed8bd | d9ba0807e424f79ccb0382c7ebfffc3b31556cad | |||
v1.0 | complete | Taco | Taco_17637_C | def find_depths(n: int, edges: List[Tuple[int, int]]) -> List[int]:
"""
Calculate the depth of each node in a tree from the root node, assuming root node is 1.
Args:
n : int : Number of nodes in the tree
edges : List[Tuple[int, int]] : List of edges in the tree, each edge represented as a tuple... | def find_depths(n, edges):
from collections import deque, defaultdict
# Create an adjacency list
tree = defaultdict(list)
for u, v in edges:
tree[u].append(v)
tree[v].append(u)
# Array to store depth of each node
depth = [-1] * (n + 1)
# Use BFS to find depth o... | from solution import convert_input_and_run
def test_sample_input_1():
n = 5
edges_list = ["1 2", "1 3", "3 4", "3 5"]
expected_output = [0, 1, 1, 2, 2]
assert convert_input_and_run(n, edges_list) == expected_output
def test_sample_input_2():
n = 6
edges_list = ["1 3", "3 2", "1 4", "4 5", "4 6... | [
{
"docstring": null,
"function_declaration": "def find_depths(n, edges):",
"function_name": "find_depths",
"parameter_list": "(n, edges)"
},
{
"docstring": null,
"function_declaration": "def convert_input_and_run(n, edges_list):",
"function_name": "convert_input_and_run",
"parame... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_depths(n, edges):\n from collections import deque, defaultdict\n \n # Create an adjacency list\n tree = defaultdict(list)\n for u, v in edg... | trial_gpt4o_0 | {
"original_instruction": "Tree Depth Calculation\n\nYou are given a tree with $n$ nodes, numbered from 1 to $n$, and $n-1$ edges, such that the tree is connected. The tree's root is node 1, and you need to find the depth of each node in the tree. In this problem, the depth of a node is the number of edges in the pat... | 0.690944 | Taco_17637 | C | [
"find_depths",
"convert_input_and_run"
] | 2 | [
[
"convert_input_and_run",
"find_depths"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7dbd2c472f979908b9b1768fdb35e6377ac221f7 | a3ade54a5364dfb5afc81903680930a317b45684 | |||
v1.0 | complete | Taco | Taco_17273_C | from typing import List, Tuple
def solve(n: int, edges: List[Tuple[int, int, int]], queries: List[Tuple[int, int]]) -> List[int]:
""" Given a tree with n nodes and weighted edges, find the length of the path between two given nodes for each query.
Args:
n: An integer, the number of nodes in the tree.
... | import sys
import collections
sys.setrecursionlimit(10000000)
def preprocess(tree, n):
"""
Perform BFS to calculate the distance from the root to every other node
and construct parent array for each node to facilitate LCA calculation.
"""
dist = [-1] * (n + 1)
parent = [-1] * (n + 1)
lev... | from solution import solve
def test_case_1():
n = 5
edges = [(1, 2, 3), (1, 3, 2), (3, 4, 4), (3, 5, 1)]
queries = [(1, 4), (2, 5), (4, 5)]
expected = [6, 6, 5]
assert solve(n, edges, queries) == expected
def test_case_2():
n = 3
edges = [(1, 2, 1), (2, 3, 2)]
queries = [(1, 2), (1, 3)... | [
{
"docstring": "Perform BFS to calculate the distance from the root to every other node \nand construct parent array for each node to facilitate LCA calculation.",
"function_declaration": "def preprocess(tree, n):",
"function_name": "preprocess",
"parameter_list": "(tree, n)"
},
{
"docstring... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import sys\nfrom collections import defaultdict, deque\n\nsys.setrecursionlimit(200000)\n\ndef preprocess_tree(n, edges):\n # Create adjacency list for the tree... | trial_gpt4o_2 | {
"original_instruction": "Given a tree with n nodes and weighted edges, you need to answer several queries. Each query asks you to find the length of the path between two given nodes.\n\nInput:\n- The first line contains an integer n (1 ≤ n ≤ 10^5) — the number of nodes in the tree.\n- Each of the next n-1 lines con... | 0.668105 | Taco_17273 | C | [
"preprocess",
"lca",
"find_path_length",
"solve"
] | 4 | [
[
"find_path_length",
"lca"
],
[
"solve",
"find_path_length"
],
[
"solve",
"preprocess"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | f1cdb1f8ba633b5eb4a89d72cb032995aa53e0cb | 49fd8cf108735417a4aba9cdc4d2f58ede4fd751 | |||
v1.0 | complete | Taco | Taco_17458_C | import re
from typing import List
def check_password_strength(passwords: List[str]) -> List[str]:
""" Check the strength of each password based on specific criteria.
Args:
passwords (List[str]): A list of password strings.
Returns:
List[str]: A list containing "STRONG" or "WEAK" for each pa... | import re
def check_password_strength(passwords):
results = []
for password in passwords:
if len(password) < 8:
results.append("WEAK")
continue
if not re.search(r'[a-z]', password):
results.append("WEAK")
continue
if not re.search(r'[A-Z]'... | from solution import validate_passwords
def test_all_strong_passwords():
passwords = ["Passw0rd!", "Str0ng#Pass1", "VeryStr0ng!@#"]
assert validate_passwords(3, passwords) == ["STRONG", "STRONG", "STRONG"]
def test_all_weak_passwords():
passwords = ["weak", "password", "12345678"]
assert validate_pass... | [
{
"docstring": null,
"function_declaration": "def check_password_strength(passwords):",
"function_name": "check_password_strength",
"parameter_list": "(passwords)"
},
{
"docstring": null,
"function_declaration": "def validate_passwords(N, passwords):",
"function_name": "validate_pass... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import re\n\ndef is_strong_password(password):\n \"\"\"\n Determine if a password is strong based on given criteria.\n \"\"\"\n if len(password) < 8:\n... | trial_gpt4o_2 | {
"original_instruction": "Alex is building a complex password validation system for his company's internal applications. A password is considered strong if it meets the following criteria:\n\n1. It has at least 8 characters.\n2. It contains both lowercase and uppercase alphabet characters.\n3. It has at least one nu... | 0.565811 | Taco_17458 | C | [
"check_password_strength",
"validate_passwords"
] | 2 | [
[
"validate_passwords",
"check_password_strength"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 80d0582482af9058c5134edbcf3867c966288c61 | d876e741ef1b194b6aa76275b20506a2f5af5ff8 | |||
v1.0 | complete | Taco | Taco_17370_C | from typing import List, Tuple
def find_best_capitals(test_cases: List[Tuple[int, int, List[Tuple[int, int, int]]]]) -> List[int]:
""" Find the optimal city to transform into the new capital for multiple test cases.
Parameters:
test_cases (List[Tuple[int, int, List[Tuple[int, int, int]]]]) : A list of... | import heapq
import sys
INF = sys.maxsize
def dijkstra(graph, start):
n = len(graph)
dist = [INF] * n
dist[start] = 0
pq = [(0, start)]
while pq:
current_dist, u = heapq.heappop(pq)
if current_dist > dist[u]:
continue
for v, weight in grap... | from solution import find_best_capitals
def test_case_1():
test_cases = [
(3, 3, [(1, 2, 1), (2, 3, 3), (1, 3, 4)])
]
assert find_best_capitals(test_cases) == [2]
def test_case_2():
test_cases = [
(4, 5, [(1, 2, 2), (1, 3, 3), (1, 4, 1), (2, 3, 4), (3, 4, 5)])
]
assert find_bes... | [
{
"docstring": null,
"function_declaration": "def dijkstra(graph, start):",
"function_name": "dijkstra",
"parameter_list": "(graph, start)"
},
{
"docstring": null,
"function_declaration": "def find_minimal_city(n, roads):",
"function_name": "find_minimal_city",
"parameter_list": ... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\nimport sys\n\nINF = sys.maxsize\n\ndef dijkstra(graph, start):\n n = len(graph)\n dist = [INF] * n\n dist[start] = 0\n pq = [(0, start)]\... | trial_gpt4o_0 | {
"original_instruction": "In a kingdom far away, there existed n cities numbered from 1 to n. These cities are connected by m bidirectional roads. The roads are represented as a list of triples (a, b, c), where a and b are the cities connected by the road and c is the cost to travel that road. The kingdom’s king wan... | 0.594389 | Taco_17370 | C | [
"dijkstra",
"find_minimal_city",
"find_best_capitals"
] | 3 | [
[
"find_best_capitals",
"find_minimal_city"
],
[
"find_minimal_city",
"dijkstra"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 4da710acf015c1e7ba09763d511c83d205cdd436 | 2af5e3c0a040b8c0c5620d990c25148664093d14 | |||
v1.0 | complete | Taco | Taco_17472_C | from typing import List, Tuple
def generate_schedule(T: int, D: int, tasks: List[str], dependencies: List[Tuple[str, str]]) -> str:
""" Generate the order in which the tasks should be executed so that all dependencies are respected.
Args:
T : int : number of tasks
D : int : number of dependencies
... | from collections import defaultdict, deque
def schedule_tasks(T, D, tasks, dependencies):
# Create graph and indegree dict
graph = defaultdict(list)
indegree = {task: 0 for task in tasks}
# Populate the graph and indegree based on dependencies
for dep in dependencies:
u, v = dep
gr... | from solution import generate_schedule
def test_sample_case():
tasks = ["a", "b", "c", "d", "e", "f"]
dependencies = [("a", "b"), ("a", "c"), ("b", "d"), ("c", "e"), ("d", "f"), ("e", "f")]
assert generate_schedule(6, 6, tasks, dependencies) == "a b c d e f" or generate_schedule(6, 6, tasks, dependencies) ... | [
{
"docstring": null,
"function_declaration": "def schedule_tasks(T, D, tasks, dependencies):",
"function_name": "schedule_tasks",
"parameter_list": "(T, D, tasks, dependencies)"
},
{
"docstring": null,
"function_declaration": "def generate_schedule(T, D, tasks, dependencies):",
"func... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict, deque\n\ndef schedule_tasks(T, D, tasks, dependencies):\n # Create graph and indegree dict\n graph = defaultdict(list)\n... | trial_gpt4o_0 | {
"original_instruction": "A company needs to schedule a set of tasks, some of which must be completed before others start. Each task is labeled with a unique identifier, and there can be dependencies between the tasks. Given a list of task identifiers and a set of dependencies, determine the order in which the tasks... | 0.587868 | Taco_17472 | C | [
"schedule_tasks",
"generate_schedule"
] | 2 | [
[
"generate_schedule",
"schedule_tasks"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4f1e07cf38a4841dae93b668db445ee159726312 | ae6b60a16a0b8c2823df2bdd9a619d32a1ca30e5 | |||
v1.0 | complete | Taco | Taco_17849_C | def segregatePrime(N: int, Arr: List[int]) -> None:
"""
Given an array of integers, rearrange the array such that all the prime numbers
appear before all non-prime numbers, while maintaining the relative order among
prime and non-prime numbers.
>>> arr = [4, 7, 6, 5, 8, 3]
>>> segregatePrime(... | def is_prime(num):
"""
Helper function to check if a number is prime.
"""
if num <= 1:
return False
if num == 2:
return True
if num % 2 == 0:
return False
p = 3
while p * p <= num:
if num % p == 0:
return False
p += 2
return True
d... | from solution import segregatePrime
def test_example_case_1():
arr = [4, 7, 6, 5, 8, 3]
segregatePrime(len(arr), arr)
assert arr == [7, 5, 3, 4, 6, 8]
def test_example_case_2():
arr = [10, 11, 13, 15, 17]
segregatePrime(len(arr), arr)
assert arr == [11, 13, 17, 10, 15]
def test_single_element... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Function to segregate prime numbers to the front of the array while maintaining\nthe relative order of prim... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from math import isqrt\n\ndef 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 re... | trial_gpt4o_2 | {
"original_instruction": "Given an array of integers, your task is to rearrange the array such that all the prime numbers appear before all non-prime numbers, while maintaining the relative order among prime and non-prime numbers.\n\nExample 1:\nInput:\nN = 6\nArr = {4, 7, 6, 5, 8, 3}\nOutput:\n7 5 3 4 6 8\nExplanat... | 0.653164 | Taco_17849 | C | [
"is_prime",
"segregatePrime"
] | 2 | [
[
"segregatePrime",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 97b298d6beb61bc36336cc3f3a34ef5e5e873292 | 72d5136b267013107fe3ce4781b2d4b93b731fb7 | |||
v1.0 | complete | Taco | Taco_17064_C | class ListNode:
def __init__(self, val=0, next=None):
self.val = val
self.next = next
def mergeTwoLists(l1, l2):
"""
Merges two sorted linked lists l1 and l2 into a single sorted linked list.
Returns the head of the merged linked list.
"""
dummy = ListNode()
current = dummy
... | class ListNode:
def __init__(self, val=0, next=None):
self.val = val
self.next = next
def mergeTwoLists(l1, l2):
"""
Merges two sorted linked lists l1 and l2 into a single sorted linked list.
Returns the head of the merged linked list.
"""
dummy = ListNode()
current = dummy
... | from solution import merge_sorted_linked_lists
def test_merge_sorted_linked_lists():
assert merge_sorted_linked_lists([([], [0, 1])]) == [[0, 1]]
assert merge_sorted_linked_lists([([1, 3, 5], [2, 4, 6])]) == [[1, 2, 3, 4, 5, 6]]
assert merge_sorted_linked_lists([([0, 5, 9, 11], [2, 3, 7])]) == [[0, 2, 3, 5... | [] | [
0,
0,
0,
1
] | 1 | hard | 0.25 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_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 merge_two_sorted_lists(l1, l2):\n dummy = Li... | trial_gpt4o_4 | {
"original_instruction": "The task requires you to implement a function to merge two sorted linked lists and return it as a new sorted list. The new list should be made by splicing together the nodes of the first two lists.\n\nInput\n\nThe first line contains a single integer T, the number of test cases. The followi... | 0.554745 | Taco_17064 | C | [
"mergeTwoLists",
"list_to_linked_list",
"linked_list_to_list",
"merge_sorted_linked_lists",
"main"
] | 5 | [
[
"merge_sorted_linked_lists",
"linked_list_to_list"
],
[
"merge_sorted_linked_lists",
"list_to_linked_list"
],
[
"merge_sorted_linked_lists",
"mergeTwoLists"
]
] | 3 | [] | false | [
"ListNode"
] | true | pytest | true | [] | true | dd575d612da635d429981058430f55a9ed007a9c | d57973279cb3802916b28dbeb0b82b0fa9a3d3ca | |||
v1.0 | complete | Taco | Taco_17831_C | def check_intersection(coords1: List[int], coords2: List[int]) -> str:
""" Determine if two line segments intersect.
>>> check_intersection([0, 0, 1, 2], [2, 3, 3, 3])
"Non-intersecting"
>>> check_intersection([1, 2, 2, 3], [0, 0, 0, 0])
"Non-intersecting"
>>> check_intersection([1, 1, 2, 2... | def orientation(p, q, r):
"""
To find the orientation of the ordered triplet (p, q, r).
The function returns following values
0 --> p, q and r are collinear
1 --> Clockwise
2 --> Counterclockwise
"""
val = (q[1] - p[1]) * (r[0] - q[0]) - (q[0] - p[0]) * (r[1] - q[1])
if val == 0:
... | from solution import check_intersection
def test_non_intersecting():
assert check_intersection([0, 0, 1, 2], [2, 3, 3, 3]) == "Non-intersecting"
def test_intersecting():
assert check_intersection([1, 2, 2, 3], [0, 0, 0, 0]) == "Non-intersecting"
def test_collinear_and_non_intersecting():
assert check_int... | [
{
"docstring": "To find the orientation of the ordered triplet (p, q, r).\nThe function returns following values\n0 --> p, q and r are collinear\n1 --> Clockwise\n2 --> Counterclockwise",
"function_declaration": "def orientation(p, q, r):",
"function_name": "orientation",
"parameter_list": "(p, q, r... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_intersecting(rect1, rect2):\n \"\"\"\n Determine if two rectangles intersect.\n \n rect1 and rect2 are provided as lists [x1, y1, x2, y2]\n w... | trial_gpt4o_2 | {
"original_instruction": "Example\n\nInput\n\n3 2\n0 0 1 2\n2 3 3 3\n1 2\n2 3\n0 0 0 0\n5 5 5 5\n\nOutput\n\nNon-intersecting\nIntersecting",
"prompt_id": "00017831",
"row_id": 17831,
"seed_ids": "[8208]"
} | 0.635689 | Taco_17831 | C | [
"orientation",
"on_segment",
"do_intersect",
"check_intersection"
] | 4 | [
[
"check_intersection",
"do_intersect"
],
[
"do_intersect",
"on_segment"
],
[
"do_intersect",
"orientation"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 039347dd2ba410048258c32bb1e8ba50cf0897e3 | 99749b3158df8ad880942d5de4a1a8c3b766b07c | |||
v1.0 | complete | Taco | Taco_17816_C | def sum_of_squares_of_digits(n):
"""
This function calculates the sum of the squares of the digits of a number.
"""
# Your implementation here
def will_terminate_at_1(n):
"""
This function determines if the sequence starting from n will terminate at 1 or enter a loop.
"""
# Your impleme... | def sum_of_squares_of_digits(n):
"""
This function calculates the sum of the squares of the digits of a number.
"""
return sum(int(digit) ** 2 for digit in str(n))
def will_terminate_at_1(n):
"""
This function determines if the sequence starting from n will terminate at 1 or enter a loop.
"... | from solution import sum_of_squares_of_digits, will_terminate_at_1, process_test_cases
def test_sum_of_squares_of_digits():
assert sum_of_squares_of_digits(19) == 82
assert sum_of_squares_of_digits(82) == 68
assert sum_of_squares_of_digits(100) == 1
assert sum_of_squares_of_digits(2) == 4
def test_wil... | [
{
"docstring": "This function calculates the sum of the squares of the digits of a number.",
"function_declaration": "def sum_of_squares_of_digits(n):",
"function_name": "sum_of_squares_of_digits",
"parameter_list": "(n)"
},
{
"docstring": "This function determines if the sequence starting f... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def will_end_at_1(n):\n def get_next_number(num):\n return sum(int(digit) ** 2 for digit in str(num))\n \n seen_numbers = set()\n \n while n ... | trial_gpt4o_1 | {
"original_instruction": "Aditya loves numbers and has recently come across an interesting sequence. The sequence starts with a single digit number and the next number is formed by summing the square of the digits of the current number. The sequence continues until it reaches 1 or forms a loop. Aditya wants to know ... | 0.666655 | Taco_17816 | C | [
"sum_of_squares_of_digits",
"will_terminate_at_1",
"process_test_cases"
] | 3 | [
[
"process_test_cases",
"will_terminate_at_1"
],
[
"will_terminate_at_1",
"sum_of_squares_of_digits"
]
] | 2 | [
"process_test_cases"
] | false | [] | false | pytest | true | [] | true | 373bb77a4a70b1b8e80fade3b52ebd9a7ae00866 | d9d28a7dcdb6d15c5670b7a0bcc33d0d8e010413 | |||
v1.0 | complete | Taco | Taco_17129_C | from typing import List, Tuple
def max_path_sum(matrix: List[List[int]]) -> int:
""" Calculates the maximum path sum in a given matrix from the top left corner to the bottom right corner moving only right or down. """
pass
def solve(T: int, test_cases: List[Tuple[int, int, List[List[int]]]]) -> List[int]:
... | def max_path_sum(matrix):
"""
Calculates the maximum path sum in a given matrix from the top left corner to the bottom right corner moving only right or down.
"""
M = len(matrix)
N = len(matrix[0])
# Initialize dp array with the same dimensions as the matrix
dp = [[0] * N for _ in range(M)]... | import pytest
from solution import max_path_sum, solve, parse_input
def test_max_path_sum():
matrix = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
assert max_path_sum(matrix) == 29
matrix = [
[3, 8],
[5, 7]
]
assert max_path_sum(matrix) == 18
def test_solve():
... | [
{
"docstring": "Calculates the maximum path sum in a given matrix from the top left corner to the bottom right corner moving only right or down.",
"function_declaration": "def max_path_sum(matrix):",
"function_name": "max_path_sum",
"parameter_list": "(matrix)"
},
{
"docstring": null,
"f... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_path_sum(matrix):\n \"\"\"\n Calculates the maximum path sum in a given matrix from the top left corner to the bottom right corner moving only right ... | trial_gpt4o_0 | {
"original_instruction": "You are given an MxN matrix where each cell contains a positive integer. Your task is to find the maximum sum of a path from the top left corner to the bottom right corner of the matrix. You can only move either down or right at any point in time.\n\nInput:\n- The first line contains an int... | 0.566394 | Taco_17129 | C | [
"max_path_sum",
"solve",
"parse_input"
] | 3 | [
[
"solve",
"max_path_sum"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | a72ad13f1861b6729b40d4b2edf43049d6c779c9 | e6e2fe9d6ee36ac3479bad38a780bd5c732170f7 | |||
v1.0 | complete | Taco | Taco_17926_C | def is_point_in_polygon(x, y, vertices):
"""
Determines if the point (x, y) lies inside the given polygon defined by vertices.
Returns True if the point is inside, False otherwise.
"""
# implementation
def check_points_in_polygon(vertices, points):
"""
Determines if each point in the points... | def is_point_in_polygon(x, y, vertices):
"""
Determines if the point (x, y) lies inside the given polygon defined by vertices.
Returns True if the point is inside, False otherwise.
"""
n = len(vertices)
inside = False
px, py = vertices[0]
for i in range(n + 1):
sx, sy = vert... | def test_is_point_in_polygon_inside():
vertices = [(0, 0), (0, 4), (4, 4), (4, 0)]
point = (2, 2)
assert is_point_in_polygon(point[0], point[1], vertices) == True
def test_is_point_in_polygon_outside():
vertices = [(0, 0), (0, 4), (4, 4), (4, 0)]
point = (5, 5)
assert is_point_in_polygon(point[... | [
{
"docstring": "Determines if the point (x, y) lies inside the given polygon defined by vertices.\nReturns True if the point is inside, False otherwise.",
"function_declaration": "def is_point_in_polygon(x, y, vertices):",
"function_name": "is_point_in_polygon",
"parameter_list": "(x, y, vertices)"
... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_point_in_polygon(n, vertices, k, points):\n def is_inside(px, py):\n count = 0\n x1, y1 = vertices[0]\n for i in range(1, n + 1):\n ... | trial_gpt4o_2 | {
"original_instruction": "To determine if a point lies inside or outside a given polygon, we can use ray-casting algorithm. A ray is drawn from the point in question to the positive x-direction. If this ray intersects the edges of the polygon an odd number of times, the point is inside the polygon. Otherwise, the po... | 0.569406 | Taco_17926 | C | [
"is_point_in_polygon",
"check_points_in_polygon",
"read_input"
] | 3 | [
[
"check_points_in_polygon",
"is_point_in_polygon"
],
[
"read_input",
"check_points_in_polygon"
]
] | 2 | [
"read_input"
] | false | [] | false | pytest | false | [] | true | 59f635aa80403cdb45fc9b5b1ed0af17d21f750a | 0705b56072d6b0afffe8c86013f9bd319205231f | |||
v1.0 | complete | Taco | Taco_17720_C | from typing import List
def is_prime(n: int) -> bool:
"""
Helper function to check if a number is prime.
Args:
n (int): The number to check for primality.
Returns:
bool: True if the number is prime, False otherwise.
"""
pass
def countPrimeGroups(N: int, animal_IDs: List[int]) -> i... | def is_prime(n):
"""
Helper function to check if a number is prime.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return False
return True
def countPrimeGro... | from solution import countPrimeGroups
def test_countPrimeGroups_example1():
assert countPrimeGroups(6, [2, 3, 5, 10, 15, 7]) == 4
def test_countPrimeGroups_example2():
assert countPrimeGroups(5, [4, 6, 8, 10, 12]) == 0
def test_countPrimeGroups_edgecase1():
assert countPrimeGroups(1, [2]) == 1
def test_... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Given a list of animal IDs, return the count of unique prime number groups.",
"function_declaration": "def ... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef is_prime(num):\n if num <= 1:\n return False\n if num == 2:\n return True\n if num % 2 == 0:\n return False\n f... | trial_gpt4o_2 | {
"original_instruction": "In a zoo, every animal has been given an integer ID number. The zookeeper wants to create groups of animals with IDs that are prime numbers. Prime numbers are numbers greater than 1 that have no divisors other than 1 and themselves. Given a list of animal IDs, determine how many unique prim... | 0.612526 | Taco_17720 | C | [
"is_prime",
"countPrimeGroups"
] | 2 | [
[
"countPrimeGroups",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7c2e251d13da9e03ac8153b5ab4254162fe4c677 | b3a4582f0cb5c9ddfd7151e4ebcedcbb73311c50 | |||
v1.0 | complete | Taco | Taco_17821_C | def is_palindrome(number: int) -> bool:
"""
Check if a given number is a palindrome.
>>> is_palindrome(121)
True
>>> is_palindrome(123)
False
>>> is_palindrome(1)
True
>>> is_palindrome(22)
True
"""
pass
def reverse_number(number: int) -> int:
"""
Reverse the dig... | def is_palindrome(number):
"""
Checks if a given number is a palindrome.
"""
return str(number) == str(number)[::-1]
def reverse_number(number):
"""
Reverses the digits of a given number.
"""
return int(str(number)[::-1])
def transformations_to_palindrome(n):
"""
Determines the... | from solution import is_palindrome, reverse_number, transformations_to_palindrome, process_test_cases
def test_is_palindrome():
assert is_palindrome(121) == True
assert is_palindrome(123) == False
assert is_palindrome(1) == True
assert is_palindrome(22) == True
def test_reverse_number():
assert re... | [
{
"docstring": "Checks if a given number is a palindrome.",
"function_declaration": "def is_palindrome(number):",
"function_name": "is_palindrome",
"parameter_list": "(number)"
},
{
"docstring": "Reverses the digits of a given number.",
"function_declaration": "def reverse_number(number)... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome(n):\n \"\"\"\n Check if a given number is a palindrome.\n \"\"\"\n return str(n) == str(n)[::-1]\n\ndef reverse_number(n):\n \"\"\... | trial_gpt4o_1 | {
"original_instruction": "Stan and Ollie love playing with numbers. Stan has discovered a way to have fun with numbers by creating a sequence. He starts with an integer $n$ and repeatedly applies a transformation on it. The transformation consists of reversing the digits of $n$, converting it back to an integer, and... | 0.675457 | Taco_17821 | C | [
"is_palindrome",
"reverse_number",
"transformations_to_palindrome",
"process_test_cases"
] | 4 | [
[
"process_test_cases",
"transformations_to_palindrome"
],
[
"transformations_to_palindrome",
"is_palindrome"
],
[
"transformations_to_palindrome",
"reverse_number"
]
] | 3 | [
"process_test_cases"
] | false | [] | false | pytest | true | [] | true | b259cf56721e6c0f793abeac67fddd5f8613f463 | 3970f14894a52b8c822c6fa8a0683c488e051328 | |||
v1.0 | complete | Taco | Taco_16961_C | def can_organize_boxes(n: int, boxes: List[Tuple[int, int]]) -> str:
"""
Determines if it is possible to organize the boxes in such a way that each box
(except the outermost one) fits into exactly one other box.
Args:
n: int, the number of boxes.
boxes: List of tuples, each containing two i... | def can_organize_boxes(n, boxes):
"""
Determines if it is possible to organize the boxes in such a way that each box
(except the outermost one) fits into exactly one other box.
Args:
n: int, the number of boxes.
boxes: List of tuples, each containing two integers (length, width) of the boxe... | def test_organize_boxes():
assert organize_boxes("5\n1 2\n2 3\n3 4\n4 5\n5 6") == "YES"
assert organize_boxes("3\n1 5\n2 4\n3 3") == "NO"
assert organize_boxes("1\n10 10") == "YES"
assert organize_boxes("2\n1 1\n1 2") == "YES"
assert organize_boxes("2\n2 3\n1 4") == "NO"
assert organize_boxes("4... | [
{
"docstring": "Determines if it is possible to organize the boxes in such a way that each box\n(except the outermost one) fits into exactly one other box.\n\nArgs:\nn: int, the number of boxes.\nboxes: List of tuples, each containing two integers (length, width) of the boxes.\n\nReturns:\nstr: \"YES\" if it is... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def can_organize_boxes(n, boxes):\n \"\"\"\n Determines if it is possible to organize the boxes in such a way that each box\n (except the outermost one) f... | trial_gpt4o_0 | {
"original_instruction": "Alex works for a company that delivers packages and he's responsible for routing the packages to their destinations. The packages are packed in rectangular boxes with integer dimensions. Each box must fit exactly into another box or itself. A box A can fit into box B if both the length and ... | 0.57132 | Taco_16961 | C | [
"can_organize_boxes",
"organize_boxes"
] | 2 | [
[
"organize_boxes",
"can_organize_boxes"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 61b9cac461c381e5ff20a4fb04df1dc89a5f3458 | 9e653fd330bc5f53671315f42b1d4640e69df030 | |||
v1.0 | complete | Taco | Taco_16916_C | from typing import List, Tuple
def is_prime(n: int) -> bool:
""" Check if a number is a prime number.
>>> is_prime(2)
True
>>> is_prime(4)
False
"""
pass
def next_prime(n: int) -> int:
""" Find the smallest prime number greater than the given number.
>>> next_prime(9)
11
>>... | def is_prime(n):
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return True
def next_prime(n):
candidate = n + 1
w... | from solution import is_prime, next_prime, smallest_prime_bigger_than_max, process_test_cases
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(11) == True
assert is_prime(15) == False
def test_next_prime():
assert next_prime... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def next_prime(n):",
"function_name": "next_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\" Returns True if n is a prime number, else False \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n ... | trial_gpt4o_1 | {
"original_instruction": "Sarah has recently started learning about prime numbers. She is given an array of integers and she wants to find the smallest prime number which is bigger than the maximum number in the array. If all elements in the array are negative or the array is empty, return -1. \n\n-----Input-----\nT... | 0.682237 | Taco_16916 | C | [
"is_prime",
"next_prime",
"smallest_prime_bigger_than_max",
"process_test_cases"
] | 4 | [
[
"next_prime",
"is_prime"
],
[
"process_test_cases",
"smallest_prime_bigger_than_max"
],
[
"smallest_prime_bigger_than_max",
"next_prime"
]
] | 3 | [
"process_test_cases"
] | false | [] | false | pytest | true | [] | true | 8cd2a0a4c5bcbc8d3e2215a14e529aee6bebec28 | 486cd08e18b18aaf7853b16acfbe0f7cd5aaa455 | |||
v1.0 | complete | Taco | Taco_17645_C | import re
from typing import List
def is_valid_password(password: str) -> str:
""" Validate if the password meets all the criteria.
>>> is_valid_password("StrongPassw0rd") == "VALID"
'VALID'
>>> is_valid_password("weakpass") == "INVALID"
'INVALID'
>>> is_valid_password("Strong1") == "INVALID"
... | import re
def is_valid_password(password):
if len(password) < 8:
return "INVALID"
if not re.search(r'[A-Z]', password):
return "INVALID"
if not re.search(r'[a-z]', password):
return "INVALID"
if not re.search(r'[0-9]', password):
return "INVALID"
if re.search(r'[^A-Z... | from solution import is_valid_password, validate_passwords
def test_is_valid_password():
assert is_valid_password("StrongPassw0rd") == "VALID"
assert is_valid_password("weakpass") == "INVALID"
assert is_valid_password("Strong1") == "INVALID"
assert is_valid_password("WayTooLongPasswordWithoutDigit") ==... | [
{
"docstring": null,
"function_declaration": "def is_valid_password(password):",
"function_name": "is_valid_password",
"parameter_list": "(password)"
},
{
"docstring": null,
"function_declaration": "def validate_passwords(passwords):",
"function_name": "validate_passwords",
"para... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def validate_passwords(passwords):\n results = []\n for pwd in passwords:\n if (len(pwd) < 8 or \n not any(char.isupper() for char in pwd) ... | trial_gpt4o_1 | {
"original_instruction": "Marcus needs to create a safe password for his new portal account. He wants to follow a specific set of rules to ensure the password is both strong and easy to remember. According to the rules, a valid password must meet the following criteria:\n- It must be at least 8 characters long.\n- I... | 0.59003 | Taco_17645 | C | [
"is_valid_password",
"validate_passwords"
] | 2 | [
[
"validate_passwords",
"is_valid_password"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6c290fe9b0bcfd0fa60d44588d357ccecdfbedf0 | 633189b8e00ff2f2c5a3e18ff8d51d8d7409fa0a | |||
v1.0 | complete | Taco | Taco_17593_C | def get_sum_of_kth_level(node_data: List[Tuple[int, int, int]], k: int) -> int:
""" Given a binary tree, find the sum of all nodes at the K-th level of the tree.
Args:
node_data (List[Tuple[int, int, int]]): The list of node values and their children.
k (int): The level whose sum you need to find.
... | class TreeNode:
def __init__(self, value=0, left=None, right=None):
self.value = value
self.left = left
self.right = right
def build_tree(node_data):
if not node_data:
return None
nodes = {}
for value, left, right in node_data:
if value not in nodes... | from solution import get_sum_of_kth_level
def test_sample_input():
node_data = [
(1, 2, 3),
(2, 4, -1),
(3, -1, 5),
(4, -1, -1),
(5, -1, -1)
]
k = 2
assert get_sum_of_kth_level(node_data, k) == 9
def test_no_nodes():
node_data = []
k = 0
assert get_s... | [] | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_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 b... | trial_gpt4o_1 | {
"original_instruction": "Given a binary tree, find the sum of all nodes at the K-th level of the tree. Levels are numbered from 0 for the root.\n\nInput:\n\nThe first line contains an integer N, the number of nodes in the tree. \nThe following N lines each contain three values: the value of the node, the value of t... | 0.571401 | Taco_17593 | C | [
"build_tree",
"sum_at_kth_level",
"get_sum_of_kth_level"
] | 3 | [
[
"get_sum_of_kth_level",
"build_tree"
],
[
"get_sum_of_kth_level",
"sum_at_kth_level"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 8636caa82ce0a14cbde4107d2ea87d5bd573cf71 | e161dba0690c76b471af644c1466a91d5d3ad19c | |||
v1.0 | complete | Taco | Taco_18005_C | def can_form_palindrome(s: str) -> bool:
"""This function checks if the given string can be rearranged to form a palindrome.
>>> can_form_palindrome("carrace")
True
>>> can_form_palindrome("daily")
False
"""
pass
def num_strings_can_form_palindrome(strings: List[str]) -> int:
"""Th... | def can_form_palindrome(s):
"""
This function checks if the given string can be rearranged to form a palindrome.
:param s: A string containing alphanumeric characters
:return: Boolean indicating if the string can be rearranged to form a palindrome
"""
from collections import Counter
counts ... | from solution import can_form_palindrome, num_strings_can_form_palindrome
def test_can_form_palindrome():
assert can_form_palindrome("carrace") == True
assert can_form_palindrome("daily") == False
assert can_form_palindrome("aabbaa") == True
assert can_form_palindrome("a") == True
assert can_form_p... | [
{
"docstring": "This function checks if the given string can be rearranged to form a palindrome.\n\n:param s: A string containing alphanumeric characters\n:return: Boolean indicating if the string can be rearranged to form a palindrome",
"function_declaration": "def can_form_palindrome(s):",
"function_n... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def can_form_palindrome(s):\n \"\"\"\n This function checks if the given string can be rearranged to form a palindrome.\n\n :param s: A string containing ... | trial_gpt4o_0 | {
"original_instruction": "You are given a list of strings where each string consists of various alphanumeric characters. Your task is to find the number of strings that can be rearranged to form a palindrome.\n\nA palindrome is a string that reads the same forward and backward.\n\n------ Input ------\n\nThe first li... | 0.766288 | Taco_18005 | C | [
"can_form_palindrome",
"num_strings_can_form_palindrome"
] | 2 | [
[
"num_strings_can_form_palindrome",
"can_form_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b0b339f7301c738ba8975cb9c1e79254d711a298 | 488e800e21fd16a45ecc9cde6887e0170cf0fee0 | |||
v1.0 | complete | Taco | Taco_18013_C | def check_strings(t: int, strings: list) -> list:
"""
Determine whether each string in the list is a palindrome and count the
number of characters to remove if it is not.
Parameters:
t (int): The number of test cases.
strings (list): A list of strings to be checked.
Returns:
... | def is_palindrome(s: str) -> bool:
s = ''.join(s.split()) # remove spaces
return s == s[::-1]
def min_remove_to_palindrome(s: str) -> int:
s = ''.join(s.split()) # remove spaces
n = len(s)
dp = [[0] * n for _ in range(n)]
for length in range(2, n + 1):
for i in range(n - length +... | from solution import check_strings
def test_check_strings():
assert check_strings(3, ["racecar", "a man a plan a canal panama", "abca"]) == ["YES 0", "YES 0", "NO 1"]
assert check_strings(1, ["aabba"]) == ["NO 1"]
assert check_strings(2, ["abc", "abba"]) == ["NO 2", "YES 0"]
assert check_strings(1, ["a... | [
{
"docstring": null,
"function_declaration": "def is_palindrome(s):",
"function_name": "is_palindrome",
"parameter_list": "(s)"
},
{
"docstring": null,
"function_declaration": "def min_remove_to_palindrome(s):",
"function_name": "min_remove_to_palindrome",
"parameter_list": "(s)"... | [
0,
0,
0,
0,
0,
0,
0,
1,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome(s):\n \"\"\"\n Determines if the given string s is a palindrome ignoring spaces.\n \"\"\"\n s_filtered = \"\".join(s.split())\n re... | trial_gpt4o_7 | {
"original_instruction": "Nephren and the little leprechauns are playing a new game with palindromes.\n\nA string is called a palindrome if it reads the same backward as forward, ignoring spaces. For example, \"aba\", \"a man a plan a canal panama\", and \"racecar\" are palindromes.\n\nGiven a string s, determine wh... | 0.798859 | Taco_18013 | C | [
"is_palindrome",
"min_remove_to_palindrome",
"check_strings"
] | 3 | [
[
"check_strings",
"is_palindrome"
],
[
"check_strings",
"min_remove_to_palindrome"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 35250be238201fdccef87fee1236b4f5ead2a3b8 | 5ba4234c4ed54403bad19c572626cccf29e150f2 | |||
v1.0 | complete | Taco | Taco_16799_C | def is_prime(num):
"""Check if a number is prime.
>>> is_prime(2) True
>>> is_prime(3) True
>>> is_prime(4) False
>>> is_prime(5) True
>>> is_prime(29) True
>>> is_prime(30) False
"""
# Implement the function
def count_primes_in_range(n, m):
"""Count the number of prime numbers ... | def is_prime(num):
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 False
i += 6
return True
def count_primes_in_range(n, m... | from solution import is_prime, count_primes_in_range, process_queries
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(30) == False
assert is_prime(1) == False
as... | [
{
"docstring": null,
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def count_primes_in_range(n, m):",
"function_name": "count_primes_in_range",
"parameter_list": "(n, m)"
},
... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def sieve_of_eratosthenes(max_num):\n prime = [True] * (max_num + 1)\n p = 2\n while p * p <= max_num:\n if prime[p] == True:\n for i in... | trial_gpt4o_2 | {
"original_instruction": "Write a program that reads a series of queries. Each query consists of two positive integers, n and m, where n < m. The task is to compute the number of prime numbers in the range [n, m] (both inclusive).\n\nFor example, given the input values 10 and 20, there are 4 prime numbers in that ra... | 0.689983 | Taco_16799 | C | [
"is_prime",
"count_primes_in_range",
"process_queries",
"main"
] | 4 | [
[
"count_primes_in_range",
"is_prime"
],
[
"process_queries",
"count_primes_in_range"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | true | [] | true | d6e47d6f01b0d680f13a8a2874a535702a35d03d | 2d64bac56ffa084b1c3be8b55616855545bc39f7 | |||
v1.0 | complete | Taco | Taco_18036_C | def conference_room_scheduler(test_cases: List[List[Tuple[str, str]]]) -> List[int]:
""" Determine the minimum number of rooms required to schedule all sessions for multiple test cases.
Each session has a start and end time, and no sessions assigned to the same room can overlap.
>>> conference_room_schedul... | def parse_time(t):
"""
Parse a time string in HH:MM format into minutes since midnight.
"""
hours, minutes = map(int, t.split(':'))
return hours * 60 + minutes
def min_rooms_required(sessions):
"""
Given a list of sessions with start and end times, determine the minimum number of rooms requ... | from solution import conference_room_scheduler
def test_conference_room_scheduler():
# Test case 1: All sessions can be fit into 2 rooms
test_cases = [
[
("09:00", "10:00"),
("09:30", "10:30"),
("10:00", "11:00"),
("10:30", "11:30")
],
[
... | [
{
"docstring": "Parse a time string in HH:MM format into minutes since midnight.",
"function_declaration": "def parse_time(t):",
"function_name": "parse_time",
"parameter_list": "(t)"
},
{
"docstring": "Given a list of sessions with start and end times, determine the minimum number of rooms ... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from heapq import heappush, heappop\nfrom datetime import datetime\n\ndef min_rooms_required(test_cases):\n def time_to_minutes(t):\n return int(t[:2]) *... | trial_gpt4o_2 | {
"original_instruction": "A company is organizing a conference, and each session of the conference must be assigned to one of the several available rooms. The sessions have specific starting and ending times, and a session cannot overlap with any other session assigned to the same room. Your task is to determine the... | 0.604531 | Taco_18036 | C | [
"parse_time",
"min_rooms_required",
"conference_room_scheduler"
] | 3 | [
[
"conference_room_scheduler",
"min_rooms_required"
],
[
"min_rooms_required",
"parse_time"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | a7e447ae846904d36726ca6d3b3fab5bc12df3cd | 69f89e5ce9329ee0c237660be1b252e02fcb96e4 | |||
v1.0 | complete | Taco | Taco_18068_C | import math
from typing import List, Tuple
def is_triangular_number(t: int) -> bool:
"""
Check if a number t is a triangular number.
>>> is_triangular_number(1)
True
>>> is_triangular_number(3)
True
>>> is_triangular_number(2)
False
"""
pass
def find_triangular_count(X: int, Y:... | import math
def is_triangular_number(t):
"""
Check if a number t is a triangular number.
"""
if t < 1:
return False
n = (-1 + math.sqrt(1 + 8 * t)) / 2
return n.is_integer()
def find_triangular_count(X, Y):
"""
Returns the count of triangular numbers within the range [X, Y].
... | from solution import is_triangular_number, find_triangular_count, process_test_cases
def test_is_triangular_number():
assert is_triangular_number(1) == True
assert is_triangular_number(3) == True
assert is_triangular_number(6) == True
assert is_triangular_number(10) == True
assert is_triangular_num... | [
{
"docstring": "Check if a number t is a triangular number.",
"function_declaration": "def is_triangular_number(t):",
"function_name": "is_triangular_number",
"parameter_list": "(t)"
},
{
"docstring": "Returns the count of triangular numbers within the range [X, Y].",
"function_declarati... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef count_triangular_numbers_in_range(X, Y):\n def is_triangular(num):\n if num < 1:\n return False\n # We solve the qua... | trial_gpt4o_2 | {
"original_instruction": "Alice is intrigued by triangular numbers and their interesting properties. A number T is called triangular if it can be expressed as T = n * (n + 1) / 2 for some positive integer n. For instance, 1, 3, 6, 10 are the first few triangular numbers.\n\nAlice wants to find out how many triangula... | 0.637098 | Taco_18068 | C | [
"is_triangular_number",
"find_triangular_count",
"process_test_cases",
"main"
] | 4 | [
[
"find_triangular_count",
"is_triangular_number"
],
[
"process_test_cases",
"find_triangular_count"
]
] | 2 | [
"process_test_cases"
] | false | [] | false | pytest | true | [] | true | b9648608ad2e82f11dc0d71a0d09cd3410583f55 | 6ddfdd6f5224d1cf205ce00d14df8653067384d0 | |||
v1.0 | complete | Taco | Taco_17287_C | 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(levels):
"""
Builds a binary tree from a given level-order list.
"""
if not levels or levels[0] == -1:
... | 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(levels):
"""
Builds a binary tree from a given level-order list.
"""
if not levels or levels[0] == -1:
... | def test_convert_input_to_list():
input_str = "3\n1\n2 3\n4 5 -1 7"
expected_output = [1, 2, 3, 4, 5, -1, 7]
assert convert_input_to_list(input_str) == expected_output
def test_build_tree():
levels = [1, 2, 3, 4, 5, -1, 7]
root = build_tree(levels)
assert root.value == 1
assert root.left.va... | [] | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\nclass TreeNode:\n def __init__(self, value):\n self.val = value\n self.left = None\n self.right = None\n\n... | trial_gpt4o_2 | {
"original_instruction": "## Problem Description\nGiven a binary tree, traverse it level-by-level from left to right and print the nodes of each level in a new line.\n\nA binary tree is represented by a sequence of values where the value `-1` indicates a null child.\n\n### Constraints\n* The number of nodes in the b... | 0.547845 | Taco_17287 | C | [
"build_tree",
"level_order_traversal",
"convert_input_to_list",
"print_level_order"
] | 4 | [
[
"print_level_order",
"build_tree"
],
[
"print_level_order",
"convert_input_to_list"
],
[
"print_level_order",
"level_order_traversal"
]
] | 3 | [] | false | [
"TreeNode"
] | true | pytest | false | [] | true | ae39c5f1fd452351cb79382291367de9da06bb3a | 6b8161f1dc7378011e95bc8acf00e16bb3041f1f | |||
v1.0 | complete | Taco | Taco_18118_C | def is_prime(n):
"""
Returns True if n is a prime number, otherwise False.
>>> is_prime(2)
True
>>> is_prime(4)
False
>>> is_prime(17)
True
"""
def extract_primes(nums):
"""
Takes in a list of integers and returns a new list which contains only the primes from the original li... | def is_prime(n):
"""
Returns True if n is a prime number, otherwise False.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return False
return True
def extrac... | from solution import extract_primes, is_prime
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(10) == False
assert is_prime(17) == True
def test_extract_primes():
assert extract_primes([10, 15,... | [
{
"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": "Takes in a list of integers and returns a new list which contains only the primes from the original list... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_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 == 2:\n return ... | trial_gpt4o_2 | {
"original_instruction": "Write a function that takes in a list of integers and returns a new list which contains only the primes from the original list. If there are no prime numbers in the input list, return an empty list.\n\nA prime number is a number greater than 1 that has no divisors other than 1 and itself.\n... | 0.799882 | Taco_18118 | C | [
"is_prime",
"extract_primes"
] | 2 | [
[
"extract_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 032eee3a34c82f462ef52e81e97cf8cbb4093b16 | 03b3340b72002c0c7d728b16880dd9daa88b5a9e | |||
v1.0 | complete | Taco | Taco_18020_C | import itertools
import math
from typing import List, Tuple
def tsp_shortest_path(n: int, coordinates: List[Tuple[int, int]]) -> int:
""" Determine the shortest possible route that covers all locations exactly once and returns to the starting point.
>>> tsp_shortest_path(4, [(0, 0), (0, 1), (1, 0), (1, 1)])
... | import itertools
import math
def calculate_distance(p1, p2):
return math.sqrt((p1[0] - p2[0])**2 + (p1[1] - p2[1])**2)
def tsp_shortest_path(n, coordinates):
all_permutations = itertools.permutations(range(1, n))
min_distance = float('inf')
for perm in all_permutations:
current_distance = 0
... | from solution import tsp_shortest_path
def test_tsp_example():
n = 4
coordinates = [(0, 0), (0, 1), (1, 0), (1, 1)]
assert tsp_shortest_path(n, coordinates) == 4
def test_tsp_two_points():
n = 2
coordinates = [(0, 0), (3, 4)]
assert tsp_shortest_path(n, coordinates) == 10 # As round trip 5+5 ... | [
{
"docstring": null,
"function_declaration": "def calculate_distance(p1, p2):",
"function_name": "calculate_distance",
"parameter_list": "(p1, p2)"
},
{
"docstring": null,
"function_declaration": "def tsp_shortest_path(n, coordinates):",
"function_name": "tsp_shortest_path",
"par... | [
0,
0,
0,
0,
0,
1,
0,
0,
0,
1
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import itertools\nimport math\n\ndef tsp_shortest_route(num_locations, locations):\n def distance(p1, p2):\n return math.sqrt((p1[0] - p2[0]) ** 2 + (p1[... | trial_gpt4o_5 | {
"original_instruction": "You are tasked with developing a system to help a logistics company optimize their delivery routes. The company delivers parcels between various locations, and you need to determine the shortest possible route that a delivery person can take to cover all locations exactly once and return to... | 0.682998 | Taco_18020 | C | [
"calculate_distance",
"tsp_shortest_path"
] | 2 | [
[
"tsp_shortest_path",
"calculate_distance"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 856bfbe192b1f6e4ef526f69b7b9d33194876d5f | 2f76b2aad0d463cd378169133470e15af8af9b2a | |||
v1.0 | complete | Taco | Taco_18113_C | def is_prime(num: int) -> bool:
"""
Determine if a number is prime.
>>> is_prime(2) True
>>> is_prime(3) True
>>> is_prime(4) False
>>> is_prime(5) True
>>> is_prime(11) True
>>> is_prime(1) False
>>> is_prime(0) False
"""
def find_prime_subsequence(t: int, test_cases: ... | def is_prime(num):
"""
Determine if a number is prime.
"""
if num <= 1:
return False
if num == 2:
return True
if num % 2 == 0:
return False
for i in range(3, int(num**0.5) + 1, 2):
if num % i == 0:
return False
return True
def find_prime_subse... | 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(1) == False
assert is_prime(0) == False
assert is_prime(-3) == False
assert is_prime(11) == True
def test_find_prime_subsequence():
t = 3... | [
{
"docstring": "Determine if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns the result for each test case whether a subsequence with a prime sum exists,\nand the indices of one such subseque... | [
0,
0,
0,
0,
0,
1,
0,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from itertools import combinations\n\ndef is_prime(num):\n \"\"\"Helper function to check if a number is prime.\"\"\"\n if num <= 1:\n return False\n ... | trial_gpt4o_5 | {
"original_instruction": "You are given a sequence of integers and are required to find a subsequence such that the sum of the subsequence is a prime number. A subsequence is derived by deleting some or none of the elements from the sequence without changing the order of the remaining elements.\n\nInput:\nThe input ... | 0.754269 | Taco_18113 | C | [
"is_prime",
"find_prime_subsequence"
] | 2 | [
[
"find_prime_subsequence",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 178b7aa6d6abf741e781282d9506de7377435687 | 359122b2b3d4c9a68fcaa5baf6a229283682e941 | |||
v1.0 | complete | Taco | Taco_18284_C | def minimize_max_distance_buildings(buildings):
""" Given a list of building coordinates, find the maximum number of buildings
Polygono can place while ensuring the distance between the furthest pair of buildings
is minimized.
>>> minimize_max_distance_buildings([(1, 2), (3, 4), (-1, -1)]) [(1, 2), (3... | import math
def calculate_distance(x1, y1, x2, y2):
return math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
def minimize_max_distance_buildings(buildings):
n = len(buildings)
if n == 2:
# If there are only 2 buildings, they must be kept as is
return buildings
# Sort coordinates by eithe... | from solution import main
def test_case_1():
input_data = "3\n1 2\n3 4\n-1 -1"
output_data = main(input_data).strip().split('\n')
assert len(output_data) == 3
assert output_data[0] == "2"
def test_case_2():
input_data = "4\n0 0\n1 1\n2 2\n3 3"
output_data = main(input_data).strip().split('\n')... | [
{
"docstring": null,
"function_declaration": "def calculate_distance(x1, y1, x2, y2):",
"function_name": "calculate_distance",
"parameter_list": "(x1, y1, x2, y2)"
},
{
"docstring": null,
"function_declaration": "def minimize_max_distance_buildings(buildings):",
"function_name": "min... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef distance(p1, p2):\n return math.sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2)\n\ndef find_max_buildings(n, buildings):\n max_possible_... | trial_gpt4o_1 | {
"original_instruction": "A busy architect, Polygono, is planning the layout of a new city called Geoville. Geoville will have n buildings, all of which are at integer coordinates in a 2D plane. Polygono wants to design the layout in such a way that the distance between the furthest pair of buildings is minimized. T... | 0.638423 | Taco_18284 | C | [
"calculate_distance",
"minimize_max_distance_buildings",
"main"
] | 3 | [
[
"minimize_max_distance_buildings",
"calculate_distance"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 61cded721b530a31d6148a36a2c90a02c631e7a6 | 68be4f4c7bbe84a0723c9071d2b753dc2efc0e2c | |||
v1.0 | complete | Taco | Taco_18064_C | def largest_rectangle_area(heights):
"""
Calculate the largest rectangle area in a histogram given by heights.
"""
# Write your code here
pass
def process_histograms(num_test_cases, test_cases):
"""
Process multiple histogram test cases and return the results.
"""
# Write your code ... | def largest_rectangle_area(heights):
"""
Calculate the largest rectangle area in a histogram given by heights.
"""
stack = []
max_area = 0
index = 0
while index < len(heights):
if not stack or heights[stack[-1]] <= heights[index]:
stack.append(index)
inde... | from solution import largest_rectangle_histogram
def test_case_1():
test_input = [
(5, [2, 1, 5, 6, 2, 3]),
]
assert largest_rectangle_histogram(1, test_input) == [10]
def test_case_2():
test_input = [
(7, [6, 2, 5, 4, 5, 1, 6]),
]
assert largest_rectangle_histogram(1, test_inp... | [
{
"docstring": "Calculate the largest rectangle area in a histogram given by heights.",
"function_declaration": "def largest_rectangle_area(heights):",
"function_name": "largest_rectangle_area",
"parameter_list": "(heights)"
},
{
"docstring": null,
"function_declaration": "def process_hi... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def largest_rectangle_area(heights):\n \"\"\"\n Function to calculate the largest rectangle area in a histogram.\n \"\"\"\n stack = []\n max_area = ... | trial_gpt4o_2 | {
"original_instruction": "A famous problem is to find the largest rectangle that can be formed within a histogram. A histogram is a representation of data where each bar denotes the frequency (or count) of data points corresponding to that bar. Given the heights of the bars, the task is to determine the area of the ... | 0.525501 | Taco_18064 | C | [
"largest_rectangle_area",
"process_histograms",
"largest_rectangle_histogram"
] | 3 | [
[
"largest_rectangle_histogram",
"process_histograms"
],
[
"process_histograms",
"largest_rectangle_area"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 1dccbc5d439e34ae9a943ebe66eb3ab1563927de | b1f1c11f517b82659addb4cc6f8816702ffd4c72 | |||
v1.0 | complete | Taco | Taco_18228_C | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def find_second_minimum_value(root: TreeNode) -> int:
""" Find the second smallest element in the binary tree.
>>> tree = TreeNode(5, TreeNode(3, TreeNode(1), TreeNod... | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def find_second_minimum_value(root: TreeNode) -> int:
def in_order_traversal(node):
if not node:
return []
return in_order_traversal(node.left... | from solution import second_smallest_in_binary_tree
def test_case_1():
T = 1
test_cases = [
(5, [5, 3, 1, 7, 2], [(5, 3), (5, 7), (3, 1), (3, 2)])
]
output = second_smallest_in_binary_tree(T, test_cases)
assert output == [2]
def test_case_2():
T = 1
test_cases = [
(2, [10, ... | [] | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, value):\n self.value = value\n self.children = []\n\ndef find_second_minimum(tree_nodes):\n if len(tree_no... | trial_gpt4o_1 | {
"original_instruction": "Given a binary tree, you need to find the second smallest element in the tree. The tree contains unique values in its nodes.\n\n### Input Format\n\n- The first line of input contains a single integer T, the number of test cases.\n- The following lines contain the description of each test ca... | 0.579129 | Taco_18228 | C | [
"find_second_minimum_value",
"build_tree_from_edges",
"second_smallest_in_binary_tree"
] | 3 | [
[
"second_smallest_in_binary_tree",
"build_tree_from_edges"
],
[
"second_smallest_in_binary_tree",
"find_second_minimum_value"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 7b373b4131e6e007071357294b169376179f54ce | 5dd18212f484b82ffa0028c8bd7307ba1f15b641 | |||
v1.0 | complete | Taco | Taco_18111_C | def analyze_field(input_str: str) -> [int]:
""" Calculate the average fertility value for given sub-rectangles in a field.
Args:
input_str (str): String representation of the field and queries
Returns:
List[int]: List of average fertility values for each sub-rectangle
>>> analyze_... | def average_fertility(field, queries):
M, N = len(field), len(field[0])
results = []
for query in queries:
x1, y1, x2, y2 = query
total_sum = 0
count = 0
# Iterate through the sub-rectangle from (x1, y1) to (x2, y2)
for i in range(x1 - 1, x2):
... | def test_average_fertility_case1():
input_str = """3 3
1 2 3
4 5 6
7 8 9
2
1 1 2 2
2 2 3 3"""
expected_output = [3, 7]
assert analyze_field(input_str) == expected_output
def test_average_fertility_single_cell():
input_str = """2 2
5 5
5 5
1
1 1 1 1"""
expected_output = [5]
assert analyze_field(... | [
{
"docstring": null,
"function_declaration": "def average_fertility(field, queries):",
"function_name": "average_fertility",
"parameter_list": "(field, queries)"
},
{
"docstring": null,
"function_declaration": "def parse_input(input_str):",
"function_name": "parse_input",
"parame... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def calculate_average_fertility(M, N, field, queries):\n results = []\n \n for x1, y1, x2, y2 in queries:\n total_fertility = 0\n num_plots ... | trial_gpt4o_2 | {
"original_instruction": "A group of researchers is investigating a rectangular field divided into M x N plots. Each plot has a specific fertility value — a non-negative integer. The researchers want to plant certain crops that require a high and balanced fertility value across specific regions of the field. To do t... | 0.580986 | Taco_18111 | C | [
"average_fertility",
"parse_input",
"analyze_field"
] | 3 | [
[
"analyze_field",
"average_fertility"
],
[
"analyze_field",
"parse_input"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | false | [] | true | 3dfdb3a6c1963f77844d16f8b3770a1217a7c9eb | 64593a1c87953991dce63c9b35915617ce3c7d9f | |||
v1.0 | complete | Taco | Taco_18377_C | def get_prime_factors(n: int) -> set:
""" Get all prime factors of a number.
>>> get_prime_factors(12)
{2, 3}
>>> get_prime_factors(18)
{2, 3}
>>> get_prime_factors(17)
{17}
>>> get_prime_factors(100)
{2, 5}
"""
pass
def common_prime_factors(A: int, B: int) -> int:
""" F... | def get_prime_factors(n):
factors = set()
d = 2
while n > 1:
while (n % d) == 0:
factors.add(d)
n //= d
d += 1
return factors
def common_prime_factors(A, B):
primes_a = get_prime_factors(A)
primes_b = get_prime_factors(B)
common_primes = primes_a.inte... | from solution import get_prime_factors, common_prime_factors
def test_get_prime_factors():
assert get_prime_factors(12) == {2, 3}
assert get_prime_factors(18) == {2, 3}
assert get_prime_factors(17) == {17}
assert get_prime_factors(100) == {2, 5}
def test_common_prime_factors():
assert common_prime... | [
{
"docstring": null,
"function_declaration": "def get_prime_factors(n):",
"function_name": "get_prime_factors",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def common_prime_factors(A, B):",
"function_name": "common_prime_factors",
"parameter_list": "(... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from math import gcd\n\ndef prime_factors(n):\n \"\"\"\n Returns a set of prime factors of the given number n.\n \"\"\"\n factors = set()\n \n # ... | trial_gpt4o_2 | {
"original_instruction": "Write a program to read two numbers $A$ and $B$ and print the number of common prime factors between them.\n\n-----Input:-----\n- First line will contain a number $A$ and $B$ separated by space.\n\n-----Output:-----\nOutput a single line, the number of common prime factors.\n\n-----Constrai... | 0.706029 | Taco_18377 | C | [
"get_prime_factors",
"common_prime_factors"
] | 2 | [
[
"common_prime_factors",
"get_prime_factors"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0d5464969248a4041261efcb432e8e67302d74fd | 7971637f66cc6579130b1b40b7e7e837096243ec | |||
v1.0 | complete | Taco | Taco_18166_C | def rotate_and_reflect_matrix(T, matrices):
""" Given T test cases, for each provided initial NxN matrix, this function
reshapes the matrix by rotating it 90 degrees clockwise and then reflecting
the resulting matrix along its main diagonal.
Parameters:
T (int): Number of test cases.
matric... | def rotate_and_reflect_matrix(T, matrices):
def rotate_90_clockwise(matrix):
N = len(matrix)
return [[matrix[N - j - 1][i] for j in range(N)] for i in range(N)]
results = []
for matrix in matrices:
rotated_matrix = rotate_90_clockwise(matrix)
results.append(rotated_matri... | def test_rotate_3x3_matrix():
input_matrix = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
expected_output = [
[7, 4, 1],
[8, 5, 2],
[9, 6, 3]
]
assert rotate_and_reflect_matrix(1, [input_matrix]) == [expected_output]
def test_rotate_4x4_matrix():
input_mat... | [
{
"docstring": null,
"function_declaration": "def rotate_and_reflect_matrix(T, matrices):",
"function_name": "rotate_and_reflect_matrix",
"parameter_list": "(T, matrices)"
},
{
"docstring": null,
"function_declaration": "def restructured_matrix(T, matrices):",
"function_name": "restr... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def transform(matrix):\n \"\"\"\n Transforms the given NxN matrix by rotating it 90 degrees clockwise\n and then reflecting it along its main diagonal.\n ... | trial_gpt4o_2 | {
"original_instruction": "A famous programming competition consists of several rounds, each requiring solving a unique problem. One of the challenges is to redesign a given matrix according to a specific pattern. The goal of this task is to rearrange a given NxN matrix according to the following rules:\n\n1. Rotate ... | 0.543297 | Taco_18166 | C | [
"rotate_and_reflect_matrix",
"restructured_matrix"
] | 2 | [
[
"restructured_matrix",
"rotate_and_reflect_matrix"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | dacfebc2e884f938ec066b4aa76e534fcf50af95 | 52590a554015f1b97c4d47fcde87c8d1423cca12 | |||
v1.0 | complete | Taco | Taco_18024_C | from typing import List, Tuple
def tree_diameter(n: int, edges: List[Tuple[int, int]]) -> int:
""" You are given a tree which is an acyclic connected graph. The vertices are enumerated from 1 to n.
Your task is to find the diameter of the tree, which is defined as the longest shortest path between any two ver... | from collections import deque
def bfs_farthest_node(start, n, adj_list):
distances = [-1] * (n + 1)
queue = deque([start])
distances[start] = 0
farthest_node = start
while queue:
current = queue.popleft()
for neighbor in adj_list[current]:
if distances[neighbor] == ... | import pytest
from solution import tree_diameter
def test_tree_diameter_case1():
n = 5
edges = [(1, 2), (2, 3), (3, 4), (4, 5)]
assert tree_diameter(n, edges) == 4
def test_tree_diameter_case2():
n = 7
edges = [(1, 2), (1, 3), (2, 4), (2, 5), (3, 6), (3, 7)]
assert tree_diameter(n, edges) == 4... | [
{
"docstring": null,
"function_declaration": "def bfs_farthest_node(start, n, adj_list):",
"function_name": "bfs_farthest_node",
"parameter_list": "(start, n, adj_list)"
},
{
"docstring": null,
"function_declaration": "def tree_diameter(n, edges):",
"function_name": "tree_diameter",
... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef bfs_farthest_node(start, n, adj_list):\n distances = [-1] * (n + 1)\n queue = deque([start])\n distances[start] = 0\n... | trial_gpt4o_0 | {
"original_instruction": "You are given a tree which is an acyclic connected graph. The vertices are enumerated from 1 to n. Your task is to find the diameter of the tree, which is defined as the longest shortest path between any two vertices in the tree.\n\nInput\n\nThe first line contains an integer n (2 ≤ n ≤ 100... | 0.681861 | Taco_18024 | C | [
"bfs_farthest_node",
"tree_diameter"
] | 2 | [
[
"tree_diameter",
"bfs_farthest_node"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 2056c0b1ee198344de0682c2ca8cb7b8cfb40cb7 | 107e3675155a6a9dc268001de7fc5135c56d63f3 | |||
v1.0 | complete | Taco | Taco_17959_C | from typing import List, Tuple
def is_prime(num: int) -> bool:
"""
Checks if a number is a prime number.
Args:
num (int): The number to be checked.
Returns:
bool: True if the number is prime, False otherwise.
"""
pass
def has_prime_subsequence(nums: List[int]) -> str:
"""... | def is_prime(num):
"""
Checks if a number is a prime number.
"""
if num <= 1:
return False
if num == 2:
return True
if num % 2 == 0:
return False
for i in range(3, int(num ** 0.5) + 1, 2):
if num % i == 0:
return False
return True
def has_prim... | def test_is_prime():
assert is_prime(2) == True
assert is_prime(5) == True
assert is_prime(11) == True
assert is_prime(10) == False
assert is_prime(21) == False
def test_has_prime_subsequence():
assert has_prime_subsequence([1, 2, 3, 4, 5]) == "YES"
assert has_prime_subsequence([4, 6, 8, 10... | [
{
"docstring": "Checks if a number is a prime number.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns 'YES' if there exists a contiguous sub-sequence with a prime sum, otherwise returns 'NO'",
"function_dec... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Checks if a number is a prime number.\n \"\"\"\n if num <= 1:\n return False\n if num == 2:\n return Tru... | trial_gpt4o_0 | {
"original_instruction": "Alice loves playing with integers and sequences. She is particularly interested in finding a special type of sub-sequence within a sequence of integers. The special sub-sequence is defined as follows:\n1. It must be a contiguous sub-sequence.\n2. The sum of the numbers in the sub-sequence m... | 0.715961 | Taco_17959 | C | [
"is_prime",
"has_prime_subsequence",
"prime_subsequence_tests"
] | 3 | [
[
"has_prime_subsequence",
"is_prime"
],
[
"prime_subsequence_tests",
"has_prime_subsequence"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | d90314dd466db488f410698c7442808871727751 | d92d343c07abe1be1905e932c4157bec0dda64ba | |||
v1.0 | complete | Taco | Taco_18419_C | def process_commands(n: int, commands: List[Tuple[int, int, int]], deadlines: List[int]) -> List[int]:
""" Processes a series of commands to update project deadlines and queries the earliest deadline across specific departments.
Args:
n (int): Number of departments.
commands (List[Tuple[int, int, i... | import sys
from bisect import bisect_left, bisect_right
def create_segment_tree(arr, n):
seg_tree = [sys.maxsize] * 4 * n
build(seg_tree, arr, 0, n - 1, 0)
return seg_tree
def build(seg_tree, arr, start, end, node):
if start == end:
seg_tree[node] = arr[start]
else:
mid = (start + ... | def test_process_commands():
n, q = 5, 4
deadlines = [10, 20, 5, 15, 25]
commands = [(1, 1, 3), (0, 2, 6), (1, 1, 3), (1, 1, 5)]
assert process_commands(n, commands, deadlines) == [5, 5, 5]
def test_process_commands_with_updates():
n, q = 5, 6
deadlines = [10, 20, 5, 15, 25]
commands = [(1,... | [
{
"docstring": null,
"function_declaration": "def create_segment_tree(arr, n):",
"function_name": "create_segment_tree",
"parameter_list": "(arr, n)"
},
{
"docstring": null,
"function_declaration": "def build(seg_tree, arr, start, end, node):",
"function_name": "build",
"paramete... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import bisect\n\nclass ProjectManager:\n def __init__(self, deadlines):\n self.deadlines = deadlines\n self.sorted_deadlines = sorted(deadlines)\n... | trial_gpt4o_2 | {
"original_instruction": "A company has multiple departments, each with a unique project. Every employee in the company is part of exactly one department, and each department's project has a specific priority and deadline. Your task is to process a series of commands to update the project information and answer quer... | 0.576969 | Taco_18419 | C | [
"create_segment_tree",
"build",
"update",
"query",
"process_commands"
] | 5 | [
[
"create_segment_tree",
"build"
],
[
"process_commands",
"create_segment_tree"
],
[
"process_commands",
"query"
],
[
"process_commands",
"update"
]
] | 4 | [] | false | [] | false | pytest | false | [] | true | 38b2a70aa7319062eb901291ac66d3c4fc666aac | bd258129c29ece6644303dee7b79a06fc22c63b4 | |||
v1.0 | complete | Taco | Taco_17878_C | class TreeNode:
def __init__(self, value=0, left=None, right=None):
self.value = value
self.left = left
self.right = right
def build_tree(nodes):
node_dict = {}
for node in nodes:
value = node[0]
if value not in node_dict:
node_dict[value] = TreeNode(valu... | class TreeNode:
def __init__(self, value=0, left=None, right=None):
self.value = value
self.left = left
self.right = right
def build_tree(nodes):
node_dict = {}
for node in nodes:
value = node[0]
if value not in node_dict:
node_dict[value] = TreeNode(valu... | def test_invert_binary_tree():
t = 1
test_cases = [
(7, [
(1, 2, 3),
(2, 4, 5),
(3, 6, 7),
(4, -1, -1),
(5, -1, -1),
(6, -1, -1),
(7, -1, -1)
])
]
expected_output = [
[(1, 3, 2),
(3, 7, 6)... | [] | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_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 i... | trial_gpt4o_2 | {
"original_instruction": "Kaito is creating a game where you need to invert a binary tree. In a binary tree, each node has at most two children referred to as the left child and the right child. Inverting a binary tree means swapping every left node with its corresponding right node.\n\nGiven a binary tree in the fo... | 0.543339 | Taco_17878 | C | [
"build_tree",
"invert_tree",
"tree_to_list",
"invert_binary_tree"
] | 4 | [
[
"invert_binary_tree",
"build_tree"
],
[
"invert_binary_tree",
"invert_tree"
],
[
"invert_binary_tree",
"tree_to_list"
]
] | 3 | [] | false | [
"TreeNode"
] | true | pytest | false | [] | true | e78b2e2c953946c65cd29e4db6bdd3447bcaec36 | b9d3a072e906fcb35a141371340a03a2af0592a3 | |||
v1.0 | complete | Taco | Taco_18473_C | def longestPerfectSquareSubseq(N: int, arr: List[int]) -> int:
"""Given an integer array `arr` of size `N`, find the length of the longest subsequence such that every element in the
subsequence is a perfect square.
Example:
>>> longestPerfectSquareSubseq(6, [1, 2, 3, 4, 5, 16])
3
>>> l... | import math
def is_perfect_square(num):
"""
Helper function to check if a number is a perfect square.
"""
if num < 0:
return False
root = int(math.isqrt(num))
return root * root == num
def longestPerfectSquareSubseq(N, arr):
"""
Function to find the length of the longest subseq... | from solution import longestPerfectSquareSubseq
def test_example1():
assert longestPerfectSquareSubseq(6, [1, 2, 3, 4, 5, 16]) == 3
def test_example2():
assert longestPerfectSquareSubseq(4, [10, 15, 14, 7]) == 0
def test_all_perfect_squares():
assert longestPerfectSquareSubseq(5, [1, 4, 9, 16, 25]) == 5
... | [
{
"docstring": "Helper function to check if a number is a perfect square.",
"function_declaration": "def is_perfect_square(num):",
"function_name": "is_perfect_square",
"parameter_list": "(num)"
},
{
"docstring": "Function to find the length of the longest subsequence such that every element... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef is_perfect_square(num):\n \"\"\"\n Helper function to check if a number is a perfect square.\n \"\"\"\n if num < 0:\n return ... | trial_gpt4o_0 | {
"original_instruction": "Given an integer array arr[] of size N, find the length of the longest subsequence such that every element in the subsequence is a perfect square.\n\nExample 1:\nInput:\nN = 6, arr = [1, 2, 3, 4, 5, 16]\nOutput:\n3\nExplanation:\nThe longest subsequence where every element is a perfect squa... | 0.672769 | Taco_18473 | C | [
"is_perfect_square",
"longestPerfectSquareSubseq"
] | 2 | [
[
"longestPerfectSquareSubseq",
"is_perfect_square"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | bc94b629ec0fb242fd5ab84b7c983576a1e7fbf5 | dd83977f0420ecd8669b40e7fa7d3e25e60cfb74 | |||
v1.0 | complete | Taco | Taco_17624_C | from typing import List, Tuple
from collections import deque
def min_steps(grid: List[List[int]], start: Tuple[int, int], target: Tuple[int, int]) -> int:
""" Determine the minimum number of steps required for a character to travel from the starting point to the target point in a 2D grid-based environment. The gri... | from collections import deque
def min_steps(grid, start, target):
n, m = len(grid), len(grid[0])
xs, ys = start
xt, yt = target
if grid[xs][ys] == 0 or grid[xt][yt] == 0:
return -1
directions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
queue = deque([(xs, ys, 0)])
visited = set()
visi... | from solution import min_steps_wrapper
def test_basic_case():
input_str = ("5 5\n"
"1 1 1 0 1\n"
"1 0 1 1 1\n"
"1 1 1 0 1\n"
"0 1 0 1 1\n"
"1 1 1 1 1\n"
"0 0\n"
"4 4\n")
assert min_steps_wrapp... | [
{
"docstring": null,
"function_declaration": "def min_steps(grid, start, target):",
"function_name": "min_steps",
"parameter_list": "(grid, start, target)"
},
{
"docstring": null,
"function_declaration": "def parse_input(input_str):",
"function_name": "parse_input",
"parameter_li... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef min_steps(grid, start, target):\n n, m = len(grid), len(grid[0])\n xs, ys = start\n xt, yt = target\n if grid[xs][... | trial_gpt4o_0 | {
"original_instruction": "A game development company is working on creating a navigation system for characters in a 2D grid-based environment. The grid consists of cells that can either be walkable or blocked. Each cell in the grid is represented by a value: 1 for walkable and 0 for blocked. \n\nGiven the starting c... | 0.711856 | Taco_17624 | C | [
"min_steps",
"parse_input",
"min_steps_wrapper"
] | 3 | [
[
"min_steps_wrapper",
"min_steps"
],
[
"min_steps_wrapper",
"parse_input"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 419e3f95414fe6e6ea52fdbd846620efeaecb049 | 1dfb59aac344c6ec004915443cdf8d06ceeb59e1 | |||
v1.0 | complete | Taco | Taco_18196_C | def apply_operations(n, k, operations):
"""
This function applies a list of k operations to an n x n grid and returns the final state of the grid.
Args:
n (int): The size of the grid (n x n).
k (int): The number of operations.
operations (list of tuples): Each tuple contains (i, j, c) which... | def apply_operations(n, k, operations):
"""
This function applies a list of k operations to an n x n grid and returns the final state of the grid.
Args:
n (int): The size of the grid (n x n).
k (int): The number of operations.
operations (list of tuples): Each tuple contains (i, j, c) which... | from solution import apply_operations, grid_after_operations
def test_apply_operations_example_1():
n, k = 3, 4
operations = [(1, 1, 'a'), (2, 2, 'b'), (3, 3, 'c'), (3, 1, 'd')]
assert apply_operations(n, k, operations) == ["a..", ".b.", "d.c"]
def test_apply_operations_example_2():
n, k = 2, 3
op... | [
{
"docstring": "This function applies a list of k operations to an n x n grid and returns the final state of the grid.\n\nArgs:\nn (int): The size of the grid (n x n).\nk (int): The number of operations.\noperations (list of tuples): Each tuple contains (i, j, c) which indicates\n pl... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def update_grid(n, k, operations):\n grid = [['.' for _ in range(n)] for _ in range(n)]\n \n for i, j, c in operations:\n grid[i-1][j-1] = c\n\n ... | trial_gpt4o_2 | {
"original_instruction": "You are given an empty grid of size n x n and a list of k operations. Each operation is represented as a tuple (i, j, c) where i and j are the row and column indices (1-indexed) and c is a character. For each operation, you need to place the character c in the cell located at the i-th row a... | 0.624197 | Taco_18196 | C | [
"apply_operations",
"grid_after_operations"
] | 2 | [
[
"grid_after_operations",
"apply_operations"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 9526d5d4827f7f8f760c95def6abb456f436162e | 3543104c33ba61c365e22925aa6b60d3f3cfc0cb | |||
v1.0 | complete | Taco | Taco_18352_C | def is_prime(num):
"""
Determine if a number is prime.
"""
if num < 2:
return False
if num == 2:
return True
if num % 2 == 0:
return False
for i in range(3, int(num**0.5) + 1, 2):
if num % i == 0:
return False
return True
def find_special_even... | def is_prime(num):
"""
Determine if a number is prime.
"""
if num < 2:
return False
if num == 2:
return True
if num % 2 == 0:
return False
for i in range(3, int(num**0.5) + 1, 2):
if num % i == 0:
return False
return True
def find_special_even... | from solution import find_special_events
def test_no_special_events():
events = [(1001, 10), (1002, 15), (1003, 20)]
assert find_special_events(3, events) == ["None"]
def test_some_special_events():
events = [(1001, 20), (1002, 31), (1003, 12), (1004, 17), (1005, 18)]
assert find_special_events(5, eve... | [
{
"docstring": "Determine if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Find special events whose number of participants is a prime number.\n\nArgs:\n- n (int): Number of events.\n- events (list... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 == 0 or num % 3 == 0:\n return False\n ... | trial_gpt4o_1 | {
"original_instruction": "A company specializing in event management has decided to improve its tracking of participant registration for their numerous events. They keep a record of unique event IDs (event_id) and the number of participants (num_participants) registered for each event.\n\nTo facilitate their plannin... | 0.57016 | Taco_18352 | C | [
"is_prime",
"find_special_events"
] | 2 | [
[
"find_special_events",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 16f705c72305205d84128755728c75d07e7d3434 | 5f43d77e7304059db33b170369db1d7729a9c06f | |||
v1.0 | complete | Taco | Taco_18349_C | def count_connected_groups(grid, r, c):
"""
Count the number of connected groups of 1s in a grid.
>>> grid1 = [
... [0, 1, 0, 0],
... [0, 1, 1, 0],
... [0, 0, 0, 0]
... ]
>>> count_connected_groups(grid1, 3, 4)
1
>>> grid2 = [
... [1, 1, 0],
... [0, 1, 1],
... [0, 0,... | def count_connected_groups(grid, r, c):
visited = [[False] * c for _ in range(r)]
def dfs(x, y):
stack = [(x, y)]
while stack:
i, j = stack.pop()
for ni, nj in [(i-1, j), (i+1, j), (i, j-1), (i, j+1)]:
if 0 <= ni < r and 0 <= nj < c and not visited[ni... | def test_count_connected_groups():
grid1 = [
[0, 1, 0, 0],
[0, 1, 1, 0],
[0, 0, 0, 0]
]
assert count_connected_groups(grid1, 3, 4) == 1
grid2 = [
[1, 1, 0],
[0, 1, 1],
[0, 0, 1]
]
assert count_connected_groups(grid2, 3, 3) == 1
grid3 ... | [
{
"docstring": null,
"function_declaration": "def count_connected_groups(grid, r, c):",
"function_name": "count_connected_groups",
"parameter_list": "(grid, r, c)"
},
{
"docstring": null,
"function_declaration": "def remaining_ones_after_operations(grid, r, c, n):",
"function_name": ... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def number_of_1s_after_operations(T, test_cases):\n def dfs(grid, visited, i, j, R, C):\n # Stack based DFS for finding all connected 1s\n stack =... | trial_gpt4o_1 | {
"original_instruction": "### Problem\n\nYou are given a grid with `R` rows and `C` columns. Each cell in the grid has a value which can be either 1 or 0. The objective is to perform the following operation for exactly `N` times:\n- Choose a cell with value 1.\n- The chosen cell and all cells connected directly or i... | 0.602114 | Taco_18349 | C | [
"count_connected_groups",
"remaining_ones_after_operations",
"solve"
] | 3 | [
[
"remaining_ones_after_operations",
"count_connected_groups"
],
[
"solve",
"remaining_ones_after_operations"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | df630d7ae4e9ad15c02cf456b7890b41c416c603 | c17f52fda8b7a73f1143104b8a06b019202f5754 | |||
v1.0 | complete | Taco | Taco_18730_C | class Node:
def __init__(self, key):
self.data = key
self.left = None
self.right = None
def diagonalSum(root):
""" Computes the sum of the nodes present at each diagonal of the binary tree.
>>> root = Node(1)
>>> root.left = Node(2)
>>> root.right = Node(3)
>>> root.left... | class Node:
def __init__(self, key):
self.data = key
self.left = None
self.right = None
def diagonalSum(root):
if root is None:
return []
diagonal_map = {}
_diagonalSumUtil(root, 0, diagonal_map)
# Extract sums from the map and return as a list
result =... | from solution import Node, diagonalSum
def test_diagonalSum_simple():
root = Node(1)
root.left = Node(2)
root.right = Node(3)
root.left.left = Node(4)
root.left.right = Node(5)
root.right.left = Node(6)
root.right.right = Node(7)
root.right.right.left = Node(8)
assert diagonalS... | [] | [
0,
0,
0,
1,
0
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict\n\nclass Node:\n def __init__(self, data):\n self.data = data\n self.left = None\n self.right = None\n\... | trial_gpt4o_3 | {
"original_instruction": "Given a binary tree, the task is to write a function diagonalSum() that computes the sum of the nodes present at each diagonal of the tree. The diagonals of a binary tree begin from the root and extend rightwards and downwards, forming a cascading pattern.\n\nInput:\n- The function takes a ... | 0.546661 | Taco_18730 | C | [
"diagonalSum",
"_diagonalSumUtil"
] | 2 | [
[
"diagonalSum",
"_diagonalSumUtil"
]
] | 1 | [] | false | [
"Node"
] | true | pytest | true | [] | true | 72ef3fa966022767ba729be19852e2d333e92114 | 0d6c9c13478681fe605c7e6c03ce56a496737fc3 | |||
v1.0 | complete | Taco | Taco_18654_C | def is_prime(n: int) -> bool:
""" Check if a number is a prime number.
>>> is_prime(2) == True
>>> is_prime(3) == True
>>> is_prime(4) == False
>>> is_prime(5) == True
>>> is_prime(10) == False
"""
def are_twin_primes(A: int, B: int) -> str:
""" Checks if A and B are twin primes.
>>... | def is_prime(n):
if n <= 1:
return False
for i in range(2, int(n ** 0.5) + 1):
if n % i == 0:
return False
return True
def are_twin_primes(A, B):
"""
Checks if A and B are twin primes.
"""
if abs(A - B) == 2 and is_prime(A) and is_prime(B):
return "YES"
... | from solution import is_prime, are_twin_primes
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(10) == False
def test_are_twin_primes():
assert are_twin_primes(3, 5) == "YES"
assert are_twin_pr... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Checks if A and B are twin primes.",
"function_declaration": "def are_twin_primes(A, B):",
"function_name": "are_twin_primes",
"parameter_list"... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n if n <= 1:\n return False\n for i in range(2, int(n ** 0.5) + 1):\n if n % i == 0:\n return False\n return Tru... | trial_gpt4o_0 | {
"original_instruction": "John is practicing for a coding competition and is working on understanding the concept of prime numbers. He reads about twin primes, which are pairs of prime numbers that have a difference of two. John wants to write a program to check if two given numbers are twin primes.\n\n-----Input:--... | 0.732927 | Taco_18654 | C | [
"is_prime",
"are_twin_primes"
] | 2 | [
[
"are_twin_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 28ac6a744e257023b3dda958b8104e25c4ff8eaf | ba7661feca4fa1fabce99c7b3af34e03626aaeda | |||
v1.0 | complete | Taco | Taco_18610_C | from typing import List
def generate_sequence_up_to(max_value: int) -> List[int]:
""" Creates a sequence starting with 3, 5 where each term is the sum of the previous two terms, up to max_value.
>>> generate_sequence_up_to(50)
[3, 5, 8, 13, 21, 34, 55]
"""
# function implementation here
def smalle... | def generate_sequence_up_to(max_value):
sequence = [3, 5]
while sequence[-1] < max_value:
sequence.append(sequence[-1] + sequence[-2])
return sequence
def smallest_term(sequence, query):
for term in sequence:
if term >= query:
return term
return None
def process_queries... | from solution import generate_sequence_up_to, smallest_term, process_queries
def test_generate_sequence():
assert generate_sequence_up_to(50) == [3, 5, 8, 13, 21, 34, 55]
def test_smallest_term():
sequence = [3, 5, 8, 13, 21, 34, 55]
assert smallest_term(sequence, 50) == 55
assert smallest_term(sequen... | [
{
"docstring": null,
"function_declaration": "def generate_sequence_up_to(max_value):",
"function_name": "generate_sequence_up_to",
"parameter_list": "(max_value)"
},
{
"docstring": null,
"function_declaration": "def smallest_term(sequence, query):",
"function_name": "smallest_term",... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_smallest_term_greater_or_equal(seq, queries):\n \"\"\"\n For each query in queries, find the smallest term in the sequence that is greater than or e... | trial_gpt4o_1 | {
"original_instruction": "Consider an infinite sequence defined as follows: The first term is 3, the second term is 5, and each subsequent term is the sum of the previous two terms. Hence, the sequence begins as 3, 5, 8, 13, 21, 34, ...\n\nYou are given an integer M and a list of integers Q of length K. For each que... | 0.712679 | Taco_18610 | C | [
"generate_sequence_up_to",
"smallest_term",
"process_queries"
] | 3 | [
[
"process_queries",
"generate_sequence_up_to"
],
[
"process_queries",
"smallest_term"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | true | [] | true | cccb2e3ebbf5d6c70344f9f8cb3b8d73a9c58e1a | c546759f14c53a8e5b948431584c12f9e448d533 | |||
v1.0 | complete | Taco | Taco_18640_C | from typing import List, Tuple, Dict
def shortest_travel_times(n: int, m: int, s: int, routes: List[Tuple[int, int, int, str]]) -> Dict[str, List[int]]:
""" Determine the shortest travel times from the starting intersection to all other intersections,
while only traveling on roads that belong to a particular b... | from collections import defaultdict
import heapq
def dijkstra(n, edges, start, route):
graph = defaultdict(list)
for u, v, t in edges:
graph[u].append((v, t))
graph[v].append((u, t))
dist = {i: float('inf') for i in range(1, n+1)}
dist[start] = 0
min_heap = [(0, start)]
... | def test_shortest_travel_times():
n, m = 5, 6
s = 1
routes= [
(1, 2, 2, "A"),
(2, 3, 3, "A"),
(3, 4, 1, "A"),
(1, 3, 8, "B"),
(3, 5, 2, "B"),
(4, 5, 3, "C")
]
result = shortest_travel_times(n, m, s, routes)
assert result["A"] == [0, 2, 5, 6, -... | [
{
"docstring": null,
"function_declaration": "def dijkstra(n, edges, start, route):",
"function_name": "dijkstra",
"parameter_list": "(n, edges, start, route)"
},
{
"docstring": null,
"function_declaration": "def shortest_travel_times(n, m, s, routes):",
"function_name": "shortest_tr... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict\nimport heapq\n\ndef dijkstra(n, edges, start, route):\n graph = defaultdict(list)\n for u, v, t in edges:\n graph... | trial_gpt4o_0 | {
"original_instruction": "You are an urban planner tasked with creating the optimal route plan for bus lines in a city. The city is represented as a graph with n intersections and m bidirectional roads between those intersections. Each road has a certain bus route associated with it and a travel time. The goal is to... | 0.682005 | Taco_18640 | C | [
"dijkstra",
"shortest_travel_times"
] | 2 | [
[
"shortest_travel_times",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | accb0093f894560536cf8c52b66c0b3b490e101a | fc1ee3566e100f5d62a156b1669791fe841c38de | |||
v1.0 | complete | Taco | Taco_18725_C | def process_input(n: int, q: int, h: List[int], k: int, queries: List[Tuple[int, int]]) -> List[str]:
"""
Determine for each subsegment query whether the height difference within the subsegment does not exceed k.
Parameters:
n (int): Number of signposts
q (int): Number of subsegment queries
h ... | def is_uniform(subsegment_heights, k):
"""
Checks if height difference within the subsegment does not exceed k.
"""
return max(subsegment_heights) - min(subsegment_heights) <= k
def check_subsegments(n, h, k, queries):
"""
Checks each subsegment query for the uniformity condition.
"""
r... | from solution import process_input
def test_example_case():
n = 6
q = 3
h = [1, 5, 3, 9, 2, 6]
k = 4
queries = [(1, 3), (2, 5), (1, 6)]
assert process_input(n, q, h, k, queries) == ["Yes", "No", "No"]
def test_single_signpost():
n = 1
q = 1
h = [5]
k = 10
queries = [(1, 1)]... | [
{
"docstring": "Checks if height difference within the subsegment does not exceed k.",
"function_declaration": "def is_uniform(subsegment_heights, k):",
"function_name": "is_uniform",
"parameter_list": "(subsegment_heights, k)"
},
{
"docstring": "Checks each subsegment query for the uniformi... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def check_subsegments_heights(n, q, heights, k, queries):\n \"\"\"\n Checks if the height difference within each subsegment does not exceed k.\n \n Par... | trial_gpt4o_1 | {
"original_instruction": "The city is planning to erect a series of signposts along a straight road. Each signpost has a specified height. To ensure uniformity in design, the height of each signpost in any given subsegment of the road must not differ by more than a fixed number, k.\n\nYou are given the heights of n ... | 0.589336 | Taco_18725 | C | [
"is_uniform",
"check_subsegments",
"process_input"
] | 3 | [
[
"check_subsegments",
"is_uniform"
],
[
"process_input",
"check_subsegments"
]
] | 2 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | aecf9461027110c468da121dd37f1c57866bcd9e | 5488f416ebdff67c7c39092e2d2e88e267f33703 | |||
v1.0 | complete | Taco | Taco_18434_C | def shortest_path_between_cities(T: int, test_cases: List[Tuple[int, int, List[Tuple[int, int, int]], int, List[Tuple[int, int]]]]) -> List[int]:
""" Calculate the shortest distance between pairs of cities for multiple test cases.
Args:
T : int -- number of test cases
test_cases : List[Tuple[int, i... | def floyd_warshall(n, distance):
INF = float('inf')
dist = [[INF] * (n + 1) for _ in range(n + 1)]
for i in range(1, n + 1):
dist[i][i] = 0
for u in range(1, n + 1):
for v in range(1, n + 1):
if distance[u][v] != -1:
dist[u][v] = distance[u][v]
... | def test_shortest_path_between_cities():
T = 2
test_cases = [
(4, 4, [(1, 2, 5), (2, 3, 3), (3, 4, 1), (4, 1, 7)], 2, [(1, 3), (2, 4)]),
(3, 3, [(1, 2, 1), (2, 3, 1)], 1, [(1, 3)])
]
expected_results = [8, 4, 2]
assert shortest_path_between_cities(T, test_cases) == expected_resu... | [
{
"docstring": null,
"function_declaration": "def floyd_warshall(n, distance):",
"function_name": "floyd_warshall",
"parameter_list": "(n, distance)"
},
{
"docstring": null,
"function_declaration": "def shortest_path_between_cities(T, test_cases):",
"function_name": "shortest_path_be... | [
0,
0,
0,
0,
0,
0,
0,
1,
1,
1
] | 3 | hard | 0.3 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import sys\nimport heapq\n\ndef shortest_path(T, test_cases):\n results = []\n \n for test_case in test_cases:\n C, P, pathways, Q, queries = test_... | trial_gpt4o_7 | {
"original_instruction": "In a given kingdom, there is a famous magician who can create magical pathways between different cities. The king has asked the magician to connect cities in such a way that the path should be the shortest possible to travel between two specific cities. However, the magician can't directly ... | 0.725703 | Taco_18434 | C | [
"floyd_warshall",
"shortest_path_between_cities"
] | 2 | [
[
"shortest_path_between_cities",
"floyd_warshall"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | c1d2a55e868a0346a9ea9525f0ccbdfbc99b6fec | 89fd2cf4cacc882c7d818d749ea249799d14a66e | |||
v1.0 | complete | Taco | Taco_18764_C | def find_min_cost_to_visit_all_nodes(n: int, m: int, edges: List[Tuple[int, int, int]]) -> int:
""" You are given an undirected graph with n nodes and m edges. Each edge has an associated cost. Your task is
to find the minimum cost to visit every node at least once, starting and ending at the same node.
... | import itertools
def travel_cost(graph, path):
cost = 0
for i in range(len(path) - 1):
u, v = path[i], path[i+1]
if v in graph[u]:
cost += graph[u][v]
else:
return float('inf')
return cost
def find_min_cost_to_visit_all_nodes(n, m, edges):
if m < n - 1:
... | import pytest
from solution import find_min_cost_to_visit_all_nodes
def test_example_1():
n, m = 4, 6
edges = [
(1, 2, 10),
(1, 3, 15),
(1, 4, 20),
(2, 3, 35),
(2, 4, 25),
(3, 4, 30)
]
assert find_min_cost_to_visit_all_nodes(n, m, edges) == 80
def test_e... | [
{
"docstring": null,
"function_declaration": "def travel_cost(graph, path):",
"function_name": "travel_cost",
"parameter_list": "(graph, path)"
},
{
"docstring": null,
"function_declaration": "def find_min_cost_to_visit_all_nodes(n, m, edges):",
"function_name": "find_min_cost_to_vis... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import sys\n\ndef tsp(graph, n):\n # Initialize dp array to store the results\n dp = [[sys.maxsize] * (1 << n) for _ in range(n)]\n # Starting point initi... | trial_gpt4o_1 | {
"original_instruction": "You are given an undirected graph with $n$ nodes and $m$ edges. Each edge has an associated cost. Your task is to find the minimum cost to visit every node at least once, starting and ending at the same node.\n\nYou can perform the following operations on the graph:\n- Traverse each edge ex... | 0.716662 | Taco_18764 | C | [
"travel_cost",
"find_min_cost_to_visit_all_nodes"
] | 2 | [
[
"find_min_cost_to_visit_all_nodes",
"travel_cost"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f13ef4f619fc0da05d5b2979cc4f4dab4e944112 | b002c26d2ee8b8a216a0a17a5279b96eff8a8660 | |||
v1.0 | complete | Taco | Taco_16662_C | def can_complete_journey(Einit, Emax, R, C, E, books, commands, potions):
""" Determine if the scholars can complete their journey without their energy dropping to zero or below.
Args:
Einit (int): Initial energy level.
Emax (int): Maximum energy level.
R (int): Number of rows in the library grid.
... | def can_complete_journey(Einit, Emax, R, C, E, books, commands, potions):
current_energy = Einit
current_position = (0, 0)
movements = {
'U': (-1, 0),
'D': (1, 0),
'L': (0, -1),
'R': (0, 1)
}
for direction, steps in commands:
for _ in range(steps... | def test_can_complete_journey_success():
Einit = 100
Emax = 200
R = 3
C = 3
E = 10
books = [
[10, 20, 30],
[40, 50, 60],
[70, 80, 90]
]
commands = [('D', 2), ('R', 2), ('U', 1)]
potions = [50, 30]
assert can_complete_journey(Einit, Emax, R, C, E, books, c... | [
{
"docstring": null,
"function_declaration": "def can_complete_journey(Einit, Emax, R, C, E, books, commands, potions):",
"function_name": "can_complete_journey",
"parameter_list": "(Einit, Emax, R, C, E, books, commands, potions)"
},
{
"docstring": null,
"function_declaration": "def pro... | [
0,
0,
0,
0,
0,
1,
1,
0,
1,
0
] | 3 | hard | 0.3 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def can_complete_journey(e_init, e_max, rows, cols, energy_per_move, book_importance, commands, potions):\n current_energy = e_init\n x, y = 0, 0 # Starting... | trial_gpt4o_5 | {
"original_instruction": "A group of scholars are exploring the grand ancient library, a vast network of rooms filled with books and secrets. The library is represented as a rectangular grid of rooms, and each room contains exactly one book. The scholars aim to collect books using a specific set of movement commands... | 0.560808 | Taco_16662 | C | [
"can_complete_journey",
"process_dataset",
"process_input",
"solve"
] | 4 | [
[
"process_dataset",
"can_complete_journey"
],
[
"solve",
"process_dataset"
],
[
"solve",
"process_input"
]
] | 3 | [
"process_dataset",
"process_input"
] | false | [] | false | pytest | false | [] | true | 2b3398e8b6b328be07a20d38d729a9822a465c59 | 9aab6a660cf9b3385dc8b6540461f9cfd8a872c3 | |||
v1.0 | complete | Taco | Taco_18954_C | from typing import List
def is_useful_tool(identifier: str) -> bool:
"""
Determine if the tool identifier can be rearranged to form a palindrome.
>>> is_useful_tool("radar") == True
>>> is_useful_tool("abc") == False
>>> is_useful_tool("abb") == True
>>> is_useful_tool("car") == False
"""
... | def is_useful_tool(identifier):
"""
Determines if the tool identifier can be rearranged to form a palindrome.
"""
from collections import Counter
# Count the frequency of each character in the identifier
char_counts = Counter(identifier)
# Count how many characters have an odd frequency
... | from solution import is_useful_tool, determine_useful_tools
def test_is_useful_tool():
assert is_useful_tool("radar") == True
assert is_useful_tool("abc") == False
assert is_useful_tool("abb") == True
assert is_useful_tool("car") == False
assert is_useful_tool("a") == True # Single character is a ... | [
{
"docstring": "Determines if the tool identifier can be rearranged to form a palindrome.",
"function_declaration": "def is_useful_tool(identifier):",
"function_name": "is_useful_tool",
"parameter_list": "(identifier)"
},
{
"docstring": "Determines which of the given tool identifiers are use... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_useful_tool(identifier):\n \"\"\"\n Determines if the given tool identifier can be rearranged to form a palindrome.\n \"\"\"\n from collections ... | trial_gpt4o_2 | {
"original_instruction": "In a busy workshop, there are a number of different types of tools lying around. Each tool can be identified by a string of lowercase Latin letters. A tool is considered \"useful\" if its identifier can be turned into a palindrome by reordering its characters. The workshop owner, Gina, want... | 0.68357 | Taco_18954 | C | [
"is_useful_tool",
"determine_useful_tools"
] | 2 | [
[
"determine_useful_tools",
"is_useful_tool"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 899dadbea93eba9077284f4ab29425579e9eae64 | 201d57e3a931e3c58268f4ff60dacc5bffe0c41d | |||
v1.0 | complete | Taco | Taco_18720_C | from typing import List
def can_form_palindrome(s: str) -> bool:
"""
Determines if the characters of the string s can be rearranged to form a palindrome.
"""
# Your code here
def batch_check_palindromic_rearrangement(strings: List[str]) -> List[str]:
"""
Accepts a list of strings and for each ... | def can_form_palindrome(s):
"""
Determines if the characters of the string s can be rearranged to form a palindrome.
"""
from collections import Counter
# Count the frequency of each character in the string
char_count = Counter(s)
# Count how many characters have an odd frequency
o... | from solution import can_form_palindrome, batch_check_palindromic_rearrangement
def test_can_form_palindrome():
assert can_form_palindrome("aabbcc") == True
assert can_form_palindrome("abcdef") == False
assert can_form_palindrome("aaabb") == True
assert can_form_palindrome("racecar") == True
assert... | [
{
"docstring": "Determines if the characters of the string s can be rearranged to form a palindrome.",
"function_declaration": "def can_form_palindrome(s):",
"function_name": "can_form_palindrome",
"parameter_list": "(s)"
},
{
"docstring": null,
"function_declaration": "def batch_check_p... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def can_form_palindrome(s):\n \"\"\"\n Determines if the characters of the string s can be rearranged to form a palindrome.\n \"\"\"\n from collections... | trial_gpt4o_1 | {
"original_instruction": "Deepak is fascinated by palindromic sequences and wants to explore them in the context of strings. A string is called a palindrome if it reads the same forwards and backwards. For example, \"radar\" is a palindrome, but \"hello\" is not. Deepak would like to determine if it's possible to re... | 0.688385 | Taco_18720 | C | [
"can_form_palindrome",
"batch_check_palindromic_rearrangement"
] | 2 | [
[
"batch_check_palindromic_rearrangement",
"can_form_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e83d3ff422f887d448b7ead4e4101daeaeaad873 | 673705dc382a198dde0b259c58ba660a808d7ea4 | |||
v1.0 | complete | Taco | Taco_18545_C | from typing import List
def lexicographically_smallest_array(arr: List[int]) -> List[int]:
""" Find the lexicographically smallest array that can be obtained after at most one operation of removing any element and inserting it back at any other position.
>>> lexicographically_smallest_array([4, 8, 2, 7, 5])
... | def lexicographically_smallest_array(arr):
n = len(arr)
if n <= 1:
return arr
min_elem = min(arr)
min_index = arr.index(min_elem)
smallest_array = arr[:min_index] + arr[min_index+1:]
smallest_array.sort()
smallest_array.insert(0, min_elem)
return smallest_array
d... | from solution import lexicographically_smallest_array, solve
def test_lexicographically_smallest_array():
assert lexicographically_smallest_array([4, 8, 2, 7, 5]) == [2, 4, 5, 7, 8]
assert lexicographically_smallest_array([3, 1, 4, 1, 5, 9]) == [1, 1, 3, 4, 5, 9]
assert lexicographically_smallest_array([1,... | [
{
"docstring": null,
"function_declaration": "def lexicographically_smallest_array(arr):",
"function_name": "lexicographically_smallest_array",
"parameter_list": "(arr)"
},
{
"docstring": null,
"function_declaration": "def solve(arrays):",
"function_name": "solve",
"parameter_lis... | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def lexicographically_smallest_array(T, test_cases):\n results = []\n for case in test_cases:\n N, arr = case\n smallest_arr = sorted(arr[:]) ... | trial_gpt4o_4 | {
"original_instruction": "You are given an array of N integers. You are allowed to perform at most one operation of the following kind: Choose any element in the array, remove it from its position, and insert it back into any other position of the array.\n\nInput\n\nThe first line of the input contains an integer T ... | 0.641714 | Taco_18545 | C | [
"lexicographically_smallest_array",
"solve",
"array_to_string",
"main"
] | 4 | [
[
"solve",
"lexicographically_smallest_array"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a5a2809d9847cd1423c88dd5ebddf5eb7f8f89cd | bc0c3bc9ae09e7a9c4c0d96734d15ac0bf34e27c | |||
v1.0 | complete | Taco | Taco_18693_C | def max_product_of_two(arr: List[int]) -> int:
"""
Returns the maximum product of two distinct elements of the array.
If the array has less than two elements, returns -1.
>>> max_product_of_two([1, 2, 3, 4, 5])
20
>>> max_product_of_two([7, 1, 9])
63
>>> max_product_of_two([10])
-1
... | def max_product_of_two(arr):
"""
Returns the maximum product of two distinct elements of the array.
If the array has less than two elements, returns -1.
"""
if len(arr) < 2:
return -1
arr = sorted(arr, reverse=True)
return arr[0] * arr[1]
def process_test_cases(t, test_cases):
... | from solution import max_product_of_two, process_test_cases, parse_input, max_product_main
def test_max_product_of_two():
assert max_product_of_two([1, 2, 3, 4, 5]) == 20
assert max_product_of_two([7, 1, 9]) == 63
assert max_product_of_two([10]) == -1
assert max_product_of_two([5, 5]) == 25
assert ... | [
{
"docstring": "Returns the maximum product of two distinct elements of the array.\nIf the array has less than two elements, returns -1.",
"function_declaration": "def max_product_of_two(arr):",
"function_name": "max_product_of_two",
"parameter_list": "(arr)"
},
{
"docstring": null,
"fun... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_product(test_cases):\n results = []\n for n, arr in test_cases:\n if n < 2:\n results.append(-1)\n else:\n arr.so... | trial_gpt4o_2 | {
"original_instruction": "You are given an array of positive integers. Your task is to determine the maximum product of two distinct elements of this array.\n\nIf the array has less than two elements, return -1.\n\n-----Input-----\n\nThe input consists of two lines:\n\nThe first line contains a single integer $t$ ($... | 0.706429 | Taco_18693 | C | [
"max_product_of_two",
"process_test_cases",
"parse_input",
"max_product_main"
] | 4 | [
[
"max_product_main",
"parse_input"
],
[
"max_product_main",
"process_test_cases"
],
[
"process_test_cases",
"max_product_of_two"
]
] | 3 | [
"process_test_cases",
"parse_input"
] | false | [] | false | pytest | true | [] | true | 6ad4470267c2c48be128486acd02a8b0a609e87d | 165f782ca889a72a24585d163ea0680d83250c00 | |||
v1.0 | complete | Taco | Taco_19024_C | from typing import List, Tuple
from collections import defaultdict, deque
def tree_diameter(n: int, edges: List[Tuple[int, int]]) -> int:
""" Calculates the diameter of a given tree.
>>> tree_diameter(5, [(1, 2), (1, 3), (2, 4), (2, 5)])
3
>>> tree_diameter(1, [])
0
>>> tree_diameter(4, [(1, 2)... | from collections import deque, defaultdict
def longest_path_length(tree: dict, start: int) -> (int, int):
"""
BFS to find the longest path from the start node in the tree.
Returns the farthest node found and the distance to that node.
"""
visited = set()
queue = deque([(start, 0)])
farthest... | def test_sample_input():
n = 5
edges = [(1, 2), (1, 3), (2, 4), (2, 5)]
assert tree_diameter(n, edges) == 3
def test_single_node():
n = 1
edges = []
assert tree_diameter(n, edges) == 0
def test_line_graph():
n = 4
edges = [(1, 2), (2, 3), (3, 4)]
assert tree_diameter(n, edges) == 3... | [
{
"docstring": "BFS to find the longest path from the start node in the tree.\nReturns the farthest node found and the distance to that node.",
"function_declaration": "def longest_path_length(tree, start):",
"function_name": "longest_path_length",
"parameter_list": "(tree, start)"
},
{
"doc... | [
1,
0
] | 1 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque, defaultdict\n\ndef longest_path_length(tree: dict, start: int) -> (int, int):\n \"\"\"\n BFS to find the longest path from the... | trial_gpt4o_0 | {
"original_instruction": "Jack and Jill are learning about graphs in their computer science class. Their teacher has given them an interesting challenge involving trees. A tree is a connected, undirected graph with no cycles. The challenge is to find the longest path in the tree, also known as the diameter of the tr... | 0.634429 | Taco_19024 | C | [
"longest_path_length",
"tree_diameter"
] | 2 | [
[
"tree_diameter",
"longest_path_length"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 07006bcc36b8cfa939dc5024417b7a51061ddde0 | ee218b4a288cfad6ad3f9c20849f4bab0f8325ae | |||
v1.0 | complete | Taco | Taco_19049_C | from typing import Tuple, Union
def prime_sieve(limit: int) -> list:
""" Generate a list of prime numbers up to the limit using the Sieve of Eratosthenes.
"""
sieve = [True] * (limit + 1)
sieve[0] = sieve[1] = False
for start in range(2, int(limit**0.5) + 1):
if sieve[start]:
fo... | def prime_sieve(limit):
"""
Generate a list of prime numbers up to the limit using the Sieve of Eratosthenes.
"""
sieve = [True] * (limit + 1)
sieve[0] = sieve[1] = False
for start in range(2, int(limit**0.5) + 1):
if sieve[start]:
for multiple in range(start * start, limit +... | from solution import find_prime_sum
def test_find_prime_sum_10():
assert find_prime_sum(10) in [(3, 7), (7, 3)]
def test_find_prime_sum_12():
assert find_prime_sum(12) in [(5, 7), (7, 5)]
def test_find_prime_sum_17():
assert find_prime_sum(17) == -1
def test_find_prime_sum_2():
assert find_prime_sum... | [
{
"docstring": "Generate a list of prime numbers up to the limit using the Sieve of Eratosthenes.",
"function_declaration": "def prime_sieve(limit):",
"function_name": "prime_sieve",
"parameter_list": "(limit)"
},
{
"docstring": "Find two prime numbers that sum up to n. If such a pair exists... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def sieve_of_eratosthenes(max_num):\n \"\"\"\n Use the sieve of Eratosthenes to find all prime numbers up to max_num.\n \"\"\"\n is_prime = [True] * (m... | trial_gpt4o_1 | {
"original_instruction": "Emma is fascinated by numbers and patterns, and she recently discovered prime numbers. She loves manipulating numbers to derive new sequences and combinations. Now, Emma is curious about prime sums.\n\nShe defines a prime sum operation which takes a number $n$ and finds two prime numbers $p... | 0.681456 | Taco_19049 | C | [
"prime_sieve",
"find_prime_sum"
] | 2 | [
[
"find_prime_sum",
"prime_sieve"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7228b4362d1cb1fe38f64a189d84a316827e3778 | 7b51431b29605e2f4819c19d551622efdf5d8d10 | |||
v1.0 | complete | Taco | Taco_19201_C | def count_smaller_elements(nums):
"""
Write a function that takes a list of integers and returns a new list where each integer is replaced
by the number of integers smaller than it on its right side in the original list.
>>> count_smaller_elements([3, 4, 9, 6, 1])
[1, 1, 2, 1, 0]
>>> count_sma... | def count_smaller_elements(nums):
"""
Returns a list where each element is replaced by the number of integers smaller than it on its right side.
"""
if not nums:
return []
result = [0] * len(nums)
sorted_nums = []
for i in range(len(nums) - 1, -1, -1):
pos = binary_search_i... | from solution import count_smaller_elements
def test_count_smaller_elements_example():
assert count_smaller_elements([3, 4, 9, 6, 1]) == [1, 1, 2, 1, 0]
def test_count_smaller_elements_all_ascending():
assert count_smaller_elements([1, 2, 3, 4, 5]) == [0, 0, 0, 0, 0]
def test_count_smaller_elements_all_desce... | [
{
"docstring": "Returns a list where each element is replaced by the number of integers smaller than it on its right side.",
"function_declaration": "def count_smaller_elements(nums):",
"function_name": "count_smaller_elements",
"parameter_list": "(nums)"
},
{
"docstring": "Uses binary searc... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def count_smaller(nums):\n \"\"\"\n Returns a new list where each integer is replaced by the number of integers smaller \n than it on its right side in th... | trial_gpt4o_2 | {
"original_instruction": "Write a function that takes a list of integers and returns a new list where each integer is replaced by the number of integers smaller than it on its right side in the original list.\n\n-----Constraints-----\n- The list will contain between 1 and 100,000 integers.\n- Each integer in the lis... | 0.658419 | Taco_19201 | C | [
"count_smaller_elements",
"binary_search_insert_position"
] | 2 | [
[
"count_smaller_elements",
"binary_search_insert_position"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | aa9f280ff8e148d1670ee92dd9f31da0c4831425 | 0bacc1e485c0eaabd2ec07d7115467931846fd56 | |||
v1.0 | complete | Taco | Taco_19312_C | def main(input_str: str) -> str:
""" Determine if a grid can be rearranged into a magic square with pairwise swaps
>>> main("2\n3\n8 1 6\n3 5 7\n4 9 2\n5\n17 24 1 8 15\n23 5 7 14 16\n4 6 13 20 22\n10 12 19 21 3\n11 18 25 2 9")
"YES\nYES"
>>> main("1\n3\n1 2 3\n4 5 6\n7 8 9")
"NO"
""" | def is_magic_square(grid, n):
magic_sum = n * (n**2 + 1) // 2
row_sums = [sum(row) for row in grid]
col_sums = [sum(grid[i][j] for i in range(n)) for j in range(n)]
diag1_sum = sum(grid[i][i] for i in range(n))
diag2_sum = sum(grid[i][n-i-1] for i in range(n))
all_sums = row_sums + col_sums... | from solution import main
def test_case_1():
input_str = "2\n3\n8 1 6\n3 5 7\n4 9 2\n5\n17 24 1 8 15\n23 5 7 14 16\n4 6 13 20 22\n10 12 19 21 3\n11 18 25 2 9"
expected_output = "YES\nYES"
assert main(input_str) == expected_output
def test_case_2():
input_str = "1\n3\n1 2 3\n4 5 6\n7 8 9"
expected_... | [
{
"docstring": null,
"function_declaration": "def is_magic_square(grid, n):",
"function_name": "is_magic_square",
"parameter_list": "(grid, n)"
},
{
"docstring": null,
"function_declaration": "def can_form_magic_square(grids):",
"function_name": "can_form_magic_square",
"paramete... | [
0,
0,
0,
0,
0,
0,
0,
0,
1,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_magic_square(matrix):\n \"\"\"\n Check if the given matrix is a magic square.\n \"\"\"\n n = len(matrix)\n magic_sum = sum(matrix[0])\n \n... | trial_gpt4o_8 | {
"original_instruction": "You are given a square grid of size $n \\times n$, where $n$ is an odd integer. Each cell in the grid contains a unique integer from $1$ to $n^2$.\n\nYour task is to create a magic square using the given grid. In a magic square, the sum of the integers in each row, each column, and the two ... | 0.565314 | Taco_19312 | C | [
"is_magic_square",
"can_form_magic_square",
"process_input",
"main"
] | 4 | [
[
"can_form_magic_square",
"is_magic_square"
]
] | 1 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | 6c7865393d8c7dee99b59a36c2dca9cc21bf105b | d0d4c4a6331fa7253decc25846e41816037208ed | |||
v1.0 | complete | Taco | Taco_19474_C | def find_kth_largest(nums: List[int], k: int) -> int:
""" Given an unsorted array of integers, return the k-th largest element in the array.
Algorithms such as quickselect or max-heap can be considered to achieve the desired result efficiently.
>>> find_kth_largest([3, 2, 1, 5, 6, 4], 2) # return 5
>>>... | def partition(arr, low, high):
pivot = arr[high]
i = low - 1
for j in range(low, high):
if arr[j] > pivot:
i += 1
arr[i], arr[j] = arr[j], arr[i]
arr[i + 1], arr[high] = arr[high], arr[i + 1]
return i + 1
def quickselect(arr, low, high, k):
if low < high:
... | from solution import find_kth_largest
def test_single_element():
assert find_kth_largest([1], 1) == 1
def test_two_elements():
assert find_kth_largest([1, 2], 1) == 2
assert find_kth_largest([1, 2], 2) == 1
def test_general_case():
assert find_kth_largest([3, 2, 1, 5, 6, 4], 1) == 6
assert find_k... | [
{
"docstring": null,
"function_declaration": "def partition(arr, low, high):",
"function_name": "partition",
"parameter_list": "(arr, low, high)"
},
{
"docstring": null,
"function_declaration": "def quickselect(arr, low, high, k):",
"function_name": "quickselect",
"parameter_list... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_kth_largest(nums, k):\n \"\"\"\n Finds the k-th largest element in the array.\n \n :param nums: List[int], an unsorted array of integers\n ... | trial_gpt4o_2 | {
"original_instruction": "Given an unsorted array of integers, write a function named \"find_kth_largest\" that takes two arguments: an array of integers and an integer k, and returns the k-th largest element in the array.\n\nFor example, given the array [3, 2, 1, 5, 6, 4] and k = 2, your function should return 5. N... | 0.850933 | Taco_19474 | C | [
"partition",
"quickselect",
"find_kth_largest"
] | 3 | [
[
"find_kth_largest",
"quickselect"
],
[
"quickselect",
"partition"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 145da558a273ee48118783a76b938426bfdb07af | 8f6f60d82a9190f1f291bcbd6f35dc3e964093a9 | |||
v1.0 | complete | Taco | Taco_19064_C | def botanical_analysis(input_data: str) -> list:
"""
Given a series of lists with plant descriptions, determine the number of unique plants in each list.
Args:
input_data (str): The input data as a string.
Returns:
list: A list of integers, each representing the number of unique plants in ... | def count_unique_plants(T, plant_lists):
"""
Returns the number of unique plants for each list of plants.
Args:
T (int): The number of lists of plants to analyze.
plant_lists (list of list of tuples): Each list contains tuples representing each plant with (height, width, leaves).
Retur... | from solution import botanical_analysis
def test_case_1():
input_data = "2\n3\n3 2 5\n3 2 5\n1 4 10\n2\n0 0 0\n0 0 0"
assert botanical_analysis(input_data) == [2, 1]
def test_case_2():
input_data = "1\n4\n1 1 1\n2 2 2\n3 3 3\n4 4 4"
assert botanical_analysis(input_data) == [4]
def test_case_3():
... | [
{
"docstring": "Returns the number of unique plants for each list of plants.\n\nArgs:\nT (int): The number of lists of plants to analyze.\nplant_lists (list of list of tuples): Each list contains tuples representing each plant with (height, width, leaves).\n\nReturns:\nlist of int: Number of unique plants for e... | [
0,
1
] | 1 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def count_unique_plants(T, plant_lists):\n \"\"\"\n Given a number of lists of plants, each with height, width, and number of leaves, \n determine the num... | trial_gpt4o_1 | {
"original_instruction": "A famous botanist is cataloging a series of unique plants found in a remote region. Each plant can be described using three traits: height, width, and number of leaves. Two plants are identical if and only if all three traits are exactly the same.\n\nGiven a list of plants, write a program ... | 0.609837 | Taco_19064 | C | [
"count_unique_plants",
"botanical_analysis"
] | 2 | [
[
"botanical_analysis",
"count_unique_plants"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0cda912bf4d682338b9ddd12513ed6d5f89d3711 | 8960f484be9f3f7a294f2b5c0a3c48768bfb40cd | |||
v1.0 | complete | Taco | Taco_19453_C | def clean_string(s: str) -> str:
"""
Removes all non-alphanumeric characters from a string and converts it to lowercase.
"""
return ''.join(c.lower() for c in s if c.isalnum())
def is_palindrome(s: str) -> bool:
"""
Returns True if the cleaned string is a palindrome, ignoring spaces, punctuatio... | def clean_string(s: str) -> str:
"""
Removes all non-alphanumeric characters from a string and converts it to lowercase.
"""
return ''.join(c.lower() for c in s if c.isalnum())
def is_palindrome(s: str) -> bool:
"""
Returns True if the cleaned string is a palindrome, ignoring spaces, punctuatio... | from solution import is_palindrome, clean_string
def test_clean_string():
assert clean_string("A man, a plan, a canal, Panama!") == "amanaplanacanalpanama"
assert clean_string("Hello, World!") == "helloworld"
assert clean_string("No 'x' in Nixon") =="noxinnixon"
assert clean_string("Palindrome!") == "p... | [
{
"docstring": "Removes all non-alphanumeric characters from a string and converts it to lowercase.",
"function_declaration": "def clean_string(s):",
"function_name": "clean_string",
"parameter_list": "(s)"
},
{
"docstring": "Returns True if the cleaned string is a palindrome, ignoring space... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def clean_string(s: str) -> str:\n \"\"\"\n Removes all non-alphanumeric characters from a string and converts it to lowercase.\n \"\"\"\n return ''.jo... | trial_gpt4o_0 | {
"original_instruction": "A palindrome is a word that reads the same backward as forward. Write a function that accepts a string and returns True if the string is a palindrome, ignoring spaces, punctuation, and capitalization, and False otherwise.\n\n## Example\nFor example, if the input string is: `\"A man, a plan,... | 0.827669 | Taco_19453 | C | [
"clean_string",
"is_palindrome"
] | 2 | [
[
"is_palindrome",
"clean_string"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b47591cd8812ab68cef283858c7b1866a90cb312 | aff17a5620501c4882ebfad39d18869f2e0b1688 | |||
v1.0 | complete | Taco | Taco_19490_C | from typing import List
def restore_ip_addresses(s: str) -> List[str]:
"""
Given a string `s` that consists of only digits, return all possible valid IP addresses.
A valid IP address consists of exactly four integers, each integer is between 0 and 255, separated by single dots,
and cannot have l... | from typing import List
def is_valid_segment(segment: str) -> bool:
"""
Check if a segment is a valid IP segment.
"""
if len(segment) > 1 and segment[0] == '0':
return False
if not 0 <= int(segment) <= 255:
return False
return True
def restore_ip_addresses(s: str) -> List[str]:... | from solution import restore_ip_addresses
def test_restore_ip_addresses():
assert restore_ip_addresses("010010") == ["0.10.0.10", "0.100.1.0"]
def test_restore_ip_addresses_no_leading_zero():
assert restore_ip_addresses("25525511135") == ["255.255.11.135", "255.255.111.35"]
def test_restore_ip_addres... | [
{
"docstring": "Check if a segment is a valid IP segment.",
"function_declaration": "def is_valid_segment(segment):",
"function_name": "is_valid_segment",
"parameter_list": "(segment)"
},
{
"docstring": "Given a string `s` that consists of only digits, return all possible valid IP addresses.... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from typing import List\n\ndef is_valid_segment(segment: str) -> bool:\n \"\"\"\n Check if a segment is a valid IP segment.\n \"\"\"\n if len(segment) ... | trial_gpt4o_0 | {
"original_instruction": "Given a string `s` that consists of only digits, return all possible valid IP addresses that can be obtained by placing three dots (`.`) in the string.\n\nA valid IP address consists of exactly four integers, each integer is between `0` and `255`, separated by single dots, and cannot have l... | 0.627767 | Taco_19490 | C | [
"is_valid_segment",
"restore_ip_addresses"
] | 2 | [
[
"restore_ip_addresses",
"is_valid_segment"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | cf5221a10789d27d7051f5ec755cf87f819799a1 | 44eb4487239422807974c0e8ed24c2762e4deaf0 | |||
v1.0 | complete | Taco | Taco_19483_C | def auction_results(input_data):
"""
Reads the bids and outputs the highest bid for each item.
Each bid consists of the bidder's name, the item name, and the bid amount.
At the end of the auction, the program announces the highest bid for each item along with the bidder's name.
The functi... | def find_highest_bids(n, bids):
"""
Finds the highest bid for each item along with the bidder's name.
Parameters:
n : int : Number of bids
bids : list of tuple : List of tuples where each tuple contains:
(bidder's name, item name, bid amount)
Returns:
lis... | from solution import auction_results
def test_auction_results_example():
input_data = """5
John painting 300
Alice sculpture 500
John sculpture 700
Alice painting 250
Tom vase 400"""
expected_output = """painting 300 John
sculpture 700 John
vase 400 Tom"""
assert auction_results(input_data) == ex... | [
{
"docstring": "Finds the highest bid for each item along with the bidder's name.\n\nParameters:\nn : int : Number of bids\nbids : list of tuple : List of tuples where each tuple contains:\n (bidder's name, item name, bid amount)\n\nReturns:\nlist of tuple : List of tuples where each tuple... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_highest_bids(bids):\n \"\"\"\n Returns the highest bid for each item along with the bidder's name.\n \"\"\"\n highest_bids = {}\n \n for... | trial_gpt4o_2 | {
"original_instruction": "A charity organization is hosting an auction where bidders can place bids on items. Each bid consists of the bidder's name, the item name, and the bid amount. At the end of the auction, the organization wants to announce the highest bid for each item along with the bidder's name.\n\nWrite a... | 0.55205 | Taco_19483 | C | [
"find_highest_bids",
"auction_results"
] | 2 | [
[
"auction_results",
"find_highest_bids"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c7c0e2bcee90ea3d68638faad8e60cda8135d3fa | df19716788abd303d85823e1fedc69bcebb54b9b | |||
v1.0 | complete | Taco | Taco_18942_C | import math
from typing import List, Union
def is_prime(num: int) -> bool:
""" Check if a number is a prime number.
>>> is_prime(2)
True
>>> is_prime(3)
True
>>> is_prime(4)
False
>>> is_prime(5)
True
>>> is_prime(9)
False
"""
pass
def prime_factors(n: int) -> List[... | import math
def is_prime(num):
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 False
i += 6
return True
def prime_factors... | def test_is_prime():
assert is_prime(2)
assert is_prime(3)
assert not is_prime(4)
assert is_prime(5)
assert not is_prime(9)
def test_prime_factors():
assert prime_factors(10) == [2, 5]
assert prime_factors(18) == [2, 3, 3]
assert prime_factors(30) == [2, 3, 5]
def test_find_two_sets():... | [
{
"docstring": null,
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def prime_factors(n):",
"function_name": "prime_factors",
"parameter_list": "(n)"
},
{
"docstring": n... | [
1,
0
] | 1 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef is_prime(num):\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 == 0 or num % 3 == 0:\n ret... | trial_gpt4o_0 | {
"original_instruction": "In a distant city called Numerica, every year, the city holds a grand number-guessing festival. In this festival, contestants are given a number and they must guess the numbers that, when combined using multiplication, equal the given number. Specifically, the festival has a unique twist. C... | 0.705182 | Taco_18942 | C | [
"is_prime",
"prime_factors",
"find_two_sets",
"solve",
"number_guessing_festival"
] | 5 | [
[
"find_two_sets",
"prime_factors"
],
[
"number_guessing_festival",
"solve"
],
[
"solve",
"find_two_sets"
]
] | 3 | [] | false | [] | false | pytest | false | [] | true | bbb52ce50e54e3eb7b823edcde978377ac6e78e8 | 82de33c0270371c4fea3ea292a42b405cd4f2cc9 | |||
v1.0 | complete | Taco | Taco_19448_C | def process_robot_commands(commands):
"""
Processes a list of robot commands and returns the final position of the robotic arm.
:param commands: List of command strings
:return: Tuple (x, y) representing the final coordinates on the cartesian plane.
>>> process_robot_commands(["MOVE_X 10",... | def process_robot_commands(commands):
"""
Processes a list of robot commands and returns the final position of the robotic arm.
:param commands: List of command strings
:return: Tuple (x, y) representing the final coordinates on the cartesian plane.
"""
x, y = 0, 0 # Starting at the origin... | from solution import process_robot_commands, read_input_to_process
def test_process_robot_commands():
assert process_robot_commands(["MOVE_X 10", "MOVE_Y 5", "POSITION 3 7", "MOVE_X -4"]) == (-1, 7)
assert process_robot_commands(["MOVE_X 12", "MOVE_Y 8", "POSITION 1 -3"]) == (1, -3)
assert process_robot_co... | [
{
"docstring": "Processes a list of robot commands and returns the final position of the robotic arm.\n\n:param commands: List of command strings\n:return: Tuple (x, y) representing the final coordinates on the cartesian plane.",
"function_declaration": "def process_robot_commands(commands):",
"function... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def control_robotic_arm(commands):\n \"\"\"\n Computes the final position of the robotic arm after processing a series of commands.\n \n :param command... | trial_gpt4o_2 | {
"original_instruction": "In the world of competitive programming, you often have to deal with numerical constraints and optimization problems. One such problem presented to you is to achieve precise control over robotic arms in a factory setting. The robotic arms need to reach specific coordinates in a 2D plane to ... | 0.500029 | Taco_19448 | C | [
"process_robot_commands",
"read_input_to_process"
] | 2 | [
[
"read_input_to_process",
"process_robot_commands"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7e416b27ee84abc86b51d8e1ba5697108510c035 | 2cb00cdfdf009d09a45743830ac414ecf7bd0af2 | |||
v1.0 | complete | Taco | Taco_19686_C | def max_non_overlapping_tasks_from_input(N, task_list):
"""
Returns the maximum number of non-overlapping tasks that can be completed.
Parameters:
N (int): Number of tasks.
task_list (list of tuples): List of tuples where each tuple contains two integers
repres... | def max_non_overlapping_tasks(tasks):
"""
Returns the maximum number of non-overlapping tasks that can be completed.
Parameters:
tasks (list of tuples): A list where each tuple contains two integers
representing the start and end times of a task.
... | import pytest
from solution import max_non_overlapping_tasks_from_input
def test_example_case():
N = 3
tasks = [(1, 3), (2, 5), (4, 6)]
assert max_non_overlapping_tasks_from_input(N, tasks) == 2
def test_no_task_case():
N = 0
tasks = []
assert max_non_overlapping_tasks_from_input(N, tasks) == ... | [
{
"docstring": "Returns the maximum number of non-overlapping tasks that can be completed.\n\nParameters:\ntasks (list of tuples): A list where each tuple contains two integers \n representing the start and end times of a task.\n \nReturns:\nint: The maximum number ... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_non_overlapping_tasks(tasks):\n \"\"\"\n Returns the maximum number of non-overlapping tasks that can be completed.\n \n Parameters:\n tasks... | trial_gpt4o_0 | {
"original_instruction": "You have N (1 ≤ N ≤ 200,000) tasks in a to-do list. Each task i is described by a pair of integers (Si, Ei) where Si is the start time and Ei is the end time of the task. Your goal is to select the maximum number of tasks that you can complete without any overlaps in their times. A task can... | 0.589389 | Taco_19686 | C | [
"max_non_overlapping_tasks",
"max_non_overlapping_tasks_from_input"
] | 2 | [
[
"max_non_overlapping_tasks_from_input",
"max_non_overlapping_tasks"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 41a089db54e68e277dc4378a36ab8b00d8aa20bf | 6f70d3282fb34dc2537eb871e8b269c835b29d58 | |||
v1.0 | complete | Taco | Taco_19572_C | from typing import List, Tuple
def largest_clique_size(N: int, edges: List[Tuple[int, int]]) -> int:
"""Returns the size of the largest clique in the graph with N nodes and given edges.
>>> largest_clique_size(5, [(1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)])
4
>>> largest_clique_size(4, [])
1
... | from itertools import combinations
def is_clique(graph, nodes):
"""Helper function to verify if a given set of nodes forms a clique."""
for u, v in combinations(nodes, 2):
if v not in graph[u]:
return False
return True
def largest_clique_size(N, edges):
"""Returns the size of the l... | from solution import largest_clique_size
def test_sample_input():
N = 5
edges = [(1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)]
assert largest_clique_size(N, edges) == 4
def test_no_edges():
N = 4
edges = []
assert largest_clique_size(N, edges) == 1
def test_disjoint_cliques():
N = 6
... | [
{
"docstring": "Helper function to verify if a given set of nodes forms a clique.",
"function_declaration": "def is_clique(graph, nodes):",
"function_name": "is_clique",
"parameter_list": "(graph, nodes)"
},
{
"docstring": "Returns the size of the largest clique in the graph with N nodes and... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from itertools import combinations\n\ndef largest_clique_size(n, edges):\n \"\"\"\n Returns the size of the largest clique in an undirected graph with n node... | trial_gpt4o_2 | {
"original_instruction": "Given an undirected graph G with N nodes and M edges, find the size of the largest clique in this graph.\nA clique is a subset of nodes such that there is an edge between any two distinct nodes in this subset.\n\n-----Constraints-----\n- 1 <= N <= 100\n- 0 <= M <= N*(N-1)/2\n- 1 <= u_i, ... | 0.548511 | Taco_19572 | C | [
"is_clique",
"largest_clique_size",
"read_input"
] | 3 | [
[
"largest_clique_size",
"is_clique"
]
] | 1 | [
"read_input"
] | false | [] | false | pytest | true | [] | true | c36a19b5100245fa23f203a73dedf18183f0b5b9 | 2f708c7c847683241ddc0b2b1f4abd84a26fe9d5 | |||
v1.0 | complete | Taco | Taco_19574_C | def calculate_final_scores(participants):
""" Calculate the final scores for each participant.
Parameters:
participants (List[Tuple[int, List[int], List[int], List[int]]]): List of tuples where each tuple represents a participant.
- The first element of the tuple is the number of problems (N).
... | def calculate_final_scores(participants):
final_scores = []
for participant in participants:
N, scores, results, times = participant
total_score = 0
total_penalty = 0
for i in range(N):
if results[i] == 1:
total_score += scores[i]
... | from solution import calculate_final_scores, parse_input
def test_calculate_final_scores():
participants = [
(3, [100, 200, 150], [1, 0, 1], [120, 0, 75]),
(2, [50, 50], [1, 1], [30, 45]),
]
expected = [55, 25]
assert calculate_final_scores(participants) == expected
def test_parse_inpu... | [
{
"docstring": null,
"function_declaration": "def calculate_final_scores(participants):",
"function_name": "calculate_final_scores",
"parameter_list": "(participants)"
},
{
"docstring": null,
"function_declaration": "def parse_input(input_string):",
"function_name": "parse_input",
... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def calculate_final_scores(participants_data):\n \"\"\"\n Calculate the final scores for participants based on their problem-solving\n accuracy and time p... | trial_gpt4o_2 | {
"original_instruction": "Paula is organizing a coding competition and needs your help to automate the scoring of the participants. Each participant is required to solve a set of problems and should be scored based on the correctness of their solutions and the time they took to complete each problem. \n\nThe scoring... | 0.672437 | Taco_19574 | C | [
"calculate_final_scores",
"parse_input",
"run"
] | 3 | [
[
"run",
"calculate_final_scores"
],
[
"run",
"parse_input"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 4fb516ac53d3d59aa4aa47002ffde9806c230af3 | 60d6b93facd7007200797e02a9ec2c6e26795416 | |||
v1.0 | complete | Taco | Taco_19418_C | from typing import List, Tuple
def fibonacci(n: int) -> int:
"""
Calculate the Fibonacci number F(n).
Uses iterative approach for efficiency.
"""
pass
def process_queries(arr: List[int], queries: List[Tuple[int, int]]) -> List[int]:
"""
Process a list of queries on the array.
Each quer... | def fibonacci(n):
"""
Calculate the Fibonacci number F(n).
Uses iterative approach for efficiency.
"""
fib = [0, 1]
for i in range(2, n + 1):
fib.append(fib[-1] + fib[-2])
return fib[n]
def process_queries(arr, queries):
fib_cache = {i: fibonacci(i) for i in range(... | def test_fibonacci():
assert fibonacci(0) == 0
assert fibonacci(1) == 1
assert fibonacci(2) == 1
assert fibonacci(3) == 2
assert fibonacci(10) == 55
assert fibonacci(30) == 832040
def test_process_queries():
arr = [1, 2, 3, 4, 5]
queries = [(1, 3), (2, 5)]
assert process_queries(arr... | [
{
"docstring": "Calculate the Fibonacci number F(n).\nUses iterative approach for efficiency.",
"function_declaration": "def fibonacci(n):",
"function_name": "fibonacci",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def process_queries(arr, queries):",
"fu... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def fibonacci(n):\n \"\"\"\n Calculate the Fibonacci number F(n).\n Uses iterative approach for efficiency.\n \"\"\"\n fib = [0, 1]\n \n for i... | trial_gpt4o_0 | {
"original_instruction": "You are given an integer array A of size N. Your task is to process Q queries on this array. Each query consists of two integers L and R, and asks for the sum of the Fibonacci numbers from the subarray A[L:R].\n\nThe Fibonacci number for an integer X is defined as follows:\n- F(0) = 0\n- F(... | 0.679458 | Taco_19418 | C | [
"fibonacci",
"process_queries",
"fibonacci_queries"
] | 3 | [
[
"fibonacci_queries",
"process_queries"
],
[
"process_queries",
"fibonacci"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | false | [] | true | 792186eec8ef04e0d1a55e06a541c5ae49ac7ab7 | 91ccfc7764ee01c1aeb2b296db13956f17d236a6 | |||
v1.0 | complete | Taco | Taco_20034_C | def findSmallestNumber(n: int) -> int:
"""
Find the smallest integer m such that the sum of digits of m is equal to n
and m is greater than or equal to n. If such a number does not exist, return -1.
Example:
>>> findSmallestNumber(10)
19
>>> findSmallestNumber(5)
5
>>> findSmallestN... | def sum_of_digits(x):
"""
Calculate the sum of digits of the integer x.
"""
return sum(int(digit) for digit in str(x))
def findSmallestNumber(n):
"""
Find the smallest integer m such that the sum of the digits of m is equal to n
and m is greater than or equal to n. If no such number exists... | def test_findSmallestNumber_n10():
assert findSmallestNumber(10) == 19
def test_findSmallestNumber_n5():
assert findSmallestNumber(5) == 5
def test_findSmallestNumber_n27():
assert findSmallestNumber(27) == 999
def test_findSmallestNumber_n18():
assert findSmallestNumber(18) == 99
def test_findSmall... | [
{
"docstring": "Calculate the sum of digits of the integer x.",
"function_declaration": "def sum_of_digits(x):",
"function_name": "sum_of_digits",
"parameter_list": "(x)"
},
{
"docstring": "Find the smallest integer m such that the sum of the digits of m is equal to n \nand m is greater than... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def sum_of_digits(x):\n \"\"\"\n Calculate the sum of digits of the integer x.\n \"\"\"\n return sum(int(digit) for digit in str(x))\n\ndef findSmalles... | trial_gpt4o_0 | {
"original_instruction": "You are given an integer `n`. You need to find the smallest integer `m` such that the sum of digits of `m` is equal to `n` and `m` is greater than or equal to `n`. If such a number does not exist, return -1. Write a function `findSmallestNumber()` that takes the integer `n` as input and ret... | 0.678842 | Taco_20034 | C | [
"sum_of_digits",
"findSmallestNumber"
] | 2 | [
[
"findSmallestNumber",
"sum_of_digits"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 7d4fcdc251d9d2116006fb5e5224e9d3ed74ae35 | 74c42ad788d030ea78c3ff35cb0c6f2c82ff33b2 | |||
v1.0 | complete | Taco | Taco_20093_C | def largest_crop_rectangle(m: int, n: int, croppos: List[Tuple[int, int]]) -> int:
""" Returns the area of the largest rectangle consisting entirely of crops.
Args:
m (int): Number of rows in the grid.
n (int): Number of columns in the grid.
croppos (List[Tuple[int, int]]): List of tuples conta... | def largest_crop_rectangle(m, n, croppos):
"""
Returns the area of the largest rectangle consisting of only crops.
"""
grid = [[0] * n for _ in range(m)]
for r, c in croppos:
grid[r][c] = 1
max_area = 0
dp = [0] * n
for i in range(m):
for j in range(n):
if g... | from solution import largest_crop_rectangle
def test_case_1():
assert largest_crop_rectangle(5, 5, [(1, 1), (1, 2), (2, 1), (2, 2), (3, 1), (3, 3)]) == 4
def test_case_2():
assert largest_crop_rectangle(4, 4, [(0, 0), (1, 1), (2, 1), (2, 3), (3, 1), (3, 2), (3, 3)]) == 3
def test_case_3():
assert largest... | [
{
"docstring": "Returns the area of the largest rectangle consisting of only crops.",
"function_declaration": "def largest_crop_rectangle(m, n, croppos):",
"function_name": "largest_crop_rectangle",
"parameter_list": "(m, n, croppos)"
},
{
"docstring": null,
"function_declaration": "def ... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def largest_crop_rectangle(m, n, crops):\n \"\"\"\n Finds the largest rectangle within the grid that consists entirely of crops.\n :param m: Number of row... | trial_gpt4o_2 | {
"original_instruction": "Farmer John has a unique way of planting his crops in a grid. The grid is of size m x n, where each cell can either be empty or contain a crop. The crops are planted on specific positions provided by their coordinates. The challenge for Farmer John is to find the largest rectangle within th... | 0.676891 | Taco_20093 | C | [
"largest_crop_rectangle",
"largest_histogram_area"
] | 2 | [
[
"largest_crop_rectangle",
"largest_histogram_area"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 477a43e9a08fe3af2ec4c54930a7e4b579f71348 | ee32e1272bfce88db3e55d4d79dee888f20b213a | |||
v1.0 | complete | Taco | Taco_19919_C | def sum_of_digits(n):
"""
Given a non-negative integer, return the sum of its digits.
If the sum is a single digit, keep it as is.
If the sum has multiple digits, repeat the process until you get a single-digit sum.
>>> sum_of_digits(123) == 6
>>> sum_of_digits(456) == 6
>>> sum_of_digi... | def sum_of_digits(n):
while n >= 10:
n = sum(int(digit) for digit in str(n))
return n
def replace_with_digit_sum(lst):
"""
Given a list of integers, return a new list where each integer is replaced
with the sum of its digits. If the sum is a single digit, keep it as is.
If the sum has m... | from solution import replace_with_digit_sum, sum_of_digits
def test_sum_of_digits():
assert sum_of_digits(123) == 6
assert sum_of_digits(456) == 6
assert sum_of_digits(789) == 6
assert sum_of_digits(15) == 6
assert sum_of_digits(5) == 5
assert sum_of_digits(9999) == 9
def test_replace_with_dig... | [
{
"docstring": null,
"function_declaration": "def sum_of_digits(n):",
"function_name": "sum_of_digits",
"parameter_list": "(n)"
},
{
"docstring": "Given a list of integers, return a new list where each integer is replaced\nwith the sum of its digits. If the sum is a single digit, keep it as ... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def sum_of_digits(n):\n \"\"\"\n Calculate the sum of digits of a number until the sum is a single digit.\n \"\"\"\n while n >= 10:\n n = sum(in... | trial_gpt4o_2 | {
"original_instruction": "Given a list of integers, return a new list where each integer is replaced with the sum of its digits. If the sum is a single digit, keep it as is. If the sum has multiple digits, repeat the process until you get a single-digit sum.\n\nExample input:\n\n```\n[123, 456, 789, 15]\n```\n\nExpe... | 0.736411 | Taco_19919 | C | [
"sum_of_digits",
"replace_with_digit_sum"
] | 2 | [
[
"replace_with_digit_sum",
"sum_of_digits"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 743e1a54454756a5747d5c66fc7b137c64a2ea56 | ed65e05818e3489ee2a483fe96a832c700db69a6 | |||
v1.0 | complete | Taco | Taco_20062_C | def is_divisible_by_3(digits: str) -> str:
"""
Determines if the sum of the digits of a number is divisible by 3
:param digits: string representing the digits of the number
:return: "YES" if the sum of digits is divisible by 3, otherwise "NO"
>>> is_divisible_by_3("102")
'YES'
>>> is_di... | def is_divisible_by_3(digits):
"""
Determines if the sum of the digits of a number is divisible by 3
:param digits: string representing the digits of the number
:return: "YES" if the sum of digits is divisible by 3, otherwise "NO"
"""
total = sum(int(digit) for digit in digits)
return "YES" ... | import pytest
from solution import analyze_numbers, is_divisible_by_3
def test_is_divisible_by_3():
assert is_divisible_by_3("102") == "YES"
assert is_divisible_by_3("123") == "YES"
assert is_divisible_by_3("111") == "YES"
assert is_divisible_by_3("456") == "YES"
assert is_divisible_by_3("789") == ... | [
{
"docstring": "Determines if the sum of the digits of a number is divisible by 3\n:param digits: string representing the digits of the number\n:return: \"YES\" if the sum of digits is divisible by 3, otherwise \"NO\"",
"function_declaration": "def is_divisible_by_3(digits):",
"function_name": "is_divis... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_rearrangeable_divisible_by_3(s):\n \"\"\"\n Check if the digits of the string can be rearranged to form a number divisible by 3.\n \n :param s: ... | trial_gpt4o_1 | {
"original_instruction": "During a series of attempts to crack a mysterious code, you discovered an interesting pattern on an ancient encrypted tablet. The pattern is described as follows: There is a sequence of numbers, and for each number, you are to determine if it is possible to rearrange its digits such that th... | 0.639654 | Taco_20062 | C | [
"is_divisible_by_3",
"analyze_numbers"
] | 2 | [
[
"analyze_numbers",
"is_divisible_by_3"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | bbac29a61ffb4c69fb8766af4cfdad42754aa176 | 170fc01eb3c65d7a58964b7452a4425f8bdc9dd2 | |||
v1.0 | complete | Taco | Taco_20086_C | from typing import List, Tuple
def battleship_tracker(ships: List[Tuple[int, int, int, int]], queries: List[Tuple[int, int]]) -> List[str]:
""" Determine for each query point if it lies on any ship's line segment.
Args:
ships: A list of tuples where each tuple contains four integers x1, y1, x2, y2 represe... | def is_point_on_ship(x1, y1, x2, y2, qx, qy):
"""
Helper function to determine if the point (qx, qy) lies on the ship
defined by the line segment from (x1, y1) to (x2, y2).
"""
if x1 == x2: # Vertical ship
return x1 == qx and min(y1, y2) <= qy <= max(y1, y2)
else: # Horizontal ship
... | from solution import battleship_tracker
def test_battleship_tracker_example1():
ships = [(0, 0, 3, 0), (1, -1, 1, 2), (-2, 2, 2, 2)]
queries = [(0, 0), (1, 0), (1, 1), (4, 2)]
assert battleship_tracker(ships, queries) == ["YES", "YES", "YES", "NO"]
def test_battleship_tracker_example2():
ships = [(1, ... | [
{
"docstring": "Helper function to determine if the point (qx, qy) lies on the ship\ndefined by the line segment from (x1, y1) to (x2, y2).",
"function_declaration": "def is_point_on_ship(x1, y1, x2, y2, qx, qy):",
"function_name": "is_point_on_ship",
"parameter_list": "(x1, y1, x2, y2, qx, qy)"
}... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_point_on_ship(x1, y1, x2, y2, qx, qy):\n \"\"\"\n Determine if the point (qx, qy) lies on the ship defined by (x1, y1) to (x2, y2).\n \"\"\"\n #... | trial_gpt4o_1 | {
"original_instruction": "T: Battle Ship Tracker / Can You Find The Position?\n\nStory\n\nCaptain S of a powerful naval fleet always tests the skills of his crew by hiding ships in a Cartesian coordinate system. The ships are represented as vertical or horizontal line segments and the crew has to accurately determin... | 0.544921 | Taco_20086 | C | [
"is_point_on_ship",
"battleship_tracker"
] | 2 | [
[
"battleship_tracker",
"is_point_on_ship"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 861f3cb64b486d2c50e5b80ff5be5b51cd31d400 | 3730bb3c59b81242a98ce97b84c1d8d873a665bb | |||
v1.0 | complete | Taco | Taco_20242_C | def is_palindrome(s: str) -> str:
""" Returns "YES" if the string is a palindrome, otherwise returns "NO".
>>> is_palindrome("level") == "YES"
True
>>> is_palindrome("hello") == "NO"
True
>>> is_palindrome("racecar") == "YES"
True
>>> is_palindrome("abcba") == "YES"
True
>>> is_p... | def is_palindrome(s: str) -> str:
"""
Returns "YES" if the string is a palindrome, otherwise returns "NO".
"""
if s == s[::-1]:
return "YES"
return "NO"
def check_palindromes(strings):
return [is_palindrome(s) for s in strings] | from solution import is_palindrome, check_palindromes
def test_is_palindrome():
assert is_palindrome("level") == "YES"
assert is_palindrome("hello") == "NO"
assert is_palindrome("racecar") == "YES"
assert is_palindrome("abcba") == "YES"
assert is_palindrome("world") == "NO"
assert is_palindrome... | [
{
"docstring": "Returns \"YES\" if the string is a palindrome, otherwise returns \"NO\".",
"function_declaration": "def is_palindrome(s):",
"function_name": "is_palindrome",
"parameter_list": "(s)"
},
{
"docstring": null,
"function_declaration": "def check_palindromes(strings):",
"fu... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome(s):\n \"\"\"\n Checks if a string s is a palindrome.\n \"\"\"\n return s == s[::-1]\n\ndef check_palindromes(strings):\n \"\"\"\n ... | trial_gpt4o_2 | {
"original_instruction": "Tom loves palindromes. A palindrome is a string that reads the same forward and backward. For example, \"level\" and \"racecar\" are palindromes. Tom has a list of N strings, and he would like to know how many of them are palindromes. Can you help him determine this?\n\n-----Input-----\nThe... | 0.860936 | Taco_20242 | C | [
"is_palindrome",
"check_palindromes"
] | 2 | [
[
"check_palindromes",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 80624abdea0278b94b80f2b0f1ccffdfee33a822 | fb83320cc01964567d84d63312e876ade4c7e991 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.