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_82459_C | def find_largest_empty_square(n: int, m: int, grid_lines: List[str]) -> int:
"""
You are given a rectilinear grid where each cell can either be empty or contain an obstacle.
You need to find the largest empty square sub-grid within this grid. The empty square sub-grid
is a contiguous block of cells, a... | def largest_empty_square(grid):
if not grid:
return 0
n = len(grid)
m = len(grid[0])
# Create a DP table with the same dimensions as the grid
dp = [[0]*m for _ in range(n)]
max_side = 0
# Fill the DP table
for i in range(n):
for j in range(m):
i... | def test_example_1():
n = 5
m = 5
grid = [
"1 0 1 0 0",
"1 0 0 1 0",
"1 0 0 0 0",
"0 1 0 0 1",
"0 0 0 1 0"
]
assert find_largest_empty_square(n, m, grid) == 2
def test_example_2():
n = 3
m = 3
grid = [
"1 1 1",
"1 0 0",
"1 ... | [
{
"docstring": null,
"function_declaration": "def largest_empty_square(grid):",
"function_name": "largest_empty_square",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def find_largest_empty_square(n, m, grid_lines):",
"function_name": "find_largest_empty... | [
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 largest_empty_square(grid):\n if not grid:\n return 0\n n = len(grid)\n m = len(grid[0])\n \n # Create a DP table with the same dimension... | trial_gpt4o_0 | {
"original_instruction": "You are given a rectilinear grid where each cell can either be empty or contain an obstacle. You need to find the largest empty square sub-grid within this grid. The empty square sub-grid is a contiguous block of cells, all of which are empty.\n\nThe grid is represented by a 2D array of int... | 0.673541 | Taco_82459 | C | [
"largest_empty_square",
"find_largest_empty_square"
] | 2 | [
[
"find_largest_empty_square",
"largest_empty_square"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 363992b8d9999a009f19464311a7b6e538335800 | 8f5f10cbbc72e75e09f1851a52e478f50199ad51 | |||
v1.0 | complete | Taco | Taco_82678_C | def sieve(n: int) -> List[int]:
"""
Returns a list of prime numbers up to n using the Sieve of Eratosthenes.
>> sieve(10) == [2, 3, 5, 7]
"""
pass
def sum_of_primes_in_range(L: int, R: int) -> int:
"""
Finds the sum of prime numbers in the range [L, R].
>> sum_of_primes_in_range(1, 10) ... | import itertools
def sieve(n):
"""
Returns a list of prime numbers up to n using the Sieve of Eratosthenes.
"""
is_prime = [True] * (n+1)
p = 2
while (p * p <= n):
if (is_prime[p] == True):
for i in range(p * p, n+1, p):
is_prime[i] = False
p += 1
... | from solution import sum_of_primes_in_range, solve
def test_sum_of_primes_in_range():
assert sum_of_primes_in_range(1, 10) == 17
assert sum_of_primes_in_range(11, 20) == 60
assert sum_of_primes_in_range(21, 30) == 52
assert sum_of_primes_in_range(1, 1) == 0
assert sum_of_primes_in_range(0, 2) == 2
... | [
{
"docstring": "Returns a list of prime numbers up to n using the Sieve of Eratosthenes.",
"function_declaration": "def sieve(n):",
"function_name": "sieve",
"parameter_list": "(n)"
},
{
"docstring": "Finds the sum of prime numbers in the range [L, R].",
"function_declaration": "def sum_... | [
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 sieve_of_eratosthenes(max_num):\n \"\"\" Helper function to generate a list of primes up to max_num using the Sieve of Eratosthenes \"\"\"\n is_prime = [... | trial_gpt4o_2 | {
"original_instruction": "Ibrahim has just started learning about prime numbers and their importance in various algorithms and cryptographic applications. As part of his learning journey, he wants to determine the sum of prime numbers within a given range. However, he is struggling with an efficient way to compute t... | 0.664582 | Taco_82678 | C | [
"sieve",
"sum_of_primes_in_range",
"solve"
] | 3 | [
[
"solve",
"sum_of_primes_in_range"
],
[
"sum_of_primes_in_range",
"sieve"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 7156329a62cbd1d15d145412e7ac590ea58ed1b5 | 40c79b4af93c21d57f44c454f05c51a74f3bcc74 | |||
v1.0 | complete | Taco | Taco_82573_C | def count_valid_words(m: int, n: int, grid: List[str], k: int, words: List[str]) -> int:
"""
Check if each word in the list can be formed by a sequence of adjacent cells in the grid.
Each cell in the grid is adjacent horizontally or vertically.
A cell can only be used once per word.
Args:
... | def word_exists(grid, word, m, n):
def dfs(x, y, pos):
if pos == len(word):
return True
if x < 0 or x >= m or y < 0 or y >= n or word[pos] != grid[x][y]:
return False
tmp, grid[x][y] = grid[x][y], '#'
found = (dfs(x + 1, y, pos + 1) or
dfs(x -... | from solution import count_valid_words
def test_example_case_1():
m, n = 3, 4
grid = ["a b c e", "s f c s", "a d e e"]
k = 2
words = ["abcced", "see"]
assert count_valid_words(m, n, grid, k, words) == 2
def test_example_case_2():
m, n = 2, 2
grid = ["a b", "c d"]
k = 3
words = ["ab... | [
{
"docstring": null,
"function_declaration": "def word_exists(grid, word, m, n):",
"function_name": "word_exists",
"parameter_list": "(grid, word, m, n)"
},
{
"docstring": null,
"function_declaration": "def count_valid_words(m, n, grid, k, words):",
"function_name": "count_valid_word... | [
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 word_exists(grid, word, m, n):\n def dfs(x, y, pos):\n if pos == len(word):\n return True\n if x < 0 or x >= m or y < 0 or y >= n o... | trial_gpt4o_0 | {
"original_instruction": "Problem:\n\nYou are given a grid with m rows and n columns. Each cell in the grid contains a single lowercase alphabet letter. You are also given a list of k words. Your task is to implement a function that checks if each word in the list can be formed by a sequence of adjacent cells in the... | 0.65524 | Taco_82573 | C | [
"word_exists",
"count_valid_words"
] | 2 | [
[
"count_valid_words",
"word_exists"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 3ee85a8890df3611d791419d24d99b4ee3d07bc1 | f849a27d045b2d193c48e8bf5594359176f8bae0 | |||
v1.0 | complete | Taco | Taco_82607_C | import sys
import math
import heapq
def calculate_distance(p1, p2):
""" Calculate the Euclidean distance between two points.
>>> calculate_distance((0, 0), (1, 1))
1.414214
"""
pass
def prim_mst(points):
""" Create the Minimum Spanning Tree (MST) using Prim's algorithm and calculate its total ... | import sys
import math
import heapq
def calculate_distance(p1, p2):
return math.sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2)
def prim_mst(points):
N = len(points)
if N == 0:
return 0.0
in_mst = [False] * N
min_edge = [(0, 0)]
total_length = 0.0
edges_count = 0
... | import os
import sys
from io import StringIO
def test_case_1(monkeypatch):
input_data = """4
0 0
0 1
1 0
1 1
3
0 0
2 2
3 3
0
"""
expected_output = "3.000000\n4.242641\n"
monkeypatch.setattr(sys, 'stdin', StringIO(input_data))
monkeypatch.setattr(sys, 'stdout', buffer := StringIO())
from solut... | [
{
"docstring": null,
"function_declaration": "def calculate_distance(p1, p2):",
"function_name": "calculate_distance",
"parameter_list": "(p1, p2)"
},
{
"docstring": null,
"function_declaration": "def prim_mst(points):",
"function_name": "prim_mst",
"parameter_list": "(points)"
... | [
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\nfrom heapq import heappop, heappush\n\ndef calculate_distance(x1, y1, x2, y2):\n \"\"\"Calculate Euclidean distance between two points.\"\"\"\n ... | trial_gpt4o_2 | {
"original_instruction": "In a kingdom far away, there existed a dense enchanted forest where magical creatures lived in harmony. The forest was divided into various regions marked by unique trees called \"root nodes.\" These trees served as the central points of magical energy that protected the regions from extern... | 0.552709 | Taco_82607 | C | [
"calculate_distance",
"prim_mst",
"solve"
] | 3 | [
[
"prim_mst",
"calculate_distance"
],
[
"solve",
"prim_mst"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 9f53d4d04c48ffc0659f3e021e12fbb95cf5bb0f | 4b1d10824e61052890084225c83f0020d347bed5 | |||
v1.0 | complete | Taco | Taco_82741_C | def count_primes_in_ranges(ranges):
""" Count the number of prime numbers within the specified range [a, b] for each pair in ranges.
>>> count_primes_in_ranges([(1, 10)]) == [4]
>>> count_primes_in_ranges([(1, 10), (10, 20)]) == [4, 4]
>>> count_primes_in_ranges([(1, 100)]) == [25]
>>> count_primes_... | def sieve_of_eratosthenes(max_num):
is_prime = [True] * (max_num + 1)
is_prime[0] = is_prime[1] = False
p = 2
while (p * p <= max_num):
if (is_prime[p] == True):
for i in range(p * p, max_num + 1, p):
is_prime[i] = False
p += 1
return is_prime
def count_p... | from solution import count_primes_in_ranges
def test_single_range():
assert count_primes_in_ranges([(1, 10)]) == [4]
def test_multiple_ranges():
assert count_primes_in_ranges([(1, 10), (10, 20)]) == [4, 4]
def test_large_range():
assert count_primes_in_ranges([(1, 100)]) == [25] # there are 25 primes be... | [
{
"docstring": null,
"function_declaration": "def sieve_of_eratosthenes(max_num):",
"function_name": "sieve_of_eratosthenes",
"parameter_list": "(max_num)"
},
{
"docstring": null,
"function_declaration": "def count_primes_in_ranges(ranges):",
"function_name": "count_primes_in_ranges"... | [
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 count_primes_in_range(a, b):\n \"\"\"\n Counts the number of prime numbers within the range [a, b] inclusive.\n \"\"\"\n if a > b:\n a, b = ... | trial_gpt4o_2 | {
"original_instruction": "Alex is fascinated with prime numbers and primes within a range. He likes to find out how many prime numbers can be found within a specified range `[a, b]` (inclusive). Can you help him?\n\nInput Format\n\nThe first line contains an integer $\\mathbf{T}$, the number of test cases. \n\nThe n... | 0.714193 | Taco_82741 | C | [
"sieve_of_eratosthenes",
"count_primes_in_ranges"
] | 2 | [
[
"count_primes_in_ranges",
"sieve_of_eratosthenes"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 370b55240803bdbbb98d5040c5f49b3fbab25e8b | 1aed16da5f941dce996d435cb52a39b58bd774cb | |||
v1.0 | complete | Taco | Taco_82385_C | def solve(N, M, grid, Q, queries):
""" Determine if there exists a path with a specific cost from (1,1) to (x,y) for given queries.
>>> N, M = 3, 3
>>> grid = [
... [1, 2, 3],
... [4, 5, 6],
... [7, 8, 9]
... ]
>>> Q = 2
>>> queries = [
... [3, 3, 21],
... [... | def min_cost_path(grid, N, M):
dp = [[0]*M for _ in range(N)]
dp[0][0] = grid[0][0]
for i in range(1, N):
dp[i][0] = dp[i-1][0] + grid[i][0]
for j in range(1, M):
dp[0][j] = dp[0][j-1] + grid[0][j]
for i in range(1, N):
for j in range(1, M):
dp[i][j] = ... | import pytest
from solution import solve
def test_example_case():
N, M = 3, 3
grid = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
Q = 2
queries = [
[3, 3, 21],
[2, 2, 6]
]
result = solve(N, M, grid, Q, queries)
assert result == ["POSSIBLE", "IMPOSSIBLE"]
... | [
{
"docstring": null,
"function_declaration": "def min_cost_path(grid, N, M):",
"function_name": "min_cost_path",
"parameter_list": "(grid, N, M)"
},
{
"docstring": null,
"function_declaration": "def possible_path_to_cost(dp, x, y, C):",
"function_name": "possible_path_to_cost",
"... | [
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 check_paths(grid, queries):\n N = len(grid)\n M = len(grid[0])\n \n # Precompute the cost to reach each cell using dynamic programming\n dp = [[... | trial_gpt4o_4 | {
"original_instruction": "You are given a 2D grid of dimensions NxM with non-negative integers representing the cost to move through each cell. You start from the top-left cell (1,1) and want to reach the bottom-right cell (N,M). You can only move to the right or down from a cell.\n\nAdditionally, you are provided w... | 0.568502 | Taco_82385 | C | [
"min_cost_path",
"possible_path_to_cost",
"solve"
] | 3 | [
[
"solve",
"min_cost_path"
],
[
"solve",
"possible_path_to_cost"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 6967ded0fbd786cf335fd6d78a2d063364c51507 | 83c834f71b36377759ecdc32083017de2991cc46 | |||
v1.0 | complete | Taco | Taco_82604_C | def generate_summary(log_lines):
""" Generate a summary report of the events from a log.
The log entries are sorted by date and time. The input terminates with a line containing the string "END".
Args:
log_lines: A list of strings where each string is a log entry.
Returns:
... | def parse_log(log_lines):
from collections import defaultdict
from itertools import groupby
event_summary = defaultdict(lambda: defaultdict(int))
for line in log_lines:
if line.strip() == "END":
break
date, time, event_type, *event_description = line.split(maxsplit=3)
... | from solution import generate_summary
def test_generate_summary():
log_lines = [
"2023-10-01 08:23:45 LOGIN User123 logged in",
"2023-10-01 08:47:12 LOGOUT User123 logged out",
"2023-10-01 09:00:01 LOGIN User456 logged in",
"2023-10-01 10:15:05 LOGIN User789 logged in",
"202... | [
{
"docstring": null,
"function_declaration": "def parse_log(log_lines):",
"function_name": "parse_log",
"parameter_list": "(log_lines)"
},
{
"docstring": null,
"function_declaration": "def format_summary(event_summary):",
"function_name": "format_summary",
"parameter_list": "(eve... | [
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 parse_log(log):\n \"\"\"\n Parses the log file and returns a summary report.\n \"\"\"\n from collections import defaultdict\n\n event_counts = d... | trial_gpt4o_2 | {
"original_instruction": "You are given a log file consisting of multiple entries, each entry detailing an event in a system. Each entry has the format: \"YYYY-MM-DD HH:MM:SS <Event_Type> <Event_Description>\". Your task is to write a program that outputs a summary report of the events. The summary should contain th... | 0.640018 | Taco_82604 | C | [
"parse_log",
"format_summary",
"generate_summary"
] | 3 | [
[
"generate_summary",
"format_summary"
],
[
"generate_summary",
"parse_log"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 559b91d9625327adac2ff32971765794685335dc | 00084e481405207d189314bbbab3e74ce6c52374 | |||
v1.0 | complete | Taco | Taco_82634_C | from typing import List, Tuple
def min_cable_to_upgrade(n: int, m: int, edges: List[Tuple[int, int, int]]) -> int:
"""
Determine the minimum capacity of the cable that should be upgraded to optimize the data transfer between
the server with minimum capacity and the server with maximum capacity. If upgrad... | def find(parent, i):
if parent[i] == i:
return i
return find(parent, parent[i])
def union(parent, rank, x, y):
xroot = find(parent, x)
yroot = find(parent, y)
if rank[xroot] < rank[yroot]:
parent[xroot] = yroot
elif rank[xroot] > rank[yroot]:
parent[yroot] = xroot
el... | from solution import min_cable_to_upgrade
def test_basic_network():
assert min_cable_to_upgrade(5, 6, [
[1, 2, 3],
[2, 3, 2],
[3, 4, 4],
[4, 5, 6],
[1, 3, 8],
[2, 5, 5],
]) == 2
def test_single_cable():
assert min_cable_to_upgrade(2, 1, [
[1, 2, 10]
... | [
{
"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,
1,
0
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef min_key_cable_upgrade(n, m, edges):\n def dijkstra(source, target, adj, n):\n heap = [(0, source)]\n dists = [float('inf')] * ... | trial_gpt4o_3 | {
"original_instruction": "A company has a network of `n` servers connected by `m` bidirectional cables. Each cable has a bandwidth capacity. The IT team wants to determine the minimum capacity of the cable that should be upgraded to ensure that the data transfer between the server with minimum capacity and maximum c... | 0.594256 | Taco_82634 | C | [
"find",
"union",
"min_cable_to_upgrade"
] | 3 | [
[
"min_cable_to_upgrade",
"find"
],
[
"min_cable_to_upgrade",
"union"
],
[
"union",
"find"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 41a336180cb7d3e87d9e3a35f0dd5f3f009063b5 | f082120c4e30f5375560f91649afb22dcb471a4f | |||
v1.0 | complete | Taco | Taco_82847_C | def shortest_paths(n, m, edge_list, s):
"""
Determine the shortest path from a starting intersection to each other intersection.
n: int - number of intersections
m: int - number of streets
edge_list: List[Tuple[int, int, int]] - list of tuples where each tuple contains three integers u, v, w i... | import heapq
def dijkstra(n, edges, start):
"""
Returns the shortest path from the start node to all other nodes using Dijkstra's algorithm.
If a node is unreachable, the distance is marked as 'INF'.
"""
graph = [[] for _ in range(n)]
for u, v, w in edges:
graph[u-1].append((v-1, w))
... | from solution import shortest_paths
def test_example1():
n = 4
m = 4
edge_list = [(1, 2, 2), (1, 3, 4), (2, 3, 1), (3, 4, 1)]
s = 1
assert shortest_paths(n, m, edge_list, s) == [0, 2, 3, 4]
def test_example2():
n = 5
m = 3
edge_list = [(1, 2, 3), (2, 3, 2), (3, 5, 5)]
s = 4
ass... | [
{
"docstring": "Returns the shortest path from the start node to all other nodes using Dijkstra's algorithm.\nIf a node is unreachable, the distance is marked as 'INF'.",
"function_declaration": "def dijkstra(n, edges, start):",
"function_name": "dijkstra",
"parameter_list": "(n, edges, start)"
},... | [
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 heapq\n\ndef dijkstra(n, edges, s):\n \"\"\"\n Implements Dijkstra's algorithm to find shortest path from starting \n intersection `s` to all other... | trial_gpt4o_2 | {
"original_instruction": "Given a road network of a city represented as a directed graph with `n` intersections (nodes) and `m` streets (edges), we need to determine the shortest path from a starting intersection to each other intersection. Each street has a non-negative travel time. If there is no path from the sta... | 0.681075 | Taco_82847 | C | [
"dijkstra",
"shortest_paths"
] | 2 | [
[
"shortest_paths",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 1b6519a9c0abcbd9aa454ebe89f638695d2bb07f | 7a94fb8ab3b7fbfabb254e395d242cce8fe4dedb | |||
v1.0 | complete | Taco | Taco_82821_C | def max_non_overlapping_events(test_cases):
""" Given a list of events with their start and end times, find the maximum number of non-overlapping events that can be scheduled.
>>> max_non_overlapping_events([[(1, 3), (2, 5), (4, 6)]])
[2]
>>> max_non_overlapping_events([[(1, 3), (2, 5), (4, 6)], [(1, 2)... | def max_non_overlapping_events(test_cases):
results = []
for events in test_cases:
events.sort(key=lambda x: x[1])
count = 0
last_end_time = 0
for start, end in events:
if start >= last_end_time:
count += 1
last_end_time = end
... | def test_max_non_overlapping_events():
input_str = "1\n3\n1 3\n2 5\n4 6\n"
expected_output = "2"
assert solve(input_str) == expected_output
def test_max_non_overlapping_events_multiple_cases():
input_str = "2\n3\n1 3\n2 5\n4 6\n4\n1 2\n2 3\n3 4\n4 5\n"
expected_output = "2\n4"
assert solve(inpu... | [
{
"docstring": null,
"function_declaration": "def max_non_overlapping_events(test_cases):",
"function_name": "max_non_overlapping_events",
"parameter_list": "(test_cases)"
},
{
"docstring": null,
"function_declaration": "def parse_input(input_str):",
"function_name": "parse_input",
... | [
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 max_non_overlapping_events(test_cases):\n \"\"\"\n Given a list of test cases, find the maximum number of non-overlapping events that can be scheduled.\n... | trial_gpt4o_1 | {
"original_instruction": "A company is developing a software to manage events in a city park. Each event has a start time and an end time, and its schedule cannot overlap with any other event. Given a list of events, find the maximum number of non-overlapping events that can be scheduled in the park.\n\nEach event i... | 0.614415 | Taco_82821 | C | [
"max_non_overlapping_events",
"parse_input",
"solve"
] | 3 | [
[
"solve",
"max_non_overlapping_events"
],
[
"solve",
"parse_input"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | false | [] | true | ac7ee4d0bbc69a29a5e6c1c363abebc688a17a7e | bd1b5a39bbb2b973cf94c8b70383de3c399d3c11 | |||
v1.0 | complete | Taco | Taco_83041_C | import math
from typing import List
def is_perfect_square(number: int) -> bool:
""" Checks if a given number is a perfect square
>>> is_perfect_square(0)
True
>>> is_perfect_square(1)
True
>>> is_perfect_square(4)
True
"""
def has_contiguous_subarray_sum_as_perfect_square(n: int, a... | import math
def is_perfect_square(number):
"""
Checks if a given number is a perfect square
"""
if number < 0:
return False
root = math.isqrt(number)
return root * root == number
def has_contiguous_subarray_sum_as_perfect_square(n, arr):
"""
Determines if there is a contiguous ... | from solution import is_perfect_square, has_contiguous_subarray_sum_as_perfect_square
def test_is_perfect_square():
assert is_perfect_square(0) == True
assert is_perfect_square(1) == True
assert is_perfect_square(4) == True
assert is_perfect_square(9) == True
assert is_perfect_square(16) == True
... | [
{
"docstring": "Checks if a given number is a perfect square",
"function_declaration": "def is_perfect_square(number):",
"function_name": "is_perfect_square",
"parameter_list": "(number)"
},
{
"docstring": "Determines if there is a contiguous subarray with a sum that is a perfect square.",
... | [
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(number):\n \"\"\"\n Checks if a given number is a perfect square\n \"\"\"\n if number < 0:\n return False\n... | trial_gpt4o_0 | {
"original_instruction": "You are given an array containing n positive integers. Your task is to determine if there exists a contiguous subarray whose sum is a perfect square.\n\n-----Input-----\n\nThe first line of the input contains an integer n (1 ≤ n ≤ 100000) — the length of the array. \n\nThe second line conta... | 0.633117 | Taco_83041 | C | [
"is_perfect_square",
"has_contiguous_subarray_sum_as_perfect_square"
] | 2 | [
[
"has_contiguous_subarray_sum_as_perfect_square",
"is_perfect_square"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 25221b7eac8c61d6db16fd6f213e01b9a3e464df | 23f26dbfe9ea266a7bc9d8a02fe2c2f70f2068e5 | |||
v1.0 | complete | Taco | Taco_82778_C | def minimize_skill_diff(test_cases):
""" Determine the minimum possible maximum difference in skill levels within any team after organizing them optimally.
Args:
test_cases (List[Tuple[int, List[int]]]): List of test cases, each containing the number of participants and their skill levels.
Returns:
... | def minimize_skill_diff(test_cases):
results = []
for case in test_cases:
N, skills = case
skills.sort()
min_diff = float('inf')
for i in range(1, N):
min_diff = min(min_diff, skills[i] - skills[i-1])
results.append(min_diff)
return res... | from solution import minimize_skill_diff, process_input, solution
def test_minimize_skill_diff_simple_case():
testcase = [(4, [1, 4, 6, 8])]
assert minimize_skill_diff(testcase) == [2]
def test_minimize_skill_diff_multiple_cases():
testcase = [
(4, [1, 4, 6, 8]),
(5, [10, 20, 30, 40, 50])
... | [
{
"docstring": null,
"function_declaration": "def minimize_skill_diff(test_cases):",
"function_name": "minimize_skill_diff",
"parameter_list": "(test_cases)"
},
{
"docstring": null,
"function_declaration": "def process_input(input_text):",
"function_name": "process_input",
"param... | [
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 min_possible_max_diff(skill_levels):\n \"\"\"\n Determine the minimum possible maximum difference in skill levels within any team.\n \n Parameters:... | trial_gpt4o_4 | {
"original_instruction": "A company is organizing a hackathon event, and they want to distribute participants into teams efficiently. Each participant has a unique skill level, and they want to form teams such that the skill level difference among participants in the same team is minimized. You need to write a progr... | 0.644777 | Taco_82778 | C | [
"minimize_skill_diff",
"process_input",
"solution"
] | 3 | [
[
"solution",
"minimize_skill_diff"
],
[
"solution",
"process_input"
]
] | 2 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | 723171cf90485a11ed1b10a8eeb0b5e523797375 | 502f6db664afd9ae83b1b9105d57e12b8aad171c | |||
v1.0 | complete | Taco | Taco_83039_C | def find_largest_component_sizes_in_lakes(T, lake_data):
""" Find the size of the largest connected component in each lake's graph.
Args:
T (int): The number of lakes.
lake_data (list): A list where each element represents the data for a single lake. Each element is a tuple (N, M, edges) where
... | def get_largest_connected_component_size(N, edges):
from collections import defaultdict, deque
graph = defaultdict(list)
# Build graph
for u, v in edges:
graph[u].append(v)
graph[v].append(u)
visited = set()
max_size = 0
def bfs(start):
queue = deq... | import pytest
from solution import find_largest_component_sizes_in_lakes
def test_single_lake_single_component():
T = 1
lake_data = [
(5, 4, [(1, 2), (2, 3), (3, 4), (4, 5)])
]
assert find_largest_component_sizes_in_lakes(T, lake_data) == [5]
def test_single_lake_multiple_components():
T =... | [
{
"docstring": null,
"function_declaration": "def get_largest_connected_component_size(N, edges):",
"function_name": "get_largest_connected_component_size",
"parameter_list": "(N, edges)"
},
{
"docstring": null,
"function_declaration": "def find_largest_component_sizes_in_lakes(T, lake_d... | [
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 dfs(graph, node, visited):\n stack = [node]\n size = 0\n while stack:\n current = stack.pop()\n if not visited[current]:\n vi... | trial_gpt4o_2 | {
"original_instruction": "There was a fisherman who owned several lakes, and each lake was known for different types of fish he would catch. One day, he decided to design a fishing tournament for his community. The tournament rules were simple: participants had to catch different types of fish from one lake, and eac... | 0.515424 | Taco_83039 | C | [
"get_largest_connected_component_size",
"find_largest_component_sizes_in_lakes"
] | 2 | [
[
"find_largest_component_sizes_in_lakes",
"get_largest_connected_component_size"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | eb8901cfa281423ad5fd737e0b7126ed045d9b40 | b4c1517f3c88a7d2d678f2e26ccac642818509b3 | |||
v1.0 | complete | Taco | Taco_83124_C | def is_prime(num: int) -> bool:
"""
Returns True if num is a prime number, otherwise returns False.
>>> is_prime(2) True
>>> is_prime(3) True
>>> is_prime(4) False
"""
def find_primes_in_list(nums: List[int]) -> List[int]:
"""
Returns a sorted list of prime numbers from the given li... | def is_prime(num):
"""
Returns True if num is a prime number, otherwise returns False.
"""
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
r... | from solution import is_prime, find_primes_in_list
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(29) =... | [
{
"docstring": "Returns True if num is a prime number, otherwise returns False.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns a sorted list of prime numbers from the given list of integers.",
"function_de... | [
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_prime(num):\n \"\"\"\n Checks whether a number is prime or not.\n \"\"\"\n if num <= 1:\n return False\n for i in range(2, int(num**0.... | trial_gpt4o_2 | {
"original_instruction": "Emma loves numbers and is very intrigued by prime numbers. She came across a problem where she needs to check if a list of numbers contains any prime numbers. Help Emma by writing a function that takes a list of integers and returns a new list containing only the prime numbers from the orig... | 0.786141 | Taco_83124 | C | [
"is_prime",
"find_primes_in_list"
] | 2 | [
[
"find_primes_in_list",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 87c7b4cd8f6fa8b089ca1259e1fe43a252580f29 | c89f80b34caa5c11da28bbf43b8bcb7bef34c7d7 | |||
v1.0 | complete | Taco | Taco_83046_C | def goldbach_conjecture(T: int, cases: List[int]) -> List[Tuple[int, int]]:
""" The famous Goldbach Conjecture states that every even number greater than 2 can be expressed as the sum of two prime numbers. There may be multiple valid prime pairs for a given even number. This function finds such pairs.
>>> goldb... | 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 goldbach_pair(n):
for i in range(2, n)... | from solution import goldbach_conjecture
def test_goldbach_conjecture_case_10():
assert goldbach_conjecture(1, [10]) == [(3, 7)]
def test_goldbach_conjecture_case_18():
assert goldbach_conjecture(1, [18]) == [(5, 13)]
def test_goldbach_conjecture_case_28():
assert goldbach_conjecture(1, [28]) == [(5, 23)... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def goldbach_pair(n):",
"function_name": "goldbach_pair",
"parameter_list": "(n)"
},
{
"docstring": null,... | [
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 math\n\ndef sieve_of_eratosthenes(max_num):\n is_prime = [True] * (max_num + 1)\n is_prime[0] = is_prime[1] = False\n for i in range(2, int(math.sq... | trial_gpt4o_1 | {
"original_instruction": "The famous Goldbach Conjecture states that every even number greater than 2 can be expressed as the sum of two prime numbers. There may be multiple valid prime pairs for a given even number. Your task is to write a function that, given an even number, finds one such pair of prime numbers wh... | 0.60444 | Taco_83046 | C | [
"is_prime",
"goldbach_pair",
"goldbach_conjecture"
] | 3 | [
[
"goldbach_conjecture",
"goldbach_pair"
],
[
"goldbach_pair",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | e6c47c4707de7a57623406005ee98fa0d619bcae | 1a18906914f83a3fad8a6201d9cfe915b4f6d17f | |||
v1.0 | complete | Taco | Taco_83148_C | def count_topological_sorts(n: int, edges: List[Tuple[int, int]]) -> int:
""" You are given a directed acyclic graph (DAG) with n vertices and m edges.
Find the number of different topological sorts of the graph.
Args:
n: int - number of vertices (1 ≤ n ≤ 50).
edges: List of tuples (u, v) represen... | MOD = 10**9 + 7
def count_topological_sorts(n, edges):
from itertools import permutations
# Create the adjacency list and the in-degree list
adj_list = [[] for _ in range(n)]
in_degree = [0] * n
# Populate the adjacency list and in-degree list
for u, v in edges:
adj_list[u-1].... | from solution import count_topological_sorts
def test_example_1():
n = 3
edges = [(1, 2), (2, 3)]
assert count_topological_sorts(n, edges) == 1
def test_example_2():
n = 4
edges = [(1, 2), (1, 3), (2, 4), (3, 4)]
assert count_topological_sorts(n, edges) == 2
def test_no_edges():
n = 3
... | [
{
"docstring": null,
"function_declaration": "def count_topological_sorts(n, edges):",
"function_name": "count_topological_sorts",
"parameter_list": "(n, edges)"
},
{
"docstring": null,
"function_declaration": "def solve_topo_sort_problem():",
"function_name": "solve_topo_sort_proble... | [
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": "MOD = 10**9 + 7\n\ndef count_topological_sorts(n, edges):\n from functools import lru_cache\n import itertools\n\n # Calculate the adjacency matrix\n a... | trial_gpt4o_3 | {
"original_instruction": "You are given a directed acyclic graph (DAG) with n vertices and m edges. Your task is to find the number of different topological sorts of the graph. \n\nA topological sort of a directed acyclic graph is a linear ordering of its vertices such that for every directed edge u -> v, vertex u c... | 0.532123 | Taco_83148 | C | [
"count_topological_sorts",
"solve_topo_sort_problem"
] | 2 | [
[
"solve_topo_sort_problem",
"count_topological_sorts"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 487b171e6101ac8541ff3284651f2b7203a72aa3 | e0b4c19de6befe79680bf9f0879183f784b0331f | |||
v1.0 | complete | Taco | Taco_82807_C | def move_robot(R: int, C: int, grid: List[str], x: int, y: int, movements: str) -> Tuple[int, int]:
""" Move a robot according to the given sequence of movements.
Parameters:
R (int): Number of rows in the grid.
C (int): Number of columns in the grid.
grid (List[str]): Grid representation where... | def move_robot(R, C, grid, x, y, movements):
for move in movements:
if move == 'U' and x > 1 and grid[x-2][y-1] != '#':
x -= 1
elif move == 'D' and x < R and grid[x][y-1] != '#':
x += 1
elif move == 'L' and y > 1 and grid[x-1][y-2] != '#':
y -= 1
e... | from solution import move_robot, final_positions
def test_move_robot_simple():
# Grid specification
R, C = 5, 5
grid = [
".....",
".....",
".....",
".....",
"....."
]
# Single robot move
assert move_robot(R, C, grid, 1, 1, "RRR") == (1, 4)
assert move... | [
{
"docstring": null,
"function_declaration": "def move_robot(R, C, grid, x, y, movements):",
"function_name": "move_robot",
"parameter_list": "(R, C, grid, x, y, movements)"
},
{
"docstring": null,
"function_declaration": "def final_positions(R, C, grid, robots):",
"function_name": "... | [
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 simulate_robots(R, C, grid, robots):\n # Convert x and y coordinates from 1-based to 0-based\n def move_robot(start_x, start_y, moves):\n x, y = s... | trial_gpt4o_1 | {
"original_instruction": "A robotics lab has designed several specialized robots to perform tasks on a factory floor. The floor is represented as a 2D grid with R rows and C columns. Each cell in the grid can either be empty or contain an obstacle.\n\nEach robot starts at a specific position on the grid and must per... | 0.622694 | Taco_82807 | C | [
"move_robot",
"final_positions"
] | 2 | [
[
"final_positions",
"move_robot"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e8877bdd6d6326706b21078ad0360597c96e26c6 | 13443075211fa34bdc3e27b262b4c69cf5b78439 | |||
v1.0 | complete | Taco | Taco_83244_C | def longest_prime_path(N: int, edges: List[Tuple[int, int, int]]) -> int:
"""
Find the length of the longest path of the tree that is characterized by consecutive primes.
>>> longest_prime_path(5, [(1, 2, 3), (2, 3, 5), (3, 4, 7), (4, 5, 4)])
3
>>> longest_prime_path(4, [(1, 2, 6), (2, 3, 8), ... | def is_prime(x):
if x < 2:
return False
for i in range(2, int(x**0.5) + 1):
if x % i == 0:
return False
return True
from collections import defaultdict, deque
def longest_prime_path(N, edges):
# Create adjacency list
adj = defaultdict(list)
for (u, v, w) in edges:
... | def test_longest_prime_path_example():
N = 5
edges = [
(1, 2, 3),
(2, 3, 5),
(3, 4, 7),
(4, 5, 4),
]
assert longest_prime_path(N, edges) == 3
def test_longest_prime_path_no_primes():
N = 4
edges = [
(1, 2, 6),
(2, 3, 8),
(3, 4, 10),
]
... | [
{
"docstring": null,
"function_declaration": "def is_prime(x):",
"function_name": "is_prime",
"parameter_list": "(x)"
},
{
"docstring": null,
"function_declaration": "def longest_prime_path(N, edges):",
"function_name": "longest_prime_path",
"parameter_list": "(N, edges)"
},
... | [
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\nfrom collections import defaultdict\nfrom itertools import combinations\n\nsys.setrecursionlimit(200000)\n\ndef is_prime(x):\n \"\"\"\n Returns T... | trial_gpt4o_2 | {
"original_instruction": "Given a binary tree consisting of N vertices. Each vertex of the binary tree is numbered from 1 to N, and each edge has a weight associated with it. Your task is to find the length of the longest path of the tree that is characterized by consecutive primes, in other words, a path where ever... | 0.593028 | Taco_83244 | C | [
"is_prime",
"longest_prime_path"
] | 2 | [
[
"longest_prime_path",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | f76fee44723b97e2b3c3a40921974268b55c9a30 | 01126fc2bfd476c347763e608e958d90360a8277 | |||
v1.0 | complete | Taco | Taco_83205_C | def min_steps_to_achieve_ratio(a, b):
"""
Given two integers a and b representing the ratio of two liquids A and B respectively,
returns the minimum number of steps required to fill the tank with the desired ratio of a:b.
"""
pass
def gcd(x, y):
"""
Helper function to compute the Greatest C... | def min_steps_to_achieve_ratio(a, b):
"""
Given two integers a and b representing the ratio of two liquids A and B respectively,
returns the minimum number of steps required to fill the tank with the desired ratio of a:b.
"""
gcd_ab = gcd(a, b)
return (a // gcd_ab) + (b // gcd_ab)
def gcd(x, y)... | def test_gcd():
assert gcd(1, 2) == 1
assert gcd(3, 5) == 1
assert gcd(2, 2) == 2
assert gcd(7, 10) == 1
assert gcd(6, 9) == 3
def test_min_steps_to_achieve_ratio():
assert min_steps_to_achieve_ratio(1, 2) == 3
assert min_steps_to_achieve_ratio(3, 5) == 8
assert min_steps_to_achieve_rat... | [
{
"docstring": "Given two integers a and b representing the ratio of two liquids A and B respectively,\nreturns the minimum number of steps required to fill the tank with the desired ratio of a:b.",
"function_declaration": "def min_steps_to_achieve_ratio(a, b):",
"function_name": "min_steps_to_achieve_r... | [
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 min_steps_to_fill_ratio(t, test_cases):\n \"\"\"\n Returns the minimum number of steps required to achieve the desired ratio a:b for all test cases.\n ... | trial_gpt4o_2 | {
"original_instruction": "You are given an initially empty tank, and you need to fill it such that it contains a specific ratio of two different liquids, A and B. The required ratio can be represented as a:b, where `a` and `b` are integers.\n\nIn each step, you can pour either one unit of liquid A or one unit of liq... | 0.573753 | Taco_83205 | C | [
"min_steps_to_achieve_ratio",
"gcd",
"min_steps_test_cases"
] | 3 | [
[
"min_steps_test_cases",
"min_steps_to_achieve_ratio"
],
[
"min_steps_to_achieve_ratio",
"gcd"
]
] | 2 | [
"min_steps_test_cases"
] | false | [] | false | pytest | false | [] | true | 9f22c3b144add8c751845c3a41284b1787eb2cd4 | 28f8638c48dd471514d1dfd6f9a5d4d863e7c464 | |||
v1.0 | complete | Taco | Taco_83363_C | import re
def is_palindrome(s: str) -> bool:
""" Checks if the given string s is a palindrome, ignoring spaces, punctuation, and capitalization.
>>> is_palindrome("A man a plan a canal Panama")
True
>>> is_palindrome("Hello, World!")
False
>>> is_palindrome("Madam, in Eden, I'm Adam")
True
... | import re
def is_palindrome(s):
"""
Checks if the given string s is a palindrome, ignoring spaces, punctuation, and capitalization.
"""
# Remove non-alphanumeric characters and convert to lowercase
cleaned_string = re.sub(r'[^a-zA-Z0-9]', '', s).lower()
# Check if the string reads the same forw... | from solution import is_palindrome, check_palindromes
def test_is_palindrome():
assert is_palindrome("A man a plan a canal Panama") == True
assert is_palindrome("Hello, World!") == False
assert is_palindrome("Madam, in Eden, I'm Adam") == True
assert is_palindrome("racecar") == True
assert is_palin... | [
{
"docstring": "Checks if the given string s is a palindrome, ignoring spaces, punctuation, and capitalization.",
"function_declaration": "def is_palindrome(s):",
"function_name": "is_palindrome",
"parameter_list": "(s)"
},
{
"docstring": "Takes a list of strings and returns a list of \"YES\... | [
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 re\n\ndef is_palindrome(s):\n \"\"\"\n Checks if the provided string is a palindrome, ignoring spaces, punctuation, and capitalization.\n \"\"\"\n ... | trial_gpt4o_2 | {
"original_instruction": "Strings can be represented as characters and spaces combined to form words. A palindrome is a string that reads the same forwards and backwards, ignoring spaces and capitalization. For example, \"A man a plan a canal Panama\" is a palindrome because it reads the same regardless of spaces an... | 0.850981 | Taco_83363 | C | [
"is_palindrome",
"check_palindromes"
] | 2 | [
[
"check_palindromes",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e5ebb50461984fb8f524e69a363346b7796de60c | 240f620f04a87a1872f32cd9013ed7469d9e9a69 | |||
v1.0 | complete | Taco | Taco_83344_C | def find_exchange_rates(n: int, m: int, rates: List[Tuple[str, str, float]], queries: List[Tuple[str, str]]) -> List[float]:
""" Determine the exchange rate between two specified kingdoms given a list of directed edges representing the exchange rates.
>>> find_exchange_rates(5, 6, [('A', 'B', 1.2), ('B', ... | def floyd_warshall(n, rates):
from collections import defaultdict
import math
dist = defaultdict(lambda: defaultdict(lambda: math.inf))
for u in range(n):
dist[chr(ord('A') + u)][chr(ord('A') + u)] = 1.0
for u, v, r in rates:
dist[u][v] = r
for k in range(n):
... | from solution import find_exchange_rates
def test_example_case():
n = 5
m = 6
rates = [
('A', 'B', 1.2),
('B', 'C', 1.3),
('C', 'D', 0.9),
('D', 'E', 1.4),
('E', 'A', 0.8),
('B', 'D', 1.1)
]
queries = [('A', 'D'), ('C', 'E'), ('A', 'F')]
expected_... | [
{
"docstring": null,
"function_declaration": "def floyd_warshall(n, rates):",
"function_name": "floyd_warshall",
"parameter_list": "(n, rates)"
},
{
"docstring": null,
"function_declaration": "def find_exchange_rates(n, m, rates, queries):",
"function_name": "find_exchange_rates",
... | [
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 find_exchange_rate(n, m, edges, queries):\n from collections import defaultdict\n from math import isclose, inf\n\n graph = defaultdict(list)\n for... | trial_gpt4o_2 | {
"original_instruction": "In a distant land, there are multiple kingdoms. Each kingdom is represented by a letter from 'A' to 'Z'. The kingdoms decide to form some alliances. Each alliance is defined as a group of kingdoms that are directly or indirectly connected.\n\nFor example, if Kingdom A is allied with Kingdom... | 0.615048 | Taco_83344 | C | [
"floyd_warshall",
"find_exchange_rates"
] | 2 | [
[
"find_exchange_rates",
"floyd_warshall"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b77fa70f805a30d4d44735f9c4caced3cfbdedb0 | 06b59cbb015cf44cd255b4bb01d57bb9e27a7c02 | |||
v1.0 | complete | Taco | Taco_83327_C | def preprocess_evens(arr):
""" Preprocess the array to create an auxiliary array that holds the prefix sum of even numbers.
>>> preprocess_evens([1, 2, 3, 4, 5])
[0, 1, 1, 2, 2]
"""
def count_even_numbers(arr, queries):
""" Process the given queries to count the even numbers in the specified s... | def preprocess_evens(arr):
"""
Preprocess the array to create an auxiliary array that holds the prefix sum of even numbers.
"""
n = len(arr)
prefix_evens = [0] * n
prefix_evens[0] = 1 if arr[0] % 2 == 0 else 0
for i in range(1, n):
prefix_evens[i] = prefix_evens[i-1]
if ... | def test_preprocess_evens():
arr = [1, 2, 3, 4, 5]
assert preprocess_evens(arr) == [0, 1, 1, 2, 2]
def test_count_even_numbers():
arr = [1, 2, 3, 4, 5]
queries = [(1, 3), (2, 5), (1, 5)]
assert count_even_numbers(arr, queries) == [1, 2, 2]
def test_all_odds():
arr = [1, 3, 5, 7, 9]
queries... | [
{
"docstring": "Preprocess the array to create an auxiliary array that holds the prefix sum of even numbers.",
"function_declaration": "def preprocess_evens(arr):",
"function_name": "preprocess_evens",
"parameter_list": "(arr)"
},
{
"docstring": "Process the given queries to count the even n... | [
0,
1
] | 1 | medium | 0.5 | {
"trial_gpt4o_0": null,
"trial_gpt4o_1": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared1_results_combined.jsonl",
"solution_code": "def count_even_numbers(n, arr, queries):\n # Create a prefix sum array for counting even numbers\n prefix_even_count = [0] * (n + 1)... | trial_gpt4o_2 | {
"original_instruction": "You are given an array consisting of $n$ integers. Your task is to process $q$ queries, each of which asks for the count of even numbers in a given subarray.\n\n------ Input Format ------\n\n- The first line contains a single integer $n$ — the number of elements in the array.\n- The second ... | 0.726267 | Taco_83327 | C | [
"preprocess_evens",
"count_even_numbers"
] | 2 | [
[
"count_even_numbers",
"preprocess_evens"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | a9b295454d901e2f1c2459e64640827504f81204 | 5c1186ec27e40c61d4f36040e17177b822cfebd7 | |||
v1.0 | complete | Taco | Taco_83532_C | class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
def findLCA(root: 'TreeNode', n1: int, n2: int) -> int:
""" Find the lowest common ancestor (LCA) of two given nodes in a binary tree.
>>> nodes = [3, 5, 1, 6, 2, 0, 8, -1, -1, 7, 4]
>>> root ... | class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
def findLCA(root, n1, n2):
def findLCAHelper(root, n1, n2):
if root is None:
return None
if root.val == n1 or root.val == n2:
return root
left_lca = f... | from solution import findLCA, build_tree
def test_findLCA_case_1():
nodes = [3, 5, 1, 6, 2, 0, 8, -1, -1, 7, 4]
root = build_tree(nodes)
assert findLCA(root, 5, 1) == 3
def test_findLCA_case_2():
nodes = [3, 5, 1, 6, 2, 0, 8, -1, -1, 7, 4]
root = build_tree(nodes)
assert findLCA(root, 6, 4) ==... | [] | [
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": "class TreeNode:\n def __init__(self, x):\n self.val = x\n self.left = None\n self.right = None\n\ndef build_tree(nodes):\n if not nodes ... | trial_gpt4o_7 | {
"original_instruction": "Given a binary tree, write a function `findLCA()` to find the lowest common ancestor (LCA) of two given nodes in the tree. \n\nInput:\nThe input consists of multiple test cases. Each test case contains the following:\n1. The first line contains the number of nodes in the binary tree.\n2. Th... | 0.552177 | Taco_83532 | C | [
"findLCA",
"existsInTree",
"build_tree"
] | 3 | [
[
"findLCA",
"existsInTree"
]
] | 1 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 35254ab76bb5dd566edbb78c99c94fc06a7f859f | abd9e2b2738b95f85f67e1f53390ada7ff779479 | |||
v1.0 | complete | Taco | Taco_82898_C | def preprocess_sums(array):
"""
Precomputes prefix sums for the given array.
Parameters:
- array: List of integers
Returns:
- prefix_sums: List of prefix sums where prefix_sums[i] is the sum of elements from array[0] to array[i-1]
"""
pass
def query_sum(prefix_sums, L, R):
... | def preprocess_sums(array):
"""
Precomputes prefix sums for the given array.
Parameters:
- array: List of integers
Returns:
- prefix_sums: List of prefix sums where prefix_sums[i] is the sum of elements from array[0] to array[i-1]
"""
prefix_sums = [0] * (len(array) + 1)
fo... | def test_process_queries():
array = [1, 2, 3, 4, 5]
queries = [(1, 3), (2, 4), (1, 5)]
result = process_queries(5, 3, array, queries)
assert result == [6, 9, 15], f"Expected [6, 9, 15], but got {result}"
def test_process_queries_single_element():
array = [100]
queries = [(1, 1)]
result = pr... | [
{
"docstring": "Precomputes prefix sums for the given array.\n\nParameters:\n- array: List of integers\n\nReturns:\n- prefix_sums: List of prefix sums where prefix_sums[i] is the sum of elements from array[0] to array[i-1]",
"function_declaration": "def preprocess_sums(array):",
"function_name": "prepro... | [
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 preprocess_prefix_sums(arr):\n \"\"\"\n Preprocess the given list to create a prefix sums array.\n \n Parameters:\n arr (list): The original lis... | trial_gpt4o_1 | {
"original_instruction": "John is an avid coder and loves challenges. Today, he stumbled upon an interesting problem while practicing. The problem is as follows: John has a list of N integers. He is given Q queries, and for each query, he needs to find the sum of the integers in a subarray from index L to R (inclusi... | 0.575063 | Taco_82898 | C | [
"preprocess_sums",
"query_sum",
"process_queries"
] | 3 | [
[
"process_queries",
"preprocess_sums"
],
[
"process_queries",
"query_sum"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | false | [] | true | 4a51d8abd250764a5d7c553225a26d3b86862a8e | 13aa713cacb6b58abf410dd5efe576ecd858bb8a | |||
v1.0 | complete | Taco | Taco_83353_C | def generate_fibonacci_up_to(limit):
""" Generate all Fibonacci-like numbers up to a given limit.
Args:
limit (int): The maximum value for the sequence generation.
Returns:
List[int]: A list of Fibonacci-like numbers up to the limit.
"""
fibonacci = [1, 2]
while fibonacci[-1] + fibonac... | def generate_fibonacci_up_to(limit):
fibonacci = [1, 2]
while fibonacci[-1] + fibonacci[-2] <= limit:
fibonacci.append(fibonacci[-1] + fibonacci[-2])
return fibonacci
def min_coins_needed(N):
fibonacci = generate_fibonacci_up_to(N)
total, count = 0, 0
for coin in reversed(fibonacci):
... | from solution import solve_cases, min_coins_needed
def test_min_coins_needed():
assert min_coins_needed(10) == 2
assert min_coins_needed(15) == 2
assert min_coins_needed(50) == 3
def test_solve_cases():
assert solve_cases([10, 15, 50]) == [2, 2, 3]
assert solve_cases([1]) == [1]
assert solve_c... | [
{
"docstring": null,
"function_declaration": "def generate_fibonacci_up_to(limit):",
"function_name": "generate_fibonacci_up_to",
"parameter_list": "(limit)"
},
{
"docstring": null,
"function_declaration": "def min_coins_needed(N):",
"function_name": "min_coins_needed",
"paramete... | [
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": "def generate_coins():\n coins = [1, 2]\n while coins[-1] <= 10**9:\n new_coin = coins[-1] + coins[-2]\n coins.append(new_coin)\n return coin... | trial_gpt4o_5 | {
"original_instruction": "In a faraway land, there exists a peculiar form of currency: magical coins. Each coin has a positive integer value, and the value is equal to the sum of its two closest lower valued coins. For instance, if there are coins with values 3 and 5, the next higher value coin will be 8, followed b... | 0.636307 | Taco_83353 | C | [
"generate_fibonacci_up_to",
"min_coins_needed",
"solve_cases"
] | 3 | [
[
"min_coins_needed",
"generate_fibonacci_up_to"
],
[
"solve_cases",
"min_coins_needed"
]
] | 2 | [
"solve_cases"
] | false | [] | false | pytest | true | [] | true | 5982765577fad6c129bd1e05fa2e084ab10a0d82 | 7772bda639ac2df2d6540310c250b9a984ad9147 | |||
v1.0 | complete | Taco | Taco_83192_C | from typing import List, Tuple
def minimum_travel_time(n: int, m: int, roads: List[Tuple[int, int, int]]) -> int:
"""
In a hypothetical kingdom, there are N cities connected by M bidirectional roads.
Each road connects two cities and has a certain travel time associated with it.
The cities are numbered... | import itertools
def tsp(N, roads):
"""
Solve the Travelling Salesman Problem (TSP) for the given cities and roads.
:param N: Number of cities
:param roads: List of tuples (u, v, w) representing roads between cities u and v with travel time w
:return: Minimum travel time to visit all cities ex... | from solution import minimum_travel_time
def test_case_1():
assert minimum_travel_time(4, 6, [(1, 2, 10), (1, 3, 15), (1, 4, 20), (2, 3, 35), (2, 4, 25), (3, 4, 30)]) == 80
def test_case_no_path():
assert minimum_travel_time(3, 2, [(1, 2, 10), (2, 3, 10)]) == -1
def test_case_single_city():
assert minimu... | [
{
"docstring": "Solve the Travelling Salesman Problem (TSP) for the given cities and roads.\n\n:param N: Number of cities\n:param roads: List of tuples (u, v, w) representing roads between cities u and v with travel time w\n:return: Minimum travel time to visit all cities exactly once and return to the start, o... | [
0,
0,
0,
0,
0,
0,
1,
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": "def tsp(N, M, roads):\n from itertools import permutations\n import sys\n\n # Initialize the adjacency matrix with infinity\n adj = [[float('inf')] * N... | trial_gpt4o_6 | {
"original_instruction": "In a hypothetical kingdom, there are N cities connected by M bidirectional roads. Each road connects two cities and has a certain travel time associated with it. The cities are numbered from 1 to N. The king wants to visit every city starting from city 1 and follow any path that visits all ... | 0.721761 | Taco_83192 | C | [
"tsp",
"minimum_travel_time"
] | 2 | [
[
"minimum_travel_time",
"tsp"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b3cbcfcd810692d3cdf87bc32828b12f925f5d64 | f97b8ccdf970875cdd8d147893895c7a1be17b3d | |||
v1.0 | complete | Taco | Taco_83667_C | def max_communication_area(matrix):
""" Return the size of the largest rectangular area covered exclusively by active sensors.
Args:
matrix (List[List[int]]): 2D list representing the grid where `1` indicates an active sensor and `0` indicates an inactive sensor.
Returns:
int: The size of ... | def max_communication_area(matrix):
if not matrix:
return 0
max_area = 0
m, n = len(matrix), len(matrix[0])
heights = [0] * n
for i in range(m):
for j in range(n):
# Update the running count of '1's in each column.
heights[j] = heights[j] + 1 if matr... | from solution import max_communication_area
def test_max_communication_area_example_1():
assert max_communication_area([
[1, 0, 1, 0, 0],
[1, 0, 1, 1, 1],
[1, 1, 1, 1, 1],
[1, 0, 0, 1, 0]
]) == 6
def test_max_communication_area_example_2():
assert max_communication_area([
... | [
{
"docstring": null,
"function_declaration": "def max_communication_area(matrix):",
"function_name": "max_communication_area",
"parameter_list": "(matrix)"
},
{
"docstring": null,
"function_declaration": "def largest_rectangle_area(heights):",
"function_name": "largest_rectangle_area... | [
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:\n return 0\n\n max_area = 0\n n = len(matrix[0])\n heights = [0] * (n + 1)\n \n for row in ... | trial_gpt4o_2 | {
"original_instruction": "A network of sensors is set up in a grid, where each sensor can either be active or inactive. Sensors are represented as a 2D grid of size m x n. The goal is to understand the extent of communication coverage provided by these sensors. A sensor at cell (i, j) can communicate with another se... | 0.596633 | Taco_83667 | C | [
"max_communication_area",
"largest_rectangle_area"
] | 2 | [
[
"max_communication_area",
"largest_rectangle_area"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e07fd78c33811ea628ca104a0efc6e2c06ac678d | 252266fd24b7311c809a8f5ef1f8288e9be6270c | |||
v1.0 | complete | Taco | Taco_83502_C | from typing import List, Tuple
def compute_prefix_sums(grid: List[List[int]]) -> List[List[int]]:
""" Compute the prefix sums for a given n x n grid of integers.
>>> compute_prefix_sums([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
[[0, 0, 0, 0], [0, 1, 3, 6], [0, 5, 12, 21], [0, 12, 27, 45]]
"""
def query_s... | def compute_prefix_sums(grid):
n = len(grid)
prefix_sums = [[0] * (n + 1) for _ in range(n + 1)]
for i in range(1, n + 1):
for j in range(1, n + 1):
prefix_sums[i][j] = grid[i - 1][j - 1] + \
prefix_sums[i - 1][j] + \
p... | def test_compute_prefix_sums():
grid = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
expected = [
[0, 0, 0, 0],
[0, 1, 3, 6],
[0, 5, 12, 21],
[0, 12, 27, 45]
]
assert compute_prefix_sums(grid) == expected
def test_query_subgrid_sum():
prefix_sums = ... | [
{
"docstring": null,
"function_declaration": "def compute_prefix_sums(grid):",
"function_name": "compute_prefix_sums",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def query_subgrid_sum(prefix_sums, x1, y1, x2, y2):",
"function_name": "query_subgrid_sum... | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
1
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def preprocess_grid(grid):\n n = len(grid)\n prefix_sum = [[0] * (n + 1) for _ in range(n + 1)]\n\n for i in range(1, n + 1):\n for j in range(1, n... | trial_gpt4o_9 | {
"original_instruction": "You are given a grid of size n x n, filled with non-negative integers. You need to process q queries on this grid. Each query is defined by four integers x1, y1, x2, y2 and asks for the sum of all elements within the subgrid determined by the corners (x1, y1) and (x2, y2) (inclusive).\n\n--... | 0.580093 | Taco_83502 | C | [
"compute_prefix_sums",
"query_subgrid_sum",
"process_queries"
] | 3 | [
[
"process_queries",
"compute_prefix_sums"
],
[
"process_queries",
"query_subgrid_sum"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | false | [] | true | fe7343796528b63474d673c97b3c518d7e3b07ac | 003594a968d65bc19d22e11a45dd6be78992f726 | |||
v1.0 | complete | Taco | Taco_83621_C | from typing import List
def max_sum_subrectangle(matrix: List[List[int]]) -> int:
"""
Function to find the maximum sum of any subrectangle in a given matrix.
:param matrix: A 2D list of integers representing the matrix.
:return: The maximum sum of any subrectangle in the matrix.
"""
def test_exam... | def max_sum_subrectangle(matrix):
"""
Function to find the maximum sum of any subrectangle in a given matrix.
:param matrix: A 2D list of integers representing the matrix.
:return: The maximum sum of any subrectangle in the matrix.
"""
if not matrix or not matrix[0]:
return 0
n... | from solution import max_sum_subrectangle
def test_example_1():
matrix = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
assert max_sum_subrectangle(matrix) == 45
def test_example_2():
matrix = [
[1, 2, 3, 4, 5],
[6, 7, 8, 9, 10],
[11, 12, 13, 14, 15],
[16, ... | [
{
"docstring": "Function to find the maximum sum of any subrectangle in a given matrix.\n\n:param matrix: A 2D list of integers representing the matrix.\n:return: The maximum sum of any subrectangle in the matrix.",
"function_declaration": "def max_sum_subrectangle(matrix):",
"function_name": "max_sum_s... | [
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 maximum_sum_subrectangle(matrix):\n def max_subarray(array):\n max_sum = float('-inf')\n current_sum = 0\n for value in array:\n ... | trial_gpt4o_4 | {
"original_instruction": "Professor Claire loves rectangles. Every time she finds a rectangular area filled with positive integers, she calculates their sum and stores it. Given a 2D matrix of dimensions N x M filled with positive integers, she wants to find the subrectangle with the highest possible sum.\n\nCan you... | 0.638543 | Taco_83621 | C | [
"max_sum_subrectangle",
"max_subarray_sum"
] | 2 | [
[
"max_sum_subrectangle",
"max_subarray_sum"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 2fa5d121543442ca67d916e98d439b1a7dc3a4c4 | 74dac5a6a28b81950defc3c9c8becabfd931ee79 | |||
v1.0 | complete | Taco | Taco_83901_C | def find_longest_magical_sequence(arr) -> int:
"""
Given an array arr, find the length of the longest contiguous subarray
such that every pair of adjacent elements differ by exactly 1.
>>> find_longest_magical_sequence([1, 2, 3, 2, 1])
5
>>> find_longest_magical_sequence([1, 2, 4, 5])
... | def find_longest_magical_sequence(arr):
"""
Given an array arr, find the length of the longest contiguous subarray
such that every pair of adjacent elements differ by exactly 1.
"""
n = len(arr)
if n == 0:
return 0
max_length = 1
current_length = 1
for i in range(1, n):
... | from solution import find_longest_magical_sequence, process_test_cases
def test_find_longest_magical_sequence():
assert find_longest_magical_sequence([1, 2, 3, 2, 1]) == 5
assert find_longest_magical_sequence([1, 2, 4, 5]) == 2
assert find_longest_magical_sequence([7, 6, 5, 6, 7, 8]) == 6
assert find_l... | [
{
"docstring": "Given an array arr, find the length of the longest contiguous subarray\nsuch that every pair of adjacent elements differ by exactly 1.",
"function_declaration": "def find_longest_magical_sequence(arr):",
"function_name": "find_longest_magical_sequence",
"parameter_list": "(arr)"
},... | [
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 longest_magical_sequence(arr):\n \"\"\"\n Returns the length of the longest contiguous subarray which is a \"Magical Sequence\".\n \"\"\"\n max_len... | trial_gpt4o_2 | {
"original_instruction": "In a distant galaxy, there is a kingdom ruled by a queen who loves solving puzzles. Recently, she has devised a new challenge based on a special kind of sequence she calls the \"Magical Sequence\". \n\nA \"Magical Sequence\" is defined as a list where every pair of adjacent elements differ ... | 0.641997 | Taco_83901 | C | [
"find_longest_magical_sequence",
"process_test_cases",
"read_input_and_process"
] | 3 | [
[
"process_test_cases",
"find_longest_magical_sequence"
],
[
"read_input_and_process",
"process_test_cases"
]
] | 2 | [
"process_test_cases"
] | false | [] | false | pytest | true | [] | true | 69ae4f56bc81c9c19065903ad90868206c27aa07 | 8fa1660fa2fbe29edf8b85cc37b93f90ea12f173 | |||
v1.0 | complete | Taco | Taco_83876_C | from typing import List, Tuple
def tree_diameter(n: int, edges: List[Tuple[int, int]]) -> int:
""" Find the distance between the two most distant nodes in the tree.
>>> tree_diameter(4, [(1, 2), (1, 3), (3, 4)])
3
>>> tree_diameter(5, [(1, 2), (1, 3), (3, 4), (4, 5)])
4
>>> tree_diameter(4, [(1... | from collections import defaultdict, deque
def find_farthest_node(start, n, graph):
visited = [False] * (n + 1)
visited[start] = True
queue = deque([(start, 0)])
farthest_node = start
max_distance = 0
while queue:
node, dist = queue.popleft()
for neighbor in graph[node]:
... | from solution import tree_diameter
def test_tree_diameter_example1():
n = 4
edges = [(1, 2), (1, 3), (3, 4)]
assert tree_diameter(n, edges) == 3
def test_tree_diameter_example2():
n = 5
edges = [(1, 2), (1, 3), (3, 4), (4, 5)]
assert tree_diameter(n, edges) == 4
def test_tree_diameter_line_tr... | [
{
"docstring": null,
"function_declaration": "def find_farthest_node(start, n, graph):",
"function_name": "find_farthest_node",
"parameter_list": "(start, n, graph)"
},
{
"docstring": null,
"function_declaration": "def tree_diameter(n, edges):",
"function_name": "tree_diameter",
... | [
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 find_tree_diameter(n, edges):\n from collections import deque, defaultdict\n \n def bfs(node):\n visited = [-1] * (n + 1)\n queue = dequ... | trial_gpt4o_2 | {
"original_instruction": "You're given a tree of n nodes, rooted at 1. Each node has a unique integer ID from 1 to n. A tree is a connected graph with no cycles.\n\nYour task is to find the distance between the two most distant nodes in the tree. The distance between two nodes is defined as the number of edges on th... | 0.704035 | Taco_83876 | C | [
"find_farthest_node",
"tree_diameter"
] | 2 | [
[
"tree_diameter",
"find_farthest_node"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 9a7b12b46767313f46709e838a50d393c753b0a7 | 73f2a5eaa0453ff01b14b4dfe9e589cd2d0310ca | |||
v1.0 | complete | Taco | Taco_83940_C | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def path_sum_exists(root, S):
""" Determine if there exists a path between any two nodes in the binary tree such that the sum of the values of the nodes in the path equal... | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def path_sum_exists(root, S):
def dfs(node, current_sum):
if not node:
return False
current_sum += node.val
if current_sum == S:
... | def test_example_1():
input_string = "7\n3 4 2 -3 5 6 -2\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7\n6"
expected_output = "True"
assert solve(input_string) == expected_output
def test_example_2():
input_string = "5\n1 -1 2 3 4\n1 2\n1 3\n2 4\n2 5\n10"
expected_output = "False"
assert solve(input_string) == ... | [] | [
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": "class TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\ndef path_su... | trial_gpt4o_0 | {
"original_instruction": "You are given a binary tree with n nodes. Each node contains an integer value. You need to determine if there exists a path between any two nodes in the tree such that the sum of the values of the nodes in the path equals a given integer S. A path can start and end at any two nodes, and it ... | 0.609973 | Taco_83940 | C | [
"path_sum_exists",
"build_tree",
"from_input_string",
"to_input_string",
"from_output_string",
"to_output_string",
"solve"
] | 7 | [
[
"solve",
"build_tree"
],
[
"solve",
"from_input_string"
],
[
"solve",
"path_sum_exists"
],
[
"solve",
"to_output_string"
]
] | 4 | [] | false | [
"TreeNode"
] | true | pytest | false | [] | true | 0241667e2a65eddf02ae764beee471720c6de6c8 | d1ac309e98b0395963db3dd6461568e20b1d6a87 | |||
v1.0 | complete | Taco | Taco_83635_C | from typing import List, Tuple
def process_test_cases(test_cases: List[Tuple[int, List[int]]]) -> List[int]:
"""
Determine the minimum number of inversions after sorting the array.
Since we can reverse any subarray, it is possible to sort the entire array,
thus eliminating all inversions.
Args:
... | def count_inversions(arr):
"""
Helper function to count inversions in an array
using a modified merge sort algorithm.
"""
if len(arr) < 2:
return 0
mid = len(arr) // 2
left = arr[:mid]
right = arr[mid:]
inv_count = count_inversions(left) + count_inversions(right)
i = j =... | from solution import process_test_cases
def test_sample_cases():
test_cases = [
(5, [3, 1, 2, 5, 4]),
(4, [4, 3, 2, 1])
]
results = process_test_cases(test_cases)
assert results == [0, 0]
def test_edge_case_single_element():
test_cases = [
(1, [1]),
]
results = proc... | [
{
"docstring": "Helper function to count inversions in an array\nusing a modified merge sort algorithm.",
"function_declaration": "def count_inversions(arr):",
"function_name": "count_inversions",
"parameter_list": "(arr)"
},
{
"docstring": "The goal of the problem is to determine the minimu... | [
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 count_inversions(arr):\n inv_count = 0\n arr_sorted = sorted(arr)\n inv_map = {v: i for i, v in enumerate(arr_sorted)}\n\n BIT = [0] * (len(arr) + ... | trial_gpt4o_2 | {
"original_instruction": "------ Problem Statement ------\nYou are given an integer array $A$ of length $N$. You are allowed to perform the following type of operation on $A$ any number of times:\n- Pick any subarray of size $M$ (where $M$ is a positive integer less than or equal to $N$) and reverse it.\n\nDetermine... | 0.741925 | Taco_83635 | C | [
"count_inversions",
"min_inversions_after_sorting",
"process_test_cases"
] | 3 | [
[
"process_test_cases",
"min_inversions_after_sorting"
]
] | 1 | [
"process_test_cases"
] | false | [] | false | pytest | true | [] | true | e427be628c1cf432f7a659e04cb583b8d8d31403 | 4553fb14b1544b052bd4d49dda35a93e0b57679b | |||
v1.0 | complete | Taco | Taco_83643_C | from typing import List, Tuple
def process_queries(A: List[int], queries: List[Tuple[int, int]]) -> List[int]:
"""
Given an array `A` of `n` integers, respond to `q` queries.
Each query consists of two integers `L` and `R`, and requires you
to return the sum of all prime numbers in the subarray `A[L... | def sieve_of_eratosthenes(max_num):
"""
Generates a list of booleans that indicates whether numbers are prime.
Returns an array is_prime where is_prime[i] is True if i is a prime number.
"""
is_prime = [True] * (max_num + 1)
is_prime[0] = is_prime[1] = False # 0 and 1 are not prime numbers
... | from solution import process_queries
def test_process_queries_sample_case():
A = [2, 3, 4, 5, 6]
queries = [(1, 3), (2, 5), (1, 5)]
assert process_queries(A, queries) == [5, 8, 10]
def test_process_queries_all_primes():
A = [2, 3, 5, 7, 11]
queries = [(1, 5), (2, 4), (3, 3)]
assert process_que... | [
{
"docstring": "Generates a list of booleans that indicates whether numbers are prime.\nReturns an array is_prime where is_prime[i] is True if i is a prime number.",
"function_declaration": "def sieve_of_eratosthenes(max_num):",
"function_name": "sieve_of_eratosthenes",
"parameter_list": "(max_num)"... | [
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 < 2:\n return False\n if num in (2, 3):\n return True\n if num % 2 == 0 or num % 3 == 0:\n return False\n... | trial_gpt4o_1 | {
"original_instruction": "Problem Statement\n\nGiven an array `A` of `n` integers, you are required to respond to `q` queries. Each query consists of two integers `L` and `R`, and requires you to return the sum of all prime numbers in the subarray `A[L...R]` inclusive.\n\nWrite a function to process these queries ef... | 0.597301 | Taco_83643 | C | [
"sieve_of_eratosthenes",
"preprocess_prime_sums",
"sum_of_primes_in_range",
"process_queries"
] | 4 | [
[
"process_queries",
"preprocess_prime_sums"
],
[
"process_queries",
"sieve_of_eratosthenes"
],
[
"process_queries",
"sum_of_primes_in_range"
]
] | 3 | [
"process_queries"
] | false | [] | false | pytest | true | [] | true | f9efe0632c9a7af0643bb8644230d68dfbdc6d30 | 634a8aef102a5bace19547d7ead34033871a6bc9 | |||
v1.0 | complete | Taco | Taco_83830_C | def find(parent, i):
if parent[i] != i:
parent[i] = find(parent, parent[i]) # Path compression
return parent[i]
def union(parent, rank, x, y):
root_x = find(parent, x)
root_y = find(parent, y)
if root_x != root_y:
if rank[root_x] > rank[root_y]:
parent[root_y] = ro... | def find(parent, i):
if parent[i] != i:
parent[i] = find(parent, parent[i]) # Path compression
return parent[i]
def union(parent, rank, x, y):
root_x = find(parent, x)
root_y = find(parent, y)
if root_x != root_y:
if rank[root_x] > rank[root_y]:
parent[root_y] = ro... | from solution import max_magical_energy
def test_example_case():
assert max_magical_energy(5, 4, [10, 20, 30, 40, 50], [(1, 2), (1, 3), (3, 4), (4, 5)]) == 150
def test_no_merge_ops():
assert max_magical_energy(3, 0, [10, 20, 30], []) == 60
def test_all_single_elements():
assert max_magical_energy(5, 4, ... | [
{
"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,
0
] | 2 | easy | 0.667 | {
"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 parent[i] = find(parent, parent[i]) # Path compression\n return parent[i]\n\ndef union(parent, rank, x, y... | trial_gpt4o_0 | {
"original_instruction": "A forest is a collection of one or more disjoint trees. We have a magic forest with n trees, each tree numbered from 1 to n. Each tree i has a value v_i associated with it, representing the magical energy it has. The magical energy of the entire forest is defined as the sum of the values of... | 0.472408 | Taco_83830 | C | [
"find",
"union",
"max_magical_energy"
] | 3 | [
[
"max_magical_energy",
"find"
],
[
"max_magical_energy",
"union"
],
[
"union",
"find"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | f1c0b782fa00e25a9c7d4f86a42fc303a25b5399 | 9e5ce9ccdc93379b17e0b7e12a279328831124e3 | |||
v1.0 | complete | Taco | Taco_84077_C | def is_prime(n: int) -> bool:
""" Determine if a number is a prime number.
>>> is_prime(2)
True
>>> is_prime(4)
False
"""
# Implement the function here
def nearest_prime(X: int) -> int:
""" Given an integer X, return the nearest prime number based on the condition.
If X is even, ret... | 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 nearest_prime(X):
if X % 2 == 0:
... | from solution import is_prime, nearest_prime
def test_is_prime():
assert not is_prime(0)
assert not is_prime(1)
assert is_prime(2)
assert is_prime(3)
assert not is_prime(4)
assert is_prime(5)
assert is_prime(29)
assert not is_prime(30)
def test_nearest_prime_even_number():
assert n... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def nearest_prime(X):",
"function_name": "nearest_prime",
"parameter_list": "(X)"
}
] | [
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_prime(n):\n \"\"\"\n Determines if a number n is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if... | trial_gpt4o_3 | {
"original_instruction": "Write a program to read an integer number $X$ and determine if it's an even or odd number. If it's even, change it to the nearest prime number greater than $X$. If it's odd, change it to the nearest prime number smaller than $X$.\n\n-----Input:-----\n- First line will contain a number $X$.\... | 0.775114 | Taco_84077 | C | [
"is_prime",
"nearest_prime"
] | 2 | [
[
"nearest_prime",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7149fb85c6c1b68729c362f764244e34e35a50e2 | f694144d0e46f7d66c977db3b65ab413a61707a8 | |||
v1.0 | complete | Taco | Taco_84259_C | def solve(T: int, test_cases: list) -> list:
"""
Solves the problem of finding the length of the longest substring of S in the range S[L...R] that contains no repeated characters.
T: int - the number of test cases
test_cases: list - a list of dictionaries where each dictionary contains:
- ... | def length_of_longest_substring(s: str) -> int:
"""
Returns the length of the longest substring of S that contains no repeated characters.
"""
n = len(s)
seen = set()
left = 0
max_length = 0
for right in range(n):
while s[right] in seen:
seen.remove(s[left])
... | from solution import solve
def test_example_cases():
T = 1
test_cases = [
{
"s": "abcabcbb",
"queries": [(1, 4), (2, 5), (3, 8)]
}
]
expected_output = [
[3, 3, 3]
]
assert solve(T, test_cases) == expected_output
def test_single_repeated... | [
{
"docstring": "Returns the length of the longest substring of S that contains no repeated characters.",
"function_declaration": "def length_of_longest_substring(s):",
"function_name": "length_of_longest_substring",
"parameter_list": "(s)"
},
{
"docstring": null,
"function_declaration": ... | [
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 length_of_longest_substring(s, queries):\n \"\"\"\n For each query in queries, returns the length of the longest substring with \n no repeated charact... | trial_gpt4o_2 | {
"original_instruction": "You are given a string S consisting of lowercase English letters. You need to answer Q queries. Each query is defined by two integers L and R. For each query, your task is to find the length of the longest substring of S in the range S[L...R] that contains no repeated characters.\n\nInput f... | 0.638721 | Taco_84259 | C | [
"length_of_longest_substring",
"process_queries",
"solve"
] | 3 | [
[
"process_queries",
"length_of_longest_substring"
],
[
"solve",
"process_queries"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | true | [] | true | 595030a2639c7cf932325edda930c00cf5f80621 | a510e0e8bda52552b7049222830a3c448de257b8 | |||
v1.0 | complete | Taco | Taco_84067_C | from typing import List, Tuple
def is_prime(num: int) -> bool:
"""Check if a number is prime."""
pass
def has_prime_sum_pair(gems: List[int]) -> bool:
"""Check if there exists a pair of gems whose sum is prime."""
pass
def can_collect_gems(t: int, test_cases: List[Tuple[int, List[int], List[int]]]) -... | def is_prime(num):
"""Check if a number is prime."""
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
return False
i += 6
retur... | from solution import is_prime, has_prime_sum_pair, can_collect_gems
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(97) == True # 97 is ... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Check if there exists a pair of gems whose sum is prime.",
"function_declaration": "def has_prime_sum_pair(gems):",
"f... | [
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(n):\n \"\"\" Check if a number is prime \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True # 2 is the only even pri... | trial_gpt4o_2 | {
"original_instruction": "In a distant land, there are N castles built along a straight line, at positions given by a list of integers. Each castle contains a rare gem, and these gems have unique integers as their identifiers. The kingdom's archaeologist, Astara, has recently figured out that the best way to collect... | 0.595541 | Taco_84067 | C | [
"is_prime",
"has_prime_sum_pair",
"can_collect_gems"
] | 3 | [
[
"can_collect_gems",
"has_prime_sum_pair"
],
[
"has_prime_sum_pair",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 9cb0e47c1c43da6d456f7429dc64bfa093098e71 | b8a264612e016e9271a6e92549a56f439d92ede5 | |||
v1.0 | complete | Taco | Taco_83908_C | def maxRectangle(N: int, M: int, matrix: List[List[int]]) -> int:
""" Given a matrix of size N x M, find the number of cells in the largest rectangular sub-matrix having all '1's.
>>> maxRectangle(4, 4, [
... [0, 1, 1, 0],
... [1, 1, 1, 1],
... [1, 1, 1, 1],
... [1, 1, 0, 0]
... | def max_histogram_area(hist):
stack = []
max_area = 0
index = 0
while index < len(hist):
if not stack or hist[stack[-1]] <= hist[index]:
stack.append(index)
index += 1
else:
top_of_stack = stack.pop()
area = (hist[top_of_stack] *
... | def test_maxRectangle_example1():
N = 4
M = 4
matrix = [
[0, 1, 1, 0],
[1, 1, 1, 1],
[1, 1, 1, 1],
[1, 1, 0, 0]
]
assert maxRectangle(N, M, matrix) == 8
def test_maxRectangle_example2():
N = 3
M = 3
matrix = [
[1, 0, 1],
[0, 1, 0],
... | [
{
"docstring": null,
"function_declaration": "def max_histogram_area(hist):",
"function_name": "max_histogram_area",
"parameter_list": "(hist)"
},
{
"docstring": null,
"function_declaration": "def maxRectangle(N, M, matrix):",
"function_name": "maxRectangle",
"parameter_list": "(... | [
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 max_histogram_area(heights):\n \"\"\"\n Helper function to find the largest rectangle area in a histogram.\n \"\"\"\n stack = []\n max_area = 0\... | trial_gpt4o_1 | {
"original_instruction": "Given a matrix of size N x M. Your task is to find the number of cells in the largest rectangular sub-matrix having all '1's.\n\nExample 1:\nInput:\nN = 4, M = 4\nMatrix:\n0 1 1 0\n1 1 1 1\n1 1 1 1\n1 1 0 0\nOutput: 8\nExplanation: The largest rectangle with all '1's has an area of 8.\n\nEx... | 0.588666 | Taco_83908 | C | [
"max_histogram_area",
"maxRectangle"
] | 2 | [
[
"maxRectangle",
"max_histogram_area"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 60e5ae6614b74fb04e611fa34a43f1b641bb7eda | 8307a06be0e1a1b898594a9dd0df7e73e70e05b1 | |||
v1.0 | complete | Taco | Taco_84090_C | def number_of_paths(N: int, M: int, K: int, rocks: List[Tuple[int, int]]) -> int:
"""
Determine the number of distinct valid paths from the top-left to the bottom-right corner without hitting any rocks.
Args:
N (int): The number of rows in the grid.
M (int): The number of columns in the grid.
... | def count_paths(N, M, K, rocks):
grid = [[0] * M for _ in range(N)]
for rock in rocks:
x, y = rock[0] - 1, rock[1] - 1
grid[x][y] = -1
if grid[0][0] == -1 or grid[N-1][M-1] == -1:
return 0
grid[0][0] = 1
for i in range(N):
for j in range(M):
if grid[i][... | from solution import number_of_paths
def test_no_obstacles():
assert number_of_paths(3, 3, 0, []) == 6
def test_with_obstacles():
assert number_of_paths(3, 3, 2, [(2, 2), (3, 1)]) == 1
def test_full_blocked_by_obstacle():
assert number_of_paths(3, 3, 1, [(1, 1)]) == 0
assert number_of_paths(3, 3, 1, ... | [
{
"docstring": null,
"function_declaration": "def count_paths(N, M, K, rocks):",
"function_name": "count_paths",
"parameter_list": "(N, M, K, rocks)"
},
{
"docstring": null,
"function_declaration": "def number_of_paths(N, M, K, rocks):",
"function_name": "number_of_paths",
"param... | [
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 count_paths(N, M, K, rocks):\n grid = [[0] * M for _ in range(N)]\n for rock in rocks:\n x, y = rock[0] - 1, rock[1] - 1\n grid[x][y] = -1\... | trial_gpt4o_0 | {
"original_instruction": "Sarah loves solving complex puzzles. One day she stumbled upon a unique grid-based puzzle game. The game consists of an NxM grid, and each cell in the grid may contain a rock. The player starts at the top-left corner (1, 1) and needs to move to the bottom-right corner (N, M). The player can... | 0.693181 | Taco_84090 | C | [
"count_paths",
"number_of_paths"
] | 2 | [
[
"number_of_paths",
"count_paths"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a64ffeb14bd7d6367967f8b288cbdf90eeb3291a | 76dbf74d9b8d3c998042c41c35a84afc1b952411 | |||
v1.0 | complete | Taco | Taco_83862_C | def unique_employees_in_projects(input_data: str) -> list:
"""
Given a string representing multiple datasets of projects and
their assigned employees, determine the total number of unique employees
involved in all projects for each dataset.
>>> unique_employees_in_projects("2\nproject1:alice,... | def count_unique_employees(datasets):
"""
Count the number of unique employees involved in all projects per dataset.
"""
results = []
for dataset in datasets:
unique_employees = set()
for project in dataset:
employees = project.split(':')[1].strip('.').split(',')
... | def test_count_unique_employees():
input_data = "2\n" \
"project1:alice,bob,charlie.\n" \
"project2:bob,dave,eve.\n" \
"3\n" \
"projectA:frank,grace,heidi.\n" \
"projectB:heidi,ivan.\n" \
"projectC:frank,judy.\n" \... | [
{
"docstring": "Count the number of unique employees involved in all projects per dataset.",
"function_declaration": "def count_unique_employees(datasets):",
"function_name": "count_unique_employees",
"parameter_list": "(datasets)"
},
{
"docstring": "Parse the input data into a list of datas... | [
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 count_unique_employees(datasets):\n \"\"\"\n Given datasets of projects and their associated employees, return the number of unique employees\n involv... | trial_gpt4o_1 | {
"original_instruction": "Consider a company where each employee can work on multiple projects and each project team can consist of multiple employees. The relationship between employees and projects can be represented as a bipartite graph where each employee or project is a node, and an edge between an employee and... | 0.658688 | Taco_83862 | C | [
"count_unique_employees",
"parse_input",
"unique_employees_in_projects"
] | 3 | [
[
"unique_employees_in_projects",
"count_unique_employees"
],
[
"unique_employees_in_projects",
"parse_input"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | false | [] | true | 8f9a90564806f7492d3951ccc034439ce439f7ef | da3b36e030fae12060055fc40539d22d29aab048 | |||
v1.0 | complete | Taco | Taco_84368_C | from collections import deque
from typing import Tuple
def is_within_bounds(x: int, y: int) -> bool:
""" Check if the position is within the bounds of a standard 8x8 chessboard. """
return 1 <= x <= 8 and 1 <= y <= 8
def min_knight_moves(start_x: int, start_y: int, end_x: int, end_y: int) -> int:
"""
... | from collections import deque
def is_within_bounds(x, y):
return 1 <= x <= 8 and 1 <= y <= 8
def min_knight_moves(start_x, start_y, end_x, end_y):
if start_x == end_x and start_y == end_y:
return 0
moves = [
(2, 1), (1, 2), (-1, 2), (-2, 1),
(-2, -1), (-1, -2), (1, -2), (2, -1... | import pytest
from solution import min_knight_moves
def test_min_knight_moves():
assert min_knight_moves(1, 1, 8, 8) == 6
assert min_knight_moves(4, 5, 4, 5) == 0
assert min_knight_moves(1, 1, 2, 3) == 1
assert min_knight_moves(1, 1, 3, 2) == 1
assert min_knight_moves(1, 1, 4, 5) == 3
assert mi... | [
{
"docstring": null,
"function_declaration": "def is_within_bounds(x, y):",
"function_name": "is_within_bounds",
"parameter_list": "(x, y)"
},
{
"docstring": null,
"function_declaration": "def min_knight_moves(start_x, start_y, end_x, end_y):",
"function_name": "min_knight_moves",
... | [
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 is_within_bounds(x, y):\n return 1 <= x <= 8 and 1 <= y <= 8\n\ndef min_knight_moves(start_x, start_y, end_x, end_y):\n ... | trial_gpt4o_0 | {
"original_instruction": "Write a program that calculates the shortest path for a knight in a standard 8x8 chessboard from a given starting position to a target position. The knight can move to any of the eight positions as per standard chess rules.\n\nConstraints\n\n* The input positions $(x_1, y_1)$ and $(x_2, y_2... | 0.622069 | Taco_84368 | C | [
"is_within_bounds",
"min_knight_moves"
] | 2 | [
[
"min_knight_moves",
"is_within_bounds"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 12f8960a410e30d839d3c6c83e5f23e4187f2f82 | c293cae0f9e74a6378114565afd29bbd0ac03f2b | |||
v1.0 | complete | Taco | Taco_84435_C | def main(V: int, E: int, edges: List[Tuple[int, int, int]]) -> int:
""" Find the minimum total effort needed to connect all points in the garden.
>>> main(4, 5, [(1, 2, 1), (1, 3, 4), (2, 3, 2), (2, 4, 3), (3, 4, 5)])
6
>>> main(4, 3, [(1, 2, 1), (2, 3, 2), (3, 4, 3)])
6
>>> main(1, 0, [])
0... | def find(parent, i):
if parent[i] == i:
return i
return find(parent, parent[i])
def union(parent, rank, x, y):
root_x = find(parent, x)
root_y = find(parent, y)
if rank[root_x] < rank[root_y]:
parent[root_x] = root_y
elif rank[root_x] > rank[root_y]:
parent[root_y] ... | from solution import main
def test_example_case():
V = 4
E = 5
edges = [
(1, 2, 1),
(1, 3, 4),
(2, 3, 2),
(2, 4, 3),
(3, 4, 5)
]
assert main(V, E, edges) == 6
def test_disconnected_graph():
V = 4
E = 3
edges = [
(1, 2, 1),
(2... | [
{
"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,
1,
0
] | 1 | hard | 0.25 | {
"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 return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n rootX = find(parent, x)\n... | trial_gpt4o_3 | {
"original_instruction": "Alex is building a small water supply network for his garden. He has a set of water pipes each connecting two points in the garden, forming a connected network. Each pipe has an associated cost, representing the effort needed to install that pipe. Alex wants to minimize the total effort req... | 0.605325 | Taco_84435 | C | [
"find",
"union",
"min_spanning_tree_cost",
"main"
] | 4 | [
[
"min_spanning_tree_cost",
"find"
],
[
"min_spanning_tree_cost",
"union"
],
[
"union",
"find"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | b112feab76fac8a14b424e6f5c94802a0d2f3471 | b71e48e541c4342d2ecd5b4fb468dde1692f115d | |||
v1.0 | complete | Taco | Taco_84556_C | def fibonacci_tree_level(n: int) -> List[int]:
"""
Prints the labels of the nodes at level n from left to right.
>>> fibonacci_tree_level(0) [1]
>>> fibonacci_tree_level(1) [1]
>>> fibonacci_tree_level(2) [1, 0]
>>> fibonacci_tree_level(3) [1, 0, 1, 1]
>>> fibonacci_tree_level(6) [1, 0, 1, ... | def fibonacci(n):
"""
Compute the nth Fibonacci number.
"""
if n == 0:
return 0
elif n == 1:
return 1
else:
return fibonacci(n-1) + fibonacci(n-2)
def fibonacci_tree_level(n):
"""
Prints the labels of the nodes at level n from left to right.
"""
if n == 0... | from solution import fibonacci_tree_level
def test_fibonacci_tree_level_0():
assert fibonacci_tree_level(0) == [1]
def test_fibonacci_tree_level_1():
assert fibonacci_tree_level(1) == [1]
def test_fibonacci_tree_level_2():
assert fibonacci_tree_level(2) == [1, 0]
def test_fibonacci_tree_level_3():
a... | [
{
"docstring": "Compute the nth Fibonacci number.",
"function_declaration": "def fibonacci(n):",
"function_name": "fibonacci",
"parameter_list": "(n)"
},
{
"docstring": "Prints the labels of the nodes at level n from left to right.",
"function_declaration": "def fibonacci_tree_level(n):"... | [
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 fibonacci_tree_labels(n):\n \"\"\"\n Returns the labels of nodes at level n in the Fibonacci tree.\n \"\"\"\n def fibonacci(k):\n if k == 0:... | trial_gpt4o_1 | {
"original_instruction": "In a mysterious forest, there is a very special tree known as the Fibonacci Tree. The Fibonacci tree's structure follows the Fibonacci sequence in a unique way.\n\nThe tree grows according to the following rules:\n- The root (level 0) starts as a single node labeled `1`.\n- The first level ... | 0.663961 | Taco_84556 | C | [
"fibonacci",
"fibonacci_tree_level"
] | 2 | [
[
"fibonacci_tree_level",
"fibonacci"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4e726358b0461611127befd549922cc53dcb502c | adfc7b1c76fc479aa964c57c162b2f32b4d4cd4a | |||
v1.0 | complete | Taco | Taco_84355_C | import math
from typing import List, Tuple
def distance(x1: int, y1: int, x2: int, y2: int) -> float:
""" Calculate the Euclidean distance between two points (x1, y1) and (x2, y2).
>>> distance(0, 0, 3, 4)
5.0
>>> distance(1, 2, 1, 2)
0.0
>>> distance(-1, -1, 1, 1)
2.828427
"""
def... | import math
def distance(x1, y1, x2, y2):
return math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
def minimum_distance(x1, y1, x2, y2, Ax, Ay, Bx, By):
direct_distance = distance(x1, y1, x2, y2)
# Using teleportation from A to B
via_teleportation1 = distance(x1, y1, Ax, Ay) + distance(Bx, By, x2, y2)
... | from solution import distance, minimum_distance, teleportation_experiment
def test_distance():
assert math.isclose(distance(0, 0, 3, 4), 5.0, rel_tol=1e-6)
assert math.isclose(distance(1, 2, 1, 2), 0.0, rel_tol=1e-6)
assert math.isclose(distance(-1, -1, 1, 1), 2.828427, rel_tol=1e-6)
def test_minimum_dist... | [
{
"docstring": null,
"function_declaration": "def distance(x1, y1, x2, y2):",
"function_name": "distance",
"parameter_list": "(x1, y1, x2, y2)"
},
{
"docstring": null,
"function_declaration": "def minimum_distance(x1, y1, x2, y2, Ax, Ay, Bx, By):",
"function_name": "minimum_distance"... | [
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 calc_min_distance(x1, y1, x2, y2, Ax, Ay, Bx, By):\n from math import sqrt\n \n def distance(px, py, qx, qy):\n return sqrt((qx - px)**2 + (qy ... | trial_gpt4o_2 | {
"original_instruction": "Dr. Frank is working on a teleportation experiment. He has set up two teleportation anchors A and B at fixed positions on a 2D Cartesian plane. To test the efficiency of teleportation between any two points, he has to determine the shortest path a person can take if teleportation between an... | 0.667989 | Taco_84355 | C | [
"distance",
"minimum_distance",
"teleportation_experiment"
] | 3 | [
[
"minimum_distance",
"distance"
],
[
"teleportation_experiment",
"minimum_distance"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 19c68b7da2ddd97e7ee855aadf208a78783b4981 | 8ff3a2d09e7d5b821f1bcf5a3b5172f163d95c1f | |||
v1.0 | complete | Taco | Taco_84307_C | from typing import List, Set, Union
def word_ladder(start: str, end: str, word_list: Set[str]) -> Union[List[str], str]:
""" Find the shortest word ladder from start to end changing one letter at a time,
where each intermediate word must also be a valid word in the given dictionary.
>>> word_ladder("h... | from collections import deque
def find_neighbors(word, word_list):
neighbors = []
for w in word_list:
if sum(1 for a, b in zip(word, w) if a != b) == 1:
neighbors.append(w)
return neighbors
def word_ladder(start, end, word_list):
if start == end:
return [start]
wor... | from solution import word_ladder
def test_word_ladder_simple_case():
start = "hit"
end = "cog"
words = {"hot", "dot", "dog", "lot", "log", "cog"}
assert word_ladder(start, end, words) == ["hit", "hot", "dot", "dog", "cog"]
def test_word_ladder_no_possible_ladder():
start = "hit"
end = "cog"
... | [
{
"docstring": null,
"function_declaration": "def find_neighbors(word, word_list):",
"function_name": "find_neighbors",
"parameter_list": "(word, word_list)"
},
{
"docstring": null,
"function_declaration": "def word_ladder(start, end, word_list):",
"function_name": "word_ladder",
... | [
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 deque\n\ndef word_ladder(start, end, word_dict):\n \"\"\"\n Finds the shortest word ladder from start to end using the given word dic... | trial_gpt4o_3 | {
"original_instruction": "> In recreational mathematics, a word ladder is a word game invented by Lewis Carroll in which players find a path between two words by changing one letter at a time. Each intermediate word must also be a valid word. For instance, a word ladder between \"hit\" and \"cog\" might be: \"hit\" ... | 0.619491 | Taco_84307 | C | [
"find_neighbors",
"word_ladder"
] | 2 | [
[
"word_ladder",
"find_neighbors"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0f57665f498a06f1026107804e3980f89765cd28 | db6e5a81df0d8887feafa9f9b5da7a885ce060c0 | |||
v1.0 | complete | Taco | Taco_84494_C | def k_chunk_sums(arr, k):
"""Compute the smallest and largest sum of k-chunks."""
pass
def process_operations(n, m, k, arr, operations):
"""Process the operations and return the results for each type 2 operation.
>>> process_operations(5, 3, 3, [1, 3, 2, 4, 5], [[2], [1, 3, 6], [2]])
[(6, 11),... | def k_chunk_sums(arr, k):
"""Compute the smallest and largest sum of k-chunks."""
if len(arr) < k:
return None, None
n = len(arr)
curr_sum = sum(arr[:k])
min_sum, max_sum = curr_sum, curr_sum
for i in range(1, n - k + 1):
curr_sum = curr_sum - arr[i - 1] + arr[i + k - 1]
... | from solution import k_chunk_sums, process_operations
def test_k_chunk_sums():
assert k_chunk_sums([1, 2, 3, 4, 5], 3) == (6, 12)
assert k_chunk_sums([-1, -2, -3, -4, -5], 2) == (-9, -3)
def test_process_operations():
n, m, k = 5, 3, 3
arr = [1, 3, 2, 4, 5]
operations = [
[2],
[1, ... | [
{
"docstring": "Compute the smallest and largest sum of k-chunks.",
"function_declaration": "def k_chunk_sums(arr, k):",
"function_name": "k_chunk_sums",
"parameter_list": "(arr, k)"
},
{
"docstring": null,
"function_declaration": "def process_operations(n, m, k, arr, operations):",
... | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
1
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def k_chunk_operations(n, m, k, arr, operations):\n def calculate_s_min_s_max(arr, k):\n current_sum = sum(arr[:k])\n s_min = s_max = current_sum\... | trial_gpt4o_9 | {
"original_instruction": "You are given an array of integers `arr` of length `n` and two positive integers `m` and `k`.\n\nWe define a k-chunk of an array as a contiguous subarray of length k. For example, if `arr = [1, 2, 3, 4, 5]` and k = 3, then [1, 2, 3], [2, 3, 4], and [3, 4, 5] are the k-chunks of `arr`.\n\nLe... | 0.58727 | Taco_84494 | C | [
"k_chunk_sums",
"process_operations"
] | 2 | [
[
"process_operations",
"k_chunk_sums"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b3e4fb3077b78ea10c409e649538a3d93fcff9ad | 496bc72937c82f1440a567790c0f6b08cb27ac1e | |||
v1.0 | complete | Taco | Taco_84501_C | def find(parent, i):
""" Find the set of an element i (uses path compression technique). """
pass
def union(parent, rank, x, y):
""" Do a union of two sets of x and y (uses union by rank). """
pass
def minimum_spanning_tree(N, P, edges):
"""
Given N outposts, P trade routes, and edges (u, v, ... | def find(parent, i):
if parent[i] == i:
return i
else:
return find(parent, parent[i])
def union(parent, rank, x, y):
xroot = find(parent, x)
yroot = find(parent, y)
if rank[xroot] < rank[yroot]:
parent[xroot] = yroot
elif rank[xroot] > rank[yroot]:
parent[yr... | def test_minimum_spanning_tree():
input_data = "5 6\n1 2 3\n1 3 1\n2 3 3\n2 4 6\n3 4 5\n4 5 2"
assert solve(input_data) == 11
def test_disconnected_graph():
input_data = "4 2\n1 2 3\n3 4 2"
assert solve(input_data) == -1
def test_single_node_no_edges():
input_data = "1 0"
assert solve(input_da... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"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, x):\n if self.pare... | trial_gpt4o_2 | {
"original_instruction": "In a distant galaxy, the interstellar trading network consists of N trading outposts, each uniquely identified by an index from 1 to N. Each outpost potentially trades with other outposts directly via trade routes that connect them. Each trade route has a specific trade cost associated with... | 0.648367 | Taco_84501 | C | [
"find",
"union",
"minimum_spanning_tree",
"solve"
] | 4 | [
[
"minimum_spanning_tree",
"find"
],
[
"minimum_spanning_tree",
"union"
],
[
"solve",
"minimum_spanning_tree"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | false | [] | true | 136f83bfa0781dc0f6f77a1637704ca0a7598fb7 | 59af19a8aa1d65966cf33db489bd3a7a542c6ac0 | |||
v1.0 | complete | Taco | Taco_84688_C | def is_palindromic(number: int) -> bool:
""" Checks if a given number is palindromic.
>>> is_palindromic(1)
True
>>> is_palindromic(121)
True
>>> is_palindromic(1331)
True
>>> is_palindromic(1221)
True
>>> is_palindromic(10)
False
"""
def count_palindromic_numbers(n:... | def is_palindromic(number):
"""
Checks if a given number is palindromic.
"""
s = str(number)
return s == s[::-1]
def count_palindromic_numbers(n):
"""
Counts how many positive integers up to n are palindromic.
"""
count = 0
for i in range(1, n + 1):
if is_palindromic(i):... | from solution import is_palindromic, count_palindromic_numbers
def test_is_palindromic():
assert is_palindromic(1) == True
assert is_palindromic(121) == True
assert is_palindromic(1331) == True
assert is_palindromic(1221) == True
assert is_palindromic(10) == False
def test_count_palindromic_number... | [
{
"docstring": "Checks if a given number is palindromic.",
"function_declaration": "def is_palindromic(number):",
"function_name": "is_palindromic",
"parameter_list": "(number)"
},
{
"docstring": "Counts how many positive integers up to n are palindromic.",
"function_declaration": "def c... | [
0,
0,
0,
0,
1,
0,
0,
0,
0
] | 1 | hard | 0.111 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def count_palindromic_numbers(n):\n \"\"\"\n Returns the count of palindromic numbers that do not exceed n.\n \"\"\"\n def is_palindrome(x):\n s... | trial_gpt4o_5 | {
"original_instruction": "Polycarpus loves palindromic numbers. A palindromic number is a number that remains the same when its digits are reversed. For example, numbers like 121, 1331, and 1221 are palindromic.\n\nGiven an integer n, Polycarpus wants to know how many positive integers that do not exceed n are palin... | 0.74585 | Taco_84688 | C | [
"is_palindromic",
"count_palindromic_numbers"
] | 2 | [
[
"count_palindromic_numbers",
"is_palindromic"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 94a98e24de6b1b2128dbc66b45d10a935ab6fc6c | 746400c381ea902488e92b6d6153c9c10227dac7 | |||
v1.0 | complete | Taco | Taco_84358_C | from typing import List, Tuple
def shortest_path(grid: List[str], start: Tuple[int, int], end: Tuple[int, int], n: int, m: int) -> int:
""" Given a grid and start/end positions, find the shortest path between them.
Args:
grid (List[str]): The grid representation of the city where '.' is walkable, ... | from collections import deque
def shortest_path(grid, start, end, n, m):
directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]
visited = [[False]*m for _ in range(n)]
queue = deque()
queue.append((start[0], start[1], 0))
visited[start[0]][start[1]] = True
while queue:
x, y, steps = queue... | def test_cases():
return [
(2, [
((4, 4), [
"S...",
".##.",
"..#D",
"...."
]),
((5, 5), [
"S....",
"#####",
"#####",
"##D##",
"#... | [
{
"docstring": null,
"function_declaration": "def shortest_path(grid, start, end, n, m):",
"function_name": "shortest_path",
"parameter_list": "(grid, start, end, n, m)"
},
{
"docstring": null,
"function_declaration": "def solve(T, test_cases):",
"function_name": "solve",
"parame... | [
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\ndef shortest_path(T, test_cases):\n directions = [(0, 1), (1, 0), (0, -1), (-1, 0)]\n\n def bfs(n, m, grid, start, destinati... | trial_gpt4o_2 | {
"original_instruction": "A group of friends decided to explore a rectangular grid city of size n x m. Each cell in the grid represents a building, and they can walk from one building to another grid cell which is directly adjacent in one of the four directions (left, right, up, down). They start at a specific build... | 0.695237 | Taco_84358 | C | [
"shortest_path",
"solve"
] | 2 | [
[
"solve",
"shortest_path"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 1ba5b2dce811d7128911bc8034be46d49071f3f3 | 2e8c26788da07546700f7b9599dbb0fa543868e7 | |||
v1.0 | complete | Taco | Taco_84526_C | def is_important_sentence(sentence: str) -> str:
"""
Determines if a sentence is important based on the criteria.
A sentence is considered "important" if it ends with a punctuation mark
('.', '!', '?') and contains at least one capitalized word (a word which
starts with a capital letter and is... | def is_important_sentence(sentence):
"""
Determines if a sentence is important based on the criteria.
A sentence is considered "important" if it ends with a punctuation mark
('.', '!', '?') and contains at least one capitalized word (a word which
starts with a capital letter and is followed by... | from solution import is_important_sentence, sentence_importance_evaluation
def test_single_sentence_important():
# Ends with a period and contains a capitalized word "This"
assert is_important_sentence("This is a test.") == "Important"
def test_single_sentence_not_important():
# Does not end with a requir... | [
{
"docstring": "Determines if a sentence is important based on the criteria.\n\nA sentence is considered \"important\" if it ends with a punctuation mark\n('.', '!', '?') and contains at least one capitalized word (a word which \nstarts with a capital letter and is followed by lowercase letters).\n\nParameters:... | [
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_important_sentence(sentence):\n \"\"\"\n Determines if a sentence is important based on the criteria.\n \n A sentence is considered \"important\... | trial_gpt4o_0 | {
"original_instruction": "You are working on a text processing system that needs to determine the \"importance\" of certain sentences based on their structure. A sentence is considered \"important\" if it ends with a punctuation mark ('.', '!', '?') and contains at least one capitalized word (a word which starts wit... | 0.637193 | Taco_84526 | C | [
"is_important_sentence",
"sentence_importance_evaluation"
] | 2 | [
[
"sentence_importance_evaluation",
"is_important_sentence"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ebaf9cd96b80add600c1e935e2ff38e4d01ac3e7 | 0ceb8cd7ab57d3587df88174c2109e4b7bc08fab | |||
v1.0 | complete | Taco | Taco_84629_C | def can_allocate(rooms, K, max_time):
"""
Check if we can allocate rooms to staff such that no staff exceeds the given max_time.
>>> can_allocate([10, 20, 30, 40, 50], 3, 60)
True
>>> can_allocate([10, 20, 30, 40, 50], 3, 50)
False
"""
pass
def find_optimal_time(N, K, rooms):
"""
... | def can_allocate(rooms, K, max_time):
current_time = 0
staff_count = 1
for time in rooms:
if current_time + time <= max_time:
current_time += time
else:
staff_count += 1
current_time = time
if staff_count > K:
return False
... | from solution import can_allocate, find_optimal_time, minimal_cleaning_time
def test_can_allocate():
assert can_allocate([10, 20, 30, 40, 50], 3, 60) == True
assert can_allocate([10, 20, 30, 40, 50], 3, 50) == False
def test_find_optimal_time():
assert find_optimal_time(5, 3, [10, 20, 30, 40, 50]) == 60
... | [
{
"docstring": null,
"function_declaration": "def can_allocate(rooms, K, max_time):",
"function_name": "can_allocate",
"parameter_list": "(rooms, K, max_time)"
},
{
"docstring": null,
"function_declaration": "def find_optimal_time(N, K, rooms):",
"function_name": "find_optimal_time",... | [
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_possible(cleaning_times, N, K, mid):\n count = 1\n current_sum = 0\n\n for time in cleaning_times:\n if current_sum + time <= mid:\n ... | trial_gpt4o_2 | {
"original_instruction": "A large hotel chain is looking to optimize room cleaning schedules. They have K staff members available each day, and N rooms that need to be cleaned. Each room takes a different amount of time to clean, represented by an array. Each staff member can clean one room at a time, but can move t... | 0.655774 | Taco_84629 | C | [
"can_allocate",
"find_optimal_time",
"minimal_cleaning_time"
] | 3 | [
[
"find_optimal_time",
"can_allocate"
],
[
"minimal_cleaning_time",
"find_optimal_time"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | d8c1bb6e67bb54ea2a074f8b0391ffa9d0257cad | f77f5f26a3fe9e3289b02455c9238022f4e96bbe | |||
v1.0 | complete | Taco | Taco_84711_C | def is_prime(num):
"""
Check if a given number is prime.
Args:
num (int): The number to check.
Returns:
bool: True if the number is prime, False otherwise.
>>> is_prime(2)
True
>>> is_prime(4)
False
"""
pass
def get_rotations(num):
"""
Get all rotations o... | 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 get_rotations(num):
ro... | from solution import is_prime, get_rotations, is_circular_prime, find_circular_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
def test_get_rotations():
assert get_rotations(197) == [197, 971, 719]
assert ... | [
{
"docstring": null,
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def get_rotations(num):",
"function_name": "get_rotations",
"parameter_list": "(num)"
},
{
"docstring... | [
0,
0,
0,
0,
0,
0,
0,
1,
1,
0
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Check if a number is a prime number.\n \"\"\"\n if num < 2:\n return False\n if num in (2, 3):\n return ... | trial_gpt4o_7 | {
"original_instruction": "Mike is a programmer who loves numbers, especially those that are prime. Recently, he received a new challenge to test his coding skills. The task involves finding a special type of prime number known as a \"Circular Prime\".\n\nA prime number is called a circular prime if all of its rotati... | 0.692197 | Taco_84711 | C | [
"is_prime",
"get_rotations",
"is_circular_prime",
"find_circular_primes"
] | 4 | [
[
"find_circular_primes",
"is_circular_prime"
],
[
"is_circular_prime",
"get_rotations"
],
[
"is_circular_prime",
"is_prime"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 8e85c24a7da7021e09dd553279e890abe2c03831 | 88dc0cd156c32373eebbaa4ada382dbb85ba7f6d | |||
v1.0 | complete | Taco | Taco_85303_C | def count_inversions(arr: List[int]) -> int:
""" Given an array of integers, determine the number of inversions in it.
An inversion is a pair of indices (i, j) such that i < j and arr[i] > arr[j].
>>> count_inversions([8, 4, 2, 1])
6
>>> count_inversions([1, 20, 6, 4, 5])
5
>>> count_in... | def merge_and_count(arr, temp_arr, left, mid, right):
i = left # Starting index for left subarray
j = mid + 1 # Starting index for right subarray
k = left # Starting index to be sorted
inv_count = 0
while i <= mid and j <= right:
if arr[i] <= arr[j]:
temp_arr[k] = arr[i]... | def test_count_inversions():
assert count_inversions([8, 4, 2, 1]) == 6
assert count_inversions([1, 20, 6, 4, 5]) == 5
assert count_inversions([1, 2, 3, 4, 5]) == 0
assert count_inversions([5, 4, 3, 2, 1]) == 10
assert count_inversions([3, 1, 2]) == 2
assert count_inversions([1, 5, 3, 2, 4]) == ... | [
{
"docstring": null,
"function_declaration": "def merge_and_count(arr, temp_arr, left, mid, right):",
"function_name": "merge_and_count",
"parameter_list": "(arr, temp_arr, left, mid, right)"
},
{
"docstring": null,
"function_declaration": "def merge_sort_and_count(arr, temp_arr, left, r... | [
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 count_inversions(a):\n \"\"\"\n Returns the number of inversions in the array a.\n \"\"\"\n # Helper function to perform merge sort and count inver... | trial_gpt4o_1 | {
"original_instruction": "Given an array `a` of `n` integers, you need to determine the number of inversions in `a`. An inversion is a pair of indices `(i, j)` such that `i < j` and `a[i] > a[j]`.\n\nInput\n\nThe first line contains an integer `n` (1 ≤ n ≤ 100000), the number of elements in the array. The second lin... | 0.874876 | Taco_85303 | C | [
"merge_and_count",
"merge_sort_and_count",
"count_inversions"
] | 3 | [
[
"count_inversions",
"merge_sort_and_count"
],
[
"merge_sort_and_count",
"merge_and_count"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 689bab7bd18d9d8f732d48a869f0a1102cd23ba8 | a26c9b6a718c4902636c0e23856d3e4613edfe7d | |||
v1.0 | complete | Taco | Taco_84871_C | def max_subarray_sum(arr):
"""
Returns the sum of the maximum subarray using Kadane's algorithm.
>>> max_subarray_sum([1, -2, 3, 5]) == 8
>>> max_subarray_sum([-1, -2, -3]) == -1
>>> max_subarray_sum([2, 3, -2, 4]) == 7
>>> max_subarray_sum([-2, 1, -3, 4, -1, 2, 1, -5, 4]) == 6
>>> max_subar... | def max_subarray_sum(arr):
"""
Returns the sum of the maximum subarray using Kadane's algorithm.
"""
max_ending_here = max_so_far = arr[0]
for x in arr[1:]:
max_ending_here = max(x, max_ending_here + x)
max_so_far = max(max_so_far, max_ending_here)
return max_so_far
def proces... | from solution import solve, max_subarray_sum, parse_input, process_test_cases
def test_max_subarray_sum():
assert max_subarray_sum([1, -2, 3, 5]) == 8
assert max_subarray_sum([-1, -2, -3]) == -1
assert max_subarray_sum([2, 3, -2, 4]) == 7
assert max_subarray_sum([-2, 1, -3, 4, -1, 2, 1, -5, 4]) == 6
... | [
{
"docstring": "Returns the sum of the maximum subarray using Kadane's algorithm.",
"function_declaration": "def max_subarray_sum(arr):",
"function_name": "max_subarray_sum",
"parameter_list": "(arr)"
},
{
"docstring": null,
"function_declaration": "def process_test_cases(test_cases):",
... | [
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_subarray_sum(arr):\n \"\"\"\n Returns the sum of the maximum subarray for the given list of integers.\n \"\"\"\n max_current = max_global = arr... | trial_gpt4o_2 | {
"original_instruction": "Samantha has a list of integers and she wants to know the sum of the maximum subarray for each given list. A subarray is a contiguous portion of the array. Help Samantha to find the maximum subarray sum for each of the provided lists of integers.\n\nINPUT:\n\nFirst line contains the number ... | 0.666226 | Taco_84871 | C | [
"max_subarray_sum",
"process_test_cases",
"parse_input",
"solve"
] | 4 | [
[
"process_test_cases",
"max_subarray_sum"
],
[
"solve",
"parse_input"
],
[
"solve",
"process_test_cases"
]
] | 3 | [
"process_test_cases",
"parse_input"
] | false | [] | false | pytest | true | [] | true | 723b4efff97000198d1259d74e5b40fbfbeba396 | aaf00679218c933f3d6ca1aa197d052528fa7bc9 | |||
v1.0 | complete | Taco | Taco_85220_C | def organize_contests(N: int, C: int) -> str:
""" Organize an online programming competition by distributing participants
into the minimal number of simultaneous contests with each contest having a
maximum capacity of C participants.
Args:
N (int): The number of participants with unique registr... | def organize_contests(N, C):
contests = []
participants = 1
while participants <= N:
contest = []
for _ in range(C):
if participants <= N:
contest.append(participants)
participants += 1
else:
break
contests.appen... | def test_organize_contests():
output = create_output(10, 3).split("\n")
assert output[0] == "4"
assert output[1] == "3 1 2 3"
assert output[2] == "3 4 5 6"
assert output[3] == "3 7 8 9"
assert output[4] == "1 10"
def test_organize_contests_with_exact_fit():
output = create_output(8, 4).spli... | [
{
"docstring": null,
"function_declaration": "def organize_contests(N, C):",
"function_name": "organize_contests",
"parameter_list": "(N, C)"
},
{
"docstring": null,
"function_declaration": "def create_output(N, C):",
"function_name": "create_output",
"parameter_list": "(N, C)"
... | [
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 arrange_contests(N, C):\n \"\"\"\n Determine the minimal number of simultaneous contests required and how the participants \n should be distributed in... | trial_gpt4o_2 | {
"original_instruction": "A company wants to organize an online programming competition. To successfully hold the event, they have to arrange the participants in a set of simultaneous contests. Each simultaneous contest will have a maximum capacity of C participants. \n\nEach participant is given a unique registrati... | 0.663326 | Taco_85220 | C | [
"organize_contests",
"create_output"
] | 2 | [
[
"create_output",
"organize_contests"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 0381e91dc93e6afcdc8fd88756ee699caacdfcdf | 8e3b4538c51c13b1516acad15efe5ec98e69235b | |||
v1.0 | complete | Taco | Taco_85213_C | from typing import List
from functools import cmp_to_key
def compare(a, b):
"""
Custom comparison function for sorting numbers based on the concatenation.
This function compares two numbers by comparing the concatenated results
in both possible orders.
"""
if a + b > b + a:
return -1
... | from functools import cmp_to_key
def compare(a, b):
"""
Custom comparison function for sorting numbers based on the concatenation.
This function compares two numbers by comparing the concatenated results
in both possible orders.
"""
if a + b > b + a:
return -1
elif a + b < b + a:
... | import pytest
from solution import largest_concatenated_number
def test_example_1():
assert largest_concatenated_number([3, 30, 34, 5, 9]) == '9534330'
def test_example_2():
assert largest_concatenated_number([54, 546, 548, 60]) == '6054854654'
def test_single_element():
assert largest_concatenated_numbe... | [
{
"docstring": "Custom comparison function for sorting numbers based on the concatenation.\nThis function compares two numbers by comparing the concatenated results\nin both possible orders.",
"function_declaration": "def compare(a, b):",
"function_name": "compare",
"parameter_list": "(a, b)"
},
... | [
0,
0,
0,
0,
0,
1,
0,
0,
1,
1
] | 3 | hard | 0.3 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from functools import cmp_to_key\n\ndef largest_number(nums):\n \"\"\"\n Returns the largest number that can be formed by concatenating a list of non-negativ... | trial_gpt4o_9 | {
"original_instruction": "For a given list of non-negative integers, find the largest number that can be formed by concatenating the list's elements.\n\nConstraints\n\n* 1 ≤ |list| ≤ 100\n* 0 ≤ element ≤ 10^9\n\nInput\n\nn\nelement_1 element_2 ... element_n\n\n|list| is the number of elements in the list.\n\nOutput\... | 0.665444 | Taco_85213 | C | [
"compare",
"largest_concatenated_number"
] | 2 | [
[
"largest_concatenated_number",
"compare"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4173cadebf69fc1e654a081bb796ee0892764574 | 4aa324ed0e71b8d8bf161b20abd4b6b207c2d8f7 | |||
v1.0 | complete | Taco | Taco_85034_C | from typing import List
def min_moves_to_meet(M: int, N: int, x1: int, y1: int, x2: int, y2: int, board: List[str]) -> int:
""" Determine the minimum number of moves required for the two robots to meet at the same cell.
If it is impossible for the robots to meet, return -1.
>>> min_moves_to_meet(5, 5, 0, 0... | from collections import deque
def bfs(start, board, M, N):
q = deque([(start, 0)])
directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]
visited = set([start])
while q:
(x, y), dist = q.popleft()
for dx, dy in directions:
nx, ny = x + dx, y + dy
if 0 <= nx < M and 0 <... | def test_min_moves_to_meet_simple():
board = [
".....",
".#...",
".###.",
".###.",
"....."
]
assert min_moves_to_meet(5, 5, 0, 0, 4, 4, board) == 8
def test_min_moves_to_meet_impossible():
board = [
".#.",
"###",
".#."
]
assert min... | [
{
"docstring": null,
"function_declaration": "def bfs(start, board, M, N):",
"function_name": "bfs",
"parameter_list": "(start, board, M, N)"
},
{
"docstring": null,
"function_declaration": "def min_moves_to_meet(M, N, x1, y1, x2, y2, board):",
"function_name": "min_moves_to_meet",
... | [
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\ndef min_moves_to_meet(M, N, x1, y1, x2, y2, board):\n directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]\n\n def bfs(start_x, s... | trial_gpt4o_1 | {
"original_instruction": "You are given a board of dimensions M x N, where each cell is either empty ('.') or contains an obstacle ('#'). Two robots are standing at two different positions (x1, y1) and (x2, y2). Both robots can only move left, right, up, or down to adjacent cells, and they cannot move through obstac... | 0.679209 | Taco_85034 | C | [
"bfs",
"min_moves_to_meet"
] | 2 | [
[
"min_moves_to_meet",
"bfs"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | be7e7ba080c468061178f84bb40869ccfb6d974d | bcfca0c716a54b29af743ee3e862c87ec58de100 | |||
v1.0 | complete | Taco | Taco_85009_C | def archery_matches(n: int, squads: List[List[int]]) -> List[str]:
""" Determines the results of inter-squad matches and the maximum skill rating each
squad can achieve by selecting an optimal subset of its archers.
>>> archery_matches(3, [[10, 20, 30, 10], [5, 15, 10], [25, 30]])
['Squad 1 vs Squad 2:... | from itertools import combinations
def calculate_squad_sum(squad):
return sum(squad)
def max_skill_subset(squad):
# The optimal subset's sum can be the total sum of the squad itself
return sum(squad)
def archery_matches(n, squads):
results = []
# Calculate inter-squad match results
for i in r... | import pytest
from solution import archery_matches
def test_archery_matches():
n = 3
squads = [[10, 20, 30, 10], [5, 15, 10], [25, 30]]
result = archery_matches(n, squads)
expected = [
"Squad 1 vs Squad 2: Winner is Squad 1",
"Squad 1 vs Squad 3: Winner is Squad 1",
"Squad 2 vs ... | [
{
"docstring": null,
"function_declaration": "def calculate_squad_sum(squad):",
"function_name": "calculate_squad_sum",
"parameter_list": "(squad)"
},
{
"docstring": null,
"function_declaration": "def max_skill_subset(squad):",
"function_name": "max_skill_subset",
"parameter_list... | [
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 archery_competition(n, squads):\n results = []\n max_skill_ratings = []\n\n # Calculate total skill rating for each squad\n total_skill_ratings = [... | trial_gpt4o_1 | {
"original_instruction": "In a far-off kingdom, the King has set up a unique tradition involving archery skills. The kingdom has n archery squads, each with a different number of archers. Each archer competes only within their own squad and is given an initial skill rating between 0 and 100, where higher is better.\... | 0.65661 | Taco_85009 | C | [
"calculate_squad_sum",
"max_skill_subset",
"archery_matches"
] | 3 | [
[
"archery_matches",
"calculate_squad_sum"
],
[
"archery_matches",
"max_skill_subset"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | b7f7ddc97df67268370575eb994a3a5a2e218b1b | ba8f83ff2389bd30fc4b7db93d5140ad9eb6651c | |||
v1.0 | complete | Taco | Taco_85334_C | def sum_of_lowest_and_highest_primes(t: int, test_cases: List[Tuple[int, List[int]]]) -> List[int]:
""" Given an array(A) of N integers, determine the sum of the lowest and highest prime numbers in the array.
If no prime numbers are found in the array, return -1.
Arguments:
t -- number of test cases
... | def is_prime(num):
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_lowest_and_highest_primes(arr):
primes = [num for num in ... | from solution import sum_of_lowest_and_highest_primes
def test_case_1():
T = 1
test_cases = [(5, [2, 3, 4, 5, 8])]
result = sum_of_lowest_and_highest_primes(T, test_cases)
assert result == [7]
def test_case_2():
T = 1
test_cases = [(4, [10, 15, 20, 25])]
result = sum_of_lowest_and_highest_... | [
{
"docstring": null,
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def find_lowest_and_highest_primes(arr):",
"function_name": "find_lowest_and_highest_primes",
"parameter_list... | [
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_prime(n):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 ... | trial_gpt4o_1 | {
"original_instruction": "Given an array(A) of N integers, write a program to determine the sum of the lowest and highest prime numbers in the array. If no prime numbers are found in the array, return -1.\n\nA prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself.\n\nI... | 0.678253 | Taco_85334 | C | [
"is_prime",
"find_lowest_and_highest_primes",
"sum_of_lowest_and_highest_primes"
] | 3 | [
[
"find_lowest_and_highest_primes",
"is_prime"
],
[
"sum_of_lowest_and_highest_primes",
"find_lowest_and_highest_primes"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 19cba52b01015affaa6636eb557b9424b1f8d9e7 | b2ebc2e739073f02cb635f9831acfd536cf36e47 | |||
v1.0 | complete | Taco | Taco_85341_C | def minimum_adjacent_swaps(n: int, heights: List[int]) -> int:
""" Returns the minimum number of adjacent swaps required to sort the array.
>>> minimum_adjacent_swaps(3, [3, 1, 2])
2
>>> minimum_adjacent_swaps(5, [5, 4, 3, 2, 1])
10
>>> minimum_adjacent_swaps(4, [1, 2, 3, 4])
0
>>> minim... | def count_inversions(arr):
"""
Uses a modified merge sort to count inversions in the array.
"""
if len(arr) < 2:
return arr, 0
mid = len(arr) // 2
left, left_count = count_inversions(arr[:mid])
right, right_count = count_inversions(arr[mid:])
merged_arr, merge_count = merge... | from solution import minimum_adjacent_swaps
def test_example1():
assert minimum_adjacent_swaps(3, [3, 1, 2]) == 2
def test_example2():
assert minimum_adjacent_swaps(5, [5, 4, 3, 2, 1]) == 10
def test_sorted_array():
assert minimum_adjacent_swaps(4, [1, 2, 3, 4]) == 0
def test_one_element():
assert m... | [
{
"docstring": "Uses a modified merge sort to count inversions in the array.",
"function_declaration": "def count_inversions(arr):",
"function_name": "count_inversions",
"parameter_list": "(arr)"
},
{
"docstring": "Merges two sorted arrays and counts inversions.",
"function_declaration":... | [
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_inversions(arr):\n \"\"\"\n Helper function to count the number of inversions (adjacent swaps)\n required to sort the array via a modified merge... | trial_gpt4o_2 | {
"original_instruction": "There are `n` children standing in a line, each with a unique height. You are asked to determine the fewest number of adjacent swaps required to arrange the children in non-decreasing order of their heights.\n\nA single swap operation can be made to exchange the positions of two consecutive... | 0.648627 | Taco_85341 | C | [
"count_inversions",
"merge_and_count",
"minimum_adjacent_swaps"
] | 3 | [
[
"count_inversions",
"merge_and_count"
],
[
"minimum_adjacent_swaps",
"count_inversions"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | c17ec1980f0037e3d1f3fef0b4084ad62e8c45c0 | 6d7c3ce02801519be42cc567e2a974a221c2d93d | |||
v1.0 | complete | Taco | Taco_85384_C | def calculate_distances(stars):
"""
Calculate the set of distances between all pairs of stars within a constellation.
"""
# Your code here
def find_matching_constellation(known_constellations, query):
"""
Given known constellations and a query constellation, find the index of the matching known... | def calculate_distances(stars):
"""
Calculate the set of distances between all pairs of stars within a constellation.
"""
distances = []
for i in range(len(stars)):
for j in range(i + 1, len(stars)):
x1, y1 = stars[i]
x2, y2 = stars[j]
dist = (x2 - x1) ** ... | from solution import calculate_distances, find_matching_constellation
def test_calculate_distances():
stars = [(0, 0), (1, 0), (1, 1), (0, 1)]
expected_distances = [1, 1, 1, 1, 2, 2]
assert calculate_distances(stars) == expected_distances
def test_find_matching_constellation():
known_constellations = ... | [
{
"docstring": "Calculate the set of distances between all pairs of stars within a constellation.",
"function_declaration": "def calculate_distances(stars):",
"function_name": "calculate_distances",
"parameter_list": "(stars)"
},
{
"docstring": "Given known constellations and a query constel... | [
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 squared_distance(star1, star2):\n return (star1[0] - star2[0]) ** 2 + (star1[1] - star2[1]) ** 2\n\ndef constellation_fingerprint(star_coordinates):\n s ... | trial_gpt4o_1 | {
"original_instruction": "The Doctor has discovered a new signal from outer space. It contains a message cleverly disguised within star constellations. Each constellation contains a number of stars, and each star has coordinates represented in a Cartesian plane. Your task is to identify the constellation that corres... | 0.580002 | Taco_85384 | C | [
"calculate_distances",
"find_matching_constellation",
"main"
] | 3 | [
[
"find_matching_constellation",
"calculate_distances"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5a50162c6f214c15f655a2fc417f178bc69443dc | fab769cc1b8e2763064dfc30359a91b6b8f42351 | |||
v1.0 | complete | Taco | Taco_85467_C | def max_unique_rows_and_columns(grid):
"""
Returns the maximum number of unique rows and columns that can be achieved by replicating existing rows or columns.
"""
# TO DO: Implement the function to find the maximum number of unique rows and columns
pass
def process_input_and_solve(input_str):
"... | def max_unique_rows_and_columns(grid):
"""
Returns the maximum number of unique rows and columns that can be achieved by replicating existing rows or columns.
"""
n = len(grid)
m = len(grid[0])
unique_rows = {tuple(row) for row in grid}
unique_columns = {tuple(grid[i][j] for i in range(n)) ... | from solution import process_input_and_solve
def test_case_1():
input_str = "3 3\n101\n010\n100"
assert process_input_and_solve(input_str) == (3, 3)
def test_case_2():
input_str = "3 3\n111\n101\n111"
assert process_input_and_solve(input_str) == (2, 2)
def test_case_3():
input_str = "4 4\n1010\n0... | [
{
"docstring": "Returns the maximum number of unique rows and columns that can be achieved by replicating existing rows or columns.",
"function_declaration": "def max_unique_rows_and_columns(grid):",
"function_name": "max_unique_rows_and_columns",
"parameter_list": "(grid)"
},
{
"docstring":... | [
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 max_unique_rows_cols(grid):\n n = len(grid)\n m = len(grid[0])\n \n # Using sets to count unique rows and cols\n unique_rows = set()\n unique... | trial_gpt4o_2 | {
"original_instruction": "Dominic is a passionate gardener who loves unique flowers. He grows flowers in his garden in specific patterns. The layout of his garden is represented as an N x M grid, where each cell can either contain a flower (represented by a 1) or be empty (represented by a 0). Dominic can replicate ... | 0.589 | Taco_85467 | C | [
"max_unique_rows_and_columns",
"process_input_and_solve"
] | 2 | [
[
"process_input_and_solve",
"max_unique_rows_and_columns"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e37bfdc314a88a4e14cc5365e48f6fb0a97396ac | e295ee099b1b6d1a5cc69866a97835f44d0ca40f | |||
v1.0 | complete | Taco | Taco_85251_C | from typing import List, Union
from collections import defaultdict, deque
def detect_cycles(n: int, adj_list: List[List[int]]) -> bool:
"""
Detect if a graph has cycles using Kahn's Algorithm (topological sort).
Returns True if there is a cycle, False otherwise.
"""
def find_top_level_species(n: int, ... | from collections import defaultdict, deque
def detect_cycles(n, adj_list):
"""
Detect if a graph has cycles using Kahn's Algorithm (topological sort).
Returns True if there is a cycle, False otherwise.
"""
in_degree = {i: 0 for i in range(1, n + 1)}
for u in adj_list:
for v in adj_list[... | import pytest
from solution import ecosystem_simulation
def test_ecosystem_with_cycle():
n = 4
m = 4
edges = [(1, 2), (2, 3), (3, 1), (3, 4)]
assert ecosystem_simulation(n, m, edges) == "Cycle"
def test_ecosystem_no_cycle_with_one_top_level():
n = 3
m = 2
edges = [(1, 2), (2, 3)]
asser... | [
{
"docstring": "Detect if a graph has cycles using Kahn's Algorithm (topological sort).\nReturns True if there is a cycle, False otherwise.",
"function_declaration": "def detect_cycles(n, adj_list):",
"function_name": "detect_cycles",
"parameter_list": "(n, adj_list)"
},
{
"docstring": "Find... | [
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": "from collections import defaultdict, deque\n\ndef detect_cycles(n, adj_list):\n \"\"\"\n Detect if a graph has cycles using Kahn's Algorithm (topological sor... | trial_gpt4o_0 | {
"original_instruction": "A university research lab is developing a simulation of an ecosystem containing various types of species, represented as a directed graph. There are n species in the simulation, and some species prey upon others. Each species is identified by a unique integer from 1 to n. If a species A pre... | 0.499184 | Taco_85251 | C | [
"detect_cycles",
"find_top_level_species",
"ecosystem_simulation"
] | 3 | [
[
"ecosystem_simulation",
"detect_cycles"
],
[
"ecosystem_simulation",
"find_top_level_species"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 1ea1e16cb787297cdc4e63c7b21c3c514135aeae | ddfa7f4b3d3259b7157f3c0ffda3bcc86f6ade9c | |||
v1.0 | complete | Taco | Taco_85535_C | MOD = 1000000007
def fibonacci(n):
""" Returns the nth Fibonacci number modulo MOD using matrix exponentiation.
>>> fibonacci(0) == 0
>>> fibonacci(1) == 1
>>> fibonacci(5) == 5
>>> fibonacci(10) == 55
>>> fibonacci(50) == 12586269025 % 1000000007
>>> fibonacci(100) == 354224848179261915075... | MOD = 1000000007
def matrix_mult(A, B):
"""Multiplies two 2x2 matrices A and B under modulo MOD."""
return [
[(A[0][0] * B[0][0] + A[0][1] * B[1][0]) % MOD,
(A[0][0] * B[0][1] + A[0][1] * B[1][1]) % MOD],
[(A[1][0] * B[0][0] + A[1][1] * B[1][0]) % MOD,
(A[1][0] * B[0][1] + A[1... | from solution import fibonacci
def test_fibonacci_0():
assert fibonacci(0) == 0
def test_fibonacci_1():
assert fibonacci(1) == 1
def test_fibonacci_5():
assert fibonacci(5) == 5
def test_fibonacci_10():
assert fibonacci(10) == 55
def test_fibonacci_50():
assert fibonacci(50) == 12586269025 % 10... | [
{
"docstring": "Multiplies two 2x2 matrices A and B under modulo MOD.",
"function_declaration": "def matrix_mult(A, B):",
"function_name": "matrix_mult",
"parameter_list": "(A, B)"
},
{
"docstring": "Computes matrix raised to the power under modulo MOD.",
"function_declaration": "def mat... | [
0,
0,
0,
0,
0,
0,
0,
1
] | 1 | hard | 0.125 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "MOD = 1000000007\n\ndef matrix_multiply(A, B):\n return [\n [(A[0][0] * B[0][0] + A[0][1] * B[1][0]) % MOD, (A[0][0] * B[0][1] + A[0][1] * B[1][1]) % MOD... | trial_gpt4o_9 | {
"original_instruction": "A young programmer loves Fibonacci numbers and plays a game of coding challenges. In one of the challenges, he needs to compute the Nth number in the Fibonacci sequence efficiently. Knowing that the standard recursive approach is too slow for large N, he seeks help to implement it using mat... | 0.757475 | Taco_85535 | C | [
"matrix_mult",
"matrix_pow",
"fibonacci"
] | 3 | [
[
"fibonacci",
"matrix_pow"
],
[
"matrix_pow",
"matrix_mult"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | a6fba5c2e20747ae63b819e9bb127a313c17990f | d0c8008712e25732a38f64352804bdeea570a53a | |||
v1.0 | complete | Taco | Taco_84958_C | def answer_queries(n, m, roads_data, q, queries_data):
""" Given the number of cities (n), number of roads (m), roads data (roads_data),
the number of queries (q), and queries data (queries_data),
return the minimum travel time between the queried cities. If no path exists, return -1.
Parameters:
... | def floyd_warshall(n, roads, queries):
# Initialize distances matrix with infinity
inf = float('inf')
dist = [[inf] * n for _ in range(n)]
# Distance to self is 0
for i in range(n):
dist[i][i] = 0
# Populate the direct roads
for u, v, t in roads:
dist[u-1][v-1] ... | from solution import answer_queries
def test_example_case_1():
n = 4
m = 4
roads_data = [
(1, 2, 5),
(1, 3, 10),
(2, 3, 2),
(3, 4, 1)
]
q = 3
queries_data = [
(1, 4),
(2, 3),
(1, 3)
]
expected = [8, 2, 7]
assert answer_queries(... | [
{
"docstring": null,
"function_declaration": "def floyd_warshall(n, roads, queries):",
"function_name": "floyd_warshall",
"parameter_list": "(n, roads, queries)"
},
{
"docstring": null,
"function_declaration": "def answer_queries(n, m, roads_data, q, queries_data):",
"function_name":... | [
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 floyd_warshall(n, roads, queries):\n # Initialize the distance matrix with infinities\n inf = float('inf')\n dist = [[inf] * n for _ in range(n)]\n ... | trial_gpt4o_2 | {
"original_instruction": "In a distant land, the Kingdom of Arryn is famous for its peculiar roads system. The kingdom consists of n cities connected by m bi-directional roads, and each road connects a pair of cities with a given travel time. The kingdom's ruler has recently become interested in the shortest travel ... | 0.725576 | Taco_84958 | C | [
"floyd_warshall",
"answer_queries"
] | 2 | [
[
"answer_queries",
"floyd_warshall"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6546c129d2b0172804ec6d2e7bb00c1f223affd0 | 1e133269ad40aad2091d786b9da0efa4be538987 | |||
v1.0 | complete | Taco | Taco_85471_C | def longest_common_subsequence(X: str, Y: str) -> int:
""" Returns the length of longest common subsequence between two strings.
"""
m = len(X)
n = len(Y)
# Create a DP table to store lengths of longest common subsequence
dp = [[0] * (n+1) for _ in range(m+1)]
# Build dp[m+1][n+1] in botto... | def longest_common_subsequence(X, Y):
m = len(X)
n = len(Y)
# Create a DP table to store lengths of longest common subsequence
# for subproblems
dp = [[None]*(n+1) for _ in range(m+1)]
# Build dp[m+1][n+1] in bottom up fashion
for i in range(m+1):
for j in range(n+1):
i... | from solution import most_unique_species
def test_basic():
assert most_unique_species(3, ["oak", "maple", "fir"]) == "fir"
def test_duplicate_species():
assert most_unique_species(4, ["oak", "oak", "oak", "maple"]) == "maple"
def test_single_species():
assert most_unique_species(1, ["pine"]) == "pine"
d... | [
{
"docstring": null,
"function_declaration": "def longest_common_subsequence(X, Y):",
"function_name": "longest_common_subsequence",
"parameter_list": "(X, Y)"
},
{
"docstring": null,
"function_declaration": "def most_unique_species(n, species_list):",
"function_name": "most_unique_s... | [
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 longest_common_subsequence(X, Y):\n m = len(X)\n n = len(Y)\n\n # Create a DP table to store lengths of longest common subsequence\n # for subprobl... | trial_gpt4o_0 | {
"original_instruction": "A botany enthusiast is cataloging various tree species in a vast forest. Each species of tree can be represented by a string made up of lowercase letters, where each character signifies a distinctive attribute. He wants to identify the most unique tree species by finding a tree species that... | 0.600423 | Taco_85471 | C | [
"longest_common_subsequence",
"most_unique_species"
] | 2 | [
[
"most_unique_species",
"longest_common_subsequence"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 045706c29b32e9f50bcadd0868533ff66fd3962c | 4e460d201a9cd8983167eccef4ea2fed3ff243d2 | |||
v1.0 | complete | Taco | Taco_85437_C | def prepare_prefix_sums(arr):
"""
Prepares the prefix sums array for the given input array.
"""
# Your code goes here
def query_sum(prefix_sums, l, r):
"""
Returns the sum of the subarray from index l to index r.
"""
# Your code goes here
def process_queries(n, queries, arr):
"""
... | def prepare_prefix_sums(arr):
"""
Prepares the prefix sums array for the given input array.
"""
n = len(arr)
prefix_sums = [0] * (n + 1)
for i in range(n):
prefix_sums[i + 1] = prefix_sums[i] + arr[i]
return prefix_sums
def query_sum(prefix_sums, l, r):
"""
Returns the sum o... | from solution import prepare_prefix_sums, query_sum, process_queries
def test_prepare_prefix_sums():
arr = [1, 2, 3, 4, 5]
assert prepare_prefix_sums(arr) == [0, 1, 3, 6, 10, 15]
def test_query_sum():
prefix_sums = [0, 1, 3, 6, 10, 15]
assert query_sum(prefix_sums, 1, 3) == 6
assert query_sum(pref... | [
{
"docstring": "Prepares the prefix sums array for the given input array.",
"function_declaration": "def prepare_prefix_sums(arr):",
"function_name": "prepare_prefix_sums",
"parameter_list": "(arr)"
},
{
"docstring": "Returns the sum of the subarray from index l to index r.",
"function_d... | [
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 preprocess_array(arr):\n \"\"\"\n Preprocesses the array to compute prefix sums.\n \"\"\"\n prefix_sums = [0] * (len(arr) + 1)\n for i in range(... | trial_gpt4o_2 | {
"original_instruction": "You are given an array of integers and a set of queries. Each query asks for the sum of a subarray within a given range. More formally, you need to process multiple queries of the following form:\n\nFind the sum of the elements from index l to index r (inclusive) in the array.\n\nInput\n\nT... | 0.551067 | Taco_85437 | C | [
"prepare_prefix_sums",
"query_sum",
"process_queries"
] | 3 | [
[
"process_queries",
"prepare_prefix_sums"
],
[
"process_queries",
"query_sum"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | true | [] | true | 45aa3c5f575f410887cc11cdff045e1d8e4bb7d0 | f90c27a988ee1fa80e4c38a129a566d7dee57074 | |||
v1.0 | complete | Taco | Taco_85588_C | def is_factorial_number(n):
"""
Determines if n is a factorial number.
"""
# Your code here
def print_factorial_numbers(L, numbers):
"""
Prints all factorial numbers from the list in ascending order,
each on a new line.
"""
# Your code here | def is_factorial_number(n):
"""
Determines if n is a factorial number.
"""
if n == 1:
return True
f = 1
i = 1
while f < n:
i += 1
f *= i
return f == n
def print_factorial_numbers(L, numbers):
"""
Prints all factorial numbers from the list in ascending ord... | import io
import sys
import pytest
from solution import is_factorial_number, print_factorial_numbers
def test_is_factorial_number():
assert is_factorial_number(1) == True
assert is_factorial_number(2) == True
assert is_factorial_number(6) == True
assert is_factorial_number(24) == True
assert is_fac... | [
{
"docstring": "Determines if n is a factorial number.",
"function_declaration": "def is_factorial_number(n):",
"function_name": "is_factorial_number",
"parameter_list": "(n)"
},
{
"docstring": "Prints all factorial numbers from the list in ascending order,\neach on a new line.",
"functi... | [
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 sys\nimport math\n\ndef generate_factorial_numbers(up_to):\n \"\"\"\n Generates a set of factorial numbers up to a given limit 'up_to'.\n \"\"\"\n ... | trial_gpt4o_2 | {
"original_instruction": "You are given a list of integers. For each integer, if it is a factorial number, print it; otherwise, continue to the next integer. A factorial number is a number that can be written as n! (n factorial) for some non-negative integer n.\n\nConstraints\n\n* 1 \\leq L \\leq 10^6 (length of the... | 0.693315 | Taco_85588 | C | [
"is_factorial_number",
"print_factorial_numbers"
] | 2 | [
[
"print_factorial_numbers",
"is_factorial_number"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0df9a3b28f7ed761493401235999210aa58589d9 | 5f4615033b73b6ad0e00c7d1041df5593e11a48c | |||
v1.0 | complete | Taco | Taco_85462_C | from typing import List
def maxSubArraySum(arr: List[int]) -> int:
""" Finds the maximum sum of any contiguous subarray of the array.
>>> maxSubArraySum([-2,1,-3,4,-1,2,1,-5,4])
6
>>> maxSubArraySum([1])
1
>>> maxSubArraySum([5,4,-1,7,8])
23
"""
from solution import maxSubArraySum
def... | from typing import List
def maxCrossingSum(arr: List[int], left: int, mid: int, right: int) -> int:
sum_left = float('-inf')
sum_temp = 0
for i in range(mid, left - 1, -1):
sum_temp += arr[i]
if sum_temp > sum_left:
sum_left = sum_temp
sum_right = float('-inf')
sum_tem... | from solution import maxSubArraySum
def test_maxSubArraySum_example1():
assert maxSubArraySum([-2,1,-3,4,-1,2,1,-5,4]) == 6
def test_maxSubArraySum_example2():
assert maxSubArraySum([1]) == 1
def test_maxSubArraySum_example3():
assert maxSubArraySum([5,4,-1,7,8]) == 23
def test_maxSubArraySum_single_neg... | [
{
"docstring": null,
"function_declaration": "def maxCrossingSum(arr, left, mid, right):",
"function_name": "maxCrossingSum",
"parameter_list": "(arr, left, mid, right)"
},
{
"docstring": null,
"function_declaration": "def maxSubArraySumUtil(arr, left, right):",
"function_name": "max... | [
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 typing import List\n\ndef maxSubArraySum(arr: List[int]) -> int:\n def find_max_crossing_subarray(arr, low, mid, high):\n left_sum = float('-inf')\n... | trial_gpt4o_2 | {
"original_instruction": "Given an array of integers `arr`, you need to find and return the maximum sum of any contiguous subarray of the array. A subarray is a contiguous part of an array. \n\nYour task is to implement the function `maxSubArraySum` that takes an array `arr` as input and returns an integer represent... | 0.722165 | Taco_85462 | C | [
"maxCrossingSum",
"maxSubArraySumUtil",
"maxSubArraySum"
] | 3 | [
[
"maxSubArraySum",
"maxSubArraySumUtil"
],
[
"maxSubArraySumUtil",
"maxCrossingSum"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 4835b4a75db1580aadc2ebade51795df3de5bf0b | 99a5076a264c7c44a5d515c522ff383933301fe5 | |||
v1.0 | complete | Taco | Taco_85699_C | def maximal_rectangle(matrix: List[List[int]]) -> int:
""" Determine the size of the largest contiguous subgrid containing only `1`s.
>>> maximal_rectangle([
... [1, 1, 0, 0, 1],
... [1, 1, 0, 1, 1],
... [1, 1, 1, 1, 1],
... [0, 0, 1, 1, 1]
... ]) == 6
>>> maximal_re... | def maximal_rectangle(matrix):
if not matrix:
return 0
max_area = 0
m, n = len(matrix), len(matrix[0])
heights = [0] * n
for i in range(m):
for j in range(n):
if matrix[i][j] == 0:
heights[j] = 0
else:
heights[j] += 1
... | def test_maximal_rectangle():
assert maximal_rectangle([
[1, 1, 0, 0, 1],
[1, 1, 0, 1, 1],
[1, 1, 1, 1, 1],
[0, 0, 1, 1, 1]
]) == 6
def test_maximal_rectangle_single_row():
assert maximal_rectangle([
[1, 1, 1, 1]
]) == 4
assert maximal_rectangle([
[1,... | [
{
"docstring": null,
"function_declaration": "def maximal_rectangle(matrix):",
"function_name": "maximal_rectangle",
"parameter_list": "(matrix)"
},
{
"docstring": null,
"function_declaration": "def largest_rectangle_area(heights):",
"function_name": "largest_rectangle_area",
"pa... | [
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 maximal_rectangle(matrix):\n if not matrix:\n return 0\n\n max_area = 0\n m, n = len(matrix), len(matrix[0])\n heights = [0] * n\n\n for ... | trial_gpt4o_0 | {
"original_instruction": "After a long day of working with HTML, Lisa wants to relax by playing a game. The game consists of a grid with `m` rows and `n` columns, where each cell contains either a `0` or a `1`. The objective of the game is to find the largest contiguous subgrid that contains only `1`s. Help Lisa det... | 0.705681 | Taco_85699 | C | [
"maximal_rectangle",
"largest_rectangle_area"
] | 2 | [
[
"maximal_rectangle",
"largest_rectangle_area"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 6ffe0a2ebe44a769a87528317ffefddc49d44ed5 | e742a810d0ecc5b39e6deb617fea4a708164d353 | |||
v1.0 | complete | Taco | Taco_85576_C | def sum_of_squares_of_digits(n: int) -> int:
"""
Given an integer n, returns the sum of the squares of its digits.
>>> sum_of_squares_of_digits(31)
10
>>> sum_of_squares_of_digits(52)
29
>>> sum_of_squares_of_digits(49)
97
>>> sum_of_squares_of_digits(0)
0
>>> sum_of_squ... | def sum_of_squares_of_digits(n):
"""
Given an integer n, returns the sum of the squares of its digits.
"""
return sum(int(digit)**2 for digit in str(n))
def bravest_knight(attacks):
"""
Given a list of integers representing the attack values of knights, returns
the attack value of the brave... | from solution import sum_of_squares_of_digits, bravest_knight
def test_sum_of_squares_of_digits():
assert sum_of_squares_of_digits(31) == 10 # 3^2 + 1^2 = 9 + 1 = 10
assert sum_of_squares_of_digits(52) == 29 # 5^2 + 2^2 = 25 + 4 = 29
assert sum_of_squares_of_digits(49) == 97 # 4^2 + 9^2 = 16 + 81 = 97
... | [
{
"docstring": "Given an integer n, returns the sum of the squares of its digits.",
"function_declaration": "def sum_of_squares_of_digits(n):",
"function_name": "sum_of_squares_of_digits",
"parameter_list": "(n)"
},
{
"docstring": "Given a list of integers representing the attack values of k... | [
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 sum_of_squares_of_digits(n):\n \"\"\"\n Returns the sum of the squares of the digits of the number n.\n \"\"\"\n return sum(int(digit) ** 2 for dig... | trial_gpt4o_1 | {
"original_instruction": "### Problem Description\n\nIn a kingdom far away, a wise king posed a challenge to find the bravest warrior among his knights. The challenge involved a unique competition called \"Sum of Squares\".\n\nGiven a list of integers, each representing the attacks of different knights, the bravest ... | 0.602801 | Taco_85576 | C | [
"sum_of_squares_of_digits",
"bravest_knight"
] | 2 | [
[
"bravest_knight",
"sum_of_squares_of_digits"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | bc36dcf2db65e370de4c3d09fb7a8b9b3e47646e | abce43106457cf45d506d2d93a45b6905b75ac7b | |||
v1.0 | complete | Taco | Taco_85600_C | def send_message(user, message, users):
""" Sends a direct message to the specified user.
>>> users = {'Alice': [], 'Bob': []}
>>> send_message('Alice', 'Hello, Alice!', users)
{'Alice': ['Hello, Alice!'], 'Bob': []}
>>> send_message('Bob', 'Hi Bob!', users)
{'Alice': ['Hello, Alice!'], 'Bob': [... | def send_message(user, message, users):
"""
Sends a direct message to the specified user.
"""
if user in users:
users[user].append(message)
return users
def send_group_message(group, message, users, groups):
"""
Sends a message to all users in the specified group.
"""
if gro... | import pytest
from solution import send_message, send_group_message, process_commands
def test_send_message():
users = {'Alice': [], 'Bob': []}
send_message('Alice', 'Hello, Alice!', users)
assert users['Alice'] == ['Hello, Alice!']
send_message('Bob', 'Hi Bob!', users)
assert users['Bob'] == ['Hi ... | [
{
"docstring": "Sends a direct message to the specified user.",
"function_declaration": "def send_message(user, message, users):",
"function_name": "send_message",
"parameter_list": "(user, message, users)"
},
{
"docstring": "Sends a message to all users in the specified group.",
"functi... | [
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 send_message(users, user, message):\n \"\"\"\n Send a message directly to a particular user.\n \n :param users: Dictionary containing user messages... | trial_gpt4o_2 | {
"original_instruction": "Create a function that simulates a message-passing system in a social network. Each user can send messages to other users, and each user can be a part of multiple groups. A message sent to a group is received by all users in that group. Implement the following two functions:\n\n1. `send_mes... | 0.45375 | Taco_85600 | C | [
"send_message",
"send_group_message",
"process_commands"
] | 3 | [
[
"process_commands",
"send_group_message"
],
[
"process_commands",
"send_message"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 2ba8355b1ff935e5aa96e795945daabd48a3e17e | 9c6bcba8d056de50ab11e28909182c3216f2cb1d | |||
v1.0 | complete | Taco | Taco_84968_C | import math
import heapq
def euclidean_distance(p1, p2):
"""Calculate the Euclidean distance between two points in 3D space."""
return math.sqrt((p1[0] - p2[0]) ** 2 +
(p1[1] - p2[1]) ** 2 +
(p1[2] - p2[2]) ** 2)
def does_intersect(p1, p2, box):
"""Check if a li... | import math
import heapq
def euclidean_distance(p1, p2):
return math.sqrt((p1[0] - p2[0]) ** 2 +
(p1[1] - p2[1]) ** 2 +
(p1[2] - p2[2]) ** 2)
def does_intersect(p1, p2, box):
xmin, ymin, zmin, xmax, ymax, zmax = box
def inside(p):
x, y, z = p
ret... | def test_euclidean_distance():
assert abs(euclidean_distance((0, 0, 0), (3, 4, 0)) - 5) < 0.00001
assert abs(euclidean_distance((1, 2, 3), (4, 5, 6)) - 5.19615) < 0.00001
def test_does_intersect():
assert does_intersect((0, 0, 0), (5, 5, 5), (2, 2, 2, 7, 7, 7)) is True
assert does_intersect((0, 0, 0), ... | [
{
"docstring": null,
"function_declaration": "def euclidean_distance(p1, p2):",
"function_name": "euclidean_distance",
"parameter_list": "(p1, p2)"
},
{
"docstring": null,
"function_declaration": "def does_intersect(p1, p2, box):",
"function_name": "does_intersect",
"parameter_li... | [
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\nimport heapq\n\ndef euclidean_distance(p1, p2):\n return math.sqrt((p1[0] - p2[0])**2 + (p1[1] - p2[1])**2 + (p1[2] - p2[2])**2)\n\ndef intersects_... | trial_gpt4o_2 | {
"original_instruction": "Dr. Ferris has been working on creating autonomous drones that can navigate through a three-dimensional space filled with obstacles. Each drone operates based on a series of waypoints that define its flight path. Each waypoint is connected in sequence to form a straight line segment. A dron... | 0.534672 | Taco_84968 | C | [
"euclidean_distance",
"does_intersect",
"dijkstra",
"minimum_energy"
] | 4 | [
[
"minimum_energy",
"dijkstra"
],
[
"minimum_energy",
"does_intersect"
],
[
"minimum_energy",
"euclidean_distance"
]
] | 3 | [] | false | [] | false | pytest | false | [] | true | 452fa2b39c6cada4e435f68e13ce013cd5de5df2 | d2f07404de9640405cea52e5bca8d2a242097613 | |||
v1.0 | complete | Taco | Taco_85470_C | def create_diagonal_matrix(N):
"""
Create an N by N matrix with 1's on both the principal and secondary diagonals.
>>> create_diagonal_matrix(3)
[[1, 0, 1], [0, 1, 0], [1, 0, 1]]
>>> create_diagonal_matrix(4)
[[1, 0, 0, 1], [0, 1, 1, 0], [0, 1, 1, 0], [1, 0, 0, 1]]
"""
pass
def gen... | def create_diagonal_matrix(N):
"""
Create an N by N matrix with 1's on both the principal and secondary diagonals.
"""
matrix = [[0]*N for _ in range(N)]
for i in range(N):
matrix[i][i] = 1
matrix[i][N-1-i] = 1
return matrix
def generate_matrices(test_cases):
"""
Generat... | from solution import create_diagonal_matrix, generate_matrices, format_matrices, main
def test_create_diagonal_matrix():
expected = [
[1, 0, 1],
[0, 1, 0],
[1, 0, 1]
]
assert create_diagonal_matrix(3) == expected
expected = [
[1, 0, 0, 1],
[0, 1, 1, 0],
... | [
{
"docstring": "Create an N by N matrix with 1's on both the principal and secondary diagonals.",
"function_declaration": "def create_diagonal_matrix(N):",
"function_name": "create_diagonal_matrix",
"parameter_list": "(N)"
},
{
"docstring": "Generate matrices for each test case.",
"funct... | [
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 create_diagonal_matrix(size):\n \"\"\"\n Creates an NxN matrix with 1s on both the main and secondary diagonals.\n \"\"\"\n matrix = [[0] * size fo... | trial_gpt4o_2 | {
"original_instruction": "Amy enjoys creating geometric patterns using matrices. Recently, she came across an intriguing problem. She has an N by N matrix filled with zeroes, and she wants to place '1's along both main diagonals (the principal diagonal and the secondary diagonal) of the matrix. \n\nCan you help her ... | 0.54892 | Taco_85470 | C | [
"create_diagonal_matrix",
"generate_matrices",
"format_matrices",
"main"
] | 4 | [
[
"generate_matrices",
"create_diagonal_matrix"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 067c6e9be3f35864820d5e4e2a9439ee47111cfc | 488831b8ae5626aaf69246ce14dcf21809528667 | |||
v1.0 | complete | Taco | Taco_85502_C | def max_points(T: int, test_cases: List[Tuple[int, List[int]]]) -> List[int]:
"""
Calculate the maximum points a player can accumulate with the given constraints.
Parameters:
T (int): The number of test cases.
test_cases (List[Tuple[int, List[int]]]): A list of tuples where each tuple contains:... | def max_points(T, test_cases):
"""
Calculate the maximum points a player can accumulate with the given constraints.
Parameters:
T (int): The number of test cases.
test_cases (List[Tuple[int, List[int]]]): A list of tuples where each tuple contains:
- An integer N (the number of levels)
... | from solution import max_points
def test_single_level():
assert max_points(1, [(1, [5])]) == [5]
def test_two_levels():
assert max_points(1, [(2, [5, 8])]) == [8]
def test_three_levels():
assert max_points(1, [(3, [1, 2, 3])]) == [4]
def test_four_levels():
assert max_points(1, [(4, [4, 5, 6, 7])]) ... | [
{
"docstring": "Calculate the maximum points a player can accumulate with the given constraints.\n\nParameters:\nT (int): The number of test cases.\ntest_cases (List[Tuple[int, List[int]]]): A list of tuples where each tuple contains:\n - An integer N (the number of levels)\n - A list of N integers repres... | [
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 max_points(T, test_cases):\n def helper(points):\n N = len(points)\n if N == 0:\n return 0\n if N == 1:\n return ... | trial_gpt4o_7 | {
"original_instruction": "You are working as a part of a team to develop a new video game. In the game, there are various levels, and each level has a certain number of points associated with it. You want to create a feature that allows a player to skip certain levels to maximize the total points they can accumulate... | 0.664553 | Taco_85502 | C | [
"max_points",
"prepare_input"
] | 2 | [
[
"prepare_input",
"max_points"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f49ec119b1e6c7d45e8c08d930deca0e3fec3487 | dd987fc0bc2617c7d4d0421c29aa2f90039fa529 | |||
v1.0 | complete | Taco | Taco_85848_C | def get_indices_for_product(p: int) -> List[int]:
""" Determine possible sets of checkpoint indices Monocarp can pass to achieve the product p.
>>> get_indices_for_product(2023) # [1, 17, 119] or any other combination
>>> get_indices_for_product(180) # [1, 9, 20] or any other combination
>>> get_indices... | def prime_factors(n):
factors = []
d = 2
while d * d <= n:
while (n % d) == 0:
factors.append(d)
n //= d
d += 1
if n > 1:
factors.append(n)
return factors
def get_indices_for_product(p):
factors = prime_factors(p)
if len(factors) < 2:
... | from solution import get_indices_for_product
def test_single_prime():
# only one factor, invalid case
assert get_indices_for_product(3) == -1
def test_multiple_factors():
# valid cases
assert get_indices_for_product(2023) == [7, 17, 17] or [1, 17, 2023]
assert get_indices_for_product(180) == [2, 2... | [
{
"docstring": null,
"function_declaration": "def prime_factors(n):",
"function_name": "prime_factors",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def get_indices_for_product(p):",
"function_name": "get_indices_for_product",
"parameter_list": "(p)"
... | [
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 find_checkpoint_indices(p):\n \"\"\"\n Finds a set of checkpoint indices whose product equals p.\n Returns the indices in increasing order if possible... | trial_gpt4o_2 | {
"original_instruction": "Monocarp is participating in a marathon event organized in his hometown. The marathon route consists of several checkpoints, and each participant must go through a certain number of checkpoints to complete the marathon. Cherishing the number \"2023\", the organizers decided that the checkpo... | 0.526953 | Taco_85848 | C | [
"prime_factors",
"get_indices_for_product",
"solve_marathons",
"main"
] | 4 | [
[
"get_indices_for_product",
"prime_factors"
],
[
"solve_marathons",
"get_indices_for_product"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 3165b04c155794334c52153c8c224dfe99626568 | 651fecbe278e50060c1816f75e3b15627b94ec75 | |||
v1.0 | complete | Taco | Taco_85822_C | def optimal_capital(n: int, goods: List[int], roads: List[Tuple[int, int]]) -> int:
"""
In a kingdom far away, there are several cities connected by roads that form a tree structure.
The goal is to choose a capital city such that the total distance to transport goods from all cities to the capital is minim... | def find_optimal_city(n, goods, roads):
from collections import defaultdict, deque
tree = defaultdict(list)
for u, v in roads:
tree[u].append(v)
tree[v].append(u)
subtree_size = [0] * (n + 1)
total_distance = [0] * (n + 1)
parent = [-1] * (n + 1)
def dfs(node):... | def test_example_case():
assert optimal_capital(5, [1, 2, 3, 4, 5], [(1, 2), (2, 3), (2, 4), (3, 5)]) == 3
def test_all_cities_produce_zero_goods():
assert optimal_capital(4, [0, 0, 0, 0], [(1, 2), (1, 3), (3, 4)]) == 1
def test_single_city():
assert optimal_capital(2, [10, 10], [(1, 2)]) == 1
def test_l... | [
{
"docstring": null,
"function_declaration": "def find_optimal_city(n, goods, roads):",
"function_name": "find_optimal_city",
"parameter_list": "(n, goods, roads)"
},
{
"docstring": null,
"function_declaration": "def optimal_capital(n, goods, roads):",
"function_name": "optimal_capit... | [
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\nfrom collections import defaultdict, deque\n\ndef find_capital(n, goods, roads):\n tree = defaultdict(list)\n \n for u, v in roads:\n t... | trial_gpt4o_2 | {
"original_instruction": "In a kingdom far away, there are several cities connected by roads that form a tree structure, i.e., there are exactly n-1 roads and any two cities are connected by exactly one path. The Kingdom's government wants to improve trade by designating a single city as the capital. Each city is as... | 0.639659 | Taco_85822 | C | [
"find_optimal_city",
"optimal_capital"
] | 2 | [
[
"optimal_capital",
"find_optimal_city"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 3284db927f62b30df24e7f6cd020b81e61d05567 | 325e38264b2c6836b21db5c2eecf64e4a533f00a | |||
v1.0 | complete | Taco | Taco_85515_C | from typing import List, Tuple
def solve_treasure_hunt(n: int, m: int, edges_input: List[Tuple[int, int, int]]) -> int:
""" Determine the minimum number of different ticket costs Alice needs to carry to visit each area at least once.
Args:
n (int): The number of areas on the island.
m (int): The n... | from collections import defaultdict
def min_ticket_costs(n, m, paths):
def find(parent, i):
if parent[i] == i:
return i
return find(parent, parent[i])
def union(parent, rank, x, y):
root_x = find(parent, x)
root_y = find(parent, y)
if rank[root_... | def test_solve_treasure_hunt():
# Test case 1
assert solve_treasure_hunt(4, 4, [
(1, 2, 7),
(2, 3, 9),
(3, 4, 5),
(4, 1, 6)
]) == 3
# Test case 2
assert solve_treasure_hunt(5, 6, [
(1, 2, 4),
(1, 3, 10),
(2, 3, 1),
(2, 4, 6),
... | [
{
"docstring": null,
"function_declaration": "def min_ticket_costs(n, m, paths):",
"function_name": "min_ticket_costs",
"parameter_list": "(n, m, paths)"
},
{
"docstring": null,
"function_declaration": "def solve_treasure_hunt(n, m, edges_input):",
"function_name": "solve_treasure_hu... | [
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 defaultdict\n\ndef min_ticket_costs(n, m, paths):\n def find(parent, i):\n if parent[i] == i:\n return i\n retu... | trial_gpt4o_0 | {
"original_instruction": "Alice is participating in a treasure hunt on an island that consists of `n` areas, numbered from 1 to `n`. There are `m` bidirectional paths between the areas. Alice starts in area 1, and her goal is to visit each area at least once.\n\nEach path has a ticket cost associated with it. To tra... | 0.627208 | Taco_85515 | C | [
"min_ticket_costs",
"solve_treasure_hunt"
] | 2 | [
[
"solve_treasure_hunt",
"min_ticket_costs"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 6985b58491701ad0c762189fe327ce03c87e312d | 1ea530cac5036b9073bab7a9ca66938ae3ba1d7d | |||
v1.0 | complete | Taco | Taco_85771_C | def sieve_of_eratosthenes(n):
"""
Returns a boolean array 'is_prime' of size n+1 where is_prime[i] is True if 'i' is a prime number.
"""
# Your code here
def preprocess_primes(arr):
"""
Preprocess to find the prefix sum array of prime counts.
"""
# Your code here
def find_prime_cou... | def sieve_of_eratosthenes(n):
"""
Returns a boolean array 'is_prime' of size n+1 where is_prime[i] is True if 'i' is a prime number.
"""
is_prime = [True] * (n + 1)
is_prime[0] = is_prime[1] = False
p = 2
while (p * p <= n):
if (is_prime[p] == True):
for i in range(p * p,... | def test_sieve_of_eratosthenes():
from solution import sieve_of_eratosthenes
assert sieve_of_eratosthenes(10) == [False, False, True, True, False, True, False, True, False, False, False]
assert sieve_of_eratosthenes(5) == [False, False, True, True, False, True]
def test_preprocess_primes():
from soluti... | [
{
"docstring": "Returns a boolean array 'is_prime' of size n+1 where is_prime[i] is True if 'i' is a prime number.",
"function_declaration": "def sieve_of_eratosthenes(n):",
"function_name": "sieve_of_eratosthenes",
"parameter_list": "(n)"
},
{
"docstring": "Preprocess to find the prefix sum... | [
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 Check if n is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % ... | trial_gpt4o_1 | {
"original_instruction": "Yana has recently learned about prime numbers and how to check if a number is prime. She is now curious about a specific problem that involves finding intervals with the most prime numbers within a given range of integers.\n\nYana has an array of integers a of length n and q queries to proc... | 0.634952 | Taco_85771 | C | [
"sieve_of_eratosthenes",
"preprocess_primes",
"find_prime_count_in_subarray",
"process_queries"
] | 4 | [
[
"preprocess_primes",
"sieve_of_eratosthenes"
],
[
"process_queries",
"find_prime_count_in_subarray"
],
[
"process_queries",
"preprocess_primes"
]
] | 3 | [
"process_queries"
] | false | [] | false | pytest | true | [] | true | 1ab2d81149468fdf50892059dabbe6558248b09b | b89b79890bc94d325f30e05fb124ef3c91d192c6 | |||
v1.0 | complete | Taco | Taco_86021_C | from typing import List, Tuple
def process_queries(n: int, q: int, node_values: List[int], edges: List[Tuple[int, int]], queries: List[List[int]]) -> List[int]:
"""
Process the queries on the given binary tree.
Args:
n (int): The number of nodes in the tree.
q (int): The number of queries.
no... | from collections import defaultdict
import sys
sys.setrecursionlimit(200000)
class SegmentTree:
def __init__(self, values):
self.n = len(values)
self.tree = [0] * (2 * self.n)
self.build(values)
def build(self, values):
for i in range(self.n):
self.tree[self.n+i] =... | def test_binary_tree_queries():
n = 7
q = 5
node_values = [1, 2, 3, 4, 5, 6, 7]
edges = [(1, 2), (1, 3), (2, 4), (2, 5), (3, 6), (3, 7)]
queries = [[2, 4, 5], [1, 4, 10], [2, 4, 5], [2, 6, 7], [2, 1, 7]]
expected_result = [5, 10, 7, 7]
assert process_queries(n, q, node_values, edges, queri... | [] | [
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):\n self.value = value\n self.children = []\n\ndef dfs_lca(node, parent, depth, parent_tracker, depth_t... | trial_gpt4o_2 | {
"original_instruction": "You are given a binary tree consisting of $n$ nodes. The nodes are numbered from $1$ to $n$ with the root being node $1$. Each node has a unique integer value assigned to it.\n\nYou should process $q$ queries with it. Each query is one of two types:\n\n\"$1$ $u$ $x$\" — update the value of ... | 0.655525 | Taco_86021 | C | [
"find_lca_and_paths",
"depth_first_search",
"process_queries"
] | 3 | [
[
"process_queries",
"depth_first_search"
],
[
"process_queries",
"find_lca_and_paths"
]
] | 2 | [
"process_queries"
] | false | [
"SegmentTree"
] | true | pytest | false | [] | true | 7b517603cc21d4efb6e5ba5badd361a0f71ec840 | 0a259498cbd5258cad826b72fddc41326e022c40 | |||
v1.0 | complete | Taco | Taco_85861_C | from typing import List
def manage_parking_lot(N: int, M: int, events: List[str]) -> List[str]:
""" You are managing a parking lot system. The parking lot has a limited number of slots and time constraints for parking each vehicle. Your task is to handle the entry and exit of cars in the parking lot efficiently.
... | from datetime import datetime, timedelta
def parse_time(time_str):
return datetime.strptime(time_str, "%H:%M")
def calculate_fee(start, end):
time_diff = end - start
total_hours = time_diff.total_seconds() / 3600
fee = (total_hours // 1 + (1 if total_hours % 1 > 0 else 0)) * 10
return int(fee)
de... | from solution import manage_parking_lot
def test_sample_case():
N = 3
M = 5
events = [
"entry 1234 10:00",
"entry 5678 10:30",
"entry 9101 11:00",
"exit 1234 13:45",
"exit 5678 14:15"
]
result = manage_parking_lot(N, M, events)
assert result == ["1234 40"... | [
{
"docstring": null,
"function_declaration": "def parse_time(time_str):",
"function_name": "parse_time",
"parameter_list": "(time_str)"
},
{
"docstring": null,
"function_declaration": "def calculate_fee(start, end):",
"function_name": "calculate_fee",
"parameter_list": "(start, e... | [
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\nfrom datetime import datetime\n\ndef calculate_parking_fee(entry_time, exit_time):\n entry_dt = datetime.strptime(entry_time, '%H:%M')\n exit_dt... | trial_gpt4o_2 | {
"original_instruction": "You are managing a parking lot system. The parking lot has a limited number of slots and time constraints for parking each vehicle. Your task is to handle the entry and exit of cars in the parking lot efficiently.\n\nA car can park if there is an available slot. When a car enters, you need ... | 0.658075 | Taco_85861 | C | [
"parse_time",
"calculate_fee",
"manage_parking_lot"
] | 3 | [
[
"manage_parking_lot",
"calculate_fee"
],
[
"manage_parking_lot",
"parse_time"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | b32734543ccf5fa8094e69a6061f7aa1a8e73dd5 | 9727469183901a420f13628a7a0106430a3e81ee | |||
v1.0 | complete | Taco | Taco_85999_C | def matching_users(n: int, input_lines: List[str]) -> List[str]:
"""
Find all pairs of users who share at least one common interest.
Args:
n (int): Number of users
input_lines (List[str]): List of strings with user ID and interests
Returns:
List[str]: List of pairs of user IDs shar... | def find_matching_users(n, user_data):
from collections import defaultdict
interest_to_users = defaultdict(set)
for user_id, interests in user_data:
for interest in interests:
interest_to_users[interest].add(user_id)
pairs = set()
for users in interest_to_users.values()... | def test_matching_users():
# Test Case 1
n1 = 3
input1 = [
"1 hiking coding",
"2 cooking hiking",
"3 cooking",
]
expected_output1 = ["1 2", "2 3"]
assert matching_users(n1, input1) == expected_output1
# Test Case 2
n2 = 4
input2 = [
"1 tennis",
... | [
{
"docstring": null,
"function_declaration": "def find_matching_users(n, user_data):",
"function_name": "find_matching_users",
"parameter_list": "(n, user_data)"
},
{
"docstring": null,
"function_declaration": "def process_input(n, input_lines):",
"function_name": "process_input",
... | [
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_matching_users(n, user_data):\n from collections import defaultdict\n \n interest_to_users = defaultdict(set)\n for user_id, interests in user... | trial_gpt4o_0 | {
"original_instruction": "Sarah's startup is developing a new messaging platform, and she is trying to implement a feature for matching users based on shared interests. Each user has a unique ID and a list of interests. The goal is to find pairs of users who have at least one common interest. Sarah needs this functi... | 0.575998 | Taco_85999 | C | [
"find_matching_users",
"process_input",
"matching_users"
] | 3 | [
[
"matching_users",
"find_matching_users"
],
[
"matching_users",
"process_input"
]
] | 2 | [
"process_input"
] | false | [] | false | pytest | false | [] | true | d70a0db30fa8959423cc5e3d575add7296136797 | 85674fe70f594bafb275e9599ff577c4e7d59905 | |||
v1.0 | complete | Taco | Taco_85907_C | def minimum_total_road_length(M: int, existing_roads: List[Tuple[int, int, int]], K: int, new_roads: List[Tuple[int, int, int]]) -> int:
""" Determine the total length of the minimal spanning tree of the graph that includes all towns with the new roads added.
Args:
M (int): The number of towns.
exi... | def find(parent, i):
if parent[i] == i:
return i
else:
return find(parent, parent[i])
def union(parent, rank, xroot, yroot):
if rank[xroot] < rank[yroot]:
parent[xroot] = yroot
elif rank[xroot] > rank[yroot]:
parent[yroot] = xroot
else:
parent[yroot] = xroot
... | def test_minimum_total_road_length():
M = 4
R = 3
existing_roads = [
(1, 2, 5),
(2, 3, 10),
(3, 4, 3)
]
K = 2
new_roads = [
(1, 3, 2),
(2, 4, 1)
]
assert minimum_total_road_length(M, existing_roads, K, new_roads) == 6
def test_case_with_no_new_roa... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, xroot, yroot):",
"function_name": "union",
"parameter_list": "(parent, rank, xroo... | [
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 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_1 | {
"original_instruction": "In the fictional land of Codeen, there are M towns, connected by R bidirectional roads. Each road has a certain length. The ruler of Codeen, King Algorith, is planning to build a new highway system that further connects these towns. This new system must be built in such a way that it minimi... | 0.659971 | Taco_85907 | C | [
"find",
"union",
"kruskal_mst",
"minimum_total_road_length"
] | 4 | [
[
"kruskal_mst",
"find"
],
[
"kruskal_mst",
"union"
],
[
"minimum_total_road_length",
"kruskal_mst"
]
] | 3 | [] | false | [] | false | pytest | false | [] | true | 74aba444b175d05e22d9cba50514886d81b95f43 | b462f0548a784b19de1088e2a3bc004a9b734aa0 | |||
v1.0 | complete | Taco | Taco_86222_C | def solve(n: int, m: int, arr: List[int], queries: List[Tuple[int, int]]) -> List[int]:
"""
Determine the minimum value within the given range for each query.
Parameters:
n (int): The size of the array.
m (int): The number of queries.
arr (List[int]): The elements of the array.
queries ... | def preprocess_min(arr):
"""
Preprocess the array using a Sparse Table to enable efficient range minimum queries.
"""
import math
n = len(arr)
log = math.ceil(math.log2(n))
st = [[0] * (log + 1) for _ in range(n)]
# Initializing Sparse Table
for i in range(n):
st[i][0] = ar... | from solution import solve
def test_example_1():
n = 8
m = 3
arr = [4, 2, 6, 1, 7, 5, 3, 8]
queries = [(1, 4), (2, 6), (3, 8)]
expected_output = [1, 1, 1]
assert solve(n, m, arr, queries) == expected_output
def test_example_2():
n = 5
m = 2
arr = [9, 7, 5, 6, 3]
queries = [(1, ... | [
{
"docstring": "Preprocess the array using a Sparse Table to enable efficient range minimum queries.",
"function_declaration": "def preprocess_min(arr):",
"function_name": "preprocess_min",
"parameter_list": "(arr)"
},
{
"docstring": null,
"function_declaration": "def range_minimum_query... | [
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_minimums(n, m, array, queries):\n \"\"\"\n Returns a list of minimum values for each query range in the array.\n \n Parameters:\n n (int): ... | trial_gpt4o_2 | {
"original_instruction": "You are given an array of n integers and m queries. Each query asks for the minimum element present in a specific subarray. Your task is to efficiently determine the minimum value within the given range for each query.\n\n### Input\n\n- The first line contains two integers, n and m (1 ≤ n ≤... | 0.657849 | Taco_86222 | C | [
"preprocess_min",
"range_minimum_query",
"process_queries",
"solve"
] | 4 | [
[
"process_queries",
"preprocess_min"
],
[
"process_queries",
"range_minimum_query"
],
[
"solve",
"process_queries"
]
] | 3 | [
"process_queries"
] | false | [] | false | pytest | true | [] | true | 39f77a56c5c1e650e87d594ab8696ea89d444997 | 84ad7371913583e630c9c439ea0db95eb65c7bf7 | |||
v1.0 | complete | Taco | Taco_86058_C | def is_harmonically_aligned(sequence):
""" Determine if a sediment sequence is harmonically aligned, and if not, suggest one possible position
where a single alteration could make it harmonically aligned. If such a change is not possible, suggest
that the sequence cannot be aligned with a single modificatio... | def is_harmonically_aligned(sequence):
"""
Determine if the sequence is harmonically aligned and, if not, suggest one possible position
where a single alteration could make it harmonically aligned.
"""
n = len(sequence)
if n < 3:
return "Aligned"
# Calculate the initial ratio
... | def test_is_harmonically_aligned_already_aligned():
assert is_harmonically_aligned([2, 4, 8, 16, 32]) == "Aligned"
def test_is_harmonically_aligned_single_change_needed():
assert is_harmonically_aligned([1, 3, 9, 10]) == "4"
def test_is_harmonically_aligned_cannot_be_aligned():
assert is_harmonically_alig... | [
{
"docstring": "Determine if the sequence is harmonically aligned and, if not, suggest one possible position\nwhere a single alteration could make it harmonically aligned.",
"function_declaration": "def is_harmonically_aligned(sequence):",
"function_name": "is_harmonically_aligned",
"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_harmonically_aligned(sequence):\n \"\"\"\n Determine if the sequence is harmonically aligned and, if not, suggest one possible position\n where a s... | trial_gpt4o_0 | {
"original_instruction": "Points: 20\nThe National Oceanographic and Atmospheric Administration (NOAA) is conducting research on seabed sediment composition to study historical climate patterns. Scientists analyze sediment samples, each documented as a sequence of mineral compositions. For data consistency, they nee... | 0.469247 | Taco_86058 | C | [
"is_harmonically_aligned",
"is_uniform_ratio",
"harmonically_aligned_results"
] | 3 | [
[
"harmonically_aligned_results",
"is_harmonically_aligned"
],
[
"is_harmonically_aligned",
"is_uniform_ratio"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 5a730d4e86da463b408647bd5debba20aa436c9f | e767135ef751c8d9917990182d21dc701ec09c73 | |||
v1.0 | complete | Taco | Taco_85908_C | def split_to_increasing_subsequences(t, test_cases):
""" You are given an integer array and your task is to find out whether there is a way to split the array into two subsequences such that:
1. Each subsequence is strictly increasing, and
2. Each element from the original array belongs to exactly one of th... | def split_to_increasing_subsequences(t, test_cases):
results = []
for i in range(t):
n, arr = test_cases[i]
if can_split(arr):
sub1, sub2 = generate_subsequences(arr)
results.append(f"YES\n{' '.join(map(str, sub1))}\n{' '.join(map(str, sub2))}")
else:
... | def split_to_increasing_subsequences(t, test_cases):
results = []
for i in range(t):
n, arr = test_cases[i]
if can_split(arr):
sub1, sub2 = generate_subsequences(arr)
results.append(f"YES\n{' '.join(map(str, sub1))}\n{' '.join(map(str, sub2))}")
else:
... | [
{
"docstring": null,
"function_declaration": "def split_to_increasing_subsequences(t, test_cases):",
"function_name": "split_to_increasing_subsequences",
"parameter_list": "(t, test_cases)"
},
{
"docstring": null,
"function_declaration": "def can_split(arr):",
"function_name": "can_s... | [
1,
1
] | 2 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def split_array_into_two_increasing_subsequences(t, test_cases):\n results = []\n \n for case in test_cases:\n n, arr = case\n if n < 2:\n ... | trial_gpt4o_1 | {
"original_instruction": "You are given an integer array and your task is to find out whether there is a way to split the array into two subsequences such that:\n\n1. Each subsequence is strictly increasing, and\n2. Each element from the original array belongs to exactly one of the two subsequences.\n\nIf it is poss... | 0.683708 | Taco_85908 | C | [
"split_to_increasing_subsequences",
"can_split",
"generate_subsequences"
] | 3 | [
[
"split_to_increasing_subsequences",
"can_split"
],
[
"split_to_increasing_subsequences",
"generate_subsequences"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | ab693153b9e407e266f3e4a7c165d122c86b8ff0 | 849904cb383d4c311039782ba1f282ddc32e42e5 | |||
v1.0 | complete | Taco | Taco_86241_C | def is_happy_number(n: int) -> bool:
""" Determine if a given number n is a Happy Number.
A Happy Number is a number defined by the following process:
- Starting with any positive integer, replace the number by the sum
of the squares of its digits.
- Repeat the process until the number equals 1 (... | def is_happy_number(n):
def get_next(number):
total_sum = 0
while number > 0:
number, digit = divmod(number, 10)
total_sum += digit ** 2
return total_sum
seen = set()
while n != 1 and n not in seen:
seen.add(n)
n = get_next(n)
return ... | from solution import is_happy_number, happy_number_classifier
def test_is_happy_number():
assert is_happy_number(19) == True
assert is_happy_number(7) == True
assert is_happy_number(2) == False
assert is_happy_number(1) == True
assert is_happy_number(0) == False
def test_happy_number_classifier():... | [
{
"docstring": null,
"function_declaration": "def is_happy_number(n):",
"function_name": "is_happy_number",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def happy_number_classifier(T, numbers):",
"function_name": "happy_number_classifier",
"parameter_l... | [
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_happy_number(n):\n \"\"\"\n Determines if a number n is a Happy Number.\n \"\"\"\n seen = set()\n while n != 1 and n not in seen:\n se... | trial_gpt4o_2 | {
"original_instruction": "Given a number, find if it's a Happy Number.\n\nA Happy Number is a number defined by the following process: \n\n- Starting with any positive integer, replace the number by the sum of the squares of its digits.\n- Repeat the process until the number equals 1 (where it will stay), or it loop... | 0.659089 | Taco_86241 | C | [
"is_happy_number",
"happy_number_classifier"
] | 2 | [
[
"happy_number_classifier",
"is_happy_number"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6cb9411d1029126c1c3896325a019cb0c7dd5b5d | 3e52a3957ffb023bf77b7e5bb1d9aa7d078e0f2c | |||
v1.0 | complete | Taco | Taco_86084_C | def max_sum_in_window(arr, K):
""" Compute the maximum sum of elements inside a sliding window of size K.
>>> max_sum_in_window([1, 3, -1, -3, 5, 3, 6, 7], 3)
16
>>> max_sum_in_window([1, 2, 3, 4, 5], 2)
9
>>> max_sum_in_window([-1, -2, -3, -4, -5], 2)
-3
>>> max_sum_in_window([1, 3, 4, ... | def max_sum_in_window(arr, K):
"""
Compute the maximum sum of elements inside a sliding window of size K.
:param arr: List of integers
:param K: Size of the sliding window
:return: Maximum sum of any subarray of size K
"""
N = len(arr)
if N < K:
return None
# Initial su... | from solution import max_sum_in_window, get_max_sum
def test_max_sum_in_window():
assert max_sum_in_window([1, 3, -1, -3, 5, 3, 6, 7], 3) == 16
assert max_sum_in_window([1, 2, 3, 4, 5], 2) == 9
assert max_sum_in_window([-1, -2, -3, -4, -5], 2) == -3
assert max_sum_in_window([1, 3, 4, 6, 8, 3, 2], 1) ==... | [
{
"docstring": "Compute the maximum sum of elements inside a sliding window of size K.\n\n:param arr: List of integers\n:param K: Size of the sliding window\n:return: Maximum sum of any subarray of size K",
"function_declaration": "def max_sum_in_window(arr, K):",
"function_name": "max_sum_in_window",
... | [
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 max_sum_subarray(arr, N, K):\n \"\"\"\n Finds the maximum sum of a subarray with length K.\n \"\"\"\n # Initial sum of the first window\n max_su... | trial_gpt4o_2 | {
"original_instruction": "One popular problem-solving technique in competitive programming contests is using the sliding window technique. In this problem, you are given a list of integers and a window size. Your task is to compute the maximum sum of the elements inside the sliding window. It's a common problem that... | 0.668631 | Taco_86084 | C | [
"max_sum_in_window",
"process_input",
"get_max_sum"
] | 3 | [
[
"get_max_sum",
"max_sum_in_window"
],
[
"get_max_sum",
"process_input"
]
] | 2 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | e6c8f7994192eb86c52b76e2c321dd8f18633551 | 15a57e857486b731446298e7b13b0aa6d3be423d | |||
v1.0 | complete | Taco | Taco_86270_C | def minimum_traversal_cost(N: int, M: int, edges: List[Tuple[int, int, int]]) -> int:
""" Given an undirected graph with N nodes and M edges, where each edge has a weight,
find the minimum possible cost to traverse the graph by visiting each node at least once.
Args:
N : int : number of nodes
M... | import heapq
def minimum_spanning_tree_cost(graph, n):
"""
Prim's algorithm to find the minimum spanning tree (MST) cost in a connected undirected graph.
"""
visited = [False] * n
min_heap = [(0, 0)] # (cost, node)
total_cost = 0
while min_heap:
cost, u = heapq.heappop(min_heap)
... | import pytest
from solution import minimum_traversal_cost
def test_example_1():
N = 4
M = 5
edges = [
(1, 2, 3),
(2, 3, 4),
(3, 4, 5),
(4, 1, 6),
(2, 4, 2)
]
assert minimum_traversal_cost(N, M, edges) == 9
def test_example_2():
N = 3
M = 3
edges ... | [
{
"docstring": "Prim's algorithm to find the minimum spanning tree (MST) cost in a connected undirected graph.",
"function_declaration": "def minimum_spanning_tree_cost(graph, n):",
"function_name": "minimum_spanning_tree_cost",
"parameter_list": "(graph, n)"
},
{
"docstring": "Given N nodes... | [
0,
0,
0,
0,
0,
0,
1,
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\n\ndef prim(N, adj):\n \"\"\"\n Uses Prim's algorithm to calculate the Minimum Spanning Tree (MST) for the given graph.\n This helps in obtai... | trial_gpt4o_6 | {
"original_instruction": "Problem statement\n\nYou are given an undirected graph with $N$ nodes and $M$ edges. Each edge has a weight associated with it. The graph is guaranteed to be connected.\n\nThe goal is to find the minimum possible cost to traverse the graph by visiting each node at least once. You can start ... | 0.744306 | Taco_86270 | C | [
"minimum_spanning_tree_cost",
"minimum_traversal_cost"
] | 2 | [
[
"minimum_traversal_cost",
"minimum_spanning_tree_cost"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e4d735f84042390a7c50703a47377b3125f5bb13 | 206377f402a574c88d01a1c100a3f38af2877fec | |||
v1.0 | complete | Taco | Taco_86192_C | def char_to_number(c: str) -> int:
""" Convert a character to its corresponding number.
>>> char_to_number('0')
0
>>> char_to_number('a')
10
>>> char_to_number('z')
35
"""
pass
def partition_and_sum(s: str) -> int:
""" Partition the given string into contiguous substrings and r... | def char_to_number(c):
if '0' <= c <= '9':
return ord(c) - ord('0')
elif 'a' <= c <= 'z':
return ord(c) - ord('a') + 10
def partition_and_sum(s):
# Sum individual values
return sum(char_to_number(c) for c in s)
def min_sum_partition(strings):
results = []
for s in strings:
... | from solution import char_to_number, partition_and_sum, min_sum_partition
def test_char_to_number():
assert char_to_number('0') == 0
assert char_to_number('5') == 5
assert char_to_number('9') == 9
assert char_to_number('a') == 10
assert char_to_number('m') == 22
assert char_to_number('z') == 35... | [
{
"docstring": null,
"function_declaration": "def char_to_number(c):",
"function_name": "char_to_number",
"parameter_list": "(c)"
},
{
"docstring": null,
"function_declaration": "def partition_and_sum(s):",
"function_name": "partition_and_sum",
"parameter_list": "(s)"
},
{
... | [
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 min_sum_partition(s):\n \"\"\"\n This function will return the minimum sum of the numbers obtained \n by partitioning the string into contiguous subst... | trial_gpt4o_8 | {
"original_instruction": "You are given a string containing digits '0'-'9' and lower-case letters 'a'-'z'. Each character can be mapped to a number based on its position in the character set; digits map to '0'-'9' and letters map to '10'-'35'. Your task is to find the minimum sum of the numbers you can obtain by par... | 0.636365 | Taco_86192 | C | [
"char_to_number",
"partition_and_sum",
"min_sum_partition"
] | 3 | [
[
"min_sum_partition",
"partition_and_sum"
],
[
"partition_and_sum",
"char_to_number"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | d34b1050bf7ce72c483e1631aff02fecb3042e44 | 4118166ff34f410537f5e5cf6074538b366b0b05 | |||
v1.0 | complete | Taco | Taco_86276_C | def longest_palindromic_substring(s: str) -> str:
"""Returns the longest palindromic substring within the input string.
The function should ignore all non-alphanumeric characters and be case-insensitive.
Args:
s (str): The input string.
Returns:
str: The longest palindromic substring.
Ex... | def preprocess_string(s):
"""
Remove non-alphanumeric characters and convert to lowercase
"""
return ''.join(char.lower() for char in s if char.isalnum())
def longest_palindromic_substring(s):
"""
Returns the longest palindromic substring within the input string s.
"""
s = preprocess_st... | from solution import longest_palindromic_substring
def test_longest_palindromic_substring_basic():
assert longest_palindromic_substring("babad") == "bab" or longest_palindromic_substring("babad") == "aba"
assert longest_palindromic_substring("cbbd") == "bb"
assert longest_palindromic_substring("a") == "a"
... | [
{
"docstring": "Remove non-alphanumeric characters and convert to lowercase",
"function_declaration": "def preprocess_string(s):",
"function_name": "preprocess_string",
"parameter_list": "(s)"
},
{
"docstring": "Returns the longest palindromic substring within the input string s.",
"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": "def longest_palindromic_substring(s):\n \"\"\"\n Returns the longest palindromic substring within the input string s.\n Ignores non-alphanumeric character... | trial_gpt4o_2 | {
"original_instruction": "A palindrome is a word, phrase, number, or other sequences of characters that reads the same forward and backward (ignoring spaces, punctuation, and capitalization). Write a function that takes a string as input and returns the longest palindromic substring within it. If there are multiple ... | 0.774875 | Taco_86276 | C | [
"preprocess_string",
"longest_palindromic_substring"
] | 2 | [
[
"longest_palindromic_substring",
"preprocess_string"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e2701e626478513cb8685031b81dfc9c5119f172 | db7e1dba67307c6f9b5a0613a8907ed7d86c429b | |||
v1.0 | complete | Taco | Taco_86291_C | from typing import List
def is_word_square(words: List[str]) -> bool:
"""
Determines if the given list of words form a word square.
>>> is_word_square(["BALL", "AREA", "LEAD", "LADY"]) == True
>>> is_word_square(["AREA", "LEAD", "BALL", "LARD"]) == False
>>> is_word_square(["AB", "BA"]) == True
... | def is_word_square(words):
"""
Determines if the given list of words form a word square.
"""
n = len(words)
for i in range(n):
for j in range(n):
if j < len(words[i]) and i < len(words[j]):
if words[i][j] != words[j][i]:
return False
... | from solution import is_word_square, evaluate_word_squares, parse_input
def test_is_word_square():
assert is_word_square(["BALL", "AREA", "LEAD", "LADY"]) == True
assert is_word_square(["AREA", "LEAD", "BALL", "LARD"]) == False
assert is_word_square(["AB", "BA"]) == True
assert is_word_square(["AB", "C... | [
{
"docstring": "Determines if the given list of words form a word square.",
"function_declaration": "def is_word_square(words):",
"function_name": "is_word_square",
"parameter_list": "(words)"
},
{
"docstring": "Evaluates multiple datasets and returns a list indicating if a word square can b... | [
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_word_square(words):\n \"\"\"\n Determines if the given list of words form a word square.\n \"\"\"\n n = len(words)\n for i in range(n):\n ... | trial_gpt4o_0 | {
"original_instruction": "In a programming challenge, you are asked to analyze strings and find specific patterns within them. The task is to identify \"word squares\" in a given list of words. A word square is a special arrangement of words in grid form where the words read the same vertically and horizontally.\n\n... | 0.606079 | Taco_86291 | C | [
"is_word_square",
"evaluate_word_squares",
"parse_input"
] | 3 | [
[
"evaluate_word_squares",
"is_word_square"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 60a644b55f0ced5c60ba3a0871622e14f061c068 | 3f623d9f7e724572dd2ea8bd11c0e7976c5c1861 | |||
v1.0 | complete | Taco | Taco_85932_C | from typing import List
def hybrid_sort_array(n: int, k: int, arr: List[int]) -> List[int]:
""" Alice has developed an innovative sorting algorithm called 'HybridSort', which combines both merge sort and quicksort under specific conditions to optimize the sorting process. Given an array `a` of `n` integers and a t... | def hybrid_sort(arr, k):
if len(arr) <= k:
quicksort(arr, 0, len(arr)-1)
else:
merge_sort(arr)
def quicksort(arr, low, high):
if low < high:
pi = partition(arr, low, high)
quicksort(arr, low, pi - 1)
quicksort(arr, pi + 1, high)
def partition(arr, low, high):
pi... | from solution import hybrid_sort_array
def test_hybrid_sort_example():
assert hybrid_sort_array(10, 3, [10, 7, 1, 8, 3, 5, 4, 2, 9, 6]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
def test_hybrid_sort_small_array():
assert hybrid_sort_array(5, 2, [5, 2, 3, 1, 4]) == [1, 2, 3, 4, 5]
def test_hybrid_sort_large_k():
... | [
{
"docstring": null,
"function_declaration": "def hybrid_sort(arr, k):",
"function_name": "hybrid_sort",
"parameter_list": "(arr, k)"
},
{
"docstring": null,
"function_declaration": "def quicksort(arr, low, high):",
"function_name": "quicksort",
"parameter_list": "(arr, low, high... | [
1,
1
] | 2 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def hybrid_sort(array, k):\n def quicksort(arr):\n if len(arr) <= 1:\n return arr\n pivot = arr[len(arr) // 2]\n left = [x for x... | trial_gpt4o_2 | {
"original_instruction": "Alice has developed an innovative sorting algorithm called 'HybridSort', which combines both merge sort and quicksort under specific conditions to optimize the sorting process. HybridSort works as follows:\n\n1. If the size of the array is less than or equal to a given threshold `k`, it use... | 0.579331 | Taco_85932 | C | [
"hybrid_sort",
"quicksort",
"partition",
"merge_sort",
"hybrid_sort_array"
] | 5 | [
[
"hybrid_sort",
"merge_sort"
],
[
"hybrid_sort",
"quicksort"
],
[
"hybrid_sort_array",
"hybrid_sort"
],
[
"quicksort",
"partition"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | 556cf28f433f58e9a83c45a20b35931eba7c00c1 | 1160d5d3e1ea83652c4a5ff6e86b02bf6540bccb | |||
v1.0 | complete | Taco | Taco_86443_C | from typing import List, Tuple
from collections import defaultdict, deque
def find_diameter(n: int, connections: List[Tuple[int, int]]) -> int:
""" Determine the maximum distance between any two employees in the company's hierarchy.
>>> find_diameter(5, [(1, 2), (1, 3), (2, 4), (2, 5)])
3
>>> find_diam... | from collections import defaultdict, deque
def find_furthest_node(start_node, graph, n):
"""
Performs a BFS from the start_node to find the furthest node from it and the distance to that node
"""
visited = [False] * (n + 1)
queue = deque([(start_node, 0)])
visited[start_node] = True
furthe... | from solution import find_diameter
def test_find_diameter_example1():
n = 5
connections = [(1, 2), (1, 3), (2, 4), (2, 5)]
assert find_diameter(n, connections) == 3
def test_find_diameter_example2():
n = 6
connections = [(1, 2), (1, 3), (2, 4), (2, 5), (3, 6)]
assert find_diameter(n, connectio... | [
{
"docstring": "Performs a BFS from the start_node to find the furthest node from it and the distance to that node",
"function_declaration": "def find_furthest_node(start_node, graph, n):",
"function_name": "find_furthest_node",
"parameter_list": "(start_node, graph, n)"
},
{
"docstring": "F... | [
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 find_diameter(n, edges):\n graph = defaultdict(list)\n\n for u, v in edges:\n graph[u].append(v)\n ... | trial_gpt4o_2 | {
"original_instruction": "A company wants to create a system to manage their employees and their hierarchical organization within different departments. The company structure follows a tree-like hierarchy where each employee might manage multiple subordinates but has exactly one direct supervisor except the top-most... | 0.57936 | Taco_86443 | C | [
"find_furthest_node",
"find_diameter"
] | 2 | [
[
"find_diameter",
"find_furthest_node"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 1e06e26c110ca27f0196157dc0bb2f538177fe66 | 04b614882e4514e5b5d7cae627b4fd3ba7ddd374 | |||
v1.0 | complete | Taco | Taco_86115_C | import os
def rle_compress(content: str) -> str:
"""
Compresses a string using Run-Length Encoding (RLE).
>>> rle_compress("AAAABBBCCDAA") == "A,4B,3C,2D,1A,2"
>>> rle_compress("A") == "A,1"
>>> rle_compress("") == ""
>>> rle_compress("AAABBAA") == "A,3B,2A,2"
"""
pass
def compress_dir... | import os
def rle_compress(content: str) -> str:
"""
Compresses a string using Run-Length Encoding (RLE).
"""
if not content:
return ""
compressed = []
last_char = content[0]
count = 1
for char in content[1:]:
if char == last_char:
count += 1
... | import os
import pytest
# Import the function from the solution code if it were in a file named solution.py
# from solution import compress_directory
def test_rle_compress():
assert rle_compress("AAAABBBCCDAA") == "A,4B,3C,2D,1A,2"
assert rle_compress("A") == "A,1"
assert rle_compress("") == ""
assert... | [
{
"docstring": "Compresses a string using Run-Length Encoding (RLE).",
"function_declaration": "def rle_compress(content):",
"function_name": "rle_compress",
"parameter_list": "(content)"
},
{
"docstring": "Compresses all text files in the given directory using the RLE algorithm.\nStores the... | [
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 os\n\ndef rle_compress(content: str) -> str:\n \"\"\"\n Compresses a string using Run-Length Encoding (RLE).\n \"\"\"\n if not content:\n ... | trial_gpt4o_0 | {
"original_instruction": "You are required to implement a file compression utility. This utility needs to scan through a directory, compress all the files in it, and store the compressed files in a subdirectory named \"compressed\". Your goal is to use the Run-Length Encoding (RLE) algorithm for compression. This al... | 0.646138 | Taco_86115 | C | [
"rle_compress",
"compress_directory"
] | 2 | [
[
"compress_directory",
"rle_compress"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 292cbe07b30305cc8371fba62083d2ce07263288 | 4d28959ff22e4db5b83e2e760cb190f90db5f7cd | |||
v1.0 | complete | Taco | Taco_86510_C | def is_prime(num):
"""
Determines 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 digit_sum(n):
... | def is_prime(num):
"""
Determines 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 digit_sum(n):
... | from solution import is_digit_sum_prime
def test_example_1():
assert is_digit_sum_prime(41) == "Yes"
def test_example_2():
assert is_digit_sum_prime(42) == "No"
def test_edge_case_1():
assert is_digit_sum_prime(1) == "No"
def test_edge_case_2():
assert is_digit_sum_prime(99999) == "No"
def test_pri... | [
{
"docstring": "Determines if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns the sum of the digits of the number n.",
"function_declaration": "def digit_sum(n):",
"function_name": "d... | [
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": "def is_prime(num):\n \"\"\"\n Helper function to check if a number is a prime number\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n ... | trial_gpt4o_5 | {
"original_instruction": "Write a program that takes an integer number `n` and determines if it is a \"digit-sum prime\" number. A \"digit-sum prime\" number is a number such that the sum of its digits is a prime number.\n\n### Input\n\nThe input consists of a single integer number `n` (1 ≤ n < 10^5).\n\n### Output\... | 0.794892 | Taco_86510 | C | [
"is_prime",
"digit_sum",
"is_digit_sum_prime"
] | 3 | [
[
"is_digit_sum_prime",
"digit_sum"
],
[
"is_digit_sum_prime",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 97481c524ce6c4e1a4db2195e21c29d8c9e3af8e | c098cc47ddc3a1d3f1c92c6df03547098e12d079 | |||
v1.0 | complete | Taco | Taco_86135_C | def min_weight_to_connect_graph(n, m, edges):
"""
Determine the minimum total weight of the new edges required to make the graph connected. If it's not possible
to connect the graph under the given constraints, output "No".
Parameters:
n (int): The number of nodes.
m (int): The number of edges.... | import heapq
def find(parent, x):
if parent[x] != x:
parent[x] = find(parent, parent[x])
return parent[x]
def union(parent, rank, x, y):
rootX = find(parent, x)
rootY = find(parent, y)
if rootX != rootY:
if rank[rootX] > rank[rootY]:
parent[rootY] = rootX
e... | def test_fully_connected_graph():
assert min_weight_to_connect_graph(4, 3, [(1, 2, 1), (2, 3, 2), (3, 4, 3)]) == 0
def test_disconnected_graph():
assert min_weight_to_connect_graph(4, 2, [(1, 2, 1), (3, 4, 1)]) == "No"
def test_single_node():
assert min_weight_to_connect_graph(1, 0, []) == 0
def test_pos... | [
{
"docstring": null,
"function_declaration": "def find(parent, x):",
"function_name": "find",
"parameter_list": "(parent, x)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
1
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\nfrom collections import defaultdict\n\ndef find(parent, i):\n while parent[i] != i:\n i = parent[i]\n return i\n\ndef union(parent, rank... | trial_gpt4o_9 | {
"original_instruction": "In an attempt to understand more complex graph structures, you're given an interesting task involving a weighted undirected graph. The graph is defined by N nodes and M edges, and each edge has an associated weight. The graph might not be connected initially, so your task is to transform th... | 0.697446 | Taco_86135 | C | [
"find",
"union",
"min_weight_to_connect_graph"
] | 3 | [
[
"min_weight_to_connect_graph",
"find"
],
[
"min_weight_to_connect_graph",
"union"
],
[
"union",
"find"
]
] | 3 | [] | false | [] | false | pytest | false | [] | true | c67cd095ca911dc423fce9f42e1d35b48c844f2a | a46bc4ab9a3de43a0f3127e36f06505355848062 | |||
v1.0 | complete | Taco | Taco_86583_C | def balance_stack(n: int, m: int, weights: List[int], L: int, U: int) -> Union[Tuple[int], str]:
"""
Determine if it is possible to reorder the plates such that the stack is balanced
and return the balanced order or "Not Possible".
>>> balance_stack(3, 500, [2, 4, 8], 2, 2)
(2, 4, 8)
>>> ba... | from itertools import permutations
def is_balanced(plates, L, U):
"""
Check if a given permutation of plates is balanced.
"""
for i in range(len(plates) - 1):
ratio = plates[i+1] / plates[i]
if not (L <= ratio <= U):
return False
return True
def balance_stack(n, m, weig... | from solution import balance_stack
def test_balance_stack_case_1():
assert balance_stack(3, 500, [2, 4, 8], 2, 2) == (2, 4, 8)
def test_balance_stack_case_2():
assert balance_stack(3, 500, [1, 100, 10], 1, 5) == "Not Possible"
def test_balance_stack_case_3():
assert balance_stack(4, 1000, [4, 1, 2, 8], 2... | [
{
"docstring": "Check if a given permutation of plates is balanced.",
"function_declaration": "def is_balanced(plates, L, U):",
"function_name": "is_balanced",
"parameter_list": "(plates, L, U)"
},
{
"docstring": "Determine if it is possible to reorder the plates such that the stack is balan... | [
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 itertools import permutations\n\ndef is_balanced(plates, L, U):\n \"\"\"\n Check if a given permutation of plates is balanced.\n \"\"\"\n for i in... | trial_gpt4o_0 | {
"original_instruction": "Mike has a stack of plates, each with a different weight. He loves to perform transformations on the stack to make it more balanced. A stack is considered balanced if, for any two consecutive plates, the ratio of their weights is within a specified range.\n\nGiven the weights of the plates ... | 0.492514 | Taco_86583 | C | [
"is_balanced",
"balance_stack"
] | 2 | [
[
"balance_stack",
"is_balanced"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a060691bc5ad6fc1cf3acf19deaf7685339aefd1 | f0c6ae8f32ff3f377b834c0ee6f70becab9b4fb1 | |||
v1.0 | complete | Taco | Taco_86339_C | def solve_graphington(input_str: str) -> (int, int):
""" Calculate the minimal repair cost and the number of distinct sets of roads
that result in the minimal cost to ensure all cities are connected
in the mystic land of Graphington.
Args:
input_str (str): Input string in the specifie... | from collections import defaultdict
import heapq
MOD = 1_000_000_007
def find_minimal_repair_cost_and_ways(n, m, edges):
parent = list(range(n))
size = [1] * n
def find(x):
if parent[x] != x:
parent[x] = find(parent[x])
return parent[x]
def union(x, y):
rootX = fi... | def test_solve_example_case():
input_str = "5 6\n1 2 3\n1 3 4\n4 2 5\n5 1 2\n2 3 7\n3 5 6\n"
assert solve_graphington(input_str) == (14, 1)
def test_small_disconnected_case():
input_str = "4 3\n1 2 1\n2 3 1\n3 4 1\n"
assert solve_graphington(input_str) == (3, 1)
def test_single_node():
input_str =... | [
{
"docstring": null,
"function_declaration": "def find_minimal_repair_cost_and_ways(n, m, edges):",
"function_name": "find_minimal_repair_cost_and_ways",
"parameter_list": "(n, m, edges)"
},
{
"docstring": null,
"function_declaration": "def solve_graphington(input_str):",
"function_n... | [
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": "MOD = 1000000007\n\ndef find(parent, i):\n if parent[i] == i:\n return i\n else:\n parent[i] = find(parent, parent[i])\n return parent[i... | trial_gpt4o_1 | {
"original_instruction": "In the mystic land of Graphington, there are N cities connected by M roads. The cities are labeled from 1 to N. Some of these roads, however, have been damaged by recent storms and need to be repaired. Each road has a repair cost associated with it. The ruling council of Graphington needs t... | 0.635546 | Taco_86339 | C | [
"find_minimal_repair_cost_and_ways",
"solve_graphington"
] | 2 | [
[
"solve_graphington",
"find_minimal_repair_cost_and_ways"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | cb3be5120d316bc11cea5b7dc5bc9f8ddef070b6 | 1c7b38698956083c80ed295588cc6b54d8b13ed0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.