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_19406_C | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def build_tree(nodes):
tree_nodes = [None] + [TreeNode(val=x[0]) for x in nodes] # create a list of nodes
for i, (v, l, r) in enumerate(nodes, start=1):
if l... | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def build_tree(nodes):
tree_nodes = [None] + [TreeNode(val=x[0]) for x in nodes] # create a list of nodes
for i, (v, l, r) in enumerate(nodes, start=1):
if l... | import pytest
from solution import max_sum_path
def test_max_sum_path():
nodes = [
(1, 2, 3), # Node 1 with children 2 and 3
(2, -1, -1), # Node 2 is a leaf
(3, 4, -1), # Node 3 with left child 4
(4, 5, -1), # Node 4 with left child 5
(5, -1, -1) # Node 5 is a leaf... | [] | [
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": "class TreeNode:\n def __init__(self, value):\n self.value = value\n self.left = None\n self.right = None\n\ndef build_tree(node_descriptions... | trial_gpt4o_7 | {
"original_instruction": "In a binary tree, each node contains an integer value. You are to determine the maximum sum of node values from any leaf node to the root node. Given such a binary tree, the path must start at a leaf node and end at the root node. A leaf node is defined as a node with no children.\n\n-----I... | 0.628469 | Apps_19406 | C | [
"build_tree",
"max_sum_leaf_to_root",
"max_sum_path"
] | 3 | [
[
"max_sum_path",
"build_tree"
],
[
"max_sum_path",
"max_sum_leaf_to_root"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 4227403e84e6fd67fa3dadf98cab4e73a9363965 | 1550e9f8bff89104ac1be02645f00ec56e538564 | |||
v1.0 | complete | Apps | Apps_19585_C | def categorize_numbers(numbers):
"""
Categorizes numbers into prime, composite, or neither.
Parameters:
numbers (list of int): List of positive integers to categorize.
Returns:
dict: A dictionary with keys 'prime', 'composite', and 'neither'.
Each key maps to ... | from math import isqrt
def is_prime(n):
"""
Helper function to determine if a number is prime.
Returns True if the number is prime, otherwise False.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i... | from solution import categorize_numbers
def test_numbers_mixed_categories():
result = categorize_numbers([2, 3, 4, 5, 1, 0, 15, 23, 25])
assert result == {
'prime': [2, 3, 5, 23],
'composite': [4, 15, 25],
'neither': [1, 0]
}
def test_composite_only():
result = categorize_numbe... | [
{
"docstring": "Helper function to determine if a number is prime.\nReturns True if the number is prime, otherwise False.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Categorizes numbers into prime, composite, or neithe... | [
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 math import isqrt\n\ndef is_prime(n):\n \"\"\"\n Helper function to determine if a number is prime.\n Returns True if the number is prime, otherwise F... | trial_gpt4o_0 | {
"original_instruction": "## **Instructions**\n\nYou are tasked to write a function that takes in an array of positive integers and returns an object (or dictionary) that categorizes each input number into `prime`, `composite`, or `neither`.\n\n1. **Prime numbers:** Numbers greater than 1 that have only two divisors... | 0.54146 | Apps_19585 | C | [
"is_prime",
"categorize_numbers"
] | 2 | [
[
"categorize_numbers",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8b568a4c58bcefc96ca8c65b7d18112f85b5cc29 | 78ae8ce2a82a6c6a0b7e0988f66c3d83cbe2c953 | |||
v1.0 | complete | Apps | Apps_19925_C | def minimize_max_partition_sum(arr: List[int], k: int) -> int:
""" Returns the minimized maximum subset sum when partitioning the array into k subsets.
>>> minimize_max_partition_sum([1, 2, 3, 4, 5], 2) == 9
>>> minimize_max_partition_sum([7, 2, 5, 10, 8], 2) == 18
>>> minimize_max_partition_sum([1, 2, ... | def can_partition(arr, k, max_sum):
"""
Helper function to check whether we can partition the array into k subsets
with each subset's sum not exceeding max_sum.
"""
current_sum = 0
count = 1
for num in arr:
if current_sum + num > max_sum:
count += 1
current_su... | from solution import minimize_max_partition_sum
def test_example_1():
arr = [1, 2, 3, 4, 5]
k = 2
assert minimize_max_partition_sum(arr, k) == 9
def test_example_2():
arr = [7, 2, 5, 10, 8]
k = 2
assert minimize_max_partition_sum(arr, k) == 18
def test_example_3():
arr = [1, 2, 3, 4]
... | [
{
"docstring": "Helper function to check whether we can partition the array into k subsets\nwith each subset's sum not exceeding max_sum.",
"function_declaration": "def can_partition(arr, k, max_sum):",
"function_name": "can_partition",
"parameter_list": "(arr, k, max_sum)"
},
{
"docstring":... | [
0,
1,
0,
1,
0,
0,
1,
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 can_partition(arr, k, max_sum):\n def _can_partition(start, k, current_sum, subsets):\n if k == 0:\n return True\n if current_sum > ... | trial_gpt4o_6 | {
"original_instruction": "## Task\n\nYou are given an integer array `arr` and a positive integer `k`. Your goal is to partition the array into `k` subsets such that the maximum subset sum is minimized. Your task is to complete the function which returns the minimized maximum subset sum.\n\n### Notes:\n\n- The number... | 0.665284 | Apps_19925 | C | [
"can_partition",
"minimize_max_partition_sum"
] | 2 | [
[
"minimize_max_partition_sum",
"can_partition"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d8c79feec037e37e54751af162e4212243280b61 | 728b2f830a03514306b577bfba3c28045b95dd60 | |||
v1.0 | complete | Apps | Apps_6491_C | class TreeNode:
def __init__(self, key):
self.left = None
self.right = None
self.val = key
def insert(node, key):
"""
Inserts a new node with the given key into the BST.
"""
if node is None:
return TreeNode(key)
if key < node.val:
node.left = insert(... | class TreeNode:
def __init__(self, key):
self.left = None
self.right = None
self.val = key
def insert(node, key):
"""
Inserts a new node with the given key into the BST.
"""
if node is None:
return TreeNode(key)
if key < node.val:
node.left = insert(... | from solution import bst_depth
def test_bst_depth_simple():
assert bst_depth(6, [3, 1, 4, 2, 5, 6]) == 3
def test_bst_depth_single_element():
assert bst_depth(1, [5]) == 0
def test_bst_depth_sorted_increasing():
assert bst_depth(5, [1, 2, 3, 4, 5]) == 4
def test_bst_depth_sorted_decreasing():
assert... | [] | [
0,
1,
0,
1,
1,
0,
0,
1,
0,
1
] | 5 | medium | 0.5 | {
"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\nclass BinarySearchTree:\n def __ini... | trial_gpt4o_1 | {
"original_instruction": "Leo is interested in data structures and recently learned about binary search trees (BST). He wants to add a series of numbers to an initially empty binary search tree and calculate the depth of the resulting tree. The depth of a binary search tree is defined as the number of edges in the l... | 0.533311 | Apps_6491 | C | [
"insert",
"max_depth",
"bst_depth"
] | 3 | [
[
"bst_depth",
"insert"
],
[
"bst_depth",
"max_depth"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | c925e6b1406a1665324855b1c35fd4a434e5d39c | c59a66b0846b6ade9501722ea10db1af4c2b794b | |||
v1.0 | complete | Apps | Apps_6717_C | def is_prime(n: int) -> bool:
""" Check if a number is a prime number.
>>> is_prime(2) True
>>> is_prime(3) True
>>> is_prime(4) False
>>> is_prime(5) True
>>> is_prime(9) False
"""
def filter_primes(lst: List[int]) -> List[int]:
""" Filter the prime numbers from a list of integers.... | def is_prime(n):
"""
Check if a number is a prime number.
:param n: Integer, the number to check.
:return: Boolean, True if the number is prime, otherwise False.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5... | from solution import is_prime, filter_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(9) == False
assert is_prime(11) == True
assert is_prime(1) == False
assert is_prime(0) == False
... | [
{
"docstring": "Check if a number is a prime number.\n:param n: Integer, the number to check.\n:return: Boolean, True if the number is prime, otherwise False.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Filter the prim... | [
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": "def is_prime(n):\n \"\"\"\n Checks if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 ... | trial_gpt4o_9 | {
"original_instruction": "Implement a function that takes a list of integers and returns a list containing only the elements that are prime numbers. If the input list is empty or no prime numbers are found, return an empty list.\n\n**Steps**:\n1. Create a helper function `is_prime` which checks if a number is a prim... | 0.748228 | Apps_6717 | C | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7b56f6ca3af7d30a57a451c7c3239196e1657d1c | 96607787e86cd43f5087c4ae3a7f6aa8f3aa9805 | |||
v1.0 | complete | Apps | Apps_6953_C | def is_carmichael(n: int) -> bool:
""" Check if the given integer n is a Carmichael number.
>>> is_carmichael(561)
True
>>> is_carmichael(1105)
True
>>> is_carmichael(1729)
True
>>> is_carmichael(15)
False
>>> is_carmichael(17)
False
""" | import math
def is_prime(n):
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return True
def gcd(a, b):
while b:
... | from solution import is_carmichael
def test_is_carmichael_true_cases():
assert is_carmichael(561) == True
assert is_carmichael(1105) == True
assert is_carmichael(1729) == True
assert is_carmichael(2465) == True
assert is_carmichael(2821) == True
def test_is_carmichael_false_cases():
assert is_... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def gcd(a, b):",
"function_name": "gcd",
"parameter_list": "(a, b)"
},
{
"docstring": null,
"function... | [
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 math import gcd\n\ndef is_prime(n):\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n retur... | trial_gpt4o_9 | {
"original_instruction": "Complete the function that checks if a given integer `n` is a Carmichael number. A Carmichael number is a composite number `n` that satisfies Fermat's little theorem for every integer `a` that is coprime to `n`, that is: \n\n```\npow(a, n-1, n) == 1\n```\n\nfor all integers `a` with `1 < a ... | 0.643059 | Apps_6953 | C | [
"is_prime",
"gcd",
"is_carmichael"
] | 3 | [
[
"is_carmichael",
"gcd"
],
[
"is_carmichael",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | b980b60fbe6b7f5b174e2861a522e91ba7d04bb1 | 5e947fafd7f827dab764265e7526befd9e109c93 | |||
v1.0 | complete | Apps | Apps_7573_C | def extractDomain(email: str) -> str:
""" Returns the domain part of the email address.
>>> extractDomain("user@example.com")
'example.com'
>>> extractDomain("admin@domain.org")
'domain.org'
"""
pass
def extractDomainsFromList(emails: list[str]) -> list[str]:
""" Returns a list of domai... | def extractDomain(email):
"""
Returns the domain part of the email address.
Parameters:
email (str): The email address from which to extract the domain.
Returns:
str: The domain part of the email.
"""
return email.split('@')[1]
def extractDomainsFromList(emails):
"""
R... | from solution import extractDomain, extractDomainsFromList
def test_extractDomain_single_email():
assert extractDomain("user@example.com") == "example.com"
assert extractDomain("admin@domain.org") == "domain.org"
assert extractDomain("someone@gmail.com") == "gmail.com"
assert extractDomain("contact@sub... | [
{
"docstring": "Returns the domain part of the email address.\n\nParameters:\nemail (str): The email address from which to extract the domain.\n\nReturns:\nstr: The domain part of the email.",
"function_declaration": "def extractDomain(email):",
"function_name": "extractDomain",
"parameter_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 extractDomain(email):\n \"\"\"\n Extracts the domain from a single email address.\n :param email: A string representing an email address.\n :return:... | trial_gpt4o_9 | {
"original_instruction": "# Domain Extractor from Email Address\n\n## Overview\n\nEmail addresses often contain domains that can be useful for various purposes such as categorization or validation. A domain in an email address is the part after the '@' symbol up to the last dot '.'.\n\n## Task\n\nDefine two function... | 0.633301 | Apps_7573 | C | [
"extractDomain",
"extractDomainsFromList"
] | 2 | [
[
"extractDomainsFromList",
"extractDomain"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 19f3daaa1ea33aa7e365260d6c19aeef35688582 | 5fde01f65b7e90bfa671abcfcc51bd92d37988a9 | |||
v1.0 | complete | Apps | Apps_7770_C | def is_prime_digit(char):
""" Returns True if the provided character represents a prime digit (2, 3, 5, 7), otherwise False.
>>> is_prime_digit('2')
True
>>> is_prime_digit('4')
False
"""
pass
def all_prime_digits(num_str):
""" Determines if all digits in the given string represent prim... | def is_prime_digit(char):
"""
Returns True if the provided character represents a prime digit (2, 3, 5, 7), otherwise False.
"""
return char in {'2', '3', '5', '7'}
def all_prime_digits(num_str):
"""
Determines if all digits in the given string represent prime digits.
"""
for char in nu... | from solution import check_prime_digits
def test_check_prime_digits_all_prime():
test_cases = ["235", "357", "222"]
expected = ["YES", "YES", "YES"]
assert check_prime_digits(test_cases) == expected
def test_check_prime_digits_with_non_prime():
test_cases = ["124", "678", "123456789"]
expected = [... | [
{
"docstring": "Returns True if the provided character represents a prime digit (2, 3, 5, 7), otherwise False.",
"function_declaration": "def is_prime_digit(char):",
"function_name": "is_prime_digit",
"parameter_list": "(char)"
},
{
"docstring": "Determines if all digits in the given string ... | [
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": "def is_prime_digit(digit):\n \"\"\"\n Checks if a digit is a prime digit (2, 3, 5, 7).\n \"\"\"\n prime_digits = {'2', '3', '5', '7'}\n return digit ... | trial_gpt4o_9 | {
"original_instruction": "Given an array of integers, determine if each integer in the array is composed of only prime digits (2, 3, 5, 7). Return \"YES\" if all digits are prime, otherwise return \"NO\".\n\n-----Input-----\nThe first line of the input contains an integer T denoting the number of test cases. The des... | 0.800708 | Apps_7770 | C | [
"is_prime_digit",
"all_prime_digits",
"check_prime_digits"
] | 3 | [
[
"all_prime_digits",
"is_prime_digit"
],
[
"check_prime_digits",
"all_prime_digits"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | c4f95ed9f49b1edeaf5a9de37c3cf041374b4554 | 2763a5d8a3cac6945f8e68dbf078573ee337bb3c | |||
v1.0 | complete | Apps | Apps_7361_C | from typing import List
def square_primes(numbers: List[int]) -> List[int]:
"""
Write a function that takes a list of integers as input and returns the list with all prime numbers replaced by their squares.
If no prime numbers are found in the list, the function should return the original list.
>... | 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 <= 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... | from solution import square_primes
def test_square_primes_with_primes():
assert square_primes([4, 7, 10, 11]) == [4, 49, 10, 121]
def test_square_primes_with_no_primes():
assert square_primes([1, 4, 6, 8]) == [1, 4, 6, 8]
def test_square_primes_all_primes():
assert square_primes([2, 3, 5, 7, 11]) == [4, ... | [
{
"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 list with prime numbers replaced by their squares.",
"function_declaration": "def square_primes(n... | [
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": "from typing import List\n\ndef is_prime(n: int) -> bool:\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if n <= 1:\n return... | trial_gpt4o_9 | {
"original_instruction": "Write a function that takes a list of integers as input and returns the list with all prime numbers replaced by their squares. If no prime numbers are found in the list, the function should return the original list.\n\n### Example:\n\n```python\ninput: [4, 7, 10, 11]\noutput: [4, 49, 10, 12... | 0.708614 | Apps_7361 | C | [
"is_prime",
"square_primes"
] | 2 | [
[
"square_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 2ef84f44fffea3f3af9932ab3987827dacf720b8 | e8ea80c36035a684aa5b48589e262c8a67580f7a | |||
v1.0 | complete | Apps | Apps_7862_C | from typing import List
def isValidWord(word: str) -> bool:
"""
Placeholder for the actual implementation of the validation function.
"""
# The actual implementation will check if the word is a valid English word.
return word in {"apple", "bag", "bog", "bug"}
def possibleValidWords(input_string: s... | from typing import List
import string
def isValidWord(word: str) -> bool:
"""
Placeholder for the actual implementation of the validation function.
"""
# The actual implementation will check if the word is a valid English word.
# This mock implementation always returns True for simplicity.
# In... | from solution import possibleValidWords, isValidWord
def test_isValidWord():
assert isValidWord("apple")
assert isValidWord("bag")
assert isValidWord("bog")
assert isValidWord("bug")
assert not isValidWord("abcd")
def test_possibleValidWords_with_single_placeholder():
assert possibleValidWords... | [
{
"docstring": "Placeholder for the actual implementation of the validation function.",
"function_declaration": "def isValidWord(word):",
"function_name": "isValidWord",
"parameter_list": "(word)"
},
{
"docstring": null,
"function_declaration": "def generate_possible_words(input_string, ... | [
0,
0,
0,
1,
1,
1,
1,
0,
0,
0
] | 4 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from typing import List\n\n# Assuming we have helper function `isValidWord` implemented.\ndef isValidWord(word: str) -> bool:\n \"\"\"\n Placeholder function.... | trial_gpt4o_6 | {
"original_instruction": "Given an input string that contains lowercase alphabetic characters and one or more special placeholders denoted by `?`, generate all possible strings by replacing each placeholder with a lowercase alphabetic character such that the resulting strings represent valid English words. \n\nYou a... | 0.691203 | Apps_7862 | C | [
"isValidWord",
"generate_possible_words",
"possibleValidWords"
] | 3 | [
[
"generate_possible_words",
"isValidWord"
],
[
"possibleValidWords",
"generate_possible_words"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | e09a88c70237c53090b08ea88d57bced325f926a | a033201de964c1f8a04a3025c35930a930d498b1 | |||
v1.0 | complete | Apps | Apps_7558_C | from typing import List
def is_prime(n: int) -> bool:
""" Helper function to check if a number is prime.
>>> is_prime(2)
True
>>> is_prime(3)
True
>>> is_prime(4)
False
>>> is_prime(5)
True
>>> is_prime(1)
False
>>> is_prime(0)
False
>>> is_prime(-1)
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 is_prime, filter_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
assert is_prime(0) == False
assert is_prime(-1) == False
assert is_prime(17) == True... | [
{
"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 list of prime numbers from the given list of integers.",
"function_declaration": "def filter_prim... | [
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_9 | {
"original_instruction": "Write a function that takes a list of integers and returns a new list containing only the prime numbers from the input list. \n\n~~~if:python\nYou may use a helper function to determine if a number is prime. Assume the input list can be empty or contain up to 1000 integers.\n~~~\n\n~~~if:bf... | 0.774979 | Apps_7558 | C | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 062461076f744cf187cea184775713675c4cee13 | 9a3d3870b14a9aa3dff082ef39fba5ceab61e387 | |||
v1.0 | complete | Apps | Apps_7681_C | MOD = 1_000_000_007
def factorial(n):
""" Calculate the factorial of n % MOD """
if n == 0 or n == 1:
return 1
result = 1
for i in range(2, n+1):
result = (result * i) % MOD
return result
def count_sequences(L, A, B):
"""
Calculate the number of distinct sequences of lengt... | MOD = 1_000_000_007
def factorial(n):
if n == 0 or n == 1:
return 1
result = 1
for i in range(2, n+1):
result = (result * i) % MOD
return result
def count_sequences(L, A, B):
n = B - A + 1 # number of elements in the range [A, B]
if L > n:
return 0
# Calculate... | import pytest
from solution import count_sequences, read_input, solve
def test_count_sequences():
assert count_sequences(3, 1, 5) == 60
assert count_sequences(4, 10, 15) == 360
assert count_sequences(5, 20, 25) == 720
assert count_sequences(2, 5, 6) == 2
assert count_sequences(3, 5, 5) == 0 # edge... | [
{
"docstring": null,
"function_declaration": "def factorial(n):",
"function_name": "factorial",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def count_sequences(L, A, B):",
"function_name": "count_sequences",
"parameter_list": "(L, A, B)"
},
{
... | [
1,
1,
1,
1,
0,
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 count_sequences(Q, cases):\n MOD = 1_000_000_007\n\n def factorial(n):\n if n == 0:\n return 1\n result = 1\n for i in ran... | trial_gpt4o_5 | {
"original_instruction": "-----Problem Statement-----\nJohn is interested in sequences. Specifically, he is curious about sequences of integers where all elements of the sequence must be distinct and each integer in the sequence must lie within a given range. He wants to know how many such sequences of a given lengt... | 0.668129 | Apps_7681 | C | [
"factorial",
"count_sequences",
"solve",
"read_input"
] | 4 | [
[
"count_sequences",
"factorial"
],
[
"solve",
"count_sequences"
]
] | 2 | [
"read_input"
] | false | [] | false | pytest | true | [] | true | ead83866869f097d7806863beb9944078cdcdd8a | c30b1384cc3f03fdacbdef3a144522a51dc546e9 | |||
v1.0 | complete | Apps | Apps_8949_C | import math
from typing import List
def is_perfect_square(n: int) -> bool:
"""
Helper function to check if a number is a perfect square.
"""
if n < 0:
return False
root = int(math.sqrt(n))
return n == root * root
def get_perfect_squares(lst: List[int]) -> List[int]:
"""
Return... | import math
def is_perfect_square(n):
"""
Helper function to check if a number is a perfect square.
"""
if n < 0:
return False
root = int(math.sqrt(n))
return n == root * root
def get_perfect_squares(lst):
"""
Returns a list of perfect squares from the given list of integers.
... | from solution import get_perfect_squares
def test_no_perfect_squares():
assert get_perfect_squares([2, 3, 5, 6, 7]) == []
def test_mixed_numbers():
assert get_perfect_squares([1, 2, 3, 4, 5]) == [1, 4]
def test_all_perfect_squares():
assert get_perfect_squares([1, 4, 9, 16, 25]) == [1, 4, 9, 16, 25]
def... | [
{
"docstring": "Helper function to check if a number is a perfect square.",
"function_declaration": "def is_perfect_square(n):",
"function_name": "is_perfect_square",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list of perfect squares from the given list of integers.",
"function... | [
1,
1,
1,
1,
0,
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 find_perfect_squares(nums):\n \"\"\"\n Returns a list of perfect squares from the given list of integers.\n \"\"\"\n perfect_squares ... | trial_gpt4o_9 | {
"original_instruction": "Design a function that takes a list of integers and returns a list of those integers which are perfect squares. \n\nA perfect square is a number that can be expressed as the product of an integer with itself. For example, `1, 4, 9, 16, 25` are perfect squares `(1*1, 2*2, 3*3, 4*4, 5*5)`.\n\... | 0.713694 | Apps_8949 | C | [
"is_perfect_square",
"get_perfect_squares"
] | 2 | [
[
"get_perfect_squares",
"is_perfect_square"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b55903f7f7a34d8a04875c7c915f75f1c84bb41f | 0ada2d4fcb0015db9480ef9cc7888447bb93222b | |||
v1.0 | complete | Apps | Apps_9288_C | def getLongestPalindrome(s: str) -> str:
"""
Returns the longest palindromic substring in the given string s.
>>> getLongestPalindrome("babad") in ["bab", "aba"]
True
>>> getLongestPalindrome("cbbd")
'bb'
>>> getLongestPalindrome("abcdef")
'a'
>>> getLongestPalindrome("")
'... | def getLongestPalindrome(s):
"""
Returns the longest palindromic substring in the given string s.
"""
n = len(s)
if n == 0:
return ""
longest = s[0]
for i in range(n):
# Check for odd-length palindromes
odd_palindrome = expandFromCenter(s, i, i)
if len(odd_p... | from solution import getLongestPalindrome
def test_getLongestPalindrome():
assert getLongestPalindrome("babad") in ["bab", "aba"]
assert getLongestPalindrome("cbbd") == "bb"
assert getLongestPalindrome("abcdef") == "a"
assert getLongestPalindrome("") == ""
assert getLongestPalindrome("a") == "a"
... | [
{
"docstring": "Returns the longest palindromic substring in the given string s.",
"function_declaration": "def getLongestPalindrome(s):",
"function_name": "getLongestPalindrome",
"parameter_list": "(s)"
},
{
"docstring": "Expands around the center and returns the longest palindromic substri... | [
1,
1,
1,
1,
0,
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 getLongestPalindrome(s):\n \"\"\"\n Returns the longest palindromic substring in a given string s.\n \"\"\"\n if not s:\n return \"\"\n\n ... | trial_gpt4o_8 | {
"original_instruction": "Write a function getLongestPalindrome that will return the longest palindromic substring in a given string. A palindrome is a word that reads the same backward as forward.\n\nE.g 1: For s = \"babad\" the result should be \"bab\" or \"aba\" (both are valid)\nE.g 2: For s = \"cbbd\" the resul... | 0.7464 | Apps_9288 | C | [
"getLongestPalindrome",
"expandFromCenter"
] | 2 | [
[
"getLongestPalindrome",
"expandFromCenter"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ac33ff31d9a8e12a7c4580afe676f5c4e7f6aef3 | 715cba050c73f9a2b134b337be23ca99333f2e5c | |||
v1.0 | complete | Apps | Apps_8309_C | from typing import List
def sum_of_digits(num: int) -> int:
"""
Returns the sum of the digits of the given number.
>>> sum_of_digits(13): 4
>>> sum_of_digits(25): 7
>>> sum_of_digits(83): 11
>>> sum_of_digits(111): 3
>>> sum_of_digits(222): 6
"""
def transform(nums: List[int]) -> List... | def sum_of_digits(num):
"""
Returns the sum of the digits of the given number.
"""
s = 0
while num > 0:
s += num % 10
num //= 10
return s
def transform(nums):
"""
Transforms the given list of integers by summing the digits of each integer.
"""
return [sum_of_digi... | from solution import sum_of_digits, transform, k_iterations
def test_sum_of_digits():
assert sum_of_digits(13) == 4
assert sum_of_digits(25) == 7
assert sum_of_digits(83) == 11
assert sum_of_digits(111) == 3
assert sum_of_digits(222) == 6
def test_transform():
assert transform([13, 25, 83]) ==... | [
{
"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 list of integers by summing the digits of each integer.",
"function_... | [
0,
0,
1,
0,
0,
1,
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 sum_of_digits(num):\n \"\"\"\n Helper function to sum the digits of a number until a single digit is achieved.\n \"\"\"\n while num > 9:\n nu... | trial_gpt4o_5 | {
"original_instruction": "You are given an integer array `nums` and an integer `k`. You need to perform a series of operations on `nums` to satisfy the following conditions:\n\n1. Sum the digits of each number in `nums`.\n2. Append the resulting sums to a new array.\n3. Perform step 1 for `k` iterations.\n\nYour tas... | 0.664263 | Apps_8309 | C | [
"sum_of_digits",
"transform",
"k_iterations"
] | 3 | [
[
"k_iterations",
"transform"
],
[
"transform",
"sum_of_digits"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 23255b1cc71a55cbfdaf9f68a2e0bc6593910962 | 21c5e03469b212ac38f55d94501a103c413b5af9 | |||
v1.0 | complete | Apps | Apps_9136_C | def book_allocation(test_cases):
"""
You are given a number of books, each with a certain number of pages.
You want to assign these books to exactly k students so that each student gets a contiguous sequence of books.
The goal is to minimize the maximum number of pages assigned to a student.
Input:... | def is_possible(books, n, k, max_pages):
students_required = 1
current_pages = 0
for pages in books:
if current_pages + pages > max_pages:
students_required += 1
current_pages = pages
if students_required > k:
return False
else:
... | from solution import book_allocation
def test_case_1():
test_cases = [{'n': 4, 'k': 2, 'books': [12, 34, 67, 90]}]
assert book_allocation(test_cases) == [113]
def test_case_2():
test_cases = [{'n': 3, 'k': 1, 'books': [15, 20, 25]}]
assert book_allocation(test_cases) == [60]
def test_case_3():
te... | [
{
"docstring": null,
"function_declaration": "def is_possible(books, n, k, max_pages):",
"function_name": "is_possible",
"parameter_list": "(books, n, k, max_pages)"
},
{
"docstring": null,
"function_declaration": "def find_minimum_maximum_pages(books, n, k):",
"function_name": "find... | [
1,
1,
0,
1,
1,
0,
0,
1,
1,
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_valid_distribution(pages, n, k, max_pages):\n students_required = 1\n current_pages_sum = 0\n\n for i in range(n):\n if pages[i] > max_pages:... | trial_gpt4o_7 | {
"original_instruction": "You are given a number of books, each with a certain number of pages. You want to assign these books to exactly $k$ students so that each student gets a contiguous sequence of books. The goal is to minimize the maximum number of pages assigned to a student.\n\n-----Input-----\n\nThe first l... | 0.699448 | Apps_9136 | C | [
"is_possible",
"find_minimum_maximum_pages",
"book_allocation"
] | 3 | [
[
"book_allocation",
"find_minimum_maximum_pages"
],
[
"find_minimum_maximum_pages",
"is_possible"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | f5d704e259a858efc51bf4e756c7ff8fbe47c2ce | 6c6f8e89bf6e77cea9e7194b934d9d3bed1fc5d9 | |||
v1.0 | complete | Apps | Apps_9657_C | from typing import List
def is_prime(n: int) -> bool:
""" Helper function to check if a number is prime.
Args:
n: An integer to check primality.
Returns:
True if n is a prime number, False otherwise.
"""
pass
def get_prime_numbers(numbers: List[int]) -> List[int]:
""" Returns a list c... | def is_prime(n):
"""
Helper function to check if a number is prime.
"""
if n <= 1:
return False
if n == 2:
return True # 2 is a prime number
if n % 2 == 0:
return False # All other even numbers are not primes
for i in range(3, int(n**0.5) + 1, 2):
if n % i =... | from solution import get_prime_numbers
def test_all_prime_numbers():
assert get_prime_numbers([2, 3, 5, 7, 11, 13, 17, 19, 23]) == [2, 3, 5, 7, 11, 13, 17, 19, 23]
def test_no_prime_numbers():
assert get_prime_numbers([4, 6, 8, 10, 12]) == []
def test_mixed_prime_and_non_prime_numbers():
assert get_prime... | [
{
"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 list containing all prime numbers from the input list.",
"function_declaration": "def get_prime_n... | [
1,
1,
1,
1,
1,
0,
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 check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return T... | trial_gpt4o_8 | {
"original_instruction": "Write a function that takes in a list of integers and returns a list containing all the integers that are prime.\n\nFor example:\n\nInput: [10, 15, 3, 7, 19]\n\nOutput: [3, 7, 19]\n\nNote: A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itsel... | 0.807623 | Apps_9657 | C | [
"is_prime",
"get_prime_numbers"
] | 2 | [
[
"get_prime_numbers",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b88df2039c7e968f7447b6585e1ebc7d15094211 | 47435d40df2224827c3b5b9b494743f5350597a1 | |||
v1.0 | complete | Apps | Apps_9215_C | from typing import List
from itertools import permutations
def special_permutation_exists(words: List[str]) -> bool:
""" Determines if there exists a permutation of words where every adjacent
pair of words differs by exactly one character.
>>> special_permutation_exists(["abc", "acc", "bcc"]) == True
... | from itertools import permutations
def differs_by_one_char(w1, w2):
"""
Helper function to determine if two words differ by exactly one character.
"""
if len(w1) != len(w2):
return False
count = 0
for c1, c2 in zip(w1, w2):
if c1 != c2:
count += 1
if coun... | def test_example_1():
words = ["abc", "acc", "bcc"]
assert special_permutation_exists(words) == True
def test_example_2():
words = ["abc", "def"]
assert special_permutation_exists(words) == False
def test_example_3():
words = ["abc", "abe", "aec"]
assert special_permutation_exists(words) == Tr... | [
{
"docstring": "Helper function to determine if two words differ by exactly one character.",
"function_declaration": "def differs_by_one_char(w1, w2):",
"function_name": "differs_by_one_char",
"parameter_list": "(w1, w2)"
},
{
"docstring": "Determines if there exists a permutation of words w... | [
0,
0,
0,
1,
0,
1,
0,
0,
1,
1
] | 4 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from itertools import permutations\n\ndef differ_by_one_char(word1, word2):\n \"\"\"\n Returns True if the two words differ by exactly one character, else Fal... | trial_gpt4o_9 | {
"original_instruction": "You are given a list of strings words containing lowercase English alphabets. A permutation of the list is considered special if every adjacent pair of words in the permutation differ by exactly one character. Two words differ by exactly one character if the length of both words is the same... | 0.647733 | Apps_9215 | C | [
"differs_by_one_char",
"special_permutation_exists"
] | 2 | [
[
"special_permutation_exists",
"differs_by_one_char"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | d44cc46ba3a6491bdab807ea0c2feead04f87556 | 8dfc3843182e92c10390166e371b8c56a58cf167 | |||
v1.0 | complete | Apps | Apps_10413_C | from typing import List
def is_happy_number(n: int) -> bool:
"""
Determines if the provided number n is a happy number.
>>> is_happy_number(19) == True
>>> is_happy_number(20) == False
"""
def determine_happy_numbers(nums: List[int]) -> List[str]:
"""
Checks a list of integers to determine... | def is_happy_number(n):
"""
Determines if the provided number n is a happy number.
"""
def get_next(number):
total_sum = 0
while number > 0:
number, digit = divmod(number, 10)
total_sum += digit * digit
return total_sum
seen_numbers = set()
wh... | from solution import is_happy_number, determine_happy_numbers
def test_is_happy_number_true():
assert is_happy_number(19) == True
def test_is_happy_number_false():
assert is_happy_number(20) == False
def test_determine_happy_numbers():
assert determine_happy_numbers([19, 20]) == ["YES", "NO"]
def test_m... | [
{
"docstring": "Determines if the provided number n is a happy number.",
"function_declaration": "def is_happy_number(n):",
"function_name": "is_happy_number",
"parameter_list": "(n)"
},
{
"docstring": "Checks a list of integers to determine if each is a happy number.\nReturns a list of stri... | [
0,
1,
0,
1,
0,
1,
1,
1,
1
] | 6 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_happy_number(n):\n \"\"\"\n Determine if a number n is a happy number.\n \"\"\"\n seen = set()\n while n not in seen:\n seen.add(n)\n ... | trial_gpt4o_9 | {
"original_instruction": "Given a list of integers, determine if each integer is a 'happy number'. A happy number is defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number equals 1 (where it will stay),... | 0.673734 | Apps_10413 | C | [
"is_happy_number",
"determine_happy_numbers"
] | 2 | [
[
"determine_happy_numbers",
"is_happy_number"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 9bfdf8e535b4bae3fad3d59f5eea83fc46c60bbe | 44c52b9edf7e3cb3496e724061de119d8f5a6661 | |||
v1.0 | complete | Apps | Apps_10823_C | def sum_of_digit_factorials(n: int) -> int:
"""
Write a function that takes an integer n as input and returns the sum of the factorials of its digits. The function should first calculate the factorial for each digit in the number, and then return the sum of these factorials. You are not allowed to use any built... | def factorial(digit: int) -> int:
"""
Returns the factorial of a given digit.
"""
if digit == 0 or digit == 1:
return 1
result = 1
for i in range(2, digit + 1):
result *= i
return result
def sum_of_digit_factorials(n: int) -> int:
"""
Returns the sum of the factorial... | from solution import sum_of_digit_factorials
def test_sum_of_digit_factorials_single_digit():
assert sum_of_digit_factorials(5) == 120
assert sum_of_digit_factorials(0) == 1
def test_sum_of_digit_factorials_multiple_digits():
assert sum_of_digit_factorials(123) == 9
assert sum_of_digit_factorials(405)... | [
{
"docstring": "Returns the factorial of a given digit.",
"function_declaration": "def factorial(digit):",
"function_name": "factorial",
"parameter_list": "(digit)"
},
{
"docstring": "Returns the sum of the factorials of the digits of an integer n.",
"function_declaration": "def sum_of_d... | [
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 factorial(digit: int) -> int:\n \"\"\"\n Returns the factorial of a given digit.\n \"\"\"\n if digit == 0 or digit == 1:\n return 1\n resu... | trial_gpt4o_0 | {
"original_instruction": "Write a function that takes an integer n as input and returns the sum of the factorials of its digits. The function should first calculate the factorial for each digit in the number, and then return the sum of these factorials. You are not allowed to use any built-in factorial function.\n\n... | 0.681639 | Apps_10823 | C | [
"factorial",
"sum_of_digit_factorials"
] | 2 | [
[
"sum_of_digit_factorials",
"factorial"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d94973a78b2efd5fa6c684837da49b4a8a0a8d56 | 10ff6b281cfb12d2167be9b8abf5ffcf8ffb93a4 | |||
v1.0 | complete | Apps | Apps_9842_C | def find_max_happiness(N: int, M: int, happiness: List[int], roads: List[Tuple[int, int, int]]) -> int:
""" Find the maximum possible happiness for a trip from city 1 to city N.
>>> find_max_happiness(4, 4, [3, 2, 5, 10], [(1, 2, 2), (2, 3, 2), (3, 4, 2), (1, 4, 7)])
14
>>> find_max_happiness(2, 1, [1,... | import heapq
def max_happiness(N, M, happiness, roads):
graph = [[] for _ in range(N+1)]
for u, v, cost in roads:
graph[u].append((v, cost))
distance = [float('-inf')] * (N+1)
distance[1] = happiness[0]
pq = [(-happiness[0], 1)]
while pq:
current_happiness, u = heapq.h... | from solution import find_max_happiness
def test_sample():
N = 4
M = 4
happiness = [3, 2, 5, 10]
roads = [(1, 2, 2), (2, 3, 2), (3, 4, 2), (1, 4, 7)]
assert find_max_happiness(N, M, happiness, roads) == 14
def test_single_road():
N = 2
M = 1
happiness = [1, 1000]
roads = [(1, 2, 1)... | [
{
"docstring": null,
"function_declaration": "def max_happiness(N, M, happiness, roads):",
"function_name": "max_happiness",
"parameter_list": "(N, M, happiness, roads)"
},
{
"docstring": null,
"function_declaration": "def find_max_happiness(N, M, happiness, roads):",
"function_name"... | [
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": "import heapq\n\ndef max_happiness(N, M, happiness, roads):\n graph = [[] for _ in range(N + 1)]\n for u, v, cost in roads:\n graph[u].append((v, cost))... | trial_gpt4o_4 | {
"original_instruction": "There are N cities connected by M one-way roads. Each city is numbered from 1 to N and each road connects two cities and has a certain travel cost associated with it. Additionally, each city has a happiness value associated with it which you gain by visiting that city.\n\nYou start at city ... | 0.69271 | Apps_9842 | C | [
"max_happiness",
"find_max_happiness"
] | 2 | [
[
"find_max_happiness",
"max_happiness"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c914e730fbe94eab1eff1c411e3afb5fb6329edb | 0bc90772b82d814679f4e0545399f9b574dd01cd | |||
v1.0 | complete | Apps | Apps_10374_C | def ocean_view_buildings(test_cases):
""" Determine which buildings can view the ocean.
>>> ocean_view_buildings([(6, [4, 2, 3, 1, 5, 8]), (5, [5, 4, 3, 2, 1])])
["6", "1 2 3 4 5"]
"""
def parse_input(input_string):
""" Parse the input string to extract test cases.
>>> parse_input... | def ocean_view_buildings(test_cases):
results = []
for buildings in test_cases:
N, heights = buildings
ocean_view_indexes = []
max_height_so_far = -1
for i in range(N - 1, -1, -1):
if heights[i] > max_height_so_far:
ocean_view_indexes.append(i + 1)
... | import pytest
from solution import ocean_view_buildings, parse_input, ocean_view_buildings_from_input
def test_ocean_view_buildings():
test_cases = [
(6, [4, 2, 3, 1, 5, 8]),
(5, [5, 4, 3, 2, 1]),
]
expected = [
"6",
"1 2 3 4 5"
]
assert ocean_view_buildings(test_cas... | [
{
"docstring": null,
"function_declaration": "def ocean_view_buildings(test_cases):",
"function_name": "ocean_view_buildings",
"parameter_list": "(test_cases)"
},
{
"docstring": null,
"function_declaration": "def parse_input(input_string):",
"function_name": "parse_input",
"param... | [
1,
0,
0,
0,
1,
0,
1,
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 can_view_ocean(N, heights):\n \"\"\"\n Returns indices of buildings that can view the ocean.\n \n Args:\n N : int : Number of buildings\n heig... | trial_gpt4o_6 | {
"original_instruction": "There is a city with N buildings aligned in a straight row, numbered from 1 to N. Each building i has a certain height Hi. A building i can view the ocean if, and only if, there are no buildings taller than building i to its right. In other words, building i can view the ocean if all buildi... | 0.526689 | Apps_10374 | C | [
"ocean_view_buildings",
"parse_input",
"ocean_view_buildings_from_input"
] | 3 | [
[
"ocean_view_buildings_from_input",
"ocean_view_buildings"
],
[
"ocean_view_buildings_from_input",
"parse_input"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 80d750a935cd48f212e07bbfe334433f8b0785e2 | 22253cfeed53b979718b9e0b314428597f886cbe | |||
v1.0 | complete | Apps | Apps_10577_C | def calculate_trip_cost(d, p, r):
"""
Returns the total cost of a taxi trip given the distance d, price per unit distance p, and return price per unit distance r.
The cost includes the trip to the customer's destination and the return trip to the starting location.
>>> calculate_trip_cost(10,... | def calculate_trip_cost(d, p, r):
"""
Returns the total cost of a taxi trip given the distance d, price per unit distance p, and return price per unit distance r.
The cost includes the trip to the customer's destination and the return trip to the starting location.
"""
if d == 0 and p == 0 and r == ... | def test_calculate_trip_cost():
assert calculate_trip_cost(10, 2, 1) == 30
assert calculate_trip_cost(15, 3, 2) == 75
assert calculate_trip_cost(0, 0, 0) == 0 # should return 0 as part of the function condition
assert calculate_trip_cost(1000, 100, 100) == 200000
assert calculate_trip_cost(500, 10,... | [
{
"docstring": "Returns the total cost of a taxi trip given the distance d, price per unit distance p, and return price per unit distance r.\nThe cost includes the trip to the customer's destination and the return trip to the starting location.",
"function_declaration": "def calculate_trip_cost(d, p, r):",
... | [
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 calculate_trip_cost(d, p, r):\n \"\"\"\n Calculate the total cost of a taxi trip.\n \n Parameters:\n d (int): distance from pickup to destination... | trial_gpt4o_9 | {
"original_instruction": "In a city, there is a single taxi service which serves multiple customers every day. Each taxi ride consists of picking up a customer from a specific location, driving to their destination, and then returning to the starting point. The service charges customers based on the total distance t... | 0.57157 | Apps_10577 | C | [
"calculate_trip_cost",
"process_trip_costs"
] | 2 | [
[
"process_trip_costs",
"calculate_trip_cost"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 47730ff025ddc0399fe63a32c1506fffe38a2a94 | 6b20e678c0c992419f0bb040ea4058c1180c4fb6 | |||
v1.0 | complete | Apps | Apps_10444_C | def ranked_students(students: List[str]) -> List[str]:
""" Each student in a class has received a unique identifier consisting of lowercase letters ('a' to 'z').
The class has a well-defined rule where a student can only move up in rank if the sum of the alphabetical positions
of the letters in their iden... | def alphabetical_sum(identifier):
"""
Returns the sum of alphabetical positions of the characters in the identifier.
"""
return sum(ord(char) - ord('a') + 1 for char in identifier)
def ranked_students(students):
"""
Returns a list of students sorted based on the sum of the alphabetical position... | from solution import ranked_students
def test_ranked_students_basic_case():
students = ["abc", "abd", "aaa"]
assert ranked_students(students) == ["aaa", "abc", "abd"]
def test_ranked_students_single_element():
students = ["abc"]
assert ranked_students(students) == ["abc"]
def test_ranked_students_ide... | [
{
"docstring": "Returns the sum of alphabetical positions of the characters in the identifier.",
"function_declaration": "def alphabetical_sum(identifier):",
"function_name": "alphabetical_sum",
"parameter_list": "(identifier)"
},
{
"docstring": "Returns a list of students sorted based on th... | [
1,
1,
0,
0,
0,
1,
1,
0,
1
] | 5 | medium | 0.556 | {
"trial_gpt4o_0": null,
"trial_gpt4o_1": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared1_results_combined.jsonl",
"solution_code": "def alphabetical_sum(identifier):\n \"\"\"\n Returns the sum of alphabetical positions of the letters in the identifier.\n \"\"\"\... | trial_gpt4o_9 | {
"original_instruction": "Each student in a class has received a unique identifier consisting of lowercase letters ('a' to 'z'). The class has a well-defined rule where a student can only move up in rank if the sum of the alphabetical positions of the letters in their identifier is greater than the sum of the letter... | 0.624807 | Apps_10444 | C | [
"alphabetical_sum",
"ranked_students"
] | 2 | [
[
"ranked_students",
"alphabetical_sum"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 58610a341268f3efe21ce516f611976089c7e5b1 | 87b92e5657ef6977aad22b8e6a065fe5f83b0f42 | |||
v1.0 | complete | Apps | Apps_10908_C | def product_excluding_extremes(arr):
"""
Given an array of integers, return the product of all the numbers except the largest and smallest elements (considered by value, not index).
If the array has duplicates of the largest or smallest value, only exclude one instance of each.
If the array is empt... | def product_excluding_extremes(arr):
"""
Returns the product of all numbers in the array excluding the smallest
and largest elements.
If the array is empty, null, or contains less than three elements, return 1.
"""
if arr is None or len(arr) < 3:
return 1
sorted_arr = sorted(a... | from solution import product_excluding_extremes
def test_product_standard_case():
assert product_excluding_extremes([6, 2, 1, 8, 10]) == 96
def test_product_with_duplicates():
assert product_excluding_extremes([1, 1, 11, 2, 3]) == 6
def test_product_with_single_element():
assert product_excluding_extreme... | [
{
"docstring": "Returns the product of all numbers in the array excluding the smallest \nand largest elements.\n\nIf the array is empty, null, or contains less than three elements, return 1.",
"function_declaration": "def product_excluding_extremes(arr):",
"function_name": "product_excluding_extremes",
... | [
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": "def product_except_extremes(arr):\n \"\"\"\n Returns the product of all numbers in the array except the largest and smallest elements.\n If the array is em... | trial_gpt4o_1 | {
"original_instruction": "Given an array of integers, return the product of all the numbers except the largest and smallest elements (considered by value, not index).\nIf the array has duplicates of the largest or smallest value, only exclude one instance of each.\nExample:\n```\n{ 6, 2, 1, 8, 10 } => 96\n{ 1, 1, 11... | 0.683723 | Apps_10908 | C | [
"product_excluding_extremes",
"product"
] | 2 | [
[
"product_excluding_extremes",
"product"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8fd5fe572137b3943ba624cd1a22a6309dc0ea32 | 838c79807aebaba08160e73c0f069fc2d704320a | |||
v1.0 | complete | Apps | Apps_9265_C | def coding_marathon_leaderboard(input_data: str) -> List[str]:
""" Generate leaderboard ranking for multiple test cases based on participant scores and names.
>>> coding_marathon_leaderboard("1\n1\nAlice 100")
["Case #1:", "Alice 100"]
>>> coding_marathon_leaderboard("1\n3\nAlice 100\nBob 100\nChar... | def generate_leaderboard(test_cases):
results = []
for case_no, (num_participants, participants) in enumerate(test_cases, 1):
sorted_participants = sorted(participants, key=lambda x: (-x[1], x[0]))
results.append(f"Case #{case_no}:")
for name, score in sorted_participants:
r... | def test_case_single_participant():
input_data = "1\n1\nAlice 100"
expected_output = ["Case #1:", "Alice 100"]
assert coding_marathon_leaderboard(input_data) == expected_output
def test_case_multiple_participants_same_score():
input_data = "1\n3\nAlice 100\nBob 100\nCharlie 100"
expected_output = [... | [
{
"docstring": null,
"function_declaration": "def generate_leaderboard(test_cases):",
"function_name": "generate_leaderboard",
"parameter_list": "(test_cases)"
},
{
"docstring": null,
"function_declaration": "def parse_input(input_data):",
"function_name": "parse_input",
"paramet... | [
1,
0,
1,
0,
1,
0,
0,
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": "def leaderboard(test_cases):\n \"\"\"\n Process multiple test cases and return ranked leaderboard of participants.\n Each leader board is sorted by score i... | trial_gpt4o_9 | {
"original_instruction": "Alex is planning to host a coding marathon and needs to set up a leaderboard. The leaderboard should rank participants based on their scores in descending order. In case two participants have the same score, they should be ranked based on their names in ascending alphabetical order. Alex ha... | 0.587091 | Apps_9265 | C | [
"generate_leaderboard",
"parse_input",
"coding_marathon_leaderboard"
] | 3 | [
[
"coding_marathon_leaderboard",
"generate_leaderboard"
],
[
"coding_marathon_leaderboard",
"parse_input"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | false | [] | true | bcb7e7b3ba0b18acae51e023f74814dc5550fc69 | 2ce021db74ec794faa7e6b35a4d48626ebdf2c88 | |||
v1.0 | complete | Apps | Apps_11453_C | def gcd(a: int, b: int) -> int:
"""
Helper function to find the Greatest Common Divisor (GCD)
of two numbers using Euclid's algorithm.
"""
def largest_square_plot(M: int, N: int):
"""
Determines the side length of the largest square plot and the total number
of such square plots needed to f... | def gcd(a, b):
"""
Helper function to find the Greatest Common Divisor (GCD)
of two numbers using Euclid's algorithm.
"""
while b:
a, b = b, a % b
return a
def largest_square_plot(M, N):
"""
Determines the side length of the largest square plot and the total number
of such s... | from solution import largest_square_plot
def test_example_case():
side_length, num_plots = largest_square_plot(20, 15)
assert side_length == 5
assert num_plots == 12
def test_equal_dimensions():
side_length, num_plots = largest_square_plot(10, 10)
assert side_length == 10
assert num_plots == 1... | [
{
"docstring": "Helper function to find the Greatest Common Divisor (GCD)\nof two numbers using Euclid's algorithm.",
"function_declaration": "def gcd(a, b):",
"function_name": "gcd",
"parameter_list": "(a, b)"
},
{
"docstring": "Determines the side length of the largest square plot and the ... | [
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 largest_square_plot(M, N):\n \"\"\"\n Calculate the side length of the largest square plot and the number\n of such plots needed to fill the entire gar... | trial_gpt4o_9 | {
"original_instruction": "A botanist has a large rectangular garden and wants to build the maximum number of square plots of the same size within it, to experiment with plant arrangements. She also wants to ensure that no space is wasted in the garden and that the side lengths of the square plots are integers. Help ... | 0.560644 | Apps_11453 | C | [
"gcd",
"largest_square_plot"
] | 2 | [
[
"largest_square_plot",
"gcd"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ee26df38961bf3056085166c8f84ecd12eafd958 | 1120963956e75560fef98b15590c3c1f8a7d40c4 | |||
v1.0 | complete | Apps | Apps_8417_C | def max_benefit(T, test_cases):
"""
Calculate the maximum total benefit value for each test case by selecting a subset of non-interacting nodes.
Args:
T (int): Number of test cases.
test_cases (List[Tuple[int, int, List[int], List[Tuple[int, int]]]]): List containing the test cases. Each test c... | def max_benefit(T, test_cases):
def find_max_non_interacting_nodes_benefit(n, m, benefits, edges):
from itertools import combinations
max_benefit_sum = 0
# Convert edge list to adjacency list
adj = {i: set() for i in range(1, n+1)}
for u, v in edges:
... | def test_max_benefit():
input_data = '''2
5
4
1 2 3 4 5
1 2
2 3
4 5
3 4
3
2
10 20 30
1 2
2 3
'''
expected_output = '''9
40
'''
assert solve(input_data) == expected_output.strip()
def test_max_benefit_single_node():
input_data = '''1
1
0
10
'''
expected_output = '''10
'''
assert solve(input_... | [
{
"docstring": null,
"function_declaration": "def max_benefit(T, test_cases):",
"function_name": "max_benefit",
"parameter_list": "(T, test_cases)"
},
{
"docstring": null,
"function_declaration": "def process_input(input_data):",
"function_name": "process_input",
"parameter_list"... | [
0,
0,
0,
0,
0,
0,
1,
0,
1,
0
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from itertools import combinations\n\ndef max_benefit_value(n, m, benefits, edges):\n adjacency_list = {i: set() for i in range(1, n+1)}\n for u, v in edges:\... | trial_gpt4o_8 | {
"original_instruction": "You are designing an ecosystem for a new simulation game where players need to create the most balanced environment to maximize the growth of plants and the well-being of animals. The ecosystem is represented by a series of nodes and edges in a graph, where nodes represent different areas (... | 0.578895 | Apps_8417 | C | [
"max_benefit",
"process_input",
"generate_output",
"solve"
] | 4 | [
[
"solve",
"generate_output"
],
[
"solve",
"max_benefit"
],
[
"solve",
"process_input"
]
] | 3 | [
"process_input",
"generate_output"
] | false | [] | false | pytest | false | [] | true | 347b85861a848e93c10186175ae45232c4c940a8 | 3d8a237d21dd04943461f3314682757c7d4d6ad5 | |||
v1.0 | complete | Apps | Apps_10997_C | def is_prime(n: int) -> bool:
"""
Helper function to determine if a number is prime.
"""
pass
def splitPrimes(arr: List[int]) -> List[List[int]]:
"""
Splits the input array into two sub-arrays: one containing prime numbers, and the other containing non-prime numbers.
>>> splitPrimes([2... | 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
for i in range(3, int(n ** 0.5) + 1, 2):
if n % i == 0:
return False
return True
def splitPr... | from solution import splitPrimes, is_prime
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(17) == True
assert is_prime(18) == False
def test_splitPrimes_with_mixed_numbers():
assert splitPrimes([2, 4, 6, 5, 9, 11, 15]) == [... | [
{
"docstring": "Helper function to determine if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Splits the input array into two sub-arrays: one containing prime numbers, and the other containing non-prim... | [
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(num):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num == 2:\n return True\n if n... | trial_gpt4o_9 | {
"original_instruction": "Write a function that takes an array of numbers as input and returns an array containing two sub-arrays. One sub-array should contain all the numbers that are prime, and the other should contain all the non-prime numbers. Arrange the numbers in each sub-array in the same order they appeared... | 0.744442 | Apps_10997 | C | [
"is_prime",
"splitPrimes"
] | 2 | [
[
"splitPrimes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 1b4a126c62cc16ac2ca43c0cc7de76686a159bb0 | 3f14e952e21446e16839e376bf7772f9fb1f30f5 | |||
v1.0 | complete | Apps | Apps_11705_C | def merge_sort(arr: List[int]) -> List[int]:
"""
Sorts an array in non-decreasing order using the merge sort algorithm
and removes any duplicate values from the final sorted array.
>>> merge_sort([4, 2, 7, 3, 1, 5])
[1, 2, 3, 4, 5, 7]
>>> merge_sort([4, 4, 2, 7, 2, 3, 1, 5, 4, 1])
[1, 2, 3,... | def merge_sort(arr):
"""
Sorts an array in non-decreasing order using the merge sort algorithm
and removes any duplicate values from the final sorted array.
"""
if len(arr) <= 1:
return arr
# Divide the array into two halves
mid = len(arr) // 2
left_half = merge_sort(arr[:mid])
... | from solution import merge_sort
def test_merge_sort_basic():
assert merge_sort([4, 2, 7, 3, 1, 5]) == [1, 2, 3, 4, 5, 7]
def test_merge_sort_with_duplicates():
assert merge_sort([4, 4, 2, 7, 2, 3, 1, 5, 4, 1]) == [1, 2, 3, 4, 5, 7]
def test_merge_sort_empty():
assert merge_sort([]) == []
def test_merge_... | [
{
"docstring": "Sorts an array in non-decreasing order using the merge sort algorithm\nand removes any duplicate values from the final sorted array.",
"function_declaration": "def merge_sort(arr):",
"function_name": "merge_sort",
"parameter_list": "(arr)"
},
{
"docstring": "Merges two sorted... | [
1,
1,
1,
1,
0,
1,
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 merge_sort(array):\n if len(array) <= 1:\n return array\n\n mid = len(array) // 2\n left_half = merge_sort(array[:mid])\n right_half = merge_... | trial_gpt4o_8 | {
"original_instruction": "Write a function that takes a list of integers and returns a new list containing the elements of the original list sorted in non-decreasing order, without using any built-in sorting functions. You are required to implement the Merge Sort algorithm to accomplish this task. The function must ... | 0.617237 | Apps_11705 | C | [
"merge_sort",
"merge"
] | 2 | [
[
"merge_sort",
"merge"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 28780c5b25464fb8c93efa098ecc4648301a5661 | 729bfb5e42c0c9133fc3d29b0f301644107b9cf0 | |||
v1.0 | complete | Apps | Apps_10800_C | def minimum_spanning_tree(t: int, test_cases: List[Tuple[int, int, List[Tuple[int, int, int]]]]) -> List[int]:
""" Determine the weight of the minimum spanning tree (MST) for the given graph.
Args:
t: Number of test cases.
test_cases: List of test cases, each containing:
- An integer n: Num... | import heapq
def find_parent(parent, i):
if parent[i] == i:
return i
else:
return find_parent(parent, parent[i])
def union(parent, rank, x, y):
xroot = find_parent(parent, x)
yroot = find_parent(parent, y)
if rank[xroot] < rank[yroot]:
parent[xroot] = yroot
elif rank[x... | from solution import minimum_spanning_tree
def test_case_1():
t = 2
test_cases = [
(4, 5, [(1, 2, 3), (1, 3, 1), (2, 3, 3), (3, 4, 6), (2, 4, 2)]),
(3, 3, [(1, 2, 4), (2, 3, 7), (1, 3, 1)])
]
assert minimum_spanning_tree(t, test_cases) == [6, 5]
def test_case_disconnected_graph():
... | [
{
"docstring": null,
"function_declaration": "def find_parent(parent, i):",
"function_name": "find_parent",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank... | [
1,
0,
0,
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 heapq\n\ndef find_parent(parent, i):\n if parent[i] == i:\n return i\n else:\n return find_parent(parent, parent[i])\n\ndef union(parent,... | trial_gpt4o_0 | {
"original_instruction": "You are given an undirected graph with $N$ nodes and $M$ edges. Each node is uniquely numbered from $1$ to $N$. Each edge has a weight associated with it. The graph may have multiple edges between two nodes but does not contain self-loops.\n\nYour task is to determine the weight of the mini... | 0.755784 | Apps_10800 | C | [
"find_parent",
"union",
"kruskal_mst",
"minimum_spanning_tree"
] | 4 | [
[
"kruskal_mst",
"find_parent"
],
[
"kruskal_mst",
"union"
],
[
"minimum_spanning_tree",
"kruskal_mst"
],
[
"union",
"find_parent"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | 047d5537fec6453a7e748d2c72483e5f81828b53 | 1e0978fbbdaebf7bf7850f5bcde70359c910ba55 | |||
v1.0 | complete | Apps | Apps_11273_C | from typing import List
def filter_primes(lst: List[int]) -> List[int]:
"""
Takes a list of integers and returns a new list containing all the integers from the original list that are prime numbers.
A prime number is a number that is greater than 1 and is only divisible by 1 and itself. For example, ... | def is_prime(num):
"""
Helper function to determine if a number is prime.
"""
if num <= 1:
return False
for i in range(2, int(num**0.5) + 1):
if num % i == 0:
return False
return True
def filter_primes(lst):
"""
Returns a list of prime numbers from the given ... | from solution import filter_primes
def test_filter_primes_mixed_numbers():
assert filter_primes([2, 3, 4, 5, 6, 7, 8, 9, 10]) == [2, 3, 5, 7]
def test_filter_primes_prime_numbers():
assert filter_primes([11, 13, 17, 19]) == [11, 13, 17, 19]
def test_filter_primes_no_primes():
assert filter_primes([4, 6, ... | [
{
"docstring": "Helper function to determine if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns a list of prime numbers from the given list.",
"function_declaration": "def filter_primes(l... | [
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 Check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n for i in range(2, int(math.sqrt(... | trial_gpt4o_9 | {
"original_instruction": "Write a function that takes a list of integers and returns a new list that contains all the integers from the original list that are prime numbers.\n\nA prime number is a number that is greater than 1 and is only divisible by 1 and itself. For example, the first few prime numbers are 2, 3, ... | 0.673519 | Apps_11273 | C | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7fb0171a6231e83c7b665f34db1eed4432853220 | 4f31dc12709ede5b7d3674ec4b33fdbfd8c75742 | |||
v1.0 | complete | Apps | Apps_11603_C | def round_half_hour(n):
""" Rounds a number to the nearest half hour increment. """
return round(n * 2) / 2
def task_durations(historical_data: dict, new_tasks: list) -> list:
"""
Returns the duration for each task based on historical data.
If the task exists in historical data, return the average... | def round_half_hour(n):
"""
Rounds a number to the nearest half hour increment.
"""
return round(n * 2) / 2
def task_durations(historical_data, new_tasks):
"""
Returns the duration for each task based on historical data.
If the task exists in historical data, return the average of the past ... | from solution import task_durations
def test_task_durations_with_existing_tasks():
historical_data = {
"design": [2, 2.5, 3],
"coding": [4.5, 4, 5]
}
new_tasks = ["design", "coding"]
result = task_durations(historical_data, new_tasks)
assert result == [2.5, 4.5]
def test_task_durat... | [
{
"docstring": "Rounds a number to the nearest half hour increment.",
"function_declaration": "def round_half_hour(n):",
"function_name": "round_half_hour",
"parameter_list": "(n)"
},
{
"docstring": "Returns the duration for each task based on historical data.\nIf the task exists in historic... | [
1,
1,
0,
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": "def round_to_nearest_half_hour(hours):\n \"\"\"\n Rounds the float hours to the nearest half-hour increment.\n \"\"\"\n return round(hours * 2) / 2\n\nd... | trial_gpt4o_9 | {
"original_instruction": "You are working on a novel time-tracking application for freelancers that tracks the time they spend on various tasks throughout their workday. Users start a task by entering its name and mark it as complete once they're done. However, users often forget to log the exact number of hours the... | 0.599922 | Apps_11603 | C | [
"round_half_hour",
"task_durations"
] | 2 | [
[
"task_durations",
"round_half_hour"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8c12a396549c097497c1bffed0751730b28eceaa | c83039a1e89b52ab4b10c5bf626f77b250e3e56c | |||
v1.0 | complete | Apps | Apps_9851_C | def can_form_query_string(T: int, test_cases: List[Tuple[int, List[str], str]]) -> List[str]:
"""
Determine if the given query string can be formed by concatenating one or more strings from the list.
Args:
T : int : Number of test cases
test_cases : List[Tuple[int, List[str], str]] : A list of ... | def get_primes_up_to(n):
primes = []
sieve = [True] * (n + 1)
sieve[0] = sieve[1] = False
for start in range(2, n + 1):
if sieve[start]:
primes.append(start)
for multiple in range(start * start, n + 1, start):
sieve[multiple] = False
return p... | from solution import can_form_query_string
def test_case_1():
T = 1
test_cases = [
(3, ["a", "aa", "aaa"], "aaaa")
]
assert can_form_query_string(T, test_cases) == ["YES"]
def test_case_2():
T = 1
test_cases = [
(3, ["a", "b", "c"], "abc")
]
assert can_form_query_string... | [
{
"docstring": null,
"function_declaration": "def get_primes_up_to(n):",
"function_name": "get_primes_up_to",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def get_prime_map():",
"function_name": "get_prime_map",
"parameter_list": "()"
},
{
"doc... | [
0,
0,
0,
0,
0,
0,
0,
0,
1
] | 1 | hard | 0.111 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def get_prime_mapping():\n \"\"\"\n Returns a dictionary mapping each letter to a unique prime number starting from 2.\n \"\"\"\n import sympy\n prim... | trial_gpt4o_9 | {
"original_instruction": "In a remote village, they have devised a new coding system for communication. Each letter of the alphabet is assigned a unique prime number starting from the smallest prime number (i.e., 'a' is assigned 2, 'b' is assigned 3, 'c' is assigned 5, and so on up to 'z' which is assigned the 26th ... | 0.559606 | Apps_9851 | C | [
"get_primes_up_to",
"get_prime_map",
"get_string_product",
"can_form_query_string"
] | 4 | [
[
"can_form_query_string",
"get_prime_map"
],
[
"can_form_query_string",
"get_string_product"
],
[
"get_prime_map",
"get_primes_up_to"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | e843becb3273807010e054ad226e8871b5dc1462 | 8a4fdcd0f0f18885e2c8e7f1a2ecd2292b0900e7 | |||
v1.0 | complete | Apps | Apps_11758_C | class TreeNode:
def __init__(self, key):
self.left = None
self.right = None
self.val = key
def insert(root, key):
if root is None:
return TreeNode(key)
if key < root.val:
root.left = insert(root.left, key)
else:
root.right = insert(root.right, key)
... | class TreeNode:
def __init__(self, key):
self.left = None
self.right = None
self.val = key
def insert(root, key):
if root is None:
return TreeNode(key)
if key < root.val:
root.left = insert(root.left, key)
else:
root.right = insert(root.right, key)
... | from solution import bst_inorder
def test_bst_inorder_example1():
input_arr = [5, 3, 7, 2, 4, 6, 8]
expected_output = [2, 3, 4, 5, 6, 7, 8]
assert bst_inorder(input_arr) == expected_output
def test_bst_inorder_example2():
input_arr = [1, 2, 3, 4, 5]
expected_output = [1, 2, 3, 4, 5]
assert bst... | [] | [
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": "class TreeNode:\n def __init__(self, key):\n self.left = None\n self.right = None\n self.val = key\n\ndef insert(root, key):\n if root is... | trial_gpt4o_9 | {
"original_instruction": "Given an array of integers, you are asked to form a valid Binary Search Tree (BST). Use the unique values in the array to build the BST. Then, perform an in-order traversal of the BST and return an array of the in-order traversal sequence.\n\n### Input\n- An integer array `arr[]` containing... | 0.545987 | Apps_11758 | C | [
"insert",
"inorder_traversal",
"bst_inorder"
] | 3 | [
[
"bst_inorder",
"inorder_traversal"
],
[
"bst_inorder",
"insert"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | d25d6c7a4ac9cb381ec0946f49fd9d4240e77cee | 6321e1896a8f17928cc45b58f7e41fd72fc71dc0 | |||
v1.0 | complete | Apps | Apps_11594_C | def to_uppercase(word):
"""
Converts the word to uppercase.
"""
pass
def starts_with_vowel(word):
"""
Returns True if the word starts with a vowel, False otherwise.
"""
pass
def filter_and_transform_words(n, words):
"""
Filters words that start with a vowel and transforms them ... | def to_uppercase(word):
"""
Converts the word to uppercase.
"""
return word.upper()
def starts_with_vowel(word):
"""
Returns True if the word starts with a vowel, False otherwise.
"""
return word[0].lower() in 'aeiou'
def filter_and_transform_words(n, words):
"""
Filters words ... | from solution import filter_and_transform_words
def test_filter_and_transform_words_all_vowels():
assert filter_and_transform_words(5, ["apple", "orange", "umbrella", "eagle", "igloo"]) == "APPLE ORANGE UMBRELLA EAGLE IGLOO"
def test_filter_and_transform_words_no_vowels():
assert filter_and_transform_words(5,... | [
{
"docstring": "Converts the word to uppercase.",
"function_declaration": "def to_uppercase(word):",
"function_name": "to_uppercase",
"parameter_list": "(word)"
},
{
"docstring": "Returns True if the word starts with a vowel, False otherwise.",
"function_declaration": "def starts_with_vo... | [
1,
1,
1,
1,
1,
0,
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": "def filter_words_starting_with_vowel(words):\n vowels = {'a', 'e', 'i', 'o', 'u'}\n\n def starts_with_vowel(word):\n return word[0].lower() in vowels\n... | trial_gpt4o_7 | {
"original_instruction": "=====Function Descriptions=====\nmap()\nThe map() function applies a given function to each item of an iterable (like list) and returns a list of the results.\n\nCode\n>>> def square(x):\n... return x * x\n>>> map(square, [0, 1, 2, 3, 4])\n[0, 1, 4, 9, 16]\n\nfilter()\nThe filter() func... | 0.683891 | Apps_11594 | C | [
"to_uppercase",
"starts_with_vowel",
"filter_and_transform_words"
] | 3 | [
[
"filter_and_transform_words",
"starts_with_vowel"
],
[
"filter_and_transform_words",
"to_uppercase"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 136e6327e119ca5a9770f2215e01a6a21386f96d | 477bab9b28c329e2a8d1e77d7b7c7a97ffd3540e | |||
v1.0 | complete | Apps | Apps_9978_C | def merge_sort(arr):
"""
Sorts a list of integers in ascending order using the merge sort algorithm.
"""
def merge(left, right):
"""
Merges two sorted lists into one sorted list.
"""
# To handle the specific problem format
def sort_integers(n, arr):
"""
Sorts a list of n intege... | def merge_sort(arr):
"""
Sorts a list of integers in ascending order using the merge sort algorithm.
"""
if len(arr) <= 1:
return arr
mid = len(arr) // 2
left_half = merge_sort(arr[:mid])
right_half = merge_sort(arr[mid:])
return merge(left_half, right_half)
def merge(left, ri... | from solution import merge_sort, sort_integers
def test_merge_sort():
assert merge_sort([5, 2, 9, 1, 5, 6]) == [1, 2, 5, 5, 6, 9]
assert merge_sort([3, 1, 4, 1, 5]) == [1, 1, 3, 4, 5]
assert merge_sort([]) == []
assert merge_sort([7]) == [7]
assert merge_sort([4, 2, 7, 1]) == [1, 2, 4, 7]
asser... | [
{
"docstring": "Sorts a list of integers in ascending order using the merge sort algorithm.",
"function_declaration": "def merge_sort(arr):",
"function_name": "merge_sort",
"parameter_list": "(arr)"
},
{
"docstring": "Merges two sorted lists into one sorted list.",
"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 merge_sort(arr):\n \"\"\"\n Sorts a list in ascending order using the merge sort algorithm.\n \"\"\"\n if len(arr) > 1:\n mid = len(arr) // 2... | trial_gpt4o_9 | {
"original_instruction": "=====Function Descriptions=====\nSorting Algorithms\nSorting algorithms are techniques to arrange data in a particular order. These algorithms can be used to sort data in ascending or descending order.\n\nExamples:\nBubble Sort\nBubble sort is an algorithm that repeatedly steps through the ... | 0.611234 | Apps_9978 | C | [
"merge_sort",
"merge",
"sort_integers"
] | 3 | [
[
"merge_sort",
"merge"
],
[
"sort_integers",
"merge_sort"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | a6ac6dcf42cb56e5fff0fed28d38cdf62b02c45e | 4e34f6b3e24afb4d26be04a743bf769dffc4e897 | |||
v1.0 | complete | Apps | Apps_19573_C | def digital_root(n):
"""
Returns the digital root of a number.
>>> digital_root(678)
3
>>> digital_root(12345)
6
>>> digital_root(99999)
9
"""
def shield_activation_code(N, K):
"""
Returns the K-th number in the sequence starting from N.
>>> shield_activation_code(67... | def digital_root(n):
"""
Returns the digital root of a number.
"""
while n >= 10:
n = sum(int(digit) for digit in str(n))
return n
def shield_activation_code(N, K):
"""
Returns the K-th number in the sequence starting from N.
"""
sequence = [N]
for i in range(1, K):... | from solution import digital_root, shield_activation_code, format_shield_activation_code
def test_digital_root():
assert digital_root(678) == 3
assert digital_root(12345) == 6
assert digital_root(9) == 9
assert digital_root(99999) == 9
def test_shield_activation_code():
assert shield_activation_co... | [
{
"docstring": "Returns the digital root of a number.",
"function_declaration": "def digital_root(n):",
"function_name": "digital_root",
"parameter_list": "(n)"
},
{
"docstring": "Returns the K-th number in the sequence starting from N.",
"function_declaration": "def shield_activation_co... | [
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 digital_root(num):\n while num >= 10:\n num = sum(int(digit) for digit in str(num))\n return num\n\ndef shield_activation_code(N, K):\n sequence... | trial_gpt4o_5 | {
"original_instruction": "A secret missionary mission requires decoding a sequence of shield activation codes embedded within a specific number pattern. The codes are generated by a numerical sequence that follows a special property: every even-indexed number (starting from index 1) in the sequence is the sum of the... | 0.551948 | Apps_19573 | C | [
"digital_root",
"shield_activation_code",
"format_shield_activation_code"
] | 3 | [
[
"format_shield_activation_code",
"shield_activation_code"
],
[
"shield_activation_code",
"digital_root"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | abd1815d99389f576e87b4c5d3aebb0d526687f5 | 406625e09bae01bc568843c69364106661383e19 | |||
v1.0 | complete | Apps | Apps_11293_C | def is_prime(n: int) -> bool:
"""
Helper function to check if a number is prime.
"""
pass
def filter_primes(lst: List[int]) -> List[int]:
"""
Returns a new list containing only the prime numbers from the input list.
>>> filter_primes([-10, 2, 3, 4, 5, 6, 7, 8, 9, 10]) [2, 3, 5, 7]
>>> ... | def is_prime(n):
"""
Helper function to 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 +... | from solution import filter_primes
def test_filter_primes_empty():
assert filter_primes([]) == []
def test_filter_primes_no_primes():
assert filter_primes([-10, -3, 0, 1, 4, 6, 8, 9, 10]) == []
def test_filter_primes_with_primes():
assert filter_primes([-10, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [2, 3, 5, 7]
... | [
{
"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 input list.",
"function_declaration": "def fi... | [
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(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_9 | {
"original_instruction": "Given a list of integers, write a function that returns a new list containing only the prime numbers from the original list.\n\nProvide an implementation that is efficient and consider edge cases (e.g., negative numbers, zero, and one which are not primes).\n\nInput will be a list of intege... | 0.784576 | Apps_11293 | C | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 52f5de0bc103ed4ff5726930ad6ac3a873d19837 | 10097d588a77fe789a3cc33e6244db27f71965d6 | |||
v1.0 | complete | Apps | Apps_11864_C | def max_seats_close_together(n, k, seats):
# Find the maximum number of seats on contiguous benches
pass
def can_place_friends(seats, n, k, min_dist):
# Helper function to check if friends can be placed with a given minimum distance
pass
def max_distance_spread_out(n, k, seats):
# Find the maximum... | def max_seats_close_together(n, k, seats):
max_sum = 0
for i in range(n - k + 1):
max_sum = max(max_sum, sum(seats[i:i + k]))
return max_sum
def can_place_friends(seats, n, k, min_dist):
count = 1
last_pos = seats[0]
for i in range(1, n):
if seats[i] - last_pos >= min_dist:
... | from solution import friends_on_benches
def test_separate_friends():
test_cases = [
(7, 3, [4, 5, 3, 2, 8, 6, 7], 0),
(6, 2, [10, 20, 30, 40, 50, 60], 1)
]
assert friends_on_benches(2, test_cases) == [21, 50]
def test_close_together_basic():
test_cases = [
(3, 2, [1, 2, 3], 0)
... | [
{
"docstring": null,
"function_declaration": "def max_seats_close_together(n, k, seats):",
"function_name": "max_seats_close_together",
"parameter_list": "(n, k, seats)"
},
{
"docstring": null,
"function_declaration": "def can_place_friends(seats, n, k, min_dist):",
"function_name": ... | [
0,
1,
0,
0,
0,
0,
0,
1,
1,
1
] | 4 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_seats_or_distance(test_cases):\n results = []\n \n for n, k, seats, p in test_cases:\n if p == 0:\n # Friends prefer to sit close... | trial_gpt4o_8 | {
"original_instruction": "In a city park, there are n benches arranged in a straight line. Each bench has a particular number of seats. A group of friends has decided to sit on these benches. The friends want to sit in such a way that no two friends are seated on the same bench. However, the friends have certain pre... | 0.587117 | Apps_11864 | C | [
"max_seats_close_together",
"can_place_friends",
"max_distance_spread_out",
"friends_on_benches"
] | 4 | [
[
"friends_on_benches",
"max_distance_spread_out"
],
[
"friends_on_benches",
"max_seats_close_together"
],
[
"max_distance_spread_out",
"can_place_friends"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | e9a1cf9e5c3055bff9fedf12878909a3e7856955 | a09f3b6e47f05e09402831690e340fe9cae64aa0 | |||
v1.0 | complete | Apps | Apps_11586_C | def process_queries(n, weights, edges, queries):
"""
Processes several queries to determine the maximum weight found on the unique path between two given nodes in a tree.
Parameters:
- n (int): Number of components in the toy tree.
- weights (List[int]): List of weights for each component.
... | from collections import defaultdict, deque
def preprocess_lca_and_max_weights(n, weights, edges):
# Adjacency list of the tree
tree = defaultdict(list)
for u, v in edges:
tree[u-1].append(v-1)
tree[v-1].append(u-1)
# Depth and parent info
depth = [-1] * n
parent = [[-1] * n... | from solution import process_queries
def test_basic_case():
n = 5
weights = [10, 30, 50, 70, 90]
edges = [(1, 2), (2, 3), (2, 4), (4, 5)]
queries = ["M 1 3", "M 1 5", "M 4 5"]
expected = [50, 90, 90]
assert process_queries(n, weights, edges, queries) == expected
def test_single_query():
n ... | [
{
"docstring": null,
"function_declaration": "def preprocess_lca_and_max_weights(n, weights, edges):",
"function_name": "preprocess_lca_and_max_weights",
"parameter_list": "(n, weights, edges)"
},
{
"docstring": null,
"function_declaration": "def find_max_weight(x, y, depth, parent, max_... | [
0,
1,
0,
0,
1,
0,
1,
1,
0,
1
] | 5 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict, deque\nimport sys\n\nsys.setrecursionlimit(40000)\n\nclass Tree:\n def __init__(self, n, weights):\n self.n = n\n ... | trial_gpt4o_9 | {
"original_instruction": "You are a developer for a toy company that develops toys using DIY kits. Your company has recently launched a new series of toys that are built using a series of connected components. Each component is represented by a node in a graph, and there's exactly one path (no cycles) between any tw... | 0.606304 | Apps_11586 | C | [
"preprocess_lca_and_max_weights",
"find_max_weight",
"process_queries"
] | 3 | [
[
"process_queries",
"find_max_weight"
],
[
"process_queries",
"preprocess_lca_and_max_weights"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | true | [] | true | 5585346c47055df89669e5ccf1ed5859a8b95cf3 | a4302f869ddf0b8b170b8c9948d0d710a47e284e | |||
v1.0 | complete | Apps | Apps_11300_C | from typing import List, Tuple
def count_pairs_with_product(arr: List[int], target: int) -> int:
""" Determines the number of pairs (i, j) where 0 ≤ i < j < n and the product of the elements at positions i and j is equal to the given target value.
>>> count_pairs_with_product([1, 3, 4, 2], 12)
1
>>> co... | def count_pairs_with_product(arr, target):
n = len(arr)
count = 0
for i in range(n):
for j in range(i + 1, n):
if arr[i] * arr[j] == target:
count += 1
return count
def solve(test_cases):
results = []
for n, target, arr in test_cases:
results.append(c... | def test_count_pairs_with_product():
assert count_pairs_with_product([1, 3, 4, 2], 12) == 1
assert count_pairs_with_product([5, 4, 2, 1, 10], 20) == 2
def test_parse_input():
input_data = "2\n4 12\n1 3 4 2\n5 20\n5 4 2 1 10"
expected_output = [(4, 12, [1, 3, 4, 2]), (5, 20, [5, 4, 2, 1, 10])]
asser... | [
{
"docstring": null,
"function_declaration": "def count_pairs_with_product(arr, target):",
"function_name": "count_pairs_with_product",
"parameter_list": "(arr, target)"
},
{
"docstring": null,
"function_declaration": "def solve(test_cases):",
"function_name": "solve",
"parameter... | [
0,
1,
1,
1,
0,
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 count_pairs_with_product(arr, target):\n \"\"\"\n Returns the number of pairs (i, j) where 0 ≤ i < j < n and the product of elements at positions i and j ... | trial_gpt4o_3 | {
"original_instruction": "Olivia loves solving puzzles. She has recently come across a new type of combinatorial puzzle involving numbers. In this puzzle, she is given an array of integers and a target value. Her goal is to find the number of ways to choose a pair of distinct elements from the array such that their ... | 0.662618 | Apps_11300 | C | [
"count_pairs_with_product",
"solve",
"parse_input",
"main"
] | 4 | [
[
"solve",
"count_pairs_with_product"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | false | [] | true | d72b8ad6a4bd79c30dd8402e8bb7665d2da4db1c | 540f370ff41a507d58e351311e06a4ca3c83990e | |||
v1.0 | complete | Taco | Taco_30_C | def minimum_delivery_times(W: int, R: int, P: int, routes: List[Tuple[int, int, int, int]], packages: List[Tuple[int, int, int]]) -> List[str]:
"""
Determine the minimum time to deliver each package from its source waypoint to its destination waypoint.
Args:
W : int : Number of waypoints (2 <= W <... | import heapq
import sys
def dijkstra(W, adj, start, end, weight):
INF = sys.maxsize
distances = [INF] * W
distances[start] = 0
priority_queue = [(0, start)]
while priority_queue:
current_distance, current_node = heapq.heappop(priority_queue)
if current_distance > distances[current_n... | from solution import minimum_delivery_times
def test_example_case():
W = 3
R = 3
P = 1
routes = [
(0, 1, 5, 10),
(1, 2, 5, 15),
(0, 2, 2, 50)
]
packages = [
(0, 2, 5)
]
assert minimum_delivery_times(W, R, P, routes, packages) == ["25"]
def test_unreachab... | [
{
"docstring": null,
"function_declaration": "def dijkstra(W, adj, start, end, weight):",
"function_name": "dijkstra",
"parameter_list": "(W, adj, start, end, weight)"
},
{
"docstring": null,
"function_declaration": "def minimum_delivery_times(W, R, P, routes, packages):",
"function_... | [
0,
1
] | 1 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef deliver_packages(W, R, P, routes, packages):\n # Creating adjacency list for graph\n graph = [[] for _ in range(W)]\n for a, b, c, t i... | trial_gpt4o_1 | {
"original_instruction": "You have been hired by a delivery company that transports packages between different waypoints in a city. The company uses a fleet of drones that can carry packages from one waypoint to another autonomously. A drone can carry a package from one waypoint to another if there exists a direct r... | 0.68791 | Taco_30 | C | [
"dijkstra",
"minimum_delivery_times"
] | 2 | [
[
"minimum_delivery_times",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 524a5b5b64cf84bd079bf76071fc9b59ee3df2eb | 56467f2c4c7eaa64d93c0d9a3a15cde4c2b46c87 | |||
v1.0 | complete | Taco | Taco_58_C | def is_even_or_odd(sum_of_digits):
"""
Determines if the sum of digits is even or odd.
Args:
- sum_of_digits (int): The sum of the digits.
Returns:
- A string "Even" if the sum is even, "Odd" if the sum is odd.
"""
pass
def sum_of_digits(n):
"""
Calculates the sum of t... | def is_even_or_odd(sum_of_digits):
"""
Determines if the sum of digits is even or odd.
Args:
- sum_of_digits (int): The sum of the digits.
Returns:
- A string "Even" if the sum is even, "Odd" if the sum is odd.
"""
return "Even" if sum_of_digits % 2 == 0 else "Odd"
def sum_of_... | def test_is_even_or_odd():
assert is_even_or_odd(6) == "Even"
assert is_even_or_odd(15) == "Odd"
assert is_even_or_odd(24) == "Even"
assert is_even_or_odd(1) == "Odd"
def test_sum_of_digits():
assert sum_of_digits(123) == 6
assert sum_of_digits(456) == 15
assert sum_of_digits(789) == 24
... | [
{
"docstring": "Determines if the sum of digits is even or odd.\n\nArgs:\n- sum_of_digits (int): The sum of the digits.\n\nReturns:\n- A string \"Even\" if the sum is even, \"Odd\" if the sum is odd.",
"function_declaration": "def is_even_or_odd(sum_of_digits):",
"function_name": "is_even_or_odd",
"... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def sum_of_digits(n):\n \"\"\"\n Returns the sum of digits of an integer n.\n \"\"\"\n return sum(int(digit) for digit in str(n))\n\ndef even_or_odd_su... | trial_gpt4o_1 | {
"original_instruction": "You are given a list of integers, and you need to determine if the sum of the digits of each integer in the list is an even or an odd number. Write a program that processes the list and outputs \"Even\" if the sum of the digits is even, and \"Odd\" if the sum of the digits is odd for each i... | 0.742547 | Taco_58 | C | [
"is_even_or_odd",
"sum_of_digits",
"process_numbers"
] | 3 | [
[
"process_numbers",
"is_even_or_odd"
],
[
"process_numbers",
"sum_of_digits"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | b6aae09da70b73f27be5103c582dc49d92e5f3a0 | a7e9b7c19357c48b518baf2a719f998fd91211f7 | |||
v1.0 | complete | Taco | Taco_39_C | def range_sum_queries(n, arr, queries):
"""
Returns a list of sums for each query.
:param n: int - The number of integers in the array
:param arr: list - The array of integers
:param queries: list of tuples - Each tuple contains starting and ending indices (L, R) for the query
:return: list... | def range_sum_queries(n, arr, queries):
"""
Returns a list of sums for each query.
:param n: int - The number of integers in the array
:param arr: list - The array of integers
:param queries: list of tuples - Each tuple contains starting and ending indices (L, R) for the query
:return: list... | import pytest
from solution import solve, parse_input, range_sum_queries
def test_parse_input():
input_str = "5 3\n1 2 3 4 5\n0 2\n1 3\n2 4"
n, arr, queries = parse_input(input_str)
assert n == 5
assert arr == [1, 2, 3, 4, 5]
assert queries == [(0, 2), (1, 3), (2, 4)]
def test_range_sum_queries():... | [
{
"docstring": "Returns a list of sums for each query.\n\n:param n: int - The number of integers in the array\n:param arr: list - The array of integers\n:param queries: list of tuples - Each tuple contains starting and ending indices (L, R) for the query\n:return: list - Sums for each query",
"function_decl... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from typing import List, Tuple\n\ndef range_sum_queries(N: int, Q: int, array: List[int], queries: List[Tuple[int, int]]) -> List[int]:\n \"\"\"\n Given an a... | trial_gpt4o_2 | {
"original_instruction": "You are given an array of integers and a list of queries. Each query consists of a starting index and an ending index. For each query, determine the sum of the integers within that range, inclusive.\n\nInput:\nFirst line contains two integers N and Q, where N is the number of integers in th... | 0.647779 | Taco_39 | C | [
"range_sum_queries",
"parse_input",
"solve"
] | 3 | [
[
"solve",
"parse_input"
],
[
"solve",
"range_sum_queries"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 6bc0f62acc1152f1e073c41466cd9170fcd28b64 | 9922a44d79f095f1708f6e1835d54d01a7fc66dc | |||
v1.0 | complete | Taco | Taco_87_C | from typing import List
def classify_ip(ip_address: str) -> str:
"""
Classify the given IP address as either 'Private' or 'Public'.
Args:
ip_address (str): The IP address to classify.
Returns:
str: 'Private' if the IP address is private, 'Public' otherwise.
Examples:
>>> classify_ip(... | def classify_ip(ip_address):
"""
Classify the given IP address as either 'Private' or 'Public'.
"""
parts = list(map(int, ip_address.split('.')))
if parts[0] == 10:
return "Private"
elif parts[0] == 172 and 16 <= parts[1] <= 31:
return "Private"
elif parts[0] == 192 and ... | from solution import classify_ip, classify_ip_addresses
def test_classify_ip_private_10():
assert classify_ip("10.0.0.1") == "Private"
assert classify_ip("10.255.255.255") == "Private"
def test_classify_ip_private_172():
assert classify_ip("172.16.0.0") == "Private"
assert classify_ip("172.31.255.255"... | [
{
"docstring": "Classify the given IP address as either 'Private' or 'Public'.",
"function_declaration": "def classify_ip(ip_address):",
"function_name": "classify_ip",
"parameter_list": "(ip_address)"
},
{
"docstring": null,
"function_declaration": "def classify_ip_addresses(ip_addresse... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def classify_ip_addresses(ip_addresses):\n \"\"\"\n Classifies a list of IP addresses as either 'Private' or 'Public'.\n \"\"\"\n private_ranges = [\n ... | trial_gpt4o_2 | {
"original_instruction": "You are given a list of IP addresses. Your task is to find out which IP addresses are public and which are private. Classify each IP address and output the result.\n\n### Public vs. Private IP Addresses\nPublic IP addresses are used to access the Internet, while private IP addresses are use... | 0.624397 | Taco_87 | C | [
"classify_ip",
"classify_ip_addresses"
] | 2 | [
[
"classify_ip_addresses",
"classify_ip"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5d5632c4521d022a18edacc06deb819e18da4626 | c6178feae41dc92eba71adc02f7f97aa786d7b92 | |||
v1.0 | complete | Taco | Taco_137_C | class TreeNode:
def __init__(self, val):
self.val = val
self.left = None
self.right = None
def build_tree(levels):
""" Build a binary tree from a list of integers representing level-order traversal where -1 represents a null node.
>>> build_tree([1, 2, 3, -1, 5, -1, -1]) Tree with r... | class TreeNode:
def __init__(self, val):
self.val = val
self.left = None
self.right = None
def build_tree(levels):
if not levels or levels[0] == -1:
return None
root = TreeNode(levels[0])
queue = [root]
i = 1
while queue and i < len(levels):
cur... | from solution import build_tree, left_view, find_left_view_of_trees
def test_build_tree():
levels = [1, 2, 3, -1, 5, -1, -1]
root = build_tree(levels)
assert root.val == 1
assert root.left.val == 2
assert root.right.val == 3
assert root.left.right.val == 5
assert root.left.left == None
... | [] | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, x):\n self.val = x\n self.left = None\n self.right = None\n\ndef build_tree(values):\n \"\"\"\n ... | trial_gpt4o_2 | {
"original_instruction": "Given a binary tree, you need to write a function that finds the left view of the binary tree. The left view of a binary tree is the set of nodes visible when the tree is viewed from the left side.\n\n-----Input:-----\n- The input consists of multiple test cases.\n- The first line contains ... | 0.549852 | Taco_137 | C | [
"build_tree",
"left_view_util",
"left_view",
"find_left_view_of_trees"
] | 4 | [
[
"find_left_view_of_trees",
"build_tree"
],
[
"find_left_view_of_trees",
"left_view"
],
[
"left_view",
"left_view_util"
]
] | 3 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | b4d864e42bc60df28792eecabc65ba1956b1d792 | cb99319b7af202f7042edd67aff41d38dd9379d2 | |||
v1.0 | complete | Taco | Taco_228_C | def min_adjacent_swaps(test_cases: List[Tuple[int, List[int]]]) -> List[int]:
""" Determine the minimum number of adjacent swaps required to sort multiple arrays in ascending order.
Args:
test_cases (List[Tuple[int, List[int]]]): A list of tuples, where each tuple contains an integer representing the number... | def merge_and_count(arr, temp_arr, left, mid, right):
i = left # Starting index for left subarray
j = mid + 1 # Starting index for right subarray
k = left # Starting index to be sorted
inv_count = 0
while i <= mid and j <= right:
if arr[i] <= arr[j]:
temp_arr[k] = arr[i]... | from solution import min_adjacent_swaps
def test_min_adjacent_swaps_example():
test_cases = [
(3, [3, 2, 1]),
(4, [4, 3, 2, 1]),
]
assert min_adjacent_swaps(test_cases) == [3, 6]
def test_min_adjacent_swaps_sorted():
test_cases = [
(3, [1, 2, 3]),
(4, [1, 2, 3, 4]),
... | [
{
"docstring": null,
"function_declaration": "def merge_and_count(arr, temp_arr, left, mid, right):",
"function_name": "merge_and_count",
"parameter_list": "(arr, temp_arr, left, mid, right)"
},
{
"docstring": null,
"function_declaration": "def merge_sort_and_count(arr, temp_arr, left, r... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def merge_and_count(arr, temp_arr, left, mid, right):\n i = left # Starting index for left subarray\n j = mid + 1 # Starting index for right subarray\n ... | trial_gpt4o_0 | {
"original_instruction": "Ash has been given a task by his computer science professor. He needs to analyze the efficiency of sorting algorithms. Ash is provided with multiple arrays. For each array, he needs to determine the minimum number of adjacent swaps required to sort the array in ascending order. Can you help... | 0.678799 | Taco_228 | C | [
"merge_and_count",
"merge_sort_and_count",
"min_adjacent_swaps"
] | 3 | [
[
"merge_sort_and_count",
"merge_and_count"
],
[
"min_adjacent_swaps",
"merge_sort_and_count"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 26620207c28129ef83d77dfef144b304d49ba331 | 81501970c9663a56ada3b910e81d15f9f2edfc08 | |||
v1.0 | complete | Taco | Taco_374_C | import math
def is_perfect_square(num):
"""Check if a given number is a perfect square."""
if num < 0:
return False
sqrt_num = int(math.sqrt(num))
return sqrt_num * sqrt_num == num
def has_pair_with_condition(n, integers):
"""
Checks if there exists a pair of integers (a, b) in the co... | import math
def is_perfect_square(num):
if num < 0:
return False
sqrt_num = int(math.sqrt(num))
return sqrt_num * sqrt_num == num
def has_pair_with_condition(n, integers):
integers_set = set(integers)
for a in integers:
for b in integers:
if b >= a * a + a:
... | from solution import has_pair_with_condition
def test_has_pair_with_valid_pair():
assert has_pair_with_condition(5, [3, 12, 25, 7, 18]) == "YES"
def test_has_pair_without_valid_pair():
assert has_pair_with_condition(3, [5, 7, 11]) == "NO"
def test_with_negative_numbers():
assert has_pair_with_condition(4... | [
{
"docstring": null,
"function_declaration": "def is_perfect_square(num):",
"function_name": "is_perfect_square",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def has_pair_with_condition(n, integers):",
"function_name": "has_pair_with_condition",
"pa... | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef exists_pair_with_conditions(n, numbers):\n \"\"\"\n Check if there exists a pair (a, b) such that:\n - a * b is a perfect square\n -... | trial_gpt4o_4 | {
"original_instruction": "You are given a collection of `n` distinct integers. Your task is to find out whether there exists a pair of integers (a, b) in this collection such that their product is a perfect square, and b is greater than or equal to a^2 + a.\n\nA perfect square is an integer that is the square of an ... | 0.660892 | Taco_374 | C | [
"is_perfect_square",
"has_pair_with_condition"
] | 2 | [
[
"has_pair_with_condition",
"is_perfect_square"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 1eb8531a0a44e7a81e0a9699a259f522c60842ac | bf6eb8f2ab1a0a1477a37b48310e174a7a76ab88 | |||
v1.0 | complete | Taco | Taco_179_C | def min_lights_to_connect_islands(T: int, test_cases: list) -> list:
""" Calculate the minimum length of lights needed to connect all the islands
in an optimal manner for each test case.
>>> min_lights_to_connect_islands(2, [
(4, 5, [(1, 2, 1), (1, 3, 2), (4, 1, 4), (2, 4, 3), (3, 4, 5... | def find(parent, i):
if parent[i] != i:
parent[i] = find(parent, parent[i])
return parent[i]
def union(parent, rank, x, y):
rootX = find(parent, x)
rootY = find(parent, y)
if rootX != rootY:
if rank[rootX] > rank[rootY]:
parent[rootY] = rootX
elif rank[rootX... | def test_min_lights_to_connect_islands():
test_cases = [
(4, 5, [(1, 2, 1), (1, 3, 2), (4, 1, 4), (2, 4, 3), (3, 4, 5)]),
(3, 3, [(1, 2, 7), (2, 3, 10), (3, 1, 5)])
]
expected_results = [6, 12]
assert min_lights_to_connect_islands(2, test_cases) == expected_results
def test_empty_g... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n else:\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n root_x = f... | trial_gpt4o_4 | {
"original_instruction": "The ancient city of Zephyria is celebrated for its intricate network of roads and bridges connecting its numerous islands. Each year, the citizens host a grand festival where they string lights along these roads and bridges in a dazzling display. To make the arrangement more efficient, the ... | 0.594968 | Taco_179 | C | [
"find",
"union",
"min_lights_to_connect_islands",
"solve"
] | 4 | [
[
"min_lights_to_connect_islands",
"find"
],
[
"min_lights_to_connect_islands",
"union"
],
[
"solve",
"min_lights_to_connect_islands"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | false | [] | true | 7b00832aad6732958097587c312ba637622dadcd | 963ce2419299de130bce24f78796018906bf8554 | |||
v1.0 | complete | Taco | Taco_406_C | def is_prime(n):
"""
Checks if a number is prime.
>>> is_prime(2) True
>>> is_prime(4) False
"""
def fibonacci(n):
"""
Returns the n-th Fibonacci number.
The Fibonacci sequence starts from 0, 1, 1, 2, 3, 5, 8, ...
>>> fibonacci(0) 0
>>> fibonacci(7) 13
"""
def sum_o... | 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 fibonacci(n):
"""
Ret... | from solution import is_prime, fibonacci, sum_of_evens, process_number
def test_is_prime():
assert not is_prime(1)
assert is_prime(2)
assert is_prime(3)
assert not is_prime(4)
assert is_prime(5)
assert not is_prime(10)
def test_fibonacci():
assert fibonacci(0) == 0
assert fibonacci(1) ... | [
{
"docstring": "Checks if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns the n-th Fibonacci number.\nThe Fibonacci sequence starts from 0, 1, 1, 2, 3, 5, 8, ...",
"function_declaration": "de... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Checks if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2... | trial_gpt4o_0 | {
"original_instruction": "# Task:\n\nGiven an integer `n`, write a function to check if it's a prime number and return the `n`-th Fibonacci number if it is, or the sum of all even numbers from `1` to `n` (inclusive) if it is not.\n\n## Example:\n```python\nInput: process_number(7)\n\nOutput: \"7 is prime, 13th Fibon... | 0.765134 | Taco_406 | C | [
"is_prime",
"fibonacci",
"sum_of_evens",
"process_number"
] | 4 | [
[
"process_number",
"fibonacci"
],
[
"process_number",
"is_prime"
],
[
"process_number",
"sum_of_evens"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 7019cf866f0f9677ea7012a810ea404707242e01 | e70a6b5165caf3e934a91924fc19c763e0f5eecd | |||
v1.0 | complete | Taco | Taco_464_C | class TreeNode:
def __init__(self, value):
self.value = value
self.left = None
self.right = None
def build_tree(values):
"""
Build a binary tree from level-order traversal values.
:param values: List of integers or None, representing level-order traversal of a binary tree.
... | class TreeNode:
def __init__(self, value):
self.value = value
self.left = None
self.right = None
def build_tree(values):
if not values:
return None
it = iter(values)
root = TreeNode(next(it))
queue = [root]
while queue:
node = queue.pop(0)
try:
... | from solution import build_tree, transform_to_bst, inorder_traversal, process_trees
def test_single_node_tree():
values = [1]
root = build_tree(values)
transform_to_bst(root)
assert inorder_traversal(root) == [1]
def test_already_bst_tree():
values = [1, 2, 3]
root = build_tree(values)
tra... | [] | [
0,
0,
0,
1,
1
] | 2 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "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 level_o... | trial_gpt4o_4 | {
"original_instruction": "You are given a binary tree where each node contains an integer value. Write a program to transform this binary tree into a binary search tree (BST) while maintaining the original structure of the tree (i.e., the transformed tree should have the same structure as the original tree).\n\n### ... | 0.540853 | Taco_464 | C | [
"build_tree",
"inorder_traversal",
"transform_to_bst",
"process_trees"
] | 4 | [
[
"process_trees",
"build_tree"
],
[
"process_trees",
"inorder_traversal"
],
[
"process_trees",
"transform_to_bst"
],
[
"transform_to_bst",
"inorder_traversal"
]
] | 4 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 465e08b7f415f11f6292f1f20ae5d07f3bb60304 | dbde3836d2074d843c842112ec88f7f61856de5a | |||
v1.0 | complete | Taco | Taco_513_C | def maximal_rectangle(matrix):
""" Determine the largest rectangular area that can be formed using only cells that contain the value 1.
The grid is represented as a list of list of integers where 0 <= grid[i][j] <= 1.
Args:
matrix: List[List[int]]
Returns:
int: the area of the largest rectangl... | def maximal_rectangle(matrix):
if not matrix:
return 0
n, m = len(matrix), len(matrix[0])
max_area = 0
heights = [0] * m
for row in matrix:
for j in range(m):
heights[j] = heights[j] + 1 if row[j] == 1 else 0
max_area = max(max_area, largest_rectangle_area(heigh... | from solution import maximal_rectangle
def test_maximal_rectangle_4x4():
matrix = [
[1, 0, 1, 0],
[1, 0, 1, 1],
[1, 1, 1, 1],
[1, 0, 1, 1]
]
assert maximal_rectangle(matrix) == 6
def test_maximal_rectangle_3x3():
matrix = [
[1, 1, 1],
[1, 0, 1],
... | [
{
"docstring": null,
"function_declaration": "def maximal_rectangle(matrix):",
"function_name": "maximal_rectangle",
"parameter_list": "(matrix)"
},
{
"docstring": null,
"function_declaration": "def largest_rectangle_area(heights):",
"function_name": "largest_rectangle_area",
"pa... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def maximalRectangle(grid):\n \"\"\"\n This function calculates the area of the largest rectangle consisting only of 1s in a 2D grid.\n :param grid: List ... | trial_gpt4o_1 | {
"original_instruction": "You are given a 2D grid of size NxM. Each cell in the grid contains either a 0 or a 1. Your task is to determine the largest rectangular area that can be formed using only cells that contain the value 1.\n\nWrite a program that reads the dimensions of the grid and its contents, and then cal... | 0.78021 | Taco_513 | C | [
"maximal_rectangle",
"largest_rectangle_area"
] | 2 | [
[
"maximal_rectangle",
"largest_rectangle_area"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d76281c04e8631e3d55a0a5668c2d2e26f8eb177 | 475900f9cbcf94cf4636ca1f907048723743fb15 | |||
v1.0 | complete | Taco | Taco_739_C | def next_palindrome(n: int) -> int:
""" Given an integer n, find the smallest palindrome larger than n.
>>> next_palindrome(123) == 131
>>> next_palindrome(999) == 1001
>>> next_palindrome(987654321) == 987656789
""" | def is_palindrome(number):
"""
Helper function to check if a number is a palindrome.
"""
return str(number) == str(number)[::-1]
def next_palindrome(n):
"""
Function to find the smallest palindrome larger than n.
"""
n += 1
while not is_palindrome(n):
n += 1
return n
# ... | from solution import next_palindrome
def test_next_palindrome_small_numbers():
assert next_palindrome(123) == 131
assert next_palindrome(130) == 131
assert next_palindrome(999) == 1001
def test_next_palindrome_large_numbers():
assert next_palindrome(1234321) == 1235321
assert next_palindrome(98765... | [
{
"docstring": "Helper function to check if a number is a palindrome.",
"function_declaration": "def is_palindrome(number):",
"function_name": "is_palindrome",
"parameter_list": "(number)"
},
{
"docstring": "Function to find the smallest palindrome larger than n.",
"function_declaration"... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome(x):\n return str(x) == str(x)[::-1]\n\ndef smallest_palindrome_larger_than(n):\n \"\"\"\n Returns the smallest palindrome larger than n.... | trial_gpt4o_2 | {
"original_instruction": "Given an integer $n$, find the smallest palindrome larger than $n$. A palindrome is a number that reads the same backward as forward (e.g., $121$ or $12321$).\n\nInput Format\n\nA single integer $n$.\n\nConstraints\n\n$1 \\leq n \\leq 10^{12}$\n\nOutput Format\n\nPrint the smallest palindro... | 0.750007 | Taco_739 | C | [
"is_palindrome",
"next_palindrome"
] | 2 | [
[
"next_palindrome",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 9c422673ddcc2ac9a80ad3e72cf1f0e42db2935e | bdb61107202869a29372b8ab10857205f4045fe1 | |||
v1.0 | complete | Taco | Taco_798_C | def is_prime(n: int) -> bool:
"""
Helper function to determine if a number is prime.
"""
pass
def filter_primes(arr: List[int]) -> List[int]:
"""
Returns a new array containing only the prime numbers from the input array.
>>> filter_primes([4, 5, 8, 9, 11])
[5, 11]
>>> filter_prime... | 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
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return False
return True
def filter_pr... | from solution import filter_primes
def test_empty_array():
assert 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([4, 5, 8, 9, 1... | [
{
"docstring": "Helper function to determine 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 input array.",
"function_declaration": "... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Returns True if n is a prime number, otherwise False.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n ... | trial_gpt4o_1 | {
"original_instruction": "You are given an array of integers. Your task is to write a function that returns a new array containing only the prime numbers from the given array. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself.\n\n## Examples\n\n* For the input `[... | 0.775256 | Taco_798 | C | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 59e1dabf2c04e52f12088a821de2ebf25333a234 | 44deaf68460276381217530b87d802198cd72181 | |||
v1.0 | complete | Taco | Taco_407_C | from typing import List, Tuple
from collections import defaultdict, deque
def count_bipartite_components(N: int, M: int, edges: List[Tuple[int, int]]) -> int:
""" Determines the number of bipartite components in the graph.
Args:
N (int): Number of vertices
M (int): Number of edges
edges (List[Tuple... | from collections import defaultdict, deque
def is_bipartite_component(graph, start, visited):
queue = deque([start])
visited[start] = 1 # Start coloring with 1
while queue:
node = queue.popleft()
for neighbor in graph[node]:
if visited[neighbor] == -1:
visited[... | from solution import count_bipartite_components
def test_single_component_bipartite():
N, M = 5, 4
edges = [(1, 2), (2, 3), (3, 4), (4, 5)]
assert count_bipartite_components(N, M, edges) == 1
def test_multiple_components_bipartite():
N, M = 6, 4
edges = [(1, 2), (2, 3), (4, 5), (5, 6)]
assert ... | [
{
"docstring": null,
"function_declaration": "def is_bipartite_component(graph, start, visited):",
"function_name": "is_bipartite_component",
"parameter_list": "(graph, start, visited)"
},
{
"docstring": null,
"function_declaration": "def count_bipartite_components(N, M, edges):",
"f... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def count_bipartite_components(N, M, edges):\n from collections import defaultdict, deque\n \n graph = defaultdict(list)\n for u, v in edges:\n ... | trial_gpt4o_2 | {
"original_instruction": "You are given an undirected graph with N vertices and M edges. Your task is to determine the number of components in the graph that are bipartite. A bipartite graph is a graph whose vertices can be divided into two disjoint sets such that no two graph vertices within the same set are adjace... | 0.551336 | Taco_407 | C | [
"is_bipartite_component",
"count_bipartite_components"
] | 2 | [
[
"count_bipartite_components",
"is_bipartite_component"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7c850d4d457e059818805c1d653e81ff6e1760df | a4ab064a4e69fb29c0de5ebfd3e2a18c25dbf7d6 | |||
v1.0 | complete | Taco | Taco_412_C | def is_prime(n: int) -> bool:
""" Helper function to determine if a number is prime.
>>> is_prime(2) True
>>> is_prime(3) True
>>> is_prime(4) False
"""
pass
def find_prime_creature_ids(ability_levels: List[int]) -> List[int]:
""" Returns the IDs of creatures whose ability levels are prime ... | def is_prime(n):
""" Helper function to determine if a number is prime """
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
... | from solution import find_prime_creature_ids, is_prime
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(17) == True
assert is_prime(18) == False
assert is_prime(19) == True
def test_find_prime_creature_ids_example1():
ab... | [
{
"docstring": "Helper function to determine if a number is prime ",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns the IDs of creatures whose ability levels are prime numbers.",
"function_declaration": "def fin... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Check if 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_2 | {
"original_instruction": "Problem description:\nIn a distant land, there are different species of magical creatures. Each creature has a different ability level represented by a positive integer. A new threat has emerged, and now the magical council is interested in identifying whether any creatures have an ability ... | 0.711558 | Taco_412 | C | [
"is_prime",
"find_prime_creature_ids"
] | 2 | [
[
"find_prime_creature_ids",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 555b620486363e85a0a28094f879289ee4bbf6d3 | 9628141ca63bc4c63298c120efc0caeed100dab3 | |||
v1.0 | complete | Taco | Taco_543_C | def determine_satisfaction(ratings_list):
"""
This function takes a list of lists where each inner list represents the ratings given by a single customer.
It returns a list of boolean values indicating whether each customer is satisfied.
"""
def format_satisfaction_result(ratings_list):
"""
Thi... | def determine_satisfaction(ratings_list):
"""
This function takes a list of lists where each inner list represents the ratings given by a single customer.
It returns a list of boolean values indicating whether each customer is satisfied.
"""
result = []
for ratings in ratings_list:
if al... | def test_determine_satisfaction_all_satisfied():
assert determine_satisfaction([[5, 3, 4, 3], [4, 4, 4, 4]]) == [True, True]
def test_determine_satisfaction_some_not_satisfied():
assert determine_satisfaction([[5, 3, 4, 3], [2, 1, 5, 3]]) == [True, False]
def test_determine_satisfaction_none_satisfied():
... | [
{
"docstring": "This function takes a list of lists where each inner list represents the ratings given by a single customer.\nIt returns a list of boolean values indicating whether each customer is satisfied.",
"function_declaration": "def determine_satisfaction(ratings_list):",
"function_name": "determ... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def customer_satisfaction(customers_ratings):\n \"\"\"\n Determines if customers are satisfied based on their ratings.\n \n Args:\n customers_rating... | trial_gpt4o_2 | {
"original_instruction": "You are tasked with developing a Customer Satisfaction algorithm for a shopping website. The website collects ratings from customers after each purchase. The ratings are represented as integers on a scale from 1 to 5, with 1 being the lowest and 5 being the highest. Based on these ratings, ... | 0.662777 | Taco_543 | C | [
"determine_satisfaction",
"format_satisfaction_result"
] | 2 | [
[
"format_satisfaction_result",
"determine_satisfaction"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 8da5fe1706c459b3fcc63a16c022adc825951f69 | 857c319b2e64baec1435637419cefb711f6237f1 | |||
v1.0 | complete | Taco | Taco_452_C | def solve_mosaic(N, M, K, initial_grid):
""" Alyssa is trying to create a mosaic using a grid of tiles. She has an
unlimited supply of tiles of different colors. She wants to color a given grid
following specific constraints.
The grid is an N x M matrix where each cell can be painted in one of K diff... | def is_valid_color(grid, r, c, color, N, M):
# Checking adjacent cells for the same color
for dr, dc in [(-1, 0), (1, 0), (0, -1), (0, 1)]: # Up, Down, Left, Right
nr, nc = r + dr, c + dc
if 0 <= nr < N and 0 <= nc < M and grid[nr][nc] == color:
return False
return True
def sol... | from solution import solve_mosaic
def test_example_case():
N, M, K = 3, 3, 3
initial_grid = [
[1, 0, 0],
[0, 0, 0],
[0, 0, 2]
]
result, grid = solve_mosaic(N, M, K, initial_grid)
assert result == "YES"
assert grid != None
assert grid[0][0] == 1
assert grid[2][2] ... | [
{
"docstring": null,
"function_declaration": "def is_valid_color(grid, r, c, color, N, M):",
"function_name": "is_valid_color",
"parameter_list": "(grid, r, c, color, N, M)"
},
{
"docstring": null,
"function_declaration": "def solve_mosaic(N, M, K, initial_grid):",
"function_name": "... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_valid_color(grid, row, col, color, N, M):\n # Check adjacent cells to ensure no two adjacent cells have the same color\n directions = [(-1, 0), (1, 0)... | trial_gpt4o_1 | {
"original_instruction": "Alyssa is trying to create a mosaic using a grid of tiles. She has an unlimited supply of tiles of different colors. She wants to color a given grid following specific constraints.\n\nThe grid is an N x M matrix where each cell can be painted in one of K different colors. She wants to paint... | 0.700027 | Taco_452 | C | [
"is_valid_color",
"solve_mosaic",
"main"
] | 3 | [
[
"solve_mosaic",
"is_valid_color"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e91e27484a087eabb2cdadf203ab8a64429567c6 | c0a392614a3fff7b3fd77bb282bffb49f6a53234 | |||
v1.0 | complete | Taco | Taco_943_C | def max_sum_possible(arr):
""" Returns the maximum possible sum of elements of the array after performing
the operations optimally.
>>> max_sum_possible([1, 2, 3])
6
>>> max_sum_possible([5, 3, 9, 1])
18
"""
def solve_case(n, arr):
""" Solves a single test case.
>>> solve_case(3, ... | def max_sum_possible(arr):
"""
Returns the maximum possible sum of elements of the array after performing
the operations optimally.
"""
return sum(arr)
def solve_case(n, arr):
"""
Solves a single test case.
"""
return max_sum_possible(arr)
def max_sum_of_elements(test_cases):
... | from solution import solve_case, max_sum_of_elements
def test_solve_case():
assert solve_case(3, [1, 2, 3]) == 6
assert solve_case(4, [5, 3, 9, 1]) == 18
def test_max_sum_of_elements():
assert max_sum_of_elements([
(3, [1, 2, 3]),
(4, [5, 3, 9, 1]),
]) == [6, 18]
assert max_sum_of... | [
{
"docstring": "Returns the maximum possible sum of elements of the array after performing \nthe operations optimally.",
"function_declaration": "def max_sum_possible(arr):",
"function_name": "max_sum_possible",
"parameter_list": "(arr)"
},
{
"docstring": "Solves a single test case.",
"f... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_sum_after_operations(T, test_cases):\n \"\"\"\n Function to find the maximum possible sum of array elements after performing the specified operations... | trial_gpt4o_2 | {
"original_instruction": "Tina loves solving puzzles. She has a number puzzle that consists of an array of integers. The puzzle asks her to perform operations on the elements of the array to obtain a new array where the sum of the elements is maximum. Here’s how the operation works:\n\nTina can choose any two elemen... | 0.676273 | Taco_943 | C | [
"max_sum_possible",
"solve_case",
"max_sum_of_elements"
] | 3 | [
[
"max_sum_of_elements",
"solve_case"
],
[
"solve_case",
"max_sum_possible"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | a034098e874fd334b3bb07a987c9fd9cff9fef25 | 4a9d7934d2aa2fdf9988f274ff4ec7c41128a23b | |||
v1.0 | complete | Taco | Taco_1054_C | from fractions import Fraction
from typing import List, Tuple
def sum_of_fractions(fractions_list: List[Tuple[int, int]]) -> Fraction:
""" Takes a list of tuples representing fractions and returns the sum of them in simplest form.
>>> sum_of_fractions([(1, 2)]) == Fraction(1, 2)
>>> sum_of_fractions([(1, 3... | from fractions import Fraction
def sum_of_fractions(fractions_list):
"""
Takes a list of tuples representing fractions and returns the sum of them in simplest form.
Args:
fractions_list (list): A list of tuples where each tuple contains two integers (numerator, denominator).
Returns:
... | from solution import sum_of_fractions
def test_single_fraction():
assert sum_of_fractions([(1, 2)]) == Fraction(1, 2)
def test_two_fractions():
assert sum_of_fractions([(1, 3), (2, 5)]) == Fraction(11, 15)
def test_multiple_fractions():
assert sum_of_fractions([(1, 2), (1, 3), (1, 6)]) == Fraction(1, 1)
... | [
{
"docstring": "Takes a list of tuples representing fractions and returns the sum of them in simplest form.\n\nArgs:\nfractions_list (list): A list of tuples where each tuple contains two integers (numerator, denominator).\n\nReturns:\nFraction: The sum of the fractions in simplest form.",
"function_declara... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from fractions import Fraction\n\ndef sum_of_fractions(fractions_list):\n \"\"\"\n Takes a list of tuples representing fractions and returns the sum of them ... | trial_gpt4o_0 | {
"original_instruction": "=====Problem Statement=====\nYou are given another list of rational numbers. Your task is to find and print the sum of these rational numbers in its simplest form.\n\nConcept\nThe `fractions.Fraction` class provides support for rational number arithmetic in Python. Using this class, you can... | 0.629255 | Taco_1054 | C | [
"sum_of_fractions",
"rational_sum"
] | 2 | [
[
"rational_sum",
"sum_of_fractions"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 658ea3935f3c74b177ad07e857585138a6883553 | 4c16193583ff0f04dcb3b0daef1625e3459462f8 | |||
v1.0 | complete | Taco | Taco_712_C | def max_boxes_on_conveyor(max_capacity: int, boxes: List[Tuple[int, int]]) -> int:
"""
Given the max capacity of the conveyor belt and a list of boxes with their sizes,
return the maximum number of boxes that can be placed on the belt without exceeding the capacity.
Parameters:
max_capacity (in... | def max_boxes_on_conveyor(max_capacity, boxes):
"""
Given the max capacity of the conveyor belt and a list of boxes with their sizes,
return the maximum number of boxes that can be placed on the belt without exceeding the capacity.
Parameters:
max_capacity (int): Maximum capacity of the conveyo... | import pytest
from solution import max_boxes_on_conveyor
def test_sample_input_1():
assert max_boxes_on_conveyor(10, [(1, 3), (2, 4), (3, 2), (4, 5)]) == 3
def test_sample_input_2():
assert max_boxes_on_conveyor(15, [(10, 5), (11, 8), (12, 6), (13, 3), (14, 2)]) == 3
def test_no_boxes():
assert max_boxes... | [
{
"docstring": "Given the max capacity of the conveyor belt and a list of boxes with their sizes,\nreturn the maximum number of boxes that can be placed on the belt without exceeding the capacity.\n\nParameters:\nmax_capacity (int): Maximum capacity of the conveyor belt\nboxes (List[Tuple[int, int]]): List of t... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_boxes(capacity, boxes):\n boxes.sort(key=lambda x: x[1])\n total_size = 0\n count = 0\n for _, size in boxes:\n if total_size + size <= ... | trial_gpt4o_2 | {
"original_instruction": "A manufacturing company uses a robotic arm to place boxes on a conveyor belt. These boxes are labeled with unique integer identifiers and have varying sizes. The conveyor belt has a limited capacity, measured by the sum of the sizes of the boxes it can hold at any given time.\n\nYou are tas... | 0.647932 | Taco_712 | C | [
"max_boxes_on_conveyor",
"manage_boxes"
] | 2 | [
[
"manage_boxes",
"max_boxes_on_conveyor"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d14d7dd5892fcca5fad64abc73b4306378cc6f80 | 69ce3569e6580ca8fe8c4a740cf63e2f9a5d5b22 | |||
v1.0 | complete | Taco | Taco_990_C | from typing import List
def shortest_safe_path(grid: List[List[int]]) -> int:
""" Find the shortest safe path in a minefield grid from the top-left corner to the bottom-right corner.
>>> grid = [
... [0, 0, 0, 0],
... [0, 1, 1, 0],
... [0, 0, 0, 0],
... [1, 1, 1, 0]
... ]
... | from collections import deque
def is_valid_move(x, y, grid, visited):
n, m = len(grid), len(grid[0])
return 0 <= x < n and 0 <= y < m and grid[x][y] == 0 and not visited[x][y]
def shortest_safe_path(grid):
n, m = len(grid), len(grid[0])
if grid[0][0] == 1 or grid[n-1][m-1] == 1:
return -1
... | from solution import shortest_safe_path
def test_shortest_safe_path_basic():
grid = [
[0, 0, 0, 0],
[0, 1, 1, 0],
[0, 0, 0, 0],
[1, 1, 1, 0]
]
assert shortest_safe_path(grid) == 6
def test_shortest_safe_path_no_path():
grid = [
[0, 1, 1, 1],
[1, 1, 1, 0]... | [
{
"docstring": null,
"function_declaration": "def is_valid_move(x, y, grid, visited):",
"function_name": "is_valid_move",
"parameter_list": "(x, y, grid, visited)"
},
{
"docstring": null,
"function_declaration": "def shortest_safe_path(grid):",
"function_name": "shortest_safe_path",
... | [
0,
0,
0,
1,
1
] | 2 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef shortest_safe_path(grid, n, m):\n if grid[0][0] == 1 or grid[n-1][m-1] == 1:\n return -1\n \n # Directions: (u... | trial_gpt4o_4 | {
"original_instruction": "Shortest Safe Path in a Grid with Landmines\n\nYou are given a grid representing a minefield where each cell is either safe (0) or contains a landmine (1). Your task is to find the shortest safe path in the minefield grid from the top-left corner (0,0) to the bottom-right corner (n-1,m-1), ... | 0.637207 | Taco_990 | C | [
"is_valid_move",
"shortest_safe_path"
] | 2 | [
[
"shortest_safe_path",
"is_valid_move"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | eb9e5ebb7e40d3b14ccd72d066602b6a81e49f2b | e42b12176fab8211eea5721e1b07ac7ce2a81a32 | |||
v1.0 | complete | Taco | Taco_805_C | def find_approx_hamiltonian_cycle(n: int, m: int, k: int, roads_info: List[Tuple[int, int, int]]) -> int:
"""
Approximate the shortest Hamiltonian cycle for a given number of distribution centers and roads.
Args:
n (int): Number of distribution centers.
m (int): Number of roads.
k (int): Start... | def nearest_neighbor_tsp(n, m, k, roads):
from collections import defaultdict
import heapq
graph = defaultdict(list)
for u, v, d in roads:
graph[u].append((d, v))
graph[v].append((d, u))
visited = [False] * (n + 1)
path_cost = 0
current = k
for _ in range(n - 1... | from solution import find_approx_hamiltonian_cycle
def test_case_1():
n = 4
m = 6
k = 1
roads_info = [
(1, 2, 10),
(1, 3, 15),
(1, 4, 20),
(2, 3, 35),
(2, 4, 25),
(3, 4, 30)
]
assert find_approx_hamiltonian_cycle(n, m, k, roads_info) == 80
def te... | [
{
"docstring": null,
"function_declaration": "def nearest_neighbor_tsp(n, m, k, roads):",
"function_name": "nearest_neighbor_tsp",
"parameter_list": "(n, m, k, roads)"
},
{
"docstring": null,
"function_declaration": "def find_approx_hamiltonian_cycle(n, m, k, roads_info):",
"function... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def tsp_approximation(n, m, start, roads):\n import itertools\n\n # Build graph (adjacency matrix) based on input roads\n graph = [[float('inf')] * n for ... | trial_gpt4o_1 | {
"original_instruction": "A logistics company needs to optimize the delivery route for their trucks to minimize the total travel distance. The company operates in a city with n cargo distribution centers and m bidirectional roads connecting the centers. Each road has an associated travel distance.\n\nThe company's g... | 0.603237 | Taco_805 | C | [
"nearest_neighbor_tsp",
"find_approx_hamiltonian_cycle"
] | 2 | [
[
"find_approx_hamiltonian_cycle",
"nearest_neighbor_tsp"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f5dd95fb97cfadc45bdb7800c7ee3ee8156d399e | f1c70c12b7022386d37c0c2746135ddcaff2a184 | |||
v1.0 | complete | Taco | Taco_887_C | from typing import List
def can_form_palindrome(s: str) -> str:
"""Determines if a string can be rearranged to form a palindrome.
Args:
s (str): The input string consisting of only lowercase letters.
Returns:
str: "YES" if the string can be rearranged to form a palindrome, otherwise "NO".... | def can_form_palindrome(s):
"""
Determines if a string can be rearranged to form a palindrome.
Args:
s (str): The input string consisting of only lowercase letters.
Returns:
str: "YES" if the string can be rearranged to form a palindrome, otherwise "NO".
"""
from collections im... | from solution import can_form_palindrome, can_form_palindrome_multiple_cases
def test_can_form_palindrome_yes_cases():
assert can_form_palindrome("civic") == "YES"
assert can_form_palindrome("ivicc") == "YES"
assert can_form_palindrome("aabb") == "YES"
assert can_form_palindrome("a") == "YES"
asser... | [
{
"docstring": "Determines if a string can be rearranged to form a palindrome.\n\nArgs:\ns (str): The input string consisting of only lowercase letters.\n\nReturns:\nstr: \"YES\" if the string can be rearranged to form a palindrome, otherwise \"NO\".",
"function_declaration": "def can_form_palindrome(s):",
... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def can_form_palindrome(s):\n \"\"\"\n Returns 'YES' if the string `s` can be rearranged to form a palindrome, otherwise returns 'NO'.\n \"\"\"\n from ... | trial_gpt4o_2 | {
"original_instruction": "A palindrome is a string that reads the same forward and backward. Given a series of strings, our task is to determine if each string in the list can be rearranged to form a palindrome. Note that an empty string is considered a valid palindrome.\n\n-----Input-----\nThe input consists of N c... | 0.722729 | Taco_887 | C | [
"can_form_palindrome",
"can_form_palindrome_multiple_cases"
] | 2 | [
[
"can_form_palindrome_multiple_cases",
"can_form_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 00035f280785845cb5b36ede360317f4da5a7fa4 | e25d0acb7a15908a91f3c8a3484e5bc86e4c0be0 | |||
v1.0 | complete | Taco | Taco_1283_C | from typing import List
def count_palindromic_pairs(words: List[str]) -> int:
""" Given a list of words, find the number of pairs of indices (i, j) where
0 ≤ i < j < len(words) such that the concatenation of words[i] and words[j]
forms a palindrome.
>>> count_palindromic_pairs(["bat", "tab", "ca... | def is_palindrome(s):
return s == s[::-1]
def count_palindromic_pairs(words):
count = 0
for i in range(len(words)):
for j in range(i + 1, len(words)):
if is_palindrome(words[i] + words[j]):
count += 1
return count | from solution import count_palindromic_pairs
def test_example_1():
assert count_palindromic_pairs(["bat", "tab", "cat"]) == 1
def test_example_2():
assert count_palindromic_pairs(["abcd", "dcba", "lls", "s", "sssll"]) == 2
def test_no_pairs():
assert count_palindromic_pairs(["abc", "def", "ghi"]) == 0
d... | [
{
"docstring": null,
"function_declaration": "def is_palindrome(s):",
"function_name": "is_palindrome",
"parameter_list": "(s)"
},
{
"docstring": null,
"function_declaration": "def count_palindromic_pairs(words):",
"function_name": "count_palindromic_pairs",
"parameter_list": "(w... | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome(word):\n \"\"\"\n Helper function to check if a given word is a palindrome.\n \"\"\"\n return word == word[::-1]\n\ndef count_palindr... | trial_gpt4o_4 | {
"original_instruction": "Given a list of words, your task is to find the number of pairs of indices (i, j) where 0 ≤ i < j < len(words) such that the concatenation of words[i] and words[j] forms a palindrome.\n\nExample 1:\n\nInput: [\"bat\", \"tab\", \"cat\"]\n\nOutput: 1\nExplanation: The only palindromic pair is... | 0.699553 | Taco_1283 | C | [
"is_palindrome",
"count_palindromic_pairs"
] | 2 | [
[
"count_palindromic_pairs",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 46860e925f62575728f0104b1027ea07ec910191 | 0b39a1f682ad8862665f9bcfde011c38b80ca96c | |||
v1.0 | complete | Taco | Taco_811_C | import math
from typing import List, Tuple
def closest_repair_station_distance(drone_coordinate: Tuple[int, int], repair_stations: List[Tuple[int, int]]) -> int:
""" Calculate the closest distance between a drone and repair stations.
Args:
drone_coordinate (Tuple[int, int]): The coordinate of the dron... | import math
def closest_repair_station_distance(drone_coordinate, repair_stations):
"""Calculate the closest distance between a drone and repair stations."""
min_distance = float('inf')
for rx, ry in repair_stations:
distance = math.sqrt((rx - drone_coordinate[0]) ** 2 + (ry - drone_coordinate[1]) ... | import math
from solution import closest_repair_station_distance, process_test_case, find_closest_distances_to_stations
def test_closest_repair_station_distance():
drones = [(100, 100), (200, 200), (300, 300)]
repair_stations = [(150, 150), (250, 250)]
assert closest_repair_station_distance(drones[0],... | [
{
"docstring": "Calculate the closest distance between a drone and repair stations.",
"function_declaration": "def closest_repair_station_distance(drone_coordinate, repair_stations):",
"function_name": "closest_repair_station_distance",
"parameter_list": "(drone_coordinate, repair_stations)"
},
... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef closest_repair_station_distance(drone_coordinate, repair_stations):\n \"\"\"Calculate the closest distance between a drone and repair station... | trial_gpt4o_0 | {
"original_instruction": "You are managing a fleet of N drones that are initially stationed at unique points in a 2D plane. Each drone can travel at a constant speed in any direction. There are several repair stations scattered throughout the plane, where drones can go to get fixed if something goes wrong. Given the... | 0.575276 | Taco_811 | C | [
"closest_repair_station_distance",
"process_test_case",
"find_closest_distances_to_stations"
] | 3 | [
[
"find_closest_distances_to_stations",
"process_test_case"
],
[
"process_test_case",
"closest_repair_station_distance"
]
] | 2 | [
"process_test_case"
] | false | [] | false | pytest | true | [] | true | 46ea152fbd7bf99eb3ff9aed4c1b8db2e727f2d5 | 1cbf0f796f935e29f02442af6957ac2bf2b035d3 | |||
v1.0 | complete | Taco | Taco_558_C | def solve(input_str: str) -> str:
""" You are given two simple polygons defined by their vertices in the plane. Write a program to calculate the area of the intersection of the two polygons.
The input consists of several datasets. Each dataset starts with the number of vertices, n1, of the first polygon, f... | def polygon_area(polygon):
"""
Calculate the area of a simple polygon given its vertices.
"""
n = len(polygon)
area = 0
for i in range(n):
x1, y1 = polygon[i]
x2, y2 = polygon[(i + 1) % n]
area += x1 * y2 - y1 * x2
return abs(area) / 2
def inside(p, cp1, cp2):
""... | from solution import solve
def test_example_input():
input_str = """
4
0 0
4 0
4 4
0 4
4
2 2
6 2
6 6
2 6
0
"""
expected_output = "4.0000"
assert solve(input_str).strip() == expected_output
def test_no_intersection():
input_str = """
4
0 0
2 0... | [
{
"docstring": "Calculate the area of a simple polygon given its vertices.",
"function_declaration": "def polygon_area(polygon):",
"function_name": "polygon_area",
"parameter_list": "(polygon)"
},
{
"docstring": "Check if point p is inside the edge formed by cp1 and cp2.",
"function_decl... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from shapely.geometry import Polygon\nimport sys\n\n\ndef compute_intersection_area(polygon1, polygon2):\n \"\"\"\n Computes the area of the intersection of ... | trial_gpt4o_1 | {
"original_instruction": "You are given two simple polygons defined by their vertices in the plane. Write a program to calculate the area of the intersection of the two polygons. \n\n### Input\n\nThe input consists of several datasets. Each dataset starts with the number of vertices, n1, of the first polygon, follow... | 0.497222 | Taco_558 | C | [
"polygon_area",
"inside",
"intersection",
"clip_polygon",
"intersection_area",
"parse_input",
"solve"
] | 7 | [
[
"clip_polygon",
"inside"
],
[
"clip_polygon",
"intersection"
],
[
"intersection_area",
"clip_polygon"
],
[
"intersection_area",
"polygon_area"
],
[
"solve",
"intersection_area"
],
[
"solve",
"parse_input"
]
] | 6 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | c8ab155f6d8f524eb75469acf24c89d3d528503c | 928fa294225dfd3ffbdc59a70ba59ced7abe4a8c | |||
v1.0 | complete | Taco | Taco_1085_C | from typing import List
def level_order_to_bottom_up(input_str: str) -> str:
""" Given a binary tree, return the values of its nodes in a specific order, known as "bottom-up level order traversal".
In this order, the tree is traversed level by level from the bottom up, and from left to right within each level.... | from collections import deque
class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def build_tree(nodes):
if not nodes or nodes[0] == "null":
return None
root = TreeNode(int(nodes[0]))
queue = deque([root]... | from solution import level_order_to_bottom_up
def test_level_order_to_bottom_up_example1():
input_str = "3 9 20 null null 15 7"
expected_output = "15 7 9 20 3"
assert level_order_to_bottom_up(input_str) == expected_output
def test_level_order_to_bottom_up_example2():
input_str = "1 2 3 4 null null 5"
... | [] | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\nclass TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n ... | trial_gpt4o_2 | {
"original_instruction": "Given a binary tree, return the values of its nodes in a specific order, known as \"bottom-up level order traversal\". In this order, the tree is traversed level by level from the bottom up, and from left to right within each level.\n\n-----Input-----\nThe input consists of a single line th... | 0.542471 | Taco_1085 | C | [
"build_tree",
"bottom_up_level_order_traversal",
"level_order_to_bottom_up"
] | 3 | [
[
"level_order_to_bottom_up",
"bottom_up_level_order_traversal"
],
[
"level_order_to_bottom_up",
"build_tree"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 87bc697ce42bf2a680b21423070142065ab5002b | f4a670129287ac64743d8f5a64a512dadd606510 | |||
v1.0 | complete | Taco | Taco_1534_C | def maximum_rectangle_area_in_histogram(buildings):
"""
You are given a list of integers representing the heights of buildings along a street.
Calculate the maximum area of a rectangle formed by any contiguous buildings.
Each entry in the list represents the height of a building of unit width.
... | def largestRectangleArea(heights):
"""
Calculates the maximum area of a rectangle formed by any contiguous buildings.
Uses a stack to keep track of building heights.
"""
stack = []
max_area = 0
index = 0
while index < len(heights):
if not stack or heights[index] >= heights[s... | from solution import maximum_rectangle_area_in_histogram
def test_single_building():
assert maximum_rectangle_area_in_histogram([4]) == 4
def test_increasing_height_buildings():
assert maximum_rectangle_area_in_histogram([1, 2, 3, 4, 5]) == 9
def test_decreasing_height_buildings():
assert maximum_rectang... | [
{
"docstring": "Calculates the maximum area of a rectangle formed by any contiguous buildings.\nUses a stack to keep track of building heights.",
"function_declaration": "def largestRectangleArea(heights):",
"function_name": "largestRectangleArea",
"parameter_list": "(heights)"
},
{
"docstri... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_rectangle_area_in_histogram(heights):\n \"\"\"\n Calculate the maximum rectangle area in a histogram represented by a list of building heights.\n ... | trial_gpt4o_2 | {
"original_instruction": "You are given a list of integers representing the heights of buildings along a street. You have to calculate the maximum area of a rectangle formed by any contiguous buildings. Each entry in the list represents the height of a building of unit width.\n\nInput\n\nThe first line contains an i... | 0.643136 | Taco_1534 | C | [
"largestRectangleArea",
"maximum_rectangle_area_in_histogram"
] | 2 | [
[
"maximum_rectangle_area_in_histogram",
"largestRectangleArea"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8ecbc7f1d2256f786ea97fd59f733a42f32cbe4f | 19de773065a1db5730dbefe11c2a7ed2546cabed | |||
v1.0 | complete | Taco | Taco_596_C | def decode_number(encoded_number: str, base: int) -> int:
"""
Decodes the encoded number from the specified base to base 10.
"""
# Your code here
def evaluate_operation(x: int, operator: str, y: int) -> int:
"""
Evaluates the expression x operator y.
"""
# Your code here
def is_operati... | def decode_number(encoded_number, base):
"""
Decodes the encoded number from the specified base to base 10.
"""
return int(encoded_number, base)
def evaluate_operation(x, operator, y):
"""
Evaluates the expression x operator y.
"""
if operator == '+':
return x + y
elif opera... | def test_decode_number():
assert decode_number('10', 16) == 16
assert decode_number('1a', 16) == 26
assert decode_number('z', 36) == 35
def test_evaluate_operation():
assert evaluate_operation(2, '+', 3) == 5
assert evaluate_operation(10, '-', 2) == 8
assert evaluate_operation(1, '*', 2) == 2
... | [
{
"docstring": "Decodes the encoded number from the specified base to base 10.",
"function_declaration": "def decode_number(encoded_number, base):",
"function_name": "decode_number",
"parameter_list": "(encoded_number, base)"
},
{
"docstring": "Evaluates the expression x operator y.",
"f... | [
0,
0,
0,
0,
0,
0,
0,
0,
1,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_operation_correct(operation, base):\n # Helper function to convert a custom base number to int\n def to_int(value, base):\n return int(value, b... | trial_gpt4o_8 | {
"original_instruction": "You are given a list of operations in the form \"X operation Y = Z\", where X, Y, and Z are non-negative integers, and operation is one of '+', '-', '*', or '/'. However, the numbers and the operations are encoded in a custom base system using the symbols '0'-'9' and 'a'-'z' representing va... | 0.599535 | Taco_596 | C | [
"decode_number",
"evaluate_operation",
"is_operation_correct",
"parse_statement",
"count_correct_operations"
] | 5 | [
[
"count_correct_operations",
"is_operation_correct"
],
[
"is_operation_correct",
"decode_number"
],
[
"is_operation_correct",
"evaluate_operation"
],
[
"is_operation_correct",
"parse_statement"
]
] | 4 | [] | false | [] | false | pytest | false | [] | true | 358a9ce1dfc3ee3abeab0a67be224b257aa529f9 | db6c1d77400c7b0f26e13c376f7866af578be240 | |||
v1.0 | complete | Taco | Taco_1228_C | def sum_of_cubes_of_digits(n):
""" Returns the sum of the cubes of the digits of the number n.
>>> sum_of_cubes_of_digits(1)
1
>>> sum_of_cubes_of_digits(12)
9
>>> sum_of_cubes_of_digits(123)
36
>>> sum_of_cubes_of_digits(999)
2187
"""
def kth_number_in_sequence(start, k):
... | def sum_of_cubes_of_digits(n):
"""
Returns the sum of the cubes of the digits of the number n.
"""
return sum(int(digit)**3 for digit in str(n))
def kth_number_in_sequence(start, k):
"""
Returns the k-th number in the special sequence starting from 'start'.
"""
current = start
for _... | from solution import sum_of_cubes_of_digits, kth_number_in_sequence, process_multiple_cases
# Testing sum_of_cubes_of_digits
def test_sum_of_cubes_of_digits():
assert sum_of_cubes_of_digits(1) == 1
assert sum_of_cubes_of_digits(12) == 9
assert sum_of_cubes_of_digits(123) == 1**3 + 2**3 + 3**3 == 36
ass... | [
{
"docstring": "Returns the sum of the cubes of the digits of the number n.",
"function_declaration": "def sum_of_cubes_of_digits(n):",
"function_name": "sum_of_cubes_of_digits",
"parameter_list": "(n)"
},
{
"docstring": "Returns the k-th number in the special sequence starting from 'start'.... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def next_number(n):\n return sum(int(digit) ** 3 for digit in str(n))\n\ndef kth_number(n, k):\n current = n\n for _ in range(k - 1):\n current = n... | trial_gpt4o_1 | {
"original_instruction": "There is a special number sequence defined as follows:\n - The sequence starts with the first number as 1.\n - For any number `n(i)` in the sequence, the next number `n(i+1)` is generated by summing the cubes of the digits of `n(i)`.\n\nFor example, starting with 1:\n1. 1 --> 1^3 = 1 (Next ... | 0.696146 | Taco_1228 | C | [
"sum_of_cubes_of_digits",
"kth_number_in_sequence",
"process_multiple_cases"
] | 3 | [
[
"kth_number_in_sequence",
"sum_of_cubes_of_digits"
],
[
"process_multiple_cases",
"kth_number_in_sequence"
]
] | 2 | [
"process_multiple_cases"
] | false | [] | false | pytest | true | [] | true | 78435af58c5006fbecb983d843497ec47a82a530 | c5fc980a4d586c16bf4ab5f57f737dd99e16d517 | |||
v1.0 | complete | Taco | Taco_1290_C | from typing import List
def is_prime(n: int) -> bool:
"""Check if a number is prime.
>>> is_prime(2)
True
>>> is_prime(4)
False
>>> is_prime(17)
True
"""
pass
def filter_and_sort_primes(nums: List[int]) -> List[int]:
""" Given a list of integers, return a new list with only the... | def is_prime(n):
"""
Check if a number is prime.
"""
if n <= 1:
return False
elif n == 2:
return True
elif n % 2 == 0:
return False
max_divisor = int(n**0.5) + 1
for d in range(3, max_divisor, 2):
if n % d == 0:
return False
return True
de... | from solution import is_prime, filter_and_sort_primes
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
assert is_prime(0) == False
assert is_prime(1) == False
assert is_prime(-... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Given a list of integers, return a new list with only the prime numbers \nfrom the original list, sorted in ascending order and wi... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return ... | trial_gpt4o_2 | {
"original_instruction": "Given a list of integers, return a new list with only the prime numbers from the original list. The returned list should be sorted in ascending order. Consider that a prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. In case of duplicates... | 0.715725 | Taco_1290 | C | [
"is_prime",
"filter_and_sort_primes"
] | 2 | [
[
"filter_and_sort_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d6ac296c5b7ad8ca4e7ef88110ff5f87a6bc8938 | 61f4becc651e5b9cde12f24f5fb01025ecac6ef7 | |||
v1.0 | complete | Taco | Taco_1106_C | def find_largest_rectangle(grid):
"""
This function takes a grid of '0's and '1's and returns the size of the largest rectangle containing only '1's
and the number of such largest rectangles.
>>> find_largest_rectangle([
"10101",
"11100",
"11111",
"10010"
])
(6, ... | def find_largest_rectangle(grid):
"""
This function takes a grid of '0's and '1's and returns the size of the largest rectangle containing only '1's
and the number of such largest rectangles.
"""
n = len(grid)
m = len(grid[0]) if n > 0 else 0
if not n or not m:
return 0, 0
... | def test_find_largest_rectangle():
grid1 = [
"10101",
"11100",
"11111",
"10010"
]
assert find_largest_rectangle(grid1) == (6, 1)
grid2 = [
"101010",
"010101",
"101010",
"010101",
"101010",
"010101"
]
assert find_lar... | [
{
"docstring": "This function takes a grid of '0's and '1's and returns the size of the largest rectangle containing only '1's\nand the number of such largest rectangles.",
"function_declaration": "def find_largest_rectangle(grid):",
"function_name": "find_largest_rectangle",
"parameter_list": "(gri... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def largest_rectangle(T, test_cases):\n def maximal_rectangle(matrix):\n if not matrix:\n return 0, 0\n \n n = len(matrix)\n ... | trial_gpt4o_2 | {
"original_instruction": "You are given a grid consisting of $N$ rows and $M$ columns. Each cell in the grid contains either a '0' or a '1'. Your task is to find the size of the largest rectangle containing only '1's and return the number of such largest rectangles that can be found in the grid.\n\n------ Input ---... | 0.616404 | Taco_1106 | C | [
"find_largest_rectangle",
"process_test_cases",
"parse_input",
"solve"
] | 4 | [
[
"process_test_cases",
"find_largest_rectangle"
],
[
"solve",
"parse_input"
],
[
"solve",
"process_test_cases"
]
] | 3 | [
"process_test_cases",
"parse_input"
] | false | [] | false | pytest | false | [] | true | e623a48cca9c9795594c510bf7322a07d3e9db53 | 4030d5b34844f2443ef07d4cb9c9251235deb466 | |||
v1.0 | complete | Taco | Taco_1402_C | def maximum_tree_value(n: int, values: List[int], edges: List[Tuple[int, int, int]]) -> int:
""" Find the maximum sum of the vertex values in the resulting tree after adding the minimum number of edges to connect the forest.
Args:
n (int): The number of vertices in the forest.
values (List[int]): The v... | def find(parent, i):
if parent[i] == i:
return i
else:
return find(parent, parent[i])
def union(parent, rank, x, y):
xroot = find(parent, x)
yroot = find(parent, y)
if rank[xroot] < rank[yroot]:
parent[xroot] = yroot
elif rank[xroot] > rank[yroot]:
parent[yroot]... | from solution import maximum_tree_value
def test_case_1():
n = 4
values = [1, 2, 3, 4]
edges = [
(1, 2, 1),
(2, 3, 2),
(3, 4, 1)
]
assert maximum_tree_value(n, values, edges) == 10
def test_case_2():
n = 5
values = [5, 3, 6, 1, 4]
edges = [
(1, 2, 3),
... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n else:\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n xroot = fi... | trial_gpt4o_0 | {
"original_instruction": "In a forest, there are multiple trees represented as an undirected graph where each node is a vertex and each edge connects two vertices. Each vertex has an integer value associated with it, and each edge has an integer weight.\n\nThe forest is initially fragmented and can be connected into... | 0.663246 | Taco_1402 | C | [
"find",
"union",
"maximum_tree_value"
] | 3 | [
[
"maximum_tree_value",
"find"
],
[
"maximum_tree_value",
"union"
],
[
"union",
"find"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 3199884afed84d707e9d045f9fb7b6c8a3d86ebe | 9b5751f2766ea62d6ab94c50e01ef6ca80ddfc63 | |||
v1.0 | complete | Taco | Taco_1230_C | def can_word_be_formed(R: int, C: int, char_grid: List[List[str]], target_word: str) -> str:
"""
Check if the word can be formed in the grid by starting from any cell and moving
horizontally, vertically, or diagonally, in any of the eight possible directions.
Args:
R (int): Number of rows in ... | def is_word_in_grid(grid, word):
rows = len(grid)
cols = len(grid[0])
def dfs(x, y, word_index):
if word_index == len(word):
return True
if x < 0 or y < 0 or x >= rows or y >= cols or grid[x][y] != word[word_index]:
return False
temp = grid[x][y]
... | from solution import can_word_be_formed
def test_basic_example():
R = 3
C = 4
char_grid = [
['A', 'B', 'C', 'D'],
['E', 'F', 'G', 'H'],
['I', 'J', 'K', 'L']
]
word = "BEF"
assert can_word_be_formed(R, C, char_grid, word) == "YES"
word = "AGH"
assert can_word... | [
{
"docstring": null,
"function_declaration": "def is_word_in_grid(grid, word):",
"function_name": "is_word_in_grid",
"parameter_list": "(grid, word)"
},
{
"docstring": null,
"function_declaration": "def can_word_be_formed(R, C, char_grid, target_word):",
"function_name": "can_word_be... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_word_in_grid(grid, word):\n rows = len(grid)\n cols = len(grid[0])\n \n def dfs(x, y, word_index):\n if word_index == len(word):\n ... | trial_gpt4o_0 | {
"original_instruction": "You are given a rectangular grid of characters. Each cell in the grid contains a letter from the English alphabet ('A'-'Z'). You are also given a word. Your task is to write a program that checks if the word can be formed in the grid by starting from any cell and moving horizontally, vertic... | 0.690135 | Taco_1230 | C | [
"is_word_in_grid",
"can_word_be_formed"
] | 2 | [
[
"can_word_be_formed",
"is_word_in_grid"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5e4504eea436ddb3e5a90d8638af1cdbadd55bbf | f1021b9813060200f79eeab17817fe93cff395bd | |||
v1.0 | complete | Taco | Taco_1825_C | from typing import List, Tuple
def travel_agency_min_cost(n: int, m: int, s: int, t: int, roads: List[Tuple[int, int, int]]) -> int:
"""
Determine the minimum travel cost from a starting city to a destination city.
Parameters:
n (int): The number of cities.
m (int): The number of roads.
s (in... | import heapq
def minimum_travel_cost(n, m, s, t, roads):
graph = {i: [] for i in range(1, n + 1)}
for u, v, w in roads:
graph[u].append((v, w))
graph[v].append((u, w))
pq = [(0, s)]
distances = {i: float('inf') for i in range(1, n + 1)}
distances[s] = 0
visited = set()
... | from solution import travel_agency_min_cost
def test_minimum_travel_cost_example1():
n = 5
m = 6
s, t = 1, 5
roads = [
(1, 2, 2),
(1, 3, 5),
(2, 3, 1),
(2, 4, 2),
(3, 4, 3),
(4, 5, 1)
]
assert travel_agency_min_cost(n, m, s, t, roads) == 5
def te... | [
{
"docstring": null,
"function_declaration": "def minimum_travel_cost(n, m, s, t, roads):",
"function_name": "minimum_travel_cost",
"parameter_list": "(n, m, s, t, roads)"
},
{
"docstring": null,
"function_declaration": "def travel_agency_min_cost(n, m, s, t, roads):",
"function_name... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef minimum_travel_cost(n, m, s, t, roads):\n graph = {i: [] for i in range(1, n + 1)}\n for u, v, w in roads:\n graph[u].append((v, w... | trial_gpt4o_0 | {
"original_instruction": "A travel agency is offering a special tour package that includes visits to several cities. The agency has hired you to help them plan the itineraries. Each city is represented as a node in a graph, and the roads between the cities are the edges. Each road has a travel cost associated with i... | 0.70349 | Taco_1825 | C | [
"minimum_travel_cost",
"travel_agency_min_cost"
] | 2 | [
[
"travel_agency_min_cost",
"minimum_travel_cost"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b63dedd266d3fdcb56fa1ad2be4a48cb75e04dbf | fb0a11b89851bc40cd6d95b3e5c1816e3fffc5c1 | |||
v1.0 | complete | Taco | Taco_1750_C | def min_operations_to_sort(T, test_cases):
""" Determines the minimum number of operations to sort each test case by reversing subarrays.
Parameters:
T (int): Number of test cases.
test_cases (list of tuples): Each tuple contains (N, A), where N is the length of A and A is the list of integ... | def min_operations_to_sort(T, test_cases):
"""
Determines the minimum number of operations to sort each test case by reversing subarrays.
Parameters:
T (int): Number of test cases.
test_cases (list of tuples): Each tuple contains (N, A), where N is the length of A and A is the list of i... | def test_min_operations_to_sort():
test_cases = [
(4, [1, 3, 6, 7]),
(3, [10, 1, 4]),
(6, [3, 1, 3, 3, 4, 3]),
(4, [4, 3, 2, 1]), # requires 1 operation (entire reversal)
(5, [5, 4, 3, 2, 1]) # requires 1 operation (entire reversal)
]
expected = [0, 1, 1, 1, 1]
... | [
{
"docstring": "Determines the minimum number of operations to sort each test case by reversing subarrays.\n\nParameters:\n T (int): Number of test cases.\n test_cases (list of tuples): Each tuple contains (N, A), where N is the length of A and A is the list of integers.\n\nReturns:\n list of int: Mini... | [
0,
0,
0,
0,
0,
0,
0,
0,
1,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def min_operations_to_sort(arr):\n \"\"\"\n Returns the minimum number of operations to sort the array `arr` in non-descending order by reversing subarrays.\... | trial_gpt4o_8 | {
"original_instruction": "In a coding assessment, your task is to determine the minimum number of operations to remove all the \"bad\" pairs from a sequence. A pair (i, j) is considered \"bad\" if i < j and A[i] > A[j].\n\nYou are allowed the following operation any number of times (possibly 0):\n- Select any subarr... | 0.660315 | Taco_1750 | C | [
"min_operations_to_sort",
"handle_user_input"
] | 2 | [
[
"handle_user_input",
"min_operations_to_sort"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 9ea7d39464ed0e3866d55a504665076f90653feb | ecd200a4af988fa6f705937a4fba074d4fefe1f7 | |||
v1.0 | complete | Taco | Taco_1558_C | def nearest_palindrome(n: int) -> int:
""" Finds the smallest nearest palindrome number to the given number n.
>>> nearest_palindrome(123) == 121
>>> nearest_palindrome(888) == 888
>>> nearest_palindrome(100) == 99 # tie between 99 and 101, return 99
>>> nearest_palindrome(0) == 0
>>> nearest_p... | def is_palindrome(num):
"""
Helper function to check if a number is a palindrome.
"""
return str(num) == str(num)[::-1]
def nearest_palindrome(n: int) -> int:
"""
Finds the smallest nearest palindrome number to the given number n.
"""
if is_palindrome(n):
return n
lower, up... | from solution import nearest_palindrome
def test_nearest_palindrome_simple():
assert nearest_palindrome(123) == 121
assert nearest_palindrome(100) == 99
assert nearest_palindrome(787) == 787
assert nearest_palindrome(12345) == 12321
def test_nearest_palindrome_tie_cases():
assert nearest_palindrom... | [
{
"docstring": "Helper function to check if a number is a palindrome.",
"function_declaration": "def is_palindrome(num):",
"function_name": "is_palindrome",
"parameter_list": "(num)"
},
{
"docstring": "Finds the smallest nearest palindrome number to the given number n.",
"function_declar... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome(n: int) -> bool:\n return str(n) == str(n)[::-1]\n\ndef nearest_palindrome(n: int) -> int:\n if is_palindrome(n):\n return n\n \n... | trial_gpt4o_1 | {
"original_instruction": "**Objective:**\n\nImplement a function to find the nearest palindrome number to a given number `n`.\n\n**Description:**\n\nA palindrome number is a number that reads the same backwards as forwards. The task is to find the smallest nearest palindrome number to a given integer `n`. If there a... | 0.742076 | Taco_1558 | C | [
"is_palindrome",
"nearest_palindrome"
] | 2 | [
[
"nearest_palindrome",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ed872b1dfc9c713fc3aa98fb8cf14151224cee2d | 9e83ab8443a858ffe1d4b6a2af088a75253c887f | |||
v1.0 | complete | Taco | Taco_1035_C | import math
def scavenger_hunt(x: int, y: int):
""" Given the coordinates of the first clue, determine the locations of the remaining 9 clues according to:
1. The coordinates of each clue are distinct integer points within [-10, 10].
2. The Euclidean distance between any two clues is at least √2.
3. Th... | import math
def is_valid_coordinate(x, y, clues):
""" Check if the coordinate (x, y) is a valid clue location. """
if any(math.dist((x, y), (cx, cy)) < math.sqrt(2) for cx, cy in clues):
return False
return True
def are_squares_even(x, y, clues):
""" Check if the sum of the squares of coordina... | from solution import scavenger_hunt, generate_clues
def test_first_clue_2_3():
clues = generate_clues(2, 3)
assert len(clues) == 10
assert (2, 3) in clues
def test_first_clue_0_0():
clues = generate_clues(0, 0)
assert len(clues) == 10
assert (0, 0) in clues
def test_distance_check():
clue... | [
{
"docstring": "Check if the coordinate (x, y) is a valid clue location. ",
"function_declaration": "def is_valid_coordinate(x, y, clues):",
"function_name": "is_valid_coordinate",
"parameter_list": "(x, y, clues)"
},
{
"docstring": "Check if the sum of the squares of coordinates remains eve... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef is_valid_coordinate(x, y, clues):\n \"\"\" Check if the coordinate (x, y) is a valid clue location. \"\"\"\n if any(math.dist((x, y), (cx,... | trial_gpt4o_0 | {
"original_instruction": "Eleanor is organizing a scavenger hunt in her $20 \\times 20$ grid park. The park is overlaid with a Cartesian coordinate system so that any point $(x,y)$ in the park has coordinates $x \\in [-10, 10]$ and $y \\in [-10, 10]$. Eleanor wants to hide $10$ clues in unique locations according to... | 0.529179 | Taco_1035 | C | [
"is_valid_coordinate",
"are_squares_even",
"generate_clues",
"scavenger_hunt"
] | 4 | [
[
"generate_clues",
"are_squares_even"
],
[
"generate_clues",
"is_valid_coordinate"
],
[
"scavenger_hunt",
"generate_clues"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 90ed75e3846bb152f0c70ed1537c04ca28095ead | a32a0f4a82318ec4f50f7ae86aa0a1329dba3661 | |||
v1.0 | complete | Taco | Taco_2100_C | def can_partition_to_powers_of_two(n: int, arr: List[int]) -> str:
"""
Given a list of integers, determine if it is possible to partition the list
into contiguous subarrays such that the sum of each subarray is an integer power of 2.
Example:
>>> can_partition_to_powers_of_two(6, [2, 3, 1, 1, 4, 8... | def is_power_of_two(x):
"""
Checks if x is a power of 2.
"""
return (x & (x - 1)) == 0 and x != 0
def can_partition_to_powers_of_two(n, arr):
"""
Determines if it is possible to partition the array into contiguous subarrays
such that the sum of each subarray is a power of 2.
"""
i =... | from solution import can_partition_to_powers_of_two
def test_example1():
assert can_partition_to_powers_of_two(6, [2, 3, 1, 1, 4, 8]) == "Yes"
def test_example2():
assert can_partition_to_powers_of_two(4, [2, 4, 1, 3]) == "No"
def test_example3():
assert can_partition_to_powers_of_two(1, [16]) == "Yes"
... | [
{
"docstring": "Checks if x is a power of 2.",
"function_declaration": "def is_power_of_two(x):",
"function_name": "is_power_of_two",
"parameter_list": "(x)"
},
{
"docstring": "Determines if it is possible to partition the array into contiguous subarrays\nsuch that the sum of each subarray i... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_power_of_two(n):\n \"\"\"\n Returns True if n is an integer power of 2, otherwise False.\n \"\"\"\n return (n & (n - 1)) == 0 and n != 0\n\ndef ... | trial_gpt4o_1 | {
"original_instruction": "Given a list of integers, you need to partition the list into contiguous subarrays such that the sum of each subarray is an integer power of 2. You need to determine if it's possible to do so. \n\nFor example, the integer powers of 2 are 1 (2^0), 2 (2^1), 4 (2^2), 8 (2^3), etc.\n\nInput\n\n... | 0.630476 | Taco_2100 | C | [
"is_power_of_two",
"can_partition_to_powers_of_two"
] | 2 | [
[
"can_partition_to_powers_of_two",
"is_power_of_two"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 348625615ccf26dfc594d16639e9a23045ddb287 | d094d958f06f916cc2fce642d3d2d39e0b03d2a7 | |||
v1.0 | complete | Taco | Taco_1648_C | def isPythagoreanPrime(N: int) -> int:
""" Given a number N, check if it is a Pythagorean prime. A Pythagorean prime is a prime number that can be expressed in the form 4k + 1.
>>> isPythagoreanPrime(5)
1
>>> isPythagoreanPrime(7)
0
>>> isPythagoreanPrime(10)
0
"""
pass
def test_isP... | def is_prime(num):
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
return False
i += 6
return True
def isPythagoreanPrime(N):
... | def test_isPythagoreanPrime():
assert isPythagoreanPrime(5) == 1 # Pythagorean prime
assert isPythagoreanPrime(7) == 0 # Prime, but not Pythagorean prime
assert isPythagoreanPrime(10) == 0 # Not a prime
assert isPythagoreanPrime(13) == 1 # Pythagorean prime
assert isPythagoreanPrime(1) == 0 # N... | [
{
"docstring": null,
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def isPythagoreanPrime(N):",
"function_name": "isPythagoreanPrime",
"parameter_list": "(N)"
}
] | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 == 0 or num % 3 == 0:\n return False\n ... | trial_gpt4o_0 | {
"original_instruction": "Given a number N. Check if it is a Pythagorean prime. A Pythagorean prime is a prime number that can be expressed in the form 4k + 1. \nFor a given number N, return 1 if it is a Pythagorean prime, otherwise return 0.\n\nExample 1:\nInput: N = 5\nOutput: 1\nExplanation: 5 is a prime number a... | 0.755391 | Taco_1648 | C | [
"is_prime",
"isPythagoreanPrime"
] | 2 | [
[
"isPythagoreanPrime",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 4b9caacd07ac7fdaf813fe079be120ee6ed4c8a6 | a4ec18ab19a2ec4ca962767dfb26cffd0138ce25 | |||
v1.0 | complete | Taco | Taco_1879_C | MOD = 1000000007
def process_queries(n, values, queries):
""" Perform operations on an array using Fenwick Tree.
Given an initial array of size n and a list of queries, this function performs
update and range product queries on the array.
Args:
n: int - Number of elements in the initial array... | MOD = 1000000007
def update_fenwick_tree(fenwick_tree, index, value, mod):
while index < len(fenwick_tree):
fenwick_tree[index] = (fenwick_tree[index] * value) % mod
index += index & -index
def query_fenwick_tree(fenwick_tree, index, mod):
result = 1
while index > 0:
result = (resu... | def test_process_queries():
n = 5
values = [1, 2, 3, 4, 5]
queries = [
[2, 1, 3], # Product from index 1 to 3: 2*3*4 = 24
[1, 2, 10], # Update index 2 to 10: [1, 2, 10, 4, 5]
[2, 1, 3] # Product from index 1 to 3: 2*10*4 = 80
]
expected_output = [24, 80]
assert p... | [
{
"docstring": null,
"function_declaration": "def update_fenwick_tree(fenwick_tree, index, value, mod):",
"function_name": "update_fenwick_tree",
"parameter_list": "(fenwick_tree, index, value, mod)"
},
{
"docstring": null,
"function_declaration": "def query_fenwick_tree(fenwick_tree, in... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "MOD = 1000000007\n\nclass FenwickTree:\n def __init__(self, n):\n self.n = n\n self.tree = [1] * (n + 1)\n\n def _update(self, index, value):\n... | trial_gpt4o_2 | {
"original_instruction": "Sam is learning about different data structures and how to manipulate them. He recently came across the concept of Fenwick Trees (Binary Indexed Trees) and Segment Trees, which can be used to efficiently answer range queries and update values in arrays. Sam wants to apply this knowledge to ... | 0.611116 | Taco_1879 | C | [
"update_fenwick_tree",
"query_fenwick_tree",
"range_product",
"process_queries"
] | 4 | [
[
"process_queries",
"range_product"
],
[
"process_queries",
"update_fenwick_tree"
],
[
"range_product",
"query_fenwick_tree"
]
] | 3 | [
"process_queries"
] | false | [] | false | pytest | false | [] | true | 097d6b8898ac8bac102c9477c9a277be398e4b2d | dff800ca34abcae892e439d130c4c7a6cac7b32e | |||
v1.0 | complete | Taco | Taco_1888_C | def min_travel_time(N: int, t: List[List[int]]) -> int:
"""
Determines the shortest possible travel time from house 0 to house N-1.
:param N: Integer, the number of houses
:param t: List[List[int]], the time delay matrix
:return: Integer, minimum travel time from house 0 to house N-1
>... | import heapq
def dijkstra(N, t):
"""Function to calculate the minimum travel time using Dijkstra's algorithm."""
# Initialize a priority queue
pq = [(0, 0)] # (current_weight, node)
distances = {i: float('inf') for i in range(N)}
distances[0] = 0
visited = set()
while pq:
... | def test_sample_case():
t = [
[0, 3, -1, 7],
[8, 0, 2, -1],
[5, -1, 0, 1],
[2, -1, -1, 0]
]
assert min_travel_time(4, t) == 6
def test_case_no_route():
t = [
[0, 3, -1, -1],
[8, 0, 2, -1],
[5, -1, 0, -1],
[-1, -1, -1, 0]
]
assert m... | [
{
"docstring": "Function to calculate the minimum travel time using Dijkstra's algorithm.",
"function_declaration": "def dijkstra(N, t):",
"function_name": "dijkstra",
"parameter_list": "(N, t)"
},
{
"docstring": "Determines the shortest possible travel time from house 0 to house N-1.\n\n:pa... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef min_travel_time(N, t):\n \"\"\"\n Determine the shortest possible time to travel from house 0 to house N-1.\n Uses Dijkstra's algorith... | trial_gpt4o_2 | {
"original_instruction": "In a city, there are N houses, and there is exactly one unidirectional road from each house to another house. The houses are numbered from 0 to N-1. Alice can travel from house `i` to house `j` if there is a direct road from `i` to `j`. \n\nUnfortunately, some of the roads are riddled with ... | 0.715682 | Taco_1888 | C | [
"dijkstra",
"min_travel_time"
] | 2 | [
[
"min_travel_time",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | d949e398f3c6473bb4dee8f9d6286db5136695cd | 56510537de072659a7c2f75146053da5d88161e1 | |||
v1.0 | complete | Taco | Taco_1599_C | from typing import List, Tuple
def count_inversions(arr: List[int]) -> Tuple[List[int], int]:
""" Merge sort based function to count inversions.
>>> count_inversions([4,3,2,1])[1]
6
>>> count_inversions([1,2,3,4,5])[1]
0
"""
pass
def merge_and_count(left: List[int], right: List[int]) -> Tu... | def count_inversions(arr):
# Merge sort based function to count inversions
if len(arr) < 2:
return arr, 0
mid = len(arr) // 2
left, left_inv = count_inversions(arr[:mid])
right, right_inv = count_inversions(arr[mid:])
merged, split_inv = merge_and_count(left, right)
return merged, le... | def test_count_inversions():
assert count_inversions([4, 3, 2, 1])[1] == 6
assert count_inversions([1, 2, 3, 4, 5])[1] == 0
assert count_inversions([3, 1, 2])[1] == 2
def test_minimum_swaps_to_sort():
assert minimum_swaps_to_sort([4, 3, 2, 1]) == 6
assert minimum_swaps_to_sort([1, 2, 3, 4, 5]) == 0... | [
{
"docstring": null,
"function_declaration": "def count_inversions(arr):",
"function_name": "count_inversions",
"parameter_list": "(arr)"
},
{
"docstring": null,
"function_declaration": "def merge_and_count(left, right):",
"function_name": "merge_and_count",
"parameter_list": "(l... | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def minimum_adjacent_swaps(arr):\n \"\"\"\n Returns the minimum number of adjacent swaps required to sort the array.\n \"\"\"\n arr = [(val, idx) for i... | trial_gpt4o_4 | {
"original_instruction": "A group of students is playing a card game during their break. The deck of cards consists of N cards numbered from 1 to N. The cards are initially placed in random order. The goal is to sort the cards in ascending order. However, the students can only perform a specific type of operation: t... | 0.619221 | Taco_1599 | C | [
"count_inversions",
"merge_and_count",
"minimum_swaps_to_sort",
"process_test_cases",
"read_input",
"main"
] | 6 | [
[
"count_inversions",
"merge_and_count"
],
[
"minimum_swaps_to_sort",
"count_inversions"
],
[
"process_test_cases",
"minimum_swaps_to_sort"
]
] | 3 | [
"process_test_cases",
"read_input"
] | false | [] | false | pytest | false | [] | true | ee1ba5b986aa5c7694aa4125746f0c7504f877c1 | 0b8b991d9fa4328c035e6ecfef9d3bed9fc592d1 | |||
v1.0 | complete | Taco | Taco_1984_C | def treasure_hunt(n: int, m: int, grid: List[str], x: int, y: int) -> int:
""" Help a treasure hunter find the maximum number of treasure chests he can collect starting from a given position in the grid.
Args:
n (int): Number of rows in the grid.
m (int): Number of columns in the grid.
grid (Li... | def max_treasures(grid, start_x, start_y):
n = len(grid)
m = len(grid[0])
# Valid moves: up, down, left, right
moves = [(-1, 0), (1, 0), (0, -1), (0, 1)]
# Convert 1-indexed to 0-indexed
start_x -= 1
start_y -= 1
def is_valid(x, y):
return 0 <= x < n and 0 <= y < m... | def test_example1():
grid = [
".....",
".T.#.",
".....",
"##...",
"###T."
]
assert treasure_hunt(5, 5, grid, 3, 1) == 2
def test_example2():
grid = [
".T.",
".#.",
".T."
]
assert treasure_hunt(3, 3, grid, 1, 1) == 2
def test_examp... | [
{
"docstring": null,
"function_declaration": "def max_treasures(grid, start_x, start_y):",
"function_name": "max_treasures",
"parameter_list": "(grid, start_x, start_y)"
},
{
"docstring": null,
"function_declaration": "def treasure_hunt(n, m, grid, x, y):",
"function_name": "treasure... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_treasure(grid, start_pos):\n n, m = len(grid), len(grid[0])\n x, y = start_pos\n x, y = x - 1, y - 1 # Convert to 0-indexed\n\n # Directions f... | trial_gpt4o_1 | {
"original_instruction": "**Treasure Hunt in the Grid**\n\nYou are given an n x m grid consisting of empty cells (denoted by '.'), obstacles (denoted by '#'), and treasure chests (denoted by 'T'). Your task is to help a treasure hunter find the maximum number of treasure chests he can collect starting from a given s... | 0.644013 | Taco_1984 | C | [
"max_treasures",
"treasure_hunt"
] | 2 | [
[
"treasure_hunt",
"max_treasures"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 55373f5c4893921b2f3bcc59ea8197969a63749b | 2a311ec41f56c61931d744f9d4f445951a8ef498 | |||
v1.0 | complete | Taco | Taco_1744_C | from typing import List, Tuple
def is_walkable(trails: List[Tuple[int, int, int, int]]) -> bool:
""" Determine if the trails in the park are walkable.
>>> is_walkable([(0, 0, 1, 1), (1, 1, 2, 2), (2, 2, 3, 3)])
True
>>> is_walkable([(0, 0, 1, 1), (2, 2, 3, 3)])
False
"""
pass
def walk... | def is_walkable(trails):
from collections import defaultdict, deque
def find_common_point(trail1, trail2):
return (set(trail1[:2]) & set(trail2[:2])) or (set(trail1[2:]) & set(trail2[2:])) or \
(set(trail1[:2]) & set(trail2[2:])) or (set(trail1[2:]) & set(trail2[:2]))
graph = de... | from solution import walkable_park, parse_input
def test_case_1():
input_str = "2\n3\n0 0 1 1\n1 1 2 2\n2 2 3 3\n2\n0 0 1 1\n2 2 3 3\n"
test_cases = parse_input(input_str)
result = walkable_park(test_cases)
assert result == ["Case #1: YES", "Case #2: NO"]
def test_case_2():
input_str = "1\n4\n0 0 ... | [
{
"docstring": null,
"function_declaration": "def is_walkable(trails):",
"function_name": "is_walkable",
"parameter_list": "(trails)"
},
{
"docstring": null,
"function_declaration": "def walkable_park(test_cases):",
"function_name": "walkable_park",
"parameter_list": "(test_cases... | [
0,
0,
0,
1,
0
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find(parent, i):\n \"\"\"\n A function to find the parent of element i\n \"\"\"\n if parent[i] == i:\n return i\n else:\n parent[i... | trial_gpt4o_3 | {
"original_instruction": "You are tasked with designing a park consisting of N trails. Each trail is represented by a line segment in a 2D plane from coordinate (x1, y1) to (x2, y2). Your goal is to ensure the park is walkable, meaning it's possible to walk from any point on one trail to any point on another trail w... | 0.531554 | Taco_1744 | C | [
"is_walkable",
"walkable_park",
"parse_input"
] | 3 | [
[
"walkable_park",
"is_walkable"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 741be436357efcd5e470b069b09bd0026b43012f | bd3ed6dbb8a642431241d7f06dd44fe06b4cb6e1 | |||
v1.0 | complete | Taco | Taco_2275_C | def solve(T: int, test_cases: List[Tuple[int, List[Tuple[int, int]]]]) -> List[str]:
""" Compute the perimeter of the convex hull for given test cases.
>>> solve(2, [(4, [(0, 0), (0, 1), (1, 0), (1, 1)]), (3, [(2, 3), (4, 5), (6, 7)])])
["4.00", "11.31"]
>>> solve(1, [(4, [(1, 1), (1, 2), (2, 2), (2, 1)... | import math
from functools import cmp_to_key
def distance(p1, p2):
return math.sqrt((p2[0] - p1[0]) ** 2 + (p2[1] - p1[1]) ** 2)
def cross_product(o, a, b):
return (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0])
def convex_hull(points):
points = sorted(points)
lower = []
for p ... | from solution import solve
def test_example_cases():
T = 2
test_cases = [
(4, [(0, 0), (0, 1), (1, 0), (1, 1)]),
(3, [(2, 3), (4, 5), (6, 7)])
]
expected = ["4.00", "11.31"]
assert solve(T, test_cases) == expected
def test_single_test_case_square():
T = 1
test_cases = [(4,... | [
{
"docstring": null,
"function_declaration": "def distance(p1, p2):",
"function_name": "distance",
"parameter_list": "(p1, p2)"
},
{
"docstring": null,
"function_declaration": "def cross_product(o, a, b):",
"function_name": "cross_product",
"parameter_list": "(o, a, b)"
},
{
... | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef calculate_distance(p1, p2):\n \"\"\"\n Calculate the distance between two points p1 and p2.\n \"\"\"\n return math.sqrt((p2[0] - p1[... | trial_gpt4o_4 | {
"original_instruction": "Chef has recently taken an interest in computational geometry, particularly in the topic of convex hulls. Chef has a set of points (x, y) on a 2D plane and he wants to construct the convex hull out of these points. The convex hull is the smallest convex polygon that can enclose all of the g... | 0.500487 | Taco_2275 | C | [
"distance",
"cross_product",
"convex_hull",
"perimeter_of_convex_hull",
"format_output",
"solve",
"main"
] | 7 | [
[
"convex_hull",
"cross_product"
],
[
"perimeter_of_convex_hull",
"convex_hull"
],
[
"perimeter_of_convex_hull",
"distance"
],
[
"solve",
"format_output"
],
[
"solve",
"perimeter_of_convex_hull"
]
] | 5 | [
"format_output"
] | false | [] | false | pytest | true | [] | true | d567b626e65d8c5f78a4e3a0a00adfe71452964e | bb07ed9e13c62193d4ecdfe694da2d17dcbf9210 | |||
v1.0 | complete | Taco | Taco_1650_C | import math
from typing import List, Tuple
def euclidean_distance(ratings1: List[int], ratings2: List[int]) -> float:
"""
Computes the Euclidean distance between two rating vectors.
"""
pass
def find_closest_users(users_ratings: List[List[int]], target_user_id: int) -> List[int]:
"""
Finds the... | import math
def euclidean_distance(ratings1, ratings2):
"""
Computes the Euclidean distance between two rating vectors.
"""
distance = 0
for r1, r2 in zip(ratings1, ratings2):
distance += (r1 - r2) ** 2
return math.sqrt(distance)
def find_closest_users(users_ratings, target_user_id):
... | def test_recommend_all_three():
input_data = """5
1 1 2 3 -1
2 1 3 2 -1
3 5 4 3 -1
4 1 2 3 -1
5 5 5 5 -1
1"""
assert recommend_songs(input_data) == "2 3 4"
def test_recommend_two_users():
input_data = """3
10 5 5 5 -1
20 1 1 1 -1
30 3 3 3 -1
30"""
assert recommend_songs(input_data) == "10 20"
def test... | [
{
"docstring": "Computes the Euclidean distance between two rating vectors.",
"function_declaration": "def euclidean_distance(ratings1, ratings2):",
"function_name": "euclidean_distance",
"parameter_list": "(ratings1, ratings2)"
},
{
"docstring": "Finds the user IDs of the three most similar... | [
0,
0,
0,
1,
0
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef find_closest_users(data, target_user_id):\n # Parse the input data\n n = int(data[0])\n users = {}\n target_user_ratings = []\n\n ... | trial_gpt4o_3 | {
"original_instruction": "You are tasked with developing an online music store's service for recommending songs to users. The recommendation algorithm is based on a simple version of collaborative filtering. To start, you need to write a function that finds the users with the closest music tastes to a given user bas... | 0.613936 | Taco_1650 | C | [
"euclidean_distance",
"find_closest_users",
"recommend_songs"
] | 3 | [
[
"find_closest_users",
"euclidean_distance"
],
[
"recommend_songs",
"find_closest_users"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 6d589cddc93e7f19b7f1a22a1b282c25700fbcf6 | b5f66ad0dad5b59015e1f9948a3bcd40323f1cf5 | |||
v1.0 | complete | Taco | Taco_2319_C | def smallest_int_divisible(K: int) -> int:
""" Determine the smallest integer N such that when divided by each integer from 1 to K (inclusive),
the remainder is always a multiple of that integer. If no such N exists within the range of 1 to 10^9, return -1.
>>> smallest_int_divisible(3)
60
>>>... | import math
from functools import reduce
def lcm(x, y):
return x * y // math.gcd(x, y)
def smallest_int_divisible(K):
if K < 1 or K > 20:
return -1
smallest_multiple = reduce(lcm, range(1, K + 1))
# Check if the result is within the limit of 10^9
if smallest_multiple > 10**9:... | from solution import smallest_int_divisible
def test_smallest_int_divisible():
assert smallest_int_divisible(1) == 1
assert smallest_int_divisible(2) == 2
assert smallest_int_divisible(3) == 6
assert smallest_int_divisible(4) == 12
assert smallest_int_divisible(5) == 60
assert smallest_int_divi... | [
{
"docstring": null,
"function_declaration": "def lcm(x, y):",
"function_name": "lcm",
"parameter_list": "(x, y)"
},
{
"docstring": null,
"function_declaration": "def smallest_int_divisible(K):",
"function_name": "smallest_int_divisible",
"parameter_list": "(K)"
}
] | [
0,
0,
0,
0,
0,
0,
0,
1,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef smallest_integer(K):\n \"\"\"\n Determines the smallest integer N such that when divided by each integer from 1 to K \n (inclusive), th... | trial_gpt4o_7 | {
"original_instruction": "Determine the smallest integer N such that when divided by each integer from 1 to K (inclusive), the remainder is always a multiple of that integer. If no such N exists within the range of 1 to 10^9, print -1.\n\n### Constraints\n- 1 ≤ K ≤ 20\n- K is an integer.\n\n### Input\nInput is given... | 0.707301 | Taco_2319 | C | [
"lcm",
"smallest_int_divisible"
] | 2 | [
[
"smallest_int_divisible",
"lcm"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6754508c3c49a9cbb3550dbe56b3a0e83ecb1559 | ca0526a2ee9495129a6032fa9b0f1bc6a2bf3cbe | |||
v1.0 | complete | Taco | Taco_2170_C | def solve(adventure_data):
"""
Given the data of adventurers, keys, and gates, compute maximum number of gates that can be opened without exceeding
the total magical power limit.
adventure_data format:
- List of tuples containing the information about keys, their magical powers, and the gates.
... | def can_open_gate(gate, key_counts, key_powers, total_power):
used = [0] * len(key_counts)
power = 0
for key in gate:
if key_counts[key - 1] <= 0:
return False
if power + key_powers[key - 1] > total_power:
return False
power += key_powers[key - 1]
used... | from solution import solve
def test_example_case():
adventure_data = [
(3, 100),
(5, 20), (4, 15), (3, 10),
(2,),
(2, 1, 2), (1, 3),
(4, 90),
(3, 10), (2, 20), (1, 30), (1, 15),
(1,),
(3, 2, 3, 4),
]
assert solve(adventure_data) == [2, 1]
def... | [
{
"docstring": null,
"function_declaration": "def can_open_gate(gate, key_counts, key_powers, total_power):",
"function_name": "can_open_gate",
"parameter_list": "(gate, key_counts, key_powers, total_power)"
},
{
"docstring": null,
"function_declaration": "def max_gates_opened(keys, max_... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import sys\nfrom itertools import combinations\n\ndef max_gates(n, m, keys, gates):\n def gate_power(gate):\n return sum(keys[key-1][1] for key in gate)\... | trial_gpt4o_1 | {
"original_instruction": "**Problem**\n\nA group of adventurers are exploring a mystical forest and have encountered a series of enchanted gates, each guarded by a magical creature. Each gate will only open if the adventurers present a specific combination of magical keys. Each key has a certain level of magic power... | 0.531782 | Taco_2170 | C | [
"can_open_gate",
"max_gates_opened",
"solve"
] | 3 | [
[
"max_gates_opened",
"can_open_gate"
],
[
"solve",
"max_gates_opened"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 251e4f559a1b018ad0ad0e5a468679d45ff474d7 | 84f85cf303b0e5fc01b398204d46a5e6b34d4d63 | |||
v1.0 | complete | Taco | Taco_2372_C | def is_special(n: int) -> bool:
""" Determines if the digits of an integer can be arranged to form a palindrome.
>>> is_special(121) True
>>> is_special(131) True
>>> is_special(123) False
>>> is_special(787) True
>>> is_special(12) False
>>> is_special(222) True
>>> is_special(12321) Tr... | def is_special(n: int) -> bool:
"""
Determines if the digits of an integer can be arranged to form a palindrome.
"""
from collections import Counter
# Convert integer to string to get its digits
digits = str(n)
# Count occurrences of each digit
count = Counter(digits)
# A number... | def test_is_special():
assert is_special(121) == True
assert is_special(131) == True
assert is_special(123) == False
assert is_special(787) == True
assert is_special(12) == False
assert is_special(222) == True
assert is_special(12321) == True
assert is_special(445) == True
def test_coun... | [
{
"docstring": "Determines if the digits of an integer can be arranged to form a palindrome.",
"function_declaration": "def is_special(n):",
"function_name": "is_special",
"parameter_list": "(n)"
},
{
"docstring": "Counts how many integers in the list are special.",
"function_declaration... | [
0,
0,
0,
0,
0,
1,
0,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_special_integer(x):\n \"\"\"\n Returns True if the digits of integer x can be rearranged to form a palindrome. \n Otherwise, returns False.\n \"... | trial_gpt4o_5 | {
"original_instruction": "Anna has a list of integers and she wants to know how many special integers it contains. An integer is considered special if its digits can be arranged to form a palindrome. By definition, a palindrome is a number that reads the same backward as forward.\n\nWrite a program that takes an inp... | 0.722722 | Taco_2372 | C | [
"is_special",
"count_special_integers"
] | 2 | [
[
"count_special_integers",
"is_special"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | abd48f488c9a693daa377b519b1be5b9803db7b6 | da80713f205a0ba228deafeb7366000416b09922 | |||
v1.0 | complete | Taco | Taco_1954_C | def preprocess_grid(n: int, m: int, grid: List[List[int]]) -> List[List[int]]:
""" Preprocess the grid to create a prefix sum array.
>>> preprocess_grid(3, 3, [[1, 2, 3], [4, 5, 6], [7, 8, 9]])
[[0, 0, 0, 0], [0, 1, 3, 6], [0, 5, 12, 21], [0, 12, 27, 45]]
"""
pass
def query_sum(prefix_sum: List[Lis... | def preprocess_grid(n, m, grid):
# Create a prefix sum array
prefix_sum = [[0] * (m + 1) for _ in range(n + 1)]
for i in range(1, n + 1):
for j in range(1, m + 1):
prefix_sum[i][j] = grid[i-1][j-1] + prefix_sum[i-1][j] + prefix_sum[i][j-1] - prefix_sum[i-1][j-1]
return pref... | def test_preprocess_grid():
n, m = 3, 3
grid = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
prefix_sum = preprocess_grid(n, m, grid)
expected_prefix_sum = [
[0, 0, 0, 0],
[0, 1, 3, 6],
[0, 5, 12, 21],
[0, 12, 27, 45]
]
assert prefix_sum == expec... | [
{
"docstring": null,
"function_declaration": "def preprocess_grid(n, m, grid):",
"function_name": "preprocess_grid",
"parameter_list": "(n, m, grid)"
},
{
"docstring": null,
"function_declaration": "def query_sum(prefix_sum, r1, c1, r2, c2):",
"function_name": "query_sum",
"param... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def preprocess_grid(grid):\n n = len(grid)\n m = len(grid[0])\n prefix_sum = [[0 for _ in range(m + 1)] for _ in range(n + 1)]\n \n for i in range(1... | trial_gpt4o_2 | {
"original_instruction": "A large warehouse is organized in a systematic way where shelves are aligned in a grid formation. Each shelf can be identified with coordinates (i, j) where 'i' is the row number and 'j' is the column number starting from (1, 1) at the top-left corner. Each shelf has a certain number of ide... | 0.555371 | Taco_1954 | C | [
"preprocess_grid",
"query_sum",
"total_items_in_subgrid"
] | 3 | [
[
"total_items_in_subgrid",
"preprocess_grid"
],
[
"total_items_in_subgrid",
"query_sum"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 3def0aaa3e3bf535215a629127222e7e2c4f6f74 | f2a1209ad433513c3585844954f374c21146fccc | |||
v1.0 | complete | Taco | Taco_2115_C | def is_subsequence(s: str, sub: str) -> bool:
"""
Returns True if 'sub' is a subsequence of 's', otherwise False.
>>> is_subsequence('abcde', 'a') == True
>>> is_subsequence('abcde', 'bb') == False
>>> is_subsequence('abcde', 'acd') == True
>>> is_subsequence('abcde', 'ace') == True
>>> is_s... | def is_subsequence(s, sub):
"""
Returns True if 'sub' is a subsequence of 's', otherwise False.
"""
iter_s = iter(s)
return all(char in iter_s for char in sub)
def count_subsequences(s, l):
"""
Returns the number of strings in `l` that are subsequences of string `s`.
"""
return sum(... | from solution import is_subsequence, count_subsequences
def test_is_subsequence():
assert is_subsequence('abcde', 'a') == True
assert is_subsequence('abcde', 'bb') == False
assert is_subsequence('abcde', 'acd') == True
assert is_subsequence('abcde', 'ace') == True
assert is_subsequence('abcde', 'bd... | [
{
"docstring": "Returns True if 'sub' is a subsequence of 's', otherwise False.",
"function_declaration": "def is_subsequence(s, sub):",
"function_name": "is_subsequence",
"parameter_list": "(s, sub)"
},
{
"docstring": "Returns the number of strings in `l` that are subsequences of string `s`... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_subsequence(s, sub):\n \"\"\"\n Returns True if 'sub' is a subsequence of 's', otherwise False.\n \"\"\"\n iter_s = iter(s)\n return all(char... | trial_gpt4o_0 | {
"original_instruction": "A subsequence of characters in a string is a string derived by deleting some or no characters without changing the order of the remaining characters. For example, \"abc\", \"def\", and \"abcdef\" are subsequences of \"abcdef\", but \"bdca\" and \"aefc\" are not.\n\nGiven a string `s` and a ... | 0.726005 | Taco_2115 | C | [
"is_subsequence",
"count_subsequences",
"main"
] | 3 | [
[
"count_subsequences",
"is_subsequence"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6d73ca8bdda8dc13a60e0dc162a692ee8ebe2427 | 15e4a649b17e5fbafa12744dee4d7a553fc59045 | |||
v1.0 | complete | Taco | Taco_1874_C | def solve_prime_sum_problem(T, cases):
""" Given an integer N, determine if N can be expressed as the sum of two prime numbers (not necessarily distinct) or not.
>>> solve_prime_sum_problem(3, [4, 5, 8])
["YES", "YES", "YES"]
>>> solve_prime_sum_problem(1, [1])
["NO"]
>>> solve_pr... | def sieve_of_eratosthenes(limit):
"""
Generates a list of prime numbers up to a given limit using the Sieve of Eratosthenes algorithm.
"""
is_prime = [True] * (limit + 1)
is_prime[0] = is_prime[1] = False
for start in range(2, int(limit ** 0.5) + 1):
if is_prime[start]:
for m... | from solution import solve_prime_sum_problem
def test_example_cases():
T = 3
cases = [4, 5, 8]
assert solve_prime_sum_problem(T, cases) == ["YES", "YES", "YES"]
def test_single_prime_pair():
T = 1
cases = [4]
assert solve_prime_sum_problem(T, cases) == ["YES"]
def test_non_expressible_number(... | [
{
"docstring": "Generates a list of prime numbers up to a given limit using the Sieve of Eratosthenes algorithm.",
"function_declaration": "def sieve_of_eratosthenes(limit):",
"function_name": "sieve_of_eratosthenes",
"parameter_list": "(limit)"
},
{
"docstring": "Determines if a number can ... | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\" Check if the given number is a prime number. \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n return True\n... | trial_gpt4o_4 | {
"original_instruction": "Aly is an enthusiastic programmer who loves solving algorithms-based puzzles. Recently, he came across a number puzzle related to prime numbers. The puzzle is as follows:\n\nGiven an integer N, determine if N can be expressed as the sum of two prime numbers (not necessarily distinct) or not... | 0.636129 | Taco_1874 | C | [
"sieve_of_eratosthenes",
"can_be_expressed_as_sum_of_primes",
"solve_prime_sum_problem"
] | 3 | [
[
"solve_prime_sum_problem",
"can_be_expressed_as_sum_of_primes"
],
[
"solve_prime_sum_problem",
"sieve_of_eratosthenes"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 3972ec846dc5f0dbcc1e07a04f3e9db39b4eae53 | b071411227d7fdf08811b6ebe1a8f92218eeb35a | |||
v1.0 | complete | Taco | Taco_2053_C | def is_prime(num):
"""
Check if a number is prime.
>>> is_prime(1) == False
>>> is_prime(2) == True
>>> is_prime(3) == True
>>> is_prime(4) == False
>>> is_prime(5) == True
>>> is_prime(29) == True
>>> is_prime(99) == False
"""
# Implement the function
def smallest_prim... | def is_prime(num):
"""
Check if a number is prime.
"""
if num < 2:
return False
if num == 2:
return True
if num % 2 == 0:
return False
for i in range(3, int(num**0.5) + 1, 2):
if num % i == 0:
return False
return True
def smallest_prime_greate... | import pytest
from solution import is_prime, smallest_prime_greater_than_or_equal_to, process_test_cases
def test_is_prime():
assert not is_prime(1)
assert is_prime(2)
assert is_prime(3)
assert not is_prime(4)
assert is_prime(5)
assert is_prime(29)
assert not is_prime(99)
def test_smallest... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns the smallest prime number greater than or equal to the given number n.",
"function_declaration": "def smallest_pri... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if num < 2:\n return False\n if num == 2:\n return True\n if n... | trial_gpt4o_0 | {
"original_instruction": "The inhabitants of the fictional country AlgoLand love prime numbers. To celebrate their love for primes, they decided to organize a **Prime Number Game**. In this game, each player is given a positive integer n, and their task is to find the smallest prime number k, where k is greater than... | 0.776095 | Taco_2053 | C | [
"is_prime",
"smallest_prime_greater_than_or_equal_to",
"process_test_cases"
] | 3 | [
[
"process_test_cases",
"smallest_prime_greater_than_or_equal_to"
],
[
"smallest_prime_greater_than_or_equal_to",
"is_prime"
]
] | 2 | [
"process_test_cases"
] | false | [] | false | pytest | true | [] | true | ebfa9e89480297debaf6b259c83ba3681dfaa397 | 1b64bf252a28e20c90bacd1a410d89f67e7c74d5 | |||
v1.0 | complete | Taco | Taco_2346_C | def is_palindrome(x):
"""Check if a number is a palindrome"""
return str(x) == str(x)[::-1]
def next_palindrome(n):
"""Finds the smallest palindrome greater than or equal to n"""
while not is_palindrome(n):
n += 1
return n
def find_smallest_palindromes(test_cases):
"""Find the smallest... | def is_palindrome(x):
"""Check if a number is a palindrome"""
return str(x) == str(x)[::-1]
def next_palindrome(n):
"""Finds the smallest palindrome greater than or equal to n"""
while not is_palindrome(n):
n += 1
return n
def find_smallest_palindromes(test_cases):
"""Find the smallest... | from solution import is_palindrome, next_palindrome, find_smallest_palindromes
def test_is_palindrome():
assert is_palindrome(121) == True
assert is_palindrome(123) == False
assert is_palindrome(1) == True
assert is_palindrome(22) == True
assert is_palindrome(12321) == True
def test_next_palin... | [
{
"docstring": "Check if a number is a palindrome",
"function_declaration": "def is_palindrome(x):",
"function_name": "is_palindrome",
"parameter_list": "(x)"
},
{
"docstring": "Finds the smallest palindrome greater than or equal to n",
"function_declaration": "def next_palindrome(n):",
... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindromic(x):\n \"\"\"\n Function to check if a number is palindromic.\n \"\"\"\n return str(x) == str(x)[::-1]\n\ndef find_smallest_palindrom... | trial_gpt4o_2 | {
"original_instruction": "A number is said to be **palindromic** if it reads the same backward as forward. For example, 121 is palindromic while 123 is not.\n\nGiven an integer $n$, find the smallest integer $x \\ge n$ such that $x$ is palindromic.\n\n-----Input-----\n\nThe first line of input contains one integer $... | 0.685534 | Taco_2346 | C | [
"is_palindrome",
"next_palindrome",
"find_smallest_palindromes"
] | 3 | [
[
"find_smallest_palindromes",
"next_palindrome"
],
[
"next_palindrome",
"is_palindrome"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 4b255ab36ad49fa55d284c18a156947474f6bfea | 4b5787d2772e97b4a0563dc5df72c7e5f30b95f1 | |||
v1.0 | complete | Taco | Taco_2176_C | def compute_shortest_paths(inputs):
""" Compute the shortest travel time from the source intersection to the target intersection in a city represented as a directed graph.
The city graph is given in the form of input string with test cases. Each test case starts with two integers N and M where N is the num... | import heapq
import sys
def dijkstra(N, edges, S, T):
# Create adjacency list
graph = {i: [] for i in range(1, N+1)}
for U, V, W in edges:
graph[U].append((V, W))
# Distance array to track shortest paths
dist = {i: sys.maxsize for i in range(1, N+1)}
dist[S] = 0
# Priority queue t... | def test_dijkstra():
inputs = """2
4 4
1 2 4
1 3 2
2 3 5
3 4 1
1 4
5 7
1 2 3
1 3 2
1 4 7
2 3 1
2 5 6
3 4 2
4 5 1
1 5"""
expected_output = [3, 5]
assert compute_shortest_paths(inputs) == expected_output
def test_no_path():
inputs = """1
3 2
1 2 1
2 3 1
3 1"""
expected_output = ["NO PATH"]
assert... | [
{
"docstring": null,
"function_declaration": "def dijkstra(N, edges, S, T):",
"function_name": "dijkstra",
"parameter_list": "(N, edges, S, T)"
},
{
"docstring": null,
"function_declaration": "def get_shortest_paths(test_cases):",
"function_name": "get_shortest_paths",
"parameter... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef shortest_path(T, test_cases):\n results = []\n \n def dijkstra(n, graph, start, target):\n pq = [(0, start)]\n distances... | trial_gpt4o_2 | {
"original_instruction": "A construction company has developed a new traffic management system for a city that aims to minimize the total time taken for people to travel between various points in the city. The system needs a module to calculate the shortest possible path between any two points in the city, taking in... | 0.761492 | Taco_2176 | C | [
"dijkstra",
"get_shortest_paths",
"compute_shortest_paths"
] | 3 | [
[
"compute_shortest_paths",
"get_shortest_paths"
],
[
"get_shortest_paths",
"dijkstra"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 61d2d3d71255d7daf6ae4d9ebea263db0ff7f9ae | 37197f21fc77ace29c0bc0797249a8dcc6606dc7 | |||
v1.0 | complete | Taco | Taco_2623_C | def can_be_non_decreasing(t: int, test_cases: List[Tuple[int, List[int]]]) -> List[str]:
""" Determine if it is possible to make the sequence non-decreasing by performing exactly one operation (swap or replace).
>>> can_be_non_decreasing(3, [(4, [1, 5, 3, 2]), (3, [4, 2, 3]), (5, [5, 4, 3, 2, 1])])
["YES", ... | def can_be_non_decreasing(t, test_cases):
results = []
for n, arr in test_cases:
if is_non_decreasing(arr):
results.append("YES")
continue
possible = False
for i in range(n):
for j in range(i + 1, n):
# Try swapping i and j
... | from solution import can_be_non_decreasing
def test_single_case_yes():
assert can_be_non_decreasing(1, [(4, [1, 5, 3, 2])]) == ["YES"]
def test_single_case_no():
assert can_be_non_decreasing(1, [(5, [5, 4, 3, 2, 1])]) == ["NO"]
def test_multiple_cases():
test_cases = [
(4, [1, 5, 3, 2]),
... | [
{
"docstring": null,
"function_declaration": "def can_be_non_decreasing(t, test_cases):",
"function_name": "can_be_non_decreasing",
"parameter_list": "(t, test_cases)"
},
{
"docstring": null,
"function_declaration": "def is_non_decreasing(arr):",
"function_name": "is_non_decreasing",... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def can_be_non_decreasing_by_one_operation(t, test_cases):\n results = []\n for case in test_cases:\n n, seq = case\n if n == 2:\n r... | trial_gpt4o_2 | {
"original_instruction": "Anna has a sequence of $n$ integers $b_1, b_2, \\ldots, b_n$. She can perform exactly one of the following operations on the sequence:\n\n1. **Swap**: Choose two elements in the sequence and swap their positions.\n2. **Replace**: Choose one element in the sequence and replace it with any ot... | 0.68826 | Taco_2623 | C | [
"can_be_non_decreasing",
"is_non_decreasing"
] | 2 | [
[
"can_be_non_decreasing",
"is_non_decreasing"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5a04c63d791021483e59725c67dc8269eba5b011 | 423aee431e0c776001ac793ca69e97010654ccb7 | |||
v1.0 | complete | Taco | Taco_2172_C | from typing import List
def rotate_matrix_90_clockwise(matrix: List[List[int]]) -> List[List[int]]:
"""
Rotates a square matrix 90 degrees clockwise.
"""
pass
def rotate_matrix_k_times(matrix: List[List[int]], k: int) -> List[List[int]]:
"""
Rotates a square matrix k times clockwise.
"""
... | def rotate_matrix_90_clockwise(matrix):
"""
Rotates a square matrix 90 degrees clockwise.
"""
n = len(matrix)
rotated = [[0] * n for _ in range(n)]
for i in range(n):
for j in range(n):
rotated[j][n - i - 1] = matrix[i][j]
return rotated
def rotate_matrix_k_tim... | def test_rotate_1():
input_data = "1\n3\n1 2 3\n4 5 6\n7 8 9\n1"
expected_output = "7 4 1\n8 5 2\n9 6 3"
assert solve(input_data) == expected_output
def test_rotate_2():
input_data = "1\n3\n1 2 3\n4 5 6\n7 8 9\n2"
expected_output = "9 8 7\n6 5 4\n3 2 1"
assert solve(input_data) == expected_outp... | [
{
"docstring": "Rotates a square matrix 90 degrees clockwise.",
"function_declaration": "def rotate_matrix_90_clockwise(matrix):",
"function_name": "rotate_matrix_90_clockwise",
"parameter_list": "(matrix)"
},
{
"docstring": null,
"function_declaration": "def rotate_matrix_k_times(matrix... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def rotate_matrix_90_clockwise(matrix):\n \"\"\"\n Rotates a square matrix 90 degrees clockwise.\n \"\"\"\n n = len(matrix)\n rotated = [[0] * n for... | trial_gpt4o_0 | {
"original_instruction": "Teja is developing an interest in matrix manipulations. Utkarsh decides to challenge him with matrix rotations. Given a square matrix, he needs to rotate it 90 degrees clockwise a specific number of times.\n\nGiven an integer K, Teja needs to rotate the matrix K times in clockwise direction... | 0.571813 | Taco_2172 | C | [
"rotate_matrix_90_clockwise",
"rotate_matrix_k_times",
"process_input",
"format_output",
"solve"
] | 5 | [
[
"process_input",
"rotate_matrix_k_times"
],
[
"rotate_matrix_k_times",
"rotate_matrix_90_clockwise"
],
[
"solve",
"format_output"
],
[
"solve",
"process_input"
]
] | 4 | [
"process_input",
"format_output"
] | false | [] | false | pytest | false | [] | true | 317a93e2524caf9962126653314c692f02e6cadc | 8e7fbccdc4349ad6950bc0cbb057ab12056d3540 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.