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 | instruct | Apps | Apps_1082_I | Given a large NxN grid where N can be up to 10^5, each cell (i, j) containing a unique positive integer in the range 1 to N^2. You need to process q queries on this grid. Each query provides four integers x1, y1, x2, y2 which define a subgrid. For each query, you are to find the sum of the grid values in the subgrid de... | def create_prefix_sum(grid, n):
MOD = 10**9 + 7
prefix_sum = [[0] * (n + 1) for _ in range(n + 1)]
for i in range(1, n + 1):
for j in range(1, n + 1):
prefix_sum[i][j] = (grid[i - 1][j - 1] +
prefix_sum[i - 1][j] +
pref... | def test_create_prefix_sum():
grid = [
[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12],
[13, 14, 15, 16]
]
n = 4
expected = [
[0, 0, 0, 0, 0],
[0, 1, 3, 6, 10],
[0, 6, 14, 24, 36],
[0, 15, 33, 54, 78],
[0, 28, 60, 96, 136]
]
pre... | [
{
"docstring": null,
"function_declaration": "def create_prefix_sum(grid, n):",
"function_name": "create_prefix_sum",
"parameter_list": "(grid, n)"
},
{
"docstring": null,
"function_declaration": "def compute_subgrid_sum(prefix_sum, x1, y1, x2, y2):",
"function_name": "compute_subgri... | [
0,
0,
0,
0,
0,
0,
1,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "MOD = 10**9 + 7\n\ndef compute_prefix_sum(grid, N):\n \"\"\"\n Computes the prefix sum matrix for the given grid.\n \"\"\"\n prefix_sum = [[0] * (N + 1)... | trial_gpt4o_6 | {
"original_instruction": "",
"prompt_id": "00001082",
"row_id": 1082,
"seed_ids": "[2014]"
} | 0.711699 | Apps_1082 | I | [
"create_prefix_sum",
"compute_subgrid_sum",
"process_queries"
] | 3 | [
[
"process_queries",
"compute_subgrid_sum"
],
[
"process_queries",
"create_prefix_sum"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | false | [] | true | 12c4feaf089562c98e0adbe2d4922e6fcb4c0381 | 6f3d53948e0d3d86cfe9915fb93a3257016d67b7 | |||
v1.0 | instruct | Apps | Apps_1107_I | Create a function that takes a list of integers and returns a new list containing only the prime numbers from the original list. If the original list contains no prime numbers, the function should return an empty list. | def is_prime(n):
"""
Determines if a given number n is a prime.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return False
return True
def filter_primes(num... | from solution import filter_primes
def test_filter_primes_with_all_primes():
assert filter_primes([2, 3, 5, 7, 11]) == [2, 3, 5, 7, 11]
def test_filter_primes_with_no_primes():
assert filter_primes([4, 6, 8, 10, 12]) == []
def test_filter_primes_with_mixed_numbers():
assert filter_primes([4, 5, 6, 7, 8, ... | [
{
"docstring": "Determines if a given number n is a prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Takes a list of integers and returns a new list containing only the prime numbers from the original list.",
"fu... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Helper function to determine if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n retu... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00001107",
"row_id": 1107,
"seed_ids": "[3466]"
} | 0.64698 | Apps_1107 | I | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 1e483a2ba555ecff5b7a519efa084a9aaefa3f7f | 9169f2eb82ca8ccf89aa0f51ef16d3f7bca6c944 | |||
v1.0 | instruct | Apps | Apps_1110_I | Write a function that takes two integers, `start` and `end`, and returns a list of all prime numbers between `start` and `end` (inclusive). The function should ensure that both endpoints are included if they are prime. If no prime numbers exist in the range, return an empty list.
Prime numbers are natural numbers grea... | def is_prime(number):
"""
Helper function to check if a number is prime.
"""
if number <= 1:
return False
for i in range(2, int(number**0.5) + 1):
if number % i == 0:
return False
return True
def find_primes(start, end):
"""
Returns a list of all prime number... | from solution import find_primes
def test_primes_in_range():
assert find_primes(10, 30) == [11, 13, 17, 19, 23, 29]
def test_no_primes():
assert find_primes(14, 16) == []
assert find_primes(0, 1) == []
assert find_primes(4, 4) == []
def test_single_prime_range():
assert find_primes(2, 2) == [2]
... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(number):",
"function_name": "is_prime",
"parameter_list": "(number)"
},
{
"docstring": "Returns a list of all prime numbers between start and end (inclusive).",
"function_declaration": ... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return T... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00001110",
"row_id": 1110,
"seed_ids": "[2757]"
} | 0.644146 | Apps_1110 | I | [
"is_prime",
"find_primes"
] | 2 | [
[
"find_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 2c03b36b508cc56ceb14eaabeb4ea3a4ce5c1f1b | 4cf0521206b53d64cadb2e33c9c0602d4a6ea0c6 | |||
v1.0 | instruct | Apps | Apps_1113_I | Create a function that takes a list of integers and returns a new list containing only the prime numbers from the original list in the same order.
The input list will always contain at least one integer, and you do not need to account for different data types. | def is_prime(n):
"""
Helper function to check if a number is prime.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return False
return True
def filter_primes... | from solution import filter_primes
def test_filter_primes_all_primes():
assert filter_primes([2, 3, 5, 7, 11, 13]) == [2, 3, 5, 7, 11, 13]
def test_filter_primes_no_primes():
assert filter_primes([1, 4, 6, 8, 10, 12]) == []
def test_filter_primes_mixed():
assert filter_primes([1, 2, 4, 5, 6, 7, 8, 9, 10,... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a new list containing only the prime numbers from the original list.",
"function_declaration": "def... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Helper function to check if a given number n is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n ... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00001113",
"row_id": 1113,
"seed_ids": "[4553]"
} | 0.578 | Apps_1113 | I | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 083c8d67c2ca530ae47cc1235eedafa4ba0364c8 | ccd1a7dcc02a1c49a2cf569221158df95176d99e | |||
v1.0 | instruct | Apps | Apps_1151_I | A kingdom, driven by the need to strengthen its defenses, has decided to build a network of roads to connect all its cities. The king has tasked his engineers with constructing the network in a way that minimizes the total cost while ensuring that all cities are connected.
The engineers have a list of possible roads t... | def find(parent, i):
if parent[i] == i:
return i
return find(parent, parent[i])
def union(parent, rank, x, y):
xroot = find(parent, x)
yroot = find(parent, y)
if rank[xroot] < rank[yroot]:
parent[xroot] = yroot
elif rank[xroot] > rank[yroot]:
parent[yroot] = xroot
... | from solution import minimum_cost_to_connect_all_cities
def test_sample_input():
edges = [
(1, 2, 5),
(1, 3, 10),
(1, 4, 6),
(2, 3, 15),
(3, 4, 4)
]
assert minimum_cost_to_connect_all_cities(4, edges) == 15
def test_disconnected_graph():
edges = []
assert mi... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
1,
0,
1,
0,
0,
0,
0,
0,
0,
0
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n xroot = find(parent, x)\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00001151",
"row_id": 1151,
"seed_ids": "[1319]"
} | 0.794595 | Apps_1151 | I | [
"find",
"union",
"kruskal",
"minimum_cost_to_connect_all_cities"
] | 4 | [
[
"kruskal",
"find"
],
[
"kruskal",
"union"
],
[
"minimum_cost_to_connect_all_cities",
"kruskal"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | 44edea4dc084badf74ddf045f5d629e61c8c3e08 | 17e76b15d97477821459be7ef49e36ba16e5fce5 | |||
v1.0 | instruct | Apps | Apps_1266_I | You are given a series of segments represented as pairs of coordinates. Each segment is either vertical or horizontal. Your task is to determine the number of segments that overlap with any other segment.
A segment is defined by its two endpoints (x1, y1) and (x2, y2). It is either vertical if x1 == x2, or horizontal ... | def count_overlapping_segments(t, test_cases):
results = []
for n, segments in test_cases:
overlaps = 0
visited = [False] * n
for i in range(n):
for j in range(i+1, n):
if is_overlapping(segments[i], segments[j]):
if not visited[i]:
... | from solution import count_overlapping_segments
def test_single_test_case():
t = 1
test_cases = [
(3, [(1, 2, 1, 4), (1, 3, 1, 5), (2, 2, 2, 4)])
]
assert count_overlapping_segments(t, test_cases) == [2]
def test_multiple_test_case():
t = 2
test_cases = [
(3, [(1, 2, 1, 4), (1,... | [
{
"docstring": null,
"function_declaration": "def count_overlapping_segments(t, test_cases):",
"function_name": "count_overlapping_segments",
"parameter_list": "(t, test_cases)"
},
{
"docstring": null,
"function_declaration": "def is_overlapping(seg1, seg2):",
"function_name": "is_ov... | [
0,
0,
0,
0,
0,
1,
0,
0,
0,
1
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def count_overlapping_segments(T, test_cases):\n \"\"\"\n Function to count the number of overlapping segments in each test case.\n \n Args:\n T : in... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00001266",
"row_id": 1266,
"seed_ids": "[18]"
} | 0.665245 | Apps_1266 | I | [
"count_overlapping_segments",
"is_overlapping"
] | 2 | [
[
"count_overlapping_segments",
"is_overlapping"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 249af72092b7efab06932860a09e4062422b2630 | 12357c911fcec526e6daf3d2763770b90498a713 | |||
v1.0 | instruct | Apps | Apps_1308_I | Write function that takes a list of integers and returns a new list containing all the prime numbers from the original list, in the order they appeared. Use the helper function provided to determine if a number is prime.
### Helper Function
The helper function `is_prime` takes an integer and returns `True` if the numb... | def is_prime(n):
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return True
def filter_primes(lst):
"""
Takes a li... | def test_filter_primes():
assert filter_primes([2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == [2, 3, 5, 7, 11]
assert filter_primes([4, 6, 8, 9, 10]) == []
assert filter_primes([]) == []
assert filter_primes([-10, -5, 0, 1, 19, 23]) == [19, 23]
assert filter_primes([11, 18, 19, 21, 23, 29]) == [11, 19, 23, 29... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Takes a list of integers and returns a new list containing all the prime numbers \nfrom the original list, in the order they appeared.",
"function_decl... | [
1,
1,
1,
1,
0,
1,
1,
1,
1
] | 8 | easy | 0.889 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n return False\n i = 5\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00001308",
"row_id": 1308,
"seed_ids": "[1652]"
} | 0.753197 | Apps_1308 | I | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 3aeaca7069c80d45f8cef8ad25e2f97a445db1c9 | d4c311f1cf711aa36ac3de2be8d1a0da072cfcf6 | |||
v1.0 | instruct | Apps | Apps_1356_I | Farmer John has a rectangular farm with $M$ rows and $N$ columns, represented by a 2D grid. Each cell in the grid can either be empty (denoted by a 0) or have a tree (denoted by a 1).
Farmer John wants to maximize the area of a rectangular plot of land he can clear without moving any trees that are currently in place... | def maximalRectangle(grid):
if not grid:
return 0
M, N = len(grid), len(grid[0])
height = [0] * N
max_area = 0
for row in grid:
for i in range(N):
height[i] = height[i] + 1 if row[i] == 0 else 0
max_area = max(max_area, largestRectangleArea(height))
return... | import pytest
from solution import main
def test_example1():
input_string = "2\n4 4\n0 1 0 0\n0 0 0 1\n1 0 0 0\n1 1 1 0\n3 3\n1 1 1\n1 0 0\n1 0 0"
expected_output = "4\n4"
assert main(input_string) == expected_output
def test_single_row():
input_string = "1\n1 5\n0 0 1 0 0"
expected_output = "2"
... | [
{
"docstring": null,
"function_declaration": "def maximalRectangle(grid):",
"function_name": "maximalRectangle",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def largestRectangleArea(heights):",
"function_name": "largestRectangleArea",
"parameter_li... | [
0,
1,
1,
1,
1,
1,
1,
0,
1,
0
] | 7 | easy | 0.7 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def maximalRectangle(matrix):\n if not matrix:\n return 0\n\n max_area = 0\n row = len(matrix)\n col = len(matrix[0])\n \n heights = [0] * ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00001356",
"row_id": 1356,
"seed_ids": "[1428]"
} | 0.651073 | Apps_1356 | I | [
"maximalRectangle",
"largestRectangleArea",
"process_test_cases",
"parse_input",
"format_output",
"main"
] | 6 | [
[
"maximalRectangle",
"largestRectangleArea"
],
[
"process_test_cases",
"maximalRectangle"
]
] | 2 | [
"process_test_cases",
"parse_input",
"format_output"
] | false | [] | false | pytest | true | [] | true | 0bc0a00a345de233aacff8a5169c9ac6e5d72617 | 9a343f54be80532bd9d23a607ef747828e69d828 | |||
v1.0 | instruct | Apps | Apps_1409_I | **Step 1:** Create a function called `count_words()` that counts the frequency of each word in a given string and returns a dictionary where the keys are the words and the values are the counts. Assume that words are separated by spaces and are case-insensitive.
For example, `count_words("Hello world hello")` would re... | def count_words(s):
"""
Counts the frequency of each word in a given string, ignoring case.
Args:
s: str - The input string.
Returns:
dict - A dictionary where the keys are words and the values are their counts.
"""
words = s.lower().split()
word_count = {}
for word in ... | import pytest
from solution import count_words, most_common_word
def test_count_words_empty_string():
assert count_words("") == {}
def test_count_words_single_word():
assert count_words("hello") == {"hello": 1}
def test_count_words_multiple_words():
assert count_words("hello world hello") == {"hello": 2,... | [
{
"docstring": "Counts the frequency of each word in a given string, ignoring case.\n\nArgs:\ns: str - The input string.\n\nReturns:\ndict - A dictionary where the keys are words and the values are their counts.",
"function_declaration": "def count_words(s):",
"function_name": "count_words",
"parame... | [
1,
1,
1,
1,
1,
0,
1,
1,
1,
0
] | 8 | easy | 0.8 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def count_words(s):\n \"\"\"\n Counts the frequency of each word in a given string.\n\n Parameters:\n s (str): The input string.\n\n Returns:\n di... | trial_gpt4o_6 | {
"original_instruction": "",
"prompt_id": "00001409",
"row_id": 1409,
"seed_ids": "[2716]"
} | 0.804295 | Apps_1409 | I | [
"count_words",
"most_common_word"
] | 2 | [
[
"most_common_word",
"count_words"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d4cc50bbddddf592158ce92964b87edd2b2bcc04 | 2ac9995e014680fa74fc6351bbbfebee274773b8 | |||
v1.0 | instruct | Apps | Apps_1488_I | =====Problem Statement=====
You are given a list of integers. Your task is to compute and print the number of distinct integers in the list and then to output the squared value of each distinct integer, sorted in ascending order.
=====Constraints=====
1 ≤ n ≤ 10^4
-10^4 ≤ integer value ≤ 10^4
=====Input Format=====
T... | def distinct_squared_sorted(arr):
"""
This function takes a list of integers, computes the number of distinct integers,
and returns a sorted list of their squared values.
:param arr: List[int] - List of integers.
:return: (int, List[int]) - Number of distinct integers and list of squared value... | def test_distinct_squared_sorted_example_case():
arr = [1, -2, 3, -2, 4]
expected_count = 4
expected_squares = [1, 4, 9, 16]
assert distinct_squared_sorted(arr) == (expected_count, expected_squares)
def test_distinct_squared_sorted_single_element():
arr = [5]
expected_count = 1
expected_squ... | [
{
"docstring": "This function takes a list of integers, computes the number of distinct integers, \nand returns a sorted list of their squared values.\n\n:param arr: List[int] - List of integers.\n:return: (int, List[int]) - Number of distinct integers and list of squared values sorted.",
"function_declarat... | [
1,
0,
0,
0,
0,
0,
0,
1,
0,
0
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def distinct_squared_sorted(arr):\n \"\"\"\n This function takes a list of integers, computes the number of distinct integers, \n and returns a sorted list... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00001488",
"row_id": 1488,
"seed_ids": "[2594]"
} | 0.721646 | Apps_1488 | I | [
"distinct_squared_sorted",
"format_output",
"process_integers"
] | 3 | [
[
"process_integers",
"distinct_squared_sorted"
],
[
"process_integers",
"format_output"
]
] | 2 | [
"format_output"
] | false | [] | false | pytest | false | [] | true | c6e02b2c045ef0a27f0b7a874e9dd2f74d85e9ad | b09d109cd1fda2ec556c2d522fa67a3b9cf669ae | |||
v1.0 | instruct | Apps | Apps_1496_I | Write a function that accepts a list of integers and returns a new list containing only the prime numbers from the original list, in the same order that they appeared.
To determine if a number is prime, a prime number (other than 1) has exactly two distinct positive divisors: 1 and itself.
Visualization:
```
input: ... | def is_prime(num):
"""
Returns True if num is a prime number, otherwise False.
"""
if num < 2:
return False
for i in range(2, int(num**0.5) + 1):
if num % i == 0:
return False
return True
def filter_primes(numbers):
"""
Returns a list containing only the prim... | from solution import is_prime, filter_primes
def test_is_prime():
assert is_prime(1) == False
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(17) == True
assert is_prime(18) == False
def test_filter_primes_empty_list():
assert filter_primes... | [
{
"docstring": "Returns True if num is a prime number, otherwise False.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns a list containing only the prime numbers from the provided list.",
"function_declarati... | [
1,
1,
1,
0,
1,
1,
1,
1,
1,
1
] | 9 | easy | 0.9 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Helper function to determine if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n retu... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00001496",
"row_id": 1496,
"seed_ids": "[3396]"
} | 0.681683 | Apps_1496 | I | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 17682779d7cd76fe4aefcbc31742db00d21fc2cf | 71fed6d8953b0a71fb45f6bd0ca21a940c490574 | |||
v1.0 | instruct | Apps | Apps_1543_I | Given a sorting machine that can only handle sorting arrays of integers where the size of the array is a power of 2, write a function that:
1. Takes an unsorted array with a length that is a power of 2.
2. Efficiently sorts the array in ascending order by implementing an iterative merge sort.
Iterative merge sort (or ... | from typing import List
def merge(arr, left, mid, right):
n1 = mid - left + 1
n2 = right - mid
# Create temporary arrays
L = arr[left:left + n1]
R = arr[mid + 1:mid + 1 + n2]
i, j, k = 0, 0, left
while i < n1 and j < n2:
if L[i] <= R[j]:
arr[k] = L[i]
i += ... | from solution import iterative_merge_sort
def test_sorted_array():
arr = [1, 2, 3, 4, 5, 6, 7, 8]
sorted_arr = iterative_merge_sort(arr)
assert sorted_arr == [1, 2, 3, 4, 5, 6, 7, 8]
def test_reverse_sorted_array():
arr = [8, 7, 6, 5, 4, 3, 2, 1]
sorted_arr = iterative_merge_sort(arr)
assert s... | [
{
"docstring": null,
"function_declaration": "def merge(arr, left, mid, right):",
"function_name": "merge",
"parameter_list": "(arr, left, mid, right)"
},
{
"docstring": null,
"function_declaration": "def iterative_merge_sort(arr):",
"function_name": "iterative_merge_sort",
"para... | [
1,
1,
1,
1,
1,
1,
1,
1,
0,
1
] | 9 | easy | 0.9 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from typing import List\n\ndef merge(left: List[int], right: List[int]) -> List[int]:\n \"\"\"\n Merge two sorted arrays into one sorted array.\n \"\"\"\n ... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00001543",
"row_id": 1543,
"seed_ids": "[3580]"
} | 0.629675 | Apps_1543 | I | [
"merge",
"iterative_merge_sort"
] | 2 | [
[
"iterative_merge_sort",
"merge"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5e0f12a8045b16f91a93e08963ef2d8118a6542d | c722bcc89bf07331b588ea174fcbb72e84d6b351 | |||
v1.0 | instruct | Apps | Apps_1567_I | Samuel is fascinated by palindromic numbers. A palindromic number is a number that remains the same when its digits are reversed. Samuel is interested in counting how many subarrays of an array are palindromic when treated as concatenated numbers.
Write a program to help Samuel find the number of palindromic subarrays... | def is_palindrome(s):
"""
Check if a given string s is a palindrome.
"""
return s == s[::-1]
def count_palindromic_subarrays(arr):
"""
Count the number of palindromic subarrays in the given array of integers.
"""
n = len(arr)
count = 0
for i in range(n):
for j in ra... | from solution import is_palindrome, count_palindromic_subarrays, solve
def test_is_palindrome():
assert is_palindrome("121") == True
assert is_palindrome("123") == False
assert is_palindrome("1") == True
assert is_palindrome("1221") == True
assert is_palindrome("12321") == True
def test_count_pali... | [
{
"docstring": "Check if a given string s is a palindrome.",
"function_declaration": "def is_palindrome(s):",
"function_name": "is_palindrome",
"parameter_list": "(s)"
},
{
"docstring": "Count the number of palindromic subarrays in the given array of integers.",
"function_declaration": "... | [
1,
0,
0,
1,
1,
1,
1,
1,
1,
0
] | 7 | easy | 0.7 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindromic(number):\n \"\"\"\n Helper function to determine if a given number (as a string) is palindromic.\n \"\"\"\n return number == number[:... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00001567",
"row_id": 1567,
"seed_ids": "[1224]"
} | 0.714993 | Apps_1567 | I | [
"is_palindrome",
"count_palindromic_subarrays",
"solve"
] | 3 | [
[
"count_palindromic_subarrays",
"is_palindrome"
],
[
"solve",
"count_palindromic_subarrays"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 4ae61efdfded685850096338c4f66213a252c448 | 1254c6cd535b5a264e8d314d08bd39ccd80ae765 | |||
v1.0 | instruct | Apps | Apps_1613_I | In a town, there are numerous paths that connect various landmarks, and each path has a length associated with it. Your task is to find the shortest path that connects a set of given landmarks, visiting each landmark exactly once and returning to the starting point. This is known as the Travelling Salesman Problem (TSP... | import itertools
def calculate_path_length(graph, path):
total_length = 0
for i in range(len(path) - 1):
segment = (path[i], path[i + 1])
if segment in graph:
total_length += graph[segment]
else:
total_length += graph[(path[i + 1], path[i])] # assuming the graph... | from solution import find_shortest_path
def test_find_shortest_path():
graph = {
('A', 'B'): 10,
('A', 'C'): 15,
('B', 'C'): 35,
('B', 'D'): 25,
('C', 'D'): 30,
('D', 'A'): 20 # Adding D -> A for completeness
}
landmarks = ['A', 'B', 'C', 'D']
resul... | [
{
"docstring": null,
"function_declaration": "def calculate_path_length(graph, path):",
"function_name": "calculate_path_length",
"parameter_list": "(graph, path)"
},
{
"docstring": null,
"function_declaration": "def find_shortest_path(graph, landmarks):",
"function_name": "find_shor... | [
1,
0,
0,
1,
0,
0,
0,
1,
0,
0
] | 3 | hard | 0.3 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import itertools\n\ndef calculate_path_length(graph, path):\n length = 0\n for i in range(len(path) - 1):\n length += graph.get((path[i], path[i + 1]),... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00001613",
"row_id": 1613,
"seed_ids": "[4401]"
} | 0.638819 | Apps_1613 | I | [
"calculate_path_length",
"find_shortest_path"
] | 2 | [
[
"find_shortest_path",
"calculate_path_length"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d6b97c91269ce2f164516e8e524571751f1ecaf1 | 785a7db0d637d1e9dcab4d8e5e599ff1b775115d | |||
v1.0 | instruct | Apps | Apps_1669_I | ## Task
Given a **list of integers**, write a function to return a new list consisting of all prime numbers from the original list. The order of the prime numbers in the returned list should be the same as their order in the input list.
# Notes:
* A prime number is a positive integer greater than 1 that has no posit... | def is_prime(num):
"""
Determine if a number num is a prime number.
"""
if num <= 1:
return False
if num == 2:
return True
if num % 2 == 0:
return False
for i in range(3, int(num**0.5) + 1, 2):
if num % i == 0:
return False
return True
def fil... | from solution import filter_primes
def test_filter_primes_general_case():
assert filter_primes([1, 3, 4, 7, 10]) == [3, 7]
def test_filter_primes_including_negative_and_zero():
assert filter_primes([-1, -3, 0, 2, 4]) == [2]
def test_filter_primes_all_primes():
assert filter_primes([2, 3, 5, 7, 11]) == [2... | [
{
"docstring": "Determine if a number num is a prime number.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Given a list of integers, return a new list consisting of all prime numbers from the original list.",
"fu... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n 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": "",
"prompt_id": "00001669",
"row_id": 1669,
"seed_ids": "[3026]"
} | 0.668521 | Apps_1669 | I | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | bb895cdf3c65748226f59c41ff9de13168391cb5 | e2fed42015026a36b688529284b72c6ba6b9fb87 | |||
v1.0 | instruct | Apps | Apps_1672_I | You are given a grid with $N$ rows and $M$ columns. Each cell of the grid contains an integer. You are allowed to perform a certain operation any number of times: select a sub-grid, in which all values on the border are greater than or equal to the values inside the sub-grid, then increase all values inside this sub-gr... | def can_make_all_cells_equal(grid):
N = len(grid)
M = len(grid[0])
target = grid[0][0]
for row in grid:
for value in row:
if value != target:
return "NO"
return "YES"
def solve(test_cases):
results = []
for grid in test_cases:
... | def test_valid_all_equal():
input_data = "1\n2 2\n1 1\n1 1"
expected_output = "YES"
assert main(input_data) == expected_output
def test_valid_single_row():
input_data = "1\n1 3\n1 1 1"
expected_output = "YES"
assert main(input_data) == expected_output
def test_valid_single_column():
in... | [
{
"docstring": null,
"function_declaration": "def can_make_all_cells_equal(grid):",
"function_name": "can_make_all_cells_equal",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def solve(test_cases):",
"function_name": "solve",
"parameter_list": "(test... | [
0,
0,
0,
1,
0,
0,
0,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def can_make_all_cells_equal(grid):\n max_value = max(max(row) for row in grid)\n for row in grid:\n for cell in row:\n if cell < max_value:... | trial_gpt4o_3 | {
"original_instruction": "",
"prompt_id": "00001672",
"row_id": 1672,
"seed_ids": "[1022]"
} | 0.798809 | Apps_1672 | I | [
"can_make_all_cells_equal",
"solve",
"read_input",
"main"
] | 4 | [
[
"solve",
"can_make_all_cells_equal"
]
] | 1 | [
"read_input"
] | false | [] | false | pytest | false | [] | true | 82168b0d1af897a6ba693e5532d7c4e716ab888b | f574a95b281203f84534563b97f6d2325cec91aa | |||
v1.0 | instruct | Apps | Apps_1676_I | ## Data Cleanup and Reconciler
You are given a list of product records from two different databases. Each record contains a product ID and a product name, and you need to reconcile discrepancies between these databases. Sometimes, two records from the two databases may represent the same product but are listed with sl... | from typing import List, Tuple
import numpy as np
def levenshtein_distance(a: str, b: str) -> int:
if a == b:
return 0
if len(a) < len(b):
a, b = b, a
previous_row = range(len(b) + 1)
for i, ca in enumerate(a):
current_row = [i + 1]
for j, cb in enumerate(b):
... | from solution import reconcile_products
def test_reconcile_products_exact_match():
db1 = [(1, "apple"), (2, "banana"), (3, "orange")]
db2 = [(4, "apple"), (5, "banana"), (6, "orange")]
assert reconcile_products(db1, db2) == [1, 2, 3]
def test_reconcile_products_typo_match():
db1 = [(1, "apple"), (2, "... | [
{
"docstring": null,
"function_declaration": "def levenshtein_distance(a, b):",
"function_name": "levenshtein_distance",
"parameter_list": "(a, b)"
},
{
"docstring": null,
"function_declaration": "def reconcile_products(db1, db2):",
"function_name": "reconcile_products",
"paramet... | [
0,
0,
0,
0,
0,
1,
0,
0,
0,
1
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from typing import List, Tuple\nimport itertools\n\ndef levenshtein_distance(s1: str, s2: str) -> int:\n if len(s1) < len(s2):\n return levenshtein_distan... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00001676",
"row_id": 1676,
"seed_ids": "[2758]"
} | 0.560762 | Apps_1676 | I | [
"levenshtein_distance",
"reconcile_products"
] | 2 | [
[
"reconcile_products",
"levenshtein_distance"
]
] | 1 | [] | false | [] | false | pytest | true | [
"numpy"
] | false | 93a8aabe1fce2aadad7f528ad0c32b81ff480287 | f367a4d4d42f86ee16f2b520dc66489a65adcda6 | |||
v1.0 | instruct | Apps | Apps_1712_I | Write a function that takes a list of integers and returns a sublist containing only the prime numbers from the original list.
A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. For instance, 2, 3, and 5 are prime numbers, while 4 and 6 are not.
**Requirements:**... | def is_prime(n):
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return True
def get_prime_numbers(lst):
"""
Return... | from solution import get_prime_numbers
def test_get_prime_numbers_empty_list():
assert get_prime_numbers([]) == []
def test_get_prime_numbers_no_primes():
assert get_prime_numbers([4, 6, 8, 9, 10, 12]) == []
def test_get_prime_numbers_all_primes():
assert get_prime_numbers([2, 3, 5, 7, 11]) == [2, 3, 5, ... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a sublist containing only the prime numbers from the original list.",
"function_declaration": "def get_prime_numbers(lst):",
"function_name... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef is_prime(n):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n ... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00001712",
"row_id": 1712,
"seed_ids": "[3680]"
} | 0.668022 | Apps_1712 | I | [
"is_prime",
"get_prime_numbers"
] | 2 | [
[
"get_prime_numbers",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | fde39ec59e370263ab9c13a9d6af6d1e84bae248 | c766838724c885bf3fe6e092d69e149c19363381 | |||
v1.0 | instruct | Apps | Apps_1729_I | Write a function that takes an integer as input and returns the next prime palindrome greater than the given integer. A prime palindrome is a number that is both a prime number and a palindrome. For example, the next prime palindrome after 31 is 101. If the input number itself is a prime palindrome, return the next one... | def is_prime(n):
if n < 2:
return False
if n in (2, 3):
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return True
def is_palindrome(n):
return str(n) ==... | from solution import next_prime_palindrome
def test_next_prime_palindrome():
assert next_prime_palindrome(31) == 101
assert next_prime_palindrome(101) == 131
assert next_prime_palindrome(131) == 151
assert next_prime_palindrome(151) == 181
assert next_prime_palindrome(181) == 191
def test_next_pri... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def is_palindrome(n):",
"function_name": "is_palindrome",
"parameter_list": "(n)"
},
{
"docstring": null,... | [
1,
0,
1,
1,
0,
1,
1,
0,
0,
0
] | 5 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"Returns True if n is a prime number, otherwise False.\"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n... | trial_gpt4o_5 | {
"original_instruction": "",
"prompt_id": "00001729",
"row_id": 1729,
"seed_ids": "[3321]"
} | 0.730981 | Apps_1729 | I | [
"is_prime",
"is_palindrome",
"next_prime_palindrome"
] | 3 | [
[
"next_prime_palindrome",
"is_palindrome"
],
[
"next_prime_palindrome",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | f324517dd32e085033ca0de8ab0aa70d20babf8e | 1a66bb660f5a84a82d98dbfba0f7185036149719 | |||
v1.0 | instruct | Apps | Apps_1794_I | ## Palindrome Chains
Given a number, determine the number of steps required to transform it into a palindrome. At each step, add the number to its reverse. If the resulting number is a palindrome, stop. Otherwise, repeat the process with the new number.
# Task
Create a function that takes an integer `n` and returns t... | def is_palindrome(n):
"""
Check if a number is a palindrome.
"""
return str(n) == str(n)[::-1]
def steps_to_palindrome(n):
"""
Returns the number of steps required to transform the number into a palindrome.
Returns -1 if it does not become a palindrome within 1000 steps.
"""
steps =... | from solution import steps_to_palindrome
def test_palindrome_cases():
assert steps_to_palindrome(87) == 4
assert steps_to_palindrome(56) == 1
assert steps_to_palindrome(11) == 0
def test_no_palindrome_within_1000_steps():
assert steps_to_palindrome(89) == 24 # Known to reach palindrome in 24 steps
... | [
{
"docstring": "Check if a number is a palindrome.",
"function_declaration": "def is_palindrome(n):",
"function_name": "is_palindrome",
"parameter_list": "(n)"
},
{
"docstring": "Returns the number of steps required to transform the number into a palindrome.\nReturns -1 if it does not become... | [
0,
0,
0,
0,
0,
0,
0,
0,
1,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome(n):\n \"\"\"\n Check if a number is palindrome.\n \"\"\"\n return str(n) == str(n)[::-1]\n\ndef steps_to_palindrome(n, max_steps=1000)... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00001794",
"row_id": 1794,
"seed_ids": "[4816]"
} | 0.690929 | Apps_1794 | I | [
"is_palindrome",
"steps_to_palindrome"
] | 2 | [
[
"steps_to_palindrome",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 97cb8b9c6de56ae54a3a74142f4dbe406ce59d69 | 46cd8f45e951905fd0ef8aa4fbaab4c8a68decec | |||
v1.0 | instruct | Apps | Apps_1799_I | The task is to implement a function that helps in formatting list output as a string, where numbers that are perfect squares and perfect cubes are replaced by special strings. Given an integer array `nums`, return a formatted string where:
1. Numbers in the array that are perfect squares (like 1, 4, 9, 16,...) should ... | import math
def is_perfect_square(n):
return int(math.sqrt(n)) ** 2 == n
def is_perfect_cube(n):
return int(round(n ** (1/3))) ** 3 == n
def format_numbers(nums):
results = []
for num in nums:
if is_perfect_square(num) and is_perfect_cube(num):
results.append("Square-Cube")
... | from solution import format_numbers
def test_single_element():
assert format_numbers([1]) == "Square-Cube"
assert format_numbers([4]) == "Square"
assert format_numbers([8]) == "Cube"
assert format_numbers([5]) == "5"
def test_multiple_elements():
assert format_numbers([1, 3, 4, 8, 9, 16, 27, 64, 8... | [
{
"docstring": null,
"function_declaration": "def is_perfect_square(n):",
"function_name": "is_perfect_square",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def is_perfect_cube(n):",
"function_name": "is_perfect_cube",
"parameter_list": "(n)"
},
{
... | [
0,
0,
1,
1,
0,
0,
1,
0,
0,
1
] | 4 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef format_numbers(nums):\n \"\"\"\n Format numbers replacing perfect squares with 'Square', perfect cubes\n with 'Cube', and numbers that a... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00001799",
"row_id": 1799,
"seed_ids": "[2721]"
} | 0.498047 | Apps_1799 | I | [
"is_perfect_square",
"is_perfect_cube",
"format_numbers"
] | 3 | [
[
"format_numbers",
"is_perfect_cube"
],
[
"format_numbers",
"is_perfect_square"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 5a9badddeea7dca949eb6f9a18f47d78e07d2eb2 | baeb6f6059d23b6bced2288a49edb38eccd6ef0a | |||
v1.0 | instruct | Apps | Apps_1838_I | Write a function that takes a string which represents a sentence and returns a new string with each word reversed but the word order intact. The function should maintain any capital letters in their respective positions after reversing each word.
## Examples
```python
reverse_words("Hello World") # returns "olleH dl... | def reverse_word(word):
"""
This helper function takes a single word and returns the word reversed.
It maintains the initial capitalization position for each character after reversing the word.
"""
n = len(word)
new_word = [''] * n
for i, ch in enumerate(word):
if ch.isupper():
... | from solution import reverse_words
def test_reverse_words_single_word():
assert reverse_words("Hello") == "olleH"
assert reverse_words("WORLD") == "DLROW"
assert reverse_words("pYtHoN") == "NoHtYp"
def test_reverse_words_multiple_words():
assert reverse_words("Hello World") == "olleH dlroW"
assert... | [
{
"docstring": "This helper function takes a single word and returns the word reversed.\nIt maintains the initial capitalization position for each character after reversing the word.",
"function_declaration": "def reverse_word(word):",
"function_name": "reverse_word",
"parameter_list": "(word)"
},... | [
0,
0,
0,
0,
1,
0,
0,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def reverse_words(sentence):\n \"\"\"\n Takes a string which represents a sentence and returns a new string with each word reversed \n but the word order i... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00001838",
"row_id": 1838,
"seed_ids": "[3319]"
} | 0.697217 | Apps_1838 | I | [
"reverse_word",
"reverse_words"
] | 2 | [
[
"reverse_words",
"reverse_word"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | eff88683e049bc35107ebadbb36f503725a6fb15 | 35414450d23c8c63994b980d807cccb43eedfe69 | |||
v1.0 | instruct | Apps | Apps_1862_I | -----Problem Statement-----
A "super prime" is a prime number that remains prime when its digits are cyclically rotated. For example, the prime number 197 remains prime (197, 719, 971) with each rotation of its digits, hence it is a super prime.
In this problem, given a positive integer N, your task is to determine how... | def generate_primes_up_to(n):
"""
Returns a list of boolean values where the index is the number
and the value at that index is True if the number is prime.
"""
sieve = [True] * (n + 1)
sieve[0] = sieve[1] = False # 0 and 1 are not prime numbers
for start in range(2, int(n**0.5) + 1):
... | def test_generate_primes_up_to():
sieve = generate_primes_up_to(10)
assert sieve[2] is True
assert sieve[3] is True
assert sieve[4] is False
assert sieve[5] is True
assert sieve[7] is True
def test_is_cyclic_prime():
prime_sieve = generate_primes_up_to(1000)
assert is_cyclic_prime(197... | [
{
"docstring": "Returns a list of boolean values where the index is the number\nand the value at that index is True if the number is prime.",
"function_declaration": "def generate_primes_up_to(n):",
"function_name": "generate_primes_up_to",
"parameter_list": "(n)"
},
{
"docstring": "Checks i... | [
0,
0,
0,
0,
0,
0,
0,
1,
0
] | 1 | hard | 0.111 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def generate_primes(n):\n \"\"\"Generate a list of prime numbers up to n using the Sieve of Eratosthenes.\"\"\"\n sieve = [True] * (n + 1)\n sieve[0] = sie... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00001862",
"row_id": 1862,
"seed_ids": "[955]"
} | 0.606158 | Apps_1862 | I | [
"generate_primes_up_to",
"is_cyclic_prime",
"count_super_primes_upto_n",
"super_primes"
] | 4 | [
[
"count_super_primes_upto_n",
"is_cyclic_prime"
],
[
"super_primes",
"count_super_primes_upto_n"
],
[
"super_primes",
"generate_primes_up_to"
]
] | 3 | [] | false | [] | false | pytest | false | [] | true | bbde87cade3a54b03be4ea01a79694e26f5665ab | 8b4c4d6229835d3d627afff399ff36788c4f69bf | |||
v1.0 | instruct | Apps | Apps_1912_I | Given an undirected graph with `n` vertices and `m` edges, you need to check if there is a cycle in the graph. If a cycle exists, return `True`. Otherwise, return `False`.
-----Input-----
The first line of the input contains an integer `T` denoting the number of test cases. The description of `T` test cases follows.
F... | def is_cyclic_dfs(graph, vertex, visited, parent):
visited[vertex] = True
for neighbor in graph[vertex]:
if not visited[neighbor]:
if is_cyclic_dfs(graph, neighbor, visited, vertex):
return True
elif neighbor != parent:
return True
return False
def ha... | import pytest
from solution import cycle_detection
def test_cycle_detection_example_1():
test_cases = [
(3, 3, [(1, 2), (2, 3), (3, 1)]),
]
assert cycle_detection(test_cases) == [True]
def test_cycle_detection_example_2():
test_cases = [
(4, 3, [(1, 2), (2, 3), (3, 4)]),
]
asse... | [
{
"docstring": null,
"function_declaration": "def is_cyclic_dfs(graph, vertex, visited, parent):",
"function_name": "is_cyclic_dfs",
"parameter_list": "(graph, vertex, visited, parent)"
},
{
"docstring": null,
"function_declaration": "def has_cycle(n, edges):",
"function_name": "has_... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def has_cycle(n, edges):\n \"\"\"\n Check if an undirected graph has a cycle.\n :param n: Number of vertices\n :param edges: List of tuples representing... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00001912",
"row_id": 1912,
"seed_ids": "[1354]"
} | 0.808916 | Apps_1912 | I | [
"is_cyclic_dfs",
"has_cycle",
"cycle_detection"
] | 3 | [
[
"cycle_detection",
"has_cycle"
],
[
"has_cycle",
"is_cyclic_dfs"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 0f166be527c55dccaf48a4dbaf0b82e0b44509fd | 5ba3240e42beef673701bff8b2088d3b2900a7ae | |||
v1.0 | instruct | Apps | Apps_1921_I | Alex is studying binary trees and is particularly interested in the concept of "symmetric trees." A binary tree is said to be symmetric if it is a mirror image of itself.
Your task is to help Alex implement a function to check if a given binary tree is symmetric.
-----Input:-----
- First line will contain $T$, the nu... | class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
def is_symmetric(root):
if not root:
return True
def is_mirror(t1, t2):
if not t1 and not t2:
return True
if not t1 or not t2:
return False
... | def test_is_symmetric():
input_data = "2\n1 2 2 3 4 4 3\n1 2 2 N 3 N 3"
expected_output = "YES\nNO"
assert main(input_data) == expected_output
def test_single_node_tree():
input_data = "1\n1"
expected_output = "YES"
assert main(input_data) == expected_output
def test_asymmetric_tree():
inp... | [] | [
0,
1,
0,
0,
0,
0,
1,
0,
1
] | 3 | medium | 0.333 | {
"trial_gpt4o_0": null,
"trial_gpt4o_1": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared1_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.righ... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00001921",
"row_id": 1921,
"seed_ids": "[625]"
} | 0.682232 | Apps_1921 | I | [
"is_symmetric",
"build_tree",
"check_symmetric_trees",
"main"
] | 4 | [
[
"check_symmetric_trees",
"build_tree"
],
[
"check_symmetric_trees",
"is_symmetric"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | false | [] | true | e0306fb8ad17107db6adce90bc638977dae6fb62 | 943f27f1ae574aa5b35221ac050f4e3417b459f7 | |||
v1.0 | instruct | Apps | Apps_1932_I | You are a software engineer tasked with implementing functionality in a logistics application. One of the features to develop is a route optimizer for delivery trucks.
Write a function that takes a list of delivery points, where each point is represented as a tuple of integers (x, y). The function should return the sh... | from itertools import permutations
from math import sqrt
def euclidean_distance(p1, p2):
return sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2)
def total_distance(route):
total = 0
for i in range(len(route) - 1):
total += euclidean_distance(route[i], route[i+1])
return total
def shortest_ro... | from solution import shortest_route
def test_no_points():
assert shortest_route([]) == [(0, 0), (0, 0)]
def test_single_point():
assert shortest_route([(1, 2)]) == [(0, 0), (1, 2), (0, 0)]
def test_two_points():
route = shortest_route([(1, 2), (3, 4)])
assert route[0] == (0, 0)
assert set(route[1... | [
{
"docstring": null,
"function_declaration": "def euclidean_distance(p1, p2):",
"function_name": "euclidean_distance",
"parameter_list": "(p1, p2)"
},
{
"docstring": null,
"function_declaration": "def total_distance(route):",
"function_name": "total_distance",
"parameter_list": "... | [
1,
1,
1,
0,
1,
1,
1,
1,
0,
1
] | 8 | easy | 0.8 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from itertools import permutations\nfrom math import sqrt\n\ndef euclidean_distance(p1, p2):\n return sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2)\n\ndef to... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00001932",
"row_id": 1932,
"seed_ids": "[4543]"
} | 0.653377 | Apps_1932 | I | [
"euclidean_distance",
"total_distance",
"shortest_route"
] | 3 | [
[
"shortest_route",
"total_distance"
],
[
"total_distance",
"euclidean_distance"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | f204d22afffa32ca5f7b574b2da052004d9a807b | 6ec7c9c728c882aa82665bb81b3fa97771d5675e | |||
v1.0 | instruct | Apps | Apps_1944_I | Alex likes probabilistic algorithms and is particularly fascinated by the properties of random number generators. He devised a problem where he needs to test if two random number generators produce sequences with similar properties.
Suppose Alex has two random number generators, RNG1 and RNG2. Both RNGs generate sequ... | def calculate_mean(sequence):
return sum(sequence) / len(sequence)
def calculate_std_dev(sequence, mean):
variance = sum((x - mean) ** 2 for x in sequence) / len(sequence)
return variance ** 0.5
def are_sequences_similar(n, sequence1, sequence2):
mean1 = calculate_mean(sequence1)
mean2 = calculate... | def test_calculate_mean():
assert calculate_mean([1, 2, 3, 4]) == 2.5
assert calculate_mean([2, 3, 4, 5]) == 3.5
assert calculate_mean([-1, -2, -3, -4]) == -2.5
assert calculate_mean([0, 0, 0, 0]) == 0.0
def test_calculate_std_dev():
assert abs(calculate_std_dev([1, 2, 3, 4], 2.5) - 1.1180339887498... | [
{
"docstring": null,
"function_declaration": "def calculate_mean(sequence):",
"function_name": "calculate_mean",
"parameter_list": "(sequence)"
},
{
"docstring": null,
"function_declaration": "def calculate_std_dev(sequence, mean):",
"function_name": "calculate_std_dev",
"paramet... | [
1,
0,
1,
1,
1,
0,
1,
0,
0
] | 5 | medium | 0.556 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef are_sequences_similar(n, rng1, rng2):\n \"\"\"\n Determines if two sequences are statistically similar based on mean and standard deviation... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00001944",
"row_id": 1944,
"seed_ids": "[2336]"
} | 0.575421 | Apps_1944 | I | [
"calculate_mean",
"calculate_std_dev",
"are_sequences_similar"
] | 3 | [
[
"are_sequences_similar",
"calculate_mean"
],
[
"are_sequences_similar",
"calculate_std_dev"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 02df0dd83e81951e912069abbb518cebc054e875 | dfa1cea172c646108f98b11679ce60a20ea13897 | |||
v1.0 | instruct | Apps | Apps_1959_I | Polycarp likes playing with binary trees and powers of two. He has a binary tree and he wants to maximize the sum of values in the nodes along any path from the root to any leaf. Additionally, Polycarp can only include values that are powers of two (e.g., 1, 2, 4, 8, 16, etc.) in his sum.
A binary tree is represented ... | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def is_power_of_two(x):
"""
Helper function to determine if a number is a power of two.
"""
return (x & (x - 1) == 0) and x != 0
def max_power_of_two_path_su... | from solution import max_power_of_two_path_sum, TreeNode
def test_empty_tree():
assert max_power_of_two_path_sum(None) == 0
def test_single_node_tree():
assert max_power_of_two_path_sum(TreeNode(8)) == 8
assert max_power_of_two_path_sum(TreeNode(10)) == 0
def test_mixed_tree():
root = TreeNode(5, Tre... | [] | [
0,
0,
1,
0,
0,
0,
0,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\ndef max_powe... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00001959",
"row_id": 1959,
"seed_ids": "[101]"
} | 0.566226 | Apps_1959 | I | [
"is_power_of_two",
"max_power_of_two_path_sum"
] | 2 | [
[
"max_power_of_two_path_sum",
"is_power_of_two"
]
] | 1 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 91f8c204997fe7e0b349ffbe4ee604a8b57ebb87 | 13ddc77d5f39add1702dce9586cbb941aeea8285 | |||
v1.0 | instruct | Apps | Apps_2001_I | Sarah loves playing with numbers. Recently, she became interested in finding the nearest palindromic number for any given integer. A palindromic number is a number that reads the same forwards and backwards, like 121 or 5445. Given an integer N, Sarah wants to find the smallest palindromic number that is greater than o... | def is_palindrome(num):
"""Check if a number is a palindrome."""
return str(num) == str(num)[::-1]
def next_palindrome(n):
"""Find the smallest palindromic number greater than or equal to n."""
while True:
if is_palindrome(n):
return n
n += 1
def find_nearest_palindromes(te... | from solution import is_palindrome, next_palindrome, find_nearest_palindromes
def test_is_palindrome():
assert is_palindrome(121) == True
assert is_palindrome(12321) == True
assert is_palindrome(123) == False
assert is_palindrome(808) == True
assert is_palindrome(10) == False
def test_next_palindr... | [
{
"docstring": "Check if a number is a palindrome.",
"function_declaration": "def is_palindrome(num):",
"function_name": "is_palindrome",
"parameter_list": "(num)"
},
{
"docstring": "Find the smallest palindromic number greater than or equal to n.",
"function_declaration": "def next_pali... | [
0,
0,
0,
1,
0,
1,
0,
1,
0
] | 3 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome(num):\n return str(num) == str(num)[::-1]\n\ndef nearest_palindrome(N):\n while not is_palindrome(N):\n N += 1\n return N\n\ndef s... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00002001",
"row_id": 2001,
"seed_ids": "[1248]"
} | 0.809998 | Apps_2001 | I | [
"is_palindrome",
"next_palindrome",
"find_nearest_palindromes"
] | 3 | [
[
"find_nearest_palindromes",
"next_palindrome"
],
[
"next_palindrome",
"is_palindrome"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | c2820f8121dded9c97aea47e368d121faa94071c | 81d086de50717de0d6d232d8972989f9ec255e43 | |||
v1.0 | instruct | Apps | Apps_2024_I | A company manufactures widgets in batches. Each batch contains a varying number of widgets, and each widget requires a different processing time. The company wants to minimize the maximum load on any single worker by distributing the processing time of widgets as evenly as possible among workers.
Given `N` widgets and... | def is_valid_distribution(N, W, processing_times, max_load):
current_worker = 1
current_load = 0
for time in processing_times:
if current_load + time > max_load:
current_worker += 1
current_load = time
if current_worker > W:
return False
... | def test_is_valid_distribution():
assert is_valid_distribution(5, 3, [10, 15, 20, 25, 30], 50) == True
assert is_valid_distribution(5, 3, [10, 15, 20, 25, 30], 40) == False
def test_find_min_max_processing_time():
assert find_min_max_processing_time(7, 3, [10, 15, 20, 25, 30, 35, 40]) == 70
assert find... | [
{
"docstring": null,
"function_declaration": "def is_valid_distribution(N, W, processing_times, max_load):",
"function_name": "is_valid_distribution",
"parameter_list": "(N, W, processing_times, max_load)"
},
{
"docstring": null,
"function_declaration": "def find_min_max_processing_time(... | [
1,
1,
0,
1,
0,
1,
1,
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 canDistribute(workers, max_load, processing_times):\n \"\"\"\n Function to check if it's possible to distribute widgets among workers such that\n the m... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00002024",
"row_id": 2024,
"seed_ids": "[1000]"
} | 0.740339 | Apps_2024 | I | [
"is_valid_distribution",
"find_min_max_processing_time",
"minimum_maximum_load"
] | 3 | [
[
"find_min_max_processing_time",
"is_valid_distribution"
],
[
"minimum_maximum_load",
"find_min_max_processing_time"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | c7c01b182c7b16021643bec803374ff9c618838f | 0bd5223873977451477c8d4268c9d6632761d271 | |||
v1.0 | instruct | Apps | Apps_2041_I | -----
ANOMALY DETECTION
-----
In a research facility, scientists are continuously monitoring temperature readings collected every minute. For every one hour period, they need to check for anomalies. An anomaly in the temperature is detected if the variance of the temperature within an hour exceeds a threshold value T.... | import math
def calculate_variance(readings, mean):
"""
Calculate variance given a list of readings and their mean.
"""
N = len(readings)
variance = sum((xi - mean) ** 2 for xi in readings) / N
return variance
def anomaly_detection(T, N, temperature_readings):
"""
Calculate the number ... | def test_anomaly_detection():
T = 4
N = 120
temperature_readings = [
72, 71, 69, 70, 73, 74, 68, 72, 75, 70, 69, 71, 72, 73, 73, 72, 70, 69, 71, 70,
70, 72, 71, 68, 74, 69, 73, 72, 71, 72, 70, 69, 73, 75, 74, 71, 72, 73, 72, 71,
71, 70, 69, 75, 72, 71, 72, 74, 69, 70, 73, 75, 70, 7... | [
{
"docstring": "Calculate variance given a list of readings and their mean.",
"function_declaration": "def calculate_variance(readings, mean):",
"function_name": "calculate_variance",
"parameter_list": "(readings, mean)"
},
{
"docstring": "Calculate the number of hours with temperature anoma... | [
1,
1,
0,
0,
0,
1,
0,
1,
0,
0
] | 4 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def count_anomalies(T, N, temperatures):\n \"\"\"\n Returns the number of hours that have an anomaly in their temperature readings\n based on the variance ... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00002041",
"row_id": 2041,
"seed_ids": "[972]"
} | 0.511668 | Apps_2041 | I | [
"calculate_variance",
"anomaly_detection"
] | 2 | [
[
"anomaly_detection",
"calculate_variance"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | d0d41c81ec3b4fad32c551f2e8ddaf0ba298ecf7 | a77c2ab2e9937bdd8469290c1e9469027bca20b7 | |||
v1.0 | instruct | Apps | Apps_2054_I | A digital office building uses a smart lock system to manage room access, driven by a schedule of employee check-ins. Every employee has a unique ID and check-in time. The system keeps track of the people inside each room and ensures that a single employee cannot occupy two different rooms at the same time.
You need t... | from collections import defaultdict
from datetime import datetime
def parse_time(t):
return datetime.strptime(t, "%H:%M")
def find_overlaps(events):
employee_events = defaultdict(list)
for event in events:
employee_id, room_id, start_time, end_time = event
start_time = parse_time(star... | from solution import find_overlaps
def test_no_overlaps():
events = [
("E1", "Room1", "09:00", "10:00"),
("E2", "Room1", "10:00", "11:00"),
("E3", "Room2", "11:00", "12:00")
]
assert find_overlaps(events) == []
def test_single_employee_overlap():
events = [
("E1", "Room... | [
{
"docstring": null,
"function_declaration": "def parse_time(t):",
"function_name": "parse_time",
"parameter_list": "(t)"
},
{
"docstring": null,
"function_declaration": "def find_overlaps(events):",
"function_name": "find_overlaps",
"parameter_list": "(events)"
}
] | [
0,
1,
1,
1,
1,
0,
1,
1,
1,
1
] | 8 | easy | 0.8 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_overlaps(events):\n from collections import defaultdict\n\n def parse_time(time_str):\n hours, minutes = map(int, time_str.split(':'))\n ... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00002054",
"row_id": 2054,
"seed_ids": "[3443]"
} | 0.578437 | Apps_2054 | I | [
"parse_time",
"find_overlaps"
] | 2 | [
[
"find_overlaps",
"parse_time"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e63a32973486e71cde04c4fa80629f9bcbbcc106 | d891e38e942d7385f102f88303c720c6f535e5d2 | |||
v1.0 | instruct | Apps | Apps_2245_I | You are given two matrices $A$ and $B$ of dimensions $N \times M$. Your task is to determine if there exists a permutation of the rows of matrix $A$, say $A'$, such that $A'$ can be transformed into matrix $B$ by permuting the columns of $A'$.
-----Input-----
- The first line of the input contains a single integer $T$... | def can_transform_matrix(N, M, A, B):
# Sort each row in both matrices
sorted_A = [sorted(row) for row in A]
sorted_B = [sorted(row) for row in B]
# Sort the rows lexicographically
sorted_A.sort()
sorted_B.sort()
# Compare sorted versions of A and B
return sorted_A == sorted_B
... | import pytest
from solution import solve_problem
def test_example_1():
input_data = "2\n2 2\n1 2\n3 4\n3 4\n1 2\n2 3\n4 1\n2 3\n1 2\n3\n1 2\n3 4\n5 6\n3 4\n5 6\n1 2"
expected_output = "YES\nNO"
assert solve_problem(input_data) == expected_output
def test_case_same_matrices():
input_data = "1\n3 3\n1 2... | [
{
"docstring": null,
"function_declaration": "def can_transform_matrix(N, M, A, B):",
"function_name": "can_transform_matrix",
"parameter_list": "(N, M, A, B)"
},
{
"docstring": null,
"function_declaration": "def matrix_permutation_possible(test_cases):",
"function_name": "matrix_per... | [
1,
1,
0,
0,
1,
0,
1,
1,
0,
1
] | 6 | medium | 0.6 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def can_transform(A, B):\n \"\"\"\n Determines if there exists a permutation of the rows of matrix A, say A', \n such that A' can be transformed into matri... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00002245",
"row_id": 2245,
"seed_ids": "[914]"
} | 0.673413 | Apps_2245 | I | [
"can_transform_matrix",
"matrix_permutation_possible",
"solve_problem"
] | 3 | [
[
"matrix_permutation_possible",
"can_transform_matrix"
],
[
"solve_problem",
"matrix_permutation_possible"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 959fdadebb1457633a583647fc5826c193b4ac29 | efe7b27c556a1979ae51af01f17ce641008e2dd2 | |||
v1.0 | instruct | Apps | Apps_2246_I | Tina loves playing with her toy fencing set, positioning her pieces to represent a field partitioned by fences. The field is represented by a grid of `m` rows and `n` columns where some cells contain a fence ('#') and others are empty ('.'). Tina wants to find the largest rectangular section of the field that is not in... | def max_histogram_area(heights):
stack = []
max_area = 0
index = 0
while index < len(heights):
if not stack or heights[stack[-1]] <= heights[index]:
stack.append(index)
index += 1
else:
top_of_stack = stack.pop()
area = (heights[top_of_sta... | def test_example_1():
m = 6
n = 7
grid = [
".......",
"..#....",
".#.....",
".......",
"..#....",
".....#."
]
assert solve(m, n, grid) == 20
def test_example_2():
m = 4
n = 4
grid = [
".##.",
"....",
"..#.",
... | [
{
"docstring": null,
"function_declaration": "def max_histogram_area(heights):",
"function_name": "max_histogram_area",
"parameter_list": "(heights)"
},
{
"docstring": null,
"function_declaration": "def largest_rectangle_without_fences(grid, m, n):",
"function_name": "largest_rectang... | [
1,
1,
1,
1,
1,
1,
1,
0,
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 largest_rectangle_area(matrix):\n if not matrix:\n return 0\n max_area = 0\n rows, cols = len(matrix), len(matrix[0])\n heights = [0] * cols\... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00002246",
"row_id": 2246,
"seed_ids": "[2135]"
} | 0.654886 | Apps_2246 | I | [
"max_histogram_area",
"largest_rectangle_without_fences",
"solve"
] | 3 | [
[
"largest_rectangle_without_fences",
"max_histogram_area"
],
[
"solve",
"largest_rectangle_without_fences"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 5a5187f467d4795fe4ff63c803928f97041db921 | ab3b492a3fa90e14afe93ce0548f32aa8b584353 | |||
v1.0 | instruct | Apps | Apps_2321_I | Write a function that takes an array of integers and returns a new array containing only the prime numbers from the original array, in the same order. | def is_prime(n):
"""
Checks if a number is prime.
"""
if n <= 1:
return False
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
return True
def filter_primes(arr):
"""
Returns a new array containing only the prime numbers from the original array... | from solution import filter_primes
def test_no_primes():
assert filter_primes([4, 6, 8, 9, 10]) == []
def test_all_primes():
assert filter_primes([2, 3, 5, 7, 11]) == [2, 3, 5, 7, 11]
def test_mixed_numbers():
assert filter_primes([2, 4, 5, 6, 7, 10]) == [2, 5, 7]
def test_including_negative_numbers():
... | [
{
"docstring": "Checks if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a new array containing only the prime numbers from the original array.",
"function_declaration": "def filter_primes(a... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Checks if a number n is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n ... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00002321",
"row_id": 2321,
"seed_ids": "[4222]"
} | 0.634156 | Apps_2321 | I | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d5daf126c6e050f59a8e8f749cf5ae29466096b7 | 06f6528dddbd0d428a8c93b153823a99ad75418f | |||
v1.0 | instruct | Apps | Apps_2341_I | There are N towns connected by M bidirectional roads. Each road has a specific length and a color. A town mayor wants to ensure that the roads in the town form a connected graph where no two roads of the same color meet at the same town.
You need to help the mayor determine the maximum length of any colored road that d... | class UnionFind:
def __init__(self, n):
self.parent = list(range(n))
self.rank = [0] * n
def find(self, u):
if self.parent[u] != u:
self.parent[u] = self.find(self.parent[u])
return self.parent[u]
def union(self, u, v):
root_u = self.find(u)
... | def test_maximum_non_conflicting_road_length():
# Test case 1
roads = [
(1, 2, 4, 1),
(1, 3, 3, 2),
(2, 4, 2, 1),
(3, 4, 5, 1),
(1, 4, 8, 2)
]
assert maximum_non_conflicting_road_length(4, 5, roads) == 8
# Test case 2
roads = [
(1, 2, 10, 1),
... | [] | [
1,
0,
1,
0,
0,
0,
0,
0,
1
] | 3 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict\n\ndef get_max_road_length(n, m, roads):\n def is_valid(town_roads, last_edge):\n for road in town_roads:\n ... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00002341",
"row_id": 2341,
"seed_ids": "[2323]"
} | 0.776673 | Apps_2341 | I | [
"max_road_length",
"maximum_non_conflicting_road_length"
] | 2 | [
[
"maximum_non_conflicting_road_length",
"max_road_length"
]
] | 1 | [] | false | [
"UnionFind"
] | true | pytest | false | [] | true | 555f844a6c9cf8a7b89be386ca47a6bde6431a71 | 27d394f97ca0c71127030427fb8148ea6fdc82cb | |||
v1.0 | instruct | Apps | Apps_2349_I | For an array of integers $A$, a subarray is a contiguous part of the array. Let the sum of a subarray $B$ be defined as $sum(B)$. A subarray $B$ is said to be a harmonic subarray if $sum(B) \times \text{length}(B)$ is a prime number.
You are given the task to determine how many harmonic subarrays there are in a given ... | def is_prime(num):
"""
Determine if a number is prime.
"""
if num <= 1:
return False
if num == 2:
return True
if num % 2 == 0:
return False
p = 3
while p * p <= num:
if num % p == 0:
return False
p += 2
return True
def count_harmon... | from solution import harmonic_subarrays
def test_single_case():
# Basic test case
assert harmonic_subarrays(1, [
(3, "2 3 1")
]) == [2]
def test_multiple_cases():
# Multiple cases in one go
assert harmonic_subarrays(2, [
(3, "2 3 1"),
(4, "2 5 4 7")
]) == [2, 3]
def te... | [
{
"docstring": "Determine if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Count the number of harmonic subarrays.",
"function_declaration": "def count_harmonic_subarrays(N, A):",
"function... | [
0,
0,
0,
0,
0,
0,
1,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n re... | trial_gpt4o_6 | {
"original_instruction": "",
"prompt_id": "00002349",
"row_id": 2349,
"seed_ids": "[639]"
} | 0.66189 | Apps_2349 | I | [
"is_prime",
"count_harmonic_subarrays",
"solve",
"harmonic_subarrays"
] | 4 | [
[
"count_harmonic_subarrays",
"is_prime"
],
[
"harmonic_subarrays",
"solve"
],
[
"solve",
"count_harmonic_subarrays"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 535232236eaf0b4f5505478d5f5a5e571f73408c | f56ca8e554bb88d498ff1d1691210d4af6592ebc | |||
v1.0 | instruct | Apps | Apps_2355_I | Calculate Inversions
Given an array of integers, an inversion occurs if for any indices `i` and `j` (1 ≤ i < j ≤ N), `arr[i]` > `arr[j]`.
Your task is to count the number of inversions in a given array.
-----Input:-----
The first line of the input contains a single integer `T`, the number of test cases.
Each test... | def merge_and_count(arr, temp_arr, left, right):
if left >= right:
return 0
mid = (left + right) // 2
inv_count = merge_and_count(arr, temp_arr, left, mid)
inv_count += merge_and_count(arr, temp_arr, mid + 1, right)
inv_count += merge_and_merge(arr, temp_arr, left, mid, right)
return in... | from solution import solve_inversions
def test_case_1():
test_input = (2, [(5, [2, 4, 1, 3, 5]), (3, [3, 1, 2])])
expected = [3, 2]
assert solve_inversions(*test_input) == expected
def test_case_2():
test_input = (1, [(4, [4, 3, 2, 1])])
expected = [6]
assert solve_inversions(*test_input) =... | [
{
"docstring": null,
"function_declaration": "def merge_and_count(arr, temp_arr, left, right):",
"function_name": "merge_and_count",
"parameter_list": "(arr, temp_arr, left, right)"
},
{
"docstring": null,
"function_declaration": "def merge_and_merge(arr, temp_arr, left, mid, right):",
... | [
1,
1,
0,
1,
0,
0,
1,
0,
0
] | 4 | medium | 0.444 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def count_inversions(arr):\n \"\"\"\n Function to count inversions in an array using modified merge sort.\n \"\"\"\n # Helper function for merge sort to... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00002355",
"row_id": 2355,
"seed_ids": "[1038]"
} | 0.746599 | Apps_2355 | I | [
"merge_and_count",
"merge_and_merge",
"count_inversions",
"solve_inversions"
] | 4 | [
[
"count_inversions",
"merge_and_count"
],
[
"merge_and_count",
"merge_and_merge"
],
[
"solve_inversions",
"count_inversions"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | b4d298d8d02a5e34def2a595c2a39a2ce4f995f4 | 8504ac3f11cbfcf6fedc770e74de3949d18f1bbd | |||
v1.0 | instruct | Apps | Apps_2370_I | A team of biologists is working on a project to identify and classify DNA sequences. They decide to develop a small utility to help them convert DNA sequences into corresponding RNA sequences and to validate DNA sequences for any invalid characters.
DNA sequences are composed of the bases 'A', 'C', 'G', and 'T'. RNA s... | def dna_to_rna(dna_sequence):
"""
Converts a DNA sequence to an RNA sequence by replacing all occurrences of 'T' with 'U'.
If the DNA sequence contains invalid characters, returns None.
"""
valid_bases = {'A', 'C', 'G', 'T'}
if not validate_dna(dna_sequence):
return None
return dna_s... | from solution import dna_to_rna, validate_dna
def test_dna_to_rna_valid_sequence():
assert dna_to_rna("ACGTACGT") == "ACGUACGU"
def test_dna_to_rna_invalid_sequence():
assert dna_to_rna("ACGTACGX") == None
def test_dna_to_rna_empty_sequence():
assert dna_to_rna("") == ""
def test_dna_to_rna_all_valid_ba... | [
{
"docstring": "Converts a DNA sequence to an RNA sequence by replacing all occurrences of 'T' with 'U'.\nIf the DNA sequence contains invalid characters, returns None.",
"function_declaration": "def dna_to_rna(dna_sequence):",
"function_name": "dna_to_rna",
"parameter_list": "(dna_sequence)"
},
... | [
1,
1,
1,
0,
1,
1,
1,
1,
1,
1
] | 9 | easy | 0.9 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def dna_to_rna(dna_sequence):\n \"\"\"\n Converts a DNA sequence to a RNA sequence by replacing 'T' with 'U'.\n Returns None if there are invalid character... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00002370",
"row_id": 2370,
"seed_ids": "[1793]"
} | 0.562712 | Apps_2370 | I | [
"dna_to_rna",
"validate_dna"
] | 2 | [
[
"dna_to_rna",
"validate_dna"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 53390ae91ed89674cafc9e74af8766de1146f4ba | 3a3ef73856ac39f9dc4f55a314ca88c37427d954 | |||
v1.0 | instruct | Apps | Apps_2384_I | A startup company wants to automate the task of generating seating arrangements for their upcoming orientation session. They need a program that will help them arrange the attendees in a specific pattern based on the number of rows.
-----Input:-----
- First line will contain $T$, the number of test cases. Then the tes... | def generate_seating_pattern(n):
"""
Returns the seating arrangement pattern for N rows.
"""
pattern = []
for i in range(1, n+1):
pattern.append('#' * i)
return pattern
def generate_patterns_for_test_cases(test_cases):
"""
Given a list of test cases, generates seating patterns f... | from solution import generate_seating_patterns
def test_case_1():
T = 3
test_cases = [2, 3, 4]
expected_output = "#\n##\n\n#\n##\n###\n\n#\n##\n###\n####"
assert generate_seating_patterns(T, test_cases) == expected_output
def test_case_2():
T = 2
test_cases = [1, 3]
expected_output = "#\n\... | [
{
"docstring": "Returns the seating arrangement pattern for N rows.",
"function_declaration": "def generate_seating_pattern(n):",
"function_name": "generate_seating_pattern",
"parameter_list": "(n)"
},
{
"docstring": "Given a list of test cases, generates seating patterns for each case.",
... | [
1,
1,
0,
1,
0,
1,
0,
0,
0
] | 4 | medium | 0.444 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def generate_pattern(N):\n \"\"\"\n Generate seating arrangement pattern based on the number of rows.\n \"\"\"\n pattern = []\n for i in range(N):\n ... | trial_gpt4o_5 | {
"original_instruction": "",
"prompt_id": "00002384",
"row_id": 2384,
"seed_ids": "[1245]"
} | 0.659854 | Apps_2384 | I | [
"generate_seating_pattern",
"generate_patterns_for_test_cases",
"generate_seating_patterns"
] | 3 | [
[
"generate_patterns_for_test_cases",
"generate_seating_pattern"
],
[
"generate_seating_patterns",
"generate_patterns_for_test_cases"
]
] | 2 | [
"generate_patterns_for_test_cases"
] | false | [] | false | pytest | true | [] | true | be8f0a9c42a5e9a9b004de9b5cc7a63081fa87fa | dabaea02d7d3cf2a4e9a2c9a93a288fed7bdf248 | |||
v1.0 | instruct | Apps | Apps_2414_I | Write a function to calculate the sum of digits of a given number string raised to the power of their respective positions (with the leftmost digit having a position value of 1). The sum should then be checked if it is a prime number. If it is, return true; otherwise, return false.
A prime number is a number greater t... | def is_prime(n):
"""Check if a number is prime."""
if n <= 1:
return False
if n == 2 or n == 3:
return True
if n % 2 == 0:
return False
for i in range(3, int(n ** 0.5) + 1, 2):
if n % i == 0:
return False
return True
def sum_of_powers_and_prime_check(... | from solution import sum_of_powers_and_prime_check
def test_edge_cases():
assert sum_of_powers_and_prime_check("1") == False
assert sum_of_powers_and_prime_check("2") == True
assert sum_of_powers_and_prime_check("0") == False
def test_known_cases():
assert sum_of_powers_and_prime_check("123") == False... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Calculate the sum of digits raised to the power of their positions.\nCheck if the resulting sum is a prime number.",
"function... | [
0,
0,
0,
1,
0,
0,
0,
1,
1,
0
] | 3 | hard | 0.3 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n return False\n \n for i in range(3, i... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00002414",
"row_id": 2414,
"seed_ids": "[3129]"
} | 0.66646 | Apps_2414 | I | [
"is_prime",
"sum_of_powers_and_prime_check"
] | 2 | [
[
"sum_of_powers_and_prime_check",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4611d5848b4fb19cb90e83d78507945c4cf1e35b | ef46e6fce97104eb616fdcd2c94fd69e5e6a85b2 | |||
v1.0 | instruct | Apps | Apps_2450_I | Zara is a botanist who loves studying tree growth patterns.
One day she was observing a specific type of tree, which can be represented as a binary tree with nodes numbered from $1$ to $n$. In this tree, each node can have at most two children.
Zara wants to gather information about the sum of values of the nodes alo... | def path_sums(n, values, edges):
from collections import defaultdict, deque
# Create adjacency list
tree = defaultdict(list)
for u, v in edges:
tree[u].append(v)
tree[v].append(u)
# Initialize sum array with None
path_sum = [None] * (n + 1)
path_sum[1] = values[0]
# BF... | from solution import solve
def test_example_1():
n = 5
values = [1, 2, 3, 4, 5]
edges = [(1, 2), (1, 3), (2, 4), (2, 5)]
expected = [1, 3, 4, 7, 8]
result = solve(n, values, edges)
assert result == expected
def test_example_2():
n = 3
values = [2, 1, 4]
edges = [(1, 2), (1, 3)]
... | [
{
"docstring": null,
"function_declaration": "def path_sums(n, values, edges):",
"function_name": "path_sums",
"parameter_list": "(n, values, edges)"
},
{
"docstring": null,
"function_declaration": "def solve(n, values, edges):",
"function_name": "solve",
"parameter_list": "(n, v... | [
0,
0,
0,
1,
1,
1,
1,
1,
1,
1
] | 7 | easy | 0.7 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def tree_path_sums(n, values, edges):\n from collections import defaultdict, deque\n \n tree = defaultdict(list)\n for u, v in edges:\n tree[u].a... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00002450",
"row_id": 2450,
"seed_ids": "[2132]"
} | 0.705286 | Apps_2450 | I | [
"path_sums",
"solve"
] | 2 | [
[
"solve",
"path_sums"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 179587d6fa972a93bad7b7c9b1633d97226fe470 | 9a961fa4a4d9b4320db30a9dcf84bf21a305ef70 | |||
v1.0 | instruct | Apps | Apps_2461_I | Given an integer $N$, write a program to print a hexadecimal representation of an MxM spiral matrix filled sequentially with numbers from 1 to $N \times N$.
-----Input:-----
- A single integer $N$ indicating the size of the matrix.
-----Output:-----
- M lines, each with M space-separated hexadecimal numbers in upperc... | def generate_spiral_matrix(N):
def spiral_coords(size):
x, y = 0, 0
dx, dy = 0, 1
for _ in range(size * size):
yield x, y
if not (0 <= x + dx < size and 0 <= y + dy < size and matrix[x + dx][y + dy] == 0):
dx, dy = dy, -dx
x += dx
... | from solution import generate_spiral_matrix, print_hex_spiral_matrix
import io
import pytest
def test_generate_spiral_matrix():
expected = [
[1, 2, 3],
[8, 9, 4],
[7, 6, 5]
]
assert generate_spiral_matrix(3) == expected
def test_small_matrix():
expected = [
[1]
]
... | [
{
"docstring": null,
"function_declaration": "def generate_spiral_matrix(N):",
"function_name": "generate_spiral_matrix",
"parameter_list": "(N)"
},
{
"docstring": null,
"function_declaration": "def print_hex_spiral_matrix(N):",
"function_name": "print_hex_spiral_matrix",
"parame... | [
0,
1,
0,
1,
1,
0,
0,
0,
0,
1
] | 4 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def spiral_matrix_hex(N):\n \"\"\"\n Generates an N x N spiral matrix filled with sequential numbers from 1 to N^2 in hexadecimal representation.\n \"\"\"\... | trial_gpt4o_3 | {
"original_instruction": "",
"prompt_id": "00002461",
"row_id": 2461,
"seed_ids": "[738]"
} | 0.573939 | Apps_2461 | I | [
"generate_spiral_matrix",
"print_hex_spiral_matrix"
] | 2 | [
[
"print_hex_spiral_matrix",
"generate_spiral_matrix"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c152c9995d7d43ab711d4035b33658554405ba7f | 4a0f65ebee39e07e4929cd6d7b6d5cc374246c6f | |||
v1.0 | instruct | Apps | Apps_2484_I | In a distant land, there exist mystical flowers that bloom in a magical garden. Each flower has a unique blooming time and wilting time. The garden keeper wants to arrange them in such a way that there is always at least one flower blooming at any given time.
Your task is to find out if it is possible to arrange flowe... | def can_arrange_flowers(N, intervals):
"""
Determine if it's possible to arrange flowers such that there is always
at least one flower blooming at any given time from the earliest blooming
time to the latest wilting time.
Parameters:
N (int): Number of flowers.
intervals (list): List ... | from solution import can_arrange_flowers, flowers_blooming_possible
def test_single_flower():
assert can_arrange_flowers(1, [(1, 5)]) == True
def test_overlapping_periods():
assert can_arrange_flowers(3, [(1, 4), (5, 8), (2, 6)]) == True
def test_non_overlapping_periods():
assert can_arrange_flowers(3, [... | [
{
"docstring": "Determine if it's possible to arrange flowers such that there is always \nat least one flower blooming at any given time from the earliest blooming \ntime to the latest wilting time.\n\nParameters:\nN (int): Number of flowers.\nintervals (list): List of tuples containing blooming and wilting tim... | [
0,
0,
0,
0,
0,
0,
0,
1,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_possible_to_keep_continuous_blooming(flowers):\n \"\"\"\n Determines if it is possible to arrange flowers so that there is always at least one flower b... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00002484",
"row_id": 2484,
"seed_ids": "[1459]"
} | 0.658759 | Apps_2484 | I | [
"can_arrange_flowers",
"flowers_blooming_possible"
] | 2 | [
[
"flowers_blooming_possible",
"can_arrange_flowers"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 68f953ccde4c075732b736d481230bed215fd869 | 3093327c20f40907bb70a1d1f44154b2c05ebeb5 | |||
v1.0 | instruct | Apps | Apps_2491_I | You are given an n x n grid where each cell contains an integer. You are required to start at the top-left corner of the grid and move to the bottom-right corner. From each cell, you can move either right or down to the next cell. You want to find the minimal path sum from the top-left corner to the bottom-right corner... | def minimal_path_sum(grid):
"""
Given a 2D grid of integers, find the minimal path sum from the top-left corner to the bottom-right corner,
where you can only move either right or down.
"""
n = len(grid)
dp = [[0] * n for _ in range(n)]
dp[0][0] = grid[0][0]
# Initialize the first r... | from solution import minimal_path_sum, solve_minimal_path_sum, parse_input
def test_minimal_path_sum_basic():
grid = [
[1, 3, 1],
[1, 5, 1],
[4, 2, 1]
]
assert minimal_path_sum(grid) == 7
def test_minimal_path_sum_two_by_two():
grid = [
[1, 2],
[1, 1]
]
... | [
{
"docstring": "Given a 2D grid of integers, find the minimal path sum from the top-left corner to the bottom-right corner,\nwhere you can only move either right or down.",
"function_declaration": "def minimal_path_sum(grid):",
"function_name": "minimal_path_sum",
"parameter_list": "(grid)"
},
{... | [
0,
0,
0,
1,
0,
1,
0,
0,
1,
0
] | 3 | hard | 0.3 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def minimal_path_sum(T, test_cases):\n \"\"\"\n This function computes the minimal path sum from top-left to bottom-right\n in a grid for each test case.\n... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00002491",
"row_id": 2491,
"seed_ids": "[1265]"
} | 0.751967 | Apps_2491 | I | [
"minimal_path_sum",
"solve_minimal_path_sum",
"parse_input"
] | 3 | [
[
"solve_minimal_path_sum",
"minimal_path_sum"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | d95b074202827de554740843984e44c230651a85 | e081d544d135ed959bae8f4348280890320d8332 | |||
v1.0 | instruct | Apps | Apps_2508_I | Create a function that takes a list of integers and returns the sum of all prime numbers in the list. If there are no prime numbers in the list, the function should return 0.
Remember, a prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself.
Function Signature:
```pyth... | from typing import List
def is_prime(n: int) -> bool:
"""
Check if a number is prime.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return False
return True... | from solution import sum_of_primes
def test_sum_of_primes_with_only_primes():
assert sum_of_primes([2, 3, 5, 7]) == 17
def test_sum_of_primes_with_no_primes():
assert sum_of_primes([1, 4, 6, 8, 9, 10]) == 0
def test_sum_of_primes_with_mixed_numbers():
assert sum_of_primes([2, 3, 4, 5, 6]) == 10
def test... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns the sum of all prime numbers in the list.",
"function_declaration": "def sum_of_primes(numbers):",
"function_name"... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from typing import List\n\ndef is_prime(n: int) -> bool:\n \"\"\"\n Checks if a number is a prime number.\n \"\"\"\n if n <= 1:\n return False\n ... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00002508",
"row_id": 2508,
"seed_ids": "[3294]"
} | 0.714646 | Apps_2508 | I | [
"is_prime",
"sum_of_primes"
] | 2 | [
[
"sum_of_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 1ea9506a701517204aa02ffb0bdd0404ea64a1c2 | 517e33b626fdf37777c046e8e097de29d543d9b8 | |||
v1.0 | instruct | Apps | Apps_2523_I | You are given a sequence of Fibonacci numbers: `0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ...`. Notice that `0` is in position `one`.
A Fibonacci number is called a **"special Fibonacci"** if it is even and the sum of its digits is a prime number. For example:
- `2` is in position `four` (the digit sum is `2`, wh... | def is_prime(n):
"""Check if a number is prime."""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return True
def digi... | def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(17) == True
assert is_prime(18) == False
def test_digit_sum():
assert digit_sum(123) == 6
assert digit_sum(34) == 7
assert digit_sum(500) == 5
assert digit_sum(0) =... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Return the sum of the digits of a number.",
"function_declaration": "def digit_sum(n):",
"function_name": "digit_sum",
... | [
0,
0,
0,
0,
0,
1,
0,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if n < 2:\n return False\n if n == 2:\n return True\n if n % 2 ==... | trial_gpt4o_5 | {
"original_instruction": "",
"prompt_id": "00002523",
"row_id": 2523,
"seed_ids": "[3856]"
} | 0.589277 | Apps_2523 | I | [
"is_prime",
"digit_sum",
"fibonacci",
"sum_special_fibonacci"
] | 4 | [
[
"sum_special_fibonacci",
"digit_sum"
],
[
"sum_special_fibonacci",
"fibonacci"
],
[
"sum_special_fibonacci",
"is_prime"
]
] | 3 | [] | false | [] | false | pytest | false | [] | true | 7b7e4dbd337018675243c404282477164fd79be0 | b933a6a8a42d6fdad4600e6a05d14fe0a7fd613c | |||
v1.0 | instruct | Apps | Apps_2571_I | A binary tree is a data structure where each node has at most two children, referred to as the left child and the right child. A Binary Search Tree (BST) is a special kind of binary tree where for every node, the value of all the nodes in the left subtree is less than the node's value, and the value of all the nodes in... | class Node:
def __init__(self, value, left=None, right=None):
self.value = value
self.left = left
self.right = right
def parse_tree(preorder_str):
if preorder_str == 'null':
return None
if preorder_str[0] != '(' and preorder_str[-1] != ')':
return Node(int(preorder_s... | from solution import check_binary_search_tree
def test_case_1():
input_str = "(10,(5,(1,null,null),(8,null,null)),(15,(12,null,null),(20,null,null)))"
assert check_binary_search_tree(input_str) == "True"
def test_case_2():
input_str = "(10,(5,(1,null,null),(12,null,null)),(15,(7,null,null),(20,null,null))... | [] | [
0,
0,
0,
0,
0,
0,
0,
1,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_bst(tree_string):\n import ast\n\n tree = ast.literal_eval(tree_string)\n \n def is_bst_helper(node, min_val, max_val):\n if node == \"nul... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00002571",
"row_id": 2571,
"seed_ids": "[3308]"
} | 0.6353 | Apps_2571 | I | [
"parse_tree",
"parse_subtrees",
"isBST",
"check_binary_search_tree"
] | 4 | [
[
"check_binary_search_tree",
"isBST"
],
[
"check_binary_search_tree",
"parse_tree"
],
[
"parse_tree",
"parse_subtrees"
]
] | 3 | [] | false | [
"Node"
] | true | pytest | true | [] | true | d73c5555139ba7cae5b527e7c5649d9348b125c3 | 914d90160f6facce23e1b98e8c9bf6e4d0379c1a | |||
v1.0 | instruct | Apps | Apps_2589_I | Given a binary tree, determine if it is height-balanced. A height-balanced binary tree is defined as a binary tree in which the left and right subtrees of every node differ in height by no more than 1.
Input:
The first line contains a single integer T, the number of test cases. For each test case, the first line conta... | class TreeNode:
def __init__(self, value=0):
self.value = value
self.left = None
self.right = None
def is_balanced(root):
def check_height(node):
if not node:
return 0, True
left_height, left_balanced = check_height(node.left)
right_height, right_bala... | from solution import solve
def test_case_1():
t = 2
test_cases = [
(5, [(1, 2, 'L'), (1, 3, 'R'), (2, 4, 'L'), (2, 5, 'R')]),
(3, [(1, 2, 'L'), (2, 3, 'L'), (3, 4, 'L')])
]
assert solve(t, test_cases) == ["YES", "NO"]
def test_case_2():
t = 1
test_cases = [
(0, [])
... | [] | [
0,
0,
1,
0,
0,
1,
0,
1,
1,
0
] | 4 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, value):\n self.value = value\n self.left = None\n self.right = None\n\ndef is_balanced(root):\n def ... | trial_gpt4o_5 | {
"original_instruction": "",
"prompt_id": "00002589",
"row_id": 2589,
"seed_ids": "[1139]"
} | 0.724666 | Apps_2589 | I | [
"is_balanced",
"build_tree",
"solve"
] | 3 | [
[
"solve",
"build_tree"
],
[
"solve",
"is_balanced"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 8c031bc18a315fbcc7a0921c73ed1d60d9a1bfa5 | 670ebca010f059dd2fd5aca671ae1a3fa8ce28ea | |||
v1.0 | instruct | Apps | Apps_2610_I | A game consists of placing n distinct integers on an n x n grid, such that each integer from 1 to n^2 appears exactly once. Your task is to create such an arrangement following specific rules for row and column sums.
The sum of all integers in each row must be unique and the sum of all integers in each column must als... | import random
def generate_grid(n):
"""
Generates an n x n grid with unique row and column sums and an equal sum
of all row sums to all column sums.
"""
numbers = list(range(1, n * n + 1))
random.shuffle(numbers)
grid = [[0] * n for _ in range(n)]
for i in range(n):
for j ... | from solution import generate_valid_grid, check_unique_sums
def test_generate_valid_grid_3():
n = 3
grid = generate_valid_grid(n)
assert check_unique_sums(grid) == True
def test_generate_valid_grid_2():
n = 2
grid = generate_valid_grid(n)
assert check_unique_sums(grid) == True
def test_genera... | [
{
"docstring": "Generates an n x n grid with unique row and column sums and an equal sum\nof all row sums to all column sums.",
"function_declaration": "def generate_grid(n):",
"function_name": "generate_grid",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def ... | [
1,
0,
0,
0,
1,
0,
1,
1,
0,
0
] | 4 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def construct_grid(n):\n \"\"\"\n Constructs an n x n grid where each row and column sums are unique \n and the sum of all row sums equals the sum of all c... | trial_gpt4o_6 | {
"original_instruction": "",
"prompt_id": "00002610",
"row_id": 2610,
"seed_ids": "[2232]"
} | 0.696185 | Apps_2610 | I | [
"generate_grid",
"check_unique_sums",
"fix_grid",
"generate_valid_grid"
] | 4 | [
[
"fix_grid",
"check_unique_sums"
],
[
"fix_grid",
"generate_grid"
],
[
"generate_valid_grid",
"fix_grid"
],
[
"generate_valid_grid",
"generate_grid"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | 16adcc1ed720cccd35a9f7f96ebcf5b009dde54b | 416c9f134df095be171f60c7c3ea2ff88b123b80 | |||
v1.0 | instruct | Apps | Apps_2640_I | In a certain country, there are exactly n cities and m bidirectional roads connecting these cities. The cities are numbered with integers from 1 to n. If there is a road between cities a and b, you can travel that road in either direction in exactly one hour. The government plans to build several new transport hubs in ... | from collections import deque
def bfs_shortest_path(graph, start, n):
"""
Perform BFS to find the shortest path from start to all other vertices in an unweighted graph.
"""
visited = [False] * (n + 1)
distance = [float('inf')] * (n + 1)
queue = deque([start])
visited[start] = True
... | def test_min_transport_hubs_example1():
assert min_transport_hubs(4, 3, 2, [(1, 2), (2, 3), (3, 4)]) == 1
def test_min_transport_hubs_example2():
assert min_transport_hubs(5, 5, 2, [(1, 2), (2, 3), (3, 4), (4, 5), (5, 1)]) == 0
def test_min_transport_hubs_example3():
assert min_transport_hubs(6, 5, 1, [(1... | [
{
"docstring": "Perform BFS to find the shortest path from start to all other vertices in an unweighted graph.",
"function_declaration": "def bfs_shortest_path(graph, start, n):",
"function_name": "bfs_shortest_path",
"parameter_list": "(graph, start, n)"
},
{
"docstring": null,
"functio... | [
0,
0,
1,
0,
1,
0,
1,
1,
0,
0
] | 4 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef min_transport_hubs(n, m, k, roads):\n def dijkstra(graph, start):\n distances = {city: float('inf') for city in range(1, n + 1)}\n ... | trial_gpt4o_6 | {
"original_instruction": "",
"prompt_id": "00002640",
"row_id": 2640,
"seed_ids": "[2090]"
} | 0.814605 | Apps_2640 | I | [
"bfs_shortest_path",
"min_transport_hubs"
] | 2 | [
[
"min_transport_hubs",
"bfs_shortest_path"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 736ae60bd04f30b29accf793f2c3e1fc1ba668d9 | 8ddd49f90bc04a52246b2a19cdb9365985dbe056 | |||
v1.0 | instruct | Apps | Apps_2681_I | Given a string S consisting of lowercase letters and a dictionary D of words, return the shortest transformation sequence from S to a word in D that changes only one character at a time. Each transformed string must exist in the dictionary.
Example 1:
Input:
S = "hit",
D = ["hot", "dot", "dog", "lot", "log", "cog"]
... | from collections import deque
def is_one_letter_diff(word1, word2):
"""
Determines if word1 and word2 differ by exactly one letter.
"""
diff_count = sum(1 for a, b in zip(word1, word2) if a != b)
return diff_count == 1
def shortest_transformation_sequence(S, D):
"""
Returns the shortest tr... | from solution import shortest_transformation_sequence
def test_shortest_transformation_sequence_example1():
assert shortest_transformation_sequence("hit", ["hot", "dot", "dog", "lot", "log", "cog"]) == 1
def test_shortest_transformation_sequence_example2():
assert shortest_transformation_sequence("lead", ["lo... | [
{
"docstring": "Determines if word1 and word2 differ by exactly one letter.",
"function_declaration": "def is_one_letter_diff(word1, word2):",
"function_name": "is_one_letter_diff",
"parameter_list": "(word1, word2)"
},
{
"docstring": "Returns the shortest transformation sequence from S to a... | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
1
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef shortest_transformation_sequence(S, D):\n \"\"\"\n Returns the length of the shortest transformation sequence from S to a... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00002681",
"row_id": 2681,
"seed_ids": "[496]"
} | 0.694437 | Apps_2681 | I | [
"is_one_letter_diff",
"shortest_transformation_sequence"
] | 2 | [
[
"shortest_transformation_sequence",
"is_one_letter_diff"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c6eb8e990f52760380c88fb98ea1899702c16979 | b52fa87e170eecdb4c0665ce106482af36e78105 | |||
v1.0 | instruct | Apps | Apps_2715_I | You are given a binary tree with $N$ nodes. Each node has a unique value associated with it, ranging from $1$ to $N$. Write a program to determine if the tree is a "valid" binary search tree (BST). A binary search tree satisfies the following conditions:
- The left subtree of a node contains only nodes with values less... | def is_valid_bst(node_data):
from collections import defaultdict
# Building the tree
tree = {}
for data in node_data:
V, L, R = data
tree[V] = (L, R)
# Helper function to validate a BST
def validate(node, low, high):
if node == -1:
return True
if not... | def test_check_bst_valid():
n = 5
node_data = [
(4, 2, 5),
(2, 1, 3),
(5, -1, -1),
(1, -1, -1),
(3, -1, -1)
]
assert check_bst(n, node_data) == "YES"
def test_check_bst_invalid():
n = 3
node_data = [
(1, 2, 3),
(2, -1, -1),
(3, -1,... | [
{
"docstring": null,
"function_declaration": "def is_valid_bst(node_data):",
"function_name": "is_valid_bst",
"parameter_list": "(node_data)"
},
{
"docstring": null,
"function_declaration": "def check_bst(n, node_data):",
"function_name": "check_bst",
"parameter_list": "(n, node_... | [
0,
1,
0,
0,
1,
1,
1,
1,
1,
1
] | 7 | easy | 0.7 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, value, left=None, right=None):\n self.value = value\n self.left = left\n self.right = right\n\ndef crea... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00002715",
"row_id": 2715,
"seed_ids": "[776]"
} | 0.617025 | Apps_2715 | I | [
"is_valid_bst",
"check_bst"
] | 2 | [
[
"check_bst",
"is_valid_bst"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | bcce08c00505cd496d365990550e1692e51e9950 | 4a1f2fa4726c152b59eab97ed7b05b44825a6bf4 | |||
v1.0 | instruct | Apps | Apps_2728_I | There is an underground mall with N shops arranged in a line from 1 to N. Each shop sells a certain number of items represented by an array `items` where `items[i]` indicates the number of items in the i-th shop. The shop management conducts promotions by merging consecutive shops to form a bigger shop, which will then... | def preprocess_items(items):
"""
Precompute the prefix sums for the items list.
"""
prefix_sums = [0] * (len(items) + 1)
for i in range(1, len(items) + 1):
prefix_sums[i] = prefix_sums[i - 1] + items[i - 1]
return prefix_sums
def query_total_items(prefix_sums, L, R):
"""
Return ... | def test_total_items_in_ranges():
N = 5
items = [2, 4, 1, 6, 3]
Q = 3
queries = [(1, 3), (2, 5), (1, 5)]
result = total_items_in_ranges(N, items, Q, queries)
expected = [7, 14, 16]
assert result == expected
def test_total_items_in_ranges_single_query():
N = 4
items = [1, 2, 3, ... | [
{
"docstring": "Precompute the prefix sums for the items list.",
"function_declaration": "def preprocess_items(items):",
"function_name": "preprocess_items",
"parameter_list": "(items)"
},
{
"docstring": "Return the total number of items in the range [L, R] (1-based index).",
"function_d... | [
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 preprocess_items(items):\n \"\"\"\n Function to preprocess the items array to create prefix sums for fast range sum queries.\n \"\"\"\n N = len(item... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00002728",
"row_id": 2728,
"seed_ids": "[1331]"
} | 0.686518 | Apps_2728 | I | [
"preprocess_items",
"query_total_items",
"total_items_in_ranges"
] | 3 | [
[
"total_items_in_ranges",
"preprocess_items"
],
[
"total_items_in_ranges",
"query_total_items"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | eb315fc6228a63fc26a1ae5ac45e6e16edda3c13 | b7c5d3de1cb705859395fcb573f530fcc498eb63 | |||
v1.0 | instruct | Apps | Apps_2731_I | Johnny loves string manipulation and enjoys creating new words from fragments of other words. Given two strings, A and B of the same length, Johnny wants to create a new string C by interleaving characters from A and B.
One interleaving way is defined as picking the first character from A, then the first character fro... | def interleave_strings(A, B):
"""
Generate an interleaved string C from A and B.
"""
return ''.join([A[i] + B[i] for i in range(len(A))])
def count_distinct_characters(C):
"""
Count the number of distinct characters in the string C.
"""
return len(set(C))
def process_queries(N, A, B, q... | from solution import process_queries
def test_process_queries_example_case():
N = 5
A = "abcde"
B = "fghij"
queries = ["1 3 k", "3", "2 5 z", "3"]
results = process_queries(N, A, B, queries)
assert results == [10, 10]
def test_process_queries_single_update_A():
N = 3
A = "abc"
B = ... | [
{
"docstring": "Generate an interleaved string C from A and B.",
"function_declaration": "def interleave_strings(A, B):",
"function_name": "interleave_strings",
"parameter_list": "(A, B)"
},
{
"docstring": "Count the number of distinct characters in the string C.",
"function_declaration"... | [
0,
0,
0,
0,
0,
1,
1,
1,
1,
0
] | 4 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def interleaved_string_distinct_count(A, B, queries):\n \"\"\"\n Function to handle the interleaving and queries for updating and counting distinct chars.\n ... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00002731",
"row_id": 2731,
"seed_ids": "[765]"
} | 0.718639 | Apps_2731 | I | [
"interleave_strings",
"count_distinct_characters",
"process_queries"
] | 3 | [
[
"process_queries",
"count_distinct_characters"
],
[
"process_queries",
"interleave_strings"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | true | [] | true | 569992e0f21e07a4e5a3d4f9564c77e69a0a0987 | df536fa0b6f837264cbfc5c0881fe1c0486761ac | |||
v1.0 | instruct | Apps | Apps_2796_I | Note: This question carries $150$ points.
The city of Algorithmsville is organizing a coding competition, and they have a very unique scoring system. They want to assign scores to the participants based on their user ID which is a combination of letters and digits. The score is calculated as the sum of the ASCII values... | def calculate_ascii_score(user_id):
"""
Calculate the ASCII score of a user ID by summing ASCII values of all characters.
"""
return sum(ord(char) for char in user_id)
def find_highest_score_user(ids):
"""
Given a list of user IDs, find the one(s) with the highest ASCII value score.
"""
... | from solution import calculate_ascii_score, find_highest_score_user
def test_calculate_ascii_score():
assert calculate_ascii_score("A3B") == 182
assert calculate_ascii_score("a") == 97
assert calculate_ascii_score("1") == 49
assert calculate_ascii_score("AB") == 131
def test_find_highest_score_user_si... | [
{
"docstring": "Calculate the ASCII score of a user ID by summing ASCII values of all characters.",
"function_declaration": "def calculate_ascii_score(user_id):",
"function_name": "calculate_ascii_score",
"parameter_list": "(user_id)"
},
{
"docstring": "Given a list of user IDs, find the one... | [
0,
0,
0,
0,
0,
0,
1,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def calculate_score(user_id):\n \"\"\"\n Calculates the score for a given user ID by summing the ASCII values of its characters.\n \"\"\"\n return sum(o... | trial_gpt4o_6 | {
"original_instruction": "",
"prompt_id": "00002796",
"row_id": 2796,
"seed_ids": "[898]"
} | 0.722853 | Apps_2796 | I | [
"calculate_ascii_score",
"find_highest_score_user"
] | 2 | [
[
"find_highest_score_user",
"calculate_ascii_score"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d993f69309b7c8943453d31fa9010c92e00fab3a | c0d066a77faecab3efd9b4c0b8263572b17ba0cd | |||
v1.0 | instruct | Apps | Apps_2802_I | You are given a rectangular grid of cells with non-negative integer elevations. Water can flow from one cell to its neighboring cells (left, right, up, down) if the elevation of the neighboring cell is less than or equal to the current cell. You are tasked with determining the number of cells from which water can flow ... | def pacific_atlantic_water_flow(matrix):
if not matrix or not matrix[0]:
return 0
m, n = len(matrix), len(matrix[0])
def dfs(x, y, visited):
directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]
stack = [(x, y)]
visited.add((x, y))
while stack:
cx, cy = stack.... | from solution import solve
def test_sample_input():
input_str = "5 5\n1 2 2 3 5\n3 2 3 4 4\n2 4 5 3 1\n6 7 1 4 5\n5 1 1 2 4"
assert solve(input_str) == 7
def test_single_cell():
input_str = "1 1\n0"
assert solve(input_str) == 1
def test_empty_matrix():
input_str = "0 0"
assert solve(input_str... | [
{
"docstring": null,
"function_declaration": "def pacific_atlantic_water_flow(matrix):",
"function_name": "pacific_atlantic_water_flow",
"parameter_list": "(matrix)"
},
{
"docstring": null,
"function_declaration": "def rect_grid_from_input(input_str):",
"function_name": "rect_grid_fr... | [
0,
0,
0,
0,
0,
0,
1,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def pacific_atlantic(matrix):\n if not matrix or not matrix[0]:\n return 0\n\n m, n = len(matrix), len(matrix[0])\n\n def dfs(i, j, visited, prev_he... | trial_gpt4o_6 | {
"original_instruction": "",
"prompt_id": "00002802",
"row_id": 2802,
"seed_ids": "[752]"
} | 0.707266 | Apps_2802 | I | [
"pacific_atlantic_water_flow",
"rect_grid_from_input",
"solve"
] | 3 | [
[
"solve",
"pacific_atlantic_water_flow"
],
[
"solve",
"rect_grid_from_input"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | ec625c148a28746cfa9f05aeb49f8e2b72b02311 | c6dbd2481856ad9fb1ffd377c01cc0fb60902d61 | |||
v1.0 | instruct | Apps | Apps_2805_I | Create a function that takes a list of integers as input and returns a new list containing only the elements that are prime numbers. A prime number is a number that has no divisors other than 1 and itself. If the input is not a list, return "Please enter a valid list". If the input list contains non-integer elements, t... | def is_prime(n):
"""
Helper function to determine if a number is prime.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
max_divisor = int(n**0.5) + 1
for d in range(3, max_divisor, 2):
if n % d == 0:
return False
... | from solution import filter_primes
def test_non_list_input():
assert filter_primes("12345") == "Please enter a valid list"
assert filter_primes(12345) == "Please enter a valid list"
assert filter_primes(None) == "Please enter a valid list"
assert filter_primes(123.45) == "Please enter a valid list"
de... | [
{
"docstring": "Helper function to determine if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Takes a list of integers and returns a list of prime numbers.\nIf the input is not a list, returns \"Please... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Helper function to determine if a given number is prime.\n \"\"\"\n if n <= 1:\n return False\n for i in range(2, ... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00002805",
"row_id": 2805,
"seed_ids": "[3483]"
} | 0.695273 | Apps_2805 | I | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a89a4e60db33d4f81cefb2b3148ca2760f85b9a7 | 2762732205b0e5a36d753941841f7791e212bc38 | |||
v1.0 | instruct | Apps | Apps_2891_I | Challenge:
Design a function to validate if strings in a list are valid email addresses. An email address is considered valid if it meets the following conditions:
1. It contains exactly one '@' symbol.
2. The local part (portion before '@') must contain only alphanumeric characters and the following special characte... | import re
def is_valid_email(email):
"""
Returns True if the email is valid according to the defined rules, False otherwise.
"""
try:
local, domain = email.split('@')
except ValueError:
return False
# Validate local part
if not re.match(r'^[a-zA-Z0-9]+([._-]?[a-zA-Z0-9]... | from solution import is_valid_email, filter_valid_emails
def test_is_valid_email():
assert is_valid_email('test.email@example.com') == True
assert is_valid_email('username@domain.com') == True
assert is_valid_email('.invalid@domain.com') == False
assert is_valid_email('username@domain,com') == False
... | [
{
"docstring": "Returns True if the email is valid according to the defined rules, False otherwise.",
"function_declaration": "def is_valid_email(email):",
"function_name": "is_valid_email",
"parameter_list": "(email)"
},
{
"docstring": "Filters and returns a list of valid emails according t... | [
0,
0,
1,
0,
1,
0,
0,
0,
1,
0
] | 3 | hard | 0.3 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_valid_email(email):\n if email.count('@') != 1:\n return False\n \n local, domain = email.split('@')\n \n # Check local part\n if le... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00002891",
"row_id": 2891,
"seed_ids": "[3677]"
} | 0.538853 | Apps_2891 | I | [
"is_valid_email",
"filter_valid_emails"
] | 2 | [
[
"filter_valid_emails",
"is_valid_email"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | cdaecbda25ef40c60b0a0aec514e08b199fd19bf | b6f1fdae98a34f1a4ee23cb6ff934fe13543c690 | |||
v1.0 | instruct | Apps | Apps_2908_I | You are given a 2D grid of size $n \times m$. Each cell in the grid has a value, which is either 0 or 1. Your task is to find the size of the largest square containing only 1s.
-----Input-----
- The first line of the input contains an integer $T$ denoting the number of test cases. The description of the test cases fol... | def largest_square_of_ones(grids):
def find_largest_square(grid, n, m):
max_side = 0
dp = [[0] * m for _ in range(n)]
for i in range(n):
for j in range(m):
if grid[i][j] == 1:
if i == 0 or j == 0:
dp[i][j] = 1
... | def test_largest_square_of_ones():
input_data_1 = "2\n3 3\n1 1 1\n1 1 1\n1 1 1\n4 5\n1 0 1 0 0\n1 0 1 1 1\n1 1 1 1 1\n1 0 0 1 0"
expected_output_1 = "3\n2"
assert solve(input_data_1) == expected_output_1
input_data_2 = "1\n2 2\n0 0\n0 0"
expected_output_2 = "0"
assert solve(input_data_2) == exp... | [
{
"docstring": null,
"function_declaration": "def largest_square_of_ones(grids):",
"function_name": "largest_square_of_ones",
"parameter_list": "(grids)"
},
{
"docstring": null,
"function_declaration": "def process_input(input_data):",
"function_name": "process_input",
"parameter... | [
1,
1,
1,
1,
0,
1,
1,
0,
0
] | 6 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def largest_square(grid):\n \"\"\"\n This function receives a n x m grid of 0s and 1s and returns the size of the largest square containing only 1s.\n \"\"... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00002908",
"row_id": 2908,
"seed_ids": "[770]"
} | 0.718512 | Apps_2908 | I | [
"largest_square_of_ones",
"process_input",
"solve"
] | 3 | [
[
"solve",
"largest_square_of_ones"
],
[
"solve",
"process_input"
]
] | 2 | [
"process_input"
] | false | [] | false | pytest | false | [] | true | e0627e1eebbd147d2cb62af266398203fe6661a8 | 95233e9756b3f66f499c0324cfc495f4d6b7a13c | |||
v1.0 | instruct | Apps | Apps_2959_I | Given an array of positive integers and an integer k, write a function that partitions the array into k contiguous subarrays (subsequences) such that the largest sum among these subarrays is minimized. Your function should return this minimized largest sum.
Example:
Given array nums = [7, 2, 5, 10, 8] and k = 2,
The... | def can_split(nums, k, max_sum):
"""
Helper function to determine if it's possible to split the array
into k or fewer parts with all parts having sums not exceeding max_sum.
"""
current_sum = 0
required_splits = 1
for num in nums:
if current_sum + num <= max_sum:
cur... | from solution import splitArray
def test_example_case():
nums = [7, 2, 5, 10, 8]
k = 2
assert splitArray(nums, k) == 18
def test_small_case():
nums = [1, 2, 3, 4, 5]
k = 2
assert splitArray(nums, k) == 9
def test_single_element_array():
nums = [10]
k = 1
assert splitArray(nums, k)... | [
{
"docstring": "Helper function to determine if it's possible to split the array\ninto k or fewer parts with all parts having sums not exceeding max_sum.",
"function_declaration": "def can_split(nums, k, max_sum):",
"function_name": "can_split",
"parameter_list": "(nums, k, max_sum)"
},
{
"d... | [
0,
1,
1,
1,
1,
1,
1,
0,
1,
0
] | 7 | easy | 0.7 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def minimize_largest_sum(nums, k):\n def can_split(nums, k, max_sum):\n subarray_sum = 0\n subarray_count = 1\n \n for num in nums:\n... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00002959",
"row_id": 2959,
"seed_ids": "[481]"
} | 0.791139 | Apps_2959 | I | [
"can_split",
"splitArray"
] | 2 | [
[
"splitArray",
"can_split"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8df856016195aeca778b6d744293bbb5d0b5655b | b99cd14df79003b258fee6f3aa7e4849ebed0ba3 | |||
v1.0 | instruct | Apps | Apps_3034_I | # Task
Given an integer `n`, return the product of all the prime numbers less than or equal to `n`.
# Example
For `n = 10`, the result should be `210`
Since `2 * 3 * 5 * 7 = 210`
For `n = 5`, the result should be `30`
Since `2 * 3 * 5 = 30`
For `n = 2`, the result should be `2`
Since `2` is the only prime number... | def is_prime(num):
"""
Returns True if num is a prime number.
"""
if num <= 1:
return False
for i in range(2, int(num**0.5) + 1):
if num % i == 0:
return False
return True
def product_of_primes(n):
"""
Returns the product of all prime numbers less than or equ... | from solution import is_prime, product_of_primes
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(1) == False
def test_product_of_primes():
assert product_of_primes(10) == 210
assert product_of... | [
{
"docstring": "Returns True if num is a prime number.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns the product of all prime numbers less than or equal to n.",
"function_declaration": "def product_of_pri... | [
1,
1,
0,
1,
0,
1,
1,
1,
0,
0
] | 6 | medium | 0.6 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n for i in range(2, int(nu... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00003034",
"row_id": 3034,
"seed_ids": "[4384]"
} | 0.644635 | Apps_3034 | I | [
"is_prime",
"product_of_primes"
] | 2 | [
[
"product_of_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 34440fe949ebc55553180c55ce012b73041a7c93 | 0079b962c3d8885b18821546ab874e9fd740dcf8 | |||
v1.0 | instruct | Apps | Apps_3127_I | Given a binary tree, implement an algorithm to perform an in-order traversal of the tree without using recursion. Return an array of node values representing the in-order traversal.
### Input
- The input will consist of a series of lines representing the nodes of the binary tree.
- Each line will contain three integer... | class TreeNode:
def __init__(self, value):
self.value = value
self.left = None
self.right = None
def build_tree_from_input(lines):
if not lines:
return None
nodes = {}
for line in lines:
N, L, R = map(int, line.split())
if N not in nodes:
... | from solution import binary_tree_inorder_traversal
def test_binary_tree_inorder_traversal():
input_lines = [
"1 2 3",
"2 4 5",
"3 -1 -1",
"4 -1 -1",
"5 -1 -1"
]
result = binary_tree_inorder_traversal(input_lines)
assert result == [4, 2, 5, 1, 3]
def test_binary_... | [] | [
0,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 9 | easy | 0.9 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\ndef build_tr... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00003127",
"row_id": 3127,
"seed_ids": "[600]"
} | 0.574556 | Apps_3127 | I | [
"build_tree_from_input",
"inorder_traversal",
"binary_tree_inorder_traversal"
] | 3 | [
[
"binary_tree_inorder_traversal",
"build_tree_from_input"
],
[
"binary_tree_inorder_traversal",
"inorder_traversal"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | e5fc1b3e2ac654f0a9499d6a6eede0f5a73ccd47 | 48f86903103bd9b38fe86014c5d37c10d6750e26 | |||
v1.0 | instruct | Apps | Apps_3133_I | ### Encrypt and Decrypt Strings with Caesar Cipher
A Caesar cipher is one of the simplest and most widely known encryption techniques. It is a type of substitution cipher in which each letter in the plaintext is shifted a certain number of places down the alphabet. For example, with a shift of 1, 'A' would be replaced... | def encrypt(text, shift):
"""
Encrypts the text using Caesar cipher with the given shift value.
"""
encrypted_text = []
for char in text:
if char.isalpha():
shift_amount = shift % 26
if char.islower():
new_char = chr((ord(char) - ord('a') + shift_amoun... | from solution import encrypt, decrypt
def test_encrypt_positive_shift():
assert encrypt("Hello, World!", 3) == "Khoor, Zruog!"
assert encrypt("abcXYZ", 2) == "cdeZAB"
def test_encrypt_negative_shift():
assert encrypt("Hello, World!", -3) == "Ebiil, Tloia!"
assert encrypt("abcXYZ", -2) == "yzaVWX"
... | [
{
"docstring": "Encrypts the text using Caesar cipher with the given shift value.",
"function_declaration": "def encrypt(text, shift):",
"function_name": "encrypt",
"parameter_list": "(text, shift)"
},
{
"docstring": "Decrypts the text using Caesar cipher with the given shift value.",
"f... | [
1,
1,
1,
0,
1,
0,
1,
1,
1,
1
] | 8 | easy | 0.8 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def encrypt(text, shift):\n \"\"\"\n Encrypts the given text using Caesar cipher with the provided shift.\n \n Parameters:\n text (str): the string t... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00003133",
"row_id": 3133,
"seed_ids": "[4198]"
} | 0.719671 | Apps_3133 | I | [
"encrypt",
"decrypt"
] | 2 | [
[
"decrypt",
"encrypt"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0ab4a3a0b05014142ed01651ed8b31c62f4da165 | 8f10e75cb643fd2961bfa515872e17885e0672d5 | |||
v1.0 | instruct | Apps | Apps_3187_I | You are given a grid of size $n \times m$ filled with integers. You need to find the largest plus sign that can be formed using cells with value 1. A plus sign consists of a center cell and four arms extending from it, with equal length in all four directions (up, down, left, right). The length of an arm is the number ... | def largest_plus_sign(grid):
"""
Function to determine the order of the largest plus sign in a given grid
:param grid: List of List of integers representing the grid
:return: Integer representing the order of the largest plus sign
"""
n = len(grid)
if n == 0:
return 0
m = le... | def test_example_1():
n, m = 5, 5
input_grid = [
"1 1 1 1 1",
"1 1 1 1 1",
"1 1 1 1 1",
"1 1 1 1 1",
"1 1 1 1 1"
]
assert read_input_and_solve(n, m, input_grid) == 2
def test_example_2():
n, m = 3, 3
input_grid = [
"1 0 1",
"0 1 0",
... | [
{
"docstring": "Function to determine the order of the largest plus sign in a given grid\n\n:param grid: List of List of integers representing the grid\n:return: Integer representing the order of the largest plus sign",
"function_declaration": "def largest_plus_sign(grid):",
"function_name": "largest_pl... | [
0,
1,
0,
0,
0,
1,
0,
1,
0,
0
] | 3 | hard | 0.3 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def largest_plus_sign(n, m, grid):\n if n == 0 or m == 0:\n return 0\n \n left = [[0] * m for _ in range(n)]\n right = [[0] * m for _ in range(n)... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00003187",
"row_id": 3187,
"seed_ids": "[2391]"
} | 0.627041 | Apps_3187 | I | [
"largest_plus_sign",
"read_input_and_solve"
] | 2 | [
[
"read_input_and_solve",
"largest_plus_sign"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 06a6c951a0ba4c2a7dbcb78a2a23b46620467be3 | de05371da3e0124d1f9555e052dddf6938191b62 | |||
v1.0 | instruct | Apps | Apps_3188_I | Joy has a collection of n unique toys, each with a distinct integer ID. Every toy can be represented as a node in a graph, where there is an undirected edge between two nodes if the absolute difference between their IDs is a perfect square.
Write a program to determine the sum of the sizes of all connected components ... | import math
from collections import defaultdict, deque
def is_perfect_square(x):
return int(math.isqrt(x)) ** 2 == x
def sum_of_sizes_of_connected_components(n, toy_ids):
def bfs(node):
queue = deque([node])
visited[node] = True
size = 0
while queue:
current = queue... | import pytest
from solution import sum_of_sizes_of_connected_components
def test_small_example():
assert sum_of_sizes_of_connected_components(5, [1, 4, 9, 16, 23]) == 5
def test_all_isolated():
assert sum_of_sizes_of_connected_components(3, [1, 2, 3]) == 3
def test_all_connected():
assert sum_of_sizes_of... | [
{
"docstring": null,
"function_declaration": "def is_perfect_square(x):",
"function_name": "is_perfect_square",
"parameter_list": "(x)"
},
{
"docstring": null,
"function_declaration": "def sum_of_sizes_of_connected_components(n, toy_ids):",
"function_name": "sum_of_sizes_of_connected... | [
0,
1,
1,
1,
1,
1,
1,
1,
0,
1
] | 8 | easy | 0.8 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef is_perfect_square(x):\n \"\"\"\n Returns True if x is a perfect square, otherwise returns False\n \"\"\"\n return int(math.sqrt(x))**... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00003188",
"row_id": 3188,
"seed_ids": "[2156]"
} | 0.607347 | Apps_3188 | I | [
"is_perfect_square",
"sum_of_sizes_of_connected_components"
] | 2 | [
[
"sum_of_sizes_of_connected_components",
"is_perfect_square"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4b0330fcac09493bc84cf8a8d333c11968a32c39 | 0ad00c4b0603ca37f5a0beb32d4301ff853f3c22 | |||
v1.0 | instruct | Apps | Apps_3193_I | You are given an undirected graph with `n` nodes and `m` edges where each node is labeled from `1` to `n`. Each edge connects two nodes and has a weight associated with it. Your task is to find the Minimum Spanning Tree (MST) of the graph using Kruskal's algorithm and output its total weight.
-----Input-----
The firs... | def find(parent, i):
if parent[i] == i:
return i
else:
return find(parent, parent[i])
def union(parent, rank, x, y):
xroot = find(parent, x)
yroot = find(parent, y)
if rank[xroot] < rank[yroot]:
parent[xroot] = yroot
elif rank[xroot] > rank[yroot]:
parent[yr... | def test_example_case():
assert minimum_spanning_tree(4, 5, [(1, 2, 1), (1, 3, 4), (2, 3, 2), (3, 4, 3), (4, 2, 5)]) == 6
def test_no_edges():
assert minimum_spanning_tree(1, 0, []) == 0
assert minimum_spanning_tree(2, 0, []) == "IMPOSSIBLE"
assert minimum_spanning_tree(3, 0, []) == "IMPOSSIBLE"
def t... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
1,
1,
1,
1,
1,
1,
1,
0,
1,
0
] | 8 | easy | 0.8 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class UnionFind:\n def __init__(self, n):\n self.parent = list(range(n))\n self.rank = [0] * n\n\n def find(self, u):\n if self.parent[u]... | trial_gpt4o_5 | {
"original_instruction": "",
"prompt_id": "00003193",
"row_id": 3193,
"seed_ids": "[18]"
} | 0.785455 | Apps_3193 | I | [
"find",
"union",
"kruskal",
"minimum_spanning_tree"
] | 4 | [
[
"kruskal",
"find"
],
[
"kruskal",
"union"
],
[
"minimum_spanning_tree",
"kruskal"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | false | [] | true | ea83ddf17b8401492c400f73de4b8fc0edbb48be | bae5b4f63963777044159d4ae3625e453009b03d | |||
v1.0 | instruct | Apps | Apps_3281_I | A large number of students have enrolled in a coding contest. Given a list of contest scores, you need to find the highest score and the second highest score among the participants. If there is no second highest score (i.e., all participants have the same score), return "NO SECOND HIGHEST".
-----Input:-----
- The firs... | def find_highest_and_second_highest(scores):
unique_scores = sorted(set(scores), reverse=True)
if len(unique_scores) < 2:
return "NO SECOND HIGHEST"
else:
return f"{unique_scores[0]} {unique_scores[1]}"
def process_input_lines(lines):
n = int(lines[0].strip())
scores = list(map(... | from solution import find_highest_and_second_highest, process_input_lines
def test_example_1():
assert find_highest_and_second_highest([10, 20, 20, 30, 30]) == "30 20"
def test_example_2():
assert find_highest_and_second_highest([50, 50, 50]) == "NO SECOND HIGHEST"
def test_all_same_scores():
ass... | [
{
"docstring": null,
"function_declaration": "def find_highest_and_second_highest(scores):",
"function_name": "find_highest_and_second_highest",
"parameter_list": "(scores)"
},
{
"docstring": null,
"function_declaration": "def process_input_lines(lines):",
"function_name": "process_i... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_highest_and_second_highest(scores):\n \"\"\"\n Given a list of scores, returns a tuple of the highest and the second highest scores.\n If there is... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00003281",
"row_id": 3281,
"seed_ids": "[1546]"
} | 0.686702 | Apps_3281 | I | [
"find_highest_and_second_highest",
"process_input_lines"
] | 2 | [
[
"process_input_lines",
"find_highest_and_second_highest"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 48f2f416dafdbe639d4ec80de04016dc6b48e86b | a78f0cb1cdac1913b4045e5a779ae095870a321e | |||
v1.0 | instruct | Apps | Apps_3293_I | You are given a rectangular grid consisting of 'N' rows and 'M' columns with each cell either being land ('L') or water ('W'). You need to find the largest rectangular landmass (contiguous section of 'L' cells) that can be formed on the grid. A landmass is defined as a rectangle containing only 'L' cells.
-----Input--... | def maximalRectangle(grid):
if not grid:
return 0
max_area = 0
N = len(grid)
M = len(grid[0])
heights = [0] * M
for row in grid:
for idx in range(M):
if row[idx] == 'L':
heights[idx] += 1
else:
heights[idx] = 0
... | from solution import findLargestLandmass
def test_findLargestLandmass_example():
N = 4
M = 5
grid = [
"LWLWL",
"LLLWW",
"WLLWL",
"LLLWL",
]
assert findLargestLandmass(N, M, grid) == 6
def test_findLargestLandmass_allLand():
N = 3
M = 3
grid = [
"... | [
{
"docstring": null,
"function_declaration": "def maximalRectangle(grid):",
"function_name": "maximalRectangle",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def largestRectangleArea(heights):",
"function_name": "largestRectangleArea",
"parameter_li... | [
1,
1,
1,
0,
1,
0,
0,
0,
0,
1
] | 5 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def largest_landmass_area(N, M, grid):\n if not grid or not grid[0]:\n return 0\n \n max_area = 0\n heights = [0] * M\n \n for row in grid:... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00003293",
"row_id": 3293,
"seed_ids": "[1676]"
} | 0.672099 | Apps_3293 | I | [
"maximalRectangle",
"largestRectangleArea",
"findLargestLandmass"
] | 3 | [
[
"findLargestLandmass",
"maximalRectangle"
],
[
"maximalRectangle",
"largestRectangleArea"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 099e8877475c96f8a0b8c3cb71408cc03307f47b | 6151526a63112fb4256764197464cdd1975fe0a0 | |||
v1.0 | instruct | Apps | Apps_3309_I | =====Function Description=====
.ordinal()
This operation converts an integer into its corresponding ordinal representation.
Example
>>> ordinal(1)
'1st'
>>> ordinal(2)
'2nd'
>>> ordinal(3)
'3rd'
>>> ordinal(4)
'4th'
>>> ordinal(11)
'11th'
>>> ordinal(21)
'21st'
>>> ordinal(22)
'22nd'
>>> ordinal(23)
'23rd'
.nth_ele... | def ordinal(num):
"""
Converts an integer to its ordinal representation.
Args:
num (int): The integer to convert.
Returns:
str: The ordinal representation of the integer.
"""
if 11 <= num % 100 <= 13:
suffix = 'th'
else:
suffixes = {1: 'st', 2: 'nd', 3: 'rd'... | def test_ordinal():
assert ordinal(1) == "1st"
assert ordinal(2) == "2nd"
assert ordinal(3) == "3rd"
assert ordinal(4) == "4th"
assert ordinal(11) == "11th"
assert ordinal(21) == "21st"
assert ordinal(22) == "22nd"
assert ordinal(23) == "23rd"
def test_nth_element():
assert nth_elem... | [
{
"docstring": "Converts an integer to its ordinal representation.\n\nArgs:\nnum (int): The integer to convert.\n\nReturns:\nstr: The ordinal representation of the integer.",
"function_declaration": "def ordinal(num):",
"function_name": "ordinal",
"parameter_list": "(num)"
},
{
"docstring": ... | [
1,
1,
1,
1,
1,
0,
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 ordinal(n):\n \"\"\"\n Convert an integer into its corresponding ordinal representation.\n \"\"\"\n if 10 <= n % 100 <= 20:\n suffix = 'th'\n... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00003309",
"row_id": 3309,
"seed_ids": "[2555]"
} | 0.630077 | Apps_3309 | I | [
"ordinal",
"nth_element",
"find_ordinal_at_index"
] | 3 | [
[
"find_ordinal_at_index",
"nth_element"
],
[
"find_ordinal_at_index",
"ordinal"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | c0bf44a1218d9db18ce1cfabc4cb017224d2ce76 | 035841ba8853f912475befe7ada7323d16a12dce | |||
v1.0 | instruct | Apps | Apps_3328_I | =====Function Descriptions=====
itertools.product()
The itertools.product() function returns the Cartesian product of input iterables.
Code
>>> import itertools
>>> itertools.product([1, 2, 3], repeat=2)
<itertools.product object at 0x00DF4D0>
>>> list(itertools.product([1, 2, 3], repeat=2))
[(1, 1), (1, 2), (1, 3), ... | import itertools
def is_palindrome(s):
cleaned = ''.join(filter(str.isalnum, s)).lower()
return cleaned == cleaned[::-1]
def palindrome_permutations(S):
permutations = set(itertools.permutations(S))
palindrome_perms = ["".join(p) for p in permutations if is_palindrome("".join(p))]
if not pali... | from solution import palindrome_permutations
def test_single_character_input():
assert palindrome_permutations("a") == None # Since it will print "a"
def test_two_character_palindrome():
assert palindrome_permutations("aa") == None # Since it will print "aa"
def test_two_character_non_palindrome():
asser... | [
{
"docstring": null,
"function_declaration": "def is_palindrome(s):",
"function_name": "is_palindrome",
"parameter_list": "(s)"
},
{
"docstring": null,
"function_declaration": "def palindrome_permutations(S):",
"function_name": "palindrome_permutations",
"parameter_list": "(S)"
... | [
0,
0,
0,
0,
1,
0,
0,
0,
0
] | 1 | hard | 0.111 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import itertools\n\ndef is_palindrome(s):\n \"\"\"\n Function to check if a given string is a palindrome.\n \"\"\"\n s = ''.join(filter(str.isalnum, s))... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00003328",
"row_id": 3328,
"seed_ids": "[4756]"
} | 0.662792 | Apps_3328 | I | [
"is_palindrome",
"palindrome_permutations"
] | 2 | [
[
"palindrome_permutations",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c78c15c1a236072e55bc8c70f19bd3c7cdaed358 | 424f4bb5cee59c8750c3ce81dafef68b05d8b145 | |||
v1.0 | instruct | Apps | Apps_3379_I | In Scala, an indirectly recursive function is one that makes a call to another function, which in turn calls the original function. This indirect recursion can be useful for implementing algorithms that need to alternate between different behaviors or states in each call.
Implement two mutually recursive functions, `e... | def evenSum(lst):
"""
Returns the sum of elements at even indices in the list.
"""
if not lst:
return 0
return lst[0] + oddSum(lst[1:])
def oddSum(lst):
"""
Returns the sum of elements at odd indices in the list.
"""
if not lst:
return 0
return evenSum(lst[1:]) | from solution import evenSum, oddSum
def test_evenSum_empty_list():
assert evenSum([]) == 0
def test_oddSum_empty_list():
assert oddSum([]) == 0
def test_evenSum_single_element_list():
assert evenSum([9]) == 9
def test_oddSum_single_element_list():
assert oddSum([9]) == 0
def test_evenSum_multiple_... | [
{
"docstring": "Returns the sum of elements at even indices in the list.",
"function_declaration": "def evenSum(lst):",
"function_name": "evenSum",
"parameter_list": "(lst)"
},
{
"docstring": "Returns the sum of elements at odd indices in the list.",
"function_declaration": "def oddSum(l... | [
0,
0,
1,
1,
1,
0,
0,
0,
0,
0
] | 3 | hard | 0.3 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def evenSum(lst):\n \"\"\"\n Computes the sum of elements at even indices of a given list.\n \"\"\"\n def helper(ls, is_even):\n if not ls:\n ... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00003379",
"row_id": 3379,
"seed_ids": "[4782]"
} | 0.604032 | Apps_3379 | I | [
"evenSum",
"oddSum"
] | 2 | [
[
"evenSum",
"oddSum"
],
[
"oddSum",
"evenSum"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 44c1e4b0c102467e986cb07cd3a9ba935d620536 | 6e8fbdb7312d577b34106267e079b54a05033443 | |||
v1.0 | instruct | Apps | Apps_3429_I | Your task is to implement a simplified version of the A* algorithm for navigating a robot in a 2D grid. The robot starts at position `(0,0)` of the grid and needs to reach the bottom-right corner `(n-1, n-1)`.
The grid contains cells marked as `0` (walkable) and `1` (obstacle). The robot can move up, down, left, or ri... | from heapq import heappush, heappop
from typing import List, Tuple
def manhattan_distance(x1: int, y1: int, x2: int, y2: int) -> int:
return abs(x1 - x2) + abs(y1 - y2)
def shortest_path(grid: List[List[int]]) -> int:
n = len(grid)
if grid[0][0] == 1 or grid[n-1][n-1] == 1:
return -1
... | def test_shortest_path():
assert shortest_path([[0,0,0], [0,1,0], [0,0,0]]) == 4
assert shortest_path([[0,1], [1,0]]) == -1
assert shortest_path([[0,0,1], [1,0,1], [1,0,0]]) == 4
assert shortest_path([[0]]) == 0
assert shortest_path([[1,0,0], [0,1,0], [0,0,0]]) == -1
assert shortest_path([[0,1,1... | [
{
"docstring": null,
"function_declaration": "def manhattan_distance(x1, y1, x2, y2):",
"function_name": "manhattan_distance",
"parameter_list": "(x1, y1, x2, y2)"
},
{
"docstring": null,
"function_declaration": "def shortest_path(grid):",
"function_name": "shortest_path",
"param... | [
1,
1,
0,
0,
1,
0,
1,
1,
0,
0
] | 5 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\nfrom typing import List, Tuple\n\ndef heuristic(x: int, y: int, goal_x: int, goal_y: int) -> int:\n return abs(x - goal_x) + abs(y - goal_y)\n\ndef... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00003429",
"row_id": 3429,
"seed_ids": "[4349]"
} | 0.632113 | Apps_3429 | I | [
"manhattan_distance",
"shortest_path"
] | 2 | [
[
"shortest_path",
"manhattan_distance"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 79338cd138d0f8cca3bc71db6cbed842ef61e7f1 | b944b0f2fa7f96cb8702ce72be7f40e14f046937 | |||
v1.0 | instruct | Apps | Apps_3453_I | You are designing a system to keep track of reservations at a restaurant. Each reservation can be for a different table, and no two reservations can overlap in time. Every table is identified by a unique number.
Your task is to determine if all reservations in the list can be accommodated without any time overlap for ... | def can_accommodate_reservations(test_cases):
results = []
for reservations in test_cases:
reservations.sort() # Sort by start time
accepted = True
for i in range(1, len(reservations)):
if reservations[i][0] < reservations[i - 1][1]:
accepted = False
... | from solution import restaurant_reservations
def test_sample_input():
input_text = "2\n3\n1 3\n2 5\n4 6\n2\n1 2\n2 3\n"
expected_output = "REJECTED\nACCEPTED\n"
assert run_test_case(input_text) == expected_output
def run_test_case(input_text):
import sys
from io import StringIO
old_stdout = s... | [
{
"docstring": null,
"function_declaration": "def can_accommodate_reservations(test_cases):",
"function_name": "can_accommodate_reservations",
"parameter_list": "(test_cases)"
},
{
"docstring": null,
"function_declaration": "def parse_input(input_text):",
"function_name": "parse_inpu... | [
1,
1,
1,
1,
1,
1,
0,
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 can_accommodate_reservations(test_cases):\n results = []\n for reservations in test_cases:\n reservations.sort(key=lambda x: x[0])\n is_acce... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00003453",
"row_id": 3453,
"seed_ids": "[1305]"
} | 0.670341 | Apps_3453 | I | [
"can_accommodate_reservations",
"parse_input",
"restaurant_reservations"
] | 3 | [
[
"restaurant_reservations",
"can_accommodate_reservations"
],
[
"restaurant_reservations",
"parse_input"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 7a926d78ebfab80ce4925170bea267ffd7b64a43 | 89c05b601f717ef8a50a9a815a45e3d8c45a787d | |||
v1.0 | instruct | Apps | Apps_3488_I | Write a function `primes_between(a, b)` that returns a list of all prime numbers between `a` and `b` (including `a` and `b`, if they themselves are prime).
A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. For instance, the list of prime numbers between 10 and 30... | def is_prime(n):
"""
Helper function to check if a number is a prime.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i... | from solution import primes_between
def test_primes_between_10_and_20():
assert primes_between(10, 20) == [11, 13, 17, 19]
def test_primes_between_30_and_50():
assert primes_between(30, 50) == [31, 37, 41, 43, 47]
def test_primes_between_1_and_10():
assert primes_between(1, 10) == [2, 3, 5, 7]
def test_... | [
{
"docstring": "Helper function to check if a number is a prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list of all prime numbers between a and b (inclusive).",
"function_declaration": "def primes_be... | [
1,
1,
1,
1,
1,
1,
1,
0,
1,
1
] | 9 | easy | 0.9 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 == 0 or num % 3 == 0:\n return False\n i... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00003488",
"row_id": 3488,
"seed_ids": "[3301]"
} | 0.665619 | Apps_3488 | I | [
"is_prime",
"primes_between"
] | 2 | [
[
"primes_between",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 689ff4802d41692716dfd9b34fa5fe36a8845478 | a3f7e8f0c58c109938286f30dbe4200df170b1b0 | |||
v1.0 | instruct | Apps | Apps_3495_I | Write a function that takes a list of integers and returns a new list containing the integers that are palindromes. A palindrome is a number that reads the same forward and backward.
### Examples
- Input: [123, 121, 454, 32, 303]
- Output: [121, 454, 303]
- Input: [10, 101, 20]
- Output: [101] | def is_palindrome(number):
"""
Checks if a given number is a palindrome.
"""
number_str = str(number)
return number_str == number_str[::-1]
def filter_palindromes(numbers):
"""
Returns a new list containing the integers that are palindromes.
Parameters:
- numbers: List of integ... | from solution import filter_palindromes
def test_filter_palindromes_all_palindromes():
assert filter_palindromes([121, 131, 141]) == [121, 131, 141]
def test_filter_palindromes_no_palindromes():
assert filter_palindromes([123, 456, 789]) == []
def test_filter_palindromes_mixed():
assert filter_palindrome... | [
{
"docstring": "Checks if a given number is a palindrome.",
"function_declaration": "def is_palindrome(number):",
"function_name": "is_palindrome",
"parameter_list": "(number)"
},
{
"docstring": "Returns a new list containing the integers that are palindromes.\n\nParameters:\n- numbers: List... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_palindromes(numbers):\n \"\"\"\n Returns a list of palindrome integers from the input list.\n \"\"\"\n def is_palindrome(n):\n str_n = s... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00003495",
"row_id": 3495,
"seed_ids": "[4290]"
} | 0.698242 | Apps_3495 | I | [
"is_palindrome",
"filter_palindromes"
] | 2 | [
[
"filter_palindromes",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a60db1d18761e94d44557025b7e6248fb3cf0328 | a20088ebd3d20c5594e4f3f0ed16e1ff4a142bbb | |||
v1.0 | instruct | Apps | Apps_3524_I | Write a function that takes an array of integers and returns a new array containing only the prime numbers from the original array. If there are no prime numbers in the input array, the function should return an empty array.
## Examples
```
[2, 3, 4, 5, 6] => [2, 3, 5]
[1, 4, 6, 8, 9, 10] => []
[7, ... | def is_prime(n):
"""
Returns True if n is a prime number, otherwise False.
"""
if n < 2:
return False
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
return True
def filter_primes(arr):
"""
Returns a list containing only the prime numbers in t... | from solution import filter_primes
def test_filter_prime_basic():
assert filter_primes([2, 3, 4, 5, 6]) == [2, 3, 5]
def test_filter_prime_no_primes():
assert filter_primes([1, 4, 6, 8, 9, 10]) == []
assert filter_primes([15, 18, 20, 22, 24, 25]) == []
def test_filter_prime_all_primes():
assert filt... | [
{
"docstring": "Returns True if n is a prime number, otherwise False.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list containing only the prime numbers in the given array.",
"function_declaration": "def ... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if n < 2:\n return False\n for i in range(2, int(n ** 0.... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00003524",
"row_id": 3524,
"seed_ids": "[4096]"
} | 0.678373 | Apps_3524 | I | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d1b115102b9a4e5de9e69cf2e95ed4d458b64cb7 | 5def1e9d4fff44e1d2ef11a697db7dec9d0389ee | |||
v1.0 | instruct | Apps | Apps_3558_I | Given a list of integers, determine if each integer is a "Perfect Number". A Perfect Number is a positive integer that is equal to the sum of its proper divisors, excluding the number itself. For example, the number 6 has proper divisors 1, 2, and 3, and 1 + 2 + 3 = 6, so 6 is a Perfect Number.
-----Input-----
A list ... | def is_perfect_number(num):
"""
Determines if a number is a Perfect Number.
A Perfect Number is a positive integer that is equal to the sum of its proper divisors, excluding the number itself.
"""
if num <= 1:
return False
divisor_sum = 1 # Start with 1, which is a proper divisor o... | from solution import is_perfect_number, check_perfect_numbers
def test_is_perfect_number():
# Testing known perfect numbers
assert is_perfect_number(6) == True
assert is_perfect_number(28) == True
assert is_perfect_number(496) == True
assert is_perfect_number(8128) == True
# Testing non-pe... | [
{
"docstring": "Determines if a number is a Perfect Number.\nA Perfect Number is a positive integer that is equal to the sum of its proper divisors, excluding the number itself.",
"function_declaration": "def is_perfect_number(num):",
"function_name": "is_perfect_number",
"parameter_list": "(num)"
... | [
1,
0,
1,
1,
1,
1,
1,
1,
1,
1
] | 9 | easy | 0.9 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def sum_of_proper_divisors(n):\n \"\"\"\n Returns the sum of proper divisors of n excluding itself.\n \"\"\"\n if n <= 1:\n return 0\n \n ... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00003558",
"row_id": 3558,
"seed_ids": "[741]"
} | 0.619526 | Apps_3558 | I | [
"is_perfect_number",
"check_perfect_numbers"
] | 2 | [
[
"check_perfect_numbers",
"is_perfect_number"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | cfdea6212e4ef6899313d2d66164197d7203b063 | b4e8a92a46d2989af35840f9f4851fe9f16af7b9 | |||
v1.0 | instruct | Apps | Apps_3567_I | A company has a server, which is represented by a grid of dimensions $M \times N$, where each cell in the grid represents a unit of processing power. The processing power of the cell located at $(i, j)$ is given by a matrix $P$ of size $M \times N$. The company's goal is to identify a rectangular subgrid within this gr... | def max_sum_subgrid(M, N, grid):
# Initialize max sum as the smallest possible value
max_sum = -float('inf')
# Prefix sums for rows
for top in range(M):
temp_sums = [0] * N
for bottom in range(top, M):
for col in range(N):
temp_sums[col] += grid[bottom][col]
... | from solution import max_sum_subgrid, process_input
def test_example_case():
M = 4
N = 5
grid = [
[1, 2, -1, -4, -20],
[-8, -3, 4, 2, 1],
[3, 8, 10, 1, 3],
[-4, -1, 1, 7, -6]
]
assert max_sum_subgrid(M, N, grid) == 29
def test_single_element():
M = 1
N = 1
... | [
{
"docstring": null,
"function_declaration": "def max_sum_subgrid(M, N, grid):",
"function_name": "max_sum_subgrid",
"parameter_list": "(M, N, grid)"
},
{
"docstring": null,
"function_declaration": "def kadane(arr):",
"function_name": "kadane",
"parameter_list": "(arr)"
},
{
... | [
1,
0,
0,
1,
1,
0,
0,
0,
1,
0
] | 4 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_sum_subgrid(M, N, P):\n def max_subarray_sum(arr):\n max_ending_here = max_so_far = arr[0]\n for x in arr[1:]:\n max_ending_here... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00003567",
"row_id": 3567,
"seed_ids": "[877]"
} | 0.666341 | Apps_3567 | I | [
"max_sum_subgrid",
"kadane",
"process_input"
] | 3 | [
[
"max_sum_subgrid",
"kadane"
]
] | 1 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | 29780fd0751bb072a65270e6513d1886fa0d758e | 681b6b134f686528eeb87112a36a380cc5062ae5 | |||
v1.0 | instruct | Apps | Apps_3596_I | Alice is learning about binary search trees (BST) and their properties. She knows that a BST is a tree data structure where each node has at most two children, referred to as the left child and the right child. For any given node with value V, all values in the left subtree are less than V, and all values in the right ... | from collections import deque
class TreeNode:
def __init__(self, val):
self.val = val
self.left = None
self.right = None
def construct_bst_from_level_order(level_order):
if not level_order:
return None
root = TreeNode(level_order[0])
queue = deque([root])
index... | from solution import bst_inorder_from_level_order
def test_example_case():
n = 7
level_order = [4, 2, 6, 1, 3, 5, 7]
assert bst_inorder_from_level_order(n, level_order) == [1, 2, 3, 4, 5, 6, 7]
def test_single_node():
n = 1
level_order = [10]
assert bst_inorder_from_level_order(n, level_order)... | [] | [
0,
0,
1,
1,
0,
0,
1,
1,
1,
1
] | 6 | medium | 0.6 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, key):\n self.left = None\n self.right = None\n self.val = key\n\ndef insert_level_order(arr, root, i, n... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00003596",
"row_id": 3596,
"seed_ids": "[2321]"
} | 0.562845 | Apps_3596 | I | [
"construct_bst_from_level_order",
"inorder_traversal",
"bst_inorder_from_level_order"
] | 3 | [
[
"bst_inorder_from_level_order",
"construct_bst_from_level_order"
],
[
"bst_inorder_from_level_order",
"inorder_traversal"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 79fd44e22d7f7bec6a1e295ab04a91d81ee8da57 | dab3f497c864686901ab2ee37dbbb674c0c0030e | |||
v1.0 | instruct | Apps | Apps_3600_I | You are given a grid with R rows and C columns, filled with integers. The task is to find the minimum path sum from the top-left corner of the grid to the bottom-right corner. You can only move either down or right at any point in time.
-----Input-----
The first line contains two integers R and C, indicating the numb... | def min_path_sum(grid):
R = len(grid)
C = len(grid[0])
dp = [[0] * C for _ in range(R)]
dp[0][0] = grid[0][0]
for i in range(1, R):
dp[i][0] = dp[i-1][0] + grid[i][0]
for j in range(1, C):
dp[0][j] = dp[0][j-1] + grid[0][j]
for i in range(1, R):
... | from solution import find_min_path_sum
def test_sample_input():
R = 3
C = 3
grid_values = [1, 3, 1, 1, 5, 1, 4, 2, 1]
assert find_min_path_sum(R, C, grid_values) == 7
def test_single_cell():
R = 1
C = 1
grid_values = [5]
assert find_min_path_sum(R, C, grid_values) == 5
def test_row_gr... | [
{
"docstring": null,
"function_declaration": "def min_path_sum(grid):",
"function_name": "min_path_sum",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def find_min_path_sum(R, C, grid_values):",
"function_name": "find_min_path_sum",
"parameter_list":... | [
1,
0,
1,
0,
1,
1,
0,
0,
0
] | 4 | medium | 0.444 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def min_path_sum(grid):\n \"\"\"\n Returns the minimum path sum from top-left corner to bottom-right corner in a grid.\n \n Args:\n grid (list of lis... | trial_gpt4o_3 | {
"original_instruction": "",
"prompt_id": "00003600",
"row_id": 3600,
"seed_ids": "[1190]"
} | 0.699928 | Apps_3600 | I | [
"min_path_sum",
"find_min_path_sum"
] | 2 | [
[
"find_min_path_sum",
"min_path_sum"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 198f1aca3b63768e38c5b0eed29a94a543f77149 | 1d253d37c2331dd4cc650f61b683aa7bfa8a293a | |||
v1.0 | instruct | Apps | Apps_3617_I | Linova has been inspired by the diverse landscapes in her kingdom and wants to create a unique way for her people to travel. The kingdom can be represented as a tree with `n` nodes (cities) and `n-1` edges (roads). A path between two cities is defined as the sequence of node visits starting from one city and ending in ... | from collections import deque, defaultdict
def find_farthest_node(start, graph, n):
visited = [False] * (n + 1)
dist = [0] * (n + 1)
queue = deque([start])
visited[start] = True
farthest_node = start
while queue:
node = queue.popleft()
for neighbor in graph[no... | def test_max_shortest_distance():
assert max_shortest_distance(5, [(1, 2), (1, 3), (3, 4), (3, 5)]) == 2
assert max_shortest_distance(4, [(1, 2), (2, 3), (3, 4)]) == 2
assert max_shortest_distance(3, [(1, 2), (1, 3)]) == 1
assert max_shortest_distance(2, [(1, 2)]) == 1
assert max_shortest_distance(6... | [
{
"docstring": null,
"function_declaration": "def find_farthest_node(start, graph, n):",
"function_name": "find_farthest_node",
"parameter_list": "(start, graph, n)"
},
{
"docstring": null,
"function_declaration": "def max_shortest_distance(n, roads):",
"function_name": "max_shortest... | [
0,
0,
1,
1,
0,
0,
0,
0,
0,
0
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef bfs(tree, start):\n n = len(tree)\n distance = [-1] * n\n distance[start] = 0\n queue = deque([start])\n while q... | trial_gpt4o_3 | {
"original_instruction": "",
"prompt_id": "00003617",
"row_id": 3617,
"seed_ids": "[2199]"
} | 0.769462 | Apps_3617 | I | [
"find_farthest_node",
"max_shortest_distance"
] | 2 | [
[
"max_shortest_distance",
"find_farthest_node"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 512aaeae924727c35d4f56452f4ebe10fa2f9bae | 85857007af8cd3d0c51a08328c814b637c2f1228 | |||
v1.0 | instruct | Apps | Apps_3632_I | Given an integer array `nums` of length `n` and an integer `k`, write a function `kth_largest_element(nums, k)` that returns the `k`-th largest element in the array.
Constraints:
- You may assume that k is always valid, 1 ≤ k ≤ n.
- You must solve it in O(n) time complexity on average.
### Example:
```python
def kth_... | import random
def partition(nums, left, right):
pivot_index = random.randint(left, right)
pivot_value = nums[pivot_index]
nums[pivot_index], nums[right] = nums[right], nums[pivot_index]
store_index = left
for i in range(left, right):
if nums[i] < pivot_value:
nums[store_index], ... | from solution import kth_largest_element
def test_kth_largest_element():
assert kth_largest_element([3, 2, 1, 5, 6, 4], 2) == 5
assert kth_largest_element([3, 2, 3, 1, 2, 4, 5, 5, 6], 4) == 4
assert kth_largest_element([1, 2, 3, 4, 5, 6], 1) == 6
assert kth_largest_element([1, 2, 3, 4, 5, 6], 6) == 1
... | [
{
"docstring": null,
"function_declaration": "def partition(nums, left, right):",
"function_name": "partition",
"parameter_list": "(nums, left, right)"
},
{
"docstring": null,
"function_declaration": "def quickselect(nums, left, right, k_smallest):",
"function_name": "quickselect",
... | [
0,
1,
1,
1,
0,
0,
0,
1,
0,
0
] | 4 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\n\ndef partition(nums, left, right, pivot_index):\n pivot_value = nums[pivot_index]\n # Move pivot value to the end\n nums[pivot_index], nums... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00003632",
"row_id": 3632,
"seed_ids": "[4039]"
} | 0.754377 | Apps_3632 | I | [
"partition",
"quickselect",
"kth_largest_element"
] | 3 | [
[
"kth_largest_element",
"quickselect"
],
[
"quickselect",
"partition"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 650aa4d7f23bb0800d335f8daf6c8617340b95f4 | 1e522a754f4d24cf91ec7a9fd376685dac190b1c | |||
v1.0 | instruct | Apps | Apps_3657_I | =====Problem Statement=====
A valid email address follows these rules:
1. It must have exactly one "@" symbol.
2. The local part (part before the "@") can contain alphanumeric characters and special characters: ".", "-", and "_". It cannot start or end with a special character, and the special characters cannot be con... | import re
def is_valid_email(email):
"""
Check if an email address is valid based on the given rules.
"""
pattern = re.compile(
r'^[a-zA-Z0-9]+(?:[._-][a-zA-Z0-9]+)*@[a-zA-Z0-9]+(?:\.[a-zA-Z0-9]+)+$'
)
return pattern.match(email) is not None
def filter_valid_emails(emails):
"""
... | from solution import is_valid_email, filter_valid_emails
def test_is_valid_email():
assert is_valid_email("john.doe@example.com") == True
assert is_valid_email("my-email@domain.co") == True
assert is_valid_email("hello_world123@sub.domain.com") == True
assert is_valid_email("john..doe@example.com") == ... | [
{
"docstring": "Check if an email address is valid based on the given rules.",
"function_declaration": "def is_valid_email(email):",
"function_name": "is_valid_email",
"parameter_list": "(email)"
},
{
"docstring": "Filters a list of email addresses, returning only the valid ones.",
"func... | [
1,
1,
1,
0,
1,
1,
0,
0,
0
] | 5 | medium | 0.556 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import re\n\ndef is_valid_email(email):\n \"\"\"\n Returns True if the given email address is valid according to the specified rules.\n \"\"\"\n local, ... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00003657",
"row_id": 3657,
"seed_ids": "[2646]"
} | 0.553501 | Apps_3657 | I | [
"is_valid_email",
"filter_valid_emails"
] | 2 | [
[
"filter_valid_emails",
"is_valid_email"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ae6a5d172f1c419afead4e19d311628cb1067536 | 7aa57d8ae0db34d5c19e560885e5c60bc90702dd | |||
v1.0 | instruct | Apps | Apps_3703_I | **Task Description:**
As part of the expansion plans for your robotics simulation lab, you need to assign tasks to multiple robots. Each robot has a specific, limited capacity for carrying out tasks within a given time frame. To optimize the task distribution among the robots, you aim to minimize the total time taken ... | def minimize_max_time(M, N, robot_caps, task_durations):
"""
Distributes tasks among robots to minimize the maximum time taken by the robot finishing last.
Returns -1 if not possible to distribute tasks within given constraints.
"""
tasks = sorted(task_durations, reverse=True)
robots = [0] * M
... | def test_minimize_max_time_case1():
input_str = '3 5\n8 10 12\n2 4 6 8 10\n'
assert solve_task_distribution(input_str) == [12]
def test_minimize_max_time_case2():
input_str = '2 3\n7 5\n6 8 9\n'
assert solve_task_distribution(input_str) == [-1]
def test_minimize_max_time_multiple_cases():
input_st... | [
{
"docstring": "Distributes tasks among robots to minimize the maximum time taken by the robot finishing last.\nReturns -1 if not possible to distribute tasks within given constraints.",
"function_declaration": "def minimize_max_time(M, N, robot_caps, task_durations):",
"function_name": "minimize_max_ti... | [
0,
0,
0,
0,
1,
0,
0,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def can_distribute(tasks, robots, max_time, N, M):\n time_needed = [0] * M\n for task in tasks:\n best_robot = -1\n for robot in range(M):\n ... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00003703",
"row_id": 3703,
"seed_ids": "[1495]"
} | 0.689527 | Apps_3703 | I | [
"minimize_max_time",
"parse_input",
"solve_task_distribution"
] | 3 | [
[
"solve_task_distribution",
"minimize_max_time"
],
[
"solve_task_distribution",
"parse_input"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | false | [] | true | 7e4d6be54a9904f5c15b53e97c45fe5d0bd45bfc | a6ce7a0b35fdb86725bd6b8f859d423385e4e765 | |||
v1.0 | instruct | Apps | Apps_3738_I | Ali is working on a project to help with event management. He is tasked with creating a program to manage invitations to guests. Each invitation has a guest's name and a priority level. Ali needs to write a function that sorts the invitations first by priority level in descending order, and if two guests have the same ... | def sort_invitations(n, invitations):
"""
Sorts invitations by priority level in descending order,
and by name in alphabetical order for the same priority level.
Parameters:
- n: int, number of invitations
- invitations: List of tuples [(name, priority), ...]
Returns:
- List of tuples ... | from solution import process_invitations
def test_process_invitations_example():
input_data = "5\nJane 2\nDavid 3\nAlice 2\nBob 1\nCharlie 3"
expected_output = "Charlie 3\nDavid 3\nAlice 2\nJane 2\nBob 1"
assert process_invitations(input_data) == expected_output
def test_process_invitations_same_priority(... | [
{
"docstring": "Sorts invitations by priority level in descending order,\nand by name in alphabetical order for the same priority level.\n\nParameters:\n- n: int, number of invitations\n- invitations: List of tuples [(name, priority), ...]\n\nReturns:\n- List of tuples [(name, priority), ...] sorted accordingly... | [
1,
1,
0,
1,
1,
0,
1,
1,
1,
0
] | 7 | easy | 0.7 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def sort_invitations(n, invitations):\n \"\"\"\n Sort invitations by priority in descending order, and by name in alphabetical order for the same priority.\n ... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00003738",
"row_id": 3738,
"seed_ids": "[1470]"
} | 0.644947 | Apps_3738 | I | [
"sort_invitations",
"process_invitations"
] | 2 | [
[
"process_invitations",
"sort_invitations"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0f55725a0d367d99a64222bfa736b3f8a34cfec5 | 06c40fba3047d1baf0feb898bc8270d4db60db78 | |||
v1.0 | instruct | Apps | Apps_3779_I | Jenna is an avid gamer who loves grid-based puzzle games. Recently, she has encountered a thrilling new game called "Treasure Grid". In this game, Jenna plays on a 2D grid, and each cell in the grid can contain either an obstacle ('#') or a treasure ('.'). Jenna's goal is to determine the largest rectangular area withi... | def max_histogram_area(histogram):
"""
Calculate the maximum rectangular area in the histogram (a list of non-negative integers).
"""
stack = []
max_area = 0
index = 0
while index < len(histogram):
# Push current bar onto stack if it is higher than bar at stack top
if no... | import pytest
from solution import solve_treasure_grid
def test_example():
test_cases = [([".#..", "#..#", "##.#", "#..#"], 4, 4),
([".##", "##.", "###"], 3, 3)]
expected_results = [4, 1]
assert solve_treasure_grid(test_cases) == expected_results
def test_single_row():
test_cases = ... | [
{
"docstring": "Calculate the maximum rectangular area in the histogram (a list of non-negative integers).",
"function_declaration": "def max_histogram_area(histogram):",
"function_name": "max_histogram_area",
"parameter_list": "(histogram)"
},
{
"docstring": "Calculate the largest rectangul... | [
0,
0,
0,
0,
0,
0,
1,
0,
0
] | 1 | hard | 0.111 | {
"trial_gpt4o_0": null,
"trial_gpt4o_1": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared1_results_combined.jsonl",
"solution_code": "def max_histogram_area(heights):\n stack = []\n max_area = 0\n index = 0\n\n while index < len(heights):\n if not stack ... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00003779",
"row_id": 3779,
"seed_ids": "[1492]"
} | 0.646853 | Apps_3779 | I | [
"max_histogram_area",
"largest_treasure_area",
"solve_treasure_grid"
] | 3 | [
[
"largest_treasure_area",
"max_histogram_area"
],
[
"solve_treasure_grid",
"largest_treasure_area"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | a872faa87734e126f78ff93d3e0db0c9d7ba9a7d | a4953364b65c82a70e84491b5b82e4c3220f6913 | |||
v1.0 | instruct | Apps | Apps_3831_I | You are given a collection of words. You need to determine the number of pairs of these words that form palindromic concatenations.
A palindromic concatenation is defined as a pair of words $(a, b)$ such that the concatenation of $a$ and $b$ (i.e., $a + b$) is a palindrome. Each word can only form pairs with other wor... | def count_palindromic_pairs(words):
"""
Given a list of words, count the number of unique pairs that form palindromic concatenations.
Args:
words (list): List of words.
Returns:
int: Maximum number of unique pairs of words forming palindromic concatenations.
"""
from collections im... | from solution import main
def test_example_1():
input_lines = [
"3",
"5",
"ab",
"ba",
"abc",
"cba",
"abc",
"4",
"aa",
"bb",
"cc",
"dd",
"3",
"rotor",
"motor",
"madam"
]
expected_o... | [
{
"docstring": "Given a list of words, count the number of unique pairs that form palindromic concatenations.\n\nArgs:\nwords (list): List of words.\n\nReturns:\nint: Maximum number of unique pairs of words forming palindromic concatenations.",
"function_declaration": "def count_palindromic_pairs(words):",
... | [
0,
1,
1,
0,
0,
1,
0,
0,
0,
1
] | 4 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def count_palindromic_pairs(words):\n count = 0\n used_words = set()\n word_set = set(words)\n \n for word in words:\n if word in used_words:\... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00003831",
"row_id": 3831,
"seed_ids": "[118]"
} | 0.796503 | Apps_3831 | I | [
"count_palindromic_pairs",
"maximum_palindromic_pairs",
"process_input",
"process_output",
"main"
] | 5 | [
[
"maximum_palindromic_pairs",
"count_palindromic_pairs"
]
] | 1 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | c85f75544c72cdd14f1b1fe70fe2dac475b13bfb | d4c889475efd0327b7caecbee319c9f813be72bd | |||
v1.0 | instruct | Apps | Apps_3849_I | You are given an integer array A of length N. Your task is to find if it is possible to split the array into exactly K non-empty continuous subarrays such that the sum of each subarray is a prime number.
Prime number is a natural number greater than 1 that cannot be formed by multiplying two smaller natural numbers. E... | def is_prime(n):
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
p = 3
while p * p <= n:
if n % p == 0:
return False
p += 2
return True
def can_split_into_k_primes(N, K, A):
# Helper function to compute prefix su... | from solution import can_split_into_k_primes
def test_example_1():
assert can_split_into_k_primes(5, 3, [3, 7, 1, 2, 11]) == "YES"
def test_example_2():
assert can_split_into_k_primes(5, 2, [4, 6, 2, 5, 9]) == "NO"
def test_single_element_prime():
assert can_split_into_k_primes(1, 1, [2]) == "YES"
def t... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def can_split_into_k_primes(N, K, A):",
"function_name": "can_split_into_k_primes",
"parameter_list": "(N, K, A)"... | [
0,
0,
1,
1,
0,
0,
0,
0,
0,
0
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Checks if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num == 2 or num == 3:\n return T... | trial_gpt4o_3 | {
"original_instruction": "",
"prompt_id": "00003849",
"row_id": 3849,
"seed_ids": "[2291]"
} | 0.663096 | Apps_3849 | I | [
"is_prime",
"can_split_into_k_primes",
"main"
] | 3 | [
[
"can_split_into_k_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 63731e226d693de02c3ad353f12e2c78e1aaff9b | eee7b8826c0c7b98bd9089388225b1b3981a4f42 | |||
v1.0 | instruct | Apps | Apps_3871_I | Alex is learning about binary trees. He came across a problem where he needs to determine the maximum sum of nodes for any path in a binary tree. A path in a binary tree is a sequence of nodes where each pair of adjacent nodes in the sequence has an edge connecting them. A path can start and end at any node in the tree... | class TreeNode:
def __init__(self, value=0):
self.value = value
self.left = None
self.right = None
def find_maximum_path_sum(root):
def helper(node):
nonlocal max_sum
if not node:
return 0
left_max = max(helper(node.left), 0)
right_max = max(h... | from solution import max_sum_for_all_cases, build_tree_from_edges, find_maximum_path_sum
def test_case_1():
num_cases = 2
cases = [
(5, [4, -10, 3, 5, 2], [(1, 2), (1, 3), (3, 4), (3, 5)]),
(3, [1, 2, 3], [(1, 2), (1, 3)])
]
assert max_sum_for_all_cases(num_cases, cases) == [12, 6]
def... | [] | [
0,
0,
0,
0,
0,
1,
0,
0,
0,
1
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "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 maxPathS... | trial_gpt4o_5 | {
"original_instruction": "",
"prompt_id": "00003871",
"row_id": 3871,
"seed_ids": "[1536]"
} | 0.705913 | Apps_3871 | I | [
"find_maximum_path_sum",
"build_tree_from_edges",
"max_sum_for_all_cases"
] | 3 | [
[
"max_sum_for_all_cases",
"build_tree_from_edges"
],
[
"max_sum_for_all_cases",
"find_maximum_path_sum"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 1e799861a695fea38fa6083841b44cbc6684d152 | c90b5ece63a8cb25a41d33de308de60cdd36a3bd | |||
v1.0 | instruct | Apps | Apps_3983_I | Write a function that takes an array of integers and returns a new array containing only the prime numbers from the original array. If no prime numbers are found, the function should return an empty array.
The function should filter the list in such a way that preserves the original order of the elements that are pri... | def is_prime(num):
"""
Helper function to determine if a number is prime.
"""
if num <= 1:
return False
if num == 2:
return True
if num % 2 == 0:
return False
for i in range(3, int(num**0.5) + 1, 2):
if num % i == 0:
return False
return True
d... | from solution import is_prime, filter_primes
def test_is_prime():
assert not is_prime(-1)
assert not is_prime(0)
assert not is_prime(1)
assert is_prime(2)
assert is_prime(3)
assert not is_prime(4)
assert is_prime(5)
assert not is_prime(9)
assert is_prime(37)
assert not is_prime(... | [
{
"docstring": "Helper function to determine if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Return a new array containing only the prime numbers from the original array.",
"function_declarati... | [
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(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_9 | {
"original_instruction": "",
"prompt_id": "00003983",
"row_id": 3983,
"seed_ids": "[3127]"
} | 0.671146 | Apps_3983 | I | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | df8c304c0d3b1a6420dddf14cd581fa8a9032a76 | fb91e35cb2570dfe1fe11bdfd821a10d2619cbdd | |||
v1.0 | instruct | Apps | Apps_4034_I | You are given a matrix of dimensions n x m filled with non-negative integers. Your goal is to find the maximum sum of the elements in one contiguous submatrix. A submatrix is defined as a rectangular array of numbers obtained by selecting a contiguous block from the original matrix.
Write a program that, given the dim... | def max_submatrix_sum(matrix):
"""
Given a 2D matrix, finds the maximum sum of any contiguous submatrix.
"""
n = len(matrix)
m = len(matrix[0])
max_sum = float('-inf')
for left in range(m):
tmp = [0] * n
for right in range(left, m):
for i in range(n):
... | from solution import max_submatrix_sum
def test_example_case():
matrix = [
[1, 2, -1, -4, -20],
[-8, -3, 4, 2, 1],
[3, 8, 10, 1, 3],
[-4, -1, 1, 7, -6]
]
assert max_submatrix_sum(matrix) == 29
def test_single_element():
matrix = [[-50]]
assert max_submatrix_sum(matr... | [
{
"docstring": "Given a 2D matrix, finds the maximum sum of any contiguous submatrix.",
"function_declaration": "def max_submatrix_sum(matrix):",
"function_name": "max_submatrix_sum",
"parameter_list": "(matrix)"
},
{
"docstring": "Helper function to apply Kadane's algorithm on 1D array to f... | [
0,
1,
1,
0,
1,
1,
1,
0,
0,
0
] | 5 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def maximum_submatrix_sum(matrix):\n \"\"\"\n Returns the maximum sum of the elements in any contiguous submatrix of the given matrix.\n \"\"\"\n def ka... | trial_gpt4o_6 | {
"original_instruction": "",
"prompt_id": "00004034",
"row_id": 4034,
"seed_ids": "[58]"
} | 0.677508 | Apps_4034 | I | [
"max_submatrix_sum",
"kadane"
] | 2 | [
[
"max_submatrix_sum",
"kadane"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | dbe5f8e412bcfcbede77a107141bfcecb2ecab5c | 9c24fe11c2f0e48ce7a7a3d57c071d8a36b5e547 | |||
v1.0 | instruct | Apps | Apps_4054_I | A new roller coaster is being built in the amusement park. The challenge is to design the height pattern of the rails such that they make the ride thrilling. The height pattern should mimic a 'mountain range'. Let's break it down:
- The rail height should start at 1, increase to a peak, and should again decrease back ... | def is_valid_mountain(heights):
n = len(heights)
if n < 3 or heights[0] != 1 or heights[-1] != 1:
return "invalid"
peak_found = False
for i in range(1, n):
if peak_found:
if heights[i] > heights[i-1]:
return "invalid"
else:
if heights[i] ... | def test_is_valid_mountain_valid():
assert is_valid_mountain([1, 2, 3, 2, 1]) == "valid"
assert is_valid_mountain([1, 2, 4, 2, 1]) == "valid"
def test_is_valid_mountain_invalid():
assert is_valid_mountain([1, 1, 1, 2, 1, 1]) == "invalid"
assert is_valid_mountain([1, 2, 1, 2]) == "invalid"
assert is... | [
{
"docstring": null,
"function_declaration": "def is_valid_mountain(heights):",
"function_name": "is_valid_mountain",
"parameter_list": "(heights)"
},
{
"docstring": null,
"function_declaration": "def validate_rails(R, rails):",
"function_name": "validate_rails",
"parameter_list"... | [
0,
0,
0,
0,
1,
0,
0,
0,
0,
1
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def check_mountain_range_patterns(R, patterns):\n results = []\n \n for pattern in patterns:\n N, heights = pattern\n if heights[0] != 1 or h... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00004054",
"row_id": 4054,
"seed_ids": "[1019]"
} | 0.641403 | Apps_4054 | I | [
"is_valid_mountain",
"validate_rails"
] | 2 | [
[
"validate_rails",
"is_valid_mountain"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 4e9c9b4e17d15647ce4b61d45df7e4351945787a | edb21d1b52e87b0f5ed9e4d8a6a38c261034bf1b | |||
v1.0 | instruct | Apps | Apps_4074_I | Consider Alice wanting to find prime numbers in a certain range to help her in a cryptography project. She needs your help to count the number of prime numbers in a given range.
Within a given range, prime numbers are those that have no divisors other than 1 and themselves, and they must be greater than 1.
A prime nu... | def sieve_of_eratosthenes(max_range):
sieve = [True] * (max_range + 1)
sieve[0] = sieve[1] = False # 0 and 1 are not prime
p = 2
while (p * p <= max_range):
if (sieve[p] == True):
for i in range(p * p, max_range + 1, p):
sieve[i] = False
p += 1
return siev... | from solution import count_primes_in_range
def test_count_primes_single_case():
assert count_primes_in_range(1, [(1, 10)]) == [4]
def test_count_primes_multiple_cases():
assert count_primes_in_range(3, [(1, 10), (11, 20), (21, 30)]) == [4, 4, 2]
def test_count_primes_in_large_range():
assert count_primes... | [
{
"docstring": null,
"function_declaration": "def sieve_of_eratosthenes(max_range):",
"function_name": "sieve_of_eratosthenes",
"parameter_list": "(max_range)"
},
{
"docstring": null,
"function_declaration": "def prime_count_in_range(L, R, sieve):",
"function_name": "prime_count_in_r... | [
0,
0,
0,
1,
0,
0,
1,
0
] | 2 | hard | 0.25 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def sieve_of_eratosthenes(max_num):\n is_prime = [True] * (max_num + 1)\n is_prime[0], is_prime[1] = False, False\n\n for start in range(2, int(max_num**0.... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00004074",
"row_id": 4074,
"seed_ids": "[1394]"
} | 0.665817 | Apps_4074 | I | [
"sieve_of_eratosthenes",
"prime_count_in_range",
"count_primes_in_range"
] | 3 | [
[
"count_primes_in_range",
"prime_count_in_range"
],
[
"count_primes_in_range",
"sieve_of_eratosthenes"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 9e7b475c7e28989802b8609bdee00bbf46c6252c | 62519a3809fd01ed223e9bc7903bf7dbdcf51b85 | |||
v1.0 | instruct | Apps | Apps_4122_I | Ravi loves playing with numbers. He came across a game where he has to find the smallest positive integer that is a multiple of a given number 'X' and also forms a palindrome when written in decimal notation. Ravi needs your help to solve this problem efficiently.
-----Input:-----
- The first line of the input contain... | def is_palindrome(n):
"""
Check if a given number n is a palindrome.
"""
return str(n) == str(n)[::-1]
def smallest_palindrome_multiple(x):
"""
Find the smallest positive integer that is a multiple of x and a palindrome.
"""
i = 1
while True:
if is_palindrome(i) and i % x ==... | from solution import solve
def test_sample():
T = 2
test_cases = [1, 5]
assert solve(T, test_cases) == [1, 5]
def test_single_digit_palindromes():
T = 5
test_cases = [1, 2, 3, 4, 5]
assert solve(T, test_cases) == [1, 2, 3, 4, 5]
def test_larger_palindromes():
T = 2
test_cases = [11, 2... | [
{
"docstring": "Check if a given number n is a palindrome.",
"function_declaration": "def is_palindrome(n):",
"function_name": "is_palindrome",
"parameter_list": "(n)"
},
{
"docstring": "Find the smallest positive integer that is a multiple of x and a palindrome.",
"function_declaration"... | [
0,
0,
0,
0,
1,
0,
0,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome(n):\n \"\"\"\n Check if a given integer is a palindrome.\n \"\"\"\n num_str = str(n)\n return num_str == num_str[::-1]\n\ndef small... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00004122",
"row_id": 4122,
"seed_ids": "[591]"
} | 0.777386 | Apps_4122 | I | [
"is_palindrome",
"smallest_palindrome_multiple",
"solve"
] | 3 | [
[
"smallest_palindrome_multiple",
"is_palindrome"
],
[
"solve",
"smallest_palindrome_multiple"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 050f53ef90c151d421130212ad9be0a36aefb55a | 5baf371216429bf0d9bac5947a223d64985256d7 | |||
v1.0 | instruct | Apps | Apps_4131_I | Henry the Wi-Fi hacker has another challenge for you. Given a list of Wi-Fi networks represented by their signal strengths, he wants to determine the longest consecutive sequence of networks with strictly increasing signal strengths. However, this time he wants you to find the longest sequence that has a prime length.
... | def is_prime(n):
"""Check if an integer n is a prime number."""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return T... | from solution import longest_prime_length_increasing_subsequence
def test_longest_prime_length_increasing_subsequence():
assert longest_prime_length_increasing_subsequence([3, 2, 1, 2, 3, 5, 6, 4, 1, 2, 3]) == 5
assert longest_prime_length_increasing_subsequence([1, 2, 3, 4, 5, 6, 7, 8, 9]) == 7 # [1, 2, 3, 4... | [
{
"docstring": "Check if an integer n is a prime number.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns the length of the longest strictly increasing subsequence with a prime length.",
"function_declaration": ... | [
1,
0,
1,
0,
0,
0,
0,
0,
0,
0
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"Check if an integer n is a prime number.\"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00004131",
"row_id": 4131,
"seed_ids": "[780]"
} | 0.564869 | Apps_4131 | I | [
"is_prime",
"longest_prime_length_increasing_subsequence"
] | 2 | [
[
"longest_prime_length_increasing_subsequence",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 28e856386b62c5ff0c02151edeb561181a540331 | d6230614bed4b0f74174bc3ac0dc40cf9035c2cd | |||
v1.0 | instruct | Apps | Apps_4145_I | Write a function that takes an array of positive integers and returns an array where each element is replaced by the sum of its digits raised to the power of its position in the array (0-indexed). For example, given the input array `[3, 25, 18]`, the output should be `[3^0, (2+5)^1, (1+8)^2]` which evaluates to `[1, 7,... | def sum_of_digits(num):
"""
Returns the sum of the digits of the given number.
"""
return sum(int(digit) for digit in str(num))
def transform_array(arr):
"""
Transforms the given array according to the described rule:
Each element at index i is replaced by the sum of its digits raised to th... | from solution import transform_array
def test_single_element():
assert transform_array([3]) == [1]
def test_two_elements():
assert transform_array([3, 25]) == [1, 7]
def test_three_elements():
assert transform_array([3, 25, 18]) == [1, 7, 81]
def test_empty_list():
assert transform_array([]) == []
... | [
{
"docstring": "Returns the sum of the digits of the given number.",
"function_declaration": "def sum_of_digits(num):",
"function_name": "sum_of_digits",
"parameter_list": "(num)"
},
{
"docstring": "Transforms the given array according to the described rule:\nEach element at index i is repla... | [
0,
0,
0,
0,
0,
0,
0,
0,
1,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def sum_of_digits_power(arr):\n \"\"\"\n This function takes an array of positive integers and returns an array\n where each element is replaced by the sum... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00004145",
"row_id": 4145,
"seed_ids": "[3303]"
} | 0.58501 | Apps_4145 | I | [
"sum_of_digits",
"transform_array"
] | 2 | [
[
"transform_array",
"sum_of_digits"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a72447ad941af57de3641c76b46765620c25469c | 4e4cad8a17a97b34dcca59c79d0abd993da17b69 | |||
v1.0 | instruct | Apps | Apps_4192_I | Villager Jenny has a garden with a collection of enchanted mushrooms arranged in a grid. The grid has `N` rows and `M` columns, and each cell of the grid contains a certain number of magical spores. Jenny wants to find out the total number of spores in specific subgrids from her garden.
To help her, write a program to... | def preprocess_grid(grid):
N = len(grid)
M = len(grid[0])
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 pre... | import pytest
def test_preprocess_grid():
grid = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
expected = [
[0, 0, 0, 0],
[0, 1, 3, 6],
[0, 5, 12, 21],
[0, 12, 27, 45]
]
assert preprocess_grid(grid) == expected
def test_query_sum():
prefix_sum = ... | [
{
"docstring": null,
"function_declaration": "def preprocess_grid(grid):",
"function_name": "preprocess_grid",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def query_sum(prefix_sum, r1, c1, r2, c2):",
"function_name": "query_sum",
"parameter_list": ... | [
0,
1,
0,
1,
1,
1,
1,
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 preload_prefix_sum(grid):\n \"\"\"\n Calculate the prefix sum matrix for the given grid.\n \"\"\"\n N = len(grid)\n M = len(grid[0])\n prefix_... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00004192",
"row_id": 4192,
"seed_ids": "[1496]"
} | 0.702205 | Apps_4192 | I | [
"preprocess_grid",
"query_sum",
"solve"
] | 3 | [
[
"solve",
"preprocess_grid"
],
[
"solve",
"query_sum"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | b28e4378823f5e59b7630531dfa0073149dcf5a1 | 02b73eb58299ecdfbbc1ae8e6e7145fab85154c1 | |||
v1.0 | instruct | Apps | Apps_4201_I | Alice loves playing with numbers and she came up with a puzzle game. She gives her friends a list of integers and challenges them to find the maximum sum of a subsequence with the constraint that no two elements in the subsequence should be adjacent in the original list. Your task is to implement a function that takes ... | def max_non_adjacent_sum(nums):
"""
Returns the maximum sum of a subsequence such that no two elements are adjacent.
"""
if not nums:
return 0
incl = 0 # Max sum including the previous element
excl = 0 # Max sum excluding the previous element
for num in nums:
# Cu... | from solution import max_non_adjacent_sum, solve_problem
def test_max_non_adjacent_sum_example():
assert solve_problem(6, [3, 2, 5, 10, 7]) == 15
def test_max_non_adjacent_sum_small():
assert solve_problem(3, [1, 2, 3]) == 4
def test_max_non_adjacent_sum_all_positive():
assert solve_problem(4, [4, 1, 2, ... | [
{
"docstring": "Returns the maximum sum of a subsequence such that no two elements are adjacent.",
"function_declaration": "def max_non_adjacent_sum(nums):",
"function_name": "max_non_adjacent_sum",
"parameter_list": "(nums)"
},
{
"docstring": null,
"function_declaration": "def solve_pro... | [
1,
0,
0,
0,
1,
0,
0,
0,
0,
1
] | 3 | hard | 0.3 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_non_adjacent_sum(nums):\n \"\"\"\n Returns the maximum sum of a subsequence such that no two elements are adjacent.\n \"\"\"\n if not nums:\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00004201",
"row_id": 4201,
"seed_ids": "[1280]"
} | 0.766036 | Apps_4201 | I | [
"max_non_adjacent_sum",
"solve_problem"
] | 2 | [
[
"solve_problem",
"max_non_adjacent_sum"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a2e09d679f72cc6f8c32e408ddcb07fc8b79c876 | b78964bb7465240ef70d1b01e6dc573a4f0c1f34 | |||
v1.0 | instruct | Apps | Apps_4208_I | =====Problem Statement=====
You are given a list of integers which may contain some duplicate elements. Your task is to find and print all unique subsets of the given list.
A subset is a collection of elements that can be derived from the list by deleting some or none of the elements without changing the order of the ... | def find_unique_subsets(arr):
"""
Returns all unique subsets of the given list in lexicographical order.
"""
def backtrack(start, path):
result.append(path[:])
for i in range(start, len(arr)):
if i > start and arr[i] == arr[i - 1]:
continue
path.ap... | from solution import find_unique_subsets, format_subsets_for_output, unique_subsets
def test_find_unique_subsets_empty():
assert find_unique_subsets([]) == [[]]
def test_find_unique_subsets_no_duplicates():
assert find_unique_subsets([1, 2, 3]) == [
[],
[1],
[1, 2],
[1, 2, 3],
... | [
{
"docstring": "Returns all unique subsets of the given list in lexicographical order.",
"function_declaration": "def find_unique_subsets(arr):",
"function_name": "find_unique_subsets",
"parameter_list": "(arr)"
},
{
"docstring": "Converts each subset into a string in the form of space-separ... | [
1,
0,
0,
1,
0,
1,
1,
0,
1,
1
] | 6 | medium | 0.6 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from itertools import combinations\n\ndef unique_subsets(arr):\n \"\"\"\n Returns all unique subsets of the given list of integers.\n The subsets are retur... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00004208",
"row_id": 4208,
"seed_ids": "[2575]"
} | 0.60482 | Apps_4208 | I | [
"find_unique_subsets",
"format_subsets_for_output",
"unique_subsets"
] | 3 | [
[
"unique_subsets",
"find_unique_subsets"
],
[
"unique_subsets",
"format_subsets_for_output"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 8839896adada8aeccb24abb39598fb2b4c96df12 | 6ec4de83f774f5d1861db60cc9a415c0cad462bf |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.