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 | Apps | Apps_54_C | def calculate_tree_depths(n, edges):
""" For the given number of servers (n) and their connections (edges), calculate the depths of each node in the tree.
>>> calculate_tree_depths(5, [(1, 2), (1, 3), (3, 4), (3, 5)])
[-1, 0, 1, 1, 2, 2]
"""
pass
def minimum_servers_to_isolate(n, edges, scenarios):... | def calculate_tree_depths(n, edges):
from collections import deque, defaultdict
tree = defaultdict(list)
for u, v in edges:
tree[u].append(v)
tree[v].append(u)
depths = [-1] * (n + 1)
queue = deque([(1, 0)])
depths[1] = 0
while queue:
node, depth = queue.poplef... | def test_calculate_tree_depths():
n = 5
edges = [(1, 2), (1, 3), (3, 4), (3, 5)]
expected_depths = [-1, 0, 1, 1, 2, 2]
assert calculate_tree_depths(n, edges) == expected_depths
def test_minimum_servers_to_isolate():
n = 5
edges = [(1, 2), (1, 3), (3, 4), (3, 5)]
scenarios = [3, 4, 5]
ex... | [
{
"docstring": null,
"function_declaration": "def calculate_tree_depths(n, edges):",
"function_name": "calculate_tree_depths",
"parameter_list": "(n, edges)"
},
{
"docstring": null,
"function_declaration": "def minimum_servers_to_isolate(n, edges, scenarios):",
"function_name": "mini... | [
0,
0,
0,
0,
1,
0,
0,
0,
0
] | 1 | hard | 0.111 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def minimum_servers_to_disable(n, edges, scenarios):\n from collections import defaultdict, deque\n\n # Building the adjacency list of the tree\n tree = de... | trial_gpt4o_4 | {
"original_instruction": "In the bustling city of Techville, there are n interconnected computer servers. The servers are set up in such a way that there's only one unique path between any two servers. The city's cybersecurity team has recently discovered a malware threat that could target and disable these servers.... | 0.599009 | Apps_54 | C | [
"calculate_tree_depths",
"minimum_servers_to_isolate"
] | 2 | [
[
"minimum_servers_to_isolate",
"calculate_tree_depths"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 14b3994a0da2494f03f0d46df9a92ab611d91aaa | 42d30c67d063a2b66c6fbf658078f1553e85461e | |||
v1.0 | complete | Apps | Apps_111_C | def count_elements_less_equal(a, m):
"""
This function takes a list 'a' of integers and a maximum value 'm'.
It returns a list 'b' where each element 'b[i]' represents the number
of elements in 'a' that are less than or equal to 'i'.
"""
def solve(test_cases):
"""
This function takes a list... | def count_elements_less_equal(a, m):
"""
This function takes a list 'a' of integers and a maximum value 'm'.
It returns a list 'b' where each element 'b[i]' represents the number
of elements in 'a' that are less than or equal to 'i'.
"""
# Create a list to store the count of elements except init... | import pytest
from solution import count_elements_less_equal, solve, parse_input
def test_count_elements_less_equal():
assert count_elements_less_equal([1, 2, 1, 3, 2], 5) == [2, 4, 5, 5, 5]
assert count_elements_less_equal([1, 3, 3, 2], 3) == [1, 2, 4]
def test_solve():
input_data = [
(5, 5, [1, ... | [
{
"docstring": "This function takes a list 'a' of integers and a maximum value 'm'.\nIt returns a list 'b' where each element 'b[i]' represents the number\nof elements in 'a' that are less than or equal to 'i'.",
"function_declaration": "def count_elements_less_equal(a, m):",
"function_name": "count_ele... | [
1,
1,
0,
1,
1,
1,
1,
1,
1,
1
] | 9 | easy | 0.9 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_b_arrays(t, test_cases):\n results = []\n \n for n, m, a in test_cases:\n b = [0] * m\n \n # Count occurrences of each number... | trial_gpt4o_7 | {
"original_instruction": "You are given an array `a` consisting of `n` integers between `1` and `m` inclusive. Your task is to find an array `b` of length `m`, where each element `b[i]` represents the number of elements in `a` that are less than or equal to `i`. If there are no elements in `a` that are less than or ... | 0.612252 | Apps_111 | C | [
"count_elements_less_equal",
"solve",
"parse_input"
] | 3 | [
[
"solve",
"count_elements_less_equal"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 473e5c49bc31687662302371277649377e18bcc5 | 5ed69b6ba11094fa35a8104638c15b972a510cfe | |||
v1.0 | complete | Apps | Apps_334_C | from typing import List
def filter_primes(lst: List[int]) -> List[int]:
"""Takes a list of integers and returns a list containing only the prime numbers from the input list.
>>> filter_primes([10, 15, 3, 7, 8, 19, 23, 6])
[3, 7, 19, 23]
>>> filter_primes([4, 6, 8, 9, 10])
[]
>>> filter_primes([... | def is_prime(n):
"""
Helper function to check if the given number n is a prime number.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
retur... | from solution import filter_primes
def test_filter_primes_with_primes_and_non_primes():
assert filter_primes([10, 15, 3, 7, 8, 19, 23, 6]) == [3, 7, 19, 23]
def test_filter_primes_with_all_non_primes():
assert filter_primes([4, 6, 8, 9, 10]) == []
def test_filter_primes_with_all_primes():
assert filter_p... | [
{
"docstring": "Helper function to check if the given number n is a prime number.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list containing only the prime numbers from the input list.",
"function_declar... | [
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 9 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Helper function to determine if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n retu... | trial_gpt4o_4 | {
"original_instruction": "Write a function that takes a list of integers and returns a list containing only the prime numbers from the input list. \n\nFor example, if the input list is:\n\n [10, 15, 3, 7, 8, 19, 23, 6]\n\nthe function should return:\n\n [3, 7, 19, 23]\n\nThe input list can contain any integer ... | 0.665447 | Apps_334 | C | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 042f0c8bb4120d8d014beb406fcf224d6d6a8926 | 04743b28062b1a828438a9e2d015b560853ee002 | |||
v1.0 | complete | Apps | Apps_574_C | def outpost_finder(input_string: str) -> List[int]:
""" Determines the minimum number of outposts needed to monitor
all houses in each test case.
Args:
input_string (str): A string representation of the input
Returns:
List[int]: A list of integers representing the minimum number
... | def min_outposts(test_cases):
results = []
for case in test_cases:
N, r, houses = case
houses.sort()
outposts = 0
i = 0
while i < N:
outposts += 1
loc = houses[i] + r
while i < N and houses[i] <= loc:
i += 1
... | from solution import outpost_finder
def test_example_case_1():
input_string = "2\n5 2\n1 2 5 6 7\n3 1\n3 5 6\n"
output = outpost_finder(input_string)
assert output == [2, 2]
def test_single_house():
input_string = "1\n1 1\n1\n"
output = outpost_finder(input_string)
assert output == [1]
def te... | [
{
"docstring": null,
"function_declaration": "def min_outposts(test_cases):",
"function_name": "min_outposts",
"parameter_list": "(test_cases)"
},
{
"docstring": null,
"function_declaration": "def parse_input(input_string):",
"function_name": "parse_input",
"parameter_list": "(in... | [
0,
0,
1,
1,
0,
1,
0,
1,
0
] | 4 | medium | 0.444 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def min_outposts(T, test_cases):\n results = []\n \n for case in test_cases:\n N, r, positions = case\n positions.sort()\n outposts = ... | trial_gpt4o_8 | {
"original_instruction": "In a town, there are $N$ houses lined up in a straight row on a 1D number line. The position of each house is represented by an integer $x_i$. To ensure safety and simplification of mail delivery, the town council has decided to establish a number of security outposts in such a way that eve... | 0.503895 | Apps_574 | C | [
"min_outposts",
"parse_input",
"outpost_finder"
] | 3 | [
[
"outpost_finder",
"min_outposts"
],
[
"outpost_finder",
"parse_input"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | e1784b843b1dc056c9f7eebeca01a275061ee981 | c95376e0e06ffa375ee6f3c8292b0d2a9cc4a155 | |||
v1.0 | complete | Apps | Apps_516_C | from typing import List, Tuple
def solve(T: int, test_cases: List[Tuple[int, List[int]]]) -> List[int]:
"""Help Dr. Chan determine the largest number of experiments he can run simultaneously such that all the chosen numbers are pairwise coprime.
Args:
T (int): Number of test cases
test_cases (List[Tup... | from math import gcd
from functools import reduce
from itertools import combinations
def gcd_pairs(numbers):
"""
Calculate the gcd of each pair in list of numbers.
"""
return all(gcd(a, b) == 1 for a, b in combinations(numbers, 2))
def max_pairwise_coprime_subset(a):
"""
Return the size of lar... | from solution import solve
def test_example1():
T = 2
test_cases = [
(5, [3, 5, 7, 11, 13]),
(4, [6, 10, 15, 21])
]
assert solve(T, test_cases) == [5, 2]
def test_single_element():
T = 1
test_cases = [(1, [10])]
assert solve(T, test_cases) == [1]
def test_all_ones():
T... | [
{
"docstring": "Calculate the gcd of each pair in list of numbers.",
"function_declaration": "def gcd_pairs(numbers):",
"function_name": "gcd_pairs",
"parameter_list": "(numbers)"
},
{
"docstring": "Return the size of largest subset of a such that all elements are pairwise coprime.",
"fu... | [
0,
1,
0,
0,
0,
0,
1,
0,
0,
0
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\nfrom collections import defaultdict\n\ndef gcd(a, b):\n while b:\n a, b = b, a % b\n return a\n\ndef max_pairwise_coprime_subset_size(n, a... | trial_gpt4o_6 | {
"original_instruction": "Dr. Chan is working on a research project involving prime numbers. He has a machine that can conduct multiple experiments in parallel as long as the numbers used in these experiments are \"scientifically distinct.\" Numbers are scientifically distinct if they share no common factors other t... | 0.643849 | Apps_516 | C | [
"gcd_pairs",
"max_pairwise_coprime_subset",
"solve"
] | 3 | [
[
"max_pairwise_coprime_subset",
"gcd_pairs"
],
[
"solve",
"max_pairwise_coprime_subset"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 471dac24e59b6d77775ee4d86e3e64b775f3f263 | e90955ed21793b0c63346fb043059191ed6b4a51 | |||
v1.0 | complete | Apps | Apps_509_C | def is_prime(num: int) -> bool:
"""
Check if a number is a prime number.
>>> is_prime(2)
True
>>> is_prime(4)
False
>>> is_prime(11)
True
"""
# Implement the function to check if num is a prime number
def smallest_prime_greater_than(N: int) -> int:
"""
Find the smallest... | def is_prime(num):
"""
Returns True if num is a prime number, otherwise False.
"""
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
... | from solution import is_prime, smallest_prime_greater_than, process_test_cases
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(10) == False
assert is_prime(11) == True
assert is_prime(15) == Fa... | [
{
"docstring": "Returns True if num is a prime number, otherwise False.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns the smallest prime number greater than N.",
"function_declaration": "def smallest_prim... | [
1,
1,
1,
1,
0,
1,
0,
1,
1,
1
] | 8 | easy | 0.8 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Returns True if num is a prime number, otherwise False.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n ... | trial_gpt4o_0 | {
"original_instruction": "Write a function to find the smallest prime number greater than a given number $N$. A prime number is a natural number greater than 1 that cannot be formed by multiplying two smaller natural numbers.\n\n-----Input:-----\n- First-line will contain $T$, the number of test cases. Then the test... | 0.740285 | Apps_509 | C | [
"is_prime",
"smallest_prime_greater_than",
"process_test_cases"
] | 3 | [
[
"process_test_cases",
"smallest_prime_greater_than"
],
[
"smallest_prime_greater_than",
"is_prime"
]
] | 2 | [
"process_test_cases"
] | false | [] | false | pytest | true | [] | true | 210607ec1b11a6cf87742d88200cda96523b226e | b91bdc502d8227dd5784787cc79a706e908e3b2d | |||
v1.0 | complete | Apps | Apps_505_C | def find_min_max_pages(n: int, pages: List[int], k: int) -> int:
""" You are given an array of integers representing the number of pages in n books. You need to distribute these books among k students in such a way that each student gets a contiguous segment of the books. The goal is to minimize the maximum number ... | def is_possible(pages, n, k, max_pages):
student_count = 1
current_sum = 0
for page in pages:
current_sum += page
if current_sum > max_pages:
student_count += 1
current_sum = page
if student_count > k:
return Fals... | from solution import find_min_max_pages
def test_example_case():
assert find_min_max_pages(4, [10, 20, 30, 40], 2) == 60
def test_single_book():
assert find_min_max_pages(1, [100], 1) == 100
def test_equal_partition():
assert find_min_max_pages(4, [10, 10, 10, 10], 4) == 10
def test_large_number_of_book... | [
{
"docstring": null,
"function_declaration": "def is_possible(pages, n, k, max_pages):",
"function_name": "is_possible",
"parameter_list": "(pages, n, k, max_pages)"
},
{
"docstring": null,
"function_declaration": "def find_min_max_pages(n, pages, k):",
"function_name": "find_min_max... | [
1,
0,
1,
1,
0,
1,
1,
0,
0,
0
] | 5 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def canDistributeBooks(books, n, k, maxPages):\n students = 1\n current_sum = 0\n\n for pages in books:\n if pages > maxPages:\n return F... | trial_gpt4o_6 | {
"original_instruction": "You are given an array of integers representing the number of pages in $n$ books. You need to distribute these books among $k$ students in such a way that each student gets a contiguous segment of the books. The goal is to minimize the maximum number of pages that a student can receive.\n\n... | 0.701753 | Apps_505 | C | [
"is_possible",
"find_min_max_pages"
] | 2 | [
[
"find_min_max_pages",
"is_possible"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5bb6a1e57872a8aa3eac0bcb24360d9b3d2796cc | e582bae9f302250744dbe155070682a4395aa34a | |||
v1.0 | complete | Apps | Apps_808_C | def is_circular_prime(n: int) -> bool:
""" Determine if a number is a circular prime.
Circular prime is a prime number that, in any cyclic permutation of its digits, results in a prime number.
>>> is_circular_prime(197)
True
>>> is_circular_prime(1193)
True
>>> is_circular_prime(101)
... | def is_prime(n):
"""
Check if a number is a prime.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return False
return True
def rotate_number(n):
... | from solution import is_circular_prime
def test_single_digit_prime():
assert is_circular_prime(2) == True
assert is_circular_prime(3) == True
assert is_circular_prime(5) == True
assert is_circular_prime(7) == True
def test_single_digit_non_prime():
assert is_circular_prime(1) == False
assert i... | [
{
"docstring": "Check if a number is a prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Generate all rotations of a number.",
"function_declaration": "def rotate_number(n):",
"function_name": "rotate_number",... | [
0,
1,
0,
0,
1,
0,
0,
1,
1,
1
] | 5 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n if num <= 1:\n return False\n if num == 2:\n return True\n if num % 2 == 0:\n return False\n for i in range(3,... | trial_gpt4o_8 | {
"original_instruction": "## Circular Prime Checker\n\nA circular prime is a prime number that, in any cyclic permutation of its digits, results in a prime number. For example, 197 is a circular prime because 197, 971, and 719 are all primes. \n\nYou need to write a function to determine if a given number is a circu... | 0.739244 | Apps_808 | C | [
"is_prime",
"rotate_number",
"is_circular_prime"
] | 3 | [
[
"is_circular_prime",
"is_prime"
],
[
"is_circular_prime",
"rotate_number"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 7b79196238fc4e4a8b64267cfa037adb554738ba | 63c9bd6cf40f47e2e8d8488eb5a7d0b29a82cb1a | |||
v1.0 | complete | Apps | Apps_450_C | def is_palindromic(n):
"""
Check if the number n is a palindromic number.
"""
pass
def sum_palindromic_numbers_in_range(A, B):
"""
Calculate the sum of all palindromic numbers within the inclusive range [A, B].
"""
pass
def process_test_cases(test_cases):
"""
Process multiple t... | def is_palindromic(n):
"""
Check if the number n is a palindromic number.
"""
s = str(n)
return s == s[::-1]
def sum_palindromic_numbers_in_range(A, B):
"""
Calculate the sum of all palindromic numbers within the inclusive range [A, B].
"""
return sum(n for n in range(A, B+1) if is_... | from solution import is_palindromic, sum_palindromic_numbers_in_range, process_test_cases
def test_is_palindromic():
assert is_palindromic(121)
assert is_palindromic(12321)
assert not is_palindromic(123)
assert not is_palindromic(12345)
def test_sum_palindromic_numbers_in_range():
assert sum_palin... | [
{
"docstring": "Check if the number n is a palindromic number.",
"function_declaration": "def is_palindromic(n):",
"function_name": "is_palindromic",
"parameter_list": "(n)"
},
{
"docstring": "Calculate the sum of all palindromic numbers within the inclusive range [A, B].",
"function_dec... | [
0,
0,
0,
0,
0,
1,
0,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def sum_palindromes_in_range(A, B):\n \"\"\"\n Calculate the sum of all palindromic numbers within the range [A, B].\n \"\"\"\n return sum(num for num i... | trial_gpt4o_5 | {
"original_instruction": "Lena loves numbers and recently discovered an interesting property of palindromic numbers. A palindromic number is a number that remains the same when its digits are reversed. She wants to explore the sum of all palindromic numbers within a given range [A, B].\n\nYou are Lena's friend, and ... | 0.625962 | Apps_450 | C | [
"is_palindromic",
"sum_palindromic_numbers_in_range",
"process_test_cases"
] | 3 | [
[
"process_test_cases",
"sum_palindromic_numbers_in_range"
],
[
"sum_palindromic_numbers_in_range",
"is_palindromic"
]
] | 2 | [
"process_test_cases"
] | false | [] | false | pytest | true | [] | true | 56aa1ceaee7afce82c241217cf5cba4178889571 | 23567bdddd66d0cbd1a1735bfbbf00ddde683110 | |||
v1.0 | complete | Apps | Apps_694_C | from typing import List
def shortest_path_with_treasures(n: int, m: int, grid: List[str]) -> str:
""" Find the shortest path from the top-left to the bottom-right corner of the grid, collecting as many treasures as possible.
>>> shortest_path_with_treasures(5, 5, ["T...T", ".#.#.", "T.....", ".#.#.", "T...T"]... | from collections import deque
def find_shortest_path(n, m, grid):
# Directions for moving up, down, left, right
directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]
def is_valid(x, y):
return 0 <= x < n and 0 <= y < m and grid[x][y] != '#'
visited = [[[False, 0] for _ in range(m)] for _ in... | import pytest
from solution import shortest_path_with_treasures
def test_example_case():
n, m = 5, 5
grid = [
"T...T",
".#.#.",
"T.....",
".#.#.",
"T...T"
]
assert shortest_path_with_treasures(n, m, grid) == "8 3"
def test_no_path():
n, m = 3, 3
grid = [... | [
{
"docstring": null,
"function_declaration": "def find_shortest_path(n, m, grid):",
"function_name": "find_shortest_path",
"parameter_list": "(n, m, grid)"
},
{
"docstring": null,
"function_declaration": "def shortest_path_with_treasures(n, m, grid):",
"function_name": "shortest_path... | [
0,
0,
1,
1,
0,
0,
0,
0,
0,
0
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef bfs(grid, n, m):\n if grid[0][0] == '#' or grid[n-1][m-1] == '#':\n return -1, 0\n \n directions = [(-1, 0), (1... | trial_gpt4o_2 | {
"original_instruction": "You are given a grid with $n$ rows and $m$ columns. Each cell in the grid is either empty, contains an obstacle, or contains a treasure. You need to find the shortest path from the top-left corner of the grid to the bottom-right corner, collecting as many treasures as possible on your way.\... | 0.598343 | Apps_694 | C | [
"find_shortest_path",
"shortest_path_with_treasures"
] | 2 | [
[
"shortest_path_with_treasures",
"find_shortest_path"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b632c6410efe0acfa1e31d52088b33f98869e0b2 | f075cd58f6bd79448232b3eee3a34181b4ceb521 | |||
v1.0 | complete | Apps | Apps_636_C | def count_less_equal_elements(A):
""" Returns an array B such that for each element B[i], the value is equal to the number
of elements in A that are less than or equal to A[i].
>>> count_less_equal_elements([4, 2, 9, 1, 7]) == [3, 2, 5, 1, 4]
>>> count_less_equal_elements([3, 3, 3]) == [3, 3, 3]
>>>... | def count_less_equal_elements(A):
"""
Returns an array B such that for each element B[i], the value is equal to the number
of elements in A that are less than or equal to A[i].
"""
sorted_A = sorted(A)
B = []
for num in A:
count = binary_search_find_count(sorted_A, num)
B.app... | from solution import count_less_equal_elements
def test_sample_case_1():
assert count_less_equal_elements([4, 2, 9, 1, 7]) == [3, 2, 5, 1, 4]
def test_sample_case_2():
assert count_less_equal_elements([3, 3, 3]) == [3, 3, 3]
def test_single_element():
assert count_less_equal_elements([5]) == [1]
def tes... | [
{
"docstring": "Returns an array B such that for each element B[i], the value is equal to the number\nof elements in A that are less than or equal to A[i].",
"function_declaration": "def count_less_equal_elements(A):",
"function_name": "count_less_equal_elements",
"parameter_list": "(A)"
},
{
... | [
1,
1,
0,
1,
1,
1,
0,
0,
0,
1
] | 6 | medium | 0.6 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def calculate_b(A):\n \"\"\"\n Given an array A, calculate array B such that each B[i] is the number of elements in A that are less than or equal to A[i].\n ... | trial_gpt4o_9 | {
"original_instruction": "You are given an integer array `A`. Create an array `B` such that for each element `B[i]`, the value is equal to the number of elements in `A` that are less than or equal to `A[i]`.\n\n-----Input-----\n\nThe first line contains an integer `n` (1 ≤ n ≤ 10^5), the number of elements in array ... | 0.627951 | Apps_636 | C | [
"count_less_equal_elements",
"binary_search_find_count"
] | 2 | [
[
"count_less_equal_elements",
"binary_search_find_count"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6bb17eed93cd109221fd9ff9d52292c71e8d8893 | 3a94ae695e09a73988f46eec0f428cd3c8314911 | |||
v1.0 | complete | Apps | Apps_876_C | import re
from typing import List
def is_palindrome(S: str) -> bool:
"""
Determines if the given string S is a palindrome, ignoring case and non-alphanumeric characters.
>>> is_palindrome("A man, a plan, a canal: Panama")
True
>>> is_palindrome("race a car")
False
>>> is_palindrome("No lemo... | import re
def is_palindrome(S):
"""
Determines if the given string S is a palindrome, ignoring case and non-alphanumeric characters.
"""
# Clean the string, keep only alphanumeric characters and convert to lowercase
clean_s = re.sub(r'[^A-Za-z0-9]', '', S).lower()
# Check if the cleaned string ... | from solution import is_palindrome, check_palindromes
def test_is_palindrome():
assert is_palindrome("A man, a plan, a canal: Panama") == True
assert is_palindrome("race a car") == False
assert is_palindrome("No lemon, no melon") == True
assert is_palindrome("Madam In Eden, I’m Adam") == True
asser... | [
{
"docstring": "Determines if the given string S is a palindrome, ignoring case and non-alphanumeric characters.",
"function_declaration": "def is_palindrome(S):",
"function_name": "is_palindrome",
"parameter_list": "(S)"
},
{
"docstring": "Given T strings, determines for each if it is a pal... | [
1,
0,
1,
1,
1,
1,
1,
1,
0,
1
] | 8 | easy | 0.8 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import re\n\ndef is_palindrome(s):\n \"\"\"\n Checks if the given string s is a palindrome, considering only alphanumeric characters and ignoring cases.\n ... | trial_gpt4o_9 | {
"original_instruction": "John is attempting to create a program that checks whether a given string is a palindrome. A palindrome is a word that reads the same backward as forward. However, his program should ignore case and non-alphanumeric characters while checking for palindromes.\n\nWrite a function to determine... | 0.849771 | Apps_876 | C | [
"is_palindrome",
"check_palindromes"
] | 2 | [
[
"check_palindromes",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ba7d57aa7b0b3949c8e4faa1ba1b0ce487ee148b | 5e45b23416b70c9efa530b527f16cccbfc9b47f9 | |||
v1.0 | complete | Apps | Apps_780_C | from typing import List
def is_prime(n: int) -> bool:
"""Checks if a given number is a prime number.
>>> is_prime(2)
True
>>> is_prime(3)
True
>>> is_prime(4)
False
>>> is_prime(17)
True
>>> is_prime(18)
False
"""
def filter_primes(numbers: List[int]) -> List[int]:
... | def is_prime(n):
"""
Checks if a number is prime.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return False
return True
def filter_primes(numbers):
"""... | from solution import filter_primes, is_prime
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(1) == False
assert is_prime(0) == False
assert is_prime(17) == True
assert is_prime(18) == False... | [
{
"docstring": "Checks if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list of prime numbers from the given list of integers.",
"function_declaration": "def filter_primes(numbers):",
... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Returns True if n is a prime number, otherwise False.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n r... | trial_gpt4o_7 | {
"original_instruction": "Create a function that takes in a list of integers and returns a new list containing only the prime numbers from the original list. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself.\n\nFor example, given the list `[2, 3, 4, 5, 6, 7, 8, ... | 0.763127 | Apps_780 | C | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 24010763dbbc5d77b94ef0c04e6957b031f535c4 | c8756d58eba65da000f40c52c449277c19a5a7cc | |||
v1.0 | complete | Apps | Apps_847_C | def is_prime(n: int) -> bool:
"""
Helper function to check if a number n is prime.
>>> is_prime(3) True
>>> is_prime(4) False
>>> is_prime(5) True
>>> is_prime(1) False
>>> is_prime(2) True
>>> is_prime(29) True
>>> is_prime(0) False
>>> is_prime(-3) False
"""
def filter... | def is_prime(n):
"""
Helper function to check if a number n is prime.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return False
return True
def filter_prim... | from solution import is_prime, filter_primes
def test_is_prime():
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(1) == False
assert is_prime(2) == True
assert is_prime(29) == True
assert is_prime(0) == False
assert is_prime(-3) == False... | [
{
"docstring": "Helper function to check if a number n is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Filters the prime numbers from the given list lst.",
"function_declaration": "def filter_primes(lst):",
... | [
1,
1,
1,
1,
1,
1,
1,
1,
0,
1
] | 9 | easy | 0.9 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n for i in range(2, int(nu... | trial_gpt4o_5 | {
"original_instruction": "You are required to implement a function that takes a list of integers and returns a list consisting of all the prime numbers found within the given list. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself.\n\n### Tests\n```python\nfilter... | 0.786252 | Apps_847 | C | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 11143682a7239c117a8af1cc8512d34022137bda | 9e100676bd1e977fa1878975acee8f950aeae5a3 | |||
v1.0 | complete | Apps | Apps_669_C | from typing import List, Tuple
def tsp_solver(input_str: str) -> List[int]:
"""Solve the Traveling Salesman Problem (TSP) for the given input string.
The function takes an input string containing multiple test cases, where each test case
consists of a number of cities and a matrix of distances between each... | from itertools import permutations
def calculate_tsp(n, matrix):
def calculate_path_length(path):
total_length = 0
for i in range(len(path) - 1):
total_length += matrix[path[i]][path[i+1]]
total_length += matrix[path[-1]][path[0]]
return total_length
cities = list(r... | from solution import tsp_solver
def test_example_case():
input_str = "2\n4\n0 10 15 20\n10 0 35 25\n15 35 0 30\n20 25 30 0\n3\n0 5 9\n5 0 10\n9 10 0\n"
expected_output = [80, 24]
assert tsp_solver(input_str) == expected_output
def test_single_case():
input_str = "1\n3\n0 1 2\n1 0 3\n2 3 0\n"
expec... | [
{
"docstring": null,
"function_declaration": "def calculate_tsp(n, matrix):",
"function_name": "calculate_tsp",
"parameter_list": "(n, matrix)"
},
{
"docstring": null,
"function_declaration": "def find_min_tsp_distances(T, test_cases):",
"function_name": "find_min_tsp_distances",
... | [
0,
0,
0,
1,
0,
0,
0,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import itertools\n\ndef traveling_salesman(matrix, n):\n min_path = float('inf')\n cities = list(range(n))\n \n for perm in itertools.permutations(citie... | trial_gpt4o_3 | {
"original_instruction": "Richard is planning a vacation and wants to visit several cities. He has a list of cities and the distances between each pair of cities. Richard wants to find a route that will allow him to visit all cities exactly once and return to the starting city with the minimum total distance travele... | 0.629732 | Apps_669 | C | [
"calculate_tsp",
"find_min_tsp_distances",
"parse_input",
"tsp_solver"
] | 4 | [
[
"find_min_tsp_distances",
"calculate_tsp"
],
[
"tsp_solver",
"find_min_tsp_distances"
],
[
"tsp_solver",
"parse_input"
]
] | 3 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | cbd30f75d7a284090b195b4a7d19352fedf181cc | c3d8b86ca2fac1e7efa175136c103fda3f46d8a3 | |||
v1.0 | complete | Apps | Apps_820_C | def is_prime(x):
"""
Helper function that determines if a number is prime.
>>> is_prime(2) == True
>>> is_prime(3) == True
>>> is_prime(4) == False
>>> is_prime(29) == True
>>> is_prime(1) == False
>>> is_prime(-3) == False
"""
pass
def has_prime_in_parts(n, k):
"""
Dete... | def is_prime(x):
"""
Helper function that determines if a number is prime.
"""
if x <= 1:
return False
if x <= 3:
return True
if x % 2 == 0 or x % 3 == 0:
return False
i = 5
while i * i <= x:
if x % i == 0 or x % (i + 2) == 0:
return False
... | from solution import is_prime, has_prime_in_parts
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(29) == True
assert is_prime(1) == False
assert is_prime(-3) == False
def test_has_prime_in_parts():
assert has_prime_in_p... | [
{
"docstring": "Helper function that determines if a number is prime.",
"function_declaration": "def is_prime(x):",
"function_name": "is_prime",
"parameter_list": "(x)"
},
{
"docstring": "Determine if there is at least one part containing a prime number \nwhen the cards numbered 1 to n are d... | [
0,
1,
0,
1,
1,
0,
1,
0,
1,
1
] | 6 | medium | 0.6 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef is_prime(x):\n if x <= 1:\n return False\n if x <= 3:\n return True\n if x % 2 == 0 or x % 3 == 0:\n return False\n... | trial_gpt4o_8 | {
"original_instruction": "# Task\nJoe and Sam love playing card games. They are particularly fascinated by a game that involves a special sequence in the deck. The deck contains cards numbered from 1 to `n`. Joe and Sam noticed that the cards form an interesting pattern when divided into separate parts.\n\nThe game ... | 0.703667 | Apps_820 | C | [
"is_prime",
"has_prime_in_parts"
] | 2 | [
[
"has_prime_in_parts",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 113de79ee6a0e6a511fc0da5aaf3880cb14ed522 | 7e150c160557dd269ed2b53311fb105036f9fe32 | |||
v1.0 | complete | Apps | Apps_773_C | from typing import List, Tuple
def encode(message: str) -> List[Tuple[int, int]]:
""" Encode a message into a unique sequence of domino tiles.
Args:
message (str): The message to encode.
Returns:
List[Tuple[int, int]]: The list of domino tiles encoding the message or None if invali... | import math
from functools import reduce
def message_to_number(message):
""" Convert message to a number base 36 """
base_36 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
number = 0
for char in message:
number = number * 36 + base_36.index(char)
return number
def number_to_message(number):
... | from solution import encode, decode
def test_encode_valid_message():
message = "HELLO"
encoded = encode(message)
assert isinstance(encoded, list)
assert len(encoded) == 28
assert all(isinstance(tile, tuple) for tile in encoded)
assert all(0 <= a <= 6 and 0 <= b <= 6 and a <= b for a, b in encod... | [
{
"docstring": "Convert message to a number base 36 ",
"function_declaration": "def message_to_number(message):",
"function_name": "message_to_number",
"parameter_list": "(message)"
},
{
"docstring": "Convert a number to a message base 36 ",
"function_declaration": "def number_to_message... | [
0,
1,
0,
0,
0,
0,
0,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\nfrom string import ascii_uppercase, digits\n\n# All unique tiles in a standard domino set\nALL_TILES = [(i, j) for i in range(7) for j in range(i, 7)]\... | trial_gpt4o_1 | {
"original_instruction": "A common cryptography technique involves encoding messages in unexpected places. For this task, you will use a set of dominoes to encode and decode messages. \n\nA standard set of dominoes includes 28 tiles, each representing a pair of numbers between 0 and 6. For example, a domino tile mig... | 0.566458 | Apps_773 | C | [
"message_to_number",
"number_to_message",
"factorial",
"encode",
"decode"
] | 5 | [
[
"decode",
"number_to_message"
],
[
"encode",
"factorial"
],
[
"encode",
"message_to_number"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | ad089d34f599879b9bb3034fd694314fe37865a2 | 5c857b01d6a6efea30756cc7d554817d23369e89 | |||
v1.0 | complete | Apps | Apps_1107_C | from typing import List
def filter_primes(numbers: List[int]) -> List[int]:
"""
Create a function that takes a list of integers and returns a new list containing only the prime numbers from the original list. If the original list contains no prime numbers, the function should return an empty list.
>>>... | def is_prime(n):
"""
Determines if a given number n is a prime.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return False
return True
def filter_primes(num... | from solution import filter_primes
def test_filter_primes_with_all_primes():
assert filter_primes([2, 3, 5, 7, 11]) == [2, 3, 5, 7, 11]
def test_filter_primes_with_no_primes():
assert filter_primes([4, 6, 8, 10, 12]) == []
def test_filter_primes_with_mixed_numbers():
assert filter_primes([4, 5, 6, 7, 8, ... | [
{
"docstring": "Determines if a given number n is a prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Takes a list of integers and returns a new list containing only the prime numbers from the original list.",
"fu... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Helper function to determine if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n retu... | trial_gpt4o_4 | {
"original_instruction": "Create a function that takes a list of integers and returns a new list containing only the prime numbers from the original list. If the original list contains no prime numbers, the function should return an empty list.",
"prompt_id": "00001107",
"row_id": 1107,
"seed_ids": "[3466]"
} | 0.683073 | Apps_1107 | C | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0a7c02ba71c7d512cff2137a274cd9b93165b5b0 | 9169f2eb82ca8ccf89aa0f51ef16d3f7bca6c944 | |||
v1.0 | complete | Apps | Apps_1027_C | def is_prime(n: int) -> bool:
""" Helper function that checks if a number n is prime.
>>> is_prime(2) True
>>> is_prime(3) True
>>> is_prime(4) False
>>> is_prime(5) True
>>> is_prime(10) False
>>> is_prime(0) False
>>> is_prime(1) False
>>> is_prime(17) True
"""
def is_prim... | def is_prime(n):
"""
Helper function that checks if a number n is prime.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return False
return True
def is_prime... | def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(10) == False
assert is_prime(0) == False
assert is_prime(1) == False
assert is_prime(17) == True
def test_is_prime_list():
assert is_prim... | [
{
"docstring": "Helper function that checks if a number n is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list of booleans where each boolean indicates if the corresponding number in the input list is p... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 =... | trial_gpt4o_6 | {
"original_instruction": "Write a function that receives a list of integers and returns a list of booleans where each boolean represents if the corresponding integer in the input list is a prime number.\n\nThe input to the function will be a list of positive integers.\n\nFor example:\n\n is_prime_list([2, 3, 4, 5... | 0.873395 | Apps_1027 | C | [
"is_prime",
"is_prime_list"
] | 2 | [
[
"is_prime_list",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 73b9038ed70605a823f61bed36b4438db7a26139 | 4e96e917ae3d37628f237f9e949c0f6c487de21e | |||
v1.0 | complete | Apps | Apps_1151_C | from typing import List, Tuple
def minimum_cost_to_connect_all_cities(n: int, edges: List[Tuple[int, int, int]]) -> int:
""" Determine the minimum total cost required to connect all cities in the kingdom.
The function takes the number of cities (n) and a list of possible roads (edges) where each road is a tupl... | def find(parent, i):
if parent[i] == i:
return i
return find(parent, parent[i])
def union(parent, rank, x, y):
xroot = find(parent, x)
yroot = find(parent, y)
if rank[xroot] < rank[yroot]:
parent[xroot] = yroot
elif rank[xroot] > rank[yroot]:
parent[yroot] = xroot
... | from solution import minimum_cost_to_connect_all_cities
def test_sample_input():
edges = [
(1, 2, 5),
(1, 3, 10),
(1, 4, 6),
(2, 3, 15),
(3, 4, 4)
]
assert minimum_cost_to_connect_all_cities(4, edges) == 15
def test_disconnected_graph():
edges = []
assert mi... | [
{
"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,
1,
0,
0,
0,
0,
0,
0,
0
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "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 xroot = find(parent, x)\n ... | trial_gpt4o_0 | {
"original_instruction": "A kingdom, driven by the need to strengthen its defenses, has decided to build a network of roads to connect all its cities. The king has tasked his engineers with constructing the network in a way that minimizes the total cost while ensuring that all cities are connected.\n\nThe engineers ... | 0.677262 | Apps_1151 | C | [
"find",
"union",
"kruskal",
"minimum_cost_to_connect_all_cities"
] | 4 | [
[
"kruskal",
"find"
],
[
"kruskal",
"union"
],
[
"minimum_cost_to_connect_all_cities",
"kruskal"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | f8894618101a838e4c99cf5b832d9a68fd491e80 | 17e76b15d97477821459be7ef49e36ba16e5fce5 | |||
v1.0 | complete | Apps | Apps_559_C | import math
import heapq
from typing import List, Tuple
def calc_distance(x1: int, y1: int, x2: int, y2: int) -> float:
""" Calculate the Euclidean distance between two points (x1, y1) and (x2, y2).
>>> calc_distance(0, 0, 3, 4)
5.0
>>> calc_distance(1, 1, 1, 1)
0.0
"""
pass
def minimum_ca... | import math
import heapq
def calc_distance(x1, y1, x2, y2):
return math.sqrt((x1 - x2)**2 + (y1 - y2)**2)
def minimum_cable_length(n, tower_status, cities):
# Using Prim's algorithm to calculate the Minimum Spanning Tree (MST)
# List to check if the city is already in the MST or not
in_mst = [Fal... | from solution import calc_distance, minimum_cable_length, solve_telecom_coverage
def test_calc_distance():
assert calc_distance(0, 0, 3, 4) == 5.0
assert calc_distance(1, 1, 1, 1) == 0.0
assert calc_distance(-1, -1, 1, 1) == math.sqrt(8)
def test_minimum_cable_length():
n = 3
tower_status = "100"
... | [
{
"docstring": null,
"function_declaration": "def calc_distance(x1, y1, x2, y2):",
"function_name": "calc_distance",
"parameter_list": "(x1, y1, x2, y2)"
},
{
"docstring": null,
"function_declaration": "def minimum_cable_length(n, tower_status, cities):",
"function_name": "minimum_ca... | [
0,
0,
1,
0,
0,
0,
0,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\nimport heapq\n\ndef min_cable_length(T, test_cases):\n results = []\n\n def distance(p1, p2):\n return math.sqrt((p1[0] - p2[0]) ** 2 + (p... | trial_gpt4o_2 | {
"original_instruction": "In a certain country, there are n cities connected by roads. Each city can be represented as a point on a 2D plane with coordinates (x, y). Some cities have established telecom towers while others do not. The goal is to provide telecom coverage to all the cities using the shortest possible ... | 0.605852 | Apps_559 | C | [
"calc_distance",
"minimum_cable_length",
"solve_telecom_coverage",
"main"
] | 4 | [
[
"minimum_cable_length",
"calc_distance"
],
[
"solve_telecom_coverage",
"minimum_cable_length"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 59f9ab019d41146a01722cc48f84f3f562c97103 | c264a2772d64bf9b68ddf6228a2e04be22faee0b | |||
v1.0 | complete | Apps | Apps_1113_C | from typing import List
def is_prime(n: int) -> bool:
""" Helper function to check if a number is prime. """
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return False
... | def is_prime(n):
"""
Helper function to check if a number is prime.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return False
return True
def filter_primes... | from solution import filter_primes
def test_filter_primes_all_primes():
assert filter_primes([2, 3, 5, 7, 11, 13]) == [2, 3, 5, 7, 11, 13]
def test_filter_primes_no_primes():
assert filter_primes([1, 4, 6, 8, 10, 12]) == []
def test_filter_primes_mixed():
assert filter_primes([1, 2, 4, 5, 6, 7, 8, 9, 10,... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a new list containing only the prime numbers from the original list.",
"function_declaration": "def... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Helper function to check if a given number n is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n ... | trial_gpt4o_8 | {
"original_instruction": "Create a function that takes a list of integers and returns a new list containing only the prime numbers from the original list in the same order.\n\nThe input list will always contain at least one integer, and you do not need to account for different data types.",
"prompt_id": "00001113"... | 0.757126 | Apps_1113 | C | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 53c38ee101d7eec49e4795f6618f138e1cd41d65 | ccd1a7dcc02a1c49a2cf569221158df95176d99e | |||
v1.0 | complete | Apps | Apps_1838_C | def reverse_words(sentence: str) -> str:
"""
This function takes a string which represents a sentence and returns a new string with
each word reversed but the word order intact, maintaining the initial capitalization
position for each character after reversing the words.
>>> reverse_words("Hel... | def reverse_word(word):
"""
This helper function takes a single word and returns the word reversed.
It maintains the initial capitalization position for each character after reversing the word.
"""
n = len(word)
new_word = [''] * n
for i, ch in enumerate(word):
if ch.isupper():
... | from solution import reverse_words
def test_reverse_words_single_word():
assert reverse_words("Hello") == "olleH"
assert reverse_words("WORLD") == "DLROW"
assert reverse_words("pYtHoN") == "NoHtYp"
def test_reverse_words_multiple_words():
assert reverse_words("Hello World") == "olleH dlroW"
assert... | [
{
"docstring": "This helper function takes a single word and returns the word reversed.\nIt maintains the initial capitalization position for each character after reversing the word.",
"function_declaration": "def reverse_word(word):",
"function_name": "reverse_word",
"parameter_list": "(word)"
},... | [
0,
0,
0,
0,
1,
0,
0,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def reverse_words(sentence):\n \"\"\"\n Takes a string which represents a sentence and returns a new string with each word reversed \n but the word order i... | trial_gpt4o_4 | {
"original_instruction": "Write a function that takes a string which represents a sentence and returns a new string with each word reversed but the word order intact. The function should maintain any capital letters in their respective positions after reversing each word.\n\n## Examples\n\n```python\nreverse_words(\... | 0.751409 | Apps_1838 | C | [
"reverse_word",
"reverse_words"
] | 2 | [
[
"reverse_words",
"reverse_word"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b0b7e8d6a47b1dd5cede94deaa802f24b0dc8f4a | 35414450d23c8c63994b980d807cccb43eedfe69 | |||
v1.0 | complete | Apps | Apps_1110_C | def find_primes(start: int, end: int) -> list:
"""
Write a function that takes two integers, `start` and `end`, and returns a list of all prime numbers between `start` and `end` (inclusive). The function should ensure that both endpoints are included if they are prime. If no prime numbers exist in the range, re... | def is_prime(number):
"""
Helper function to check if a number is prime.
"""
if number <= 1:
return False
for i in range(2, int(number**0.5) + 1):
if number % i == 0:
return False
return True
def find_primes(start, end):
"""
Returns a list of all prime number... | from solution import find_primes
def test_primes_in_range():
assert find_primes(10, 30) == [11, 13, 17, 19, 23, 29]
def test_no_primes():
assert find_primes(14, 16) == []
assert find_primes(0, 1) == []
assert find_primes(4, 4) == []
def test_single_prime_range():
assert find_primes(2, 2) == [2]
... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(number):",
"function_name": "is_prime",
"parameter_list": "(number)"
},
{
"docstring": "Returns a list of all prime numbers between start and end (inclusive).",
"function_declaration": ... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return T... | trial_gpt4o_9 | {
"original_instruction": "Write a function that takes two integers, `start` and `end`, and returns a list of all prime numbers between `start` and `end` (inclusive). The function should ensure that both endpoints are included if they are prime. If no prime numbers exist in the range, return an empty list.\n\nPrime n... | 0.694973 | Apps_1110 | C | [
"is_prime",
"find_primes"
] | 2 | [
[
"find_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 63bc7b6ead8a70b0f0ed617a8de65c2486836e48 | 4cf0521206b53d64cadb2e33c9c0602d4a6ea0c6 | |||
v1.0 | complete | Apps | Apps_1729_C | def is_prime(n: int) -> bool:
""" Check if a number is prime.
"""
pass
def is_palindrome(n: int) -> bool:
""" Check if a number is a palindrome.
"""
pass
def next_prime_palindrome(n: int) -> int:
""" Write a function that takes an integer as input and returns the next prime palindrome grea... | def is_prime(n):
if n < 2:
return False
if n in (2, 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 is_palindrome(n):
return str(n) ==... | from solution import next_prime_palindrome
def test_next_prime_palindrome():
assert next_prime_palindrome(31) == 101
assert next_prime_palindrome(101) == 131
assert next_prime_palindrome(131) == 151
assert next_prime_palindrome(151) == 181
assert next_prime_palindrome(181) == 191
def test_next_pri... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def is_palindrome(n):",
"function_name": "is_palindrome",
"parameter_list": "(n)"
},
{
"docstring": null,... | [
1,
0,
1,
1,
0,
1,
1,
0,
0,
0
] | 5 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"Returns True if n is a prime number, otherwise False.\"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n... | trial_gpt4o_5 | {
"original_instruction": "Write a function that takes an integer as input and returns the next prime palindrome greater than the given integer. A prime palindrome is a number that is both a prime number and a palindrome. For example, the next prime palindrome after 31 is 101. If the input number itself is a prime pa... | 0.732168 | Apps_1729 | C | [
"is_prime",
"is_palindrome",
"next_prime_palindrome"
] | 3 | [
[
"next_prime_palindrome",
"is_palindrome"
],
[
"next_prime_palindrome",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 222272bacab59a1729b9d686e6ebb1a5765837b0 | 1a66bb660f5a84a82d98dbfba0f7185036149719 | |||
v1.0 | complete | Apps | Apps_1266_C | def count_overlapping_segments(t: int, test_cases: List[Tuple[int, List[Tuple[int, int, int, int]]]]) -> List[int]:
"""
Determine the number of segments that overlap with any other segment.
Args:
t (int): the number of test cases.
test_cases (List[Tuple[int, List[Tuple[int, int, int, int]]]]):... | def count_overlapping_segments(t, test_cases):
results = []
for n, segments in test_cases:
overlaps = 0
visited = [False] * n
for i in range(n):
for j in range(i+1, n):
if is_overlapping(segments[i], segments[j]):
if not visited[i]:
... | from solution import count_overlapping_segments
def test_single_test_case():
t = 1
test_cases = [
(3, [(1, 2, 1, 4), (1, 3, 1, 5), (2, 2, 2, 4)])
]
assert count_overlapping_segments(t, test_cases) == [2]
def test_multiple_test_case():
t = 2
test_cases = [
(3, [(1, 2, 1, 4), (1,... | [
{
"docstring": null,
"function_declaration": "def count_overlapping_segments(t, test_cases):",
"function_name": "count_overlapping_segments",
"parameter_list": "(t, test_cases)"
},
{
"docstring": null,
"function_declaration": "def is_overlapping(seg1, seg2):",
"function_name": "is_ov... | [
0,
0,
0,
0,
0,
1,
0,
0,
0,
1
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def count_overlapping_segments(T, test_cases):\n \"\"\"\n Function to count the number of overlapping segments in each test case.\n \n Args:\n T : in... | trial_gpt4o_9 | {
"original_instruction": "You are given a series of segments represented as pairs of coordinates. Each segment is either vertical or horizontal. Your task is to determine the number of segments that overlap with any other segment.\n\nA segment is defined by its two endpoints (x1, y1) and (x2, y2). It is either verti... | 0.579779 | Apps_1266 | C | [
"count_overlapping_segments",
"is_overlapping"
] | 2 | [
[
"count_overlapping_segments",
"is_overlapping"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 64f2c24d5bce41bab9fe6f68fc02e0af8ef2305c | 12357c911fcec526e6daf3d2763770b90498a713 | |||
v1.0 | complete | Apps | Apps_1676_C | from typing import List, Tuple
def reconcile_products(db1: List[Tuple[int, str]], db2: List[Tuple[int, str]]) -> List[int]:
"""Reconcile discrepancies between two product databases based on product names.
For the purpose of this task, two product names are considered a match if their Levenshtein distance
... | from typing import List, Tuple
import numpy as np
def levenshtein_distance(a: str, b: str) -> int:
if a == b:
return 0
if len(a) < len(b):
a, b = b, a
previous_row = range(len(b) + 1)
for i, ca in enumerate(a):
current_row = [i + 1]
for j, cb in enumerate(b):
... | from solution import reconcile_products
def test_reconcile_products_exact_match():
db1 = [(1, "apple"), (2, "banana"), (3, "orange")]
db2 = [(4, "apple"), (5, "banana"), (6, "orange")]
assert reconcile_products(db1, db2) == [1, 2, 3]
def test_reconcile_products_typo_match():
db1 = [(1, "apple"), (2, "... | [
{
"docstring": null,
"function_declaration": "def levenshtein_distance(a, b):",
"function_name": "levenshtein_distance",
"parameter_list": "(a, b)"
},
{
"docstring": null,
"function_declaration": "def reconcile_products(db1, db2):",
"function_name": "reconcile_products",
"paramet... | [
0,
0,
0,
0,
0,
1,
0,
0,
0,
1
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from typing import List, Tuple\nimport itertools\n\ndef levenshtein_distance(s1: str, s2: str) -> int:\n if len(s1) < len(s2):\n return levenshtein_distan... | trial_gpt4o_9 | {
"original_instruction": "## Data Cleanup and Reconciler\n\nYou are given a list of product records from two different databases. Each record contains a product ID and a product name, and you need to reconcile discrepancies between these databases. Sometimes, two records from the two databases may represent the same... | 0.544922 | Apps_1676 | C | [
"levenshtein_distance",
"reconcile_products"
] | 2 | [
[
"reconcile_products",
"levenshtein_distance"
]
] | 1 | [] | false | [] | false | pytest | true | [
"numpy"
] | false | cc6009b495d94bc8c88d55ffd74fe97c281c00fa | f367a4d4d42f86ee16f2b520dc66489a65adcda6 | |||
v1.0 | complete | Apps | Apps_1712_C | def is_prime(n: int) -> bool:
"""Check if a number is prime.
>>> is_prime(2)
True
>>> is_prime(4)
False
"""
pass
def get_prime_numbers(lst: List[int]) -> List[int]:
"""
Returns a sublist containing only the prime numbers from the original list.
>>> get_prime_numbers([])
[]
... | 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 get_prime_numbers(lst):
"""
Return... | from solution import get_prime_numbers
def test_get_prime_numbers_empty_list():
assert get_prime_numbers([]) == []
def test_get_prime_numbers_no_primes():
assert get_prime_numbers([4, 6, 8, 9, 10, 12]) == []
def test_get_prime_numbers_all_primes():
assert get_prime_numbers([2, 3, 5, 7, 11]) == [2, 3, 5, ... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a sublist containing only the prime numbers from the original list.",
"function_declaration": "def get_prime_numbers(lst):",
"function_name... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef is_prime(n):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n ... | trial_gpt4o_9 | {
"original_instruction": "Write a function that takes a list of integers and returns a sublist containing only the prime numbers from the original list. \n\nA prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. For instance, 2, 3, and 5 are prime numbers, while 4 an... | 0.817438 | Apps_1712 | C | [
"is_prime",
"get_prime_numbers"
] | 2 | [
[
"get_prime_numbers",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a76a21c515b260c3eeb3af891670613d71db95c9 | c766838724c885bf3fe6e092d69e149c19363381 | |||
v1.0 | complete | Apps | Apps_1543_C | from typing import List
def merge(arr, left, mid, right):
""" Helper function to merge two sorted halves of an array.
Arguments:
arr : List[int] -- The input array containing two sorted halves.
left : int -- The starting index of the left half.
mid : int -- The ending index of the left half.
ri... | from typing import List
def merge(arr, left, mid, right):
n1 = mid - left + 1
n2 = right - mid
# Create temporary arrays
L = arr[left:left + n1]
R = arr[mid + 1:mid + 1 + n2]
i, j, k = 0, 0, left
while i < n1 and j < n2:
if L[i] <= R[j]:
arr[k] = L[i]
i += ... | from solution import iterative_merge_sort
def test_sorted_array():
arr = [1, 2, 3, 4, 5, 6, 7, 8]
sorted_arr = iterative_merge_sort(arr)
assert sorted_arr == [1, 2, 3, 4, 5, 6, 7, 8]
def test_reverse_sorted_array():
arr = [8, 7, 6, 5, 4, 3, 2, 1]
sorted_arr = iterative_merge_sort(arr)
assert s... | [
{
"docstring": null,
"function_declaration": "def merge(arr, left, mid, right):",
"function_name": "merge",
"parameter_list": "(arr, left, mid, right)"
},
{
"docstring": null,
"function_declaration": "def iterative_merge_sort(arr):",
"function_name": "iterative_merge_sort",
"para... | [
1,
1,
1,
1,
1,
1,
1,
1,
0,
1
] | 9 | easy | 0.9 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from typing import List\n\ndef merge(left: List[int], right: List[int]) -> List[int]:\n \"\"\"\n Merge two sorted arrays into one sorted array.\n \"\"\"\n ... | trial_gpt4o_7 | {
"original_instruction": "Given a sorting machine that can only handle sorting arrays of integers where the size of the array is a power of 2, write a function that:\n1. Takes an unsorted array with a length that is a power of 2.\n2. Efficiently sorts the array in ascending order by implementing an iterative merge s... | 0.629816 | Apps_1543 | C | [
"merge",
"iterative_merge_sort"
] | 2 | [
[
"iterative_merge_sort",
"merge"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e59c81c87ebaa4e9f310cc7fce239676eb70f9ba | c722bcc89bf07331b588ea174fcbb72e84d6b351 | |||
v1.0 | complete | Apps | Apps_984_C | def products_above_threshold(test_cases):
""" Given test cases consisting of product quantities and threshold queries,
determine the number of products that exceed each threshold.
Args:
test_cases (List[Tuple[int, List[int], int, List[int]]]): A list of test cases where each test case is a tup... | def products_above_threshold(test_cases):
results = []
for test_case in test_cases:
N, quantities, Q, queries = test_case
quantities.sort()
for threshold in queries:
count = len(quantities) - binary_search(quantities, threshold)
results.append(count)
... | from solution import parse_input, products_above_threshold, binary_search
def test_parse_input():
input_string = "1\n5\n10 20 15 5 30\n3\n10 15 25"
test_cases = parse_input(input_string)
assert test_cases == [(5, [10, 20, 15, 5, 30], 3, [10, 15, 25])]
def test_binary_search():
arr = [5, 10, 15, 20, 30... | [
{
"docstring": null,
"function_declaration": "def products_above_threshold(test_cases):",
"function_name": "products_above_threshold",
"parameter_list": "(test_cases)"
},
{
"docstring": null,
"function_declaration": "def binary_search(arr, x):",
"function_name": "binary_search",
... | [
1,
1,
0,
1,
1,
1,
0,
0,
1,
1
] | 7 | easy | 0.7 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def optimize_storage_for_queries(T, test_cases):\n results = []\n \n for i in range(T):\n N = test_cases[i]['N']\n quantities = test_cases[i]... | trial_gpt4o_8 | {
"original_instruction": "A large distribution company stores a vast array of products in its warehouses, each product identified by a SKU (Stock Keeping Unit) and stored in specific quantities. The management wants to optimize their storage by identifying products with quantities above a certain threshold quickly. ... | 0.61588 | Apps_984 | C | [
"products_above_threshold",
"binary_search",
"parse_input"
] | 3 | [
[
"products_above_threshold",
"binary_search"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | f84743f9ebd3acf25279a64bc20b639a7ddf3c98 | c09f313e1b40dcd55f076a7337bbd0bd4b4142f5 | |||
v1.0 | complete | Apps | Apps_1496_C | def is_prime(num: int) -> bool:
"""
Determines if a given number is a prime number.
A prime number (other than 1) has exactly two distinct positive divisors: 1 and itself.
>>> is_prime(1) == False
>>> is_prime(2) == True
>>> is_prime(3) == True
>>> is_prime(4) == False
>>> is_p... | def is_prime(num):
"""
Returns True if num is a prime number, otherwise False.
"""
if num < 2:
return False
for i in range(2, int(num**0.5) + 1):
if num % i == 0:
return False
return True
def filter_primes(numbers):
"""
Returns a list containing only the prim... | from solution import is_prime, filter_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(17) == True
assert is_prime(18) == False
def test_filter_primes_empty_list():
assert filter_primes... | [
{
"docstring": "Returns True if num is a prime number, otherwise False.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns a list containing only the prime numbers from the provided list.",
"function_declarati... | [
1,
1,
1,
0,
1,
1,
1,
1,
1,
1
] | 9 | easy | 0.9 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Helper function to determine if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n retu... | trial_gpt4o_9 | {
"original_instruction": "Write a function that accepts a list of integers and returns a new list containing only the prime numbers from the original list, in the same order that they appeared. \n\nTo determine if a number is prime, a prime number (other than 1) has exactly two distinct positive divisors: 1 and itse... | 0.784118 | Apps_1496 | C | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 62bd55d0f0d4eedd2be5adcd2ae3b0632e60cab8 | 71fed6d8953b0a71fb45f6bd0ca21a940c490574 | |||
v1.0 | complete | Apps | Apps_1567_C | def is_palindrome(s: str) -> bool:
""" Check if a given string s is a palindrome.
>>> is_palindrome("121")
True
>>> is_palindrome("123")
False
"""
pass
def count_palindromic_subarrays(arr: List[int]) -> int:
""" Count the number of palindromic subarrays in the given array of integers.
... | def is_palindrome(s):
"""
Check if a given string s is a palindrome.
"""
return s == s[::-1]
def count_palindromic_subarrays(arr):
"""
Count the number of palindromic subarrays in the given array of integers.
"""
n = len(arr)
count = 0
for i in range(n):
for j in ra... | from solution import is_palindrome, count_palindromic_subarrays, solve
def test_is_palindrome():
assert is_palindrome("121") == True
assert is_palindrome("123") == False
assert is_palindrome("1") == True
assert is_palindrome("1221") == True
assert is_palindrome("12321") == True
def test_count_pali... | [
{
"docstring": "Check if a given string s is a palindrome.",
"function_declaration": "def is_palindrome(s):",
"function_name": "is_palindrome",
"parameter_list": "(s)"
},
{
"docstring": "Count the number of palindromic subarrays in the given array of integers.",
"function_declaration": "... | [
1,
0,
0,
1,
1,
1,
1,
1,
1,
0
] | 7 | easy | 0.7 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindromic(number):\n \"\"\"\n Helper function to determine if a given number (as a string) is palindromic.\n \"\"\"\n return number == number[:... | trial_gpt4o_8 | {
"original_instruction": "Samuel is fascinated by palindromic numbers. A palindromic number is a number that remains the same when its digits are reversed. Samuel is interested in counting how many subarrays of an array are palindromic when treated as concatenated numbers.\n\nWrite a program to help Samuel find the ... | 0.685378 | Apps_1567 | C | [
"is_palindrome",
"count_palindromic_subarrays",
"solve"
] | 3 | [
[
"count_palindromic_subarrays",
"is_palindrome"
],
[
"solve",
"count_palindromic_subarrays"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | e7c0b29c65bb7b7a5ac00032a82264439052985d | 1254c6cd535b5a264e8d314d08bd39ccd80ae765 | |||
v1.0 | complete | Apps | Apps_1862_C | def generate_primes_up_to(n):
""" Returns a list of boolean values where the index is the number
and the value at that index is True if the number is prime. """
pass
def is_cyclic_prime(num, prime_sieve):
""" Checks if num is a cyclic prime by rotating its digits
and checking if all rotations are p... | def generate_primes_up_to(n):
"""
Returns a list of boolean values where the index is the number
and the value at that index is True if the number is prime.
"""
sieve = [True] * (n + 1)
sieve[0] = sieve[1] = False # 0 and 1 are not prime numbers
for start in range(2, int(n**0.5) + 1):
... | def test_generate_primes_up_to():
sieve = generate_primes_up_to(10)
assert sieve[2] is True
assert sieve[3] is True
assert sieve[4] is False
assert sieve[5] is True
assert sieve[7] is True
def test_is_cyclic_prime():
prime_sieve = generate_primes_up_to(1000)
assert is_cyclic_prime(197... | [
{
"docstring": "Returns a list of boolean values where the index is the number\nand the value at that index is True if the number is prime.",
"function_declaration": "def generate_primes_up_to(n):",
"function_name": "generate_primes_up_to",
"parameter_list": "(n)"
},
{
"docstring": "Checks i... | [
0,
0,
0,
0,
0,
0,
0,
1,
0
] | 1 | hard | 0.111 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def generate_primes(n):\n \"\"\"Generate a list of prime numbers up to n using the Sieve of Eratosthenes.\"\"\"\n sieve = [True] * (n + 1)\n sieve[0] = sie... | trial_gpt4o_8 | {
"original_instruction": "-----Problem Statement-----\nA \"super prime\" is a prime number that remains prime when its digits are cyclically rotated. For example, the prime number 197 remains prime (197, 719, 971) with each rotation of its digits, hence it is a super prime.\nIn this problem, given a positive integer... | 0.698215 | Apps_1862 | C | [
"generate_primes_up_to",
"is_cyclic_prime",
"count_super_primes_upto_n",
"super_primes"
] | 4 | [
[
"count_super_primes_upto_n",
"is_cyclic_prime"
],
[
"super_primes",
"count_super_primes_upto_n"
],
[
"super_primes",
"generate_primes_up_to"
]
] | 3 | [] | false | [] | false | pytest | false | [] | true | 11a3a53a979ac02f93d16dcd77682c6d5412a508 | 8b4c4d6229835d3d627afff399ff36788c4f69bf | |||
v1.0 | complete | Apps | Apps_1799_C | import math
from typing import List
def format_numbers(nums: List[int]) -> str:
""" Returns a formatted string where:
1. Numbers in the array that are perfect squares are replaced with the string "Square".
2. Numbers that are perfect cubes are replaced with the string "Cube".
3. Numbers that are both p... | import math
def is_perfect_square(n):
return int(math.sqrt(n)) ** 2 == n
def is_perfect_cube(n):
return int(round(n ** (1/3))) ** 3 == n
def format_numbers(nums):
results = []
for num in nums:
if is_perfect_square(num) and is_perfect_cube(num):
results.append("Square-Cube")
... | from solution import format_numbers
def test_single_element():
assert format_numbers([1]) == "Square-Cube"
assert format_numbers([4]) == "Square"
assert format_numbers([8]) == "Cube"
assert format_numbers([5]) == "5"
def test_multiple_elements():
assert format_numbers([1, 3, 4, 8, 9, 16, 27, 64, 8... | [
{
"docstring": null,
"function_declaration": "def is_perfect_square(n):",
"function_name": "is_perfect_square",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def is_perfect_cube(n):",
"function_name": "is_perfect_cube",
"parameter_list": "(n)"
},
{
... | [
0,
0,
1,
1,
0,
0,
1,
0,
0,
1
] | 4 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef format_numbers(nums):\n \"\"\"\n Format numbers replacing perfect squares with 'Square', perfect cubes\n with 'Cube', and numbers that a... | trial_gpt4o_9 | {
"original_instruction": "The task is to implement a function that helps in formatting list output as a string, where numbers that are perfect squares and perfect cubes are replaced by special strings. Given an integer array `nums`, return a formatted string where:\n\n1. Numbers in the array that are perfect squares... | 0.558102 | Apps_1799 | C | [
"is_perfect_square",
"is_perfect_cube",
"format_numbers"
] | 3 | [
[
"format_numbers",
"is_perfect_cube"
],
[
"format_numbers",
"is_perfect_square"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 7e894c4a9498528178e967bd762fbc93775e3058 | baeb6f6059d23b6bced2288a49edb38eccd6ef0a | |||
v1.0 | complete | Apps | Apps_2349_C | def harmonic_subarrays(T, cases):
""" Determine the number of harmonic subarrays in a list of integers.
>>> harmonic_subarrays(2, [(3, "2 3 1"), (4, "2 5 4 7")])
[2, 3]
>>> harmonic_subarrays(1, [(1, "1")])
[0]
""" | def is_prime(num):
"""
Determine if a number is prime.
"""
if num <= 1:
return False
if num == 2:
return True
if num % 2 == 0:
return False
p = 3
while p * p <= num:
if num % p == 0:
return False
p += 2
return True
def count_harmon... | from solution import harmonic_subarrays
def test_single_case():
# Basic test case
assert harmonic_subarrays(1, [
(3, "2 3 1")
]) == [2]
def test_multiple_cases():
# Multiple cases in one go
assert harmonic_subarrays(2, [
(3, "2 3 1"),
(4, "2 5 4 7")
]) == [2, 3]
def te... | [
{
"docstring": "Determine if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Count the number of harmonic subarrays.",
"function_declaration": "def count_harmonic_subarrays(N, A):",
"function... | [
0,
0,
0,
0,
0,
0,
1,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n re... | trial_gpt4o_6 | {
"original_instruction": "For an array of integers $A$, a subarray is a contiguous part of the array. Let the sum of a subarray $B$ be defined as $sum(B)$. A subarray $B$ is said to be a harmonic subarray if $sum(B) \\times \\text{length}(B)$ is a prime number.\n\nYou are given the task to determine how many harmoni... | 0.568183 | Apps_2349 | C | [
"is_prime",
"count_harmonic_subarrays",
"solve",
"harmonic_subarrays"
] | 4 | [
[
"count_harmonic_subarrays",
"is_prime"
],
[
"harmonic_subarrays",
"solve"
],
[
"solve",
"count_harmonic_subarrays"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 84d838e21209b5fd42a68bd6425692ecf425e71f | f56ca8e554bb88d498ff1d1691210d4af6592ebc | |||
v1.0 | complete | Apps | Apps_2001_C | def is_palindrome(num: int) -> bool:
"""Check if a number is a palindrome.
>>> is_palindrome(121)
True
>>> is_palindrome(123)
False
>>> is_palindrome(808)
True
"""
pass
def next_palindrome(n: int) -> int:
"""Find the smallest palindromic number greater than or equal to n.
>>... | def is_palindrome(num):
"""Check if a number is a palindrome."""
return str(num) == str(num)[::-1]
def next_palindrome(n):
"""Find the smallest palindromic number greater than or equal to n."""
while True:
if is_palindrome(n):
return n
n += 1
def find_nearest_palindromes(te... | from solution import is_palindrome, next_palindrome, find_nearest_palindromes
def test_is_palindrome():
assert is_palindrome(121) == True
assert is_palindrome(12321) == True
assert is_palindrome(123) == False
assert is_palindrome(808) == True
assert is_palindrome(10) == False
def test_next_palindr... | [
{
"docstring": "Check if a number is a palindrome.",
"function_declaration": "def is_palindrome(num):",
"function_name": "is_palindrome",
"parameter_list": "(num)"
},
{
"docstring": "Find the smallest palindromic number greater than or equal to n.",
"function_declaration": "def next_pali... | [
0,
0,
0,
1,
0,
1,
0,
1,
0
] | 3 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome(num):\n return str(num) == str(num)[::-1]\n\ndef nearest_palindrome(N):\n while not is_palindrome(N):\n N += 1\n return N\n\ndef s... | trial_gpt4o_8 | {
"original_instruction": "Sarah loves playing with numbers. Recently, she became interested in finding the nearest palindromic number for any given integer. A palindromic number is a number that reads the same forwards and backwards, like 121 or 5445. Given an integer N, Sarah wants to find the smallest palindromic ... | 0.742528 | Apps_2001 | C | [
"is_palindrome",
"next_palindrome",
"find_nearest_palindromes"
] | 3 | [
[
"find_nearest_palindromes",
"next_palindrome"
],
[
"next_palindrome",
"is_palindrome"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | c85739cc88ad7fa4565f2b68c9febfb7d1122603 | 81d086de50717de0d6d232d8972989f9ec255e43 | |||
v1.0 | complete | Apps | Apps_1921_C | class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
def is_symmetric(root):
"""Check if a binary tree is symmetric (mirror image of itself).
>>> is_symmetric(TreeNode(1).val == TreeNode(2).val == TreeNode(2).val == TreeNode(3).val == TreeNode(4).va... | class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
def is_symmetric(root):
if not root:
return True
def is_mirror(t1, t2):
if not t1 and not t2:
return True
if not t1 or not t2:
return False
... | def test_is_symmetric():
input_data = "2\n1 2 2 3 4 4 3\n1 2 2 N 3 N 3"
expected_output = "YES\nNO"
assert main(input_data) == expected_output
def test_single_node_tree():
input_data = "1\n1"
expected_output = "YES"
assert main(input_data) == expected_output
def test_asymmetric_tree():
inp... | [] | [
0,
1,
0,
0,
0,
0,
1,
0,
1
] | 3 | medium | 0.333 | {
"trial_gpt4o_0": null,
"trial_gpt4o_1": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared1_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.righ... | trial_gpt4o_9 | {
"original_instruction": "Alex is studying binary trees and is particularly interested in the concept of \"symmetric trees.\" A binary tree is said to be symmetric if it is a mirror image of itself.\n\nYour task is to help Alex implement a function to check if a given binary tree is symmetric.\n\n-----Input:-----\n-... | 0.631571 | Apps_1921 | C | [
"is_symmetric",
"build_tree",
"check_symmetric_trees",
"main"
] | 4 | [
[
"check_symmetric_trees",
"build_tree"
],
[
"check_symmetric_trees",
"is_symmetric"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | false | [] | true | eadfad6cec9038f231beffd9ac72b067cfd2206c | 943f27f1ae574aa5b35221ac050f4e3417b459f7 | |||
v1.0 | complete | Apps | Apps_1912_C | def cycle_detection(test_cases: List[Tuple[int, int, List[Tuple[int, int]]]]) -> List[bool]:
""" Given an undirected graph with `n` vertices and `m` edges, check if there is a cycle in the graph.
If a cycle exists, return `True`. Otherwise, return `False`.
Parameters:
test_cases (List[Tuple[int, in... | def is_cyclic_dfs(graph, vertex, visited, parent):
visited[vertex] = True
for neighbor in graph[vertex]:
if not visited[neighbor]:
if is_cyclic_dfs(graph, neighbor, visited, vertex):
return True
elif neighbor != parent:
return True
return False
def ha... | import pytest
from solution import cycle_detection
def test_cycle_detection_example_1():
test_cases = [
(3, 3, [(1, 2), (2, 3), (3, 1)]),
]
assert cycle_detection(test_cases) == [True]
def test_cycle_detection_example_2():
test_cases = [
(4, 3, [(1, 2), (2, 3), (3, 4)]),
]
asse... | [
{
"docstring": null,
"function_declaration": "def is_cyclic_dfs(graph, vertex, visited, parent):",
"function_name": "is_cyclic_dfs",
"parameter_list": "(graph, vertex, visited, parent)"
},
{
"docstring": null,
"function_declaration": "def has_cycle(n, edges):",
"function_name": "has_... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def has_cycle(n, edges):\n \"\"\"\n Check if an undirected graph has a cycle.\n :param n: Number of vertices\n :param edges: List of tuples representing... | trial_gpt4o_9 | {
"original_instruction": "Given an undirected graph with `n` vertices and `m` edges, you need to check if there is a cycle in the graph. If a cycle exists, return `True`. Otherwise, return `False`.\n\n-----Input-----\nThe first line of the input contains an integer `T` denoting the number of test cases. The descript... | 0.632557 | Apps_1912 | C | [
"is_cyclic_dfs",
"has_cycle",
"cycle_detection"
] | 3 | [
[
"cycle_detection",
"has_cycle"
],
[
"has_cycle",
"is_cyclic_dfs"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | ad91925bcbe75c22c9998d9c66e331918750da13 | 5ba3240e42beef673701bff8b2088d3b2900a7ae | |||
v1.0 | complete | Apps | Apps_1051_C | from typing import List
def alternate_capitalization(title: str) -> str:
""" Capitalizes alternate words in a given title, starting with the first word.
Args:
title (str): The book title as a string of words separated by spaces.
Returns:
str: The title with alternate words capitalized.
>>... | def alternate_capitalization(title):
words = title.split()
formatted_words = [word.capitalize() if i % 2 == 0 else word.lower() for i, word in enumerate(words)]
return ' '.join(formatted_words)
def format_books(titles):
sorted_titles = sorted(titles)
formatted_titles = [alternate_capitalization(tit... | from solution import format_books, alternate_capitalization
def test_alternate_capitalization():
assert alternate_capitalization("the great gatsby") == "The great Gatsby"
assert alternate_capitalization("to kill a mockingbird") == "To kill A mockingbird"
assert alternate_capitalization("pride and prejudice... | [
{
"docstring": null,
"function_declaration": "def alternate_capitalization(title):",
"function_name": "alternate_capitalization",
"parameter_list": "(title)"
},
{
"docstring": null,
"function_declaration": "def format_books(titles):",
"function_name": "format_books",
"parameter_l... | [
1,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def alternate_capitalization(title):\n words = title.split()\n formatted_words = [word.capitalize() if i % 2 == 0 else word.lower() for i, word in enumerate(w... | trial_gpt4o_0 | {
"original_instruction": "Sarah loves to organize her bookshelf. She has a list of book titles and she wants to sort them alphabetically. However, she prefers to see the book titles in a way that each alternate word in the title is capitalized, starting from the first word. Write a function that takes a list of book... | 0.518866 | Apps_1051 | C | [
"alternate_capitalization",
"format_books"
] | 2 | [
[
"format_books",
"alternate_capitalization"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5b07155f28819d4fc84e9c4e2b818d2af9fc0592 | 10d6c165f23c3241928e994cf75d026eaf7942f2 | |||
v1.0 | complete | Apps | Apps_1409_C | def count_words(s: str) -> dict:
"""Counts the frequency of each word in a given string, ignoring case.
Args:
s: str - The input string.
Returns:
dict - A dictionary where the keys are words and the values are their counts.
Examples:
>>> count_words("")
{}
>>> cou... | def count_words(s):
"""
Counts the frequency of each word in a given string, ignoring case.
Args:
s: str - The input string.
Returns:
dict - A dictionary where the keys are words and the values are their counts.
"""
words = s.lower().split()
word_count = {}
for word in ... | import pytest
from solution import count_words, most_common_word
def test_count_words_empty_string():
assert count_words("") == {}
def test_count_words_single_word():
assert count_words("hello") == {"hello": 1}
def test_count_words_multiple_words():
assert count_words("hello world hello") == {"hello": 2,... | [
{
"docstring": "Counts the frequency of each word in a given string, ignoring case.\n\nArgs:\ns: str - The input string.\n\nReturns:\ndict - A dictionary where the keys are words and the values are their counts.",
"function_declaration": "def count_words(s):",
"function_name": "count_words",
"parame... | [
1,
1,
1,
1,
1,
0,
1,
1,
1,
0
] | 8 | easy | 0.8 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def count_words(s):\n \"\"\"\n Counts the frequency of each word in a given string.\n\n Parameters:\n s (str): The input string.\n\n Returns:\n di... | trial_gpt4o_6 | {
"original_instruction": "**Step 1:** Create a function called `count_words()` that counts the frequency of each word in a given string and returns a dictionary where the keys are the words and the values are the counts. Assume that words are separated by spaces and are case-insensitive.\n\nFor example, `count_words... | 0.735831 | Apps_1409 | C | [
"count_words",
"most_common_word"
] | 2 | [
[
"most_common_word",
"count_words"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d2a5d10662c732c31d43631b1461e2b5f7466ab6 | 2ac9995e014680fa74fc6351bbbfebee274773b8 | |||
v1.0 | complete | Apps | Apps_2157_C | def is_prime(n: int) -> bool:
""" Returns True if n is a prime number, otherwise False.
>>> is_prime(2)
True
>>> is_prime(3)
True
>>> is_prime(4)
False
>>> is_prime(5)
True
"""
def sum_of_primes(numbers: List[int]) -> int:
""" Returns the sum of all prime numbers in the inpu... | def is_prime(n):
"""
Returns True if n is a prime number, otherwise False.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return False
return True
def sum_of... | from solution import is_prime, sum_of_primes
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(11) == True
assert is_prime(1) == False
assert is_prime(0) == False
assert is_prime(-1) == False... | [
{
"docstring": "Returns True if n is a prime number, otherwise False.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns the sum of all prime numbers in the input list `numbers`.",
"function_declaration": "def sum... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Determine if the number is prime.\n \"\"\"\n if n <= 1:\n return False\n for i in range(2, int(n**0.5) + 1):\n ... | trial_gpt4o_9 | {
"original_instruction": "Implement a function that takes a list of integers and returns the sum of the elements that are prime numbers. You may utilize a helper function to determine if a number is prime.\n\nA prime number is defined as a number greater than 1 that has no positive divisors other than 1 and itself.\... | 0.772145 | Apps_2157 | C | [
"is_prime",
"sum_of_primes"
] | 2 | [
[
"sum_of_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 02c9b68792d461e263bb279b51e505f505d167c6 | 7cf1cf1659072e0ec75605fd6396173fbcbc781a | |||
v1.0 | complete | Apps | Apps_1794_C | def is_palindrome(n: int) -> bool:
"""Check if a number is a palindrome.
>>> is_palindrome(121)
True
>>> is_palindrome(123)
False
"""
# your code here
def steps_to_palindrome(n: int) -> int:
"""Returns the number of steps required to transform the number into a palindrome,
or -1 if ... | def is_palindrome(n):
"""
Check if a number is a palindrome.
"""
return str(n) == str(n)[::-1]
def steps_to_palindrome(n):
"""
Returns the number of steps required to transform the number into a palindrome.
Returns -1 if it does not become a palindrome within 1000 steps.
"""
steps =... | from solution import steps_to_palindrome
def test_palindrome_cases():
assert steps_to_palindrome(87) == 4
assert steps_to_palindrome(56) == 1
assert steps_to_palindrome(11) == 0
def test_no_palindrome_within_1000_steps():
assert steps_to_palindrome(89) == 24 # Known to reach palindrome in 24 steps
... | [
{
"docstring": "Check if a number is a palindrome.",
"function_declaration": "def is_palindrome(n):",
"function_name": "is_palindrome",
"parameter_list": "(n)"
},
{
"docstring": "Returns the number of steps required to transform the number into a palindrome.\nReturns -1 if it does not become... | [
0,
0,
0,
0,
0,
0,
0,
0,
1,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome(n):\n \"\"\"\n Check if a number is palindrome.\n \"\"\"\n return str(n) == str(n)[::-1]\n\ndef steps_to_palindrome(n, max_steps=1000)... | trial_gpt4o_8 | {
"original_instruction": "## Palindrome Chains\n\nGiven a number, determine the number of steps required to transform it into a palindrome. At each step, add the number to its reverse. If the resulting number is a palindrome, stop. Otherwise, repeat the process with the new number.\n\n# Task\nCreate a function that ... | 0.694052 | Apps_1794 | C | [
"is_palindrome",
"steps_to_palindrome"
] | 2 | [
[
"steps_to_palindrome",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 82cea3b1211223fce7717ac32ad000927b2b2b26 | 46cd8f45e951905fd0ef8aa4fbaab4c8a68decec | |||
v1.0 | complete | Apps | Apps_1932_C | from typing import List, Tuple
def shortest_route(points: List[Tuple[int, int]]) -> List[Tuple[int, int]]:
""" Return the shortest route that starts from the origin point (0, 0),
visits each delivery point exactly once, and then returns to the origin.
Example:
>>> shortest_route([])
[(0, 0), ... | from itertools import permutations
from math import sqrt
def euclidean_distance(p1, p2):
return sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2)
def total_distance(route):
total = 0
for i in range(len(route) - 1):
total += euclidean_distance(route[i], route[i+1])
return total
def shortest_ro... | from solution import shortest_route
def test_no_points():
assert shortest_route([]) == [(0, 0), (0, 0)]
def test_single_point():
assert shortest_route([(1, 2)]) == [(0, 0), (1, 2), (0, 0)]
def test_two_points():
route = shortest_route([(1, 2), (3, 4)])
assert route[0] == (0, 0)
assert set(route[1... | [
{
"docstring": null,
"function_declaration": "def euclidean_distance(p1, p2):",
"function_name": "euclidean_distance",
"parameter_list": "(p1, p2)"
},
{
"docstring": null,
"function_declaration": "def total_distance(route):",
"function_name": "total_distance",
"parameter_list": "... | [
1,
1,
1,
0,
1,
1,
1,
1,
0,
1
] | 8 | easy | 0.8 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from itertools import permutations\nfrom math import sqrt\n\ndef euclidean_distance(p1, p2):\n return sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2)\n\ndef to... | trial_gpt4o_9 | {
"original_instruction": "You are a software engineer tasked with implementing functionality in a logistics application. One of the features to develop is a route optimizer for delivery trucks.\n\nWrite a function that takes a list of delivery points, where each point is represented as a tuple of integers (x, y). Th... | 0.6582 | Apps_1932 | C | [
"euclidean_distance",
"total_distance",
"shortest_route"
] | 3 | [
[
"shortest_route",
"total_distance"
],
[
"total_distance",
"euclidean_distance"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 441f58ac2a03ee07ee143b36f30fb9beb7bc7c70 | 6ec7c9c728c882aa82665bb81b3fa97771d5675e | |||
v1.0 | complete | Apps | Apps_1308_C | def filter_primes(lst):
"""
Takes a list of integers and returns a new list containing all the prime numbers
from the original list, in the order they appeared.
"""
# Your code here
def is_prime(n):
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 =... | 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 filter_primes(lst):
"""
Takes a li... | def test_filter_primes():
assert filter_primes([2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == [2, 3, 5, 7, 11]
assert filter_primes([4, 6, 8, 9, 10]) == []
assert filter_primes([]) == []
assert filter_primes([-10, -5, 0, 1, 19, 23]) == [19, 23]
assert filter_primes([11, 18, 19, 21, 23, 29]) == [11, 19, 23, 29... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Takes a list of integers and returns a new list containing all the prime numbers \nfrom the original list, in the order they appeared.",
"function_decl... | [
1,
1,
1,
1,
0,
1,
1,
1,
1
] | 8 | easy | 0.889 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n return False\n i = 5\n ... | trial_gpt4o_0 | {
"original_instruction": "Write function that takes a list of integers and returns a new list containing all the prime numbers from the original list, in the order they appeared. Use the helper function provided to determine if a number is prime.\n\n### Helper Function\nThe helper function `is_prime` takes an intege... | 0.730489 | Apps_1308 | C | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | d1f475b6a1a19659484f391abc967d343ca17895 | d4c311f1cf711aa36ac3de2be8d1a0da072cfcf6 | |||
v1.0 | complete | Apps | Apps_2508_C | from typing import List
def sum_of_primes(numbers: List[int]) -> int:
"""
Create a function that takes a list of integers and returns the sum of all prime numbers in the list.
If there are no prime numbers in the list, the function should return 0.
Remember, a prime number is a natural number greate... | from typing import List
def is_prime(n: int) -> bool:
"""
Check if a number is prime.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return False
return True... | from solution import sum_of_primes
def test_sum_of_primes_with_only_primes():
assert sum_of_primes([2, 3, 5, 7]) == 17
def test_sum_of_primes_with_no_primes():
assert sum_of_primes([1, 4, 6, 8, 9, 10]) == 0
def test_sum_of_primes_with_mixed_numbers():
assert sum_of_primes([2, 3, 4, 5, 6]) == 10
def test... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns the sum of all prime numbers in the list.",
"function_declaration": "def sum_of_primes(numbers):",
"function_name"... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from typing import List\n\ndef is_prime(n: int) -> bool:\n \"\"\"\n Checks if a number is a prime number.\n \"\"\"\n if n <= 1:\n return False\n ... | trial_gpt4o_9 | {
"original_instruction": "Create a function that takes a list of integers and returns the sum of all prime numbers in the list. If there are no prime numbers in the list, the function should return 0. \n\nRemember, a prime number is a natural number greater than 1 that has no positive divisors other than 1 and itsel... | 0.692452 | Apps_2508 | C | [
"is_prime",
"sum_of_primes"
] | 2 | [
[
"sum_of_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 9aa8f4b7f4ea92931aa6e1662cdfddce9ba2b957 | 517e33b626fdf37777c046e8e097de29d543d9b8 | |||
v1.0 | complete | Apps | Apps_1959_C | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def max_power_of_two_path_sum(root: TreeNode) -> int:
"""
Returns the maximum sum of values along any path from the root to a leaf
considering only the node valu... | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def is_power_of_two(x):
"""
Helper function to determine if a number is a power of two.
"""
return (x & (x - 1) == 0) and x != 0
def max_power_of_two_path_su... | from solution import max_power_of_two_path_sum, TreeNode
def test_empty_tree():
assert max_power_of_two_path_sum(None) == 0
def test_single_node_tree():
assert max_power_of_two_path_sum(TreeNode(8)) == 8
assert max_power_of_two_path_sum(TreeNode(10)) == 0
def test_mixed_tree():
root = TreeNode(5, Tre... | [] | [
0,
0,
1,
0,
0,
0,
0,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "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 max_powe... | trial_gpt4o_2 | {
"original_instruction": "Polycarp likes playing with binary trees and powers of two. He has a binary tree and he wants to maximize the sum of values in the nodes along any path from the root to any leaf. Additionally, Polycarp can only include values that are powers of two (e.g., 1, 2, 4, 8, 16, etc.) in his sum.\n... | 0.560231 | Apps_1959 | C | [
"is_power_of_two",
"max_power_of_two_path_sum"
] | 2 | [
[
"max_power_of_two_path_sum",
"is_power_of_two"
]
] | 1 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 1562c2f92e1879d18e48213f3c961c02c13eac9d | 13ddc77d5f39add1702dce9586cbb941aeea8285 | |||
v1.0 | complete | Apps | Apps_2610_C | def generate_valid_grid(n: int) -> List[List[int]]:
""" Generates an n x n grid with unique row and column sums where the sum of all row sums is equal to the sum of all column sums.
>>> generate_valid_grid(3)
[[9, 2, 4],
[7, 5, 1],
[3, 8, 6]]
>>> generate_valid_grid(2)
[[1, 4],
[3, 2... | import random
def generate_grid(n):
"""
Generates an n x n grid with unique row and column sums and an equal sum
of all row sums to all column sums.
"""
numbers = list(range(1, n * n + 1))
random.shuffle(numbers)
grid = [[0] * n for _ in range(n)]
for i in range(n):
for j ... | from solution import generate_valid_grid, check_unique_sums
def test_generate_valid_grid_3():
n = 3
grid = generate_valid_grid(n)
assert check_unique_sums(grid) == True
def test_generate_valid_grid_2():
n = 2
grid = generate_valid_grid(n)
assert check_unique_sums(grid) == True
def test_genera... | [
{
"docstring": "Generates an n x n grid with unique row and column sums and an equal sum\nof all row sums to all column sums.",
"function_declaration": "def generate_grid(n):",
"function_name": "generate_grid",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def ... | [
1,
0,
0,
0,
1,
0,
1,
1,
0,
0
] | 4 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def construct_grid(n):\n \"\"\"\n Constructs an n x n grid where each row and column sums are unique \n and the sum of all row sums equals the sum of all c... | trial_gpt4o_6 | {
"original_instruction": "A game consists of placing n distinct integers on an n x n grid, such that each integer from 1 to n^2 appears exactly once. Your task is to create such an arrangement following specific rules for row and column sums.\n\nThe sum of all integers in each row must be unique and the sum of all i... | 0.62702 | Apps_2610 | C | [
"generate_grid",
"check_unique_sums",
"fix_grid",
"generate_valid_grid"
] | 4 | [
[
"fix_grid",
"check_unique_sums"
],
[
"fix_grid",
"generate_grid"
],
[
"generate_valid_grid",
"fix_grid"
],
[
"generate_valid_grid",
"generate_grid"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | 716cad5e792bd56389fba12a135b5a3a20e0f56c | 416c9f134df095be171f60c7c3ea2ff88b123b80 | |||
v1.0 | complete | Apps | Apps_998_C | from typing import List, Tuple
def shortest_paths(n: int, roads: List[Tuple[int, int, int]], queries: List[Tuple[int, int]]) -> List[int]:
"""
Find the shortest paths in a virtual city from one city to another. The function should return
a list of shortest path lengths for each query.
Args:
... | import heapq
def dijkstra(graph, start, n):
distances = [float('inf')] * (n + 1)
distances[start] = 0
priority_queue = [(0, start)]
while priority_queue:
current_distance, current_city = heapq.heappop(priority_queue)
if current_distance > distances[current_city]:
continue
... | def test_example_case():
n = 5
roads = [
(1, 2, 3),
(1, 3, 5),
(2, 3, 2),
(3, 4, 4),
(2, 4, 6),
(4, 5, 1)
]
queries = [
(1, 5),
(2, 4),
(3, 1)
]
expected_output = [10, 6, 5]
assert shortest_paths(n, roads, queries) == ex... | [
{
"docstring": null,
"function_declaration": "def dijkstra(graph, start, n):",
"function_name": "dijkstra",
"parameter_list": "(graph, start, n)"
},
{
"docstring": null,
"function_declaration": "def shortest_paths(n, roads, queries):",
"function_name": "shortest_paths",
"paramete... | [
1,
0,
1,
1,
1,
1,
0,
1,
1,
1
] | 8 | easy | 0.8 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef dijkstra(graph, start, n):\n distances = [float('inf')] * (n + 1)\n distances[start] = 0\n priority_queue = [(0, start)]\n \n whi... | trial_gpt4o_9 | {
"original_instruction": "In a world of virtual cities, there are N cities connected by M bidirectional roads. Each road has a length associated with it. The task is to help travelers find the shortest path from one city to another, given that they have a list of travel queries.\n\n-----Input-----\n- The first line ... | 0.747701 | Apps_998 | C | [
"dijkstra",
"shortest_paths"
] | 2 | [
[
"shortest_paths",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 35cb69fb2f4dbb894ae454dfca46189e66f7d9df | b229b4d853277bad51bfba970f6a04e5a4a094e3 | |||
v1.0 | complete | Apps | Apps_2484_C | def can_arrange_flowers(N: int, intervals: List[Tuple[int, int]]) -> bool:
"""
Determine if it's possible to arrange flowers such that there is always
at least one flower blooming at any given time from the earliest blooming
time to the latest wilting time.
Args:
N (int): Number of flowers.
... | def can_arrange_flowers(N, intervals):
"""
Determine if it's possible to arrange flowers such that there is always
at least one flower blooming at any given time from the earliest blooming
time to the latest wilting time.
Parameters:
N (int): Number of flowers.
intervals (list): List ... | from solution import can_arrange_flowers, flowers_blooming_possible
def test_single_flower():
assert can_arrange_flowers(1, [(1, 5)]) == True
def test_overlapping_periods():
assert can_arrange_flowers(3, [(1, 4), (5, 8), (2, 6)]) == True
def test_non_overlapping_periods():
assert can_arrange_flowers(3, [... | [
{
"docstring": "Determine if it's possible to arrange flowers such that there is always \nat least one flower blooming at any given time from the earliest blooming \ntime to the latest wilting time.\n\nParameters:\nN (int): Number of flowers.\nintervals (list): List of tuples containing blooming and wilting tim... | [
0,
0,
0,
0,
0,
0,
0,
1,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_possible_to_keep_continuous_blooming(flowers):\n \"\"\"\n Determines if it is possible to arrange flowers so that there is always at least one flower b... | trial_gpt4o_7 | {
"original_instruction": "In a distant land, there exist mystical flowers that bloom in a magical garden. Each flower has a unique blooming time and wilting time. The garden keeper wants to arrange them in such a way that there is always at least one flower blooming at any given time.\n\nYour task is to find out if ... | 0.547 | Apps_2484 | C | [
"can_arrange_flowers",
"flowers_blooming_possible"
] | 2 | [
[
"flowers_blooming_possible",
"can_arrange_flowers"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8fe2695e174814003d7dfaa35f6aef638f46cf52 | 3093327c20f40907bb70a1d1f44154b2c05ebeb5 | |||
v1.0 | complete | Apps | Apps_2321_C | from typing import List
def filter_primes(arr: List[int]) -> List[int]:
""" Returns a new array containing only the prime numbers from the original array.
>>> filter_primes([4, 6, 8, 9, 10]) == []
>>> filter_primes([2, 3, 5, 7, 11]) == [2, 3, 5, 7, 11]
>>> filter_primes([2, 4, 5, 6, 7, 10]) == [2, 5, 7... | def is_prime(n):
"""
Checks if a number is prime.
"""
if n <= 1:
return False
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
return True
def filter_primes(arr):
"""
Returns a new array containing only the prime numbers from the original array... | from solution import filter_primes
def test_no_primes():
assert filter_primes([4, 6, 8, 9, 10]) == []
def test_all_primes():
assert filter_primes([2, 3, 5, 7, 11]) == [2, 3, 5, 7, 11]
def test_mixed_numbers():
assert filter_primes([2, 4, 5, 6, 7, 10]) == [2, 5, 7]
def test_including_negative_numbers():
... | [
{
"docstring": "Checks if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a new array containing only the prime numbers from the original array.",
"function_declaration": "def filter_primes(a... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Checks if a number n is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n ... | trial_gpt4o_9 | {
"original_instruction": "Write a function that takes an array of integers and returns a new array containing only the prime numbers from the original array, in the same order.",
"prompt_id": "00002321",
"row_id": 2321,
"seed_ids": "[4222]"
} | 0.65097 | Apps_2321 | C | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ca0e0aa6683c2f192f1d9e0d889af4ca3f38ab67 | 06f6528dddbd0d428a8c93b153823a99ad75418f | |||
v1.0 | complete | Apps | Apps_1356_C | from typing import List
def maximalRectangle(grid: List[List[int]]) -> int:
"""
Given an MxN grid representing a rectangular farm where 0 indicates an empty cell
and 1 indicates a tree, find the largest rectangle containing only 0s.
>>>
>>>
"""
def largestRectangleArea(heights: List[int]) ->... | def maximalRectangle(grid):
if not grid:
return 0
M, N = len(grid), len(grid[0])
height = [0] * N
max_area = 0
for row in grid:
for i in range(N):
height[i] = height[i] + 1 if row[i] == 0 else 0
max_area = max(max_area, largestRectangleArea(height))
return... | import pytest
from solution import main
def test_example1():
input_string = "2\n4 4\n0 1 0 0\n0 0 0 1\n1 0 0 0\n1 1 1 0\n3 3\n1 1 1\n1 0 0\n1 0 0"
expected_output = "4\n4"
assert main(input_string) == expected_output
def test_single_row():
input_string = "1\n1 5\n0 0 1 0 0"
expected_output = "2"
... | [
{
"docstring": null,
"function_declaration": "def maximalRectangle(grid):",
"function_name": "maximalRectangle",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def largestRectangleArea(heights):",
"function_name": "largestRectangleArea",
"parameter_li... | [
0,
1,
1,
1,
1,
1,
1,
0,
1,
0
] | 7 | easy | 0.7 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def maximalRectangle(matrix):\n if not matrix:\n return 0\n\n max_area = 0\n row = len(matrix)\n col = len(matrix[0])\n \n heights = [0] * ... | trial_gpt4o_2 | {
"original_instruction": "Farmer John has a rectangular farm with $M$ rows and $N$ columns, represented by a 2D grid. Each cell in the grid can either be empty (denoted by a 0) or have a tree (denoted by a 1). \n\nFarmer John wants to maximize the area of a rectangular plot of land he can clear without moving any tr... | 0.544354 | Apps_1356 | C | [
"maximalRectangle",
"largestRectangleArea",
"process_test_cases",
"parse_input",
"format_output",
"main"
] | 6 | [
[
"maximalRectangle",
"largestRectangleArea"
],
[
"process_test_cases",
"maximalRectangle"
]
] | 2 | [
"process_test_cases",
"parse_input",
"format_output"
] | false | [] | false | pytest | true | [] | true | 16c771360785aa79e0b9e75a58d7688b7f4740cd | 9a343f54be80532bd9d23a607ef747828e69d828 | |||
v1.0 | complete | Apps | Apps_2370_C | def dna_to_rna(dna_sequence: str) -> str:
""" Converts a DNA sequence to an RNA sequence by replacing all occurrences of 'T' with 'U'.
If the DNA sequence contains invalid characters, returns None.
>>> dna_to_rna("ACGTACGT") "ACGUACGU"
>>> dna_to_rna("ACGTACGX") None
>>> dna_to_rna("") ""
>>> dn... | def dna_to_rna(dna_sequence):
"""
Converts a DNA sequence to an RNA sequence by replacing all occurrences of 'T' with 'U'.
If the DNA sequence contains invalid characters, returns None.
"""
valid_bases = {'A', 'C', 'G', 'T'}
if not validate_dna(dna_sequence):
return None
return dna_s... | from solution import dna_to_rna, validate_dna
def test_dna_to_rna_valid_sequence():
assert dna_to_rna("ACGTACGT") == "ACGUACGU"
def test_dna_to_rna_invalid_sequence():
assert dna_to_rna("ACGTACGX") == None
def test_dna_to_rna_empty_sequence():
assert dna_to_rna("") == ""
def test_dna_to_rna_all_valid_ba... | [
{
"docstring": "Converts a DNA sequence to an RNA sequence by replacing all occurrences of 'T' with 'U'.\nIf the DNA sequence contains invalid characters, returns None.",
"function_declaration": "def dna_to_rna(dna_sequence):",
"function_name": "dna_to_rna",
"parameter_list": "(dna_sequence)"
},
... | [
1,
1,
1,
0,
1,
1,
1,
1,
1,
1
] | 9 | easy | 0.9 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def dna_to_rna(dna_sequence):\n \"\"\"\n Converts a DNA sequence to a RNA sequence by replacing 'T' with 'U'.\n Returns None if there are invalid character... | trial_gpt4o_9 | {
"original_instruction": "A team of biologists is working on a project to identify and classify DNA sequences. They decide to develop a small utility to help them convert DNA sequences into corresponding RNA sequences and to validate DNA sequences for any invalid characters.\n\nDNA sequences are composed of the base... | 0.586293 | Apps_2370 | C | [
"dna_to_rna",
"validate_dna"
] | 2 | [
[
"dna_to_rna",
"validate_dna"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a2ca35217904834ba41d8ab8a5350fc61e689f00 | 3a3ef73856ac39f9dc4f55a314ca88c37427d954 | |||
v1.0 | complete | Apps | Apps_2414_C | def is_prime(n):
"""Check if a number is prime."""
if n <= 1:
return False
if n == 2 or n == 3:
return True
if n % 2 == 0:
return False
for i in range(3, int(n ** 0.5) + 1, 2):
if n % i == 0:
return False
return True
def sum_of_powers_and_prime_check(... | def is_prime(n):
"""Check if a number is prime."""
if n <= 1:
return False
if n == 2 or n == 3:
return True
if n % 2 == 0:
return False
for i in range(3, int(n ** 0.5) + 1, 2):
if n % i == 0:
return False
return True
def sum_of_powers_and_prime_check(... | from solution import sum_of_powers_and_prime_check
def test_edge_cases():
assert sum_of_powers_and_prime_check("1") == False
assert sum_of_powers_and_prime_check("2") == True
assert sum_of_powers_and_prime_check("0") == False
def test_known_cases():
assert sum_of_powers_and_prime_check("123") == False... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Calculate the sum of digits raised to the power of their positions.\nCheck if the resulting sum is a prime number.",
"function... | [
0,
0,
0,
1,
0,
0,
0,
1,
1,
0
] | 3 | hard | 0.3 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n return False\n \n for i in range(3, i... | trial_gpt4o_8 | {
"original_instruction": "Write a function to calculate the sum of digits of a given number string raised to the power of their respective positions (with the leftmost digit having a position value of 1). The sum should then be checked if it is a prime number. If it is, return true; otherwise, return false.\n\nA pri... | 0.811692 | Apps_2414 | C | [
"is_prime",
"sum_of_powers_and_prime_check"
] | 2 | [
[
"sum_of_powers_and_prime_check",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 21358fa60f57e53580777a77d8edd480c6e823ee | ef46e6fce97104eb616fdcd2c94fd69e5e6a85b2 | |||
v1.0 | complete | Apps | Apps_2450_C | from typing import List, Tuple
def solve(n: int, values: List[int], edges: List[Tuple[int, int]]) -> List[int]:
""" Calculate the sum of values of nodes along the path from the root node to each node in a binary tree.
>>> solve(5, [1, 2, 3, 4, 5], [(1, 2), (1, 3), (2, 4), (2, 5)])
[1, 3, 4, 7, 8]
>>> s... | def path_sums(n, values, edges):
from collections import defaultdict, deque
# Create adjacency list
tree = defaultdict(list)
for u, v in edges:
tree[u].append(v)
tree[v].append(u)
# Initialize sum array with None
path_sum = [None] * (n + 1)
path_sum[1] = values[0]
# BF... | from solution import solve
def test_example_1():
n = 5
values = [1, 2, 3, 4, 5]
edges = [(1, 2), (1, 3), (2, 4), (2, 5)]
expected = [1, 3, 4, 7, 8]
result = solve(n, values, edges)
assert result == expected
def test_example_2():
n = 3
values = [2, 1, 4]
edges = [(1, 2), (1, 3)]
... | [
{
"docstring": null,
"function_declaration": "def path_sums(n, values, edges):",
"function_name": "path_sums",
"parameter_list": "(n, values, edges)"
},
{
"docstring": null,
"function_declaration": "def solve(n, values, edges):",
"function_name": "solve",
"parameter_list": "(n, v... | [
0,
0,
0,
1,
1,
1,
1,
1,
1,
1
] | 7 | easy | 0.7 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def tree_path_sums(n, values, edges):\n from collections import defaultdict, deque\n \n tree = defaultdict(list)\n for u, v in edges:\n tree[u].a... | trial_gpt4o_8 | {
"original_instruction": "Zara is a botanist who loves studying tree growth patterns.\n\nOne day she was observing a specific type of tree, which can be represented as a binary tree with nodes numbered from $1$ to $n$. In this tree, each node can have at most two children.\n\nZara wants to gather information about t... | 0.666625 | Apps_2450 | C | [
"path_sums",
"solve"
] | 2 | [
[
"solve",
"path_sums"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 13b8cc901b1adb2af0becb66dec778be3d918d44 | 9a961fa4a4d9b4320db30a9dcf84bf21a305ef70 | |||
v1.0 | complete | Apps | Apps_1488_C | def distinct_squared_sorted(arr):
"""
This function takes a list of integers, computes the number of distinct integers,
and returns a sorted list of their squared values.
:param arr: List[int] - List of integers.
:return: (int, List[int]) - Number of distinct integers and list of squared value... | def distinct_squared_sorted(arr):
"""
This function takes a list of integers, computes the number of distinct integers,
and returns a sorted list of their squared values.
:param arr: List[int] - List of integers.
:return: (int, List[int]) - Number of distinct integers and list of squared value... | def test_distinct_squared_sorted_example_case():
arr = [1, -2, 3, -2, 4]
expected_count = 4
expected_squares = [1, 4, 9, 16]
assert distinct_squared_sorted(arr) == (expected_count, expected_squares)
def test_distinct_squared_sorted_single_element():
arr = [5]
expected_count = 1
expected_squ... | [
{
"docstring": "This function takes a list of integers, computes the number of distinct integers, \nand returns a sorted list of their squared values.\n\n:param arr: List[int] - List of integers.\n:return: (int, List[int]) - Number of distinct integers and list of squared values sorted.",
"function_declarat... | [
1,
0,
0,
0,
0,
0,
0,
1,
0,
0
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def distinct_squared_sorted(arr):\n \"\"\"\n This function takes a list of integers, computes the number of distinct integers, \n and returns a sorted list... | trial_gpt4o_0 | {
"original_instruction": "=====Problem Statement=====\nYou are given a list of integers. Your task is to compute and print the number of distinct integers in the list and then to output the squared value of each distinct integer, sorted in ascending order.\n\n=====Constraints=====\n1 ≤ n ≤ 10^4\n-10^4 ≤ integer valu... | 0.646927 | Apps_1488 | C | [
"distinct_squared_sorted",
"format_output",
"process_integers"
] | 3 | [
[
"process_integers",
"distinct_squared_sorted"
],
[
"process_integers",
"format_output"
]
] | 2 | [
"format_output"
] | false | [] | false | pytest | false | [] | true | 532b38ed229ac7bab613c636bc92cb87c02f7254 | b09d109cd1fda2ec556c2d522fa67a3b9cf669ae | |||
v1.0 | complete | Apps | Apps_2523_C | def is_prime(n):
"""Check if a number is prime.
>>> is_prime(2)
True
>>> is_prime(4)
False
"""
def digit_sum(n):
"""Return the sum of the digits of a number.
>>> digit_sum(34)
7
>>> digit_sum(123)
6
"""
def fibonacci(n):
"""Generate the first n Fibonacci numbers.
... | def is_prime(n):
"""Check 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) == 0:
return False
i += 6
return True
def digi... | 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(18) == False
def test_digit_sum():
assert digit_sum(123) == 6
assert digit_sum(34) == 7
assert digit_sum(500) == 5
assert digit_sum(0) =... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Return the sum of the digits of a number.",
"function_declaration": "def digit_sum(n):",
"function_name": "digit_sum",
... | [
0,
0,
0,
0,
0,
1,
0,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if n < 2:\n return False\n if n == 2:\n return True\n if n % 2 ==... | trial_gpt4o_5 | {
"original_instruction": "You are given a sequence of Fibonacci numbers: `0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ...`. Notice that `0` is in position `one`. \n\nA Fibonacci number is called a **\"special Fibonacci\"** if it is even and the sum of its digits is a prime number. For example:\n- `2` is in positio... | 0.827244 | Apps_2523 | C | [
"is_prime",
"digit_sum",
"fibonacci",
"sum_special_fibonacci"
] | 4 | [
[
"sum_special_fibonacci",
"digit_sum"
],
[
"sum_special_fibonacci",
"fibonacci"
],
[
"sum_special_fibonacci",
"is_prime"
]
] | 3 | [] | false | [] | false | pytest | false | [] | true | 07401088000f032042724b3ad9ea10e4d605cbea | b933a6a8a42d6fdad4600e6a05d14fe0a7fd613c | |||
v1.0 | complete | Apps | Apps_2054_C | from typing import List, Tuple
def find_overlaps(events: List[Tuple[str, str, str, str]]) -> List[str]:
""" Analyzes a list of employee check-ins to identify any employees who have overlapping or conflicting check-ins.
Args:
events (List[Tuple[str, str, str, str]]): A list of tuples where each tuple c... | from collections import defaultdict
from datetime import datetime
def parse_time(t):
return datetime.strptime(t, "%H:%M")
def find_overlaps(events):
employee_events = defaultdict(list)
for event in events:
employee_id, room_id, start_time, end_time = event
start_time = parse_time(star... | from solution import find_overlaps
def test_no_overlaps():
events = [
("E1", "Room1", "09:00", "10:00"),
("E2", "Room1", "10:00", "11:00"),
("E3", "Room2", "11:00", "12:00")
]
assert find_overlaps(events) == []
def test_single_employee_overlap():
events = [
("E1", "Room... | [
{
"docstring": null,
"function_declaration": "def parse_time(t):",
"function_name": "parse_time",
"parameter_list": "(t)"
},
{
"docstring": null,
"function_declaration": "def find_overlaps(events):",
"function_name": "find_overlaps",
"parameter_list": "(events)"
}
] | [
0,
1,
1,
1,
1,
0,
1,
1,
1,
1
] | 8 | easy | 0.8 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_overlaps(events):\n from collections import defaultdict\n\n def parse_time(time_str):\n hours, minutes = map(int, time_str.split(':'))\n ... | trial_gpt4o_9 | {
"original_instruction": "A digital office building uses a smart lock system to manage room access, driven by a schedule of employee check-ins. Every employee has a unique ID and check-in time. The system keeps track of the people inside each room and ensures that a single employee cannot occupy two different rooms ... | 0.587112 | Apps_2054 | C | [
"parse_time",
"find_overlaps"
] | 2 | [
[
"find_overlaps",
"parse_time"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7f08ebcfb338dc8687e5cfc22f53b2027d7136aa | d891e38e942d7385f102f88303c720c6f535e5d2 | |||
v1.0 | complete | Apps | Apps_1672_C | def can_make_all_cells_equal(grid):
"""
Determine if it's possible to make all cells of the grid equal using the given operation.
:param grid: The grid of integers.
:return: "YES" if it's possible to make all cells equal, "NO" otherwise.
>>> can_make_all_cells_equal([[1, 2, 3], [2, 3, 4], [3, 4, 5]]... | def can_make_all_cells_equal(grid):
N = len(grid)
M = len(grid[0])
target = grid[0][0]
for row in grid:
for value in row:
if value != target:
return "NO"
return "YES"
def solve(test_cases):
results = []
for grid in test_cases:
... | def test_valid_all_equal():
input_data = "1\n2 2\n1 1\n1 1"
expected_output = "YES"
assert main(input_data) == expected_output
def test_valid_single_row():
input_data = "1\n1 3\n1 1 1"
expected_output = "YES"
assert main(input_data) == expected_output
def test_valid_single_column():
in... | [
{
"docstring": null,
"function_declaration": "def can_make_all_cells_equal(grid):",
"function_name": "can_make_all_cells_equal",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def solve(test_cases):",
"function_name": "solve",
"parameter_list": "(test... | [
0,
0,
0,
1,
0,
0,
0,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def can_make_all_cells_equal(grid):\n max_value = max(max(row) for row in grid)\n for row in grid:\n for cell in row:\n if cell < max_value:... | trial_gpt4o_3 | {
"original_instruction": "You are given a grid with $N$ rows and $M$ columns. Each cell of the grid contains an integer. You are allowed to perform a certain operation any number of times: select a sub-grid, in which all values on the border are greater than or equal to the values inside the sub-grid, then increase ... | 0.665258 | Apps_1672 | C | [
"can_make_all_cells_equal",
"solve",
"read_input",
"main"
] | 4 | [
[
"solve",
"can_make_all_cells_equal"
]
] | 1 | [
"read_input"
] | false | [] | false | pytest | false | [] | true | 97e365e78dff3910213a5dcee1b69066dc44fdcc | f574a95b281203f84534563b97f6d2325cec91aa | |||
v1.0 | complete | Apps | Apps_2796_C | def calculate_ascii_score(user_id: str) -> int:
"""
Calculate the ASCII score of a user ID by summing the ASCII values of all characters in the user ID.
>>> calculate_ascii_score("A3B")
182
>>> calculate_ascii_score("a")
97
"""
pass
def find_highest_score_user(ids: List[str]) -> List[s... | def calculate_ascii_score(user_id):
"""
Calculate the ASCII score of a user ID by summing ASCII values of all characters.
"""
return sum(ord(char) for char in user_id)
def find_highest_score_user(ids):
"""
Given a list of user IDs, find the one(s) with the highest ASCII value score.
"""
... | from solution import calculate_ascii_score, find_highest_score_user
def test_calculate_ascii_score():
assert calculate_ascii_score("A3B") == 182
assert calculate_ascii_score("a") == 97
assert calculate_ascii_score("1") == 49
assert calculate_ascii_score("AB") == 131
def test_find_highest_score_user_si... | [
{
"docstring": "Calculate the ASCII score of a user ID by summing ASCII values of all characters.",
"function_declaration": "def calculate_ascii_score(user_id):",
"function_name": "calculate_ascii_score",
"parameter_list": "(user_id)"
},
{
"docstring": "Given a list of user IDs, find the one... | [
0,
0,
0,
0,
0,
0,
1,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def calculate_score(user_id):\n \"\"\"\n Calculates the score for a given user ID by summing the ASCII values of its characters.\n \"\"\"\n return sum(o... | trial_gpt4o_6 | {
"original_instruction": "Note: This question carries $150$ points.\nThe city of Algorithmsville is organizing a coding competition, and they have a very unique scoring system. They want to assign scores to the participants based on their user ID which is a combination of letters and digits. The score is calculated ... | 0.651639 | Apps_2796 | C | [
"calculate_ascii_score",
"find_highest_score_user"
] | 2 | [
[
"find_highest_score_user",
"calculate_ascii_score"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 77ebf3dd4794e52f7392de18317fe1df3f17ab0b | c0d066a77faecab3efd9b4c0b8263572b17ba0cd | |||
v1.0 | complete | Apps | Apps_2805_C | def is_prime(n: int) -> bool:
"""
Helper function to determine if a number is prime.
"""
# Your implementation
def filter_primes(lst: list) -> list:
"""
Takes a list of integers as input and returns a list of prime numbers.
If the input is not a list, returns "Please enter a valid list".
... | def is_prime(n):
"""
Helper function to determine if a number is prime.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
max_divisor = int(n**0.5) + 1
for d in range(3, max_divisor, 2):
if n % d == 0:
return False
... | from solution import filter_primes
def test_non_list_input():
assert filter_primes("12345") == "Please enter a valid list"
assert filter_primes(12345) == "Please enter a valid list"
assert filter_primes(None) == "Please enter a valid list"
assert filter_primes(123.45) == "Please enter a valid list"
de... | [
{
"docstring": "Helper function to determine if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Takes a list of integers and returns a list of prime numbers.\nIf the input is not a list, returns \"Please... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Helper function to determine if a given number is prime.\n \"\"\"\n if n <= 1:\n return False\n for i in range(2, ... | trial_gpt4o_7 | {
"original_instruction": "Create a function that takes a list of integers as input and returns a new list containing only the elements that are prime numbers. A prime number is a number that has no divisors other than 1 and itself. If the input is not a list, return \"Please enter a valid list\". If the input list c... | 0.799858 | Apps_2805 | C | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e18a8ca08fc7cff0c756456c11857d4737d0de6b | 2762732205b0e5a36d753941841f7791e212bc38 | |||
v1.0 | complete | Apps | Apps_2491_C | def minimal_path_sum(grid):
"""
Given a 2D grid of integers, find the minimal path sum from the top-left corner to the bottom-right corner,
where you can only move either right or down.
>>> minimal_path_sum([[1, 3, 1], [1, 5, 1], [4, 2, 1]])
7
>>> minimal_path_sum([[1, 2], [1, 1]])
3
""... | def minimal_path_sum(grid):
"""
Given a 2D grid of integers, find the minimal path sum from the top-left corner to the bottom-right corner,
where you can only move either right or down.
"""
n = len(grid)
dp = [[0] * n for _ in range(n)]
dp[0][0] = grid[0][0]
# Initialize the first r... | from solution import minimal_path_sum, solve_minimal_path_sum, parse_input
def test_minimal_path_sum_basic():
grid = [
[1, 3, 1],
[1, 5, 1],
[4, 2, 1]
]
assert minimal_path_sum(grid) == 7
def test_minimal_path_sum_two_by_two():
grid = [
[1, 2],
[1, 1]
]
... | [
{
"docstring": "Given a 2D grid of integers, find the minimal path sum from the top-left corner to the bottom-right corner,\nwhere you can only move either right or down.",
"function_declaration": "def minimal_path_sum(grid):",
"function_name": "minimal_path_sum",
"parameter_list": "(grid)"
},
{... | [
0,
0,
0,
1,
0,
1,
0,
0,
1,
0
] | 3 | hard | 0.3 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def minimal_path_sum(T, test_cases):\n \"\"\"\n This function computes the minimal path sum from top-left to bottom-right\n in a grid for each test case.\n... | trial_gpt4o_8 | {
"original_instruction": "You are given an n x n grid where each cell contains an integer. You are required to start at the top-left corner of the grid and move to the bottom-right corner. From each cell, you can move either right or down to the next cell. You want to find the minimal path sum from the top-left corn... | 0.712323 | Apps_2491 | C | [
"minimal_path_sum",
"solve_minimal_path_sum",
"parse_input"
] | 3 | [
[
"solve_minimal_path_sum",
"minimal_path_sum"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 4d3f14ff060c61e1d98c4d4cb3c38a8b9be55e49 | e081d544d135ed959bae8f4348280890320d8332 | |||
v1.0 | complete | Apps | Apps_2681_C | from collections import deque
from typing import List
def is_one_letter_diff(word1: str, word2: str) -> bool:
"""
Determines if word1 and word2 differ by exactly one letter.
"""
diff_count = sum(1 for a, b in zip(word1, word2) if a != b)
return diff_count == 1
def shortest_transformation_sequence(... | from collections import deque
def is_one_letter_diff(word1, word2):
"""
Determines if word1 and word2 differ by exactly one letter.
"""
diff_count = sum(1 for a, b in zip(word1, word2) if a != b)
return diff_count == 1
def shortest_transformation_sequence(S, D):
"""
Returns the shortest tr... | from solution import shortest_transformation_sequence
def test_shortest_transformation_sequence_example1():
assert shortest_transformation_sequence("hit", ["hot", "dot", "dog", "lot", "log", "cog"]) == 1
def test_shortest_transformation_sequence_example2():
assert shortest_transformation_sequence("lead", ["lo... | [
{
"docstring": "Determines if word1 and word2 differ by exactly one letter.",
"function_declaration": "def is_one_letter_diff(word1, word2):",
"function_name": "is_one_letter_diff",
"parameter_list": "(word1, word2)"
},
{
"docstring": "Returns the shortest transformation sequence from S to a... | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
1
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef shortest_transformation_sequence(S, D):\n \"\"\"\n Returns the length of the shortest transformation sequence from S to a... | trial_gpt4o_9 | {
"original_instruction": "Given a string S consisting of lowercase letters and a dictionary D of words, return the shortest transformation sequence from S to a word in D that changes only one character at a time. Each transformed string must exist in the dictionary.\n\nExample 1:\nInput: \nS = \"hit\", \nD = [\"hot\... | 0.639621 | Apps_2681 | C | [
"is_one_letter_diff",
"shortest_transformation_sequence"
] | 2 | [
[
"shortest_transformation_sequence",
"is_one_letter_diff"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c78ab57821e4cf815b3aafeccbb07da77f208520 | b52fa87e170eecdb4c0665ce106482af36e78105 | |||
v1.0 | complete | Apps | Apps_2640_C | def min_transport_hubs(n: int, m: int, k: int, roads: List[Tuple[int, int]]) -> int:
""" Determine the least number of transport hubs required to ensure that the travel time between any two cities is no more than k hours after the transport hubs are built.
>>> min_transport_hubs(4, 3, 2, [(1, 2), (2, 3), (3, 4)... | from collections import deque
def bfs_shortest_path(graph, start, n):
"""
Perform BFS to find the shortest path from start to all other vertices in an unweighted graph.
"""
visited = [False] * (n + 1)
distance = [float('inf')] * (n + 1)
queue = deque([start])
visited[start] = True
... | def test_min_transport_hubs_example1():
assert min_transport_hubs(4, 3, 2, [(1, 2), (2, 3), (3, 4)]) == 1
def test_min_transport_hubs_example2():
assert min_transport_hubs(5, 5, 2, [(1, 2), (2, 3), (3, 4), (4, 5), (5, 1)]) == 0
def test_min_transport_hubs_example3():
assert min_transport_hubs(6, 5, 1, [(1... | [
{
"docstring": "Perform BFS to find the shortest path from start to all other vertices in an unweighted graph.",
"function_declaration": "def bfs_shortest_path(graph, start, n):",
"function_name": "bfs_shortest_path",
"parameter_list": "(graph, start, n)"
},
{
"docstring": null,
"functio... | [
0,
0,
1,
0,
1,
0,
1,
1,
0,
0
] | 4 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef min_transport_hubs(n, m, k, roads):\n def dijkstra(graph, start):\n distances = {city: float('inf') for city in range(1, n + 1)}\n ... | trial_gpt4o_6 | {
"original_instruction": "In a certain country, there are exactly n cities and m bidirectional roads connecting these cities. The cities are numbered with integers from 1 to n. If there is a road between cities a and b, you can travel that road in either direction in exactly one hour. The government plans to build s... | 0.709798 | Apps_2640 | C | [
"bfs_shortest_path",
"min_transport_hubs"
] | 2 | [
[
"min_transport_hubs",
"bfs_shortest_path"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | fe25b1f2527caac21a008bb619c79ffe99b87a37 | 8ddd49f90bc04a52246b2a19cdb9365985dbe056 | |||
v1.0 | complete | Apps | Apps_3034_C | def is_prime(num):
"""
Returns True if num is a prime number.
"""
pass
def product_of_primes(n):
"""
Returns the product of all prime numbers less than or equal to n.
>>> product_of_primes(10)
210
>>> product_of_primes(5)
30
>>> product_of_primes(2)
2
>>> product_of... | def is_prime(num):
"""
Returns True if num is a prime number.
"""
if num <= 1:
return False
for i in range(2, int(num**0.5) + 1):
if num % i == 0:
return False
return True
def product_of_primes(n):
"""
Returns the product of all prime numbers less than or equ... | from solution import is_prime, product_of_primes
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(1) == False
def test_product_of_primes():
assert product_of_primes(10) == 210
assert product_of... | [
{
"docstring": "Returns True if num is a prime number.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns the product of all prime numbers less than or equal to n.",
"function_declaration": "def product_of_pri... | [
1,
1,
0,
1,
0,
1,
1,
1,
0,
0
] | 6 | medium | 0.6 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n for i in range(2, int(nu... | trial_gpt4o_7 | {
"original_instruction": "# Task\nGiven an integer `n`, return the product of all the prime numbers less than or equal to `n`.\n\n# Example\n\nFor `n = 10`, the result should be `210`\n\nSince `2 * 3 * 5 * 7 = 210`\n\nFor `n = 5`, the result should be `30`\n\nSince `2 * 3 * 5 = 30`\n\nFor `n = 2`, the result should ... | 0.852852 | Apps_3034 | C | [
"is_prime",
"product_of_primes"
] | 2 | [
[
"product_of_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 77b01c73531aec4ec9c473ae68eb1940e0e87cd0 | 0079b962c3d8885b18821546ab874e9fd740dcf8 | |||
v1.0 | complete | Apps | Apps_2341_C | def maximum_non_conflicting_road_length(n: int, m: int, edges: List[Tuple[int, int, int, int]]) -> int:
""" Determine the maximum length of any colored road that does not result in a town having roads of the same color meeting at it.
>>> maximum_non_conflicting_road_length(4, 5, [(1, 2, 4, 1), (1, 3, 3, 2), (2... | class UnionFind:
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)
... | def test_maximum_non_conflicting_road_length():
# Test case 1
roads = [
(1, 2, 4, 1),
(1, 3, 3, 2),
(2, 4, 2, 1),
(3, 4, 5, 1),
(1, 4, 8, 2)
]
assert maximum_non_conflicting_road_length(4, 5, roads) == 8
# Test case 2
roads = [
(1, 2, 10, 1),
... | [] | [
1,
0,
1,
0,
0,
0,
0,
0,
1
] | 3 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict\n\ndef get_max_road_length(n, m, roads):\n def is_valid(town_roads, last_edge):\n for road in town_roads:\n ... | trial_gpt4o_9 | {
"original_instruction": "There are N towns connected by M bidirectional roads. Each road has a specific length and a color. A town mayor wants to ensure that the roads in the town form a connected graph where no two roads of the same color meet at the same town.\nYou need to help the mayor determine the maximum len... | 0.677151 | Apps_2341 | C | [
"max_road_length",
"maximum_non_conflicting_road_length"
] | 2 | [
[
"maximum_non_conflicting_road_length",
"max_road_length"
]
] | 1 | [] | false | [
"UnionFind"
] | true | pytest | false | [] | true | 5ab013af5f2f8d50f402add825693969333dda30 | 27d394f97ca0c71127030427fb8148ea6fdc82cb | |||
v1.0 | complete | Apps | Apps_2959_C | def splitArray(nums: List[int], k: int) -> int:
""" Partition the array into k contiguous subarrays such that the largest sum among these subarrays is minimized.
Args:
nums (List[int]): A list of positive integers.
k (int): The number of subarrays.
Returns:
int: The minimized largest s... | def can_split(nums, k, max_sum):
"""
Helper function to determine if it's possible to split the array
into k or fewer parts with all parts having sums not exceeding max_sum.
"""
current_sum = 0
required_splits = 1
for num in nums:
if current_sum + num <= max_sum:
cur... | from solution import splitArray
def test_example_case():
nums = [7, 2, 5, 10, 8]
k = 2
assert splitArray(nums, k) == 18
def test_small_case():
nums = [1, 2, 3, 4, 5]
k = 2
assert splitArray(nums, k) == 9
def test_single_element_array():
nums = [10]
k = 1
assert splitArray(nums, k)... | [
{
"docstring": "Helper function to determine if it's possible to split the array\ninto k or fewer parts with all parts having sums not exceeding max_sum.",
"function_declaration": "def can_split(nums, k, max_sum):",
"function_name": "can_split",
"parameter_list": "(nums, k, max_sum)"
},
{
"d... | [
0,
1,
1,
1,
1,
1,
1,
0,
1,
0
] | 7 | easy | 0.7 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def minimize_largest_sum(nums, k):\n def can_split(nums, k, max_sum):\n subarray_sum = 0\n subarray_count = 1\n \n for num in nums:\n... | trial_gpt4o_8 | {
"original_instruction": "Given an array of positive integers and an integer k, write a function that partitions the array into k contiguous subarrays (subsequences) such that the largest sum among these subarrays is minimized. Your function should return this minimized largest sum.\n\nExample:\n\nGiven array nums =... | 0.752392 | Apps_2959 | C | [
"can_split",
"splitArray"
] | 2 | [
[
"splitArray",
"can_split"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a084fe120e00edb2ceb11b63c81bf2a5692c9f46 | b99cd14df79003b258fee6f3aa7e4849ebed0ba3 | |||
v1.0 | complete | Apps | Apps_2384_C | def generate_seating_patterns(T, test_cases):
"""
Generates the seating patterns for multiple test cases.
Parameters:
T (int): The number of test cases.
test_cases (List[int]): A list containing the number of rows for each test case.
Returns:
str: A string representing the seating ... | def generate_seating_pattern(n):
"""
Returns the seating arrangement pattern for N rows.
"""
pattern = []
for i in range(1, n+1):
pattern.append('#' * i)
return pattern
def generate_patterns_for_test_cases(test_cases):
"""
Given a list of test cases, generates seating patterns f... | from solution import generate_seating_patterns
def test_case_1():
T = 3
test_cases = [2, 3, 4]
expected_output = "#\n##\n\n#\n##\n###\n\n#\n##\n###\n####"
assert generate_seating_patterns(T, test_cases) == expected_output
def test_case_2():
T = 2
test_cases = [1, 3]
expected_output = "#\n\... | [
{
"docstring": "Returns the seating arrangement pattern for N rows.",
"function_declaration": "def generate_seating_pattern(n):",
"function_name": "generate_seating_pattern",
"parameter_list": "(n)"
},
{
"docstring": "Given a list of test cases, generates seating patterns for each case.",
... | [
1,
1,
0,
1,
0,
1,
0,
0,
0
] | 4 | medium | 0.444 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def generate_pattern(N):\n \"\"\"\n Generate seating arrangement pattern based on the number of rows.\n \"\"\"\n pattern = []\n for i in range(N):\n ... | trial_gpt4o_5 | {
"original_instruction": "A startup company wants to automate the task of generating seating arrangements for their upcoming orientation session. They need a program that will help them arrange the attendees in a specific pattern based on the number of rows.\n\n-----Input:-----\n- First line will contain $T$, the nu... | 0.560343 | Apps_2384 | C | [
"generate_seating_pattern",
"generate_patterns_for_test_cases",
"generate_seating_patterns"
] | 3 | [
[
"generate_patterns_for_test_cases",
"generate_seating_pattern"
],
[
"generate_seating_patterns",
"generate_patterns_for_test_cases"
]
] | 2 | [
"generate_patterns_for_test_cases"
] | false | [] | false | pytest | true | [] | true | c5153d7c3e97cec825de584a31009c0ea33c000d | dabaea02d7d3cf2a4e9a2c9a93a288fed7bdf248 | |||
v1.0 | complete | Apps | Apps_1613_C | def find_shortest_path(graph, landmarks):
""" Find the shortest path that connects a set of given landmarks, visiting each landmark exactly once and returning to the starting point.
>>> graph = {
... ('A', 'B'): 10,
... ('A', 'C'): 15,
... ('B', 'C'): 35,
... ('B', 'D'): 25,
... | import itertools
def calculate_path_length(graph, path):
total_length = 0
for i in range(len(path) - 1):
segment = (path[i], path[i + 1])
if segment in graph:
total_length += graph[segment]
else:
total_length += graph[(path[i + 1], path[i])] # assuming the graph... | from solution import find_shortest_path
def test_find_shortest_path():
graph = {
('A', 'B'): 10,
('A', 'C'): 15,
('B', 'C'): 35,
('B', 'D'): 25,
('C', 'D'): 30,
('D', 'A'): 20 # Adding D -> A for completeness
}
landmarks = ['A', 'B', 'C', 'D']
resul... | [
{
"docstring": null,
"function_declaration": "def calculate_path_length(graph, path):",
"function_name": "calculate_path_length",
"parameter_list": "(graph, path)"
},
{
"docstring": null,
"function_declaration": "def find_shortest_path(graph, landmarks):",
"function_name": "find_shor... | [
1,
0,
0,
1,
0,
0,
0,
1,
0,
0
] | 3 | hard | 0.3 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import itertools\n\ndef calculate_path_length(graph, path):\n length = 0\n for i in range(len(path) - 1):\n length += graph.get((path[i], path[i + 1]),... | trial_gpt4o_7 | {
"original_instruction": "In a town, there are numerous paths that connect various landmarks, and each path has a length associated with it. Your task is to find the shortest path that connects a set of given landmarks, visiting each landmark exactly once and returning to the starting point. This is known as the Tra... | 0.663544 | Apps_1613 | C | [
"calculate_path_length",
"find_shortest_path"
] | 2 | [
[
"find_shortest_path",
"calculate_path_length"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c2e0ff91cf84b6efc008f23790df4888194b63d6 | 785a7db0d637d1e9dcab4d8e5e599ff1b775115d | |||
v1.0 | complete | Apps | Apps_3188_C | import math
from collections import defaultdict, deque
def sum_of_sizes_of_connected_components(n, toy_ids):
"""Determine the sum of the sizes of all connected components in the graph formed by toys with IDs.
Two nodes belong to the same connected component if there is a path of edges between them,
and an ... | import math
from collections import defaultdict, deque
def is_perfect_square(x):
return int(math.isqrt(x)) ** 2 == x
def sum_of_sizes_of_connected_components(n, toy_ids):
def bfs(node):
queue = deque([node])
visited[node] = True
size = 0
while queue:
current = queue... | import pytest
from solution import sum_of_sizes_of_connected_components
def test_small_example():
assert sum_of_sizes_of_connected_components(5, [1, 4, 9, 16, 23]) == 5
def test_all_isolated():
assert sum_of_sizes_of_connected_components(3, [1, 2, 3]) == 3
def test_all_connected():
assert sum_of_sizes_of... | [
{
"docstring": null,
"function_declaration": "def is_perfect_square(x):",
"function_name": "is_perfect_square",
"parameter_list": "(x)"
},
{
"docstring": null,
"function_declaration": "def sum_of_sizes_of_connected_components(n, toy_ids):",
"function_name": "sum_of_sizes_of_connected... | [
0,
1,
1,
1,
1,
1,
1,
1,
0,
1
] | 8 | easy | 0.8 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef is_perfect_square(x):\n \"\"\"\n Returns True if x is a perfect square, otherwise returns False\n \"\"\"\n return int(math.sqrt(x))**... | trial_gpt4o_9 | {
"original_instruction": "Joy has a collection of n unique toys, each with a distinct integer ID. Every toy can be represented as a node in a graph, where there is an undirected edge between two nodes if the absolute difference between their IDs is a perfect square.\n\nWrite a program to determine the sum of the siz... | 0.539108 | Apps_3188 | C | [
"is_perfect_square",
"sum_of_sizes_of_connected_components"
] | 2 | [
[
"sum_of_sizes_of_connected_components",
"is_perfect_square"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6a87fa5bc85f716429fc8d7ed6c4028f5966e9b9 | 0ad00c4b0603ca37f5a0beb32d4301ff853f3c22 | |||
v1.0 | complete | Apps | Apps_3328_C | import itertools
def is_palindrome(s):
""" Helper function to check if a string is a palindrome. """
cleaned = ''.join(filter(str.isalnum, s)).lower()
return cleaned == cleaned[::-1]
def palindrome_permutations(S: str) -> None:
""" Generate all possible permutations of the characters in S. For each pe... | import itertools
def is_palindrome(s):
cleaned = ''.join(filter(str.isalnum, s)).lower()
return cleaned == cleaned[::-1]
def palindrome_permutations(S):
permutations = set(itertools.permutations(S))
palindrome_perms = ["".join(p) for p in permutations if is_palindrome("".join(p))]
if not pali... | from solution import palindrome_permutations
def test_single_character_input():
assert palindrome_permutations("a") == None # Since it will print "a"
def test_two_character_palindrome():
assert palindrome_permutations("aa") == None # Since it will print "aa"
def test_two_character_non_palindrome():
asser... | [
{
"docstring": null,
"function_declaration": "def is_palindrome(s):",
"function_name": "is_palindrome",
"parameter_list": "(s)"
},
{
"docstring": null,
"function_declaration": "def palindrome_permutations(S):",
"function_name": "palindrome_permutations",
"parameter_list": "(S)"
... | [
0,
0,
0,
0,
1,
0,
0,
0,
0
] | 1 | hard | 0.111 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import itertools\n\ndef is_palindrome(s):\n \"\"\"\n Function to check if a given string is a palindrome.\n \"\"\"\n s = ''.join(filter(str.isalnum, s))... | trial_gpt4o_4 | {
"original_instruction": "=====Function Descriptions=====\nitertools.product()\n\nThe itertools.product() function returns the Cartesian product of input iterables.\nCode\n\n>>> import itertools\n>>> itertools.product([1, 2, 3], repeat=2)\n<itertools.product object at 0x00DF4D0>\n>>> list(itertools.product([1, 2, 3]... | 0.787551 | Apps_3328 | C | [
"is_palindrome",
"palindrome_permutations"
] | 2 | [
[
"palindrome_permutations",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 58ec29e10905b1e3d71b7193bc87c0b877a6e478 | 424f4bb5cee59c8750c3ce81dafef68b05d8b145 | |||
v1.0 | complete | Apps | Apps_2571_C | class Node:
def __init__(self, value, left=None, right=None):
self.value = value
self.left = left
self.right = right
def parse_tree(preorder_str: str) -> Node:
""" Parse the string representation of the binary tree into a tree structure. """
def parse_subtrees(subtree_str: str) -> Tupl... | class Node:
def __init__(self, value, left=None, right=None):
self.value = value
self.left = left
self.right = right
def parse_tree(preorder_str):
if preorder_str == 'null':
return None
if preorder_str[0] != '(' and preorder_str[-1] != ')':
return Node(int(preorder_s... | from solution import check_binary_search_tree
def test_case_1():
input_str = "(10,(5,(1,null,null),(8,null,null)),(15,(12,null,null),(20,null,null)))"
assert check_binary_search_tree(input_str) == "True"
def test_case_2():
input_str = "(10,(5,(1,null,null),(12,null,null)),(15,(7,null,null),(20,null,null))... | [] | [
0,
0,
0,
0,
0,
0,
0,
1,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_bst(tree_string):\n import ast\n\n tree = ast.literal_eval(tree_string)\n \n def is_bst_helper(node, min_val, max_val):\n if node == \"nul... | trial_gpt4o_7 | {
"original_instruction": "A binary tree is a data structure where each node has at most two children, referred to as the left child and the right child. A Binary Search Tree (BST) is a special kind of binary tree where for every node, the value of all the nodes in the left subtree is less than the node's value, and ... | 0.625592 | Apps_2571 | C | [
"parse_tree",
"parse_subtrees",
"isBST",
"check_binary_search_tree"
] | 4 | [
[
"check_binary_search_tree",
"isBST"
],
[
"check_binary_search_tree",
"parse_tree"
],
[
"parse_tree",
"parse_subtrees"
]
] | 3 | [] | false | [
"Node"
] | true | pytest | true | [] | true | 7feb4fcb8ef7573e8768ad76c4bdfb4add534c4d | 914d90160f6facce23e1b98e8c9bf6e4d0379c1a | |||
v1.0 | complete | Apps | Apps_3379_C | def evenSum(lst):
"""
Returns the sum of elements at even indices in the list.
>>> evenSum([1, 2, 3, 4, 5]) == 9
>>> evenSum([10, 20, 30, 40]) == 40
>>> evenSum([]) == 0
>>> evenSum([7]) == 7
"""
pass
def oddSum(lst):
"""
Returns the sum of elements at odd indices in the list.
... | def evenSum(lst):
"""
Returns the sum of elements at even indices in the list.
"""
if not lst:
return 0
return lst[0] + oddSum(lst[1:])
def oddSum(lst):
"""
Returns the sum of elements at odd indices in the list.
"""
if not lst:
return 0
return evenSum(lst[1:]) | from solution import evenSum, oddSum
def test_evenSum_empty_list():
assert evenSum([]) == 0
def test_oddSum_empty_list():
assert oddSum([]) == 0
def test_evenSum_single_element_list():
assert evenSum([9]) == 9
def test_oddSum_single_element_list():
assert oddSum([9]) == 0
def test_evenSum_multiple_... | [
{
"docstring": "Returns the sum of elements at even indices in the list.",
"function_declaration": "def evenSum(lst):",
"function_name": "evenSum",
"parameter_list": "(lst)"
},
{
"docstring": "Returns the sum of elements at odd indices in the list.",
"function_declaration": "def oddSum(l... | [
0,
0,
1,
1,
1,
0,
0,
0,
0,
0
] | 3 | hard | 0.3 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def evenSum(lst):\n \"\"\"\n Computes the sum of elements at even indices of a given list.\n \"\"\"\n def helper(ls, is_even):\n if not ls:\n ... | trial_gpt4o_4 | {
"original_instruction": "In Scala, an indirectly recursive function is one that makes a call to another function, which in turn calls the original function. This indirect recursion can be useful for implementing algorithms that need to alternate between different behaviors or states in each call.\n\nImplement two m... | 0.823959 | Apps_3379 | C | [
"evenSum",
"oddSum"
] | 2 | [
[
"evenSum",
"oddSum"
],
[
"oddSum",
"evenSum"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 48b9ac9c7e6c1ec2d64b06ee2574b6e4874f05d0 | 6e8fbdb7312d577b34106267e079b54a05033443 | |||
v1.0 | complete | Apps | Apps_2731_C | def interleave_strings(A: str, B: str) -> str:
""" Generate an interleaved string C from A and B.
"""
pass
def count_distinct_characters(C: str) -> int:
""" Count the number of distinct characters in the string C.
"""
pass
def process_queries(N: int, A: str, B: str, queries: List[str]) -> List... | def interleave_strings(A, B):
"""
Generate an interleaved string C from A and B.
"""
return ''.join([A[i] + B[i] for i in range(len(A))])
def count_distinct_characters(C):
"""
Count the number of distinct characters in the string C.
"""
return len(set(C))
def process_queries(N, A, B, q... | from solution import process_queries
def test_process_queries_example_case():
N = 5
A = "abcde"
B = "fghij"
queries = ["1 3 k", "3", "2 5 z", "3"]
results = process_queries(N, A, B, queries)
assert results == [10, 10]
def test_process_queries_single_update_A():
N = 3
A = "abc"
B = ... | [
{
"docstring": "Generate an interleaved string C from A and B.",
"function_declaration": "def interleave_strings(A, B):",
"function_name": "interleave_strings",
"parameter_list": "(A, B)"
},
{
"docstring": "Count the number of distinct characters in the string C.",
"function_declaration"... | [
0,
0,
0,
0,
0,
1,
1,
1,
1,
0
] | 4 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def interleaved_string_distinct_count(A, B, queries):\n \"\"\"\n Function to handle the interleaving and queries for updating and counting distinct chars.\n ... | trial_gpt4o_8 | {
"original_instruction": "Johnny loves string manipulation and enjoys creating new words from fragments of other words. Given two strings, A and B of the same length, Johnny wants to create a new string C by interleaving characters from A and B.\n\nOne interleaving way is defined as picking the first character from ... | 0.588513 | Apps_2731 | C | [
"interleave_strings",
"count_distinct_characters",
"process_queries"
] | 3 | [
[
"process_queries",
"count_distinct_characters"
],
[
"process_queries",
"interleave_strings"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | true | [] | true | 2b62cac7049a566fa8964e309bdc8c16d4fa90ad | df536fa0b6f837264cbfc5c0881fe1c0486761ac | |||
v1.0 | complete | Apps | Apps_3127_C | class TreeNode:
def __init__(self, value):
self.value = value
self.left = None
self.right = None
def build_tree_from_input(lines):
"""
This function builds a binary tree from a list of input lines.
Parameters:
lines: List[str] : A list of strings representing the nodes ... | class TreeNode:
def __init__(self, value):
self.value = value
self.left = None
self.right = None
def build_tree_from_input(lines):
if not lines:
return None
nodes = {}
for line in lines:
N, L, R = map(int, line.split())
if N not in nodes:
... | from solution import binary_tree_inorder_traversal
def test_binary_tree_inorder_traversal():
input_lines = [
"1 2 3",
"2 4 5",
"3 -1 -1",
"4 -1 -1",
"5 -1 -1"
]
result = binary_tree_inorder_traversal(input_lines)
assert result == [4, 2, 5, 1, 3]
def test_binary_... | [] | [
0,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 9 | easy | 0.9 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "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 build_tr... | trial_gpt4o_7 | {
"original_instruction": "Given a binary tree, implement an algorithm to perform an in-order traversal of the tree without using recursion. Return an array of node values representing the in-order traversal.\n\n### Input\n- The input will consist of a series of lines representing the nodes of the binary tree.\n- Eac... | 0.570725 | Apps_3127 | C | [
"build_tree_from_input",
"inorder_traversal",
"binary_tree_inorder_traversal"
] | 3 | [
[
"binary_tree_inorder_traversal",
"build_tree_from_input"
],
[
"binary_tree_inorder_traversal",
"inorder_traversal"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 1db34431e59564b6e0320cba6a2ba61b462071be | 48f86903103bd9b38fe86014c5d37c10d6750e26 | |||
v1.0 | complete | Apps | Apps_3281_C | def find_highest_and_second_highest(scores: List[int]) -> str:
""" Find the highest and second highest scores.
>>> find_highest_and_second_highest([10, 20, 20, 30, 30])
'30 20'
>>> find_highest_and_second_highest([50, 50, 50])
'NO SECOND HIGHEST'
>>> find_highest_and_second_highest([100, 100, 10... | def find_highest_and_second_highest(scores):
unique_scores = sorted(set(scores), reverse=True)
if len(unique_scores) < 2:
return "NO SECOND HIGHEST"
else:
return f"{unique_scores[0]} {unique_scores[1]}"
def process_input_lines(lines):
n = int(lines[0].strip())
scores = list(map(... | from solution import find_highest_and_second_highest, process_input_lines
def test_example_1():
assert find_highest_and_second_highest([10, 20, 20, 30, 30]) == "30 20"
def test_example_2():
assert find_highest_and_second_highest([50, 50, 50]) == "NO SECOND HIGHEST"
def test_all_same_scores():
ass... | [
{
"docstring": null,
"function_declaration": "def find_highest_and_second_highest(scores):",
"function_name": "find_highest_and_second_highest",
"parameter_list": "(scores)"
},
{
"docstring": null,
"function_declaration": "def process_input_lines(lines):",
"function_name": "process_i... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_highest_and_second_highest(scores):\n \"\"\"\n Given a list of scores, returns a tuple of the highest and the second highest scores.\n If there is... | trial_gpt4o_9 | {
"original_instruction": "A large number of students have enrolled in a coding contest. Given a list of contest scores, you need to find the highest score and the second highest score among the participants. If there is no second highest score (i.e., all participants have the same score), return \"NO SECOND HIGHEST\... | 0.59021 | Apps_3281 | C | [
"find_highest_and_second_highest",
"process_input_lines"
] | 2 | [
[
"process_input_lines",
"find_highest_and_second_highest"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 48644282155ce22cb828c60c88655f197b13c477 | a78f0cb1cdac1913b4045e5a779ae095870a321e | |||
v1.0 | complete | Apps | Apps_2891_C | def is_valid_email(email: str) -> bool:
"""Returns True if the email is valid according to the defined rules, False otherwise.
>>> is_valid_email('test.email@example.com') == True
>>> is_valid_email('username@domain.com') == True
>>> is_valid_email('.invalid@domain.com') == False
>>> is_valid_email(... | import re
def is_valid_email(email):
"""
Returns True if the email is valid according to the defined rules, False otherwise.
"""
try:
local, domain = email.split('@')
except ValueError:
return False
# Validate local part
if not re.match(r'^[a-zA-Z0-9]+([._-]?[a-zA-Z0-9]... | from solution import is_valid_email, filter_valid_emails
def test_is_valid_email():
assert is_valid_email('test.email@example.com') == True
assert is_valid_email('username@domain.com') == True
assert is_valid_email('.invalid@domain.com') == False
assert is_valid_email('username@domain,com') == False
... | [
{
"docstring": "Returns True if the email is valid according to the defined rules, False otherwise.",
"function_declaration": "def is_valid_email(email):",
"function_name": "is_valid_email",
"parameter_list": "(email)"
},
{
"docstring": "Filters and returns a list of valid emails according t... | [
0,
0,
1,
0,
1,
0,
0,
0,
1,
0
] | 3 | hard | 0.3 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_valid_email(email):\n if email.count('@') != 1:\n return False\n \n local, domain = email.split('@')\n \n # Check local part\n if le... | trial_gpt4o_2 | {
"original_instruction": "Challenge:\n\nDesign a function to validate if strings in a list are valid email addresses. An email address is considered valid if it meets the following conditions:\n\n1. It contains exactly one '@' symbol.\n2. The local part (portion before '@') must contain only alphanumeric characters ... | 0.583952 | Apps_2891 | C | [
"is_valid_email",
"filter_valid_emails"
] | 2 | [
[
"filter_valid_emails",
"is_valid_email"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 194516f7644d879c6f124ec5fcd20785988d0589 | b6f1fdae98a34f1a4ee23cb6ff934fe13543c690 | |||
v1.0 | complete | Apps | Apps_1082_C | def create_prefix_sum(grid, n):
""" Create a prefix sum matrix for the given grid.
>>> grid = [
[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12],
[13, 14, 15, 16]
]
>>> create_prefix_sum(grid, 4)
[
[0, 0, 0, 0, 0],
[0, 1, 3, 6, 10],
[0, 6, 14, 24, 3... | def create_prefix_sum(grid, n):
MOD = 10**9 + 7
prefix_sum = [[0] * (n + 1) for _ in range(n + 1)]
for i in range(1, n + 1):
for j in range(1, n + 1):
prefix_sum[i][j] = (grid[i - 1][j - 1] +
prefix_sum[i - 1][j] +
pref... | def test_create_prefix_sum():
grid = [
[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12],
[13, 14, 15, 16]
]
n = 4
expected = [
[0, 0, 0, 0, 0],
[0, 1, 3, 6, 10],
[0, 6, 14, 24, 36],
[0, 15, 33, 54, 78],
[0, 28, 60, 96, 136]
]
pre... | [
{
"docstring": null,
"function_declaration": "def create_prefix_sum(grid, n):",
"function_name": "create_prefix_sum",
"parameter_list": "(grid, n)"
},
{
"docstring": null,
"function_declaration": "def compute_subgrid_sum(prefix_sum, x1, y1, x2, y2):",
"function_name": "compute_subgri... | [
0,
0,
0,
0,
0,
0,
1,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "MOD = 10**9 + 7\n\ndef compute_prefix_sum(grid, N):\n \"\"\"\n Computes the prefix sum matrix for the given grid.\n \"\"\"\n prefix_sum = [[0] * (N + 1)... | trial_gpt4o_6 | {
"original_instruction": "Given a large NxN grid where N can be up to 10^5, each cell (i, j) containing a unique positive integer in the range 1 to N^2. You need to process q queries on this grid. Each query provides four integers x1, y1, x2, y2 which define a subgrid. For each query, you are to find the sum of the ... | 0.561786 | Apps_1082 | C | [
"create_prefix_sum",
"compute_subgrid_sum",
"process_queries"
] | 3 | [
[
"process_queries",
"compute_subgrid_sum"
],
[
"process_queries",
"create_prefix_sum"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | false | [] | true | f7605cdd03ea8af533c7e57854cb795e8b337747 | 6f3d53948e0d3d86cfe9915fb93a3257016d67b7 | |||
v1.0 | complete | Apps | Apps_3293_C | def findLargestLandmass(N: int, M: int, grid: List[str]) -> int:
""" You are given a rectangular grid consisting of 'N' rows and 'M' columns with each cell either being land ('L') or water ('W').
You need to find the largest rectangular landmass (contiguous section of 'L' cells) that can be formed on the grid.... | def maximalRectangle(grid):
if not grid:
return 0
max_area = 0
N = len(grid)
M = len(grid[0])
heights = [0] * M
for row in grid:
for idx in range(M):
if row[idx] == 'L':
heights[idx] += 1
else:
heights[idx] = 0
... | from solution import findLargestLandmass
def test_findLargestLandmass_example():
N = 4
M = 5
grid = [
"LWLWL",
"LLLWW",
"WLLWL",
"LLLWL",
]
assert findLargestLandmass(N, M, grid) == 6
def test_findLargestLandmass_allLand():
N = 3
M = 3
grid = [
"... | [
{
"docstring": null,
"function_declaration": "def maximalRectangle(grid):",
"function_name": "maximalRectangle",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def largestRectangleArea(heights):",
"function_name": "largestRectangleArea",
"parameter_li... | [
1,
1,
1,
0,
1,
0,
0,
0,
0,
1
] | 5 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def largest_landmass_area(N, M, grid):\n if not grid or not grid[0]:\n return 0\n \n max_area = 0\n heights = [0] * M\n \n for row in grid:... | trial_gpt4o_1 | {
"original_instruction": "You are given a rectangular grid consisting of 'N' rows and 'M' columns with each cell either being land ('L') or water ('W'). You need to find the largest rectangular landmass (contiguous section of 'L' cells) that can be formed on the grid. A landmass is defined as a rectangle containing ... | 0.598987 | Apps_3293 | C | [
"maximalRectangle",
"largestRectangleArea",
"findLargestLandmass"
] | 3 | [
[
"findLargestLandmass",
"maximalRectangle"
],
[
"maximalRectangle",
"largestRectangleArea"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | e59bdc4aafbe518e442f5f5960f7e4724f774cf2 | 6151526a63112fb4256764197464cdd1975fe0a0 | |||
v1.0 | complete | Apps | Apps_3558_C | from typing import List
def is_perfect_number(num: int) -> bool:
""" Determines if a number is a Perfect Number.
A Perfect Number is a positive integer that is equal to the sum of its proper divisors, excluding the number itself.
>>> is_perfect_number(6)
True
>>> is_perfect_number(28)
... | def is_perfect_number(num):
"""
Determines if a number is a Perfect Number.
A Perfect Number is a positive integer that is equal to the sum of its proper divisors, excluding the number itself.
"""
if num <= 1:
return False
divisor_sum = 1 # Start with 1, which is a proper divisor o... | from solution import is_perfect_number, check_perfect_numbers
def test_is_perfect_number():
# Testing known perfect numbers
assert is_perfect_number(6) == True
assert is_perfect_number(28) == True
assert is_perfect_number(496) == True
assert is_perfect_number(8128) == True
# Testing non-pe... | [
{
"docstring": "Determines if a number is a Perfect Number.\nA Perfect Number is a positive integer that is equal to the sum of its proper divisors, excluding the number itself.",
"function_declaration": "def is_perfect_number(num):",
"function_name": "is_perfect_number",
"parameter_list": "(num)"
... | [
1,
0,
1,
1,
1,
1,
1,
1,
1,
1
] | 9 | easy | 0.9 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def sum_of_proper_divisors(n):\n \"\"\"\n Returns the sum of proper divisors of n excluding itself.\n \"\"\"\n if n <= 1:\n return 0\n \n ... | trial_gpt4o_9 | {
"original_instruction": "Given a list of integers, determine if each integer is a \"Perfect Number\". A Perfect Number is a positive integer that is equal to the sum of its proper divisors, excluding the number itself. For example, the number 6 has proper divisors 1, 2, and 3, and 1 + 2 + 3 = 6, so 6 is a Perfect N... | 0.662307 | Apps_3558 | C | [
"is_perfect_number",
"check_perfect_numbers"
] | 2 | [
[
"check_perfect_numbers",
"is_perfect_number"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8a3655321e28f812726d9dbe6122a6dcb74f1ad9 | b4e8a92a46d2989af35840f9f4851fe9f16af7b9 | |||
v1.0 | complete | Apps | Apps_3632_C | from typing import List
def kth_largest_element(nums: List[int], k: int) -> int:
""" Given an integer array nums of length n and an integer k,
return the k-th largest element in the array.
>>> kth_largest_element([3, 2, 1, 5, 6, 4], 2)
5
>>> kth_largest_element([3, 2, 3, 1, 2, 4, 5, 5, 6], 4)
... | import random
def partition(nums, left, right):
pivot_index = random.randint(left, right)
pivot_value = nums[pivot_index]
nums[pivot_index], nums[right] = nums[right], nums[pivot_index]
store_index = left
for i in range(left, right):
if nums[i] < pivot_value:
nums[store_index], ... | from solution import kth_largest_element
def test_kth_largest_element():
assert kth_largest_element([3, 2, 1, 5, 6, 4], 2) == 5
assert kth_largest_element([3, 2, 3, 1, 2, 4, 5, 5, 6], 4) == 4
assert kth_largest_element([1, 2, 3, 4, 5, 6], 1) == 6
assert kth_largest_element([1, 2, 3, 4, 5, 6], 6) == 1
... | [
{
"docstring": null,
"function_declaration": "def partition(nums, left, right):",
"function_name": "partition",
"parameter_list": "(nums, left, right)"
},
{
"docstring": null,
"function_declaration": "def quickselect(nums, left, right, k_smallest):",
"function_name": "quickselect",
... | [
0,
1,
1,
1,
0,
0,
0,
1,
0,
0
] | 4 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\n\ndef partition(nums, left, right, pivot_index):\n pivot_value = nums[pivot_index]\n # Move pivot value to the end\n nums[pivot_index], nums... | trial_gpt4o_7 | {
"original_instruction": "Given an integer array `nums` of length `n` and an integer `k`, write a function `kth_largest_element(nums, k)` that returns the `k`-th largest element in the array.\n\nConstraints:\n- You may assume that k is always valid, 1 ≤ k ≤ n.\n- You must solve it in O(n) time complexity on average.... | 0.803764 | Apps_3632 | C | [
"partition",
"quickselect",
"kth_largest_element"
] | 3 | [
[
"kth_largest_element",
"quickselect"
],
[
"quickselect",
"partition"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | f1fd137ea0a49da71c33ffad4ac5d6b0aff9b449 | 1e522a754f4d24cf91ec7a9fd376685dac190b1c | |||
v1.0 | complete | Apps | Apps_3596_C | def bst_inorder_from_level_order(n, level_order):
""" Construct a BST from a given level order traversal and return the in-order traversal of the BST.
>>> bst_inorder_from_level_order(7, [4, 2, 6, 1, 3, 5, 7])
[1, 2, 3, 4, 5, 6, 7]
>>> bst_inorder_from_level_order(1, [10])
[10]
>>> bst_inorder_f... | from collections import deque
class TreeNode:
def __init__(self, val):
self.val = val
self.left = None
self.right = None
def construct_bst_from_level_order(level_order):
if not level_order:
return None
root = TreeNode(level_order[0])
queue = deque([root])
index... | from solution import bst_inorder_from_level_order
def test_example_case():
n = 7
level_order = [4, 2, 6, 1, 3, 5, 7]
assert bst_inorder_from_level_order(n, level_order) == [1, 2, 3, 4, 5, 6, 7]
def test_single_node():
n = 1
level_order = [10]
assert bst_inorder_from_level_order(n, level_order)... | [] | [
0,
0,
1,
1,
0,
0,
1,
1,
1,
1
] | 6 | medium | 0.6 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, key):\n self.left = None\n self.right = None\n self.val = key\n\ndef insert_level_order(arr, root, i, n... | trial_gpt4o_2 | {
"original_instruction": "Alice is learning about binary search trees (BST) and their properties. She knows that a BST is a tree data structure where each node has at most two children, referred to as the left child and the right child. For any given node with value V, all values in the left subtree are less than V,... | 0.488835 | Apps_3596 | C | [
"construct_bst_from_level_order",
"inorder_traversal",
"bst_inorder_from_level_order"
] | 3 | [
[
"bst_inorder_from_level_order",
"construct_bst_from_level_order"
],
[
"bst_inorder_from_level_order",
"inorder_traversal"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 06eb1c8ea16a91900ddc1d28a325ac14c4cb13cf | dab3f497c864686901ab2ee37dbbb674c0c0030e | |||
v1.0 | complete | Apps | Apps_2802_C | def pacific_atlantic_water_flow(matrix: List[List[int]]) -> int:
""" Determine the number of cells from which water can flow to both the Pacific and Atlantic Oceans.
>>> pacific_atlantic_water_flow([[1, 2, 2, 3, 5], [3, 2, 3, 4, 4], [2, 4, 5, 3, 1], [6, 7, 1, 4, 5], [5, 1, 1, 2, 4]]) == 7
>>> pacific_atlant... | def pacific_atlantic_water_flow(matrix):
if not matrix or not matrix[0]:
return 0
m, n = len(matrix), len(matrix[0])
def dfs(x, y, visited):
directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]
stack = [(x, y)]
visited.add((x, y))
while stack:
cx, cy = stack.... | from solution import solve
def test_sample_input():
input_str = "5 5\n1 2 2 3 5\n3 2 3 4 4\n2 4 5 3 1\n6 7 1 4 5\n5 1 1 2 4"
assert solve(input_str) == 7
def test_single_cell():
input_str = "1 1\n0"
assert solve(input_str) == 1
def test_empty_matrix():
input_str = "0 0"
assert solve(input_str... | [
{
"docstring": null,
"function_declaration": "def pacific_atlantic_water_flow(matrix):",
"function_name": "pacific_atlantic_water_flow",
"parameter_list": "(matrix)"
},
{
"docstring": null,
"function_declaration": "def rect_grid_from_input(input_str):",
"function_name": "rect_grid_fr... | [
0,
0,
0,
0,
0,
0,
1,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def pacific_atlantic(matrix):\n if not matrix or not matrix[0]:\n return 0\n\n m, n = len(matrix), len(matrix[0])\n\n def dfs(i, j, visited, prev_he... | trial_gpt4o_6 | {
"original_instruction": "You are given a rectangular grid of cells with non-negative integer elevations. Water can flow from one cell to its neighboring cells (left, right, up, down) if the elevation of the neighboring cell is less than or equal to the current cell. You are tasked with determining the number of cel... | 0.636549 | Apps_2802 | C | [
"pacific_atlantic_water_flow",
"rect_grid_from_input",
"solve"
] | 3 | [
[
"solve",
"pacific_atlantic_water_flow"
],
[
"solve",
"rect_grid_from_input"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | d3473d4349fa9b5ac41c13da7b49ae601577a642 | c6dbd2481856ad9fb1ffd377c01cc0fb60902d61 | |||
v1.0 | complete | Apps | Apps_3600_C | def find_min_path_sum(R: int, C: int, grid_values: List[int]) -> int:
"""Find the minimum path sum from the top-left corner of grid to the bottom-right corner.
The grid is represented by its values in a flat list traversed row-wise.
>>> find_min_path_sum(3, 3, [1, 3, 1, 1, 5, 1, 4, 2, 1])
7
... | def min_path_sum(grid):
R = len(grid)
C = len(grid[0])
dp = [[0] * C for _ in range(R)]
dp[0][0] = grid[0][0]
for i in range(1, R):
dp[i][0] = dp[i-1][0] + grid[i][0]
for j in range(1, C):
dp[0][j] = dp[0][j-1] + grid[0][j]
for i in range(1, R):
... | from solution import find_min_path_sum
def test_sample_input():
R = 3
C = 3
grid_values = [1, 3, 1, 1, 5, 1, 4, 2, 1]
assert find_min_path_sum(R, C, grid_values) == 7
def test_single_cell():
R = 1
C = 1
grid_values = [5]
assert find_min_path_sum(R, C, grid_values) == 5
def test_row_gr... | [
{
"docstring": null,
"function_declaration": "def min_path_sum(grid):",
"function_name": "min_path_sum",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def find_min_path_sum(R, C, grid_values):",
"function_name": "find_min_path_sum",
"parameter_list":... | [
1,
0,
1,
0,
1,
1,
0,
0,
0
] | 4 | medium | 0.444 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def min_path_sum(grid):\n \"\"\"\n Returns the minimum path sum from top-left corner to bottom-right corner in a grid.\n \n Args:\n grid (list of lis... | trial_gpt4o_3 | {
"original_instruction": "You are given a grid with R rows and C columns, filled with integers. The task is to find the minimum path sum from the top-left corner of the grid to the bottom-right corner. You can only move either down or right at any point in time.\n\n-----Input-----\n\nThe first line contains two inte... | 0.721757 | Apps_3600 | C | [
"min_path_sum",
"find_min_path_sum"
] | 2 | [
[
"find_min_path_sum",
"min_path_sum"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e64e8327693af191ce8837ff88eb7245c28f263c | 1d253d37c2331dd4cc650f61b683aa7bfa8a293a | |||
v1.0 | complete | Apps | Apps_3524_C | def filter_primes(arr):
"""
Takes an array of integers and returns a new array containing only the prime numbers
from the original array. If there are no prime numbers in the input array,
the function should return an empty array.
>>> filter_primes([2, 3, 4, 5, 6]) == [2, 3, 5]
>>> filte... | def is_prime(n):
"""
Returns True if n is a prime number, otherwise False.
"""
if n < 2:
return False
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
return True
def filter_primes(arr):
"""
Returns a list containing only the prime numbers in t... | from solution import filter_primes
def test_filter_prime_basic():
assert filter_primes([2, 3, 4, 5, 6]) == [2, 3, 5]
def test_filter_prime_no_primes():
assert filter_primes([1, 4, 6, 8, 9, 10]) == []
assert filter_primes([15, 18, 20, 22, 24, 25]) == []
def test_filter_prime_all_primes():
assert filt... | [
{
"docstring": "Returns True if n is a prime number, otherwise False.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list containing only the prime numbers in the given array.",
"function_declaration": "def ... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if n < 2:\n return False\n for i in range(2, int(n ** 0.... | trial_gpt4o_9 | {
"original_instruction": "Write a function that takes an array of integers and returns a new array containing only the prime numbers from the original array. If there are no prime numbers in the input array, the function should return an empty array.\n\n## Examples\n\n```\n[2, 3, 4, 5, 6] => [2, 3, 5]\n[1... | 0.698036 | Apps_3524 | C | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f91c16bcaa8b1bda882804983e933a010076d25e | 5def1e9d4fff44e1d2ef11a697db7dec9d0389ee | |||
v1.0 | complete | Apps | Apps_3133_C | def encrypt(text: str, shift: int) -> str:
"""Encrypt the input text using Caesar cipher with the given shift value.
>>> encrypt("Hello, World!", 3)
'Khoor, Zruog!'
>>> encrypt("abcXYZ", -5)
'vwxSTU'
"""
pass
def decrypt(text: str, shift: int) -> str:
"""Decrypt the encrypted text using... | def encrypt(text, shift):
"""
Encrypts the text using Caesar cipher with the given shift value.
"""
encrypted_text = []
for char in text:
if char.isalpha():
shift_amount = shift % 26
if char.islower():
new_char = chr((ord(char) - ord('a') + shift_amoun... | from solution import encrypt, decrypt
def test_encrypt_positive_shift():
assert encrypt("Hello, World!", 3) == "Khoor, Zruog!"
assert encrypt("abcXYZ", 2) == "cdeZAB"
def test_encrypt_negative_shift():
assert encrypt("Hello, World!", -3) == "Ebiil, Tloia!"
assert encrypt("abcXYZ", -2) == "yzaVWX"
... | [
{
"docstring": "Encrypts the text using Caesar cipher with the given shift value.",
"function_declaration": "def encrypt(text, shift):",
"function_name": "encrypt",
"parameter_list": "(text, shift)"
},
{
"docstring": "Decrypts the text using Caesar cipher with the given shift value.",
"f... | [
1,
1,
1,
0,
1,
0,
1,
1,
1,
1
] | 8 | easy | 0.8 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def encrypt(text, shift):\n \"\"\"\n Encrypts the given text using Caesar cipher with the provided shift.\n \n Parameters:\n text (str): the string t... | trial_gpt4o_9 | {
"original_instruction": "### Encrypt and Decrypt Strings with Caesar Cipher\n\nA Caesar cipher is one of the simplest and most widely known encryption techniques. It is a type of substitution cipher in which each letter in the plaintext is shifted a certain number of places down the alphabet. For example, with a sh... | 0.66758 | Apps_3133 | C | [
"encrypt",
"decrypt"
] | 2 | [
[
"decrypt",
"encrypt"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8f82e05a2ba475de1f8a8a7d2d7428a6c0fa7a7b | 8f10e75cb643fd2961bfa515872e17885e0672d5 | |||
v1.0 | complete | Apps | Apps_3463_C | def is_palindrome(n: int) -> bool:
""" Helper function to check if a number is a palindrome.
>>> is_palindrome(121) == True
>>> is_palindrome(123) == False
"""
pass
def next_palindrome(num: int) -> int:
""" Returns the next palindrome greater than the input number.
>>> next_palindrome(123) ... | def is_palindrome(n):
"""
Helper function to check if a number is a palindrome.
"""
return str(n) == str(n)[::-1]
def next_palindrome(num):
"""
Returns the next palindrome greater than the input number.
"""
num += 1
while not is_palindrome(num):
num += 1
return num | from solution import next_palindrome
def test_single_digit():
assert next_palindrome(8) == 9
assert next_palindrome(9) == 11
def test_double_digit():
assert next_palindrome(10) == 11
assert next_palindrome(12) == 22
def test_triple_digit():
assert next_palindrome(123) == 131
assert next_palin... | [
{
"docstring": "Helper function to check if a number is a palindrome.",
"function_declaration": "def is_palindrome(n):",
"function_name": "is_palindrome",
"parameter_list": "(n)"
},
{
"docstring": "Returns the next palindrome greater than the input number.",
"function_declaration": "def ... | [
1,
0,
1,
1,
0,
1,
1,
1,
1,
1
] | 8 | easy | 0.8 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def next_palindrome(num):\n \"\"\"\n Returns the next palindrome greater than the given number.\n \"\"\"\n def is_palindrome(n):\n return str(n) ... | trial_gpt4o_9 | {
"original_instruction": "A palindrome is a number that reads the same backward as forward. For example, `121` and `1331` are palindromes, while `123` and `1245` are not.\n\nWrite a function `next_palindrome(num)` (JavaScript: `nextPalindrome(num)`) that receives a positive integer `num` and returns the next palindr... | 0.67916 | Apps_3463 | C | [
"is_palindrome",
"next_palindrome"
] | 2 | [
[
"next_palindrome",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 2a17ecd1f143410e49f9f06e89bb124bd7ac6ad3 | 71a7aecee62b93d544215f6583154d042e79de94 | |||
v1.0 | complete | Apps | Apps_2715_C | def is_valid_bst(node_data):
""" Determine if a binary tree is a valid binary search tree (BST).
Args:
node_data: List of tuples, where each tuple contains three integers (V, L, R)
representing a node value and its left and right children.
Returns:
str: "YES" if the tree is a valid ... | def is_valid_bst(node_data):
from collections import defaultdict
# Building the tree
tree = {}
for data in node_data:
V, L, R = data
tree[V] = (L, R)
# Helper function to validate a BST
def validate(node, low, high):
if node == -1:
return True
if not... | def test_check_bst_valid():
n = 5
node_data = [
(4, 2, 5),
(2, 1, 3),
(5, -1, -1),
(1, -1, -1),
(3, -1, -1)
]
assert check_bst(n, node_data) == "YES"
def test_check_bst_invalid():
n = 3
node_data = [
(1, 2, 3),
(2, -1, -1),
(3, -1,... | [
{
"docstring": null,
"function_declaration": "def is_valid_bst(node_data):",
"function_name": "is_valid_bst",
"parameter_list": "(node_data)"
},
{
"docstring": null,
"function_declaration": "def check_bst(n, node_data):",
"function_name": "check_bst",
"parameter_list": "(n, node_... | [
0,
1,
0,
0,
1,
1,
1,
1,
1,
1
] | 7 | easy | 0.7 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, value, left=None, right=None):\n self.value = value\n self.left = left\n self.right = right\n\ndef crea... | trial_gpt4o_8 | {
"original_instruction": "You are given a binary tree with $N$ nodes. Each node has a unique value associated with it, ranging from $1$ to $N$. Write a program to determine if the tree is a \"valid\" binary search tree (BST). A binary search tree satisfies the following conditions:\n- The left subtree of a node cont... | 0.6372 | Apps_2715 | C | [
"is_valid_bst",
"check_bst"
] | 2 | [
[
"check_bst",
"is_valid_bst"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 8e3dc2c1a3a490f4e4d0a0b1214e50c8b2c57a79 | 4a1f2fa4726c152b59eab97ed7b05b44825a6bf4 | |||
v1.0 | complete | Apps | Apps_4074_C | def count_primes_in_range(T: int, ranges: List[Tuple[int, int]]) -> List[int]:
""" Count the number of prime numbers in each specified range.
>>> count_primes_in_range(1, [(1, 10)])
[4]
>>> count_primes_in_range(3, [(1, 10), (11, 20), (21, 30)])
[4, 4, 2]
""" | def sieve_of_eratosthenes(max_range):
sieve = [True] * (max_range + 1)
sieve[0] = sieve[1] = False # 0 and 1 are not prime
p = 2
while (p * p <= max_range):
if (sieve[p] == True):
for i in range(p * p, max_range + 1, p):
sieve[i] = False
p += 1
return siev... | from solution import count_primes_in_range
def test_count_primes_single_case():
assert count_primes_in_range(1, [(1, 10)]) == [4]
def test_count_primes_multiple_cases():
assert count_primes_in_range(3, [(1, 10), (11, 20), (21, 30)]) == [4, 4, 2]
def test_count_primes_in_large_range():
assert count_primes... | [
{
"docstring": null,
"function_declaration": "def sieve_of_eratosthenes(max_range):",
"function_name": "sieve_of_eratosthenes",
"parameter_list": "(max_range)"
},
{
"docstring": null,
"function_declaration": "def prime_count_in_range(L, R, sieve):",
"function_name": "prime_count_in_r... | [
0,
0,
0,
1,
0,
0,
1,
0
] | 2 | hard | 0.25 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def sieve_of_eratosthenes(max_num):\n is_prime = [True] * (max_num + 1)\n is_prime[0], is_prime[1] = False, False\n\n for start in range(2, int(max_num**0.... | trial_gpt4o_4 | {
"original_instruction": "Consider Alice wanting to find prime numbers in a certain range to help her in a cryptography project. She needs your help to count the number of prime numbers in a given range.\n\nWithin a given range, prime numbers are those that have no divisors other than 1 and themselves, and they must... | 0.747203 | Apps_4074 | C | [
"sieve_of_eratosthenes",
"prime_count_in_range",
"count_primes_in_range"
] | 3 | [
[
"count_primes_in_range",
"prime_count_in_range"
],
[
"count_primes_in_range",
"sieve_of_eratosthenes"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 35dd9fe9fddb1d7c96e593b7f3effd788b8388da | 62519a3809fd01ed223e9bc7903bf7dbdcf51b85 | |||
v1.0 | complete | Apps | Apps_3488_C | from typing import List
def primes_between(a: int, b: int) -> List[int]:
"""Returns a list of all prime numbers between a and b (including a and b, if they themselves are prime).
>>> primes_between(10, 20)
[11, 13, 17, 19]
>>> primes_between(30, 50)
[31, 37, 41, 43, 47]
>>> primes_between(... | def is_prime(n):
"""
Helper function to check if a number is a 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 primes_between
def test_primes_between_10_and_20():
assert primes_between(10, 20) == [11, 13, 17, 19]
def test_primes_between_30_and_50():
assert primes_between(30, 50) == [31, 37, 41, 43, 47]
def test_primes_between_1_and_10():
assert primes_between(1, 10) == [2, 3, 5, 7]
def test_... | [
{
"docstring": "Helper function to check if a number is a prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list of all prime numbers between a and b (inclusive).",
"function_declaration": "def primes_be... | [
1,
1,
1,
1,
1,
1,
1,
0,
1,
1
] | 9 | easy | 0.9 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 == 0 or num % 3 == 0:\n return False\n i... | trial_gpt4o_9 | {
"original_instruction": "Write a function `primes_between(a, b)` that returns a list of all prime numbers between `a` and `b` (including `a` and `b`, if they themselves are prime). \n\nA prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. For instance, the list of ... | 0.680092 | Apps_3488 | C | [
"is_prime",
"primes_between"
] | 2 | [
[
"primes_between",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c711436ef2334c98e6c91d204a55820de688149d | a3f7e8f0c58c109938286f30dbe4200df170b1b0 | |||
v1.0 | complete | Apps | Apps_1944_C | from typing import List
def calculate_mean(sequence: List[int]) -> float:
"""
Calculate the mean of a sequence of numbers.
>>> calculate_mean([1, 2, 3, 4])
2.5
>>> calculate_mean([2, 3, 4, 5])
3.5
"""
def calculate_std_dev(sequence: List[int], mean: float) -> float:
"""
Calcula... | def calculate_mean(sequence):
return sum(sequence) / len(sequence)
def calculate_std_dev(sequence, mean):
variance = sum((x - mean) ** 2 for x in sequence) / len(sequence)
return variance ** 0.5
def are_sequences_similar(n, sequence1, sequence2):
mean1 = calculate_mean(sequence1)
mean2 = calculate... | def test_calculate_mean():
assert calculate_mean([1, 2, 3, 4]) == 2.5
assert calculate_mean([2, 3, 4, 5]) == 3.5
assert calculate_mean([-1, -2, -3, -4]) == -2.5
assert calculate_mean([0, 0, 0, 0]) == 0.0
def test_calculate_std_dev():
assert abs(calculate_std_dev([1, 2, 3, 4], 2.5) - 1.1180339887498... | [
{
"docstring": null,
"function_declaration": "def calculate_mean(sequence):",
"function_name": "calculate_mean",
"parameter_list": "(sequence)"
},
{
"docstring": null,
"function_declaration": "def calculate_std_dev(sequence, mean):",
"function_name": "calculate_std_dev",
"paramet... | [
1,
0,
1,
1,
1,
0,
1,
0,
0
] | 5 | medium | 0.556 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef are_sequences_similar(n, rng1, rng2):\n \"\"\"\n Determines if two sequences are statistically similar based on mean and standard deviation... | trial_gpt4o_7 | {
"original_instruction": "Alex likes probabilistic algorithms and is particularly fascinated by the properties of random number generators. He devised a problem where he needs to test if two random number generators produce sequences with similar properties. \n\nSuppose Alex has two random number generators, RNG1 an... | 0.625971 | Apps_1944 | C | [
"calculate_mean",
"calculate_std_dev",
"are_sequences_similar"
] | 3 | [
[
"are_sequences_similar",
"calculate_mean"
],
[
"are_sequences_similar",
"calculate_std_dev"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 43dc7b9818d450287a5148488dd00c4e28ea90f6 | dfa1cea172c646108f98b11679ce60a20ea13897 | |||
v1.0 | complete | Apps | Apps_3495_C | def is_palindrome(number: int) -> bool:
"""
Checks if a given number is a palindrome.
>>> is_palindrome(121) True
>>> is_palindrome(123) False
>>> is_palindrome(0) True
>>> is_palindrome(-121) False
"""
pass
def filter_palindromes(numbers: List[int]) -> List[int]:
"""
Retur... | def is_palindrome(number):
"""
Checks if a given number is a palindrome.
"""
number_str = str(number)
return number_str == number_str[::-1]
def filter_palindromes(numbers):
"""
Returns a new list containing the integers that are palindromes.
Parameters:
- numbers: List of integ... | from solution import filter_palindromes
def test_filter_palindromes_all_palindromes():
assert filter_palindromes([121, 131, 141]) == [121, 131, 141]
def test_filter_palindromes_no_palindromes():
assert filter_palindromes([123, 456, 789]) == []
def test_filter_palindromes_mixed():
assert filter_palindrome... | [
{
"docstring": "Checks if a given number is a palindrome.",
"function_declaration": "def is_palindrome(number):",
"function_name": "is_palindrome",
"parameter_list": "(number)"
},
{
"docstring": "Returns a new list containing the integers that are palindromes.\n\nParameters:\n- numbers: List... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_palindromes(numbers):\n \"\"\"\n Returns a list of palindrome integers from the input list.\n \"\"\"\n def is_palindrome(n):\n str_n = s... | trial_gpt4o_9 | {
"original_instruction": "Write a function that takes a list of integers and returns a new list containing the integers that are palindromes. A palindrome is a number that reads the same forward and backward.\n\n### Examples\n- Input: [123, 121, 454, 32, 303]\n- Output: [121, 454, 303]\n\n- Input: [10, 101, 20]\n- O... | 0.724485 | Apps_3495 | C | [
"is_palindrome",
"filter_palindromes"
] | 2 | [
[
"filter_palindromes",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 46ab7653a7ce88e9f2b65745232f8bd2a1362635 | a20088ebd3d20c5594e4f3f0ed16e1ff4a142bbb | |||
v1.0 | complete | Apps | Apps_3657_C | import re
from typing import List
def is_valid_email(email: str) -> bool:
""" Check if an email address is valid based on the given rules.
>>> is_valid_email("john.doe@example.com") == True
>>> is_valid_email("my-email@domain.co") == True
>>> is_valid_email("hello_world123@sub.domain.com") == True
... | import re
def is_valid_email(email):
"""
Check if an email address is valid based on the given rules.
"""
pattern = re.compile(
r'^[a-zA-Z0-9]+(?:[._-][a-zA-Z0-9]+)*@[a-zA-Z0-9]+(?:\.[a-zA-Z0-9]+)+$'
)
return pattern.match(email) is not None
def filter_valid_emails(emails):
"""
... | from solution import is_valid_email, filter_valid_emails
def test_is_valid_email():
assert is_valid_email("john.doe@example.com") == True
assert is_valid_email("my-email@domain.co") == True
assert is_valid_email("hello_world123@sub.domain.com") == True
assert is_valid_email("john..doe@example.com") == ... | [
{
"docstring": "Check if an email address is valid based on the given rules.",
"function_declaration": "def is_valid_email(email):",
"function_name": "is_valid_email",
"parameter_list": "(email)"
},
{
"docstring": "Filters a list of email addresses, returning only the valid ones.",
"func... | [
1,
1,
1,
0,
1,
1,
0,
0,
0
] | 5 | medium | 0.556 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import re\n\ndef is_valid_email(email):\n \"\"\"\n Returns True if the given email address is valid according to the specified rules.\n \"\"\"\n local, ... | trial_gpt4o_4 | {
"original_instruction": "=====Problem Statement=====\nA valid email address follows these rules:\n\n1. It must have exactly one \"@\" symbol.\n2. The local part (part before the \"@\") can contain alphanumeric characters and special characters: \".\", \"-\", and \"_\". It cannot start or end with a special characte... | 0.620246 | Apps_3657 | C | [
"is_valid_email",
"filter_valid_emails"
] | 2 | [
[
"filter_valid_emails",
"is_valid_email"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | eceee9d3660f80341e76653581932aa7fe335748 | 7aa57d8ae0db34d5c19e560885e5c60bc90702dd | |||
v1.0 | complete | Apps | Apps_2245_C | def can_transform_matrix(N, M, A, B):
""" Determine if there exists a permutation of the rows and columns of matrix A to transform it into matrix B.
Arguments:
- N: int - Number of rows in the matrices.
- M: int - Number of columns in the matrices.
- A: List[List[int]] - The first matrix.
- B: L... | def can_transform_matrix(N, M, A, B):
# Sort each row in both matrices
sorted_A = [sorted(row) for row in A]
sorted_B = [sorted(row) for row in B]
# Sort the rows lexicographically
sorted_A.sort()
sorted_B.sort()
# Compare sorted versions of A and B
return sorted_A == sorted_B
... | import pytest
from solution import solve_problem
def test_example_1():
input_data = "2\n2 2\n1 2\n3 4\n3 4\n1 2\n2 3\n4 1\n2 3\n1 2\n3\n1 2\n3 4\n5 6\n3 4\n5 6\n1 2"
expected_output = "YES\nNO"
assert solve_problem(input_data) == expected_output
def test_case_same_matrices():
input_data = "1\n3 3\n1 2... | [
{
"docstring": null,
"function_declaration": "def can_transform_matrix(N, M, A, B):",
"function_name": "can_transform_matrix",
"parameter_list": "(N, M, A, B)"
},
{
"docstring": null,
"function_declaration": "def matrix_permutation_possible(test_cases):",
"function_name": "matrix_per... | [
1,
1,
0,
0,
1,
0,
1,
1,
0,
1
] | 6 | medium | 0.6 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def can_transform(A, B):\n \"\"\"\n Determines if there exists a permutation of the rows of matrix A, say A', \n such that A' can be transformed into matri... | trial_gpt4o_9 | {
"original_instruction": "You are given two matrices $A$ and $B$ of dimensions $N \\times M$. Your task is to determine if there exists a permutation of the rows of matrix $A$, say $A'$, such that $A'$ can be transformed into matrix $B$ by permuting the columns of $A'$.\n\n-----Input-----\n- The first line of the in... | 0.58994 | Apps_2245 | C | [
"can_transform_matrix",
"matrix_permutation_possible",
"solve_problem"
] | 3 | [
[
"matrix_permutation_possible",
"can_transform_matrix"
],
[
"solve_problem",
"matrix_permutation_possible"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | c02af27ccadc1738f2e406ffc8316afcf7fb6ae3 | efe7b27c556a1979ae51af01f17ce641008e2dd2 | |||
v1.0 | complete | Apps | Apps_3567_C | def max_sum_subgrid(M: int, N: int, grid: [[int]]) -> int:
"""Identify a rectangular subgrid within the grid that has the maximum sum of processing power and return the sum.
Args:
M: int - the number of rows in the grid
N: int - the number of columns in the grid
grid: List of lists - the proces... | def max_sum_subgrid(M, N, grid):
# Initialize max sum as the smallest possible value
max_sum = -float('inf')
# Prefix sums for rows
for top in range(M):
temp_sums = [0] * N
for bottom in range(top, M):
for col in range(N):
temp_sums[col] += grid[bottom][col]
... | from solution import max_sum_subgrid, process_input
def test_example_case():
M = 4
N = 5
grid = [
[1, 2, -1, -4, -20],
[-8, -3, 4, 2, 1],
[3, 8, 10, 1, 3],
[-4, -1, 1, 7, -6]
]
assert max_sum_subgrid(M, N, grid) == 29
def test_single_element():
M = 1
N = 1
... | [
{
"docstring": null,
"function_declaration": "def max_sum_subgrid(M, N, grid):",
"function_name": "max_sum_subgrid",
"parameter_list": "(M, N, grid)"
},
{
"docstring": null,
"function_declaration": "def kadane(arr):",
"function_name": "kadane",
"parameter_list": "(arr)"
},
{
... | [
1,
0,
0,
1,
1,
0,
0,
0,
1,
0
] | 4 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_sum_subgrid(M, N, P):\n def max_subarray_sum(arr):\n max_ending_here = max_so_far = arr[0]\n for x in arr[1:]:\n max_ending_here... | trial_gpt4o_8 | {
"original_instruction": "A company has a server, which is represented by a grid of dimensions $M \\times N$, where each cell in the grid represents a unit of processing power. The processing power of the cell located at $(i, j)$ is given by a matrix $P$ of size $M \\times N$. The company's goal is to identify a rec... | 0.576959 | Apps_3567 | C | [
"max_sum_subgrid",
"kadane",
"process_input"
] | 3 | [
[
"max_sum_subgrid",
"kadane"
]
] | 1 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | 4994d9cf997a48c9994cd3ae51b38edfa3dad1cc | 681b6b134f686528eeb87112a36a380cc5062ae5 | |||
v1.0 | complete | Apps | Apps_2355_C | def solve_inversions(num_cases: int, test_cases: List[Tuple[int, List[int]]]) -> List[int]:
""" Calculate the number of inversions in an array for each test case.
An inversion is when for any indices i and j (1 ≤ i < j ≤ N), arr[i] > arr[j].
Args:
num_cases (int): The number of test cases.
test_cas... | def merge_and_count(arr, temp_arr, left, right):
if left >= right:
return 0
mid = (left + right) // 2
inv_count = merge_and_count(arr, temp_arr, left, mid)
inv_count += merge_and_count(arr, temp_arr, mid + 1, right)
inv_count += merge_and_merge(arr, temp_arr, left, mid, right)
return in... | from solution import solve_inversions
def test_case_1():
test_input = (2, [(5, [2, 4, 1, 3, 5]), (3, [3, 1, 2])])
expected = [3, 2]
assert solve_inversions(*test_input) == expected
def test_case_2():
test_input = (1, [(4, [4, 3, 2, 1])])
expected = [6]
assert solve_inversions(*test_input) =... | [
{
"docstring": null,
"function_declaration": "def merge_and_count(arr, temp_arr, left, right):",
"function_name": "merge_and_count",
"parameter_list": "(arr, temp_arr, left, right)"
},
{
"docstring": null,
"function_declaration": "def merge_and_merge(arr, temp_arr, left, mid, right):",
... | [
1,
1,
0,
1,
0,
0,
1,
0,
0
] | 4 | medium | 0.444 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def count_inversions(arr):\n \"\"\"\n Function to count inversions in an array using modified merge sort.\n \"\"\"\n # Helper function for merge sort to... | trial_gpt4o_4 | {
"original_instruction": "Calculate Inversions\n\nGiven an array of integers, an inversion occurs if for any indices `i` and `j` (1 ≤ i < j ≤ N), `arr[i]` > `arr[j]`. \n\nYour task is to count the number of inversions in a given array.\n\n-----Input:-----\nThe first line of the input contains a single integer `T`, t... | 0.787803 | Apps_2355 | C | [
"merge_and_count",
"merge_and_merge",
"count_inversions",
"solve_inversions"
] | 4 | [
[
"count_inversions",
"merge_and_count"
],
[
"merge_and_count",
"merge_and_merge"
],
[
"solve_inversions",
"count_inversions"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 09669147b68a51804bf606ae03e792aaa378a1ee | 8504ac3f11cbfcf6fedc770e74de3949d18f1bbd | |||
v1.0 | complete | Apps | Apps_4145_C | def sum_of_digits(num):
"""
Returns the sum of the digits of the given number.
"""
pass
def transform_array(arr):
"""
Transforms the given array according to the described rule:
Each element at index i is replaced by the sum of its digits raised to the power of i.
>>> transform_arr... | def sum_of_digits(num):
"""
Returns the sum of the digits of the given number.
"""
return sum(int(digit) for digit in str(num))
def transform_array(arr):
"""
Transforms the given array according to the described rule:
Each element at index i is replaced by the sum of its digits raised to th... | from solution import transform_array
def test_single_element():
assert transform_array([3]) == [1]
def test_two_elements():
assert transform_array([3, 25]) == [1, 7]
def test_three_elements():
assert transform_array([3, 25, 18]) == [1, 7, 81]
def test_empty_list():
assert transform_array([]) == []
... | [
{
"docstring": "Returns the sum of the digits of the given number.",
"function_declaration": "def sum_of_digits(num):",
"function_name": "sum_of_digits",
"parameter_list": "(num)"
},
{
"docstring": "Transforms the given array according to the described rule:\nEach element at index i is repla... | [
0,
0,
0,
0,
0,
0,
0,
0,
1,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def sum_of_digits_power(arr):\n \"\"\"\n This function takes an array of positive integers and returns an array\n where each element is replaced by the sum... | trial_gpt4o_8 | {
"original_instruction": "Write a function that takes an array of positive integers and returns an array where each element is replaced by the sum of its digits raised to the power of its position in the array (0-indexed). For example, given the input array `[3, 25, 18]`, the output should be `[3^0, (2+5)^1, (1+8)^2... | 0.694233 | Apps_4145 | C | [
"sum_of_digits",
"transform_array"
] | 2 | [
[
"transform_array",
"sum_of_digits"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | cf13e509259fa76cf13ddab0fe3ebe80c384d096 | 4e4cad8a17a97b34dcca59c79d0abd993da17b69 | |||
v1.0 | complete | Apps | Apps_4201_C | def max_non_adjacent_sum(nums: List[int]) -> int:
""" Returns the maximum sum of a subsequence such that no two elements are adjacent.
>>> max_non_adjacent_sum([3, 2, 5, 10, 7])
15
>>> max_non_adjacent_sum([1, 2, 3])
4
>>> max_non_adjacent_sum([-1, 4, -5, 4, 10])
14
>>> max_non_adjacent_... | def max_non_adjacent_sum(nums):
"""
Returns the maximum sum of a subsequence such that no two elements are adjacent.
"""
if not nums:
return 0
incl = 0 # Max sum including the previous element
excl = 0 # Max sum excluding the previous element
for num in nums:
# Cu... | from solution import max_non_adjacent_sum, solve_problem
def test_max_non_adjacent_sum_example():
assert solve_problem(6, [3, 2, 5, 10, 7]) == 15
def test_max_non_adjacent_sum_small():
assert solve_problem(3, [1, 2, 3]) == 4
def test_max_non_adjacent_sum_all_positive():
assert solve_problem(4, [4, 1, 2, ... | [
{
"docstring": "Returns the maximum sum of a subsequence such that no two elements are adjacent.",
"function_declaration": "def max_non_adjacent_sum(nums):",
"function_name": "max_non_adjacent_sum",
"parameter_list": "(nums)"
},
{
"docstring": null,
"function_declaration": "def solve_pro... | [
1,
0,
0,
0,
1,
0,
0,
0,
0,
1
] | 3 | hard | 0.3 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_non_adjacent_sum(nums):\n \"\"\"\n Returns the maximum sum of a subsequence such that no two elements are adjacent.\n \"\"\"\n if not nums:\n ... | trial_gpt4o_0 | {
"original_instruction": "Alice loves playing with numbers and she came up with a puzzle game. She gives her friends a list of integers and challenges them to find the maximum sum of a subsequence with the constraint that no two elements in the subsequence should be adjacent in the original list. Your task is to imp... | 0.702561 | Apps_4201 | C | [
"max_non_adjacent_sum",
"solve_problem"
] | 2 | [
[
"solve_problem",
"max_non_adjacent_sum"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6865980a836191e8266c810e06e54bb060aaec46 | b78964bb7465240ef70d1b01e6dc573a4f0c1f34 | |||
v1.0 | complete | Apps | Apps_3429_C | from typing import List
def shortest_path(grid: List[List[int]]) -> int:
""" Implement a simplified version of the A* algorithm to find the shortest path for navigating a robot in a 2D grid.
The robot starts at (0, 0) and needs to reach the bottom-right corner (n-1, n-1). The cells marked as 0 are walkabl... | from heapq import heappush, heappop
from typing import List, Tuple
def manhattan_distance(x1: int, y1: int, x2: int, y2: int) -> int:
return abs(x1 - x2) + abs(y1 - y2)
def shortest_path(grid: List[List[int]]) -> int:
n = len(grid)
if grid[0][0] == 1 or grid[n-1][n-1] == 1:
return -1
... | def test_shortest_path():
assert shortest_path([[0,0,0], [0,1,0], [0,0,0]]) == 4
assert shortest_path([[0,1], [1,0]]) == -1
assert shortest_path([[0,0,1], [1,0,1], [1,0,0]]) == 4
assert shortest_path([[0]]) == 0
assert shortest_path([[1,0,0], [0,1,0], [0,0,0]]) == -1
assert shortest_path([[0,1,1... | [
{
"docstring": null,
"function_declaration": "def manhattan_distance(x1, y1, x2, y2):",
"function_name": "manhattan_distance",
"parameter_list": "(x1, y1, x2, y2)"
},
{
"docstring": null,
"function_declaration": "def shortest_path(grid):",
"function_name": "shortest_path",
"param... | [
1,
1,
0,
0,
1,
0,
1,
1,
0,
0
] | 5 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\nfrom typing import List, Tuple\n\ndef heuristic(x: int, y: int, goal_x: int, goal_y: int) -> int:\n return abs(x - goal_x) + abs(y - goal_y)\n\ndef... | trial_gpt4o_7 | {
"original_instruction": "Your task is to implement a simplified version of the A* algorithm for navigating a robot in a 2D grid. The robot starts at position `(0,0)` of the grid and needs to reach the bottom-right corner `(n-1, n-1)`.\n\nThe grid contains cells marked as `0` (walkable) and `1` (obstacle). The robot... | 0.667845 | Apps_3429 | C | [
"manhattan_distance",
"shortest_path"
] | 2 | [
[
"shortest_path",
"manhattan_distance"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | fa8e246f2ccd953883523aa5545121d12b4374e0 | b944b0f2fa7f96cb8702ce72be7f40e14f046937 | |||
v1.0 | complete | Apps | Apps_4286_C | import math
from typing import List
def replace_with_largest_prime_factor(arr: List[int]) -> List[int]:
""" Write a function that takes an array of integers and returns a new array consisting of all the positive integers in the original array, each replaced by the largest prime factor of that integer. If the integ... | import math
def largest_prime_factor(n):
if n <= 1:
return None
while n % 2 == 0:
max_prime = 2
n //= 2
for i in range(3, int(math.sqrt(n)) + 1, 2):
while n % i == 0:
max_prime = i
n //= i
if n > 2:
max_prime = n
return ... | from solution import replace_with_largest_prime_factor
def test_replace_with_largest_prime_factor():
assert replace_with_largest_prime_factor([10, -7, 15, 0, 33]) == [5, -7, 5, 0, 11]
assert replace_with_largest_prime_factor([20, 25, 77, 8, 100]) == [5, 5, 11, 2, 5]
assert replace_with_largest_prime_factor... | [
{
"docstring": null,
"function_declaration": "def largest_prime_factor(n):",
"function_name": "largest_prime_factor",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def replace_with_largest_prime_factor(arr):",
"function_name": "replace_with_largest_prime_fa... | [
1,
1,
1,
0,
0,
1,
1,
0,
1,
1
] | 7 | easy | 0.7 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef largest_prime_factor(n):\n \"\"\"\n Helper function to find the largest prime factor of a given positive integer n.\n \"\"\"\n larges... | trial_gpt4o_8 | {
"original_instruction": "Write a function that takes an array of integers and returns a new array consisting of all the positive integers in the original array, each replaced by the largest prime factor of that integer. If the integer is negative or zero, the output array should have the integer unchanged at its co... | 0.743088 | Apps_4286 | C | [
"largest_prime_factor",
"replace_with_largest_prime_factor"
] | 2 | [
[
"replace_with_largest_prime_factor",
"largest_prime_factor"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | fb97b3ef85a24702f56d456ea5d42f5bbd7f456a | 9e2d517d18799527f859d77b8919014dd2590b6b | |||
v1.0 | complete | Apps | Apps_4054_C | def is_valid_mountain(heights) -> str:
""" Determine if the given height pattern is valid according to the mountain range rules.
>>> is_valid_mountain([1, 2, 3, 2, 1]) == "valid"
>>> is_valid_mountain([1, 1, 1, 2, 1, 1]) == "invalid"
>>> is_valid_mountain([1, 2, 4, 2, 1]) == "valid"
>>> is_valid_mou... | def is_valid_mountain(heights):
n = len(heights)
if n < 3 or heights[0] != 1 or heights[-1] != 1:
return "invalid"
peak_found = False
for i in range(1, n):
if peak_found:
if heights[i] > heights[i-1]:
return "invalid"
else:
if heights[i] ... | def test_is_valid_mountain_valid():
assert is_valid_mountain([1, 2, 3, 2, 1]) == "valid"
assert is_valid_mountain([1, 2, 4, 2, 1]) == "valid"
def test_is_valid_mountain_invalid():
assert is_valid_mountain([1, 1, 1, 2, 1, 1]) == "invalid"
assert is_valid_mountain([1, 2, 1, 2]) == "invalid"
assert is... | [
{
"docstring": null,
"function_declaration": "def is_valid_mountain(heights):",
"function_name": "is_valid_mountain",
"parameter_list": "(heights)"
},
{
"docstring": null,
"function_declaration": "def validate_rails(R, rails):",
"function_name": "validate_rails",
"parameter_list"... | [
0,
0,
0,
0,
1,
0,
0,
0,
0,
1
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def check_mountain_range_patterns(R, patterns):\n results = []\n \n for pattern in patterns:\n N, heights = pattern\n if heights[0] != 1 or h... | trial_gpt4o_4 | {
"original_instruction": "A new roller coaster is being built in the amusement park. The challenge is to design the height pattern of the rails such that they make the ride thrilling. The height pattern should mimic a 'mountain range'. Let's break it down:\n\n- The rail height should start at 1, increase to a peak, ... | 0.547082 | Apps_4054 | C | [
"is_valid_mountain",
"validate_rails"
] | 2 | [
[
"validate_rails",
"is_valid_mountain"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | f59fdce36c46f8eddbdd5b3bd7298be1036de350 | edb21d1b52e87b0f5ed9e4d8a6a38c261034bf1b |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.