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 | Code_Contests | Code_Contests_31956_C | def largest_palindromic_product(n: int) -> int:
""" Returns the largest palindromic number that is a product of two n-digit numbers.
>>> largest_palindromic_product(1)
9
>>> largest_palindromic_product(2)
9009
>>> largest_palindromic_product(3)
906609
>>> largest_palindromic_product(4)
... | def is_palindrome(number):
"""
Returns True if the given number is a palindrome, False otherwise.
"""
return str(number) == str(number)[::-1]
def largest_palindromic_product(n):
"""
Returns the largest palindromic number that is a product of two n-digit numbers.
"""
max_digit = 10 ** n ... | from solution import largest_palindromic_product
def test_largest_palindromic_product_1_digit():
assert largest_palindromic_product(1) == 9
def test_largest_palindromic_product_2_digits():
assert largest_palindromic_product(2) == 9009
def test_largest_palindromic_product_3_digits():
assert largest_palind... | [
{
"docstring": "Returns True if the given number is a palindrome, False otherwise.",
"function_declaration": "def is_palindrome(number):",
"function_name": "is_palindrome",
"parameter_list": "(number)"
},
{
"docstring": "Returns the largest palindromic number that is a product of two n-digit... | [
0,
0,
0,
0,
0,
0,
0,
1,
0
] | 1 | hard | 0.111 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome(number):\n \"\"\"\n Check if a number is a palindrome.\n \"\"\"\n return str(number) == str(number)[::-1]\n\ndef largest_pali... | trial_gpt4o_8 | {
"original_instruction": "Barry is fascinated by palindromic numbers and enjoys finding them in various scenarios. A palindromic number reads the same forwards and backwards. Barry is interested in finding the largest palindromic number that can be obtained by multiplying two n-digit numbers. Your task is to help Ba... | 0.718167 | Code_Contests_31956 | C | [
"is_palindrome",
"largest_palindromic_product"
] | 2 | [
[
"largest_palindromic_product",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | aed8e0ccedf9a07112b7675b8b3412483fac5385 | 81dda876f6a5a5da10869bc585f193b369933425 | |||
v1.0 | complete | Code_Contests | Code_Contests_31386_C | import math
from typing import List
def is_prime(num: int) -> bool:
"""
Returns True if the num is a prime number, else False.
>>> is_prime(2) == True
>>> is_prime(3) == True
>>> is_prime(4) == False
>>> is_prime(10) == False
>>> is_prime(17) == True
>>> is_prime(1) == False
>>> is_... | import math
def is_prime(num):
"""
Returns True if the num is a prime number, else False.
"""
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:... | from solution import is_prime, game_result
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(10) == False
assert is_prime(17) == True
assert is_prime(1) == False
assert is_prime(0) == False
assert is_prime(97) == True
... | [
{
"docstring": "Returns True if the num is a prime number, else False.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Determines the result of the game.",
"function_declaration": "def game_result(n, numbers):",
... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Determines if n is a prime number.\n \"\"\"\n if n < 2:\n return False\n if n == 2:\n return True\... | trial_gpt4o_2 | {
"original_instruction": "Anna and Boris are playing a game involving prime numbers. They have a list of non-negative integers and take turns picking a number from the list. Anna always moves first. The player who picks a prime number wins immediately. If no prime numbers are left to pick, the game is a draw.\n\nAnn... | 0.696095 | Code_Contests_31386 | C | [
"is_prime",
"game_result"
] | 2 | [
[
"game_result",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a8c41051ac83f5c073a55ae3d57e3721c8d51611 | 63453fa271f90cd9b50d399e39f54ef420b5dbc7 | |||
v1.0 | complete | Code_Contests | Code_Contests_31060_C | def preprocess_prefix_sums(arr):
"""
Preprocesses the array to calculate prefix sums.
"""
pass
def subarray_sum(prefix_sums, l, r):
"""
Returns the sum of the subarray from index l to r (1-based index).
"""
pass
def solve(n, m, arr, queries):
"""
Processes all the queries to fi... | def preprocess_prefix_sums(arr):
"""
Preprocesses the array to calculate prefix sums.
"""
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 subarray_sum(prefix_sums, l, r):
"""
Returns the sum of t... | def test_preprocess_prefix_sums():
arr = [1, 2, 3, 4, 5]
expected_prefix_sums = [0, 1, 3, 6, 10, 15]
assert preprocess_prefix_sums(arr) == expected_prefix_sums
def test_subarray_sum():
prefix_sums = [0, 1, 3, 6, 10, 15]
assert subarray_sum(prefix_sums, 1, 3) == 6
assert subarray_sum(prefix_sums... | [
{
"docstring": "Preprocesses the array to calculate prefix sums.",
"function_declaration": "def preprocess_prefix_sums(arr):",
"function_name": "preprocess_prefix_sums",
"parameter_list": "(arr)"
},
{
"docstring": "Returns the sum of the subarray from index l to r (1-based index).",
"fun... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def prefix_sum_array(a):\n prefix_sums = [0] * (len(a) + 1)\n for i in range(len(a)):\n prefix_sums[i + 1] = prefix_sums[i] + a[i]\n return... | trial_gpt4o_2 | {
"original_instruction": "Recently Sam started learning about prefix sums and found them quite interesting. He discovered that with the help of prefix sums he can find the sum of any subarray in constant time after doing some preprocessing. He wants to test his understanding by solving some problems using prefix sum... | 0.610433 | Code_Contests_31060 | C | [
"preprocess_prefix_sums",
"subarray_sum",
"solve"
] | 3 | [
[
"solve",
"preprocess_prefix_sums"
],
[
"solve",
"subarray_sum"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 489f420db4f48a726c86e7fbb66fc54a8ff6ff22 | 22b8628e3e4122b838deb246bb70db012517e633 | |||
v1.0 | complete | Code_Contests | Code_Contests_32103_C | def min_cost_to_connect_cities(n: int, m: int, roads: List[Tuple[int, int, int]]) -> int:
""" Determine the minimum cost to construct roads such that all cities are connected directly or indirectly.
If it is impossible to connect all the cities, return -1.
Args:
n : int : The number of cities.
... | def find(parent, i):
if parent[i] == i:
return i
else:
parent[i] = find(parent, parent[i])
return parent[i]
def union(parent, rank, x, y):
root_x = find(parent, x)
root_y = find(parent, y)
if root_x != root_y:
if rank[root_x] > rank[root_y]:
parent[r... | from solution import min_cost_to_connect_cities
def test_example_1():
n = 4
m = 5
roads = [
(1, 2, 3),
(2, 3, 1),
(3, 4, 4),
(2, 4, 2),
(1, 4, 5)
]
assert min_cost_to_connect_cities(n, m, roads) == 6
def test_example_2():
n = 3
m = 1
roads = [
... | [
{
"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,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n else:\n parent[i] = find(parent, parent[i])\n return parent[i]\n\ndef uni... | trial_gpt4o_0 | {
"original_instruction": "In a faraway kingdom, a wise king decided to build a new road network to connect all his cities together. He wants to ensure that all cities are accessible from any other city, while minimizing the cost of constructing the roads. To achieve this, the king has hired you to help him determine... | 0.70188 | Code_Contests_32103 | C | [
"find",
"union",
"kruskal",
"min_cost_to_connect_cities"
] | 4 | [
[
"kruskal",
"find"
],
[
"kruskal",
"union"
],
[
"min_cost_to_connect_cities",
"kruskal"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | 58e345775c1bf7af94af2545ed5ccab03462eeb8 | 349def4a0c253fcd32dac316ad455c087bc574f1 | |||
v1.0 | complete | Code_Contests | Code_Contests_31724_C | from typing import List, Tuple
def can_assign_types(T: int, test_cases: List[Tuple[int, int, List[Tuple[int, int]]]]) -> List[str]:
""" Determine if it is possible to assign types to all animals such that no pair of friends has the same type.
>>> can_assign_types(2, [(3, 3, [(1, 2), (2, 3), (3, 1)]), (4, 2, [(... | def is_bipartite(graph, start, color_map):
queue = [start]
color_map[start] = 0 # Start coloring with 0
while queue:
node = queue.pop(0)
for neighbor in graph[node]:
if neighbor not in color_map:
color_map[neighbor] = 1 - color_map[node]
... | from solution import can_assign_types
def test_example_cases():
T = 2
test_cases = [
(3, 3, [(1, 2), (2, 3), (3, 1)]),
(4, 2, [(1, 2), (2, 3)])
]
assert can_assign_types(T, test_cases) == ['NO', 'YES']
def test_single_animal():
T = 1
test_cases = [
(1, 0, [])
]
... | [
{
"docstring": null,
"function_declaration": "def is_bipartite(graph, start, color_map):",
"function_name": "is_bipartite",
"parameter_list": "(graph, start, color_map)"
},
{
"docstring": null,
"function_declaration": "def can_assign_types(T, test_cases):",
"function_name": "can_assi... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_bipartite(graph, n):\n color = [-1] * n\n \n def bfs(source):\n queue = [source]\n color[source] = 0\n \n while... | trial_gpt4o_2 | {
"original_instruction": "In a forest, there is a group of N animals. Each animal is either a herbivore or a carnivore. You have a list of pairs indicating which animals are friends with each other. Your task is to decide if it is possible to assign types (herbivore or carnivore) to all animals such that no pair of ... | 0.63221 | Code_Contests_31724 | C | [
"is_bipartite",
"can_assign_types"
] | 2 | [
[
"can_assign_types",
"is_bipartite"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f94257177f4d9ab52c42f3c020a26570f80f7ef6 | d9eab3cea8654efe055d788d35d92390b6cc03db | |||
v1.0 | complete | Code_Contests | Code_Contests_32228_C | def find_longest_even_odd_subarray(arr: List[int]) -> Tuple[int, int]:
"""
Given an array of integers, find the longest contiguous subarray that has an equal number of even and odd integers.
:param arr: List of integers
:return: Tuple containing starting and ending indices of the longest subarray with ... | def find_longest_even_odd_subarray(arr):
"""
Finds the longest contiguous subarray with equal number of even and odd integers.
"""
n = len(arr)
if n == 0:
return -1, -1
# Dictionary to store the first occurrence of the difference between even and odd counts
first_occurrence = {0: -1... | from solution import find_longest_even_odd_subarray
def test_example_1():
arr = [1, 2, 3, 4, 5, 6]
assert find_longest_even_odd_subarray(arr) == (1, 6)
def test_example_2():
arr = [2, 4, 6, 8, 10]
assert find_longest_even_odd_subarray(arr) == (-1, -1)
def test_single_element_odd():
arr = [1]
... | [
{
"docstring": "Finds the longest contiguous subarray with equal number of even and odd integers.",
"function_declaration": "def find_longest_even_odd_subarray(arr):",
"function_name": "find_longest_even_odd_subarray",
"parameter_list": "(arr)"
},
{
"docstring": null,
"function_declarati... | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_longest_subarray(arr):\n n = len(arr)\n prefix_sums = {0: -1}\n balance = 0\n max_length = 0\n start_index = -1\n \n for i in... | trial_gpt4o_4 | {
"original_instruction": "Alice loves playing with arrays and searching for hidden patterns in them. She recently came across a challenging problem. Given an array of integers, she wants to find the longest contiguous subarray that has an equal number of even and odd integers. Help Alice write a program that finds t... | 0.704856 | Code_Contests_32228 | C | [
"find_longest_even_odd_subarray",
"process_input_and_output"
] | 2 | [
[
"process_input_and_output",
"find_longest_even_odd_subarray"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 080d7df05fdfe1d0fb6cbb4b42af53b743a27cea | 401380348a98e0402941a3934028d58bdff77b32 | |||
v1.0 | complete | Code_Contests | Code_Contests_32236_C | from typing import List
def max_rectangle_area(grid: List[List[int]]) -> int:
"""
Eva enjoys solving puzzles on a grid. She has an m x n grid where each cell contains either a 0 or a 1.
Eva wants to identify the largest rectangle of 1's in this grid and determine its area.
Args:
grid (List[List[in... | def max_histogram_area(heights):
"""
Calculate the maximum rectangle area in a histogram represented by heights.
"""
stack = []
max_area = 0
index = 0
while index < len(heights):
if not stack or heights[stack[-1]] <= heights[index]:
stack.append(index)
index +... | from solution import max_rectangle_area
def test_sample_case():
grid = [
[1, 0, 1, 0, 0],
[1, 0, 1, 1, 1],
[1, 1, 1, 1, 1],
[1, 0, 0, 1, 0]
]
assert max_rectangle_area(grid) == 6
def test_single_row():
grid = [
[1, 1, 1, 1, 1]
]
assert max_rectangle_area... | [
{
"docstring": "Calculate the maximum rectangle area in a histogram represented by heights.",
"function_declaration": "def max_histogram_area(heights):",
"function_name": "max_histogram_area",
"parameter_list": "(heights)"
},
{
"docstring": "Calculate the maximum rectangle area of 1's in a b... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_histogram_area(heights):\n \"\"\"\n Calculate the maximum rectangle area in a histogram represented by heights.\n \"\"\"\n stack = []\n... | trial_gpt4o_0 | {
"original_instruction": "Eva enjoys solving puzzles on a grid. She has an m x n grid where each cell contains either a 0 or a 1. Eva wants to identify the largest rectangle of 1's in this grid and determine its area. Help her out!\n\nInput\nThe first line of input contains two integers m and n (1 ≤ m, n ≤ 1000) rep... | 0.735133 | Code_Contests_32236 | C | [
"max_histogram_area",
"max_rectangle_area"
] | 2 | [
[
"max_rectangle_area",
"max_histogram_area"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6e29c8ae82d790cda2f2f6ae8de76504988bd541 | ae6982ee676b8fdaa9355503ef29343c1ec075f7 | |||
v1.0 | complete | Code_Contests | Code_Contests_32264_C | def is_super_palindromic(num: int) -> bool:
"""
Checks if a number is super palindromic.
>>> is_super_palindromic(101)
True
>>> is_super_palindromic(121)
False
>>> is_super_palindromic(11)
True
>>> is_super_palindromic(22)
False
"""
def next_super_palindromic(n: in... | def is_super_palindromic(num):
"""
Checks if a number is super palindromic.
"""
s = str(num)
return s == s[::-1] and set(s).issubset({'0', '1'})
def next_super_palindromic(n):
"""
Finds the smallest super palindromic number greater than or equal to n.
"""
current = n
while True:... | from solution import is_super_palindromic, next_super_palindromic
def test_is_super_palindromic():
assert is_super_palindromic(101)
assert is_super_palindromic(1001)
assert is_super_palindromic(11)
assert not is_super_palindromic(121)
assert not is_super_palindromic(1331)
assert not is_super_pa... | [
{
"docstring": "Checks if a number is super palindromic.",
"function_declaration": "def is_super_palindromic(num):",
"function_name": "is_super_palindromic",
"parameter_list": "(num)"
},
{
"docstring": "Finds the smallest super palindromic number greater than or equal to n.",
"function_d... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def next_super_palindromic(n):\n \"\"\"\n Returns the smallest super palindromic number that is greater than or equal to n.\n \"\"\"\n \n de... | trial_gpt4o_1 | {
"original_instruction": "Tanya loves palindromic numbers. A number is considered palindromic if it reads the same backward as forward. For example, 121, 1331, and 7 are palindromic, while 123, 1221, and 466 are not.\n\nA palindromic number is super palindromic if its decimal representation is made up of the digits ... | 0.673121 | Code_Contests_32264 | C | [
"is_super_palindromic",
"next_super_palindromic"
] | 2 | [
[
"next_super_palindromic",
"is_super_palindromic"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7334723459daab64717de58246dafb93c0dd754a | a5544d0a1a5d91378e327c573260f94ef739cfdc | |||
v1.0 | complete | Code_Contests | Code_Contests_32232_C | def minimum_total_time(n: int, m: int, connections: List[Tuple[int, int, int]]) -> int:
"""
Calculate the minimum total time to establish a connected network using the most efficient routes.
Args:
n (int): The number of computers.
m (int): The number of bidirectional connections.
connectio... | import heapq
def find_minimum_spanning_tree(n, edges):
# Create adjacency list
adj = {i: [] for i in range(1, n + 1)}
for a, b, w in edges:
adj[a].append((w, b))
adj[b].append((w, a))
# Prim's algorithm to find the Minimum Spanning Tree
visited = set()
min_heap = [(0, 1)] # (co... | from solution import minimum_total_time
def test_example_case():
assert minimum_total_time(5, 6, [(1, 2, 4), (1, 3, 4), (2, 3, 2), (2, 4, 7), (3, 5, 3), (4, 5, 1)]) == 10
assert minimum_total_time(4, 2, [(1, 2, 3), (3, 4, 6)]) == -1
def test_single_connection():
assert minimum_total_time(2, 1, [(1, 2, 10)... | [
{
"docstring": null,
"function_declaration": "def find_minimum_spanning_tree(n, edges):",
"function_name": "find_minimum_spanning_tree",
"parameter_list": "(n, edges)"
},
{
"docstring": null,
"function_declaration": "def minimum_total_time(n, m, connections):",
"function_name": "mini... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef find_minimum_spanning_tree(n, edges):\n # Create adjacency list\n adj = {i: [] for i in range(1, n + 1)}\n for a, b, w in edge... | trial_gpt4o_0 | {
"original_instruction": "A large company has networked several computers together for file sharing. One day, the employees noticed that the file sharing is incredibly slow. Upon investigation, you discovered that the slowdowns are due to multiple paths between the computers and some being far more efficient than ot... | 0.636344 | Code_Contests_32232 | C | [
"find_minimum_spanning_tree",
"minimum_total_time"
] | 2 | [
[
"minimum_total_time",
"find_minimum_spanning_tree"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0d982928a05d07d9cc4e54b2c656df848219ca96 | d019f2fced9f0c09c556bec78e9cf36666cf67af | |||
v1.0 | complete | Code_Contests | Code_Contests_32142_C | def max_consecutive_ones(binary_str: str) -> int:
"""
This function returns the maximum length of consecutive '1's in a binary string.
>>> max_consecutive_ones("1101") == 2
>>> max_consecutive_ones("111011") == 3
>>> max_consecutive_ones("100001") == 1
>>> max_consecutive_ones("0000000") == 0
... | def max_consecutive_ones(binary_str):
"""
This function returns the maximum length of consecutive '1's in a binary string.
Parameters:
- binary_str: string, input binary string
Returns:
- int, maximum length of consecutive '1's
"""
return max(len(segment) for segment in binary_... | def test_max_consecutive_ones():
assert max_consecutive_ones("1101") == 2
assert max_consecutive_ones("111011") == 3
assert max_consecutive_ones("100001") == 1
assert max_consecutive_ones("0000000") == 0
assert max_consecutive_ones("1111111") == 7
assert max_consecutive_ones("1010101010") == 1
... | [
{
"docstring": "This function returns the maximum length of consecutive '1's in a binary string.\n\nParameters:\n- binary_str: string, input binary string\n\nReturns:\n- int, maximum length of consecutive '1's",
"function_declaration": "def max_consecutive_ones(binary_str):",
"function_name": "max_conse... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_consecutive_ones(binary_strings):\n \"\"\"\n Given a list of binary strings, return a list containing the maximum length\n of consecutive ... | trial_gpt4o_2 | {
"original_instruction": "You are given a list of strings which represent binary numbers. Write a function that, for each binary number in the list, determines the maximum length of consecutive '1's. If there are multiple segments of consecutive '1's with the same maximum length, consider only one of them.\n\nInput:... | 0.647349 | Code_Contests_32142 | C | [
"max_consecutive_ones",
"process_binary_strings"
] | 2 | [
[
"process_binary_strings",
"max_consecutive_ones"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 5d0a335e8d22ffc5ba3e1c8a7b5009d7e476ee9e | f60ae07442e963c6fbbec20e0064a2883c3f1b55 | |||
v1.0 | complete | Code_Contests | Code_Contests_32356_C | def is_prime(n: int) -> bool:
""" Helper function to check if a number n is prime.
>>> is_prime(2)
True
>>> is_prime(4)
False
>>> is_prime(17)
True
"""
# Implementation here
def sum_of_primes(A: int, B: int) -> int:
""" Returns the sum of all prime numbers between A and B (inclu... | def is_prime(n):
"""
Helper function to check if a number n is prime.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i... | from solution import sum_of_primes
def test_prime_sum_example1():
assert sum_of_primes(1, 10) == 17
def test_prime_sum_example2():
assert sum_of_primes(20, 30) == 52
def test_prime_sum_example3():
assert sum_of_primes(14, 16) == 0
def test_prime_sum_single_prime():
assert sum_of_primes(5, 5) == 5
d... | [
{
"docstring": "Helper function to check if a number n is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns the sum of all prime numbers between A and B (inclusive).",
"function_declaration": "def sum_of_p... | [
0,
0,
0,
1,
1
] | 2 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_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 i... | trial_gpt4o_4 | {
"original_instruction": "Story\n\nAlice is learning about prime numbers, and she finds them fascinating. To improve her programming skills, she decides to work on a problem related to prime numbers. She wants to write a program that finds all prime numbers between two given numbers A and B, inclusive. Moreover, Ali... | 0.761899 | Code_Contests_32356 | C | [
"is_prime",
"sum_of_primes"
] | 2 | [
[
"sum_of_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8fc0a5d667d8045eef8b4e576dae39a6cb3551f0 | da742b0303f38e312196773cc1a34c3a84c305fb | |||
v1.0 | complete | Code_Contests | Code_Contests_31395_C | from typing import List
def count_paths(grid: List[List[int]]) -> int:
""" Given an n x n grid with some cells blocked (represented by 1) and some cells open (represented by 0),
find the number of paths from the top-left corner to the bottom-right corner.
You can only move right or down and you c... | def count_paths(grid):
n = len(grid)
if grid[0][0] == 1 or grid[n-1][n-1] == 1:
return 0
dp = [[0] * n for _ in range(n)]
dp[0][0] = 1
for i in range(n):
for j in range(n):
if grid[i][j] == 1:
dp[i][j] = 0
else:
if i >... | def test_parse_input():
input_str = "3\n3\n0 0 0\n0 1 0\n0 0 0\n4\n0 1 0 0\n0 0 1 0\n1 0 0 0\n0 0 0 0\n2\n0 1\n0 0"
expected_output = [
[
[0, 0, 0],
[0, 1, 0],
[0, 0, 0]
],
[
[0, 1, 0, 0],
[0, 0, 1, 0],
[1, 0, 0, 0],... | [
{
"docstring": null,
"function_declaration": "def count_paths(grid):",
"function_name": "count_paths",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def solve_grids(test_cases):",
"function_name": "solve_grids",
"parameter_list": "(test_cases)"
},
... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def count_paths(grid):\n n = len(grid)\n if grid[0][0] == 1 or grid[n-1][n-1] == 1:\n return 0\n \n dp = [[0] * n for _ in range(n)]\n ... | trial_gpt4o_0 | {
"original_instruction": "You are given an n x n grid with some cells blocked and some cells open. The task is to find the number of paths from the top-left corner of the grid to the bottom-right corner, such that you can only move right or down and you cannot pass through blocked cells. Write a function to calculat... | 0.72207 | Code_Contests_31395 | C | [
"count_paths",
"solve_grids",
"parse_input",
"main"
] | 4 | [
[
"solve_grids",
"count_paths"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | false | [] | true | 4ce47f2d30f82351338fb9ff9b0d314e5d539ea9 | e547a52f90094f5bf4abd007c6f42edee7a146ba | |||
v1.0 | complete | Code_Contests | Code_Contests_32599_C | from typing import List
def rearrange_strings(strings: List[str]) -> List[str]:
""" Rearranges each string in the list such that no two adjacent characters are the same.
If it is not possible to rearrange a string to meet the condition, returns an empty string for that string.
>>> rearrange_strings(["aabb"... | from heapq import heappop, heappush
from collections import Counter
def rearrange_string(s):
"""
Rearranges the input string such that no two adjacent characters are the same.
If not possible, returns an empty string.
"""
counter = Counter(s)
max_heap = []
for char, freq in counter.ite... | from solution import rearrange_strings
def test_rearrange_strings_case1():
assert rearrange_strings(["aabb", "aaab"]) == ["abab", ""]
def test_rearrange_strings_case2():
assert rearrange_strings(["xyz", "aaa", "ab"]) == ["xyz", "", "ab"]
def test_rearrange_strings_single_char():
assert rearrange_strings(... | [
{
"docstring": "Rearranges the input string such that no two adjacent characters are the same.\nIf not possible, returns an empty string.",
"function_declaration": "def rearrange_string(s):",
"function_name": "rearrange_string",
"parameter_list": "(s)"
},
{
"docstring": null,
"function_d... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\nfrom collections import Counter\n\ndef rearrange_string(s):\n frequency = Counter(s)\n max_heap = [(-count, char) for char, count in fr... | trial_gpt4o_2 | {
"original_instruction": "You are given n strings consisting of lowercase English letters. Your task is to rearrange the characters of each string so that no two adjacent characters in the rearranged string are the same.\n\nIf there are multiple ways to achieve this, return any of them. If it is not possible to rear... | 0.672393 | Code_Contests_32599 | C | [
"rearrange_string",
"rearrange_strings"
] | 2 | [
[
"rearrange_strings",
"rearrange_string"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b95af29e2272e283d7d19dffced6d2894bd128f6 | 0bf599ff860ffac467a483b42808361e18ec565c | |||
v1.0 | complete | Code_Contests | Code_Contests_32650_C | def calculate_max_benefit(n: int, workshops: List[Tuple[int, int, int]]) -> int:
""" Calculate the maximum total benefit score by attending non-overlapping workshops.
>>> calculate_max_benefit(4, [(1, 3, 50), (3, 5, 20), (2, 6, 100), (4, 7, 200)])
250
>>> calculate_max_benefit(3, [(1, 3, 60), (2, 5, 30)... | from bisect import bisect_right
def max_benefit(workshops):
workshops.sort(key=lambda x: x[1]) # Sort by end time
# Prepare for DP
end_times = [w[1] for w in workshops]
dp = [0] * (len(workshops) + 1)
for i in range(1, len(workshops) + 1):
# Current workshop details
s_i, ... | import pytest
from solution import calculate_max_benefit
def test_single_workshop():
assert calculate_max_benefit(1, [(1, 2, 100)]) == 100
def test_non_overlapping_workshops():
assert calculate_max_benefit(3, [(1, 2, 50), (3, 4, 60), (5, 6, 70)]) == 180
def test_all_overlapping_workshops():
assert calcul... | [
{
"docstring": null,
"function_declaration": "def max_benefit(workshops):",
"function_name": "max_benefit",
"parameter_list": "(workshops)"
},
{
"docstring": null,
"function_declaration": "def calculate_max_benefit(n, workshop_list):",
"function_name": "calculate_max_benefit",
"p... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_benefit(workshops):\n workshops.sort(key=lambda x: x[1]) # Sort workshops based on end times\n\n from bisect import bisect_right\n\n n = ... | trial_gpt4o_2 | {
"original_instruction": "A company is organizing a series of workshops for its employees. Each workshop has an associated benefit score representing how beneficial it is. Employees can attend multiple workshops, but no two workshops can overlap in time.\n\nEach workshop is defined by its start time, end time, and b... | 0.59523 | Code_Contests_32650 | C | [
"max_benefit",
"calculate_max_benefit"
] | 2 | [
[
"calculate_max_benefit",
"max_benefit"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 23f539f43467d3e0b2a51cf237109184cafac1b1 | 2a5f075efd8a3577221d0333bb0c993df76423de | |||
v1.0 | complete | Code_Contests | Code_Contests_32424_C | def find_distinct_groups(T: int, test_cases: List[Tuple[int, int, List[Tuple[int, int]]]]) -> List[int]:
""" Count the number of distinct groups of employees connected directly or indirectly via friendships.
Args:
T (int): Number of test cases.
test_cases (List[Tuple[int, int, List[Tuple[int, int]]... | def find_parent(parent, i):
if parent[i] == i:
return i
parent[i] = find_parent(parent, parent[i])
return parent[i]
def union(parent, rank, x, y):
root_x = find_parent(parent, x)
root_y = find_parent(parent, y)
if root_x != root_y:
if rank[root_x] > rank[root_y]:
... | def test_find_distinct_groups():
T = 2
test_cases = [
(4, 2, [(1, 2), (2, 3)]),
(5, 0, [])
]
expected_results = [2, 5]
results = count_distinct_groups(T, test_cases)
assert results == expected_results
def test_no_friendships():
T = 1
test_cases = [(5, 0, [])]
... | [
{
"docstring": null,
"function_declaration": "def find_parent(parent, i):",
"function_name": "find_parent",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank... | [
1,
0
] | 1 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_parent(parent, i):\n if parent[i] == i:\n return i\n parent[i] = find_parent(parent, parent[i])\n return parent[i]\n\ndef union(pa... | trial_gpt4o_0 | {
"original_instruction": "A company has a network of N employees connected via friendships. Each employee can communicate with their friends directly or through mutual friends. The company wants to find out how many distinct groups of employees there are, such that each group is connected either directly or indirect... | 0.610131 | Code_Contests_32424 | C | [
"find_parent",
"union",
"count_distinct_groups"
] | 3 | [
[
"count_distinct_groups",
"find_parent"
],
[
"count_distinct_groups",
"union"
],
[
"union",
"find_parent"
]
] | 3 | [] | false | [] | false | pytest | false | [] | true | a508e5fb7d5be83ce0f6968e1bd68b67f533c3a7 | 8b34c01efe34338c3f52482bedc70d46bdfdc34e | |||
v1.0 | complete | Code_Contests | Code_Contests_32692_C | def maximalRectangle(matrix):
"""
Given a matrix containing only 0s and 1s, find the largest rectangular area containing only 1s.
>>> maximalRectangle([['1', '0', '1', '0', '0'], ['1', '0', '1', '1', '1'], ['1', '1', '1', '1', '1'], ['1', '0', '0', '1', '0']]) == 6
>>> maximalRectangle([['0', '1'], ['1'... | def maximalRectangle(matrix):
"""
Given a matrix containing only 0s and 1s, find the largest rectangular area containing only 1s.
"""
if not matrix or not matrix[0]:
return 0
n = len(matrix)
m = len(matrix[0])
max_area = 0
heights = [0] * m
for i in range(n):
... | import pytest
def test_maximalRectangle_empty_matrix():
assert maximalRectangle([]) == 0
assert maximalRectangle([[]]) == 0
def test_maximalRectangle_single_element():
assert maximalRectangle([['0']]) == 0
assert maximalRectangle([['1']]) == 1
def test_maximalRectangle_all_zeros():
assert maximal... | [
{
"docstring": "Given a matrix containing only 0s and 1s, find the largest rectangular area containing only 1s.",
"function_declaration": "def maximalRectangle(matrix):",
"function_name": "maximalRectangle",
"parameter_list": "(matrix)"
},
{
"docstring": "Helper function to calculate the lar... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def maximalRectangle(matrix):\n if not matrix:\n return 0\n \n n, m = len(matrix), len(matrix[0])\n \n # Initialize heights matrix\n ... | trial_gpt4o_1 | {
"original_instruction": "You are given a matrix with n rows and m columns. In each cell, there is either a 0 or a 1.\n\nYour task is to determine the largest possible submatrix which contains only 1s.\n\nInput:\n\nThe first line contains two integers n and m (1 ≤ n, m ≤ 500) — the number of rows and columns of the ... | 0.724365 | Code_Contests_32692 | C | [
"maximalRectangle",
"largestRectangleArea"
] | 2 | [
[
"maximalRectangle",
"largestRectangleArea"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 8dc7013eb65b2915023d823eaca58243b31f2b1d | 88e7f71a4354b341a1b8ebfd8d74bd707d727d75 | |||
v1.0 | complete | Code_Contests | Code_Contests_32586_C | def is_part_of_mst(n: int, m: int, p: int, roads: List[Tuple[int, int, int]], projects: List[Tuple[int, int, int]]) -> List[str]:
""" For each potential construction project, determine if the road would be part of the Minimum Spanning Tree (MST) if it were to be constructed.
>>> is_part_of_mst(4, 4, 3, [(1, 2,... | class DisjointSetUnion:
def __init__(self, n):
self.parent = list(range(n))
self.rank = [0] * n
def find(self, u):
if self.parent[u] != u:
self.parent[u] = self.find(self.parent[u])
return self.parent[u]
def union(self, u, v):
root_u = self.find(u)
... | from solution import is_part_of_mst
def test_example_case():
n = 4
m = 4
p = 3
roads = [
(1, 2, 5),
(2, 3, 3),
(3, 4, 2),
(4, 1, 4)
]
projects = [
(1, 3, 6),
(2, 4, 1),
(3, 1, 7)
]
expected_output = ["NO", "YES", "NO"]
assert i... | [] | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_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 root_x = find(par... | trial_gpt4o_4 | {
"original_instruction": "On a certain island, there are n cities and m bidirectional roads connecting some pairs of cities. You are given a list of potential construction projects, each characterized by the amount of gold it would take to construct that road. Despite the construction cost, the island's rulers will ... | 0.651421 | Code_Contests_32586 | C | [
"kruskal",
"is_part_of_mst"
] | 2 | [
[
"is_part_of_mst",
"kruskal"
]
] | 1 | [] | false | [
"DisjointSetUnion"
] | true | pytest | true | [] | true | bf04fb435e069b9b2b06067cfac1186bb6ffffc5 | 517310b9e2995d77d7a52453bbbd101f94c8688f | |||
v1.0 | complete | Code_Contests | Code_Contests_32681_C | def maximum_ground_distance(segments, start_x, start_y):
""" Calculate the maximum distance a truck can travel on connected ground segments without using any ramp segments.
The truck starts on the specified ground segment.
segments: A list of tuples (x1, y1, x2, y2, type) representing each segment.
star... | import math
def calculate_distance(x1, y1, x2, y2):
return math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
def maximum_ground_distance(segments, start_x, start_y):
graph = {}
ground_segments = []
for (x1, y1, x2, y2, t) in segments:
if t == "ground":
ground_segments.append((x1, y1, x2,... | from solution import maximum_ground_distance, handle_input
def test_maximum_ground_distance():
assert maximum_ground_distance([(0, 0, 1, 1, 'ground'), (1, 1, 2, 2, 'ground'), (2, 2, 3, 3, 'ramp'), (0, 0, 0, 1, 'ramp'), (0, 0, 1, 0, 'ground')], 0, 0) == 2.828
def test_handle_input():
inputs = [
"5",
... | [
{
"docstring": null,
"function_declaration": "def calculate_distance(x1, y1, x2, y2):",
"function_name": "calculate_distance",
"parameter_list": "(x1, y1, x2, y2)"
},
{
"docstring": null,
"function_declaration": "def maximum_ground_distance(segments, start_x, start_y):",
"function_na... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef calculate_distance(x1, y1, x2, y2):\n return math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)\n\ndef maximum_ground_distance(segments, star... | trial_gpt4o_0 | {
"original_instruction": "A road consists of connected segments. Each segment directly connects two intersections except for ramp segments which directly connect an intersection with the skyway or the ground. You need to determine how long a truck can travel on the ground segments without using any ramp segments.\n\... | 0.597558 | Code_Contests_32681 | C | [
"calculate_distance",
"maximum_ground_distance",
"handle_input"
] | 3 | [
[
"handle_input",
"maximum_ground_distance"
],
[
"maximum_ground_distance",
"calculate_distance"
]
] | 2 | [
"handle_input"
] | false | [] | false | pytest | true | [] | true | a642b29c85183f3ed00a15c04c232344e165519c | 1626ccc16b96ca85f977a65587284d62fbdba215 | |||
v1.0 | complete | Code_Contests | Code_Contests_32616_C | def min_cost_to_connect_islands(n: int, m: int, bridges: List[Tuple[int, int, int]]) -> int:
""" Find the minimum cost required to make all islands accessible from any other island.
n: int - the number of islands
m: int - the number of bridges
bridges: List[Tuple[int, int, int]] - a list where each... | def find(parent, i):
if parent[i] == i:
return i
return find(parent, parent[i])
def union(parent, rank, x, y):
rootX = find(parent, x)
rootY = find(parent, y)
if rootX != rootY:
if rank[rootX] > rank[rootY]:
parent[rootY] = rootX
elif rank[rootX] < rank[root... | def test_minimum_cost_possible():
bridges = [
(1, 2, 5),
(1, 3, 10),
(1, 4, 15),
(2, 3, 9),
(3, 4, 4)
]
assert min_cost_to_connect_islands(4, 5, bridges) == 18
def test_single_island():
bridges = []
assert min_cost_to_connect_islands(1, 0, bridges) == 0
def ... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n else:\n parent[i] = find(parent, parent[i])\n return parent[i]\n\ndef uni... | trial_gpt4o_1 | {
"original_instruction": "Island Connectivity\n\nYou are given an archipelago of islands connected by a network of bridges. Each bridge has a certain travel cost associated with it. There are n islands and m bridges connecting pairs of islands. Find the minimum cost required to make all islands accessible from any o... | 0.802234 | Code_Contests_32616 | C | [
"find",
"union",
"min_cost_to_connect_islands"
] | 3 | [
[
"min_cost_to_connect_islands",
"find"
],
[
"min_cost_to_connect_islands",
"union"
],
[
"union",
"find"
]
] | 3 | [] | false | [] | false | pytest | false | [] | true | 53d1faa4741c8f5ef89c28a73710e4f739351769 | c549730feca0b72678efbc51f34cb2577693974d | |||
v1.0 | complete | Code_Contests | Code_Contests_32922_C | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def sorted_array_to_bst(nums):
""" Helper function to convert sorted array to BST """
pass
def inorder_traversal(root):
""" Helper function to perform in-order t... | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def sorted_array_to_bst(nums):
if not nums:
return None
mid = len(nums) // 2
root = TreeNode(nums[mid])
root.left = sorted_array_to_bst(nums... | import pytest
from solution import balanced_bst_inorder
def test_bst_with_single_element():
assert balanced_bst_inorder([1]) == [1]
def test_bst_already_balanced():
assert balanced_bst_inorder([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5]
def test_bst_already_sorted():
assert balanced_bst_inorder([10, 20, 30, 40])... | [] | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_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 sorted_array_to_bst(nums):\n ... | trial_gpt4o_2 | {
"original_instruction": "Phoenix wants to develop a new algorithm for organizing his research papers. Each paper is represented by its importance level, and his goal is to be able to find and access papers of a certain importance level quickly. \n\nTo achieve this, he plans to use a binary search tree (BST) where e... | 0.537862 | Code_Contests_32922 | C | [
"sorted_array_to_bst",
"inorder_traversal",
"balanced_bst_inorder"
] | 3 | [
[
"balanced_bst_inorder",
"inorder_traversal"
],
[
"balanced_bst_inorder",
"sorted_array_to_bst"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 5ddb3f3144b3ae997e7addc0f162465d249e3da2 | 24fb5020bb053626191a7c4eb9c20aef3590fe87 | |||
v1.0 | complete | Code_Contests | Code_Contests_32697_C | from typing import List, Tuple
from collections import defaultdict, deque
def solve_farm_irrigation(N: int, M: int, pipelines: List[Tuple[int, int, int]]) -> int:
""" Determine the maximum water capacity that can be transported from the first fruit patch (0) to the last fruit patch (N-1) considering the given pipe... | from collections import defaultdict, deque
def bfs(capacity, neighbors, source, sink, parent):
visited = set()
queue = deque([source])
visited.add(source)
while queue:
current = queue.popleft()
if current == sink:
return True
for adjacent in ne... | def test_solve_farm_irrigation():
assert solve_farm_irrigation(4, 5, [
(0, 1, 100),
(0, 2, 1),
(1, 2, 50),
(1, 3, 100),
(2, 3, 100)
]) == 101
assert solve_farm_irrigation(2, 1, [
(0, 1, 10)
]) == 10
assert solve_farm_irrigation(3, 3, [
(0, 1,... | [
{
"docstring": null,
"function_declaration": "def bfs(capacity, neighbors, source, sink, parent):",
"function_name": "bfs",
"parameter_list": "(capacity, neighbors, source, sink, parent)"
},
{
"docstring": null,
"function_declaration": "def max_flow(N, pipelines):",
"function_name": ... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque, defaultdict\n\ndef max_water_capacity(N, M, pipelines):\n graph = defaultdict(list)\n for u, v, c in pipelines:\n ... | trial_gpt4o_1 | {
"original_instruction": "Given the soaring popularity of the online game 'Fruits vs Zombies', the developers have decided to introduce a new feature: farm irrigation. In this feature, players can irrigate their fruit farms by laying pipelines, and these pipelines come with certain capacities that can transport a sp... | 0.673124 | Code_Contests_32697 | C | [
"bfs",
"max_flow",
"solve_farm_irrigation"
] | 3 | [
[
"max_flow",
"bfs"
],
[
"solve_farm_irrigation",
"max_flow"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | bf9c7a901902b7ef8566f63b8003a5b048cb9804 | 405bc75e9c3b35af4cf91541d71348ef53eeee24 | |||
v1.0 | complete | Code_Contests | Code_Contests_32244_C | def minimum_time_to_connect_castles(cases):
"""
Determine the minimum time needed to repair enough roads so that there is at least one path connecting every pair of castles.
Args:
cases : List of Tuples containing (n, m, [(a, b, t), ...]), where n is the number of castles, m is the number of roads,
... | def find(parent, i):
if parent[i] == i:
return i
else:
parent[i] = find(parent, parent[i])
return parent[i]
def union(parent, rank, x, y):
xroot = find(parent, x)
yroot = find(parent, y)
if rank[xroot] < rank[yroot]:
parent[xroot] = yroot
elif rank[xroot] > rank... | def test_case_1():
input_str = """4 4
1 2 5
2 3 3
3 4 4
4 1 6"""
expected = 12
cases = parse_input(input_str)
results = minimum_time_to_connect_castles(cases)
assert results[0] == expected
def test_case_2():
input_str = """4 3
1 2 5
2 3 2
1 3 4"""
expected = -1
cases = parse_input(input... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n else:\n parent[i] = find(parent, parent[i])\n return parent[i]\n\ndef uni... | trial_gpt4o_1 | {
"original_instruction": "In a distant kingdom, there are N castles (numbered 1 to N inclusive) and M bidirectional roads connecting the castles. Each road i has a repair time of Ti days to make it functional. Initially, all roads are broken due to recent attacks by dragons. The kingdom's monarch has issued a royal ... | 0.602147 | Code_Contests_32244 | C | [
"find",
"union",
"kruskal",
"minimum_time_to_connect_castles",
"parse_input",
"solve"
] | 6 | [
[
"kruskal",
"find"
],
[
"kruskal",
"union"
],
[
"minimum_time_to_connect_castles",
"kruskal"
],
[
"solve",
"minimum_time_to_connect_castles"
],
[
"solve",
"parse_input"
],
[
"union",
"find"
]
] | 6 | [
"parse_input"
] | false | [] | false | pytest | false | [] | true | a6cee6c81d1429452fdc95872d24f9242da0e904 | 66ee3a30436f3f6c3c59fb10d03c81bb7f83a300 | |||
v1.0 | complete | Code_Contests | Code_Contests_33029_C | from typing import List, Tuple
def get_tree_height(n: int, edges: List[Tuple[int, int]]) -> int:
"""
Determine the height of a binary tree given its edges.
Parameters:
n (int): The number of nodes in the binary tree.
edges (List[Tuple[int, int]]): The edges in the binary tree, where each edge... | from collections import defaultdict, deque
def build_tree(edges, n):
tree = defaultdict(list)
for u, v in edges:
tree[u].append(v)
tree[v].append(u)
return tree
def get_tree_height(n, edges):
if n == 0:
return -1
if n == 1:
return 0
tree = build_tree(edges,... | from solution import get_tree_height
def test_single_node():
assert get_tree_height(1, []) == 0
def test_two_nodes():
assert get_tree_height(2, [(1, 2)]) == 1
def test_five_nodes():
assert get_tree_height(5, [(1, 2), (1, 3), (3, 4), (3, 5)]) == 2
def test_more_complex_tree():
assert get_tree_height(... | [
{
"docstring": null,
"function_declaration": "def build_tree(edges, n):",
"function_name": "build_tree",
"parameter_list": "(edges, n)"
},
{
"docstring": null,
"function_declaration": "def get_tree_height(n, edges):",
"function_name": "get_tree_height",
"parameter_list": "(n, edg... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque, defaultdict\n\ndef tree_height(n, edges):\n if n == 1:\n return 0\n\n # Create adjacency list representation of... | trial_gpt4o_1 | {
"original_instruction": "You are given a binary tree with n nodes, where each node has a unique value between 1 and n. Your task is to determine the height of the tree.\n\nThe height of a binary tree is defined as the length of the longest path from the root to a leaf node. The length of a path is the number of edg... | 0.534121 | Code_Contests_33029 | C | [
"build_tree",
"get_tree_height"
] | 2 | [
[
"get_tree_height",
"build_tree"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ad245666703a73fcad7133573b08d78d8a861ce3 | 33c84b5b6c3cfcf38dd684013800b643048f005d | |||
v1.0 | complete | Code_Contests | Code_Contests_32895_C | def connected_cities(n: int, m: int, roads: List[Tuple[int, int]], q: int, queries: List[Tuple[int, int]]) -> List[str]:
""" Determine whether there is a path between two cities.
Each query is a pair of cities and the answer to each query is YES if there is a path
connecting the two cities directly or indi... | def find_parent(parent, i):
if parent[i] == i:
return i
else:
parent[i] = find_parent(parent, parent[i])
return parent[i]
def union(parent, rank, x, y):
xroot = find_parent(parent, x)
yroot = find_parent(parent, y)
if xroot != yroot:
if rank[xroot] < rank[yroot]... | def test_connected_cities_simple_positive_case():
n, m = 5, 4
roads = [(1, 2), (2, 3), (3, 4), (4, 5)]
q = 3
queries = [(1, 5), (2, 5), (5, 1)]
assert connected_cities(n, m, roads, q, queries) == ["YES", "YES", "YES"]
def test_connected_cities_simple_negative_case():
n, m = 4, 2
roads = [(1... | [
{
"docstring": null,
"function_declaration": "def find_parent(parent, i):",
"function_name": "find_parent",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_set(parent, x):\n if parent[x] != x:\n parent[x] = find_set(parent, parent[x])\n return parent[x]\n\ndef union_set(parent, rank, x, y... | trial_gpt4o_1 | {
"original_instruction": "You are given `n` cities and `m` roads connecting some pairs of the cities. You're required to implement a system that helps determine whether there is a path between two cities. \n\nEach query is a pair of cities and the answer to each query is YES if there is a path connecting the two cit... | 0.70179 | Code_Contests_32895 | C | [
"find_parent",
"union",
"connected_cities"
] | 3 | [
[
"connected_cities",
"find_parent"
],
[
"connected_cities",
"union"
],
[
"union",
"find_parent"
]
] | 3 | [] | false | [] | false | pytest | false | [] | true | ab42cc6994e011bd1fe63248bb9de29695c30627 | 1b9fb039df2fe7941f42677ccbf0776918047bfe | |||
v1.0 | complete | Code_Contests | Code_Contests_32912_C | import math
from functools import reduce
def lcm(a, b):
"""
Returns the least common multiple of a and b.
"""
pass
def find_earliest_broadcast_time(n, frequencies):
"""
Returns the earliest time by which the signal tower can broadcast the next message
that satisfies as many of the receiver... | import math
from functools import reduce
def lcm(a, b):
"""
Returns the least common multiple of a and b.
"""
return abs(a*b) // math.gcd(a, b)
def find_earliest_broadcast_time(n, frequencies):
"""
Returns the earliest time by which the signal tower can broadcast the next message
that sati... | from solution import find_earliest_broadcast_time
def test_single_frequency():
assert find_earliest_broadcast_time(1, [5]) == 5
def test_multiple_frequencies_example_1():
assert find_earliest_broadcast_time(4, [4, 6, 8, 12]) == 24
def test_multiple_frequencies_example_2():
assert find_earliest_broadcast_... | [
{
"docstring": "Returns the least common multiple of a and b.",
"function_declaration": "def lcm(a, b):",
"function_name": "lcm",
"parameter_list": "(a, b)"
},
{
"docstring": "Returns the earliest time by which the signal tower can broadcast the next message\nthat satisfies as many of the re... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\nfrom functools import reduce\n\ndef lcm(a, b):\n \"\"\"Returns the least common multiple of a and b.\"\"\"\n return a * b // math.gcd(a,... | trial_gpt4o_2 | {
"original_instruction": "An aging signal tower is configured to broadcast a vital message at regular intervals to multiple receiver towers in a remote region. The broadcast cycle is determined by the desired frequencies of each receiver tower. However, due to wear and tear, the signal tower now has to be rebooted m... | 0.508051 | Code_Contests_32912 | C | [
"lcm",
"find_earliest_broadcast_time"
] | 2 | [
[
"find_earliest_broadcast_time",
"lcm"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 2331ccac4b3823d5d6e2611701b1e23cff407779 | c56d5c3b1b182a7fbaa0b08018ea5bb95d7b0bfa | |||
v1.0 | complete | Code_Contests | Code_Contests_31852_C | def generate_grid(n: int) -> List[List[int]]:
"""
Generate a square grid of size (2*n - 1) x (2*n - 1) with a unique numeric pattern.
The integer values run horizontally, vertically, and diagonally across the grid.
Return the grid as a list of lists of integers.
>>> generate_grid(1)
[[1]]
... | def generate_grid(n):
size = 2 * n - 1
grid = [[0] * size for _ in range(size)]
for i in range(size):
for j in range(size):
grid[i][j] = n - (abs(n - 1 - i) + abs(n - 1 - j))
for i in range(size):
for j in range(size):
if grid[i][j] < 0:
grid[i][... | from solution import generate_grid
def test_generate_grid_base_case():
expected = [
[1]
]
assert generate_grid(1) == expected
def test_generate_grid_2():
expected = [
[0, 1, 0],
[1, 2, 1],
[0, 1, 0]
]
assert generate_grid(2) == expected
def test_generate_grid_3... | [
{
"docstring": null,
"function_declaration": "def generate_grid(n):",
"function_name": "generate_grid",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def print_grid(n):",
"function_name": "print_grid",
"parameter_list": "(n)"
}
] | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def generate_grid(n):\n size = 2 * n - 1\n grid = [[0] * size for _ in range(size)]\n\n for i in range(size):\n for j in range(size):\n ... | trial_gpt4o_0 | {
"original_instruction": "John is a software engineer who loves puzzles. Recently, he came across a unique numeric pattern and wants to replicate it using a program. The pattern consists of consecutive numbers arranged in a diamond shape within a square grid of size (2*n - 1) x (2*n - 1). Here, the integer values ru... | 0.707756 | Code_Contests_31852 | C | [
"generate_grid",
"print_grid"
] | 2 | [
[
"print_grid",
"generate_grid"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0c4da185735a76fdfa9e1f309f3c66f87c455526 | b7b51c05aa1fc7d362346fcb403a870b14fb45c7 | |||
v1.0 | complete | Code_Contests | Code_Contests_33066_C | def count_ways_to_connect_towers(n: int) -> int:
"""
Returns the number of ways to connect `n` towers with non-intersecting ropes.
>>> count_ways_to_connect_towers(3)
0
>>> count_ways_to_connect_towers(4)
2
"""
pass
import pytest
def test_one_tower():
assert count_ways_to_connect_... | def calculate_catalan_number(n):
"""
Calculates the n-th Catalan number.
"""
if n == 0:
return 1
catalan = [0] * (n + 1)
catalan[0] = 1
for i in range(1, n + 1):
for j in range(i):
catalan[i] += catalan[j] * catalan[i - 1 - j]
return catalan[n]
def count_ways... | import pytest
from solution import count_ways_to_connect_towers
def test_one_tower():
assert count_ways_to_connect_towers(1) == 0
def test_two_towers():
assert count_ways_to_connect_towers(2) == 1
def test_three_towers():
assert count_ways_to_connect_towers(3) == 0
def test_four_towers():
assert cou... | [
{
"docstring": "Calculates the n-th Catalan number.",
"function_declaration": "def calculate_catalan_number(n):",
"function_name": "calculate_catalan_number",
"parameter_list": "(n)"
},
{
"docstring": "Returns the number of ways to connect `n` towers with non-intersecting ropes.",
"funct... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def calculate_catalan_number(n):\n \"\"\"\n Calculates the n-th Catalan number.\n \"\"\"\n if n == 0:\n return 1\n catalan = [0] * (n... | trial_gpt4o_0 | {
"original_instruction": "John's favorite hobby is building sandcastles. One day, while building a sandcastle with his friends, he decides to make it more challenging and fun. They plan to build a large sandcastle with several towers. Each tower is represented as a stick standing on the ground. John wants to connect... | 0.506998 | Code_Contests_33066 | C | [
"calculate_catalan_number",
"count_ways_to_connect_towers"
] | 2 | [
[
"count_ways_to_connect_towers",
"calculate_catalan_number"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 3070acf2a5423695ea566c0bfb48d6c182b1700c | 8512f5bfc5db7c5234a7ee6d68291ac527c903f1 | |||
v1.0 | complete | Code_Contests | Code_Contests_32972_C | import math
from typing import List
def is_triangular(num: int) -> int:
"""Check if a number is a triangular number and return its position in the sequence.
>>> is_triangular(1)
1
>>> is_triangular(3)
2
>>> is_triangular(6)
3
>>> is_triangular(9)
-1
>>> is_triangular(10)
4
... | import math
def is_triangular(num):
if num <= 0:
return -1
# Calculate n by solving the quadratic equation n^2 + n - 2*num = 0 using the quadratic formula
n = (-1 + math.sqrt(1 + 8 * num)) / 2
if n.is_integer():
return int(n)
else:
return -1
def process_numbers(nu... | from solution import is_triangular, process_numbers
def test_is_triangular():
assert is_triangular(1) == 1
assert is_triangular(3) == 2
assert is_triangular(6) == 3
assert is_triangular(9) == -1
assert is_triangular(10) == 4
assert is_triangular(0) == -1
assert is_triangular(-5) == -1
def ... | [
{
"docstring": null,
"function_declaration": "def is_triangular(num):",
"function_name": "is_triangular",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def process_numbers(numbers):",
"function_name": "process_numbers",
"parameter_list": "(numbers)"
... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef is_triangular_number(number):\n \"\"\"\n Determines if a number is a triangular number and returns the index of the number if it i... | trial_gpt4o_2 | {
"original_instruction": "A competitive coder loves writing short scripts to solve math problems on the go. One day, the coder encountered a fascinating problem involving triangular numbers and decided to write a program to solve it.\n\nTriangular numbers are the sequence of numbers that can form an equilateral tria... | 0.623926 | Code_Contests_32972 | C | [
"is_triangular",
"process_numbers"
] | 2 | [
[
"process_numbers",
"is_triangular"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a4b86471872fa6f09545b460c3bfb2c2d040d9c2 | 75f63126cfa612fa28b4163b85e84c6662c8550f | |||
v1.0 | complete | Code_Contests | Code_Contests_32991_C | import heapq
from collections import defaultdict
def minimum_travel_time(n: int, m: int, tracks: List[Tuple[int, int, int]], start: int, end: int) -> int:
""" Calculate the minimum travel time required for a train to travel from a given start station to a destination station.
The train can make stops at other ... | import heapq
from collections import defaultdict
import sys
def dijkstra(n, graph, start, end):
pq = [(0, start)]
dist = {i: float('inf') for i in range(1, n+1)}
dist[start] = 0
while pq:
current_dist, current_station = heapq.heappop(pq)
if current_station == end:
return c... | from solution import minimum_travel_time
def test_case1():
n = 5
m = 6
tracks = [
(1, 2, 10),
(2, 3, 20),
(1, 3, 30),
(3, 4, 10),
(4, 5, 20),
(3, 5, 30)
]
start, end = 1, 5
assert minimum_travel_time(n, m, tracks, start, end) == 60
def test_case2... | [
{
"docstring": null,
"function_declaration": "def dijkstra(n, graph, start, end):",
"function_name": "dijkstra",
"parameter_list": "(n, graph, start, end)"
},
{
"docstring": null,
"function_declaration": "def minimum_travel_time(n, m, tracks, start, end):",
"function_name": "minimum_... | [
1,
1
] | 2 | easy | 1 | {
"trial_gpt4o_0": null,
"trial_gpt4o_1": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared1_results_combined.jsonl",
"solution_code": "import heapq\nfrom collections import defaultdict\nimport sys\n\ndef dijkstra(n, graph, start, end):\n pq = [(0, start)]\n d... | trial_gpt4o_1 | {
"original_instruction": "You are tasked with managing a railway system. The system comprises multiple stations connected by railway tracks. Each track has a certain travel time associated with it. Passengers can board and deboard trains at each station.\n\nYou need to create a program that calculates the minimum tr... | 0.72247 | Code_Contests_32991 | C | [
"dijkstra",
"minimum_travel_time"
] | 2 | [
[
"minimum_travel_time",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 694d07c25223f836521292781da8a20b3620cdae | 6ad9b593aecad344f923eb1394adca1f1520c7bc | |||
v1.0 | complete | Code_Contests | Code_Contests_32700_C | def is_prime(n: int) -> bool:
"""Determine whether a given number is a prime number.
>>> is_prime(2)
True
>>> is_prime(3)
True
>>> is_prime(4)
False
>>> is_prime(11)
True
>>> is_prime(25)
False
"""
pass
def sum_of_digits(n: int) -> int:
"""Calculate the sum of di... | 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 sum_of_digits(n):
return sum(int(digit... | def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(11) == True
assert is_prime(25) == False
def test_sum_of_digits():
assert sum_of_digits(113) == 5
assert sum_of_digits(74) == 11
assert sum_of_digits(123456789) == 45
... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def sum_of_digits(n):",
"function_name": "sum_of_digits",
"parameter_list": "(n)"
},
{
"docstring": null,... | [
0,
0,
0,
1,
0
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(number):\n \"\"\"\n Helper function to check if a given number is prime.\n \"\"\"\n if number <= 1:\n return False\n if ... | trial_gpt4o_3 | {
"original_instruction": "Jack loves prime numbers and he wants to discover prime numbers in an interesting way. He came up with a method where he sums up each digit of a number and checks if the result is a prime number. Therefore, he wants your help to determine, for a given number N, whether the sum of its digits... | 0.744328 | Code_Contests_32700 | C | [
"is_prime",
"sum_of_digits",
"check_prime_digit_sum"
] | 3 | [
[
"check_prime_digit_sum",
"is_prime"
],
[
"check_prime_digit_sum",
"sum_of_digits"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 8e1ea4ac458eb0fcc9e255de2f08c5d9718ace34 | 86a76a0d9b2790fad1baa9eccd565efbeecdbf65 | |||
v1.0 | complete | Code_Contests | Code_Contests_32155_C | from typing import List, Tuple
def min_recolor_operations(t: int, test_cases: List[Tuple[int, int, List[str]]]) -> List[int]:
""" Calculate the minimum number of cells that need to be recolored to achieve the alternating pattern.
If it is impossible, return -1.
Args:
t (int): number of test cases.
... | def min_recolor_operations(t, test_cases):
favorite_patterns = [[0] * t for _ in range(2)]
# Generate the two types of favorite patterns
def generate_pattern(n, m):
pattern1 = [['G' if (i + j) % 2 == 0 else 'R' for j in range(m)] for i in range(n)]
pattern2 = [['R' if (i + j) % 2 == 0 else ... | from solution import min_recolor_operations, parse_input, min_recolor_from_input
def test_example_1():
input_str = "3\n3 3\nGRG\nRGR\nGRG\n4 4\nGRGR\nRGRG\nGRGR\nRGRG\n2 3\nGGR\nRGG\n"
expected_output = "0\n0\n3"
assert min_recolor_from_input(input_str) == expected_output
def test_no_recolor_needed():
... | [
{
"docstring": null,
"function_declaration": "def min_recolor_operations(t, test_cases):",
"function_name": "min_recolor_operations",
"parameter_list": "(t, test_cases)"
},
{
"docstring": null,
"function_declaration": "def parse_input(input_str):",
"function_name": "parse_input",
... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def min_recolor_operations(t, test_cases):\n results = []\n\n for case in test_cases:\n n, m, grid = case\n pattern1 = [[\"G\" if (i + ... | trial_gpt4o_2 | {
"original_instruction": "Jasmine loves creating shapes on her n × m checkered grid. Each cell in the grid can either be green ('G') or red ('R'). She wants to make the entire grid match her favorite alternating pattern: 'GRGRGR...' in the first row, 'RGRGRG...' in the second row, 'GRGRGR...' in the third row, and s... | 0.70289 | Code_Contests_32155 | C | [
"min_recolor_operations",
"parse_input",
"min_recolor_from_input"
] | 3 | [
[
"min_recolor_from_input",
"min_recolor_operations"
],
[
"min_recolor_from_input",
"parse_input"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 23f50a8661fad11c238f1a787d5ff74544e607e4 | 3feea7766095fab172af8c01323bfccf9b9692fe | |||
v1.0 | complete | Code_Contests | Code_Contests_33015_C | from typing import List, Tuple
def calculate_manhattan_distance(x1: int, y1: int, x2: int, y2: int) -> int:
return abs(x1 - x2) + abs(y1 - y2)
def min_total_distance(n: int, packages: List[Tuple[int, int]], m: int, drivers: List[Tuple[int, int, int]]) -> int:
""" Computes the minimum total distance drivers ha... | from itertools import permutations
import math
def calculate_manhattan_distance(x1, y1, x2, y2):
return abs(x1 - x2) + abs(y1 - y2)
def min_total_distance(n, packages, m, drivers):
# Helper function to calculate total distance for a permutation of packages
def total_distance_for_permutation(perm, packages... | from solution import min_total_distance
def test_example_1():
n = 5
packages = [(0, 0), (1, 2), (3, 3), (4, 1), (1, 1)]
m = 2
drivers = [(-1, -1, 3), (2, 2, 2)]
assert min_total_distance(n, packages, m, drivers) == 18
def test_example_2():
n = 3
packages = [(0, 0), (2, 2), (3, 3)]
m = ... | [
{
"docstring": null,
"function_declaration": "def calculate_manhattan_distance(x1, y1, x2, y2):",
"function_name": "calculate_manhattan_distance",
"parameter_list": "(x1, y1, x2, y2)"
},
{
"docstring": null,
"function_declaration": "def min_total_distance(n, packages, m, drivers):",
... | [
0,
0,
0,
0,
0,
0,
0,
1,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import itertools\n\ndef min_total_distance(n, packages, m, drivers):\n def manhattan_distance(p1, p2):\n x1, y1 = p1\n x2, y2 = p2\n ... | trial_gpt4o_7 | {
"original_instruction": "You are a software engineer at a transportation logistics company called FastRoute. Your team is working on a program to optimize delivery routes for drivers by minimizing the total distance traveled while ensuring that every package is delivered efficiently. Each package has a unique deliv... | 0.653805 | Code_Contests_33015 | C | [
"calculate_manhattan_distance",
"min_total_distance"
] | 2 | [
[
"min_total_distance",
"calculate_manhattan_distance"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8571aef2aafd2a0f1b6dafe1328c2da9501e229a | eac735b06b6106542e86601c1910ec8af2b32be1 | |||
v1.0 | complete | Code_Contests | Code_Contests_33215_C | def minimize_max_distance(T: int, test_cases: List[Tuple[int, int, List[int]]]) -> List[int]:
""" Determine the optimal locations for warehouses to minimize the maximum distance any route will need to travel to its nearest warehouse.
Args:
T (int): Number of test cases.
test_cases (List[Tuple[int, int,... | def canPlaceWarehouses(route_lengths, max_distance, K):
warehouses_used = 1
last_warehouse_position = route_lengths[0]
for i in range(1, len(route_lengths)):
if route_lengths[i] - last_warehouse_position > max_distance:
warehouses_used += 1
last_warehouse_position = route_le... | from solution import minimize_max_distance
def test_minimize_max_distance_case1():
T = 1
test_cases = [
(5, 2, [1, 2, 8, 10, 12])
]
result = minimize_max_distance(T, test_cases)
assert result == [4]
def test_minimize_max_distance_case2():
T = 1
test_cases = [
(5, 1, [1, 2, ... | [
{
"docstring": null,
"function_declaration": "def canPlaceWarehouses(route_lengths, max_distance, K):",
"function_name": "canPlaceWarehouses",
"parameter_list": "(route_lengths, max_distance, K)"
},
{
"docstring": null,
"function_declaration": "def minimize_max_distance(T, test_cases):",... | [
0,
0,
0,
0,
0,
1,
1,
0,
1
] | 3 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def min_max_distance(T, test_cases):\n def is_feasible(max_dist, routes, K):\n warehouses = 1\n last_warehouse = routes[0]\n \n ... | trial_gpt4o_9 | {
"original_instruction": "In a bustling city, there are several delivery routes, each with a specific length. The city's transport manager wants to establish warehouses such that the maximum route length from any warehouse to its assigned routes is minimized. The manager can choose to place up to K warehouses.\n\nGi... | 0.630417 | Code_Contests_33215 | C | [
"canPlaceWarehouses",
"minimize_max_distance"
] | 2 | [
[
"minimize_max_distance",
"canPlaceWarehouses"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f55628221610a703974417cb1f53b0bd7b2c2dbd | 10473a8b3f02940148e797431cacacc573e6a651 | |||
v1.0 | complete | Code_Contests | Code_Contests_33357_C | def magical_array(n: int) -> List[int]:
""" Generates a magical array with the first n elements starting from 1, where the sum of any two adjacent elements is a perfect square.
>>> magical_array(4)
[1, 3, 6, 10]
>>> magical_array(2)
[1, 3]
>>> magical_array(5)
[1, 3, 6, 10, 15]
""" | def is_perfect_square(x):
"""
Checks if a number is a perfect square.
"""
return int(x**0.5) ** 2 == x
def magical_array(n):
"""
Generates a magical array with the first n elements starting from 1.
"""
if n == 1:
return [1]
result = [1]
current = 1
while len(re... | from solution import magical_array
def test_single_element():
assert magical_array(1) == [1]
def test_two_elements():
assert magical_array(2) == [1, 3]
def test_three_elements():
assert magical_array(3) == [1, 3, 6]
def test_four_elements():
assert magical_array(4) == [1, 3, 6, 10]
def test_five_el... | [
{
"docstring": "Checks if a number is a perfect square.",
"function_declaration": "def is_perfect_square(x):",
"function_name": "is_perfect_square",
"parameter_list": "(x)"
},
{
"docstring": "Generates a magical array with the first n elements starting from 1.",
"function_declaration": "... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef is_perfect_square(x):\n \"\"\"Check if x is a perfect square.\"\"\"\n root = int(math.isqrt(x))\n return root * root == x\n\nde... | trial_gpt4o_2 | {
"original_instruction": "A magical array is an array of integers where the sum of any two adjacent elements is a perfect square. Given an integer n, write a program to find the first n elements of a magical array starting from the integer 1. If there is no valid array possible, return an empty array.\n\nInput\n\nTh... | 0.643573 | Code_Contests_33357 | C | [
"is_perfect_square",
"magical_array"
] | 2 | [
[
"magical_array",
"is_perfect_square"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ccfce83e84cc217001cb528aec2988b2e597b688 | c2b51026bc54ac39176937e571cc82bf0a1b25ea | |||
v1.0 | complete | Code_Contests | Code_Contests_33401_C | import math
def is_prime(n: int) -> bool:
""" Check if a number n is prime.
>>> is_prime(11)
True
>>> is_prime(4)
False
"""
pass
def find_twin_primes(l: int, r: int) -> None:
""" Find all pairs of twin primes (p1, p2) such that l ≤ p1 < p2 ≤ r,
and p2 - p1 = 2.
>>> find_t... | import math
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 find_twin_primes(l, r):
t... | from solution import find_twin_primes
def test_find_twin_primes_case1(capfd):
find_twin_primes(10, 50)
out, err = capfd.readouterr()
assert out == "11 13\n17 19\n29 31\n41 43\n"
assert err == ""
def test_find_twin_primes_case2(capfd):
find_twin_primes(48, 52)
out, err = capfd.readouterr()
... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def find_twin_primes(l, r):",
"function_name": "find_twin_primes",
"parameter_list": "(l, r)"
}
] | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_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 <= 3:\n return True\n if n % 2 ==... | trial_gpt4o_1 | {
"original_instruction": "Lena has a unique interest in prime numbers. She recently discovered an interesting property regarding Twin Primes. Twin Primes are pairs of primes that have a difference of 2. For example, (3, 5) and (11, 13) are twin primes.\n\nLena wants to develop a program that can find all pairs of tw... | 0.69738 | Code_Contests_33401 | C | [
"is_prime",
"find_twin_primes"
] | 2 | [
[
"find_twin_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 80b0ef0e3eeacbc19412e74b92f3b165790fa384 | 72f76efb5935197a72f6580d84dffec448a6f0d3 | |||
v1.0 | complete | Code_Contests | Code_Contests_33076_C | def find_missing_numbers(original_seq, corrupted_seq):
""" Finds the missing numbers required to restore the corrupted sequence to match the original sequence.
>>> find_missing_numbers([1, 3, 5, 7, 9], [1, 7, 9])
[3, 5]
>>> find_missing_numbers([2, 4, 6, 8, 10, 12], [4, 8, 10, 12])
[2, 6]
"""
d... | def find_missing_numbers(original_seq, corrupted_seq):
"""
Finds the missing numbers required to restore the corrupted sequence to match the original sequence.
"""
original_set = set(original_seq)
corrupted_set = set(corrupted_seq)
missing_numbers = sorted(original_set - corrupted_set)
retur... | from solution import find_missing_numbers, restore_sequences
def test_find_missing_numbers_example_1():
original_seq = [1, 3, 5, 7, 9]
corrupted_seq = [1, 7, 9]
assert find_missing_numbers(original_seq, corrupted_seq) == [3, 5]
def test_find_missing_numbers_example_2():
original_seq = [2, 4, 6, 8, 10,... | [
{
"docstring": "Finds the missing numbers required to restore the corrupted sequence to match the original sequence.",
"function_declaration": "def find_missing_numbers(original_seq, corrupted_seq):",
"function_name": "find_missing_numbers",
"parameter_list": "(original_seq, corrupted_seq)"
},
{... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_missing_numbers(original, corrupted):\n \"\"\"\n Finds the missing numbers from corrupted sequence to match the original sequence.\n \n ... | trial_gpt4o_2 | {
"original_instruction": "The Agriculture Research Institute is conducting a study to analyze the growth patterns of various crops based on climate data collected over the years. They have developed a software application that uses series of integer sequences to model the growth pattern of crops over time.\n\nHoweve... | 0.61554 | Code_Contests_33076 | C | [
"find_missing_numbers",
"restore_sequences",
"process_input"
] | 3 | [
[
"restore_sequences",
"find_missing_numbers"
]
] | 1 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | f8bb0b05a74c3eeed6e459df75b0d7c5b8accfd5 | 8907c99bec6c9ecaccdf6d1a3b6b83acc61bd3d3 | |||
v1.0 | complete | Code_Contests | Code_Contests_33153_C | from typing import List, Tuple
def can_make_all_elements_equal(n: int, arr: List[int]) -> str:
"""
Returns "YES" if it is possible to make all elements equal, otherwise "NO".
>>> can_make_all_elements_equal(3, [4, 8, 12])
"YES"
>>> can_make_all_elements_equal(4, [2, 3, 6, 9])
"NO"
>>> can_m... | import math
from functools import reduce
def can_make_all_elements_equal(n, arr):
"""
Returns "YES" if it is possible to make all elements equal, otherwise "NO".
"""
gcd_all = reduce(math.gcd, arr)
return "YES" if gcd_all != 1 else "NO"
def process_test_cases(t, test_cases):
results = []
f... | import pytest
from solution import can_make_all_elements_equal, process_test_cases, input_processing
def test_can_make_all_elements_equal():
assert can_make_all_elements_equal(3, [4, 8, 12]) == "YES"
assert can_make_all_elements_equal(4, [2, 3, 6, 9]) == "NO"
assert can_make_all_elements_equal(2, [5, 10]) ... | [
{
"docstring": "Returns \"YES\" if it is possible to make all elements equal, otherwise \"NO\".",
"function_declaration": "def can_make_all_elements_equal(n, arr):",
"function_name": "can_make_all_elements_equal",
"parameter_list": "(n, arr)"
},
{
"docstring": null,
"function_declaration... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\nfrom functools import reduce\n\ndef gcd_of_array(arr):\n return reduce(math.gcd, arr)\n\ndef can_make_elements_equal(test_cases):\n resu... | trial_gpt4o_2 | {
"original_instruction": "You are given an array of integers a = [a_0, a_1, ..., a_{n - 1}] (n ≥ 1). You can perform the following operation any number of times: choose two elements a_i and a_j (i ≠ j) and replace both a_i and a_j with a_i + a_j.\n\nDetermine whether it's possible to make all elements of the array e... | 0.614654 | Code_Contests_33153 | C | [
"can_make_all_elements_equal",
"process_test_cases",
"input_processing"
] | 3 | [
[
"process_test_cases",
"can_make_all_elements_equal"
]
] | 1 | [
"process_test_cases"
] | false | [] | false | pytest | true | [] | true | b88f7ec01d5b493f9b7c6a36b28d91ef5ab34650 | 2d81fd4967e1639f3cf7db24d6810e3766d9b129 | |||
v1.0 | complete | Code_Contests | Code_Contests_33248_C | def get_next_number(num):
"""Helper function to get the sum of the squares of digits of a number"""
sum_of_squares = 0
while num:
digit = num % 10
sum_of_squares += digit * digit
num //= 10
return sum_of_squares
def is_happy_number(n):
"""Determines if a number n is a Happy ... | def is_happy_number(n):
"""
Determines if a number n is a Happy Number or not.
Args:
n (int): positive integer to check for happiness.
Returns:
bool: True if n is a Happy Number, False otherwise.
"""
def get_next_number(num):
sum_of_squares = 0
while num:
... | from solution import is_happy_number, happy_number_checker
def test_is_happy_number():
assert is_happy_number(19) == True
assert is_happy_number(2) == False
assert is_happy_number(7) == True
assert is_happy_number(1) == True
assert is_happy_number(0) == False
def test_happy_number_checker():
a... | [
{
"docstring": "Determines if a number n is a Happy Number or not.\n\nArgs:\nn (int): positive integer to check for happiness.\n\nReturns:\nbool: True if n is a Happy Number, False otherwise.",
"function_declaration": "def is_happy_number(n):",
"function_name": "is_happy_number",
"parameter_list": "... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_happy_number(n):\n \"\"\"\n Determines if a number n is a Happy Number or not.\n \n Args:\n n (int): positive integer to check for ha... | trial_gpt4o_0 | {
"original_instruction": "**Problem Statement**\n\nBob loves playing with numbers, especially finding interesting patterns within them. One day, Bob came across the concept of Happy Numbers. Bob wants to share the joy of Happy Numbers with his friends through a program that can determine whether a given number is ha... | 0.61066 | Code_Contests_33248 | C | [
"is_happy_number",
"happy_number_checker"
] | 2 | [
[
"happy_number_checker",
"is_happy_number"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | fe30644ccd1058f38e6a8e6ac83b1a26c63f4945 | bd98d5286f3a27768e6e773ee163958138abb2e9 | |||
v1.0 | complete | Code_Contests | Code_Contests_33105_C | class TreeNode:
def __init__(self, value=0, left=None, right=None):
self.value = value
self.left = left
self.right = right
def build_tree(preorder, inorder):
"""
Build binary tree from preorder and inorder traversals.
:param preorder: List[int] - The preorder traversal.
:par... | class TreeNode:
def __init__(self, value=0, left=None, right=None):
self.value = value
self.left = left
self.right = right
def build_tree(preorder, inorder):
if not preorder or not inorder:
return None
root_value = preorder[0]
root = TreeNode(root_value)
root_index... | from solution import find_height_of_binary_tree
def test_basic_case():
n = 5
preorder = [1, 2, 4, 5, 3]
inorder = [4, 2, 5, 1, 3]
assert find_height_of_binary_tree(n, preorder, inorder) == 3
def test_single_node():
n = 1
preorder = [1]
inorder = [1]
assert find_height_of_binary_tree(n,... | [] | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, x):\n self.value = x\n self.left = None\n self.right = None\n\ndef build_tree(preorder, inorde... | trial_gpt4o_1 | {
"original_instruction": "Your task is to construct a binary tree given specific traversal orders and then compute the height of the tree. You need to use the given preorder and inorder traversal sequences to reconstruct the original binary tree and then determine its height. The height of the binary tree is the num... | 0.58299 | Code_Contests_33105 | C | [
"build_tree",
"tree_height",
"find_height_of_binary_tree"
] | 3 | [
[
"find_height_of_binary_tree",
"build_tree"
],
[
"find_height_of_binary_tree",
"tree_height"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | e2ed1c43322e6609b04b0bb2684fb93e837d0ec6 | 11efba4ac089c948b13a2440801c24f711cab309 | |||
v1.0 | complete | Code_Contests | Code_Contests_33339_C | def compute_mst(n: int, m: int, edges: List[Tuple[int, int, int]]) -> Union[int, str]:
""" Compute the total weight of the Minimum Spanning Tree (MST) for the given graph.
Parameters:
n (int): Number of nodes.
m (int): Number of edges.
edges (List[Tuple[int, int, int]]): List of edges where eac... | 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[yroot]... | def test_example1():
n, m = 4, 5
edges = [(1, 2, 3), (1, 3, 4), (4, 2, 2), (3, 2, 5), (4, 3, 1)]
assert compute_mst(n, m, edges) == 6
def test_example2():
n, m = 4, 1
edges = [(1, 2, 3)]
assert compute_mst(n, m, edges) == "IMPOSSIBLE"
def test_single_node():
n, m = 1, 0
edges = []
... | [
{
"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_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n else:\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n ro... | trial_gpt4o_1 | {
"original_instruction": "You are tasked with helping an urban planner design an efficient bus route system to connect various hubs in a city. Each hub is represented as a node, and each possible bus route between two hubs is represented as a weighted edge, where the weight denotes the distance between the two hubs.... | 0.781887 | Code_Contests_33339 | C | [
"find",
"union",
"kruskal_mst",
"compute_mst"
] | 4 | [
[
"compute_mst",
"kruskal_mst"
],
[
"kruskal_mst",
"find"
],
[
"kruskal_mst",
"union"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | false | [] | true | 195397cc8e19421a9cca8cdbfee26dbebdafb2cf | 19d1dbfe8ff2e75000f60d055f3c728ba4774121 | |||
v1.0 | complete | Code_Contests | Code_Contests_33352_C | def is_palindrome(num: int) -> bool:
"""
Returns True if num is a palindrome, False otherwise.
>>> is_palindrome(121)
True
>>> is_palindrome(123)
False
>>> is_palindrome(1)
True
>>> is_palindrome(101)
True
"""
...
def contains_palindrome(A: int, B: int) -> str:
... | def is_palindrome(num):
"""
Returns True if num is a palindrome, False otherwise.
"""
return str(num) == str(num)[::-1]
def contains_palindrome(A, B):
"""
Returns 'YES' if there is at least one palindrome in the range [A, B], 'NO' otherwise.
"""
for num in range(A, B + 1):
if is... | def test_is_palindrome():
assert is_palindrome(121) == True
assert is_palindrome(123) == False
assert is_palindrome(1) == True
assert is_palindrome(101) == True
def test_contains_palindrome():
assert contains_palindrome(10, 20) == "YES"
assert contains_palindrome(5, 5) == "YES"
assert conta... | [
{
"docstring": "Returns True if num is a palindrome, False otherwise.",
"function_declaration": "def is_palindrome(num):",
"function_name": "is_palindrome",
"parameter_list": "(num)"
},
{
"docstring": "Returns 'YES' if there is at least one palindrome in the range [A, B], 'NO' otherwise.",
... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome(n):\n \"\"\"\n Checks if a given number is a palindrome.\n \"\"\"\n s = str(n)\n return s == s[::-1]\n\ndef contains_palin... | trial_gpt4o_2 | {
"original_instruction": "### Problem Statement:\n\nA palindrome is a word, number, phrase, or other sequence of characters that reads the same forward and backward (ignoring spaces, punctuation, and capitalization). However, in this problem, we are interested in numeric palindromes.\n\nWrite a program to determine ... | 0.74338 | Code_Contests_33352 | C | [
"is_palindrome",
"contains_palindrome",
"palindromes_in_ranges"
] | 3 | [
[
"contains_palindrome",
"is_palindrome"
],
[
"palindromes_in_ranges",
"contains_palindrome"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | ef2c5fe1b682b259ddead5f62733fd1ea879541b | 9f47012fa9a5ef5258df0e8d61242ce85b0e53e2 | |||
v1.0 | complete | Code_Contests | Code_Contests_33466_C | def solve(N, M, edges):
""" Determine the optimal ProcessingUnit to start a distributed computation such that the maximum transmission time from the starting ProcessingUnit to any other ProcessingUnit in the network is minimized.
Args:
N : int : Number of ProcessingUnits
M : int : Number of communi... | import heapq
import sys
def dijkstra(N, graph, start):
distances = [float('inf')] * N
distances[start] = 0
priority_queue = [(0, start)]
while priority_queue:
current_distance, current_vertex = heapq.heappop(priority_queue)
if current_distance > distances[current_vertex]:
... | def test_given_example():
N = 6
M = 7
edges = [
(0, 1, 3),
(0, 2, 2),
(1, 2, 4),
(1, 3, 6),
(2, 3, 1),
(3, 4, 5),
(4, 5, 2)
]
assert solve(N, M, edges) == 7
def test_small_graph():
N = 3
M = 3
edges = [
(0, 1, 4),
(... | [
{
"docstring": null,
"function_declaration": "def dijkstra(N, graph, start):",
"function_name": "dijkstra",
"parameter_list": "(N, graph, start)"
},
{
"docstring": null,
"function_declaration": "def find_optimal_unit(N, M, edges):",
"function_name": "find_optimal_unit",
"paramete... | [
0,
0,
0,
0,
0,
0,
1,
0
] | 1 | hard | 0.125 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\nimport sys\nfrom collections import defaultdict\n\ndef dijkstra(graph, start, N):\n dist = [float('inf')] * N\n dist[start] = 0\n pq... | trial_gpt4o_8 | {
"original_instruction": "You are tasked with optimizing a network of N ProcessingUnits in a computing cluster. Each ProcessingUnit is connected with M communication links. The cluster can be represented as a weighted undirected graph where nodes represent ProcessingUnits and edges represent communication links with... | 0.618731 | Code_Contests_33466 | C | [
"dijkstra",
"find_optimal_unit",
"solve"
] | 3 | [
[
"find_optimal_unit",
"dijkstra"
],
[
"solve",
"find_optimal_unit"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 89e4581cfa7d371c6a9686fb6aa5ad22cfe60059 | c86a518624e95d2a3a551920149975f5d75d3158 | |||
v1.0 | complete | Code_Contests | Code_Contests_33509_C | def get_count_of_valid_chime_patterns(n: int, chime_patterns: List[str]) -> int:
""" Determine the number of chime patterns that follow the rule where the number
of consecutive 'Tick' chimes is always greater than the number of consecutive 'Tock' chimes.
>>> get_count_of_valid_chime_patterns(1, ["Tick ... | def follows_chime_rule(pattern):
chimes = pattern.split()
n = len(chimes)
i = 0
while i < n:
tick_count = 0
tock_count = 0
while i < n and chimes[i] == 'Tick':
tick_count += 1
i += 1
while i < n and chimes[i] == 'Tock':
... | from solution import get_count_of_valid_chime_patterns
def test_single_valid_pattern():
assert get_count_of_valid_chime_patterns(1, ["Tick Tick Tock Tick"]) == 1
def test_single_invalid_pattern():
assert get_count_of_valid_chime_patterns(1, ["Tick Tock Tick Tock Tock"]) == 0
def test_multiple_patterns():
... | [
{
"docstring": null,
"function_declaration": "def follows_chime_rule(pattern):",
"function_name": "follows_chime_rule",
"parameter_list": "(pattern)"
},
{
"docstring": null,
"function_declaration": "def count_valid_patterns(n, patterns):",
"function_name": "count_valid_patterns",
... | [
0,
0,
0,
0,
0,
0,
0,
1,
1
] | 2 | hard | 0.222 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def follows_rule(pattern):\n \"\"\"\n Returns True if the pattern follows the rule that the number of consecutive 'Tick'\n chimes is always greate... | trial_gpt4o_9 | {
"original_instruction": "In a remote town, there is a unique clock tower that is known for its peculiar chime pattern. The clock tower chimes following a specific sequence where each chime is either 'Tick' or 'Tock'. People in the town are fascinated by finding patterns in the sequence of chimes, especially the one... | 0.601374 | Code_Contests_33509 | C | [
"follows_chime_rule",
"count_valid_patterns",
"get_count_of_valid_chime_patterns"
] | 3 | [
[
"count_valid_patterns",
"follows_chime_rule"
],
[
"get_count_of_valid_chime_patterns",
"count_valid_patterns"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 95c4a475645383d3065a95f80508feaa148bc3c8 | 66248cc7d3820c4f2af203e4c6d1f0714b5c25db | |||
v1.0 | complete | Code_Contests | Code_Contests_33548_C | def create_theater(n, m):
""" Initializes a theater with all seats available.
:param n: Number of rows
:param m: Number of columns
:return: 2D list representing the theater seating arrangement
"""
return [['A' for _ in range(m)] for _ in range(n)]
def process_booking_commands(n, m, commands):
... | def create_theater(n, m):
"""
Initializes a theater with all seats available.
:param n: Number of rows
:param m: Number of columns
:return: 2D list representing the theater seating arrangement
"""
return [['A' for _ in range(m)] for _ in range(n)]
def process_booking_commands(n, m, com... | from solution import process_booking_commands
def test_all_available_seats():
theater = process_booking_commands(3, 3, [])
expected = [
['A', 'A', 'A'],
['A', 'A', 'A'],
['A', 'A', 'A']
]
assert theater == expected
def test_single_booking():
theater = process_booking_comman... | [
{
"docstring": "Initializes a theater with all seats available.\n\n:param n: Number of rows\n:param m: Number of columns\n:return: 2D list representing the theater seating arrangement",
"function_declaration": "def create_theater(n, m):",
"function_name": "create_theater",
"parameter_list": "(n, m)"... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def manage_seats(n, m, commands):\n # Initialize the seating arrangement with all seats available\n seats = [['A' for _ in range(m)] for _ in range(n... | trial_gpt4o_1 | {
"original_instruction": "Implement a ticket management system for a movie theater. The theater has a fixed seating arrangement with `n` rows and `m` columns, and each seat can either be available or reserved. You need to create a program that processes a series of booking commands and outputs the final seating arra... | 0.507395 | Code_Contests_33548 | C | [
"create_theater",
"process_booking_commands",
"print_seating_arrangement"
] | 3 | [
[
"process_booking_commands",
"create_theater"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c62f8e6cee58d3724127ac14882b51a681ecf248 | fabf7f02d7921f402df800297f9baf41ea531ec7 | |||
v1.0 | complete | Code_Contests | Code_Contests_33364_C | def highest_score(n: int, participants_scores: List[List[int]]) -> int:
""" Returns the highest score achieved by any participant among all given scores.
>>> highest_score(3, [[34, 67, 90, 100], [56, 88], [23, 45, 78]]) == 100
>>> highest_score(3, [[50], [50], [50]]) == 50
>>> highest_score(1, [[10, 20,... | def highest_score(n, participants_scores):
"""
Returns the highest score achieved by any participant.
Parameters:
n (int): Number of participants.
participants_scores (list of lists): Each inner list contains the scores of the songs sung by a participant.
Returns:
int: ... | from solution import highest_score, process_input_and_call_highest_score
def test_highest_score_simple():
input_str = "3\n4 34 67 90 100\n2 56 88\n3 23 45 78"
assert process_input_and_call_highest_score(input_str) == 100
def test_highest_score_all_same_scores():
input_str = "3\n1 50\n1 50\n1 50"
asser... | [
{
"docstring": "Returns the highest score achieved by any participant.\n\nParameters:\n n (int): Number of participants.\n participants_scores (list of lists): Each inner list contains the scores of the songs sung by a participant.\n\nReturns:\n int: The highest score achieved by any participant.",
... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def highest_score(n, scores):\n \"\"\"\n Finds the highest score achieved by any participant.\n\n Parameters:\n n (int): Number of participants... | trial_gpt4o_2 | {
"original_instruction": "You are given an integer n indicating the number of participants in a singing competition. Each participant sings a number of songs, and the score for each song is given as an integer array. You are required to find out the highest score achieved by any participant.\n\nInput\n\nThe first li... | 0.639872 | Code_Contests_33364 | C | [
"highest_score",
"process_input_and_call_highest_score"
] | 2 | [
[
"process_input_and_call_highest_score",
"highest_score"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c3587e3279a4ea6d6da524ff2b0ae3d4b1616679 | 7ca22359251a2305465a39d21399b105f5c3721f | |||
v1.0 | complete | Code_Contests | Code_Contests_33897_C | from typing import List
def isSynchronized(N: int, intervals: List[int]) -> bool:
""" Determines if there is a common time T where all pyrotechnic displays go off simultaneously for the first time.
>>> isSynchronized(3, [3, 5, 4]) False
>>> isSynchronized(2, [2, 4]) True
""" | from math import gcd
from functools import reduce
def lcm(a, b):
"""
Compute the Least Common Multiple of two numbers.
"""
return a * b // gcd(a, b)
def isSynchronized(N, intervals):
"""
Determines if there is a common time T where all pyrotechnic displays
go off simultaneously for the fir... | from solution import isSynchronized
def test_single_interval():
assert isSynchronized(1, [3]) == True
def test_multiple_intervals_example1():
assert isSynchronized(3, [3, 5, 4]) == False
def test_multiple_intervals_example2():
assert isSynchronized(2, [2, 4]) == True
def test_all_prime_intervals():
... | [
{
"docstring": "Compute the Least Common Multiple of two numbers.",
"function_declaration": "def lcm(a, b):",
"function_name": "lcm",
"parameter_list": "(a, b)"
},
{
"docstring": "Determines if there is a common time T where all pyrotechnic displays\ngo off simultaneously for the first time.... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from math import gcd\nfrom functools import reduce\nfrom typing import List\n\ndef lcm(a, b):\n return abs(a * b) // gcd(a, b)\n\ndef isSynchronized(N: ... | trial_gpt4o_1 | {
"original_instruction": "Create a function that determines if a given pyrotechnic show for an event will be synchronized.\n\n### Problem Description\nYou are tasked with verifying if the pyrotechnic show for a city festival will be perfectly synchronized.\n\nA pyrotechnic show is perfectly synchronized if all the p... | 0.512521 | Code_Contests_33897 | C | [
"lcm",
"isSynchronized"
] | 2 | [
[
"isSynchronized",
"lcm"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 9504234b7f6a75ae9b5dbca9aa5bff1dd549aa1e | 77d85d7cc1ba4f89a0656e78efb4b3385e91a91c | |||
v1.0 | complete | Code_Contests | Code_Contests_32932_C | import heapq
import math
from typing import List, Tuple
def is_prime(n: int) -> bool:
""" Return True if n is a prime number.
>>> is_prime(2)
True
>>> is_prime(3)
True
>>> is_prime(4)
False
>>> is_prime(5)
True
>>> is_prime(10)
False
>>> is_prime(11)
True
"""
de... | import heapq
import math
def is_prime(n):
"""Return True if n is a prime number."""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
... | def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(10) == False
assert is_prime(11) == True
def test_find_shortest_prime_path():
# Example case
n = 5
m = 6
t = 10
roads = [(1, 2, 3... | [
{
"docstring": "Return True if n is a prime number.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Find the shortest path from start to destination using Dijkstra's algorithm.",
"function_declaration": "def dijkstra(n... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\nimport math\n\ndef is_prime(n):\n \"\"\"Return True if n is a prime number.\"\"\"\n if n <= 1:\n return False\n if n <= 3:\n ... | trial_gpt4o_0 | {
"original_instruction": "A secret agent needs to transmit a message securely through an interconnected network of cities. The network is represented as a weighted undirected graph where each city is a node and each road connecting two cities is an edge with a specific weight representing the travel time. \n\nThe ag... | 0.582143 | Code_Contests_32932 | C | [
"is_prime",
"dijkstra",
"find_shortest_prime_path",
"main"
] | 4 | [
[
"find_shortest_prime_path",
"dijkstra"
],
[
"find_shortest_prime_path",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 92fed0b53878acf735e2b2c3c86ac37cd17c2039 | 0c6efed9a75e7340f1fe3c565497bcbbd2e9d520 | |||
v1.0 | complete | Code_Contests | Code_Contests_33596_C | class TreeNode:
def __init__(self, value):
self.value = value
self.left = None
self.right = None
def build_tree(level_order, edges):
""" Build the binary tree from level order and edge list.
"""
pass
def has_path_sum(root, target_sum):
""" Determine if there exists a root-t... | class TreeNode:
def __init__(self, value):
self.value = value
self.left = None
self.right = None
def build_tree(level_order, edges):
if not level_order:
return None
nodes = {val: TreeNode(val) for val in level_order}
for A, B in edges:
if nodes[A].left ... | import pytest
from solution import find_path_to_sum
def test_example_case():
N = 5
S = 10
level_order = [5, 3, 8, 2, 6]
edges = [(5, 3), (5, 8), (3, 2), (3, 6)]
assert find_path_to_sum(N, S, level_order, edges) == [5, 3, 2]
def test_no_path():
N = 3
S = 15
level_order = [1, 2, 3]
e... | [] | [
1,
0
] | 1 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, value):\n self.value = value\n self.left = None\n self.right = None\n\ndef build_tree(level_or... | trial_gpt4o_0 | {
"original_instruction": "You are given a binary tree with N nodes, each node having a unique positive integer value. Your task is to determine if there exists a path (from the root to any leaf) such that the sum of the node values along the path is equal to a given target sum S.\n\nIf such a path exists, output the... | 0.622462 | Code_Contests_33596 | C | [
"build_tree",
"has_path_sum",
"find_path_to_sum"
] | 3 | [
[
"find_path_to_sum",
"build_tree"
],
[
"find_path_to_sum",
"has_path_sum"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 3b600471ec824ed439020adb9c67337910617cee | 216416cc36dd88fef13cfafaf39bb1516d01810c | |||
v1.0 | complete | Code_Contests | Code_Contests_33612_C | from typing import List, Tuple, Union
def is_valid(matrix, x, y, n, m):
return 0 <= x < n and 0 <= y < m and matrix[x][y] == '.'
def update_grid_with_trees(grid, tree_positions, t):
for i in range(t + 1):
if i < len(tree_positions):
x, y = tree_positions[i]
if grid[x][y] == '.'... | from collections import deque
def is_valid(matrix, x, y, n, m):
return 0 <= x < n and 0 <= y < m and matrix[x][y] == '.'
def update_grid_with_trees(grid, tree_positions, t):
for i in range(t + 1):
if i < len(tree_positions):
x, y = tree_positions[i]
if grid[x][y] == '.':
... | def test_shortest_path_1():
N = 5
M = 5
sx = 0
sy = 0
ex = 4
ey = 4
grid = [
".....",
"..#..",
"..#..",
"..#..",
"....."
]
T = 5
tree_positions = [(0, 4), (4, 0), (1, 1), (1, 3), (3, 3)]
new_grid = [list(row) for row in grid]
assert... | [
{
"docstring": null,
"function_declaration": "def is_valid(matrix, x, y, n, m):",
"function_name": "is_valid",
"parameter_list": "(matrix, x, y, n, m)"
},
{
"docstring": null,
"function_declaration": "def update_grid_with_trees(grid, tree_positions, t):",
"function_name": "update_gri... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef is_valid(matrix, x, y, n, m):\n return 0 <= x < n and 0 <= y < m and matrix[x][y] == '.'\n\ndef update_grid_with_tr... | trial_gpt4o_0 | {
"original_instruction": "### D: Pathfinding in a Grid\n\nstory\n\nA group of adventurous friends decided to explore a mysterious forest divided into a rectangular grid of cells. Each cell in the grid can either be empty, a tree, or water. The friends can move up, down, left, or right to an adjacent cell, but they c... | 0.609004 | Code_Contests_33612 | C | [
"is_valid",
"update_grid_with_trees",
"shortest_path_in_forest"
] | 3 | [
[
"shortest_path_in_forest",
"is_valid"
],
[
"shortest_path_in_forest",
"update_grid_with_trees"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | f83007feff5836987261a4cbb97ddb15e006b842 | 7f2e869dc3f7a9b76d54a93f7d6bdccad4a7db03 | |||
v1.0 | complete | Code_Contests | Code_Contests_33820_C | def unique_paths_from_input(N: int, M: int, grid_lines: List[str]) -> int:
""" Determine the number of unique paths from the top-left corner to the bottom-right corner of a grid,
avoiding all blocked cells.
Args:
N : int : Number of rows in the grid
M : int : Number of columns in the grid
g... | MOD = 10**9 + 7
def count_unique_paths(grid):
N = len(grid)
M = len(grid[0])
# Create a dp table
dp = [[0] * M for _ in range(N)]
# Starting position
if grid[0][0] == '.':
dp[0][0] = 1
for i in range(N):
for j in range(M):
if grid[i][j] == '#':
... | def test_unique_paths_case_1():
N = 3
M = 3
grid_lines = [
"...",
".#.",
"..."
]
assert unique_paths_from_input(N, M, grid_lines) == 2
def test_unique_paths_case_2():
N = 3
M = 3
grid_lines = [
"...",
"...",
"..."
]
assert unique_p... | [
{
"docstring": null,
"function_declaration": "def count_unique_paths(grid):",
"function_name": "count_unique_paths",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def unique_paths_from_input(N, M, grid_lines):",
"function_name": "unique_paths_from_input"... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "MOD = 10**9 + 7\n\ndef count_unique_paths(grid):\n N = len(grid)\n M = len(grid[0])\n \n # Create a dp table\n dp = [[0] * M for _ in range(... | trial_gpt4o_0 | {
"original_instruction": "Alice and Bob's Grid Game\n\nAlice and Bob love playing games on a grid. This time, they invented a new game. They have a grid of size N x M consisting of cells. Each cell can either be empty (.) or blocked (#). Alice's goal is to find all the unique paths from the top-left corner of the gr... | 0.720138 | Code_Contests_33820 | C | [
"count_unique_paths",
"unique_paths_from_input"
] | 2 | [
[
"unique_paths_from_input",
"count_unique_paths"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 7048fb9f3ea23a88fae48bbefcb8dbc0d07f7b47 | f04b40fb9c42266af95b9546ac3014d69e28df89 | |||
v1.0 | complete | Code_Contests | Code_Contests_33778_C | def central_city(n: int, roads: List[Tuple[int, int]]) -> int:
"""Determine the optimal city to build the palace in order to minimize the maximum distance from the palace to any other city.
Args:
n (int): The number of cities.
roads (List[Tuple[int, int]]): A list of tuples where each tuple represe... | from collections import defaultdict, deque
def find_farthest_node(start_node, graph):
"""
Returns the farthest node from start_node and its distance using BFS.
"""
n = len(graph)
visited = [False] * (n + 1)
distance = [0] * (n + 1)
queue = deque([start_node])
visited[start_node] = True
... | from solution import central_city
def test_central_city_example1():
n = 7
roads = [(1, 2), (1, 3), (2, 4), (2, 5), (3, 6), (3, 7)]
assert central_city(n, roads) == 1
def test_central_city_example2():
n = 5
roads = [(1, 2), (1, 3), (2, 4), (3, 5)]
assert central_city(n, roads) == 1
def tes... | [
{
"docstring": "Returns the farthest node from start_node and its distance using BFS.",
"function_declaration": "def find_farthest_node(start_node, graph):",
"function_name": "find_farthest_node",
"parameter_list": "(start_node, graph)"
},
{
"docstring": "Returns the city that minimizes the ... | [
0,
0,
0,
0,
0,
0,
0,
0,
1,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque, defaultdict\n\ndef find_optimal_city(n, roads):\n if n == 1:\n return 1\n \n def bfs(start):\n q = de... | trial_gpt4o_8 | {
"original_instruction": "In a certain kingdom, there are `n` cities connected by `n-1` roads such that there is exactly one path between any two cities. The king wants to place a palace in one of these cities. However, to ensure his palace is as centralized as possible, he wants to minimize the maximum distance fro... | 0.657935 | Code_Contests_33778 | C | [
"find_farthest_node",
"central_city"
] | 2 | [
[
"central_city",
"find_farthest_node"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 2803621e498af26c5365e60bf5636d9a194db0d9 | 6361ea01532002154c536c9ebbdc4d84f5c2c762 | |||
v1.0 | complete | Code_Contests | Code_Contests_33774_C | def check_ip_in_ranges(ranges: List[Tuple[str, str]], ip: str) -> str:
""" Checks if the given IP is within any of the provided IP ranges.
:param ranges: List of tuples, where each tuple contains two IP addresses representing the start and end of an IP range.
:param ip: The IP address to check.
:return:... | def ip_to_int(ip):
"""
Converts an IP address to an integer for easy comparison.
"""
parts = ip.split('.')
return int(parts[0]) * 256**3 + int(parts[1]) * 256**2 + int(parts[2]) * 256 + int(parts[3])
def is_ip_in_range(ip, start_ip, end_ip):
"""
Returns True if the IP is in the provided ran... | from solution import check_ip_in_ranges
def test_ip_in_first_range():
ranges = [("192.168.1.1", "192.168.1.100"), ("10.0.0.0", "10.0.0.255"), ("172.16.0.0", "172.16.255.255")]
ip = "192.168.1.50"
assert check_ip_in_ranges(ranges, ip) == "ALLOW"
def test_ip_not_in_range():
ranges = [("192.168.0.0", "19... | [
{
"docstring": "Converts an IP address to an integer for easy comparison.",
"function_declaration": "def ip_to_int(ip):",
"function_name": "ip_to_int",
"parameter_list": "(ip)"
},
{
"docstring": "Returns True if the IP is in the provided range, otherwise False.",
"function_declaration": ... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def ip_to_int(ip):\n \"\"\"\n Converts an IP address string to an integer.\n \"\"\"\n parts = ip.split('.')\n return int(parts[0]) * 256**3 ... | trial_gpt4o_2 | {
"original_instruction": "Alice is working on a network security project where she needs to write a firewall rule to allow or deny access based on IP addresses. The firewall rules are defined by a series of IP ranges, and she needs to check if a given IP falls within those ranges.\n\nAn IP address is represented as ... | 0.698576 | Code_Contests_33774 | C | [
"ip_to_int",
"is_ip_in_range",
"check_ip_in_ranges"
] | 3 | [
[
"check_ip_in_ranges",
"is_ip_in_range"
],
[
"is_ip_in_range",
"ip_to_int"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 62018941863994c602e381e202dfe10e2c681fe3 | a6b0a7ba8047b37db503e204a476dae580eb7449 | |||
v1.0 | complete | Code_Contests | Code_Contests_33764_C | def compress_string(s: str) -> str:
""" Compress a given string using Run-Length Encoding.
>>> compress_string("AAAABBBCCDAA") "4A3B2C1D2A"
>>> compress_string("BBBCCCCCCDDDD") "3B6C4D"
"""
def decompress_string(s: str) -> str:
""" Decompress a Run-Length Encoded string back to its original for... | def compress_string(s):
compressed_str = []
i = 0
while i < len(s):
count = 1
while i + 1 < len(s) and s[i] == s[i+1]:
i += 1
count += 1
compressed_str.append(f"{count}{s[i]}")
i += 1
return "".join(compressed_str)
def decompress_string... | def test_run_length_encoding():
test_cases = [
("3", ["AAAABBBCCDAA", "4A3B2C1D2A", "BBBCCCCCCDDDD"], ["4A3B2C1D2A", "AAAABBBCCDAA", "3B6C4D"]),
("2", ["AABBCC", "2A2B2C"], ["2A2B2C", "AABBCC"]),
("1", ["HHHHHHHH"], ["8H"]),
]
for (t, input_strs, expected_output) in test_cases:
... | [
{
"docstring": null,
"function_declaration": "def compress_string(s):",
"function_name": "compress_string",
"parameter_list": "(s)"
},
{
"docstring": null,
"function_declaration": "def decompress_string(s):",
"function_name": "decompress_string",
"parameter_list": "(s)"
},
{
... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def compress(s):\n \"\"\"\n Compresses the given string using Run-Length Encoding (RLE).\n \"\"\"\n if not s:\n return s\n \n comp... | trial_gpt4o_2 | {
"original_instruction": "Design a data compression tool that encodes input strings using the Run-Length Encoding (RLE) algorithm. Run-Length Encoding is a basic form of data compression in which consecutive repetitive characters are stored as a single character and a count.\n\nWrite a program that will:\n1. Compres... | 0.686248 | Code_Contests_33764 | C | [
"compress_string",
"decompress_string",
"run_length_encoding"
] | 3 | [
[
"run_length_encoding",
"compress_string"
],
[
"run_length_encoding",
"decompress_string"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | e19a8954361c70ba3a00cc5a7bf99fe371be595a | 3e9717b64bc462d61a01ba13b51ead7952855122 | |||
v1.0 | complete | Code_Contests | Code_Contests_32993_C | from typing import List, Tuple
def hexagonal_quest(n: int, m: int, grid: List[List[int]], players: List[Tuple[int, Tuple[int, int], Tuple[int, int]]]) -> List[str]:
""" Determines whether each player can reach the target cell in the hexagonal grid starting with the given energy.
>>> n = 5
>>> m = 2
>>>... | from collections import deque
def can_reach_target(grid, energy, start, target):
n = len(grid)
directions = [(-1, 0), (1, 0), (-1, 1), (-1, -1), (1, 1), (1, -1)]
queue = deque([(start[0], start[1], energy)])
visited = set()
visited.add((start[0], start[1]))
while queue:
x, y, ... | import pytest
from solution import hexagonal_quest
def test_sample_input_1():
n = 5
m = 2
grid = [
[1, 2, 3, 4, -1],
[2, 3, 4, -1, 1],
[3, 4, -1, 1, 2],
[4, -1, 1, 2, 3],
[-1, 1, 2, 3, 4]
]
players = [
(15, (1, 1), (4, 4)),
(10, (0, 0), (3, 3)... | [
{
"docstring": null,
"function_declaration": "def can_reach_target(grid, energy, start, target):",
"function_name": "can_reach_target",
"parameter_list": "(grid, energy, start, target)"
},
{
"docstring": null,
"function_declaration": "def hexagonal_quest(n, m, grid, players):",
"func... | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef can_reach_target(n, m, grid, players):\n \"\"\"\n Determines if each player can reach the target cell with the g... | trial_gpt4o_4 | {
"original_instruction": "### Hexagonal Quest\n\nIn the world of Hexalon, a group of adventurers is on a quest to retrieve magical artifacts located in various hexagonal cells of a vast grid. Each cell in the grid contains an artifact, and each cell can only be traversed if the player has sufficient energy to overco... | 0.597259 | Code_Contests_32993 | C | [
"can_reach_target",
"hexagonal_quest"
] | 2 | [
[
"hexagonal_quest",
"can_reach_target"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 2089720865bd309c6860c2036ccf61c4fdd7013b | 7caf682fcd5d2fedf7e6884d684870a143fdedc5 | |||
v1.0 | complete | Code_Contests | Code_Contests_33855_C | def minimize_max_sum(n: int, m: int, weights: List[int], k: int) -> int:
""" Determines the least possible value of the maximum sum of any section in a valid grouping of boxes.
Args:
n: The number of boxes.
m: The number of sections.
weights: A list of integers representing the weights of the boxes... | def is_possible(weights, n, m, max_sum, k):
"""
Helper function to check if it's possible to partition weights into m sections where
each section's sum is at most max_sum and it does not exceed the threshold k.
"""
current_sum = 0
sections_count = 1
for weight in weights:
if weight ... | def test_minimize_max_sum_example1():
assert minimize_max_sum(5, 3, [1, 2, 3, 4, 5], 10) == 6
def test_minimize_max_sum_example2():
assert minimize_max_sum(6, 2, [7, 2, 4, 8, 1, 3], 15) == 13
def test_minimize_max_sum_impossible_case():
assert minimize_max_sum(6, 2, [7, 2, 4, 8, 1, 3], 5) == -1
def test_... | [
{
"docstring": "Helper function to check if it's possible to partition weights into m sections where\neach section's sum is at most max_sum and it does not exceed the threshold k.",
"function_declaration": "def is_possible(weights, n, m, max_sum, k):",
"function_name": "is_possible",
"parameter_list... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def can_partition(weights, n, m, max_sum):\n \"\"\"\n Helper function to check if it is possible to partition\n the weights into at most m groups ... | trial_gpt4o_2 | {
"original_instruction": "A warehouse manager wants to optimize the arrangement of boxes in the warehouse. Each box has a unique integral weight and needs to be grouped into distinct sections on a single floor. He decided to follow these rules for grouping:\n\n1. Each section should consist of consecutive boxes, and... | 0.648299 | Code_Contests_33855 | C | [
"is_possible",
"minimize_max_sum"
] | 2 | [
[
"minimize_max_sum",
"is_possible"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 96f5dc31ba78377a4754684c869d80ddb493b841 | 2e8de247f19c1f2d083f69323c01c64a4696fa10 | |||
v1.0 | complete | Code_Contests | Code_Contests_33460_C | def find_elevation_gain(grid):
"""
Returns the elevation gain needed to reach the highest peak from the lowest point in the grid.
Args:
grid (List[List[int]]): 2D list representing the heights in the grid.
Returns:
int: The elevation gain needed.
Examples:
>>> find... | def find_elevation_gain(grid):
"""
Returns the elevation gain needed to reach the highest peak from the lowest point in the grid.
"""
R = len(grid)
C = len(grid[0])
min_height = float('inf')
max_height = float('-inf')
for row in grid:
min_height = min(min_height, min(ro... | from solution import process_input_and_find_elevation_gain
def test_case_1():
R, C = 3, 3
grid = [
[1, 2, 3],
[6, 5, 4],
[7, 8, 9]
]
assert process_input_and_find_elevation_gain(R, C, grid) == 8
def test_case_2():
R, C = 4, 4
grid = [
[0, 2, 4, 6],
[1, 3... | [
{
"docstring": "Returns the elevation gain needed to reach the highest peak from the lowest point in the grid.",
"function_declaration": "def find_elevation_gain(grid):",
"function_name": "find_elevation_gain",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "d... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def elevation_gain(grid):\n \"\"\"\n Returns the elevation gain needed to reach the highest peak from the lowest point in the grid.\n \"\"\"\n ... | trial_gpt4o_2 | {
"original_instruction": "You are given a rectangular grid with integers, where each cell represents the height at that point. You want to find the highest peak in the grid. When traveling from a cell to an adjacent cell (up, down, left, or right), the difference in height between the starting cell and the target ce... | 0.500595 | Code_Contests_33460 | C | [
"find_elevation_gain",
"process_input_and_find_elevation_gain"
] | 2 | [
[
"process_input_and_find_elevation_gain",
"find_elevation_gain"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ce86a97c6d4ed9af5d67479375379ea04f075c4f | ab82f506552ab909767c2590bfcdfe26f602af9a | |||
v1.0 | complete | Code_Contests | Code_Contests_33730_C | def can_send_exact_flow(n: int, m: int, edges: List[Tuple[int, int, int]], src: int, sink: int, f: int) -> str:
""" Determine whether it's possible to send exactly `f` units of data flow per second from the source server to the sink server.
Args:
n (int): Number of servers.
m (int): Number of d... | from collections import deque, defaultdict
import sys
def bfs(capacity, source, sink, parent):
visited = set()
queue = deque([source])
visited.add(source)
while queue:
current = queue.popleft()
for neighbor in capacity[current]:
if neighbor not in visited and c... | def test_possible_scenario():
n = 4
m = 5
edges = [
(1, 2, 10),
(2, 3, 5),
(3, 4, 10),
(1, 3, 7),
(2, 4, 3)
]
src = 1
sink = 4
f = 8
assert can_send_exact_flow(n, m, edges, src, sink, f) == "Possible"
def test_impossible_scenario():
n = 4
... | [
{
"docstring": null,
"function_declaration": "def bfs(capacity, source, sink, parent):",
"function_name": "bfs",
"parameter_list": "(capacity, source, sink, parent)"
},
{
"docstring": null,
"function_declaration": "def edmonds_karp(n, graph, source, sink):",
"function_name": "edmonds... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict, deque\n\ndef bfs_capacity_check(graph, src, sink, parent):\n visited = [False] * len(graph)\n queue = deque([src... | trial_gpt4o_1 | {
"original_instruction": "There is a complex network of servers within a datacenter. Each server is connected to several others through directed channels that allow data packets to flow between them. The network can be represented as a directed graph where each node represents a server and each directed edge represe... | 0.473844 | Code_Contests_33730 | C | [
"bfs",
"edmonds_karp",
"can_send_exact_flow"
] | 3 | [
[
"can_send_exact_flow",
"edmonds_karp"
],
[
"edmonds_karp",
"bfs"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 51118e330757490371e427b770c2fbea39331b65 | 5a5afda206e95580e9590c46fe1c7cff915437e9 | |||
v1.0 | complete | Code_Contests | Code_Contests_33581_C | def binary_to_decimal(binary_str):
"""
Converts a binary string to its decimal value.
"""
return int(binary_str, 2)
def max_non_overlapping_sum(s1, s2):
"""
Finds the maximum possible sum of two non-overlapping substrings where
one is taken from s1 and the other is taken from s2. The sum o... | def binary_to_decimal(binary_str):
"""
Converts a binary string to its decimal value.
"""
return int(binary_str, 2)
def max_non_overlapping_sum(s1, s2):
"""
Finds the maximum possible sum of two non-overlapping substrings where
one is taken from s1 and the other is taken from s2. The sum... | import pytest
from solution import max_non_overlapping_sum
def test_example_1():
assert max_non_overlapping_sum("10110", "1101") == 22 + 13
def test_example_2():
assert max_non_overlapping_sum("11101", "101") == 29 + 5
def test_single_characters():
assert max_non_overlapping_sum("1", "0") == 1
assert... | [
{
"docstring": "Converts a binary string to its decimal value.",
"function_declaration": "def binary_to_decimal(binary_str):",
"function_name": "binary_to_decimal",
"parameter_list": "(binary_str)"
},
{
"docstring": "Finds the maximum possible sum of two non-overlapping substrings where \non... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_possible_sum(s1, s2):\n \"\"\"\n Returns the maximum possible sum of two non-overlapping substrings where\n one is taken from s1 and the o... | trial_gpt4o_1 | {
"original_instruction": "Arya is a software developer who loves to play with binary numbers. One day, she faced the following problem and needs your help to solve it.\n\nGiven two binary strings s1 and s2, Arya wants to maximize the binary sum of two non-overlapping substrings where one is taken from s1 and the oth... | 0.582211 | Code_Contests_33581 | C | [
"binary_to_decimal",
"max_non_overlapping_sum"
] | 2 | [
[
"max_non_overlapping_sum",
"binary_to_decimal"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a13260a8525482ac86eec1b36887d144c78c71fd | e9ed25ff33987a5b69c96e5bc1dc8b25d5d4325b | |||
v1.0 | complete | Code_Contests | Code_Contests_33750_C | from typing import List, Tuple
from collections import defaultdict, deque
def find_max_distance_castles(n: int, roads: List[Tuple[int, int, int]]) -> List[int]:
"""
Determine which two castles should be chosen such that the distance between them is maximized.
The distance between two castles is defined as... | from collections import defaultdict, deque
def find_farthest_node(start_node, n, graph):
"""Performs BFS to find the farthest node from the given start_node"""
distances = [-1] * (n + 1)
distances[start_node] = 0
queue = deque([start_node])
farthest_node = start_node
while queue:
curr... | from solution import find_max_distance_castles
def test_case_1():
n = 4
roads = [(1, 2, 3), (2, 3, 5), (3, 4, 2)]
result = find_max_distance_castles(n, roads)
assert result == [1, 4] or result == [4, 1]
def test_case_2():
n = 5
roads = [(1, 2, 1), (1, 3, 1), (1, 4, 1), (1, 5, 1)]
result = ... | [
{
"docstring": "Performs BFS to find the farthest node from the given start_node",
"function_declaration": "def find_farthest_node(start_node, n, graph):",
"function_name": "find_farthest_node",
"parameter_list": "(start_node, n, graph)"
},
{
"docstring": null,
"function_declaration": "d... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import sys\nfrom collections import defaultdict, deque\n\ndef find_furthest_castle(start, tree):\n \"\"\"\n Performs BFS to find the furthest castle ... | trial_gpt4o_2 | {
"original_instruction": "In a faraway kingdom, there are n castles connected by n-1 bidirectional roads. Each road connects two different castles and has a certain length. The kingdom's ruler wants to hold two events at two different castles. To avoid any possible overcrowding, the ruler requires these two castles ... | 0.618736 | Code_Contests_33750 | C | [
"find_farthest_node",
"find_max_distance_castles"
] | 2 | [
[
"find_max_distance_castles",
"find_farthest_node"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 2bc35fd5dde58491b63af0abc2b6a7be9e419479 | 3f6a54434b4764d84dc252f083eba404a23aed9d | |||
v1.0 | complete | Code_Contests | Code_Contests_34172_C | def can_segment_string(s: str, substrings: List[str]) -> str:
""" Determine if the string s can be segmented into a space-separated sequence of one or more substrings from the list.
>>> can_segment_string("leetcode", ["leet", "code", "lee", "tcode"]) == "Yes"
>>> can_segment_string("applepenapple", ["apple"... | def can_segment_string(s, substrings):
"""
Determines if the string s can be segmented into a space-separated sequence of one or more substrings.
"""
n = len(s)
dp = [False] * (n + 1)
dp[0] = True
for i in range(1, n + 1):
for substring in substrings:
if dp[i - len(subst... | from solution import can_segment_string, solve
def test_can_segment_string_1():
s = "leetcode"
substrings = ["leet", "code", "lee", "tcode"]
assert can_segment_string(s, substrings) == "Yes"
def test_can_segment_string_2():
s = "applepenapple"
substrings = ["apple", "pen"]
assert can_segment_s... | [
{
"docstring": "Determines if the string s can be segmented into a space-separated sequence of one or more substrings.",
"function_declaration": "def can_segment_string(s, substrings):",
"function_name": "can_segment_string",
"parameter_list": "(s, substrings)"
},
{
"docstring": null,
"f... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def can_segment(s, substrings):\n \"\"\"\n Determines if the string s can be segmented into a sequence of one or more of the given substrings.\n \... | trial_gpt4o_2 | {
"original_instruction": "You are given a string s consisting of lowercase letters and a set of substrings. Your task is to determine whether the string s can be segmented into a space-separated sequence of one or more of the given substrings.\n\nInput\n\nThe first line contains the string s, composed of lowercase l... | 0.602325 | Code_Contests_34172 | C | [
"can_segment_string",
"solve"
] | 2 | [
[
"solve",
"can_segment_string"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 63501dc946124ea3448f6f55acfe9bbec391949f | 47882a25097d91abdb61ca9a5dc95eff6cceb4eb | |||
v1.0 | complete | Code_Contests | Code_Contests_33829_C | def minimum_paved_roads(n: int, m: int, road_list: List[Tuple[int, int, int]]) -> int:
"""
Determine the minimum total length required to pave enough roads to ensure there is a
path connecting any two cities directly or indirectly.
Input:
- n: An integer, number of cities (2 <= n <= 100,000)
... | def kruskal_minimum_spanning_tree(n, roads):
"""
Returns the minimum total length of the paved roads necessary to ensure all cities are connected.
Uses Kruskal's algorithm.
"""
# Sort roads based on their length
roads.sort(key=lambda x: x[2])
# Union-Find data structure to detect cycles... | def test_example_case():
assert minimum_paved_roads(5, 7, [
(1, 2, 1),
(1, 3, 4),
(2, 3, 2),
(2, 4, 7),
(3, 4, 3),
(3, 5, 5),
(4, 5, 6),
]) == 11
def test_single_road():
assert minimum_paved_roads(2, 1, [
(1, 2, 10),
]) == 10
def test_dis... | [
{
"docstring": "Returns the minimum total length of the paved roads necessary to ensure all cities are connected.\nUses Kruskal's algorithm.",
"function_declaration": "def kruskal_minimum_spanning_tree(n, roads):",
"function_name": "kruskal_minimum_spanning_tree",
"parameter_list": "(n, roads)"
},... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_minimum_spanning_tree(n, m, edges):\n \"\"\"\n Returns the minimum total length of the roads necessary to connect all cities.\n Uses Krus... | trial_gpt4o_2 | {
"original_instruction": "In a small kingdom, there are n cities and m roads connecting pairs of these cities. Each road has a specific length. To enhance trade and travel efficiency, the king has decided to pave some of these roads, ensuring the total length of the paved roads is the minimum necessary to connect al... | 0.763317 | Code_Contests_33829 | C | [
"kruskal_minimum_spanning_tree",
"minimum_paved_roads"
] | 2 | [
[
"minimum_paved_roads",
"kruskal_minimum_spanning_tree"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 4ea9e3be619c2ab39f891d864f81076326ee75be | 5c24a40976a3aee8b97f8b9f1bf273dc9319a1f2 | |||
v1.0 | complete | Code_Contests | Code_Contests_33817_C | from typing import List
def is_prime(num: int) -> bool:
"""
Helper function to check if a number is prime.
>>> is_prime(2)
True
>>> is_prime(4)
False
"""
pass
def count_primes_in_list(nums: List[int]) -> int:
"""
Returns the count of prime numbers in the list.
>>> count_pri... | def is_prime(num):
"""
Helper function to check if a number is prime.
"""
if num <= 1:
return False
if num == 2:
return True
if num % 2 == 0:
return False
for i in range(3, int(num**0.5) + 1, 2):
if num % i == 0:
return False
return True
def c... | from solution import count_primes_in_list, is_prime
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(17) == True
assert is_prime(1) == False
assert is_prime(0) == False
assert is_prime(101) == True
assert is_prime(104... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns the count of prime numbers in the list.",
"function_declaration": "def count_primes_in_list(num... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num == 2:\n ... | trial_gpt4o_0 | {
"original_instruction": "Little Chef has recently learned about prime numbers and wants to apply his newfound knowledge to solve some interesting problems. \nHe is given a list of integers and needs to find out how many prime numbers are present in this list.\n\nInput \nThe first line contains an integer N, represe... | 0.821117 | Code_Contests_33817 | C | [
"is_prime",
"count_primes_in_list"
] | 2 | [
[
"count_primes_in_list",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 949c541791aa8ceac347b099776dd61f327af49a | 069dbea81eb39ede09135ac91f792fbb93c3673b | |||
v1.0 | complete | Code_Contests | Code_Contests_34240_C | def find_shortest_cycle(N: int, E: int, edge_list: List[str]) -> int:
""" Given an undirected graph with N nodes and E edges, determine whether the graph
contains a cycle and find out the minimum length of the cycle. Return -1 if there are no cycles.
>>> find_shortest_cycle(4, 4, ["1 2", "2 3", "3 1", ... | from collections import deque
def shortest_cycle(N, E, edges):
graph = [[] for _ in range(N)]
for u, v in edges:
graph[u - 1].append(v - 1)
graph[v - 1].append(u - 1)
def bfs(start):
dist = [-1] * N
parent = [-1] * N
dist[start] = 0
queue = deque([start... | from solution import find_shortest_cycle
def test_shortest_cycle_sample1():
N = 4
E = 4
edges = [
"1 2",
"2 3",
"3 1",
"3 4"
]
assert find_shortest_cycle(N, E, edges) == 3
def test_shortest_cycle_sample2():
N = 3
E = 2
edges = [
"1 2",
"2... | [
{
"docstring": null,
"function_declaration": "def shortest_cycle(N, E, edges):",
"function_name": "shortest_cycle",
"parameter_list": "(N, E, edges)"
},
{
"docstring": null,
"function_declaration": "def find_shortest_cycle(N, E, edge_list):",
"function_name": "find_shortest_cycle",
... | [
0,
1
] | 1 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque, defaultdict\n\ndef find_shortest_cycle(N, E, edges):\n graph = defaultdict(list)\n for u, v in edges:\n graph[u... | trial_gpt4o_1 | {
"original_instruction": "Given an undirected graph with `N` nodes and `E` edges, you need to determine whether the graph contains a cycle. If the graph contains a cycle, you also need to find out the minimum length of the cycle. If there are no cycles, output `-1`.\n\nInput:\n- The first line contains two integers ... | 0.68799 | Code_Contests_34240 | C | [
"shortest_cycle",
"find_shortest_cycle"
] | 2 | [
[
"find_shortest_cycle",
"shortest_cycle"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a837113b3e5934b90314f52e603fe999ee11d932 | 8eb1ec7c2b2dc1263d87f58b5b6afbee411f0e61 | |||
v1.0 | complete | Code_Contests | Code_Contests_34190_C | from typing import List, Tuple
def min_operations_to_transform(T: int, test_cases: List[Tuple[str, str, int, List[Tuple[str, str]]]]) -> List[int]:
""" Determine the minimum number of operations required to transform each source string to its corresponding target string.
Args:
T (int): Number of test ... | from collections import deque
def min_operations_to_transform(T, test_cases):
results = []
for case in test_cases:
source, target, M, operations = case
if len(source) != len(target):
results.append(-1)
continue
transformation_map = {}
for op... | from solution import min_operations_to_transform, transform_strings
def test_example_cases():
# Example case 1
num_tests = 2
all_cases = [
("abc", "bca", 3, [("a", "b"), ("b", "c"), ("c", "a")]),
("hello", "world", 1, [("h", "f")])
]
assert min_operations_to_transform(num_tests, all... | [
{
"docstring": null,
"function_declaration": "def min_operations_to_transform(T, test_cases):",
"function_name": "min_operations_to_transform",
"parameter_list": "(T, test_cases)"
},
{
"docstring": null,
"function_declaration": "def transform_strings(num_tests, all_cases):",
"functio... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def min_transformations(T, test_cases):\n def bfs(source, target, operations):\n from collections import deque, defaultdict\n \n if... | trial_gpt4o_1 | {
"original_instruction": "Write a function that determines if a string can be transformed into another string through a specific series of operations. You are given a source string and a target string, as well as a list of valid operations. Each operation is defined as replacing one character with another character ... | 0.644361 | Code_Contests_34190 | C | [
"min_operations_to_transform",
"transform_strings"
] | 2 | [
[
"transform_strings",
"min_operations_to_transform"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 418f2d47f5e09f20496427d37cd45db30b93446e | 63dca82e18db83ca1a1b61f4c2f66a9c0e8055d7 | |||
v1.0 | complete | Code_Contests | Code_Contests_34341_C | import math
from itertools import permutations
from typing import List
def gcd(x: int, y: int) -> int:
while y:
x, y = y, x % y
return x
def can_rearrange(arr: List[int]) -> str:
""" Determines if it is possible to rearrange the array such that every consecutive pair of elements has a common divis... | import math
from itertools import permutations
def gcd(x, y):
while y:
x, y = y, x % y
return x
def can_rearrange(arr):
if len(arr) == 1:
# If there's only one element, we can't have consecutive pairs, hence it could be trivially rearranged
return "YES\n" + str(arr[0])
# C... | from solution import can_rearrange
def test_can_rearrange_example_case():
assert can_rearrange([2, 3, 6, 9]).startswith("YES")
def test_can_rearrange_single_element():
assert can_rearrange([1]) == "YES\n1"
assert can_rearrange([10]) == "YES\n10"
def test_can_rearrange_impossible_case():
assert can_re... | [
{
"docstring": null,
"function_declaration": "def gcd(x, y):",
"function_name": "gcd",
"parameter_list": "(x, y)"
},
{
"docstring": null,
"function_declaration": "def can_rearrange(arr):",
"function_name": "can_rearrange",
"parameter_list": "(arr)"
}
] | [
0,
0,
0,
0,
0,
1,
0,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from math import gcd\nfrom itertools import permutations\n\ndef can_rearrange(arr):\n \"\"\"\n Determines if it is possible to rearrange the array su... | trial_gpt4o_5 | {
"original_instruction": "You are given an array of integers and your task is to determine if it is possible to rearrange the array such that every consecutive pair of elements has a common divisor greater than 1. If such a rearrangement is possible, output one valid rearrangement. Otherwise, output \"NO\" without q... | 0.598349 | Code_Contests_34341 | C | [
"gcd",
"can_rearrange"
] | 2 | [
[
"can_rearrange",
"gcd"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 05d448fa7533f1e4d06d503395b97debd6817e9c | 53326cf29d02230201c8adf969de9fc5b3605d8c | |||
v1.0 | complete | Code_Contests | Code_Contests_34342_C | import heapq
from collections import defaultdict, deque
def dijkstra(n, start, graph):
dist = [float('inf')] * (n + 1)
dist[start] = 0
pq = [(0, start)]
while pq:
current_dist, u = heapq.heappop(pq)
if current_dist > dist[u]:
continue
for v, weight in graph[u]:
... | import heapq
from collections import defaultdict, deque
def dijkstra(n, start, graph):
dist = [float('inf')] * (n + 1)
dist[start] = 0
pq = [(0, start)]
while pq:
current_dist, u = heapq.heappop(pq)
if current_dist > dist[u]:
continue
for v, weight in graph[u]:
... | def test_case_1():
input_data = "4 5\n1 2 1\n2 3 1\n3 4 1\n1 3 2\n2 4 2\n"
expected_output = 1
assert can_have_multiple_shortest_paths(4, 5, [(1, 2, 1), (2, 3, 1), (3, 4, 1), (1, 3, 2), (2, 4, 2)]) == expected_output
def test_case_2():
input_data = "3 3\n1 2 2\n2 3 2\n3 1 3\n"
expected_output = 0
... | [
{
"docstring": null,
"function_declaration": "def dijkstra(n, start, graph):",
"function_name": "dijkstra",
"parameter_list": "(n, start, graph)"
},
{
"docstring": null,
"function_declaration": "def can_have_multiple_shortest_paths(n, m, edges):",
"function_name": "can_have_multiple_... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\nimport sys\nfrom collections import defaultdict, deque\n\ndef can_ensure_multiple_minimum_paths(N, M, roads):\n # Create adjacency list re... | trial_gpt4o_1 | {
"original_instruction": "In a land far away, there exists a kingdom where people live in villages connected by roads. The kingdom has N villages numbered from 1 to N and M bidirectional roads. Each road connects two villages and has a certain travel time associated with it.\n\nThe king is keen to ensure that his su... | 0.669712 | Code_Contests_34342 | C | [
"dijkstra",
"can_have_multiple_shortest_paths",
"main"
] | 3 | [
[
"can_have_multiple_shortest_paths",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 7b2a0343dec64799864ca6d5056ac6b7cf1078d6 | a59d75a5ba1ca14fa6ab3a64c7e22f020ff67a8b | |||
v1.0 | complete | Code_Contests | Code_Contests_33856_C | def minimal_travel_costs(n: int, m: int, highways: List[Tuple[int, int, int]]) -> List[int]:
""" Compute the minimum toll cost to travel from the capital city 1 to each city after adjusting tolls.
Args:
n: the number of cities.
m: the number of highways.
highways: a list of tuples where each tu... | import heapq
def dijkstra(n, edges, src):
graph = [[] for _ in range(n + 1)]
for u, v, c in edges:
graph[u].append((v, c))
min_cost = [float('inf')] * (n + 1)
min_cost[src] = 0
pq = [(0, src)]
heapq.heapify(pq)
while pq:
current_cost, u = heapq.heappop(pq)
... | def test_minimal_travel_costs():
assert minimal_travel_costs(4, 5, [(1, 2, 10), (2, 3, 5), (3, 4, 15), (4, 2, 10), (1, 3, 20)]) == [0, 10, 15, 30]
assert minimal_travel_costs(3, 3, [(1, 2, 8), (1, 3, 12), (2, 3, 4)]) == [0, 8, 12]
# Running pytest
if __name__ == "__main__":
import pytest
pytest.main([_... | [
{
"docstring": null,
"function_declaration": "def dijkstra(n, edges, src):",
"function_name": "dijkstra",
"parameter_list": "(n, edges, src)"
},
{
"docstring": null,
"function_declaration": "def minimal_travel_costs(n, m, highways):",
"function_name": "minimal_travel_costs",
"par... | [
1
] | 1 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef dijkstra(n, edges, src):\n graph = [[] for _ in range(n + 1)]\n for u, v, c in edges:\n graph[u].append((v, c))\n \... | trial_gpt4o_0 | {
"original_instruction": "The Kingdom of Arithmia consists of n cities interconnected by m directional highways. Each highway has an associated cost representing the toll required to travel from one city to another. However, economic circumstances have necessitated the kingdom to raise tolls more frequently across s... | 0.646061 | Code_Contests_33856 | C | [
"dijkstra",
"minimal_travel_costs",
"main"
] | 3 | [
[
"minimal_travel_costs",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 4ca69dee0ff232889cd384a7fd07d00292b41611 | 20a31fb9f722fd740e0daa652622061467282b35 | |||
v1.0 | complete | Code_Contests | Code_Contests_34537_C | from itertools import permutations
def is_valid_word(word):
# This is a placeholder for the actual implementation.
# For the purpose of the example, assume a predefined dictionary:
valid_words = {"loop", "pool", "pols", "spools", "loops"}
return word in valid_words
def find_lexicographically_smallest_... | from itertools import permutations
def is_valid_word(word):
# This is a placeholder for the actual implementation.
# For the purpose of the example, assume a predefined dictionary:
valid_words = {"loop", "pool", "pols", "spools", "loops"}
return word in valid_words
def find_lexicographically_smallest_... | from solution import find_lexicographically_smallest_valid_word
def test_single_permutation_valid_word():
assert find_lexicographically_smallest_valid_word("loop") == "loop"
def test_no_valid_word():
assert find_lexicographically_smallest_valid_word("oloop") == "no valid word"
def test_multiple_valid_words()... | [
{
"docstring": null,
"function_declaration": "def is_valid_word(word):",
"function_name": "is_valid_word",
"parameter_list": "(word)"
},
{
"docstring": null,
"function_declaration": "def find_lexicographically_smallest_valid_word(S):",
"function_name": "find_lexicographically_smalles... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from itertools import permutations\n\n# This function is assumed to be available for checking valid English words.\ndef is_valid_word(word):\n # For the... | trial_gpt4o_2 | {
"original_instruction": "You're given a string `S` consisting of only lowercase Latin letters. Your task is to generate all possible permutations of this string and determine if there exist any valid English words among the generated permutations. If there are multiple valid words, you must return the lexicographic... | 0.629498 | Code_Contests_34537 | C | [
"is_valid_word",
"find_lexicographically_smallest_valid_word"
] | 2 | [
[
"find_lexicographically_smallest_valid_word",
"is_valid_word"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f6c0f465eee4b950456b16af7c63b6e5a3279f53 | e862c2fee13ed2baee8f019cd58bde29eb464948 | |||
v1.0 | complete | Code_Contests | Code_Contests_34134_C | from collections import deque, defaultdict
from typing import List, Tuple
def bfs_for_furthest_node(start_node: int, tree: defaultdict) -> Tuple[int, int]:
visited = set()
max_distance = 0
furthest_node = start_node
queue = deque([(start_node, 0)])
while queue:
node, distance = queue.p... | from collections import deque, defaultdict
def bfs_for_furthest_node(start_node, tree):
visited = set()
max_distance = 0
furthest_node = start_node
queue = deque([(start_node, 0)])
while queue:
node, distance = queue.popleft()
if distance > max_distance:
max_distanc... | from solution import tree_diameter
def test_tree_diameter_example1():
edges = [(1, 2), (1, 3), (3, 4), (3, 5)]
assert tree_diameter(5, edges) == 3
def test_tree_diameter_example2():
edges = [(1, 2), (2, 3)]
assert tree_diameter(3, edges) == 2
def test_tree_diameter_single_node():
assert tree_diam... | [
{
"docstring": null,
"function_declaration": "def bfs_for_furthest_node(start_node, tree):",
"function_name": "bfs_for_furthest_node",
"parameter_list": "(start_node, tree)"
},
{
"docstring": null,
"function_declaration": "def tree_diameter(N, edges):",
"function_name": "tree_diamete... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict, deque\n\ndef get_tree_diameter(N, edges):\n # Create an adjacency list from the edges\n tree = defaultdict(list)... | trial_gpt4o_2 | {
"original_instruction": "Given is an undirected tree T with N vertices. The vertices are numbered 1 to N. An undirected tree is a connected graph with N vertices and N-1 edges.\n\nDetermine the diameter of the tree. The diameter of a tree is the length of the longest path between any two nodes in the tree.\n\nConst... | 0.688718 | Code_Contests_34134 | C | [
"bfs_for_furthest_node",
"tree_diameter"
] | 2 | [
[
"tree_diameter",
"bfs_for_furthest_node"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 20e6de2213a3a01bfadb95e41695651b1d614e46 | ae93c4f872bc5c4aa4c615c9ea66a3b9d3834b63 | |||
v1.0 | complete | Code_Contests | Code_Contests_34033_C | def solve_input(input_str):
"""
Given a string representation of multiple test cases of grids with obstacles,
this function returns the length of the shortest path from the top-left corner
to the bottom-right corner for each grid. If no such path exists, -1 is returned.
Parameters:
input_st... | from collections import deque
def shortest_path(grid):
n = len(grid)
m = len(grid[0])
directions = [(1, 0), (-1, 0), (0, 1), (0, -1)]
def is_valid(r, c):
return 0 <= r < n and 0 <= c < m and grid[r][c] == '.'
queue = deque([(0, 0, 0)]) # (row, col, distance)
grid[0][0] = '#' # mark ... | from solution import solve_input
def test_shortest_path():
input_str = "2\n4 4\n....\n.##.\n....\n....\n3 3\n.#.\n###\n.#.\n"
expected_output = [6, -1]
assert solve_input(input_str) == expected_output
def test_all_open():
input_str = "1\n3 3\n...\n...\n...\n"
expected_output = [4]
assert solve... | [
{
"docstring": null,
"function_declaration": "def shortest_path(grid):",
"function_name": "shortest_path",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def solve(test_cases):",
"function_name": "solve",
"parameter_list": "(test_cases)"
},
{
... | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef shortest_path(grid):\n n = len(grid)\n m = len(grid[0])\n direction_vectors = [(1, 0), (-1, 0), (0, 1), (0, -... | trial_gpt4o_4 | {
"original_instruction": "You are given a grid with obstacles represented as walls. You need to find the shortest path from the top-left corner of the grid to the bottom-right corner. You can move up, down, left, or right, but you cannot pass through walls. If no such path exists, return -1.\n\nInput\n\nThe first li... | 0.684184 | Code_Contests_34033 | C | [
"shortest_path",
"solve",
"parse_input",
"solve_input"
] | 4 | [
[
"solve",
"shortest_path"
],
[
"solve_input",
"parse_input"
],
[
"solve_input",
"solve"
]
] | 3 | [
"parse_input",
"solve_input"
] | false | [] | false | pytest | true | [] | true | 0fd06a023e99db318fab0456c0b59562ee3f0ac1 | 0eb3dc253fa1ee9c91c01a0cf01219523151ad9a | |||
v1.0 | complete | Code_Contests | Code_Contests_33776_C | import heapq
from typing import List, Tuple
def dijkstra(n: int, graph: dict, start: int) -> dict:
""" Implements Dijkstra's algorithm to find the shortest paths from start node to all other nodes. """
# function body (implementation not shown)
pass
def solve(n: int, edges: List[Tuple[int, int, int]], que... | import heapq
def dijkstra(n, graph, start):
"""
Implements Dijkstra's algorithm to find the shortest paths from start node to all other nodes.
"""
distances = {i: float('inf') for i in range(1, n+1)}
distances[start] = 0
priority_queue = [(0, start)]
while priority_queue:
current_di... | from solution import solve, parse_input
def test_solve_example():
input_str = """5
7
1 2 1
1 3 4
2 3 2
2 4 7
3 5 3
4 5 1
1 5 8
3
1 5
2 5
4 1"""
n, edges, queries = parse_input(input_str)
assert solve(n, edges, queries) == [6, 5, "No Path"]
def test_solve_no_... | [
{
"docstring": "Implements Dijkstra's algorithm to find the shortest paths from start node to all other nodes.",
"function_declaration": "def dijkstra(n, graph, start):",
"function_name": "dijkstra",
"parameter_list": "(n, graph, start)"
},
{
"docstring": "Given the list of edges and queries... | [
0,
0,
0,
1,
0
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef dijkstra(graph, n, start):\n distances = {node: float('inf') for node in range(1, n+1)}\n distances[start] = 0\n priority_queu... | trial_gpt4o_3 | {
"original_instruction": "You are given a list of weighted edges representing a graph and are tasked with finding the shortest path between two nodes using Dijkstra's algorithm. The graph may be disconnected, meaning there might not be a valid path between some pairs of nodes.\n\nINPUT:\n- The first line contains an... | 0.66015 | Code_Contests_33776 | C | [
"dijkstra",
"solve",
"parse_input"
] | 3 | [
[
"solve",
"dijkstra"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 3b0e9539db9d4d8a3a37b6bfb6acd3f5bdd62f2e | 794fc18c007e919f4ce9d52d5bc91f7ee5771a2f | |||
v1.0 | complete | Code_Contests | Code_Contests_34332_C | import math
from typing import List, Tuple
def smallest_enclosing_circle(n: int, points: List[Tuple[int, int]]) -> Tuple[float, float, float]:
""" You are given a data set consisting of n distinct points in two-dimensional space. Your task is to find the smallest circle that can contain all the given points.
P... | import math
from typing import List, Tuple
class Circle:
def __init__(self, x: float = 0.0, y: float = 0.0, r: float = 0.0):
self.x = x
self.y = y
self.r = r
def dist(a: Tuple[float, float], b: Tuple[float, float]) -> float:
return math.sqrt((a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2)
de... | import pytest
from solution import smallest_enclosing_circle
def test_case_1():
n = 3
points = [(1, 1), (2, 2), (3, 3)]
cx, cy, r = smallest_enclosing_circle(n, points)
assert round(cx, 6) == 2.000000
assert round(cy, 6) == 2.000000
assert round(r, 6) == 1.414214
def test_case_2():
n =... | [] | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from math import sqrt, inf\n\ndef dist(p1, p2):\n return sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2)\n \ndef smallest_circle(points):\n # Func... | trial_gpt4o_2 | {
"original_instruction": "You are given a data set consisting of n distinct points in two-dimensional space. Your task is to find the smallest circle that can contain all the given points.\n\nInput\n\nThe first line of input will contain one integer n (1 ≤ n ≤ 10^4), the number of points.\n\nEach of the next n lines... | 0.615793 | Code_Contests_34332 | C | [
"dist",
"is_in_circle",
"make_circle_two_points",
"make_circle_three_points",
"find_smallest_enclosing_circle",
"smallest_enclosing_circle"
] | 6 | [
[
"find_smallest_enclosing_circle",
"is_in_circle"
],
[
"find_smallest_enclosing_circle",
"make_circle_three_points"
],
[
"find_smallest_enclosing_circle",
"make_circle_two_points"
],
[
"is_in_circle",
"dist"
],
[
"make_circle_three_points",
"dist"
],
[
... | 7 | [] | false | [
"Circle"
] | true | pytest | true | [] | true | ca0fce45de79a69c110dc24e135983ec5ca1e991 | 94fad7259597dc59715b26bc9c0b061b2c5a5c8a | |||
v1.0 | complete | Code_Contests | Code_Contests_34257_C | def is_scramble(s1, s2):
"""
Determines if s2 is a scrambled string of s1.
>>> is_scramble("great", "rgtae")
"YES"
>>> is_scramble("abcde", "caebd")
"NO"
"""
pass
def scramble_check(s1, s2):
"""
Outputs "YES" if s2 is a scrambled string of s1, otherwise "NO".
"""
pass
... | def is_scramble(s1, s2):
"""
Determines if s2 is a scrambled string of s1.
"""
if s1 == s2:
return True
if sorted(s1) != sorted(s2):
return False
n = len(s1)
for i in range(1, n):
if (is_scramble(s1[:i], s2[:i]) and is_scramble(s1[i:], s2[i:])) or (is_scramble(s... | from solution import scramble_check
def test_scramble_check_1():
assert scramble_check("great", "rgtae") == "YES"
def test_scramble_check_2():
assert scramble_check("abcde", "caebd") == "NO"
def test_scramble_check_3():
assert scramble_check("a", "a") == "YES"
def test_scramble_check_4():
assert scr... | [
{
"docstring": "Determines if s2 is a scrambled string of s1.",
"function_declaration": "def is_scramble(s1, s2):",
"function_name": "is_scramble",
"parameter_list": "(s1, s2)"
},
{
"docstring": "Outputs \"YES\" if s2 is a scrambled string of s1, otherwise \"NO\".",
"function_declaration... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_scramble(s1, s2):\n \"\"\"\n Returns True if s2 is a scrambled string of s1, otherwise False.\n \"\"\"\n if len(s1) != len(s2):\n ... | trial_gpt4o_2 | {
"original_instruction": "You are given two strings, s1 and s2. Your task is to determine whether s2 is a scrambled string of s1. \n\nA scrambled string is defined as follows:\n- If a string can be obtained by swapping two non-empty substrings of another string, it is considered a scrambled string. \n- For instance,... | 0.622899 | Code_Contests_34257 | C | [
"is_scramble",
"scramble_check"
] | 2 | [
[
"scramble_check",
"is_scramble"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 3f3fde2d0c440174db55f6c81358e5e5be00a649 | d0210ac217351121870e134d037b2196e7207514 | |||
v1.0 | complete | Code_Contests | Code_Contests_33700_C | def preprocess_steps(steps):
"""
Preprocess the array of daily steps using prefix sums.
:param steps: List[int], a list of steps taken each day.
:return: List[int], a list of prefix sums.
"""
# Your code here
def total_steps_in_range(prefix_sum, L, R):
"""
Calculate the total steps... | def preprocess_steps(steps):
"""
Preprocess the array of daily steps using prefix sums.
:param steps: List[int], a list of steps taken each day.
:return: List[int], a list of prefix sums.
"""
prefix_sum = [0] * (len(steps) + 1)
for i in range(len(steps)):
prefix_sum[i + 1] = pre... | def test_preprocess_steps():
steps = [1000, 2000, 3000, 4000, 5000]
expected = [0, 1000, 3000, 6000, 10000, 15000]
assert preprocess_steps(steps) == expected
def test_total_steps_in_range():
prefix_sum = [0, 1000, 3000, 6000, 10000, 15000]
assert total_steps_in_range(prefix_sum, 1, 3) == 6000
a... | [
{
"docstring": "Preprocess the array of daily steps using prefix sums.\n\n:param steps: List[int], a list of steps taken each day.\n:return: List[int], a list of prefix sums.",
"function_declaration": "def preprocess_steps(steps):",
"function_name": "preprocess_steps",
"parameter_list": "(steps)"
... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def calculate_prefix_sums(steps):\n \"\"\"\n Calculates the prefix sums for the given steps.\n \n :param steps: List[int] - A list with the num... | trial_gpt4o_2 | {
"original_instruction": "Problem\n\nYou are tasked with designing a fitness tracking application. The application tracks the steps walked by users and generates summaries based on the specified range of days. Specifically, you have to implement a function to process a list of daily steps data and answer multiple qu... | 0.603697 | Code_Contests_33700 | C | [
"preprocess_steps",
"total_steps_in_range",
"process_queries"
] | 3 | [
[
"process_queries",
"preprocess_steps"
],
[
"process_queries",
"total_steps_in_range"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | false | [] | true | ef0a65e8ad37e637d519bce2517e16dee6db464b | 47807873907fffaa0e28c34416ac02a2641ce351 | |||
v1.0 | complete | Code_Contests | Code_Contests_33773_C | def floyd_warshall(n: int, edges: List[Tuple[int, int, int]]) -> List[List[int]]:
""" Apply Floyd-Warshall algorithm to find the shortest paths between all pairs of cities.
Args:
n (int): The number of cities.
edges (list of tuples): Each tuple (u, v, w) represents a bidirectional road between city u an... | def floyd_warshall(n, edges):
# Initialize distance matrix
dist = [[float('inf')] * n for _ in range(n)]
# Distance from the node to itself is zero
for i in range(n):
dist[i][i] = 0
for u, v, w in edges:
u -= 1
v -= 1
dist[u][v] = w
dist[v][u] = ... | from solution import floyd_warshall, minimum_travel_times
def test_floyd_warshall_basic():
n = 4
edges = [
(1, 2, 1),
(2, 3, 2),
(1, 3, 4),
(3, 4, 1)
]
expected = [
[0, 1, 3, 4],
[1, 0, 2, 3],
[3, 2, 0, 1],
[4, 3, 1, 0]
]
assert fl... | [
{
"docstring": null,
"function_declaration": "def floyd_warshall(n, edges):",
"function_name": "floyd_warshall",
"parameter_list": "(n, edges)"
},
{
"docstring": null,
"function_declaration": "def minimum_travel_times(n, edges, queries):",
"function_name": "minimum_travel_times",
... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def floyd_warshall(n, roads):\n INF = float('inf')\n dist = [[INF] * n for _ in range(n)]\n \n for i in range(n):\n dist[i][i] = 0\n ... | trial_gpt4o_1 | {
"original_instruction": "A transport company has a network of cities connected by bidirectional roads. Each road has a non-negative integer weight representing the time to travel between the two cities it connects. The company is trying to determine the minimum travel time between various pairs of cities for their ... | 0.710797 | Code_Contests_33773 | C | [
"floyd_warshall",
"minimum_travel_times",
"main"
] | 3 | [
[
"minimum_travel_times",
"floyd_warshall"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 3158c444798f45a87fc5b1c18fc99fc8d47e7ab1 | 975d35f937a21bd31af346416bf893c1db9c2bbe | |||
v1.0 | complete | Code_Contests | Code_Contests_34231_C | def longest_palindromic_subsequence_length(word: str) -> int:
"""
Given a word, find the length of the longest palindromic subsequence.
>>> longest_palindromic_subsequence_length("abca")
3
>>> longest_palindromic_subsequence_length("bananas")
5
>>> longest_palindromic_subsequence_length("ab... | def longest_palindromic_subsequence_length(word):
"""
Given a word, find the length of the longest palindromic subsequence.
"""
n = len(word)
dp = [[0] * n for _ in range(n)]
for i in range(n):
dp[i][i] = 1
for cl in range(2, n + 1):
for i in range(n - cl + 1):
... | from solution import longest_palindromic_subsequence, longest_palindromic_subsequence_length
def test_longest_palindromic_subsequence_length():
assert longest_palindromic_subsequence_length("abca") == 3
assert longest_palindromic_subsequence_length("bananas") == 5
assert longest_palindromic_subsequence_len... | [
{
"docstring": "Given a word, find the length of the longest palindromic subsequence.",
"function_declaration": "def longest_palindromic_subsequence_length(word):",
"function_name": "longest_palindromic_subsequence_length",
"parameter_list": "(word)"
},
{
"docstring": "Given a list of words,... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def longest_palindromic_subsequence(s):\n n = len(s)\n if n == 0:\n return 0\n dp = [[0] * n for _ in range(n)]\n for i in range(n):\n ... | trial_gpt4o_1 | {
"original_instruction": "Given a list of words, you are to find the longest subsequence that can be formed by deleting some characters from each word in the list such that the subsequence is the same when read from left to right and right to left.\n\nA subsequence is a sequence derived from another sequence by dele... | 0.768322 | Code_Contests_34231 | C | [
"longest_palindromic_subsequence_length",
"longest_palindromic_subsequence"
] | 2 | [
[
"longest_palindromic_subsequence",
"longest_palindromic_subsequence_length"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b9aedff14d55412ad24fc1213c432a23b54bbfc2 | 5d33b82e8832317cfed3bccec69393fc80a0fd18 | |||
v1.0 | complete | Code_Contests | Code_Contests_34652_C | import math
def digit_factorial_sum(num: int) -> int:
"""
Returns the sum of the factorials of the digits of num.
>>> digit_factorial_sum(1)
1
>>> digit_factorial_sum(2)
2
>>> digit_factorial_sum(3)
6
>>> digit_factorial_sum(4)
24
>>> digit_factorial_sum(5)
120
"""
... | import math
def digit_factorial_sum(num):
"""
Returns the sum of the factorials of the digits of num.
"""
return sum(math.factorial(int(d)) for d in str(num))
def generate_sequence(n):
"""
Generates a sequence of length n where the i-th element is defined as the sum of the factorials of its di... | from solution import digit_factorial_sum, generate_sequence, formatted_sequence
def test_digit_factorial_sum():
assert digit_factorial_sum(1) == 1
assert digit_factorial_sum(2) == 2
assert digit_factorial_sum(3) == 6
assert digit_factorial_sum(4) == 24
assert digit_factorial_sum(5) == 120
asser... | [
{
"docstring": "Returns the sum of the factorials of the digits of num.",
"function_declaration": "def digit_factorial_sum(num):",
"function_name": "digit_factorial_sum",
"parameter_list": "(num)"
},
{
"docstring": "Generates a sequence of length n where the i-th element is defined as the su... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef sum_of_digit_factorials(n):\n \"\"\"\n Generates a sequence of length n where the i-th element is the sum of the factorials of its... | trial_gpt4o_2 | {
"original_instruction": "Bob is learning about numerical patterns and sequences. He has discovered an interesting sequence of numbers that follow a particular rule. Can you help him determine the rule and generate the sequence?\n\nGiven a positive integer n, generate a sequence of length n where the i-th element is... | 0.677157 | Code_Contests_34652 | C | [
"digit_factorial_sum",
"generate_sequence",
"formatted_sequence"
] | 3 | [
[
"formatted_sequence",
"generate_sequence"
],
[
"generate_sequence",
"digit_factorial_sum"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 49ba7709c23515fca4ad5aeed8c753ffa0652613 | 359ba72686c86e202dc8688a90ee0672384f00c3 | |||
v1.0 | complete | Code_Contests | Code_Contests_34505_C | def intersection_area(square1: List[Tuple[int, int]], square2: List[Tuple[int, int]]) -> int:
""" Given the coordinates of two squares on a 2D plane, returns the area of their intersection.
Args:
square1: List of 4 tuples representing the vertices of the first square.
square2: List of 4 tuples repr... | def get_square_bounds(coordinates):
"""
Given four coordinates representing the vertices of an axis-aligned square,
return the bounds of the square.
Args:
coordinates: List of tuples [(x1, y1), (x2, y2), (x3, y3), (x4, y4)]
Returns:
(x_min, x_max, y_min, y_max) The bounds of the sq... | from solution import intersection_area
def test_no_overlap():
square1 = [(0, 0), (0, 1), (1, 1), (1, 0)]
square2 = [(2, 2), (2, 3), (3, 3), (3, 2)]
assert intersection_area(square1, square2) == 0
def test_overlap_area_1():
square1 = [(0, 0), (0, 2), (2, 2), (2, 0)]
square2 = [(1, 1), (1, 3), (3, 3... | [
{
"docstring": "Given four coordinates representing the vertices of an axis-aligned square,\nreturn the bounds of the square.\n\nArgs:\ncoordinates: List of tuples [(x1, y1), (x2, y2), (x3, y3), (x4, y4)]\n\nReturns:\n(x_min, x_max, y_min, y_max) The bounds of the square.",
"function_declaration": "def get_... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def area_of_intersection(x1_min, x1_max, y1_min, y1_max, x2_min, x2_max, y2_min, y2_max):\n \"\"\"\n Computes the area of intersection between two ax... | trial_gpt4o_1 | {
"original_instruction": "Two Squares on a Plane\n\nYou are given two squares on a 2D plane. Each of the squares is defined by its four vertices, which are given in counterclockwise order. Determine if the two squares overlap, and if so, output the area of their intersection. If the squares do not overlap, output 0.... | 0.564174 | Code_Contests_34505 | C | [
"get_square_bounds",
"intersection_area"
] | 2 | [
[
"intersection_area",
"get_square_bounds"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 26dc7937c6a84c69aadf956770eac98278408c26 | eb85fe29e89125ba8265c6fd99a9677ded2d9e4c | |||
v1.0 | complete | Code_Contests | Code_Contests_34264_C | from typing import List
def find_max_sorted_books(n: int, books: List[int]) -> int:
""" Find the maximum number of books that can be reserved in a sorted sequence
(ascending order of their identifiers) from a given list of books.
>>> find_max_sorted_books(5, [3, 10, 2, 1, 20])
3
>>> find_max_sorte... | import bisect
def longest_increasing_subsequence(arr):
"""
Returns the length of the longest increasing subsequence in the array.
"""
if not arr:
return 0
lis = []
for book in arr:
pos = bisect.bisect_left(lis, book)
if pos == len(lis):
lis.append(book)
... | from solution import find_max_sorted_books
def test_example_cases():
assert find_max_sorted_books(5, [3, 10, 2, 1, 20]) == 3
assert find_max_sorted_books(6, [3, 2, 6, 4, 5, 1]) == 3
assert find_max_sorted_books(5, [5, 4, 3, 2, 1]) == 1
def test_single_element():
assert find_max_sorted_books(1, [10]) =... | [
{
"docstring": "Returns the length of the longest increasing subsequence in the array.",
"function_declaration": "def longest_increasing_subsequence(arr):",
"function_name": "longest_increasing_subsequence",
"parameter_list": "(arr)"
},
{
"docstring": null,
"function_declaration": "def f... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import bisect\n\ndef longest_increasing_subsequence(arr):\n \"\"\"\n Returns the length of the longest increasing subsequence in the array.\n \"\"... | trial_gpt4o_0 | {
"original_instruction": "Twilight Sparkle is trying to organize books in the Ponyville library. Unfortunately, due to some mischievous acts by Discord, the arrangement of books got completely messed up. Twilight needs your help to sort the books. Each book has a unique identifier, but they are now scattered in arbi... | 0.621318 | Code_Contests_34264 | C | [
"longest_increasing_subsequence",
"find_max_sorted_books"
] | 2 | [
[
"find_max_sorted_books",
"longest_increasing_subsequence"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ba60454d061629e7c50a5825241a78fd0efc658a | 8b4894c3fb724866a68e0a61db450e0ca477d122 | |||
v1.0 | complete | Code_Contests | Code_Contests_35021_C | def find_max_rectangle_area(n: int, m: int, grid_lines: List[str]) -> int:
""" Returns the maximum area of a rectangle containing only 1s in the given grid.
>>> find_max_rectangle_area(4, 5, ["10100", "10111", "11111", "10010"])
6
>>> find_max_rectangle_area(3, 3, ["111", "111", "111"])
9
>>> fi... | def max_rectangle_area(grid):
"""
Returns the maximum area of a rectangle containing only 1s in a given binary grid.
"""
if not grid:
return 0
n = len(grid)
m = len(grid[0])
max_area = 0
heights = [0] * m
for i in range(n):
for j in range(m):
if grid[i][... | from solution import find_max_rectangle_area
def test_case_1():
n, m = 4, 5
grid = [
"10100",
"10111",
"11111",
"10010"
]
assert find_max_rectangle_area(n, m, grid) == 6
def test_case_2():
n, m = 3, 3
grid = [
"111",
"111",
"111"
]
... | [
{
"docstring": "Returns the maximum area of a rectangle containing only 1s in a given binary grid.",
"function_declaration": "def max_rectangle_area(grid):",
"function_name": "max_rectangle_area",
"parameter_list": "(grid)"
},
{
"docstring": "Helper function to calculate the maximum rectangu... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_rectangle_area(grid):\n \"\"\"\n Returns the maximum area of a rectangle containing only 1s in a given binary grid.\n \"\"\"\n if not g... | trial_gpt4o_0 | {
"original_instruction": "You are given a grid with n rows and m columns consisting of cells with binary values (0s and 1s). You need to determine the maximum area of a rectangle containing only 1s within this grid.\n\nInput\n\nThe first line contains two integers n and m (1 ≤ n, m ≤ 200) — the number of rows and co... | 0.732141 | Code_Contests_35021 | C | [
"max_rectangle_area",
"max_histogram_area",
"find_max_rectangle_area"
] | 3 | [
[
"find_max_rectangle_area",
"max_rectangle_area"
],
[
"max_rectangle_area",
"max_histogram_area"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 89e91d58241fab4a3776fb021d05c2ae957a2934 | 2ee0b060118a262884b90e1d435579f43bc12eea | |||
v1.0 | complete | Code_Contests | Code_Contests_35322_C | def find_minimum_idle_participants(input_list: List[str]) -> int:
"""
Determine the minimum number of extra participants that will be idle after fulfilling the requirements of all events.
>>> find_minimum_idle_participants(["2", "3", "1 5", "2 6", "3 3", "15", "2", "4 4", "5 5", "12"])
4
>>> f... | def minimum_idle_participants(number_of_days, events_per_day, participants_per_day):
idle_participants = 0
for day in range(number_of_days):
total_required = sum(required for event, required in events_per_day[day])
participants_available = participants_per_day[day]
idle_participants += m... | def test_example_1():
input_list = [
"2",
"3",
"1 5",
"2 6",
"3 3",
"15",
"2",
"4 4",
"5 5",
"12"
]
assert find_minimum_idle_participants(input_list) == 4
def test_example_2():
input_list = [
"1",
"2",
... | [
{
"docstring": null,
"function_declaration": "def minimum_idle_participants(number_of_days, events_per_day, participants_per_day):",
"function_name": "minimum_idle_participants",
"parameter_list": "(number_of_days, events_per_day, participants_per_day)"
},
{
"docstring": null,
"function_... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def minimize_idle_participants(days):\n total_idle = 0\n \n for day in days:\n events = day['events']\n participants = day['particip... | trial_gpt4o_2 | {
"original_instruction": "In a far-off kingdom, there is a grand celebration held every year which spans multiple days. The celebration includes a series of events each happening on a specific day, and each event requires a certain number of participants for it to be successful. The king wants to ensure that for eac... | 0.551513 | Code_Contests_35322 | C | [
"minimum_idle_participants",
"parse_input",
"find_minimum_idle_participants"
] | 3 | [
[
"find_minimum_idle_participants",
"minimum_idle_participants"
],
[
"find_minimum_idle_participants",
"parse_input"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | false | [] | true | 9ed725c7bb7f3676583a1f0efbba44896e23a741 | cd9dd89bad0d7d3333644d8e98ed3bf964bd3fa4 | |||
v1.0 | complete | Code_Contests | Code_Contests_35178_C | def largest_number(nums: List[int]) -> str:
""" Rearrange the elements to form the largest possible integer.
>>> largest_number([3, 30, 34, 5, 9]) "9534330"
>>> largest_number([10, 2]) "210"
>>> largest_number([1, 11, 111, 1111]) "1111111111"
>>> largest_number([0, 0, 0, 1]) "1000"
>>> largest_n... | from functools import cmp_to_key
def compare(x, y):
if x + y > y + x:
return -1
else:
return 1
def largest_number(nums):
# Convert integers to strings for easier comparison.
nums = list(map(str, nums))
# Sort the numbers based on the custom comparator.
nums.sort(key=cmp_to... | from solution import largest_number
def test_single_digit():
assert largest_number([3, 5, 9, 1]) == "9531"
def test_mixed_numbers():
assert largest_number([3, 30, 34, 5, 9]) == "9534330"
assert largest_number([10, 2]) == "210"
def test_same_digit_numbers():
assert largest_number([1, 11, 111, 1111]) =... | [
{
"docstring": null,
"function_declaration": "def compare(x, y):",
"function_name": "compare",
"parameter_list": "(x, y)"
},
{
"docstring": null,
"function_declaration": "def largest_number(nums):",
"function_name": "largest_number",
"parameter_list": "(nums)"
}
] | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from functools import cmp_to_key\n\ndef largest_number(nums):\n \"\"\"\n Given a list of non-negative integers, arrange them such that they form the ... | trial_gpt4o_2 | {
"original_instruction": "You are given a list of integers. Your task is to rearrange the elements to form the largest possible integer. For example, given the numbers [3, 30, 34, 5, 9], the largest formed integer would be 9534330.\n\nWrite a function that takes an integer list as input and returns the largest forme... | 0.772368 | Code_Contests_35178 | C | [
"compare",
"largest_number"
] | 2 | [
[
"largest_number",
"compare"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 038a2505ade852d7e3e10ded51e705942de94ff7 | f32635d97fe47da871ffaa00fd9097b56a2f7b9f | |||
v1.0 | complete | Code_Contests | Code_Contests_35185_C | def minimum_spanning_tree(n: int, m: int, edges: List[Tuple[int, int, int]]) -> int:
""" Calculate the minimum cost required to construct a spanning tree of an undirected graph with `n` nodes and `m` edges.
If it's not possible to construct such a spanning tree, return `-1`.
Parameters:
- n (int): Numbe... | 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]:
paren... | def test_case_1():
n = 4
m = 4
edges = [(1, 2, 1), (2, 3, 2), (3, 4, 3), (4, 1, 4)]
assert minimum_spanning_tree(n, m, edges) == 6
def test_case_2():
n = 4
m = 3
edges = [(1, 2, 1), (2, 3, 2), (3, 4, 3)]
assert minimum_spanning_tree(n, m, edges) == 6
def test_case_3():
n = 4
m ... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def min_spanning_tree(n, m, edges):\n \"\"\"\n Returns the minimum cost required to construct a spanning tree of the graph using Kruskal's algorithm.... | trial_gpt4o_1 | {
"original_instruction": "You are given an undirected graph with `n` nodes, labeled from `1` to `n`, and `m` edges. Each edge has a cost associated with it. Your task is to find the minimum cost required to construct a spanning tree of the graph (i.e., a tree that includes all nodes of the graph). If it is not possi... | 0.770342 | Code_Contests_35185 | C | [
"find",
"union",
"kruskal_mst",
"minimum_spanning_tree"
] | 4 | [
[
"kruskal_mst",
"find"
],
[
"kruskal_mst",
"union"
],
[
"minimum_spanning_tree",
"kruskal_mst"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | false | [] | true | 36cec89bd2d57c7b69421a7444a1807f875480ff | 5346a15f6e3868be8839f843bc2b5b82389109cf | |||
v1.0 | complete | Code_Contests | Code_Contests_34722_C | def apply_filter(N: int, K: int, A: List[List[int]]) -> List[List[int]]:
"""
Applies a complex filter to an NxN matrix by rotating each KxK block 90 degrees clockwise.
Args:
- N (int): Size of the NxN matrix.
- K (int): Size of the KxK blocks.
- A (List[List[int]]): NxN matrix of integers repre... | from typing import List
def rotate_90_clockwise(block: List[List[int]]) -> List[List[int]]:
"""
Rotates a KxK block 90 degrees clockwise.
"""
K = len(block)
rotated = [[0] * K for _ in range(K)]
for i in range(K):
for j in range(K):
rotated[j][K - 1 - i] = block[i][j]
re... | def test_apply_filter_case_1():
N = 4
K = 2
A = [
[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12],
[13, 14, 15, 16]
]
expected = [
[5, 1, 7, 3],
[6, 2, 8, 4],
[13, 9, 15, 11],
[14, 10, 16, 12]
]
assert apply_filter(N, K, A) == expec... | [
{
"docstring": "Rotates a KxK block 90 degrees clockwise.",
"function_declaration": "def rotate_90_clockwise(block):",
"function_name": "rotate_90_clockwise",
"parameter_list": "(block)"
},
{
"docstring": "Applies the filter over NxN matrix with KxK blocks.",
"function_declaration": "def... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from typing import List\n\ndef rotate_90_clockwise(block: List[List[int]]) -> List[List[int]]:\n \"\"\"\n Rotates a given KxK block 90 degrees clockw... | trial_gpt4o_1 | {
"original_instruction": "A popular graphics editing software wants to introduce a new feature that will allow its users to apply a complex filter to their images. The filter works by rotating sections of the image's pixel matrix. Given an NxN matrix of integers representing pixel values, the filter rotates every Kx... | 0.465719 | Code_Contests_34722 | C | [
"rotate_90_clockwise",
"apply_filter"
] | 2 | [
[
"apply_filter",
"rotate_90_clockwise"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 3c435b09f4ffc1e4202a49fe68402cd4f6974165 | e1e124f0f1fe1a302950567f231d6ac371aa5fe2 | |||
v1.0 | complete | Code_Contests | Code_Contests_35386_C | from typing import List
def is_prime(num: int) -> bool:
""" Determine if a given integer is a prime number. """
pass
def count_primes(N: int, sequence: List[int]) -> int:
""" Count how many prime numbers are in the given sequence.
Args:
N: The number of integers in the sequence.
s... | def is_prime(num):
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
return False
i += 6
return True
def count_primes(N, sequence):... | from solution import is_prime, count_primes
def test_is_prime():
assert is_prime(1) == False
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(97) == True
def test_count_primes():
assert count_primes(5, [1, 2, 3, 4, 5]) == 3
assert count_prim... | [
{
"docstring": null,
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def count_primes(N, sequence):",
"function_name": "count_primes",
"parameter_list": "(N, sequence)"
}
] | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Helper function to check if a number is a prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n ... | trial_gpt4o_1 | {
"original_instruction": "Sumire has a sequence of N integers and wants to know how many of them are prime numbers.\n\nWrite a function to count how many prime numbers are in the given sequence.\n\nConstraints\n\n* The input sequence has N integers.\n* 1 \\leq N \\leq 100\n* Each integer in the sequence is between 1... | 0.773762 | Code_Contests_35386 | C | [
"is_prime",
"count_primes"
] | 2 | [
[
"count_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e20ca3b5cee8b1d8c7e5f9f6cf4caf39c131ee73 | cd9a371d4347f752007699fca48a825836795b8c | |||
v1.0 | complete | Code_Contests | Code_Contests_35157_C | from typing import List
def is_prime(n: int) -> bool:
""" Helper function to determine if a number is prime.
"""
...
def is_prime_subarray(nums: List[int], k: int) -> bool:
""" Function to check if there is a sub-array of length k in nums whose sum is a prime number.
>>> is_prime_subarray([2, 3, ... | from typing import List
def is_prime(n: int) -> bool:
"""
Helper function to determine if a number is prime.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) ... | from solution import is_prime_subarray
def test_is_prime_subarray_case1():
nums = [2, 3, 4, 7, 1]
k = 3
assert is_prime_subarray(nums, k) == False
def test_is_prime_subarray_case2():
nums = [1, 2, 3, 4, 5]
k = 3
assert is_prime_subarray(nums, k) == False
def test_is_prime_subarray_case3():
... | [
{
"docstring": "Helper function to determine if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Function to check if there is a sub-array of length k in nums whose sum is a prime number.",
"function_... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from typing import List\n\ndef is_prime(num: int) -> bool:\n \"\"\"Check if a number is prime.\"\"\"\n if num <= 1:\n return False\n if num... | trial_gpt4o_2 | {
"original_instruction": "You are given an integer array `nums` and an integer `k`. Your task is to identify whether the sub-array of length `k` exists whose sum is a prime number.\n\nA prime number is a natural number greater than 1 that is not a product of two smaller natural numbers. For example, 2, 3, 5, and 7 a... | 0.779158 | Code_Contests_35157 | C | [
"is_prime",
"is_prime_subarray"
] | 2 | [
[
"is_prime_subarray",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 3a36e5e1c3863333fcc0df48711438e2bc8a40f6 | 6769963015d4d36dbf4f21991a8cdcb8f2734a06 | |||
v1.0 | complete | Code_Contests | Code_Contests_34253_C | def convert_to_numeric_sequence(s: str) -> List[int]:
""" Convert the string to a list of numeric positions in the alphabet.
For example:
>>> convert_to_numeric_sequence("hello")
[8, 5, 12, 12, 15]
>>> convert_to_numeric_sequence("world")
[23, 15, 18, 12, 4]
"""
pass
def sum_of_digits(n... | def convert_to_numeric_sequence(s):
numeric_sequence = []
for char in s:
numeric_sequence.append(ord(char) - ord('a') + 1)
return numeric_sequence
def sum_of_digits(num):
total = 0
while num > 0:
total += num % 10
num //= 10
return total
def single_digit_compress(numeri... | def test_convert_to_numeric_sequence():
assert convert_to_numeric_sequence("hello") == [8, 5, 12, 12, 15]
assert convert_to_numeric_sequence("world") == [23, 15, 18, 12, 4]
assert convert_to_numeric_sequence("a") == [1]
assert convert_to_numeric_sequence("zzz") == [26, 26, 26]
def test_sum_of_digits():... | [
{
"docstring": null,
"function_declaration": "def convert_to_numeric_sequence(s):",
"function_name": "convert_to_numeric_sequence",
"parameter_list": "(s)"
},
{
"docstring": null,
"function_declaration": "def sum_of_digits(num):",
"function_name": "sum_of_digits",
"parameter_list... | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def compress_message(s):\n def alphabet_position(c):\n return ord(c) - ord('a') + 1\n\n def digit_sum(n):\n while n > 9:\n n... | trial_gpt4o_4 | {
"original_instruction": "The Galactic Federation has recently incorporated Earth into their alliance, and as part of this integration, Earth has been introduced to their advanced communications protocol. The requirement is that Earthlings should now encode their messages using a specific pattern encryption.\n\nIn t... | 0.576467 | Code_Contests_34253 | C | [
"convert_to_numeric_sequence",
"sum_of_digits",
"single_digit_compress",
"compress_message"
] | 4 | [
[
"compress_message",
"convert_to_numeric_sequence"
],
[
"compress_message",
"single_digit_compress"
],
[
"single_digit_compress",
"sum_of_digits"
]
] | 3 | [] | false | [] | false | pytest | false | [] | true | ad49f35951e8eec30f1daaa2db611870b328b37f | 89a4b69bdcdccb6cfee27c5cead8a25def95c091 | |||
v1.0 | complete | Code_Contests | Code_Contests_34553_C | def is_palindrome(word):
"""
Check if a given word is a palindrome.
"""
# Your code here
def find_sorted_palindromic_titles(n, titles):
"""
Find and sort all the palindromic titles in lexicographical order.
Args:
n : int : number of titles
titles : list of str : list of titles
... | def is_palindrome(word):
"""
Check if a given word is a palindrome.
"""
return word == word[::-1]
def find_sorted_palindromic_titles(n, titles):
"""
Find and sort all the palindromic titles in lexicographical order.
Args:
n : int : number of titles
titles : list of str : list o... | from solution import is_palindrome, find_sorted_palindromic_titles
def test_is_palindrome():
assert is_palindrome("radar")
assert is_palindrome("level")
assert not is_palindrome("hello")
assert is_palindrome("deified")
assert not is_palindrome("world")
def test_find_sorted_palindromic_titles_with_... | [
{
"docstring": "Check if a given word is a palindrome.",
"function_declaration": "def is_palindrome(word):",
"function_name": "is_palindrome",
"parameter_list": "(word)"
},
{
"docstring": "Find and sort all the palindromic titles in lexicographical order.\n\nArgs:\nn : int : number of titles... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_and_sort_palindromic_titles(n, titles):\n \"\"\"\n This function takes the number of titles 'n' and a list of titles 'titles'.\n It retur... | trial_gpt4o_2 | {
"original_instruction": "In a magical kingdom far away, there exists a peculiar language called \"Palindromic Language.\" Words in this language can be read the same backward as forward. The people of this kingdom are very fond of these words, and they always like to arrange them in a special sequence.\n\nOne day, ... | 0.719758 | Code_Contests_34553 | C | [
"is_palindrome",
"find_sorted_palindromic_titles"
] | 2 | [
[
"find_sorted_palindromic_titles",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b3026c1949260889d4aff4f3d35124bffe9e092f | 3a131e1e6c687fee4cd911e0fabe09dc8ee647f1 | |||
v1.0 | complete | Code_Contests | Code_Contests_35584_C | def word_to_code(word: str) -> str:
"""
Converts a word to its corresponding ASCII code representation.
>>> word_to_code("abc") "979899"
>>> word_to_code("def") "100101102"
>>> word_to_code("z") "122"
>>> word_to_code("word") "119111114100"
"""
def min_number_of_groups(test_cases: List[List... | def word_to_code(word):
"""
Converts a word to its corresponding ASCII code representation.
"""
return ''.join(str(ord(char)) for char in word)
def min_number_of_groups(test_cases):
"""
For each test case, determines the minimum number of groups required
such that no two words within the s... | from solution import word_to_code, min_number_of_groups
def test_word_to_code():
assert word_to_code("abc") == "979899"
assert word_to_code("def") == "100101102"
assert word_to_code("z") == "122"
assert word_to_code("word") == "119111114100"
def test_min_number_of_groups():
test_cases = [
... | [
{
"docstring": "Converts a word to its corresponding ASCII code representation.",
"function_declaration": "def word_to_code(word):",
"function_name": "word_to_code",
"parameter_list": "(word)"
},
{
"docstring": "For each test case, determines the minimum number of groups required \nsuch that... | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def ascii_code(word):\n return ''.join(str(ord(c)) for c in word)\n\ndef min_groups(test_cases):\n results = []\n for words in test_cases:\n ... | trial_gpt4o_4 | {
"original_instruction": "In a country called Wordland, each citizen owns a unique word. The government wants to create a special code for each word such that no two words have the same code. The code for each word is constructed by concatenating the ASCII values of its characters in the same order as they appear.\n... | 0.636487 | Code_Contests_35584 | C | [
"word_to_code",
"min_number_of_groups"
] | 2 | [
[
"min_number_of_groups",
"word_to_code"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | db7fb653238ef5f0a9f7eebf081d6cea8bb8a5bc | d9e24f51814b3bec7d0a08527cc4b130c4a2db59 | |||
v1.0 | complete | Code_Contests | Code_Contests_35651_C | def modify_grid(N: int, M: int, grid: List[str]) -> List[str]:
"""
Determine how many mines are adjacent to each cell and replace each empty cell with that number. Cells containing mines should remain unchanged.
:param N: Number of rows in the grid
:param M: Number of columns in the grid
:para... | def count_adjacent_mines(grid, row, col):
directions = [(-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 1), (1, -1), (1, 0), (1, 1)]
count = 0
for dr, dc in directions:
new_row, new_col = row + dr, col + dc
if 0 <= new_row < len(grid) and 0 <= new_col < len(grid[0]):
if grid[new_row][ne... | from solution import modify_grid
def test_example_case():
input_grid = [
".*..",
"....",
"..*.",
"...."
]
expected_output = [
"1*10",
"1221",
"01*1",
"0111"
]
output = modify_grid(4, 4, input_grid)
assert output == expected_output
... | [
{
"docstring": null,
"function_declaration": "def count_adjacent_mines(grid, row, col):",
"function_name": "count_adjacent_mines",
"parameter_list": "(grid, row, col)"
},
{
"docstring": null,
"function_declaration": "def modify_grid(N, M, grid):",
"function_name": "modify_grid",
... | [
0,
0,
0,
0,
0,
0,
0,
0,
1,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def count_mines(grid, N, M):\n \"\"\"\n Counts the number of adjacent mines for each cell in the grid and returns the modified grid.\n \n :para... | trial_gpt4o_8 | {
"original_instruction": "You are given a grid with N rows and M columns. Each cell in the grid contains either a '.' or a '*'. '.' represents an empty cell and '*' represents a mine. Your task is to determine how many mines are adjacent to each cell and replace each empty cell with that number. Cells containing min... | 0.563808 | Code_Contests_35651 | C | [
"count_adjacent_mines",
"modify_grid"
] | 2 | [
[
"modify_grid",
"count_adjacent_mines"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | be92cbc984a6812b7f9b34c59ceb450a2350801b | f378c259237df3a0a456f68931849eec3a301a62 | |||
v1.0 | complete | Code_Contests | Code_Contests_34508_C | from datetime import datetime, timedelta
def is_daytime(current_time: str, start_daytime: str, end_daytime: str) -> bool:
current = datetime.strptime(current_time, "%H:%M").time()
start = datetime.strptime(start_daytime, "%H:%M").time()
end = datetime.strptime(end_daytime, "%H:%M").time()
if start < en... | from datetime import datetime, timedelta
def is_daytime(current_time, start_daytime, end_daytime):
current = datetime.strptime(current_time, "%H:%M").time()
start = datetime.strptime(start_daytime, "%H:%M").time()
end = datetime.strptime(end_daytime, "%H:%M").time()
if start < end:
return start... | def test_simulate_lamp_daytime():
events = ["movement", "no movement", "movement", "no movement"]
assert simulate_lamp(4, events, "12:00", "06:00", "18:00") == "off"
def test_simulate_lamp_night_short_duration():
events = ["movement", "no movement", "no movement", "no movement"]
assert simulate_lamp(4,... | [
{
"docstring": null,
"function_declaration": "def is_daytime(current_time, start_daytime, end_daytime):",
"function_name": "is_daytime",
"parameter_list": "(current_time, start_daytime, end_daytime)"
},
{
"docstring": null,
"function_declaration": "def simulate_lamp(n, events, current_ti... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from datetime import datetime, timedelta\n\ndef is_night(time_str, day_start, day_end):\n time = datetime.strptime(time_str, '%H:%M')\n day_start_tim... | trial_gpt4o_2 | {
"original_instruction": "Develop a program that simulates the behavior of an automatic lamp. The lamp turns on or off based on movements detected by a sensor and the current time of day. The lamp reacts differently during day and night times.\n\nInputs:\n- A series of events that can either be 'movement' or 'no mov... | 0.53219 | Code_Contests_34508 | C | [
"is_daytime",
"simulate_lamp"
] | 2 | [
[
"simulate_lamp",
"is_daytime"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | c964eb1e06bcfee432c298d0f405b5922a3727fd | 3d61c342eaaac2fb47ce0d9da62470482b68b92c | |||
v1.0 | complete | Code_Contests | Code_Contests_35465_C | from typing import List, Tuple
def preprocess_array(arr: List[int]) -> List[int]:
""" Preprocesses the array to compute cumulative sums, which helps in efficiently answering range sum queries.
>>> preprocess_array([1, 2, 3, 4, 5])
[0, 1, 3, 6, 10, 15]
"""
def range_sum(prefix_sum: List[int], l: in... | def preprocess_array(arr):
"""
Preprocesses the array to compute cumulative sums, which helps in efficiently answering range sum queries.
"""
n = len(arr)
prefix_sum = [0] * (n + 1)
for i in range(n):
prefix_sum[i + 1] = prefix_sum[i] + arr[i]
return prefix_sum
def range_s... | def test_preprocess_array():
arr = [1, 2, 3, 4, 5]
expected_prefix_sum = [0, 1, 3, 6, 10, 15]
assert preprocess_array(arr) == expected_prefix_sum
def test_range_sum():
prefix_sum = [0, 1, 3, 6, 10, 15]
assert range_sum(prefix_sum, 1, 3) == 6
assert range_sum(prefix_sum, 2, 5) == 14
assert r... | [
{
"docstring": "Preprocesses the array to compute cumulative sums, which helps in efficiently answering range sum queries.",
"function_declaration": "def preprocess_array(arr):",
"function_name": "preprocess_array",
"parameter_list": "(arr)"
},
{
"docstring": "Returns the sum of the elements... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def preprocess_array(array):\n \"\"\"\n Preprocesses the array to compute prefix sums for efficient range sum queries.\n \"\"\"\n n = len(array... | trial_gpt4o_2 | {
"original_instruction": "You are given an array of n positive integers. Your task is to process several range queries on this array. Each query asks for the sum of all the elements in a specified sub-range of the array.\n\nTo optimize the process, you should preprocess the array to efficiently answer these range su... | 0.674191 | Code_Contests_35465 | C | [
"preprocess_array",
"range_sum",
"process_queries"
] | 3 | [
[
"process_queries",
"preprocess_array"
],
[
"process_queries",
"range_sum"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | false | [] | true | 429e0690658fa6f3ba6f3f98b804a37629ec587e | b46c168321a0e6b8fee6a3bb10fef7e21f00aacd | |||
v1.0 | complete | Code_Contests | Code_Contests_35763_C | from typing import List, Optional
def max_depth(tree: List[Optional[int]]) -> int:
""" Compute the maximum depth of a binary tree.
>>> max_depth([3, 9, 20, None, None, 15, 7])
3
>>> max_depth([1, None, 2])
2
>>> max_depth([])
0
>>> max_depth([1, 2, 3])
2
>>> max_depth([1, None, ... | from typing import List, Optional
from collections import deque
class TreeNode:
def __init__(self, val: Optional[int]):
self.val = val
self.left = None
self.right = None
def build_tree(level_order: List[Optional[int]]) -> Optional[TreeNode]:
if not level_order:
return None
... | from solution import max_depth
def test_empty_tree():
assert max_depth([]) == 0
def test_single_node():
assert max_depth([1]) == 1
def test_two_levels():
assert max_depth([1, 2, 3]) == 2
def test_unbalanced_tree():
assert max_depth([1, None, 2, None, 3]) == 3
def test_balanced_tree():
assert ma... | [] | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from typing import List, Optional\nfrom collections import deque\n\ndef max_depth(tree: List[Optional[int]]) -> int:\n if not tree or tree[0] is None:\n... | trial_gpt4o_4 | {
"original_instruction": "Amanda is solving a problem relating to binary trees. She needs to find the maximum depth of a binary tree. The depth of a binary tree is the number of nodes along the longest path from the root node down to the farthest leaf node.\n\nHelp Amanda by writing a function that computes the maxi... | 0.590698 | Code_Contests_35763 | C | [
"build_tree",
"max_depth"
] | 2 | [
[
"max_depth",
"build_tree"
]
] | 1 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 51b447c86109e467d14a2c99e3c2727069099698 | 1687ab9709ca51ad79755e1e346dbfc0fc36316e | |||
v1.0 | complete | Code_Contests | Code_Contests_34730_C | def generate_primes(limit):
"""
Generate a list of prime numbers up to the specified limit using the Sieve of Eratosthenes.
"""
sieve = [True] * (limit+1)
sieve[0] = sieve[1] = False
for start in range(2, int(limit**0.5) + 1):
if sieve[start]:
for i in range(start*start, lim... | def generate_primes(limit):
"""
Generate a list of prime numbers up to the specified limit using the Sieve of Eratosthenes.
"""
sieve = [True] * (limit+1)
sieve[0] = sieve[1] = False
for start in range(2, int(limit**0.5) + 1):
if sieve[start]:
for i in range(start*start, limi... | def test_generate_primes():
primes = generate_primes(30)
assert primes == [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
def test_primes_and_sums_up_to_10th_prime():
result = primes_and_sums_up_to_nth_prime(10)
expected = [
(2, 2),
(3, 5),
(5, 10),
(7, 17),
(11, 28),
... | [
{
"docstring": "Generate a list of prime numbers up to the specified limit using the Sieve of Eratosthenes.",
"function_declaration": "def generate_primes(limit):",
"function_name": "generate_primes",
"parameter_list": "(limit)"
},
{
"docstring": "Generate the nth prime and the sum of those ... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def generate_primes(limit):\n \"\"\"\n Generate a list of prime numbers up to the specified limit using the Sieve of Eratosthenes.\n \"\"\"\n s... | trial_gpt4o_0 | {
"original_instruction": "Write an algorithm to generate a sequence of prime numbers such that the nth prime number (starting from 1) is generated at the nth position in the sequence, while also ensuring that the sum of those prime numbers up to the nth position is always less than or equal to 1,000,000. Your task i... | 0.642689 | Code_Contests_34730 | C | [
"generate_primes",
"primes_and_sums_up_to_nth_prime",
"main"
] | 3 | [
[
"primes_and_sums_up_to_nth_prime",
"generate_primes"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 96219d1ac8ffbe9da405c2c190e26bd09d2826e8 | d5464603e4b262df3bfcde078aa92bf7f3c675e2 | |||
v1.0 | complete | Code_Contests | Code_Contests_34062_C | def common_fruit_day(test_cases):
""" Determine if there is a day of the week on which every tree produces fruit.
Args:
test_cases (list): A list of tuples where each tuple represents a test case
with the number of trees and their respective days of producing fruits.
Returns... | def common_fruit_day(test_cases):
results = []
for case in test_cases:
n = case[0]
tree_days = case[1:]
common_days = set(tree_days[0])
for days in tree_days[1:]:
common_days.intersection_update(days)
if common_days:
results.append("YES")
e... | from solution import common_fruit_day, read_input, find_common_fruit_day
def test_common_fruit_day():
test_cases = [
(3, ["Mon", "Tue", "Wed"], ["Tue", "Thu", "Sat"], ["Tue", "Fri"]),
(2, ["Mon", "Wed", "Fri"], ["Tue", "Thu", "Sat"]),
]
assert common_fruit_day(test_cases) == ["YES", "NO"]
... | [
{
"docstring": null,
"function_declaration": "def common_fruit_day(test_cases):",
"function_name": "common_fruit_day",
"parameter_list": "(test_cases)"
},
{
"docstring": null,
"function_declaration": "def read_input(input_data):",
"function_name": "read_input",
"parameter_list": ... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def common_fruit_day(test_cases):\n results = []\n for case in test_cases:\n n = case[0]\n tree_days = case[1:]\n common_days = ... | trial_gpt4o_0 | {
"original_instruction": "Problem description\nIn an enchanted forest, there are magical trees that produce fruits only on specific days. Each tree has a unique schedule of days it produces fruit, once per day. You are given the number of trees and for each tree, you are given the days of the week it produces fruits... | 0.630034 | Code_Contests_34062 | C | [
"common_fruit_day",
"read_input",
"find_common_fruit_day"
] | 3 | [
[
"find_common_fruit_day",
"common_fruit_day"
],
[
"find_common_fruit_day",
"read_input"
]
] | 2 | [
"read_input"
] | false | [] | false | pytest | true | [] | true | f242794f80e00f36a8fe5d90f904839accad81e3 | b20cd21933fc642582ea6bfe73807b6a42c1c90f | |||
v1.0 | complete | Code_Contests | Code_Contests_34966_C | def count_trees(grid):
""" Returns the number of trees (1s) in the grid.
>>> count_trees([[0, 1, 0], [1, 1, 1], [0, 1, 0]])
5
>>> count_trees([[0, 0, 0], [0, 0, 0], [0, 0, 0]])
0
"""
rows = len(grid)
cols = len(grid[0])
tree_count = 0
for i in range(rows):
for j in range... | def count_trees(grid):
"""
Returns the number of trees (1s) in the grid.
"""
rows = len(grid)
cols = len(grid[0])
tree_count = 0
for i in range(rows):
for j in range(cols):
if grid[i][j] == 1:
tree_count += 1
return tree_count
def ma... | from solution import count_trees, max_rect_area, max_histogram_area
def test_count_trees():
grid1 = [[0, 1, 0], [1, 1, 1], [0, 1, 0]]
assert count_trees(grid1) == 5
grid2 = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
assert count_trees(grid2) == 0
grid3 = [[1, 1], [1, 1]]
assert count_trees(gri... | [
{
"docstring": "Returns the number of trees (1s) in the grid.",
"function_declaration": "def count_trees(grid):",
"function_name": "count_trees",
"parameter_list": "(grid)"
},
{
"docstring": "Returns the maximum rectangular area of trees (1s) in the grid.",
"function_declaration": "def m... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def count_trees(grid):\n \"\"\"\n Returns the number of trees (1s) in the grid.\n \"\"\"\n rows = len(grid)\n cols = len(grid[0])\n tree_... | trial_gpt4o_0 | {
"original_instruction": "def count_trees(grid):\n rows = len(grid)\n cols = len(grid[0])\n tree_count = 0\n\n for i in range(rows):\n for j in range(cols):\n if grid[i][j] == 1:\n tree_count += 1\n \n return tree_count\n\ndef max_rect_area(grid):\n r... | 0.576815 | Code_Contests_34966 | C | [
"count_trees",
"max_rect_area",
"max_histogram_area"
] | 3 | [
[
"max_rect_area",
"max_histogram_area"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 71b04dd977b8c0ee55e9fb4b03f894da11db4270 | 1ed3ce98666a8cd926c362f29fa7102b415b6ac8 | |||
v1.0 | complete | Code_Contests | Code_Contests_34634_C | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def build_tree(nodes):
if not nodes:
return None
val_to_node = {}
for v, l, r in nodes:
if v not in val_to_node:
val_to_node[v] = Tree... | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def build_tree(nodes):
if not nodes:
return None
val_to_node = {}
for v, l, r in nodes:
if v not in val_to_node:
val_to_node[v] = Tree... | from solution import solve
def test_example_cases():
T = 2
test_cases = [
[(1, 2, 3), (2, -1, -1), (3, -1, -1)],
[(4, 2, 6), (2, 1, 3), (1, -1, -1), (3, -1, -1), (6, 5, 7), (5, -1, -1), (7, -1, -1)]
]
assert solve(T, test_cases) == ["YES", "YES"]
def test_single_node():
T = 1
... | [] | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_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... | trial_gpt4o_1 | {
"original_instruction": "You are given a binary tree with N nodes. Your task is to determine whether the tree is height-balanced. \nA binary tree is height-balanced if the absolute difference between the height of the left and right subtrees of every node in the tree is at most 1.\n\nInput:\nThe first line contains... | 0.704345 | Code_Contests_34634 | C | [
"build_tree",
"is_height_balanced",
"solve"
] | 3 | [
[
"solve",
"build_tree"
],
[
"solve",
"is_height_balanced"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | e4a9f89550d35f17f419fce21646299b17411a51 | f7e5fcbe33b151926f840fb1f7d50ea8d1afec38 | |||
v1.0 | complete | Code_Contests | Code_Contests_35148_C | def does_intersect(x1, y1, w1, h1, x2, y2, w2, h2):
"""
Checks if two rectangles intersect.
Rectangle 1: top-left is (x1, y1), width w1, height h1
Rectangle 2: top-left is (x2, y2), width w2, height h2
"""
# Implementation here
def detect_collisions(test_cases):
"""
Determines if the pl... | def does_intersect(x1, y1, w1, h1, x2, y2, w2, h2):
"""
Checks if two rectangles intersect.
Rectangle 1: top-left is (x1, y1), width w1, height h1
Rectangle 2: top-left is (x2, y2), width w2, height h2
"""
return not (x1 + w1 <= x2 or x2 + w2 <= x1 or y1 + h1 <= y2 or y2 + h2 <= y1)
def detect_... | def test_does_intersect():
# Test cases where rectangles intersect
assert does_intersect(1, 1, 3, 3, 2, 2, 3, 3) == True
assert does_intersect(0, 0, 5, 5, 3, 3, 2, 2) == True
# Test case where rectangles don't intersect
assert does_intersect(1, 1, 3, 3, 5, 5, 2, 2) == False
assert does_inte... | [
{
"docstring": "Checks if two rectangles intersect.\nRectangle 1: top-left is (x1, y1), width w1, height h1\nRectangle 2: top-left is (x2, y2), width w2, height h2",
"function_declaration": "def does_intersect(x1, y1, w1, h1, x2, y2, w2, h2):",
"function_name": "does_intersect",
"parameter_list": "(... | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
1
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_overlapping(x1, y1, w1, h1, x2, y2, w2, h2):\n \"\"\"\n Check if two rectangles overlap.\n Returns True if overlap, otherwise False.\n \... | trial_gpt4o_9 | {
"original_instruction": "David is an avid video game player, and he just started developing his own simple 2D platformer game. He needs help implementing a critical feature: detecting collisions between a player and various obstacles. The game is set on a grid where both the player and obstacles are represented as ... | 0.622021 | Code_Contests_35148 | C | [
"does_intersect",
"detect_collisions"
] | 2 | [
[
"detect_collisions",
"does_intersect"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 2474f2ba6db9e5fd06a040bbf9fbe8f319a93128 | 1b6ebc2b6a29e5d4618b0d16f983adbc6849d7cc | |||
v1.0 | complete | Code_Contests | Code_Contests_33654_C | from typing import List, Tuple
def preprocess_matrix(matrix: List[List[int]]) -> List[List[int]]:
"""
Preprocesses the matrix and returns a prefix sums matrix for efficient query processing.
Parameters:
matrix (List[List[int]]): The input matrix
Returns:
List[List[int]]: The prefix su... | def preprocess_matrix(matrix):
"""
Preprocesses the matrix and returns a prefix sums matrix for efficient query processing.
"""
n = len(matrix)
m = len(matrix[0])
prefix_sums = [[0] * (m + 1) for _ in range(n + 1)]
for i in range(1, n + 1):
for j in range(1, m + 1):
pref... | def test_preprocess_matrix():
matrix = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
expected_prefix_sums = [
[0, 0, 0, 0],
[0, 1, 3, 6],
[0, 5, 12, 21],
[0, 12, 27, 45]
]
assert preprocess_matrix(matrix) == expected_prefix_sums
def test_q... | [
{
"docstring": "Preprocesses the matrix and returns a prefix sums matrix for efficient query processing.",
"function_declaration": "def preprocess_matrix(matrix):",
"function_name": "preprocess_matrix",
"parameter_list": "(matrix)"
},
{
"docstring": "Computes the sum of elements in the subma... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def preprocess_matrix(matrix, n, m):\n \"\"\"\n Preprocess the matrix to get cumulative sums for efficient range sum queries.\n \"\"\"\n cumula... | trial_gpt4o_2 | {
"original_instruction": "You are given a 2D matrix of size n x m, where each cell contains an integer. You need to handle q queries, each asking for the sum of elements in a submatrix defined by its top-left and bottom-right corners.\n\nWrite a program that first reads the matrix and then processes the queries effi... | 0.609234 | Code_Contests_33654 | C | [
"preprocess_matrix",
"query_sum",
"process_queries"
] | 3 | [
[
"process_queries",
"preprocess_matrix"
],
[
"process_queries",
"query_sum"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | false | [] | true | 17dc3f03e92cab139048db0bab0d54edf95e0dae | 5040151520148203ee1d475c33f69536ad5bed1b | |||
v1.0 | complete | Code_Contests | Code_Contests_35561_C | def number_of_paths(input_data: str) -> int:
""" Find the number of distinct paths a warehouse robot can take from the top-left to the bottom-right corner, avoiding obstacles in an NxN grid.
Arguments:
input_data : str : A string representation of the grid, starting with an integer N followed by N lines of... | def num_paths(grid):
N = len(grid)
if grid[0][0] == '#' or grid[N-1][N-1] == '#':
return 0
dp = [[0] * N for _ in range(N)]
dp[0][0] = 1
for i in range(N):
for j in range(N):
if grid[i][j] == '#':
dp[i][j] = 0
else:
... | def test_num_paths_basic():
input_data = "5\n..#..\n.....\n###.#\n.#...\n...#."
assert number_of_paths(input_data) == 2
def test_num_paths_no_obstacle():
input_data = "3\n...\n...\n..."
assert number_of_paths(input_data) == 6
def test_num_paths_all_obstacles():
input_data = "3\n###\n###\n###"
... | [
{
"docstring": null,
"function_declaration": "def num_paths(grid):",
"function_name": "num_paths",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def number_of_paths(input_data):",
"function_name": "number_of_paths",
"parameter_list": "(input_data)"
... | [
0,
0,
0,
0,
0,
0,
0,
0,
1,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_paths(grid):\n N = len(grid)\n if grid[0][0] == '#' or grid[N-1][N-1] == '#':\n return 0\n \n dp = [[0] * N for _ in range(N)]\... | trial_gpt4o_8 | {
"original_instruction": "You are tasked with designing a warehouse robot system that navigates a grid to pick up and deliver packages. The grid is represented as an NxN matrix where each cell can either be empty or contain an obstacle. The robot starts at the top-left corner of the grid and needs to reach the botto... | 0.70612 | Code_Contests_35561 | C | [
"num_paths",
"number_of_paths"
] | 2 | [
[
"number_of_paths",
"num_paths"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | a87e71424dc497d4a9d1db0f89787c7bb48d82be | 2bce002facd43e58a9199aa2990cfaba335b54ca |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.