version stringclasses 1
value | style stringclasses 2
values | subset stringclasses 12
values | question_id stringlengths 9 23 | question stringlengths 27 8.13k | solution stringlengths 99 5.97k | test stringlengths 105 4.45k | test_info listlengths 0 13 | gpt_pass_sequence listlengths 1 10 | gpt_pass_trial_num int64 1 10 | gpt_difficulty stringclasses 3
values | gpt_pass_percentage float64 0.1 1 | trials dict | chosen_trial stringclasses 10
values | metadata dict | benchmark_similarity float64 0.16 0.93 | benchmark_instruction stringclasses 1
value | benchmark_task_id stringclasses 1
value | filter_reason stringclasses 1
value | base_id stringlengths 7 21 | variant stringclasses 2
values | top_function_names listlengths 2 13 | n_top_functions int64 2 13 | helper_call_edges listlengths 1 16 | n_helper_call_edges int64 1 16 | harness_functions listlengths 0 3 | structural_wrapper bool 1
class | class_names listlengths 0 5 | has_class bool 2
classes | test_kind stringclasses 1
value | test_has_solution_import bool 2
classes | third_party_imports listlengths 0 5 | stdlib_only bool 2
classes | question_norm_sha1 stringlengths 40 40 | solution_ast_sha1 stringlengths 40 40 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
v1.0 | complete | Code_Contests | Code_Contests_13536_C | import json
from datetime import datetime
from typing import List
def parse_log_entry(entry: str) -> dict:
"""
Parses a single log entry and returns a dictionary with timestamp, level, and message keys.
"""
pass
def log_level_to_number(level: str) -> int:
"""
Converts a log level to a number f... | import json
from datetime import datetime
def parse_log_entry(entry):
"""
Parses a single log entry and returns a dictionary with timestamp, level, and message keys.
"""
time, level, message = entry.split('] ', 2)
timestamp = time.strip('[')
level = level.strip('[').strip(']')
return {
... | from solution import filter_logs
def test_info_level():
n = 3
min_level = "INFO"
logs = [
"[2023-01-01 08:00:00] [INFO] Info log entry",
"[2023-01-01 09:00:00] [WARN] Warning log entry",
"[2023-01-01 10:00:00] [ERROR] Error log entry"
]
expected_output = json.dumps([
... | [
{
"docstring": "Parses a single log entry and returns a dictionary with timestamp, level, and message keys.",
"function_declaration": "def parse_log_entry(entry):",
"function_name": "parse_log_entry",
"parameter_list": "(entry)"
},
{
"docstring": "Converts a log level to a number for easy co... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import json\nfrom datetime import datetime\n\nLOG_LEVELS = {\"INFO\": 1, \"WARN\": 2, \"ERROR\": 3}\n\ndef parse_log_file(n, min_level, log_entries):\n ... | trial_gpt4o_1 | {
"original_instruction": "You are working on a project that requires parsing a log file to extract and format specific information. The log file contains entries with timestamps, log levels, and messages. The task is to format these entries into structured JSON objects based on a given set of filtering criteria.\n\n... | 0.755019 | Code_Contests_13536 | C | [
"parse_log_entry",
"log_level_to_number",
"filter_logs"
] | 3 | [
[
"filter_logs",
"log_level_to_number"
],
[
"filter_logs",
"parse_log_entry"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 851588c11bcf74412cfe2e543dd7af67d8116d8b | 6127748920cf5f983dc692da20ee8ed7b2df8205 | |||
v1.0 | complete | Code_Contests | Code_Contests_21215_C | def tournament_ranking(input_data: str) -> str:
""" Calculates the ranking of teams based on their scores in the tournament.
The input consists of multiple datasets describing teams, their matches, and scores.
For each dataset, print the final ranking of the teams in descending order of points.
In case ... | def calculate_ranking(input_data):
def parse_input(input_data):
data = input_data.strip().split('\n')
datasets = []
i = 0
while i < len(data):
N, M = map(int, data[i].split())
if N == 0 and M == 0:
break
i += 1
teams = {... | import pytest
from solution import tournament_ranking
def test_tournament_ranking_example1():
input_data = "3 3\nTeamA 0\nTeamB 0\nTeamC 0\nTeamA TeamB 2 1\nTeamB TeamC 0 0\nTeamA TeamC 1 1\n0 0\n"
expected_output = "TeamA\nTeamC\nTeamB"
assert tournament_ranking(input_data) == expected_output
def test_to... | [
{
"docstring": null,
"function_declaration": "def calculate_ranking(input_data):",
"function_name": "calculate_ranking",
"parameter_list": "(input_data)"
},
{
"docstring": null,
"function_declaration": "def format_output(results):",
"function_name": "format_output",
"parameter_li... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def rank_teams(datasets):\n results = []\n \n for dataset in datasets:\n teams = {}\n matches = dataset['matches']\n \n ... | trial_gpt4o_1 | {
"original_instruction": "The soccer league is organizing a tournament with teams from different regions. Each team will play multiple matches throughout the tournament, and each match will yield a score. Your task is to write a program that calculates the ranking of teams based on their scores.\n\nEach match played... | 0.678109 | Code_Contests_21215 | C | [
"calculate_ranking",
"format_output",
"tournament_ranking"
] | 3 | [
[
"tournament_ranking",
"calculate_ranking"
],
[
"tournament_ranking",
"format_output"
]
] | 2 | [
"format_output"
] | false | [] | false | pytest | true | [] | true | 4670cdca851c4f02a196912d843ab05afaea56cc | e15cce5cc328115663a2e427215d5155e4667a61 | |||
v1.0 | complete | Code_Contests | Code_Contests_21631_C | def find_optimal_hub_city(N: int, M: int, city_roads: List[Tuple[int, int, int]]) -> int:
"""
Determine the optimal central city such that the maximum distance from the central city to all other cities is minimized.
Args:
N (int): Number of cities.
M (int): Number of roads.
city_roads (List... | import heapq
def compute_distances(N, roads, start):
distances = [float('inf')] * N
distances[start] = 0
priority_queue = [(0, start)]
while priority_queue:
current_distance, u = heapq.heappop(priority_queue)
if current_distance > distances[u]:
continue
... | def test_find_optimal_hub_city():
assert find_optimal_hub_city(5, 5, [
(1,2,3), (1,3,2), (2,4,4), (3,4,1), (4,5,2)
]) == 4
assert find_optimal_hub_city(7, 8, [
(1,2,5), (1,3,2), (3,4,1), (3,5,4), (2,4,3), (2,6,6), (5,7,2), (6,7,1)
]) == 3
assert find_optimal_hub_city(3, 3, [
... | [
{
"docstring": null,
"function_declaration": "def compute_distances(N, roads, start):",
"function_name": "compute_distances",
"parameter_list": "(N, roads, start)"
},
{
"docstring": null,
"function_declaration": "def find_optimal_hub_city(N, M, city_roads):",
"function_name": "find_o... | [
0,
0,
0,
1,
1
] | 2 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\nimport sys\n\ndef dijkstra(n, start, adj):\n distances = [sys.maxsize] * (n + 1)\n distances[start] = 0\n pq = [(0, start)]\n \n ... | trial_gpt4o_3 | {
"original_instruction": "A large island nation consists of a network of cities connected by roads. The ruler of this nation wants to ensure that each city is prepared for any possible emergencies. A strategic plan needs to be developed so that each city can be reached from a designated central city in the shortest ... | 0.690515 | Code_Contests_21631 | C | [
"compute_distances",
"find_optimal_hub_city"
] | 2 | [
[
"find_optimal_hub_city",
"compute_distances"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 2b979fe3c91404f45560b08e18b595a941f1f16f | 4238f032be4ad13ef0d5cc6c4220afe89bd3d1fa | |||
v1.0 | complete | Code_Contests | Code_Contests_21358_C | def sum_of_digits(n):
"""
Returns the sum of digits of n.
"""
pass
def is_prime(n):
"""
Determines if a number n is prime.
"""
pass
def generate_prime_series(N):
"""
Generates the series of numbers starting with prime N, continuously
adding the sum of its digits until the n... | def sum_of_digits(n):
"""
Returns the sum of digits of n.
"""
return sum(int(digit) for digit in str(n))
def is_prime(n):
"""
Determines if a number n is prime.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
... | def test_sum_of_digits():
assert sum_of_digits(123) == 6
assert sum_of_digits(0) == 0
assert sum_of_digits(987) == 24
def test_is_prime():
assert is_prime(2) == True
assert is_prime(4) == False
assert is_prime(13) == True
assert is_prime(1) == False
assert is_prime(17) == True
def test... | [
{
"docstring": "Returns the sum of digits of n.",
"function_declaration": "def sum_of_digits(n):",
"function_name": "sum_of_digits",
"parameter_list": "(n)"
},
{
"docstring": "Determines if a number n is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime"... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def 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 Fal... | trial_gpt4o_2 | {
"original_instruction": "Ravi is a computer scientist who loves prime numbers. One day, he came across an interesting series of numbers while researching prime patterns. The series is constructed by taking a prime number and continuously adding the sum of its digits until the number is no longer prime. Ravi decided... | 0.689459 | Code_Contests_21358 | C | [
"sum_of_digits",
"is_prime",
"generate_prime_series"
] | 3 | [
[
"generate_prime_series",
"is_prime"
],
[
"generate_prime_series",
"sum_of_digits"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 704e3a1f3e62c91e77ba9ecd193f3bac7c242b61 | e1df8ed815f5d6995e30709df8d843a9bce4c39a | |||
v1.0 | complete | Code_Contests | Code_Contests_20899_C | def spiralOrder(matrix):
"""
Returns a list of elements of the matrix in spiral order.
>>> spiralOrder([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
[1, 2, 3, 6, 9, 8, 7, 4, 5]
>>> spiralOrder([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]])
[1, 2, 3, 6, 9, 12, 11, 10, 7, 4, 5, 8]
>>> spiralOrder(... | def spiralOrder(matrix):
"""
Returns a list of elements of the matrix in spiral order.
"""
res = []
while matrix:
res += matrix.pop(0)
if matrix and matrix[0]:
for row in matrix:
res.append(row.pop())
if matrix:
res += matrix.pop()[::-1... | from solution import spiralOrder, matrix_input, spiral_matrix_input
def test_spiralOrder_square_matrix():
matrix = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
assert spiralOrder(matrix) == [1, 2, 3, 6, 9, 8, 7, 4, 5]
def test_spiralOrder_rectangular_matrix():
matrix = [
[1, 2, ... | [
{
"docstring": "Returns a list of elements of the matrix in spiral order.",
"function_declaration": "def spiralOrder(matrix):",
"function_name": "spiralOrder",
"parameter_list": "(matrix)"
},
{
"docstring": null,
"function_declaration": "def matrix_input(m, n, elements):",
"function_... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def spiralOrder(matrix):\n \"\"\"\n Returns the elements of the matrix in spiral order.\n \"\"\"\n if not matrix:\n return []\n \n ... | trial_gpt4o_2 | {
"original_instruction": "A: Spiral Matrix Traversal\n\nproblem\n\nGiven an m x n matrix, return all elements of the matrix in spiral order. The matrix traversal starts from the top left corner and follows a spiral pattern towards the center in a clockwise manner.\n\nInput format\n\nThe input will begin with two int... | 0.590268 | Code_Contests_20899 | C | [
"spiralOrder",
"matrix_input",
"spiral_matrix_input"
] | 3 | [
[
"spiral_matrix_input",
"matrix_input"
],
[
"spiral_matrix_input",
"spiralOrder"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 083d6f1ae68b64a1243a6d02811f8c000d4f5f81 | bb35bbf0d991425306f8751279b5767056fef84a | |||
v1.0 | complete | Code_Contests | Code_Contests_21657_C | def evaluate_expression(expression: str) -> float:
""" Evaluates the given mathematical expression and returns the result.
>>> evaluate_expression('1 + 2') == 3
>>> evaluate_expression('4 * 5') == 20
>>> evaluate_expression('3 - 2') == 1
>>> evaluate_expression('5 / 5') == 1.0
>>> evaluate_expre... | def evaluate_expression(expression):
"""
Evaluates the given mathematical expression and returns the result.
"""
return eval(expression)
def sort_expressions(expressions):
"""
Sorts the given list of expressions based on their evaluated result.
If two expressions evaluate to the same value,... | from solution import evaluate_expression, sort_expressions, sort_expressions_in_test_cases
def test_evaluate_expression():
assert evaluate_expression('1 + 2') == 3
assert evaluate_expression('4 * 5') == 20
assert evaluate_expression('3 - 2') == 1
assert evaluate_expression('5 / 5') == 1.0
assert ev... | [
{
"docstring": "Evaluates the given mathematical expression and returns the result.",
"function_declaration": "def evaluate_expression(expression):",
"function_name": "evaluate_expression",
"parameter_list": "(expression)"
},
{
"docstring": "Sorts the given list of expressions based on their... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def sort_expressions(test_cases):\n results = []\n \n for test_case in test_cases:\n evaluated_expressions = [(expr, eval(expr)) for expr i... | trial_gpt4o_1 | {
"original_instruction": "You are given a list of strings representing mathematical expressions composed of addition, subtraction, multiplication, division, and parentheses. Your task is to sort these expressions based on their evaluated results in ascending order. If two expressions evaluate to the same result, mai... | 0.570008 | Code_Contests_21657 | C | [
"evaluate_expression",
"sort_expressions",
"sort_expressions_in_test_cases"
] | 3 | [
[
"sort_expressions",
"evaluate_expression"
],
[
"sort_expressions_in_test_cases",
"sort_expressions"
]
] | 2 | [
"sort_expressions_in_test_cases"
] | false | [] | false | pytest | true | [] | true | 8a6a0e1aa2aab6a35ef032459beb389a2bd7b1cd | 6a309e94f017e04db08be7aa0044ee9737898af0 | |||
v1.0 | complete | Code_Contests | Code_Contests_21578_C | from typing import List
def calculate_levenshtein_distance(word1: str, word2: str) -> int:
"""
Calculates the Levenshtein distance between two words.
>>> calculate_levenshtein_distance("kitten", "sitting") == 3
>>> calculate_levenshtein_distance("flaw", "lawn") == 2
>>> calculate_levenshtein_distan... | def calculate_levenshtein_distance(word1, word2):
"""
Calculates the Levenshtein distance between two words.
"""
len1, len2 = len(word1), len(word2)
dp = [[0] * (len2 + 1) for _ in range(len1 + 1)]
for i in range(len1 + 1):
for j in range(len2 + 1):
if i == 0:
... | from solution import calculate_levenshtein_distance, correct_spelling
def test_calculate_levenshtein_distance():
assert calculate_levenshtein_distance("kitten", "sitting") == 3
assert calculate_levenshtein_distance("flaw", "lawn") == 2
assert calculate_levenshtein_distance("algorithm", "altruistic") == 6
... | [
{
"docstring": "Calculates the Levenshtein distance between two words.",
"function_declaration": "def calculate_levenshtein_distance(word1, word2):",
"function_name": "calculate_levenshtein_distance",
"parameter_list": "(word1, word2)"
},
{
"docstring": "Corrects the spelling of words in the... | [
0,
0,
0,
1,
1
] | 2 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def edit_distance(word1, word2):\n m, n = len(word1), len(word2)\n dp = [[0] * (n + 1) for _ in range(m + 1)]\n\n for i in range(m + 1):\n ... | trial_gpt4o_4 | {
"original_instruction": "Implement a **spelling checker** that attempts to correct misspelled words in a text. The checker should use a provided dictionary of correctly spelled words to find the most likely correction.\n\nFor each misspelled word in the text, the spelling checker should choose the correction that h... | 0.629214 | Code_Contests_21578 | C | [
"calculate_levenshtein_distance",
"correct_spelling"
] | 2 | [
[
"correct_spelling",
"calculate_levenshtein_distance"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 473cd6a9ea06c069a530456a4f4911f544a92983 | 51dd05f0c937a4d7eb86b1c0820e5a09e8c9538a | |||
v1.0 | complete | Code_Contests | Code_Contests_21705_C | def generate_primes_up_to(n):
""" Generate a list of primes up to n using the Sieve of Eratosthenes """
sieve = [True] * (n + 1)
sieve[0] = sieve[1] = False
for start in range(2, int(n**0.5) + 1):
if sieve[start]:
for multiple in range(start*start, n+1, start):
sieve[... | def generate_primes_up_to(n):
""" Generate a list of primes up to n using the Sieve of Eratosthenes """
sieve = [True] * (n + 1)
sieve[0] = sieve[1] = False
for start in range(2, int(n**0.5) + 1):
if sieve[start]:
for multiple in range(start*start, n+1, start):
sieve[... | from solution import prime_gaps
def test_example_case():
t = 4
queries = [(2, 10), (10, 20), (20, 30), (100, 110)]
assert prime_gaps(t, queries) == [2, 4, 6, 4]
def test_single_query():
t = 1
queries = [(2, 10)]
assert prime_gaps(t, queries) == [2]
def test_no_primes_in_range():
t = 1
... | [
{
"docstring": "Generate a list of primes up to n using the Sieve of Eratosthenes ",
"function_declaration": "def generate_primes_up_to(n):",
"function_name": "generate_primes_up_to",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def prime_gaps(t, queries):",
... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def generate_primes_up_to(n):\n \"\"\" Generate a list of primes up to n using the Sieve of Eratosthenes \"\"\"\n sieve = [True] * (n + 1)\n sieve... | trial_gpt4o_0 | {
"original_instruction": "Tom is fascinated by prime numbers and is particularly interested in prime gaps - the difference between two successive prime numbers. He is curious to find the longest gap between consecutive prime numbers within a given range. Could you help him with this?\n\nTom will provide you with mul... | 0.622963 | Code_Contests_21705 | C | [
"generate_primes_up_to",
"prime_gaps"
] | 2 | [
[
"prime_gaps",
"generate_primes_up_to"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 46095524d131599e273a02e263d69194343dec15 | 89adaa1c68d7c957f5924b83250de6e4cbaf3998 | |||
v1.0 | complete | Code_Contests | Code_Contests_21293_C | import math
from typing import List, Tuple
def euclidean_distance(city1: Tuple[int, int], city2: Tuple[int, int]) -> float:
""" Calculate the Euclidean distance between two cities with coordinates city1 and city2.
city1: Tuple[int, int] - coordinates of the first city.
city2: Tuple[int, int] - coordinates ... | import math
def read_input():
import sys
input = sys.stdin.read
data = input().split()
N = int(data[0])
cities = []
for i in range(1, len(data), 2):
cities.append((int(data[i]), int(data[i+1])))
return N, cities
def euclidean_distance(city1, city2):
return math.sqrt((city2[0] -... | from solution import euclidean_distance, find_nearest_city, calculate_total_distance
def test_euclidean_distance():
assert euclidean_distance((0, 0), (0, 1)) == 1.0
assert euclidean_distance((0, 0), (1, 0)) == 1.0
assert euclidean_distance((0, 0), (1, 1)) == math.sqrt(2)
def test_find_nearest_city():
... | [
{
"docstring": null,
"function_declaration": "def read_input():",
"function_name": "read_input",
"parameter_list": "()"
},
{
"docstring": null,
"function_declaration": "def euclidean_distance(city1, city2):",
"function_name": "euclidean_distance",
"parameter_list": "(city1, city2... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef calculate_distance(x1, y1, x2, y2):\n \"\"\"\n Returns the Euclidean distance between two points (x1, y1) and (x2, y2).\n \"\"\... | trial_gpt4o_1 | {
"original_instruction": "A travel company is designing an itinerary-planning system. They need to help customers determine the shortest possible route that visits a list of cities and returns to the starting city. This problem is known as the \"Traveling Salesman Problem.\" The company uses a simple heuristic to es... | 0.63968 | Code_Contests_21293 | C | [
"read_input",
"euclidean_distance",
"find_nearest_city",
"calculate_total_distance",
"main"
] | 5 | [
[
"calculate_total_distance",
"euclidean_distance"
],
[
"calculate_total_distance",
"find_nearest_city"
],
[
"find_nearest_city",
"euclidean_distance"
]
] | 3 | [
"read_input"
] | false | [] | false | pytest | true | [] | true | 8be2e18f89585a097d0e21f547963569947506b5 | e48448363f7caf703adb9c5f3e0e69bb193d1298 | |||
v1.0 | complete | Code_Contests | Code_Contests_23724_C | def createBalancedBST(n: int) -> List[int]:
""" Given an integer n, construct a balanced binary search tree with
n nodes where each node has a unique value between 1 and n (inclusive).
The tree should be printed in level-order traversal.
>>> createBalancedBST(3)
[2, 1, 3]
>>> createB... | from collections import deque
class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def sortedArrayToBST(nums):
if not nums:
return None
mid = len(nums) // 2
root = TreeNode(nums[mid])
root.left = s... | from solution import createBalancedBST
def test_bst_with_3_nodes():
result = createBalancedBST(3)
assert result == [2, 1, 3]
def test_bst_with_5_nodes():
result = createBalancedBST(5)
assert result == [3, 2, 5, 1, 4]
def test_bst_with_1_node():
result = createBalancedBST(1)
assert result == [... | [] | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\nclass TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n... | trial_gpt4o_0 | {
"original_instruction": "Given an integer n, construct a balanced binary search tree with n nodes where each node has a unique value between 1 and n (inclusive). The tree should be printed in level-order traversal.\n\nInput\n\nThe input contains a single integer n (1 ≤ n ≤ 100) — the number of nodes in the binary s... | 0.674359 | Code_Contests_23724 | C | [
"sortedArrayToBST",
"levelOrderTraversal",
"createBalancedBST"
] | 3 | [
[
"createBalancedBST",
"levelOrderTraversal"
],
[
"createBalancedBST",
"sortedArrayToBST"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | c266f209ac20287e78d71d861e29c0d1b4f5b634 | b623c99147a899027d55b22042c0284a6bcc36b3 | |||
v1.0 | complete | Code_Contests | Code_Contests_20876_C | def max_submatrix_sum_from_input(inputs: str) -> int:
""" Given an m x n matrix of integers, find the maximum sum of any submatrix.
Input:
- inputs: str : A string containing the dimensions of the matrix followed by the elements of the matrix.
Returns:
- int : The maximum sum of any submatrix wit... | def max_submatrix_sum(matrix):
"""
Returns the maximum sum of any submatrix in the given m x n matrix.
"""
if not matrix or not matrix[0]:
return 0
m, n = len(matrix), len(matrix[0])
max_sum = float('-inf')
# Iterate over every pair of rows
for top in range(m):
... | from solution import max_submatrix_sum_from_input
def test_max_submatrix_sum_case1():
inputs = "4 5\n1 -2 0 3 4\n-5 6 7 -8 9\n3 -1 -4 2 -5\n5 2 -3 1 8"
assert max_submatrix_sum_from_input(inputs) == 23
def test_max_submatrix_sum_case2():
inputs = "3 3\n-1 -1 -1\n-1 -1 -1\n-1 -1 -1"
assert max_submatri... | [
{
"docstring": "Returns the maximum sum of any submatrix in the given m x n matrix.",
"function_declaration": "def max_submatrix_sum(matrix):",
"function_name": "max_submatrix_sum",
"parameter_list": "(matrix)"
},
{
"docstring": null,
"function_declaration": "def parse_input(inputs):",
... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_sum_submatrix(matrix):\n \"\"\"\n Finds the maximum sum of any submatrix in the given matrix.\n \"\"\"\n if not matrix or not matrix[0]... | trial_gpt4o_2 | {
"original_instruction": "Given an m x n matrix of integers, write a program to find the maximum sum of any submatrix. A submatrix is any continuous sub-section of the matrix that maintains the order of both rows and columns. \n\nInput\n\nThe first line of input contains two integers m and n (1 ≤ m, n ≤ 200), the nu... | 0.59487 | Code_Contests_20876 | C | [
"max_submatrix_sum",
"parse_input",
"max_submatrix_sum_from_input"
] | 3 | [
[
"max_submatrix_sum_from_input",
"max_submatrix_sum"
],
[
"max_submatrix_sum_from_input",
"parse_input"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 10e5635c4d9ffd17e9c9c0fc10c814e9e4a0d673 | d22a136252ce1971c74265df3deb08fb279205c5 | |||
v1.0 | complete | Code_Contests | Code_Contests_22290_C | import math
from typing import List
def is_perfect_square(n: int) -> bool:
"""
Determines if n is a perfect square.
>>> is_perfect_square(1) == True
>>> is_perfect_square(4) == True
>>> is_perfect_square(9) == True
>>> is_perfect_square(16) == True
>>> is_perfect_square(10) == False
>>>... | import math
def is_perfect_square(n):
"""
Determines if n is a perfect square.
"""
root = int(math.sqrt(n))
return root * root == n
def process_numbers(numbers):
"""
Takes a list of numbers and returns a list of 'YES' or 'NO' indicating
whether each number is a perfect square.
"""... | from solution import is_perfect_square, process_numbers
def test_is_perfect_square():
assert is_perfect_square(1) == True
assert is_perfect_square(4) == True
assert is_perfect_square(9) == True
assert is_perfect_square(16) == True
assert is_perfect_square(10) == False
assert is_perfect_square(2... | [
{
"docstring": "Determines if n is a perfect square.",
"function_declaration": "def is_perfect_square(n):",
"function_name": "is_perfect_square",
"parameter_list": "(n)"
},
{
"docstring": "Takes a list of numbers and returns a list of 'YES' or 'NO' indicating \nwhether each number is a perfe... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef is_perfect_square(n):\n \"\"\"\n Determines if n is a perfect square.\n \"\"\"\n root = int(math.sqrt(n))\n return root *... | trial_gpt4o_0 | {
"original_instruction": "Write a program that reads a list of integers and determines if each number is a perfect square. A perfect square is an integer that is the square of some integer. For example, 1, 4, 9, and 16 are perfect squares.\n\nInput\n\nInput consists of several datasets. Each dataset is a single inte... | 0.659923 | Code_Contests_22290 | C | [
"is_perfect_square",
"process_numbers"
] | 2 | [
[
"process_numbers",
"is_perfect_square"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8d3e1894f9c537f3851cd316ca325055e9e9542a | 3cb10b661f280a431df6c713e30a2049062bc3a5 | |||
v1.0 | complete | Code_Contests | Code_Contests_22092_C | def count_clusters_from_input(input_str: str) -> int:
"""
Given a string representing a grid, count the number of clusters of connected 1s.
>>> count_clusters_from_input("3 3\n1 0 1\n0 1 0\n1 0 1")
5
>>> count_clusters_from_input("4 5\n1 0 0 1 0\n0 1 0 1 0\n0 0 1 0 1\n1 0 1 1 0")
6
>>> count... | def count_clusters(m, n, grid):
def dfs(i, j):
if i < 0 or i >= m or j < 0 or j >= n or grid[i][j] == 0:
return
grid[i][j] = 0 # Mark as visited
# explore all four directions
dfs(i-1, j)
dfs(i+1, j)
dfs(i, j-1)
dfs(i, j+1)
clusters = 0
fo... | import pytest
from solution import count_clusters_from_input
def test_example_case_1():
input_str = "3 3\n1 0 1\n0 1 0\n1 0 1"
assert count_clusters_from_input(input_str) == 5
def test_example_case_2():
input_str = "4 5\n1 0 0 1 0\n0 1 0 1 0\n0 0 1 0 1\n1 0 1 1 0"
assert count_clusters_from_input(inpu... | [
{
"docstring": null,
"function_declaration": "def count_clusters(m, n, grid):",
"function_name": "count_clusters",
"parameter_list": "(m, n, grid)"
},
{
"docstring": null,
"function_declaration": "def parse_input(input_str):",
"function_name": "parse_input",
"parameter_list": "(i... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def num_clusters(m, n, grid):\n \"\"\"\n Returns the number of clusters of '1's in the given grid.\n \"\"\"\n def dfs(i, j):\n if i < 0 ... | trial_gpt4o_2 | {
"original_instruction": "Problem\n\nYou are given a two-dimensional grid. Each cell of the grid is identified by a pair of coordinates (i, j) and contains either a `1` or a `0`. You can move vertically or horizontally from one cell to another. A group of connected `1`s forms a cluster. You need to find the number o... | 0.514186 | Code_Contests_22092 | C | [
"count_clusters",
"parse_input",
"count_clusters_from_input"
] | 3 | [
[
"count_clusters_from_input",
"count_clusters"
],
[
"count_clusters_from_input",
"parse_input"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 8d94ad8fb817a2988bff3992c90a1e28aaefc89e | 42bdbcbf8aeb95edc7e13dc905621b5e4767adeb | |||
v1.0 | complete | Code_Contests | Code_Contests_14774_C | class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
def lca_multiple_queries(N: int, edges: List[Tuple[int, int]], queries: List[Tuple[int, int]]) -> List[int]:
"""Determine the lowest common ancestor (LCA) for each pair of nodes given in the queries.
... | class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
def build_tree(edges, N):
nodes = {i: TreeNode(i) for i in range(1, N + 1)}
for parent, child in edges:
if nodes[parent].left is None:
nodes[parent].left = nodes[child]
... | from solution import lca_multiple_queries
def test_simple_case():
N = 5
edges = [(1, 2), (1, 3), (2, 4), (2, 5)]
queries = [(4, 5), (3, 2), (4, 3)]
result = lca_multiple_queries(N, edges, queries)
assert result == [2, 1, 1]
def test_disparate_nodes():
N = 7
edges = [(1, 2), (1, 3), (2, 4),... | [] | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, value):\n self.value = value\n self.parent = None\n self.left = None\n self.right = Non... | trial_gpt4o_2 | {
"original_instruction": "You are given a binary tree with N nodes where each node has a unique value ranging from 1 to N. The binary tree nodes are represented using integer values from 1 to N, and you are also given an array of queries where each query consists of two integers `u` and `v`. For each query, you need... | 0.568589 | Code_Contests_14774 | C | [
"build_tree",
"find_LCA",
"process_queries",
"lca_multiple_queries"
] | 4 | [
[
"lca_multiple_queries",
"process_queries"
],
[
"process_queries",
"build_tree"
],
[
"process_queries",
"find_LCA"
]
] | 3 | [
"process_queries"
] | false | [
"TreeNode"
] | true | pytest | true | [] | true | ad9e1906ff0592fa7605ec429a5b6ba8e5f2fe3b | d73a0742cb155ed24f83193819d0da5e7d63619c | |||
v1.0 | complete | Code_Contests | Code_Contests_21527_C | def rotate_90_clockwise(matrix):
"""
Rotates the given n x n matrix 90 degrees clockwise.
"""
pass
def is_rotation(matrix1, matrix2):
"""
Checks if matrix2 is a 90-degree clockwise rotation of matrix1.
"""
pass
def solve(test_cases):
"""
Determines if matrix B is a 90-degree cl... | def rotate_90_clockwise(matrix):
"""
Rotates the given n x n matrix 90 degrees clockwise.
"""
n = len(matrix)
return [[matrix[n - j - 1][i] for j in range(n)] for i in range(n)]
def is_rotation(matrix1, matrix2):
"""
Checks if matrix2 is a 90-degree clockwise rotation of matrix1.
"""
... | from solution import solve, parse_input
def test_example_case_1():
input_data = """2
3
1 2 3
4 5 6
7 8 9
7 4 1
8 5 2
9 6 3
3
1 2 3
4 5 6
7 8 9
1 2 3
4 5 6
7 8 9"""
test_cases = parse_input(input_data)
results = solve(test_cases)
assert results == ["YES", "NO"]
def test_single_element_matrix():
inp... | [
{
"docstring": "Rotates the given n x n matrix 90 degrees clockwise.",
"function_declaration": "def rotate_90_clockwise(matrix):",
"function_name": "rotate_90_clockwise",
"parameter_list": "(matrix)"
},
{
"docstring": "Checks if matrix2 is a 90-degree clockwise rotation of matrix1.",
"fu... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def rotate_90_degrees_clockwise(matrix):\n \"\"\"\n Rotates the given n x n matrix by 90 degrees clockwise.\n \"\"\"\n n = len(matrix)\n rot... | trial_gpt4o_1 | {
"original_instruction": "Let's solve a matrix transformation problem that involves rotating a matrix clockwise by 90 degrees and checking if it matches a target matrix.\n\nYou are given two n x n matrices, A and B. Your task is to determine if matrix B is a 90-degree clockwise rotation of matrix A.\n\nInput\n\nThe ... | 0.554202 | Code_Contests_21527 | C | [
"rotate_90_clockwise",
"is_rotation",
"solve",
"parse_input"
] | 4 | [
[
"is_rotation",
"rotate_90_clockwise"
],
[
"solve",
"is_rotation"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 255316b3a3cfb02c706521c41eb6134e770713da | 957640530520b5751cd6291f699414b0898279b3 | |||
v1.0 | complete | Code_Contests | Code_Contests_21002_C | from typing import List, Tuple
def process_input(input_text: str) -> Tuple[int, int, List[Tuple[int, int, int]]]:
"""Processes the input text and returns the number of villages, number of roads, and a list of roads with their costs.
>>> process_input("4 5\n1 2 1\n1 3 4\n2 3 2\n3 4 3\n4 1 6\n")
(4, 5, [(1, ... | def find(parent, x):
if parent[x] != x:
parent[x] = find(parent, parent[x])
return parent[x]
def union(parent, rank, x, y):
rootX = find(parent, x)
rootY = find(parent, y)
if rootX != rootY:
if rank[rootX] > rank[rootY]:
parent[rootY] = rootX
elif rank[rootX... | from solution import process_input, minimum_cost_to_connect_villages
def test_example_1():
input_text = "4 5\n1 2 1\n1 3 4\n2 3 2\n3 4 3\n4 1 6\n"
n, m, roads = process_input(input_text)
assert minimum_cost_to_connect_villages(n, m, roads) == 6
def test_example_2():
input_text = "3 3\n1 2 1\n2 3 2\n1 ... | [
{
"docstring": null,
"function_declaration": "def find(parent, x):",
"function_name": "find",
"parameter_list": "(parent, x)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_min_cost_to_connect_villages(N, M, roads):\n \"\"\"\n Finds the minimum cost to connect all villages using Kruskal's algorithm.\n Returns... | trial_gpt4o_1 | {
"original_instruction": "In a distant land, there are N villages connected with M bidirectional roads. Each road has a different construction cost, and you need to find the minimum cost to connect all the villages such that every village is reachable from every other village.\n\nYour task is to find the minimum cos... | 0.664257 | Code_Contests_21002 | C | [
"find",
"union",
"minimum_cost_to_connect_villages",
"process_input"
] | 4 | [
[
"minimum_cost_to_connect_villages",
"find"
],
[
"minimum_cost_to_connect_villages",
"union"
],
[
"union",
"find"
]
] | 3 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | 31887321ccc1a81fd85bff6a03fcaeb90b544fa6 | f332f7588863bae88d45f2421a6b837feb9816c0 | |||
v1.0 | complete | Code_Contests | Code_Contests_23481_C | def is_palindrome(s: str) -> bool:
""" Check if a string is a palindrome.
>>> is_palindrome("a")
True
>>> is_palindrome("aa")
True
>>> is_palindrome("abc")
False
"""
pass
def palindromic_splits_helper(s: str, memo: dict) -> int:
""" Helper function to find palindromic splits wit... | def is_palindrome(s):
return s == s[::-1]
def palindromic_splits_helper(s, memo):
if s in memo:
return memo[s]
if not s:
return 1
total_splits = 0
for i in range(1, len(s) + 1):
if is_palindrome(s[:i]):
total_splits += palindromic_splits_helper(s[i:], memo)
... | from solution import palindromic_splits
def test_single_case_aab():
assert palindromic_splits(1, ["aab"]) == [2]
def test_single_case_aaa():
assert palindromic_splits(1, ["aaa"]) == [4]
def test_single_case_abc():
assert palindromic_splits(1, ["abc"]) == [1]
def test_multiple_cases():
assert palindr... | [
{
"docstring": null,
"function_declaration": "def is_palindrome(s):",
"function_name": "is_palindrome",
"parameter_list": "(s)"
},
{
"docstring": null,
"function_declaration": "def palindromic_splits_helper(s, memo):",
"function_name": "palindromic_splits_helper",
"parameter_list... | [
0,
0,
0,
1,
0
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def count_palindrome_splits(s):\n \"\"\"\n Returns the number of ways to split string s into distinct palindromic substrings.\n \"\"\"\n n = le... | trial_gpt4o_3 | {
"original_instruction": "Alyssa is fascinated by palindromes and wants to find out how many different ways she can split a given string `s` into palindromic substrings. \n\nA palindrome is a string that reads the same forward and backward. Alyssa wants to split the string in such a way that every substring in the s... | 0.768661 | Code_Contests_23481 | C | [
"is_palindrome",
"palindromic_splits_helper",
"palindromic_splits"
] | 3 | [
[
"palindromic_splits",
"palindromic_splits_helper"
],
[
"palindromic_splits_helper",
"is_palindrome"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | fbd41994c024f19ed3c3439e860d0c36aa214779 | b1f41f66ee7ef6af08b1a7cf4479309f367e5722 | |||
v1.0 | complete | Code_Contests | Code_Contests_21744_C | def bubble_sort_swap_count(arr):
"""Function to calculate the number of adjacent swaps required to sort the array using a bubble sort algorithm."""
pass
def min_swaps_to_sort(arrays):
"""Given a list of arrays, this function calculates the minimal number of adjacent swaps required to sort each array in non... | def bubble_sort_swap_count(arr):
"""
Function to calculate the number of adjacent swaps required to sort the array using a bubble sort algorithm.
"""
n = len(arr)
swap_count = 0
for i in range(n):
for j in range(0, n-i-1):
if arr[j] > arr[j+1]:
arr[j], arr[j+1... | from solution import min_swaps_to_sort, parse_input
def test_bubble_sort_swap_count():
assert bubble_sort_swap_count([2, 3, 4, 1, 5]) == 3
assert bubble_sort_swap_count([1, 4, 3, 2]) == 3
assert bubble_sort_swap_count([3, 2, 1]) == 3
assert bubble_sort_swap_count([1, 2, 3, 4, 5]) == 0
def test_min_swa... | [
{
"docstring": "Function to calculate the number of adjacent swaps required to sort the array using a bubble sort algorithm.",
"function_declaration": "def bubble_sort_swap_count(arr):",
"function_name": "bubble_sort_swap_count",
"parameter_list": "(arr)"
},
{
"docstring": "Given a list of a... | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
1
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def count_minimal_swaps(arr):\n \"\"\"\n Calculate the minimal number of swaps required to sort the array in non-decreasing order.\n Swaps only in... | trial_gpt4o_9 | {
"original_instruction": "Develop a program that calculates the minimal number of swaps required to sort an array in non-decreasing order. Each swap should only involve adjacent elements, similar to the bubble sort algorithm.\n\nInput\nThe first line of input contains an integer T denoting the number of test cases. ... | 0.618736 | Code_Contests_21744 | C | [
"bubble_sort_swap_count",
"min_swaps_to_sort",
"parse_input"
] | 3 | [
[
"min_swaps_to_sort",
"bubble_sort_swap_count"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | b2830569276bdb424b4a3d1a7180a9521026353e | ac8a40fbaf9872b7c9df049ffaea4e0941ffb8ac | |||
v1.0 | complete | Code_Contests | Code_Contests_28335_C | import random
import math
from typing import List
def generate_points_in_circle(x_center: int, y_center: int, radius: int, num_points: int = 10) -> List[str]:
"""
Generate random unique points inside a circle.
"""
pass
def generate_random_points_in_circles(input_data: str) -> str:
"""
Generat... | import random
import math
def generate_points_in_circle(x_center, y_center, radius, num_points=10):
points = []
while len(points) < num_points:
angle = random.uniform(0, 2 * math.pi)
r = radius * (random.random() ** 0.5)
x = x_center + r * math.cos(angle)
y = y_center + r * math... | from solution import generate_random_points_in_circles
def test_single_circle():
input_data = "1\n0 0 5"
output = generate_random_points_in_circles(input_data)
lines = output.strip().split('\n')
assert len(lines) == 10
for line in lines:
x, y = map(float, line.split())
assert x**2 +... | [
{
"docstring": null,
"function_declaration": "def generate_points_in_circle(x_center, y_center, radius, num_points=10):",
"function_name": "generate_points_in_circle",
"parameter_list": "(x_center, y_center, radius, num_points=10)"
},
{
"docstring": null,
"function_declaration": "def gen... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\nimport math\n\ndef generate_random_points_in_circle(x, y, radius, num_points=10):\n points = set()\n \n while len(points) < num_poi... | trial_gpt4o_2 | {
"original_instruction": "## Random Points In Circle\n\nConstraints\n\n* 1 ≤ n ≤ 1000\n* 1 ≤ radius ≤ 1000\n\nInput\n\nn\nx1 y1 radius1\nx2 y2 radius2\n...\nxn yn radiusn\n\nThe first line contains an integer n, the number of circles. Each of the next n lines contains three integers: the coordinates of the center (x... | 0.788966 | Code_Contests_28335 | C | [
"generate_points_in_circle",
"generate_random_points_in_circles"
] | 2 | [
[
"generate_random_points_in_circles",
"generate_points_in_circle"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 68c1907fff549a2865478955bf9be787983a9b5e | c44ee67ed3e1e0b01d7c493dcdef721c95804ce3 | |||
v1.0 | complete | Code_Contests | Code_Contests_23957_C | def is_valid_id(candidate: str) -> str:
"""
Check if the candidate ID is valid based on the following rules:
1. It must have at least one lowercase Latin letter.
2. It must not contain consecutive underscores.
3. It cannot start or end with an underscore.
4. It must have a length between 1 and 1... | def is_valid_id(candidate):
"""
Check if the candidate ID meets all the rules:
1. Contains at least one lowercase Latin letter.
2. Does not contain consecutive underscores.
3. Does not start or end with an underscore.
4. Has length between 1 and 100 characters (inclusive).
"""
# Che... | from solution import is_valid_id, validate_ids
def test_is_valid_id():
# Test valid cases
assert is_valid_id("john_doe") == "YES"
assert is_valid_id("valid_id123") == "YES"
assert is_valid_id("a") == "YES"
assert is_valid_id("a_b_c_d") == "YES"
# Test invalid cases
assert is_valid_id("... | [
{
"docstring": "Check if the candidate ID meets all the rules:\n1. Contains at least one lowercase Latin letter.\n2. Does not contain consecutive underscores.\n3. Does not start or end with an underscore.\n4. Has length between 1 and 100 characters (inclusive).",
"function_declaration": "def is_valid_id(can... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_valid_id(id_str):\n \"\"\"\n Checks if the given id_str is a valid ID based on the following rules:\n 1. It must have at least one lowercas... | trial_gpt4o_1 | {
"original_instruction": "John is creating unique IDs for his new application. Each ID consists of lowercase Latin letters (a-z) and possibly special characters like underscores ('_') and digits (0-9). John wants to ensure that all IDs are valid and follow specific rules to maintain uniformity across his application... | 0.551649 | Code_Contests_23957 | C | [
"is_valid_id",
"validate_ids"
] | 2 | [
[
"validate_ids",
"is_valid_id"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 9e4110824fdac49283c2825802989b59975b5380 | bf546a3cfd83be796fbbc6b5a9da75bd002526c7 | |||
v1.0 | complete | Code_Contests | Code_Contests_28317_C | def count_islands(m: int, n: int, grid_lines: List[str]) -> int:
"""
Given a grid of dimensions m x n consisting of '0's (empty space) and '1's (land), this function counts the number of islands.
An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may... | def num_islands(grid):
"""
Returns the number of islands in the given grid.
"""
if not grid:
return 0
def dfs(grid, x, y):
if x < 0 or x >= len(grid) or y < 0 or y >= len(grid[0]) or grid[x][y] == '0':
return
grid[x][y] = '0' # Mark as visited
dfs(grid, ... | from solution import count_islands
def test_count_islands_case_1():
assert count_islands(4, 5, ["11000", "11000", "00100", "00011"]) == 3
def test_count_islands_single_row():
assert count_islands(1, 5, ["11110"]) == 1
def test_count_islands_single_column():
assert count_islands(5, 1, ["1", "0", "1", "0",... | [
{
"docstring": "Returns the number of islands in the given grid.",
"function_declaration": "def num_islands(grid):",
"function_name": "num_islands",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def count_islands(m, n, grid_lines):",
"function_name": "co... | [
0,
0,
0,
0,
0,
1,
0,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def num_islands(m, n, grid):\n if not grid:\n return 0\n \n def dfs(grid, x, y):\n if x < 0 or y < 0 or x >= m or y >= n or grid[x][... | trial_gpt4o_5 | {
"original_instruction": "Given a grid of dimensions m x n consisting of '0's (empty space) and '1's (land), write an algorithm to count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume all four edges of the grid are surroun... | 0.561801 | Code_Contests_28317 | C | [
"num_islands",
"count_islands"
] | 2 | [
[
"count_islands",
"num_islands"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5075637ae4942bd2a803e22ba5e8e956d8b3e5ef | 7a8ca1f939eb027332c0186d193d53559d4fb624 | |||
v1.0 | complete | Code_Contests | Code_Contests_21684_C | def total_task_time(tasks):
"""
Calculate the total time spent on tasks, considering overlaps.
>>> total_task_time([("09:00", "10:30"), ("10:00", "11:00"), ("11:30", "12:00")])
150
>>> total_task_time([("09:00", "10:30"), ("11:30", "12:00")])
120
>>> total_task_time([("09:00", "10:00")... | def parse_time(time_str):
"""Parse a time string "HH:MM" into a number of minutes since midnight."""
hours, minutes = map(int, time_str.split(':'))
return hours * 60 + minutes
def total_task_time(tasks):
"""
Calculate the total time spent on tasks, considering overlaps.
"""
# Convert task t... | from solution import total_task_time
def test_no_overlaps():
tasks = [("09:00", "10:30"), ("11:00", "12:00"), ("13:00", "14:00")]
assert total_task_time(tasks) == 210
def test_full_overlap():
tasks = [("09:00", "10:00"), ("09:30", "10:30"), ("10:00", "11:00")]
assert total_task_time(tasks) == 120
def... | [
{
"docstring": "Parse a time string \"HH:MM\" into a number of minutes since midnight.",
"function_declaration": "def parse_time(time_str):",
"function_name": "parse_time",
"parameter_list": "(time_str)"
},
{
"docstring": "Calculate the total time spent on tasks, considering overlaps.",
... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def calculate_total_task_time(tasks):\n from datetime import datetime\n \n def to_minutes(time_str):\n hours, minutes = map(int, time_str.s... | trial_gpt4o_2 | {
"original_instruction": "You are managing a group of developers and want to track their task completion times. Each developer's tasks for the day are recorded with start and end times. You suspect that some tasks might overlap, leading to inefficient use of time. Your goal is to determine the total amount of time s... | 0.54079 | Code_Contests_21684 | C | [
"parse_time",
"total_task_time"
] | 2 | [
[
"total_task_time",
"parse_time"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4ecfe5968919daa952846b8f5504c1c837085b60 | b3b8fa7348361b86153fabb3838c581545d4dc87 | |||
v1.0 | complete | Code_Contests | Code_Contests_28594_C | from typing import List
def find_shortest_path(n: int, m: int, grid: List[str], coords: List[int]) -> int:
"""
Find the shortest path from one rest station to another rest station avoiding obstacles.
Args:
n (int): the number of rows in the park grid.
m (int): the number of columns in the par... | from collections import deque
def shortest_path(n, m, park, start, end):
directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]
x1, y1 = start
x2, y2 = end
queue = deque([(x1, y1, 0)]) # (x, y, distance)
visited = {(x1, y1)}
while queue:
x, y, dist = queue.popleft()
... | from solution import find_shortest_path
def test_example_1():
n = 5
m = 5
grid = [
"..o..",
"..##.",
".o..#",
"..o..",
"#.#o."
]
coords = [2, 3, 4, 3]
assert find_shortest_path(n, m, grid, coords) == 2
def test_example_2():
n = 4
m = 6
grid =... | [
{
"docstring": null,
"function_declaration": "def shortest_path(n, m, park, start, end):",
"function_name": "shortest_path",
"parameter_list": "(n, m, park, start, end)"
},
{
"docstring": null,
"function_declaration": "def find_shortest_path(n, m, grid, coords):",
"function_name": "f... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef shortest_path(n, m, grid, start, end):\n # Directions for moving in 4 possible directions (Up, Down, Left, Right)\n... | trial_gpt4o_1 | {
"original_instruction": "Alex is planning a picnic in the local park which is designed as an n × m grid of cells, where each cell is either empty or contains an obstacle. The park authorities have placed rest stations at certain locations to ensure that visitors can comfortably enjoy their time. Alex wants to find ... | 0.661108 | Code_Contests_28594 | C | [
"shortest_path",
"find_shortest_path"
] | 2 | [
[
"find_shortest_path",
"shortest_path"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 51343b0de132202f4884126fabb82be8cd9007c1 | 708a9921f79fa0d9c64aa9d772978b7f09238b0a | |||
v1.0 | complete | Code_Contests | Code_Contests_28815_C | def highest_prime_in_list(numbers: str) -> int:
""" Given a string that contains a list of numbers separated by commas,
identify and output the highest prime number in the list. If there are no
prime numbers in the list, return -1.
>>> highest_prime_in_list("3,5,8,13,23,4,6") == 23
>>> highest_prime... | 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 highest_prime_in_list... | from solution import highest_prime_in_list
def test_highest_prime():
assert highest_prime_in_list("3,5,8,13,23,4,6") == 23
assert highest_prime_in_list("10,15,22,5,67,100") == 67
assert highest_prime_in_list("8,4,6,12,15") == -1
assert highest_prime_in_list("2,3,5,7,11,13,17,19") == 19
assert highe... | [
{
"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 the highest prime number in the list or -1 if there are no prime numbers. ",
"function_declaration... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Helper function to check if a number is prime.\n Returns True if n is prime, otherwise False.\n \"\"\"\n if n <=... | trial_gpt4o_1 | {
"original_instruction": "Given a string that contains a list of numbers separated by commas, write a program to identify and output the highest prime number in the list. If there are no prime numbers in the list, return -1.\n\nA prime number is a positive integer greater than 1 that has no positive integer divisors... | 0.667211 | Code_Contests_28815 | C | [
"is_prime",
"highest_prime_in_list"
] | 2 | [
[
"highest_prime_in_list",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6814c6205c9c098c96bca70b3c2f88b71998b1bc | 4db2d6abab10ae380361e94ade71019ec746d419 | |||
v1.0 | complete | Code_Contests | Code_Contests_22450_C | def floyd_warshall(n, edges):
""" Compute the shortest path times between all pairs of parking lots.
>>> floyd_warshall(4, [(0, 1, 4), (0, 2, 9), (1, 2, 2), (1, 3, 5), (2, 3, 1)])
[[0, 4, 6, 7], [4, 0, 2, 3], [6, 2, 0, 1], [7, 3, 1, 0]]
"""
pass # implementation here
def check_sufficiency(capaciti... | def floyd_warshall(n, edges):
inf = float('inf')
dist = [[inf] * n for _ in range(n)]
for i in range(n):
dist[i][i] = 0
for u, v, w in edges:
dist[u][v] = w
dist[v][u] = w
for k in range(n):
for i in range(n):
for j in range(n):
... | import pytest
from solution import traffic_management_system
def test_single_case_sufficient():
test_cases = [
(4, 5, [3, 2, 4, 1], [(0, 1, 4), (0, 2, 9), (1, 2, 2), (1, 3, 5), (2, 3, 1)], [2, 1, 2, 1])
]
expected_output = """Case #1:
0 4 6 7
4 0 2 3
6 2 0 1
7 3 1 0
Sufficient"""
assert traffic... | [
{
"docstring": null,
"function_declaration": "def floyd_warshall(n, edges):",
"function_name": "floyd_warshall",
"parameter_list": "(n, edges)"
},
{
"docstring": null,
"function_declaration": "def check_sufficiency(capacities, demands):",
"function_name": "check_sufficiency",
"pa... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def floyd_warshall(n, edges):\n # Initialize distance matrix with infinity\n inf = float('inf')\n dist = [[inf] * n for _ in range(n)]\n \n ... | trial_gpt4o_2 | {
"original_instruction": "A software development company is designing a new traffic management system for a small town. The town has a number of parking lots and streets connecting them. Each street has a certain traversal time, and each parking lot has a maximum number of available spaces. The town planners want to... | 0.612723 | Code_Contests_22450 | C | [
"floyd_warshall",
"check_sufficiency",
"traffic_management_system"
] | 3 | [
[
"traffic_management_system",
"check_sufficiency"
],
[
"traffic_management_system",
"floyd_warshall"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 63227fe0e1b4f7cc7fa0051ec428052b6971e27e | 05445200de3ac8c8a3710f0f6f8f34835998cb48 | |||
v1.0 | complete | Code_Contests | Code_Contests_21753_C | from typing import List, Tuple
def bfs_shortest_path(graph, start, end):
"""
Use BFS to find the shortest path in an unweighted graph.
"""
visited = set()
queue = deque([(start, 0)]) # (current_node, current_distance)
while queue:
current, distance = queue.popleft()
... | from collections import deque
def bfs_shortest_path(graph, start, end):
"""
Use BFS to find the shortest path in an unweighted graph.
"""
visited = set()
queue = deque([(start, 0)]) # (current_node, current_distance)
while queue:
current, distance = queue.popleft()
... | from solution import shortest_paths
def test_shortest_paths():
n = 6
edges = [
(1, 2),
(1, 3),
(3, 4),
(2, 4),
(4, 5),
(5, 6),
(3, 6)
]
queries = [
(1, 5),
(6, 1),
(2, 6)
]
assert shortest_paths(n, edges, queries) ... | [
{
"docstring": "Use BFS to find the shortest path in an unweighted graph.",
"function_declaration": "def bfs_shortest_path(graph, start, end):",
"function_name": "bfs_shortest_path",
"parameter_list": "(graph, start, end)"
},
{
"docstring": "Build an undirected graph from edge list.",
"f... | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef bfs_shortest_path(graph, start, end):\n \"\"\"\n Function to find the shortest path between start and end nodes ... | trial_gpt4o_4 | {
"original_instruction": "Alice is designing a new social network platform and needs to create a way to identify the shortest path users can take between any two given people in her network. The network is represented as an unweighted, undirected graph where each person is a node, and a friendship between two people... | 0.650474 | Code_Contests_21753 | C | [
"bfs_shortest_path",
"build_graph",
"shortest_paths"
] | 3 | [
[
"shortest_paths",
"bfs_shortest_path"
],
[
"shortest_paths",
"build_graph"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 843090cd5632c9704bd2ad630809d2b5d557b9de | 8c0b788be4c4a358e8821a70b824e66464d9d8f4 | |||
v1.0 | complete | Code_Contests | Code_Contests_29476_C | def next_prime(n: int) -> int:
""" Given an integer n, find the smallest prime number greater than n.
>>> next_prime(10)
11
>>> next_prime(17)
19
>>> next_prime(20)
23
>>> next_prime(1)
2
>>> next_prime(2)
3
>>> next_prime(3)
5
>>> next_prime(5)
7
>>> next... | def is_prime(num):
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
return False
i += 6
return True
def next_prime(n):
candida... | from solution import next_prime
def test_next_prime():
assert next_prime(10) == 11
assert next_prime(17) == 19
assert next_prime(20) == 23
assert next_prime(1) == 2
assert next_prime(2) == 3
assert next_prime(3) == 5
assert next_prime(5) == 7
assert next_prime(1000000) == 1000003 # Lar... | [
{
"docstring": null,
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def next_prime(n):",
"function_name": "next_prime",
"parameter_list": "(n)"
}
] | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"Helper function to check if a number is a prime.\"\"\"\n if num <= 1:\n return False\n if num <= 3:\n ret... | trial_gpt4o_2 | {
"original_instruction": "Given an integer n, find the smallest prime number greater than n. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself.\n\nWrite a function `next_prime(n)` that takes an integer n as an input and returns the smallest prime number greater t... | 0.769986 | Code_Contests_29476 | C | [
"is_prime",
"next_prime"
] | 2 | [
[
"next_prime",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 36668e678c7276903d473549c2455d962fba85ec | 87483a99e2b258ec8ccaf6bf7eea3fbf312618f9 | |||
v1.0 | complete | Code_Contests | Code_Contests_28634_C | def find_palindromic_substrings(S: str) -> List[Tuple[int, int]]:
""" Find all the distinct pairs of indices (i, j) such that the substring S[i:j+1] is a palindrome.
>>> find_palindromic_substrings("ababa")
[(0, 0), (0, 2), (0, 4), (1, 1), (1, 3), (2, 2), (2, 4), (3, 3), (4, 4)]
>>> find_palindromic_sub... | def is_palindrome(s):
return s == s[::-1]
def find_palindromic_substrings(S):
result = []
for i in range(len(S)):
for j in range(i, len(S)):
if is_palindrome(S[i:j+1]):
result.append((i, j))
return result if result else "No palindromic substrings" | from solution import find_palindromic_substrings
def test_single_character():
assert find_palindromic_substrings("a") == [(0, 0)]
def test_no_palindromic_substrings():
assert find_palindromic_substrings("abcd") == [(0, 0), (1, 1), (2, 2), (3, 3)]
def test_mixed_palindromic_substrings():
assert find_palin... | [
{
"docstring": null,
"function_declaration": "def is_palindrome(s):",
"function_name": "is_palindrome",
"parameter_list": "(s)"
},
{
"docstring": null,
"function_declaration": "def find_palindromic_substrings(S):",
"function_name": "find_palindromic_substrings",
"parameter_list":... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_palindromic_substrings_indices(S):\n \"\"\"\n This function finds all the distinct pairs of indices (i, j) such that the substring S[i:j+1] ... | trial_gpt4o_2 | {
"original_instruction": "Palindrome Substring Indices\n\nProblem Statement\n\nGiven a string S, find all the distinct pairs of indices (i, j) such that the substring S[i:j+1] is a palindrome. A string is a palindrome if it reads the same backward as forward.\n\nFor example, the string \"aba\" is a palindrome, while... | 0.769406 | Code_Contests_28634 | C | [
"is_palindrome",
"find_palindromic_substrings"
] | 2 | [
[
"find_palindromic_substrings",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | cc5c794f4e504ee87e0214e6987b1c4879aafc66 | 44b0a6b043f1245f31d56b0e9493bcbbc0663817 | |||
v1.0 | complete | Code_Contests | Code_Contests_29448_C | def min_intervals_to_cover_points(n: int, k: int, points: List[int], intervals: List[Tuple[int, int]]) -> int:
"""
Determines the minimum number of intervals needed to cover all given points.
If it's impossible, returns -1.
Args:
n (int): Number of points
k (int): Number of intervals
po... | def min_intervals_to_cover_points(n, k, points, intervals):
"""
Determines the minimum number of intervals needed to cover all given points.
If it's impossible, returns -1.
"""
points.sort()
intervals.sort()
covered = 0
idx = 0
result = 0
while covered < n:
best... | from solution import min_intervals_to_cover_points
def test_example1():
points = [1, 2, 3, 4, 5]
intervals = [(1, 3), (2, 4), (3, 5)]
assert min_intervals_to_cover_points(5, 3, points, intervals) == 2
def test_example2():
points = [1, 3, 5, 7]
intervals = [(1, 2), (6, 8)]
assert min_intervals_... | [
{
"docstring": "Determines the minimum number of intervals needed to cover all given points.\nIf it's impossible, returns -1.",
"function_declaration": "def min_intervals_to_cover_points(n, k, points, intervals):",
"function_name": "min_intervals_to_cover_points",
"parameter_list": "(n, k, points, i... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def min_intervals_to_cover_points(n, k, points, intervals):\n \"\"\"\n Determines the minimum number of intervals needed to cover all given points.\n... | trial_gpt4o_0 | {
"original_instruction": "You are given a list of n distinct integers representing points on a 1-dimensional number line, and a set of k intervals. Each interval [a, b] represents a segment that can be used to cover any integer within the range [a, b] (inclusive) on the number line.\n\nYour goal is to determine the ... | 0.613897 | Code_Contests_29448 | C | [
"min_intervals_to_cover_points",
"min_intervals_to_cover_points_from_input"
] | 2 | [
[
"min_intervals_to_cover_points_from_input",
"min_intervals_to_cover_points"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b2c85a1942819f8a4eeb6f5f49b710a4b2ee7b4e | 2e9905dfa496d5e9e13a2d4192b45be513750070 | |||
v1.0 | complete | Code_Contests | Code_Contests_30548_C | def who_wins(s: str) -> str:
""" Determine the winner of the game based on the initial string.
>>> who_wins("ababa")
"Alice"
>>> who_wins("abcde")
"Bob"
""" | def can_remove_palindrome(s):
"""
Check if there is any palindrome substring of length greater than 1.
"""
n = len(s)
for length in range(2, n + 1):
for i in range(n - length + 1):
substring = s[i:i + length]
if substring == substring[::-1]:
return Tru... | from solution import who_wins
def test_who_wins_case1():
assert who_wins("ababa") == "Alice"
def test_who_wins_case2():
assert who_wins("abcde") == "Bob"
def test_who_wins_all_same_characters():
assert who_wins("aaaaa") == "Alice"
def test_who_wins_no_possible_move():
assert who_wins("abcdefgh") == ... | [
{
"docstring": "Check if there is any palindrome substring of length greater than 1.",
"function_declaration": "def can_remove_palindrome(s):",
"function_name": "can_remove_palindrome",
"parameter_list": "(s)"
},
{
"docstring": "Determine the winner of the game based on the initial string.",... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def can_remove_palindrome_substring(s):\n \"\"\"\n Returns whether there is any palindrome substring of length greater than 1 in the string.\n \"\... | trial_gpt4o_2 | {
"original_instruction": "Alice and Bob are playing an interesting game with a string. The string consists of only lowercase English letters. Alice makes the first move, and then they alternately take turns. In each move, a player must remove a substring that is a palindrome and also of length greater than 1. The pl... | 0.657537 | Code_Contests_30548 | C | [
"can_remove_palindrome",
"who_wins"
] | 2 | [
[
"who_wins",
"can_remove_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f10458c581dc87e96a3c6afff5114b9da8f4eadf | 994f3b253b393f6f0501b83bcf125cec5316b0d6 | |||
v1.0 | complete | Code_Contests | Code_Contests_28135_C | from typing import List, Tuple
def partition_watchtowers(n: int, m: int, edges: List[Tuple[int, int]]) -> str:
"""
Given a number of watchtowers and the roads connecting them as a graph, partition the vertices into two sets such that no two watchtowers in the same set are directly connected by a road.
... | from collections import deque, defaultdict
def is_bipartite(n, edges):
"""
Determines if a graph is bipartite and returns the two sets of vertices if it is.
:param n: Number of vertices
:param edges: List of edges
:return: Tuple (is_bipartite, set1, set2) or (False, [], []) if not bipartite
... | from solution import partition_watchtowers
def test_example_1():
n = 6
m = 6
edges = [(1, 2), (1, 3), (2, 4), (3, 4), (4, 5), (5, 6)]
output = partition_watchtowers(n, m, edges)
assert output.startswith("YES")
def test_example_2():
n = 5
m = 5
edges = [(1, 2), (1, 3), (2, 3), (3, 4), (... | [
{
"docstring": "Determines if a graph is bipartite and returns the two sets of vertices if it is.\n\n:param n: Number of vertices\n:param edges: List of edges\n:return: Tuple (is_bipartite, set1, set2) or (False, [], []) if not bipartite",
"function_declaration": "def is_bipartite(n, edges):",
"function... | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque, defaultdict\n\ndef is_bipartite(n, roads):\n adj_list = defaultdict(list)\n for u, v in roads:\n adj_list[u].ap... | trial_gpt4o_4 | {
"original_instruction": "The Watchtower Problem\n\nIn a far-off kingdom, there is a network of watchtowers connected by roads. The kingdom needs to set up a new defense strategy in order to maximize the visibility of these watchtowers. Each watchtower must be able to communicate with others in the network, but no t... | 0.573361 | Code_Contests_28135 | C | [
"is_bipartite",
"partition_watchtowers"
] | 2 | [
[
"partition_watchtowers",
"is_bipartite"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 17ef66f256a0972edd1fd92c7b57dfe69407be9a | b69e4329c0ed6bdc996cdd7425bd8b0bb6c99b20 | |||
v1.0 | complete | Code_Contests | Code_Contests_29135_C | from typing import List
import heapq
from collections import Counter
def jane_reorder_string(n: int, s: str) -> str:
""" Jane has a string s consisting of lowercase English letters. She wants to reorder the characters of the string
so that no two adjacent characters are the same. Your task is to help Jane find... | from collections import Counter
import heapq
def rearrange_string(s):
"""
Rearranges the string such that no two adjacent characters are the same.
If it's not possible, returns "IMPOSSIBLE".
"""
# Count the frequencies of each character
freq = Counter(s)
# Create a max heap based on fr... | from solution import jane_reorder_string
def test_jane_reorder_string_possible():
assert jane_reorder_string(4, "aabb") in ["abab", "baba"]
def test_jane_reorder_string_impossible():
assert jane_reorder_string(2, "aa") == "IMPOSSIBLE"
def test_jane_reorder_string_single_letter():
assert jane_reorder_stri... | [
{
"docstring": "Rearranges the string such that no two adjacent characters are the same.\nIf it's not possible, returns \"IMPOSSIBLE\".",
"function_declaration": "def rearrange_string(s):",
"function_name": "rearrange_string",
"parameter_list": "(s)"
},
{
"docstring": null,
"function_dec... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import Counter\nimport heapq\n\ndef rearrange_string(s):\n \"\"\"\n Rearranges the string such that no two adjacent characters are t... | trial_gpt4o_0 | {
"original_instruction": "Jane has a string s consisting of lowercase English letters. She wants to reorder the characters of the string so that no two adjacent characters are the same. Your task is to help Jane find any such reordering of the string, or determine that it is impossible to achieve.\n\nInput\n\nThe fi... | 0.688114 | Code_Contests_29135 | C | [
"rearrange_string",
"jane_reorder_string"
] | 2 | [
[
"jane_reorder_string",
"rearrange_string"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5a8aad68968914dccff75c7d76c51c846cee6d32 | cdc2d55df8063cde501f1b09a91e559b3e047b4c | |||
v1.0 | complete | Code_Contests | Code_Contests_23770_C | from typing import List, Tuple
def shortest_travel_time(n: int, m: int, roads: List[Tuple[int, int, int]], s: int, d: int) -> int:
""" Determine the shortest time required to travel from a given starting city to a destination city.
>>> shortest_travel_time(5, 6, [(1, 2, 4), (2, 3, 1), (3, 4, 2), (4, 5, 5), (1,... | import heapq
def dijkstra(n, roads, s, d):
# Build the graph
graph = {i: [] for i in range(1, n + 1)}
for u, v, t in roads:
graph[u].append((v, t))
graph[v].append((u, t))
# Priority queue for Dijkstra's algorithm
pq = [(0, s)]
dist = {i: float('inf') for i in range(1, n + 1)}
... | from solution import shortest_travel_time
def test_shortest_travel_time_example_1():
n = 5
m = 6
roads = [
(1, 2, 4),
(2, 3, 1),
(3, 4, 2),
(4, 5, 5),
(1, 3, 5),
(3, 5, 3)
]
s = 1
d = 5
assert shortest_travel_time(n, m, roads, s, d) == 8
def ... | [
{
"docstring": null,
"function_declaration": "def dijkstra(n, roads, s, d):",
"function_name": "dijkstra",
"parameter_list": "(n, roads, s, d)"
},
{
"docstring": null,
"function_declaration": "def shortest_travel_time(n, m, roads, s, d):",
"function_name": "shortest_travel_time",
... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef shortest_path_time(n, m, roads, s, d):\n graph = {i: [] for i in range(1, n+1)}\n \n for u, v, t in roads:\n graph[u].a... | trial_gpt4o_2 | {
"original_instruction": "You are given a collection of cities connected by roads. Each road has an associated travel time. Your task is to determine the shortest time required to travel from a given starting city to a destination city.\n\nInput\n\nThe first line contains two integers n (1 ≤ n ≤ 100) and m (0 ≤ m ≤ ... | 0.666432 | Code_Contests_23770 | C | [
"dijkstra",
"shortest_travel_time"
] | 2 | [
[
"shortest_travel_time",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 92458a60a017fdb2c0e974826703db64d2b55b5d | 85be6c2befe97d4227b8df81b2131332e691537e | |||
v1.0 | complete | Code_Contests | Code_Contests_29097_C | from typing import List, Tuple
def calculate_distance(x1, y1, x2, y2) -> float:
"""Calculate the Euclidean distance between two points (x1, y1) and (x2, y2)."""
pass
def union_line_segments(segments: List[Tuple[int, int, int, int]]) -> float:
"""Calculate the union of 2D line segments and return the total... | from math import sqrt
def calculate_distance(x1, y1, x2, y2):
"""
Calculates the Euclidean distance between two points (x1, y1) and (x2, y2)
"""
return sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
def union_line_segments(segments):
"""
Function to calculate the union of 2D line segments and return th... | from solution import total_street_length
def test_single_street():
assert total_street_length(1, [(0, 0, 4, 3)]) == 5.0 # Length of single segment (0,0) to (4,3)
def test_no_overlap():
assert total_street_length(2, [(0, 0, 3, 0), (4, 0, 5, 0)]) == 4.0 # Lengths add directly: 3 + 1
def test_partial_overlap(... | [
{
"docstring": "Calculates the Euclidean distance between two points (x1, y1) and (x2, y2)",
"function_declaration": "def calculate_distance(x1, y1, x2, y2):",
"function_name": "calculate_distance",
"parameter_list": "(x1, y1, x2, y2)"
},
{
"docstring": "Function to calculate the union of 2D... | [
0,
0,
0,
0,
0,
1,
0,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\nfrom typing import List, Tuple\n\nclass LineSegment:\n def __init__(self, x1, y1, x2, y2):\n self.x1, self.y1, self.x2, self.y2 = x1... | trial_gpt4o_5 | {
"original_instruction": "Obi, a professional snowplow operator, is working tirelessly to clear the streets after a recent snowstorm. Each of the n streets he needs to clear is represented as a line segment on a 2D Cartesian plane, and each street can be described by its endpoints (x1, y1) and (x2, y2). Obi wants to... | 0.60554 | Code_Contests_29097 | C | [
"calculate_distance",
"union_line_segments",
"total_street_length"
] | 3 | [
[
"total_street_length",
"union_line_segments"
],
[
"union_line_segments",
"calculate_distance"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | c1e217d82540cf105b3629eef09d8206f38abd47 | 638b60649aa65ec7367bfc3d1fdb7c129726fed1 | |||
v1.0 | complete | Code_Contests | Code_Contests_29543_C | import re
from typing import List
def is_valid_email(email: str) -> bool:
""" Checks if an email address is valid based on given criteria. """
if email.count("@") != 1:
return False
local_part, domain = email.split("@")
if "." not in domain:
return False
return True
def i... | import re
def is_valid_email(email):
"""
Checks if an email address is valid based on given criteria.
"""
if email.count("@") != 1:
return False
local_part, domain = email.split("@")
if "." not in domain:
return False
return True
def is_valid_time(time):
"""
... | from solution import filter_valid_logins
def test_single_valid_login():
assert filter_valid_logins(1, ["user@example.com 12:34"]) == ["user@example.com 12:34"]
def test_mixed_valid_and_invalid_logins():
assert filter_valid_logins(3, ["user@example.com 12:34", "invalid-email@domain 12:34", "user2@domain.c 99:9... | [
{
"docstring": "Checks if an email address is valid based on given criteria.",
"function_declaration": "def is_valid_email(email):",
"function_name": "is_valid_email",
"parameter_list": "(email)"
},
{
"docstring": "Checks if a time is in the valid HH:MM format where HH is between 00 and 23 a... | [
0,
0,
0,
0,
0,
0,
0,
0,
1,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import re\n\ndef valid_email(email):\n \"\"\"Check if the provided email is valid.\"\"\"\n if email.count('@') != 1:\n return False\n local... | trial_gpt4o_8 | {
"original_instruction": "The IT department is auditing access records to identify suspicious activity. They need to analyze a list of n login attempts and filter out invalid ones. A valid login attempt follows these rules:\n\n1. Email addresses must be valid. An email address is considered valid if it contains exac... | 0.536528 | Code_Contests_29543 | C | [
"is_valid_email",
"is_valid_time",
"filter_valid_logins"
] | 3 | [
[
"filter_valid_logins",
"is_valid_email"
],
[
"filter_valid_logins",
"is_valid_time"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | a893222daeaee13754a5cdb8e1671cedf782da7c | ca584cf8365271bafd9baa06aebc775d311ee28f | |||
v1.0 | complete | Code_Contests | Code_Contests_28953_C | from typing import List
def max_visible_fireworks(grid: List[List[int]]) -> int:
""" Determines the maximum number of non-obstructed fireworks visible in the grid.
Args:
grid (List[List[int]]): A grid representing the heights of fireworks.
Returns:
int: Maximum number of non-obstructed... | def max_visible_fireworks(grid):
N = len(grid)
directions = [(1, 0), (0, 1), (1, 1), (-1, 1)]
def is_valid(x, y):
return 0 <= x < N and 0 <= y < N
def dfs(x, y, visited):
if (x, y) in visited:
return
visited.add((x, y))
for dx, dy in directi... | from solution import max_visible_fireworks, process_input, fireworks_organization
def test_max_visible_fireworks():
assert max_visible_fireworks([
[3, 1, 4],
[1, 5, 9],
[2, 6, 5]
]) == 5
assert max_visible_fireworks([
[10, 20, 30, 40],
[50, 60, 70, 80],
[90,... | [
{
"docstring": null,
"function_declaration": "def max_visible_fireworks(grid):",
"function_name": "max_visible_fireworks",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def process_input(input_data):",
"function_name": "process_input",
"parameter_lis... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_visible_fireworks(grid):\n N = len(grid)\n directions = [(1, 0), (0, 1), (1, 1), (-1, 1)]\n \n def is_valid(x, y):\n return 0 <=... | trial_gpt4o_0 | {
"original_instruction": "You are working for Fireworks Organization Inc., which is planning a massive fireworks display on New Year's Eve. The fireworks will be launched from platforms arranged in a large grid. Each platform will launch a firework that explodes at a certain height and is visible from afar. Your tas... | 0.53111 | Code_Contests_28953 | C | [
"max_visible_fireworks",
"process_input",
"fireworks_organization"
] | 3 | [
[
"fireworks_organization",
"process_input"
],
[
"process_input",
"max_visible_fireworks"
]
] | 2 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | 622437e1abf5269be36df63b3677c58f1c93ba86 | 17175e465b9c60375ab78aea26eae0d049810815 | |||
v1.0 | complete | Code_Contests | Code_Contests_29322_C | def min_connections_to_fully_connect(n: int, connections: List[Tuple[int, int]]) -> int:
""" Determine the minimum number of connections that must be added to make the network of servers fully connected.
Args:
n (int): The number of servers.
connections (List[Tuple[int, int]]): A list of tuples rep... | def find(parent, i):
if parent[i] == i:
return i
else:
parent[i] = find(parent, parent[i])
return parent[i]
def union(parent, rank, x, y):
xroot = find(parent, x)
yroot = find(parent, y)
if xroot != yroot:
if rank[xroot] > rank[yroot]:
parent[yroot] ... | from solution import min_connections_to_fully_connect
def test_min_connections_already_connected():
assert min_connections_to_fully_connect(5, [(1, 2), (2, 3), (3, 4), (4, 5)]) == 0
def test_min_connections_two_components():
assert min_connections_to_fully_connect(4, [(1, 2), (3, 4)]) == 1
def test_min_conne... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
0,
0,
0,
1,
0
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def minimum_connections_to_fully_connect(n, m, connections):\n def find(parent, i):\n if parent[i] == i:\n return i\n parent[i]... | trial_gpt4o_3 | {
"original_instruction": "A software company wants to analyze the performance and reliability of their network of servers. They have n servers, labeled from 1 to n, and they log the connections between these servers. Each connection is bi-directional and is represented by a tuple (u, v) indicating a connection betwe... | 0.581234 | Code_Contests_29322 | C | [
"find",
"union",
"min_connections_to_fully_connect"
] | 3 | [
[
"min_connections_to_fully_connect",
"find"
],
[
"min_connections_to_fully_connect",
"union"
],
[
"union",
"find"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 332ea77ae7e91d0d4c428eba615d74e4f9c13c39 | f4698ccf09122da5e10111290ae1afaeb6cd0823 | |||
v1.0 | complete | Code_Contests | Code_Contests_30454_C | from typing import List, Tuple
def max_independent_set_size(V: int, edges: List[Tuple[int, int]]) -> int:
""" Given an undirected graph G = (V, E), where V is a set of vertices and E is a set of edges,
find the size of the maximum independent set.
>>> max_independent_set_size(5, [(0, 1), (0, 2), (1, ... | from itertools import combinations
def is_independent_set(graph, subset):
"""
Check if the given subset of vertices form an independent set in the graph.
"""
for v1, v2 in combinations(subset, 2):
if v2 in graph[v1]:
return False
return True
def max_independent_set_size(V, edge... | def test_simple_case():
assert max_independent_set_size(5, [(0, 1), (0, 2), (1, 2), (1, 3), (2, 4), (3, 4)]) == 2
def test_no_edges():
assert max_independent_set_size(5, []) == 5
def test_single_vertex():
assert max_independent_set_size(1, []) == 1
def test_no_independent_set():
assert max_independen... | [
{
"docstring": "Check if the given subset of vertices form an independent set in the graph.",
"function_declaration": "def is_independent_set(graph, subset):",
"function_name": "is_independent_set",
"parameter_list": "(graph, subset)"
},
{
"docstring": "Return the size of the maximum indepen... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_independent_set(graph, subset):\n \"\"\"\n Checks if the given subset of vertices is an independent set in the graph.\n \"\"\"\n for i i... | trial_gpt4o_2 | {
"original_instruction": "Given an undirected graph G = (V, E), where V is a set of vertices and E is a set of edges, an independent set is a subset of vertices such that no two vertices in the subset are adjacent.\n\nGiven a graph, find the size of the maximum independent set.\n\nConstraints\n\n* 1 ≤ V ≤ 100\n* 0 ≤... | 0.548249 | Code_Contests_30454 | C | [
"is_independent_set",
"max_independent_set_size"
] | 2 | [
[
"max_independent_set_size",
"is_independent_set"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | b3d450bd3288de5fb8688f1ecdb52531ee3bfc8b | 57741e982fce703ebc5d807ecf664a858666e8be | |||
v1.0 | complete | Code_Contests | Code_Contests_28961_C | from typing import List, Tuple
def find_optimal_city(n: int, m: int, tracks: List[Tuple[int, int, int]]) -> int:
"""
Determine the city that should host an event with the minimum maximum travel cost
from all other cities in the railway network.
>>> find_optimal_city(4, 4, [(1, 2, 4), (2, 3, 1), (3, 4, ... | import heapq
import sys
def dijkstra(graph, start, n):
"""
Performs Dijkstra's algorithm to find the shortest paths from start to all other nodes.
"""
distances = [sys.maxsize] * (n + 1)
distances[start] = 0
pq = [(0, start)]
while pq:
current_distance, current_vertex = heapq.h... | from solution import find_optimal_city
def test_example_1():
n = 4
m = 4
tracks = [
(1, 2, 4),
(2, 3, 1),
(3, 4, 2),
(4, 1, 5)
]
assert find_optimal_city(n, m, tracks) == 2
def test_example_2():
n = 3
m = 3
tracks = [
(1, 2, 3),
(2, 3, 1)... | [
{
"docstring": "Performs Dijkstra's algorithm to find the shortest paths from start to all other nodes.",
"function_declaration": "def dijkstra(graph, start, n):",
"function_name": "dijkstra",
"parameter_list": "(graph, start, n)"
},
{
"docstring": null,
"function_declaration": "def find... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\nimport sys\n\ndef dijkstra(graph, start, n):\n \"\"\"\n Performs Dijkstra's algorithm to find the shortest paths from start to all othe... | trial_gpt4o_0 | {
"original_instruction": "The \"Railway Department\" has a network of n cities connected by m railway tracks. Each railway track connects two distinct cities and has a certain travel cost. The travel cost between cities can vary depending on the railway track. \n\nThe Railway Department is planning to hold a major e... | 0.630749 | Code_Contests_28961 | C | [
"dijkstra",
"find_optimal_city"
] | 2 | [
[
"find_optimal_city",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e50bc5167fba7e5e1c95e590bad28689a801ef4c | 922a5ef1e1f64d8e5aba4ea552b2126e847049ec | |||
v1.0 | complete | Code_Contests | Code_Contests_30837_C | def execute_plans(plans):
""" Execute multiple city plans to find the shortest path from start to destination.
Args:
plans (List[str]): The list of city plans in a specified format.
Returns:
List[int]: A list of minimum steps for each plan or -1 if no path exists.
Example:
>>>... | from collections import deque
def shortest_path(city_plan, start, destination):
w, h = len(city_plan[0]), len(city_plan)
sx, sy = start
dx, dy = destination
def is_valid(x, y):
return 0 <= x < h and 0 <= y < w and city_plan[x][y] in ('R', 'P')
# If the start or destination is a bu... | from solution import execute_plans
def test_example_case():
plans = [
"5 5",
"RRRRR",
"RBBBB",
"RPRPR",
"RRRRR",
"RRRRR",
"0 0 4 4",
"4 4",
"RRRR",
"RBRR",
"RRRR",
"RPRR",
"0 0 3 3",
"0 0"
... | [
{
"docstring": null,
"function_declaration": "def shortest_path(city_plan, start, destination):",
"function_name": "shortest_path",
"parameter_list": "(city_plan, start, destination)"
},
{
"docstring": null,
"function_declaration": "def execute_plans(plans):",
"function_name": "execu... | [
0,
0,
0,
0,
0,
0,
0,
1,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef min_steps_to_destination(grid, start, destination):\n w, h = len(grid[0]), len(grid)\n sx, sy = start\n dx, d... | trial_gpt4o_7 | {
"original_instruction": "You are given a grid representing a city plan that is composed of buildings, roads, and parks. The city is represented as a 2D grid where each cell can either be a building (`'B'`), road (`'R'`), or park (`'P'`). The goal is to find the shortest path from the starting point to the destinati... | 0.718701 | Code_Contests_30837 | C | [
"shortest_path",
"execute_plans"
] | 2 | [
[
"execute_plans",
"shortest_path"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6602500f14bc0ab35142fb2f786fc944f13844cb | 7ef8c160a5d4cddca0cdea2f45f7a8773f7d917b | |||
v1.0 | complete | Code_Contests | Code_Contests_32013_C | def find_longest_compound_word(words: List[str]) -> str:
"""
Given a list of words, rearrange and concatenate them to form the longest possible
word that contains all the given words as subsequences.
>>> find_longest_compound_word(["abc", "bcd", "ace"]) == "abcde"
>>> find_longest_compound_word(["x... | def find_longest_compound_word(words):
"""
Given a list of words, rearrange and concatenate them to form the longest possible
word that contains all the given words as subsequences.
"""
# To find the longest compound word we can use all letters of all words given
# corner case for empty string
... | from solution import find_longest_compound_word
def test_example_1():
assert find_longest_compound_word(["abc", "bcd", "ace"]) == "abcde"
def test_example_2():
assert find_longest_compound_word(["xyz", "xy", "yz", "z"]) == "xyz"
def test_single_word():
assert find_longest_compound_word(["alone"]) == "alo... | [
{
"docstring": "Given a list of words, rearrange and concatenate them to form the longest possible\nword that contains all the given words as subsequences.",
"function_declaration": "def find_longest_compound_word(words):",
"function_name": "find_longest_compound_word",
"parameter_list": "(words)"
... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_longest_compound_word(words):\n \"\"\"\n Given a list of words, rearrange and concatenate them to form the longest possible\n word that c... | trial_gpt4o_0 | {
"original_instruction": "You are given a list of words. Your task is to compound these words to generate the longest possible word that contains all the given words as subsequences. A subsequence of a string is a new string generated from the original string by deleting some (can be none) of the characters without ... | 0.685504 | Code_Contests_32013 | C | [
"find_longest_compound_word",
"merge_two_words"
] | 2 | [
[
"find_longest_compound_word",
"merge_two_words"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8dda3a7a6690746a4e9dbf9f6d16ddd3bc7482f9 | ab88dfcf720f2a7aa7acec3bd1657e8fd9e2af2f | |||
v1.0 | complete | Code_Contests | Code_Contests_35779_C | from typing import List, Tuple
def kruskal_min_cost(n: int, edges: List[Tuple[int, int, int]]) -> int:
""" Determine the minimal total cost required to ensure that there is a way to travel between any two cities.
>>> kruskal_min_cost(4, [(1, 2, 3), (1, 3, 2), (2, 3, 4), (3, 4, 1), (2, 4, 5)])
6
>>> kru... | 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... | from solution import kruskal_min_cost
def test_min_cost_case1():
n, m = 4, 5
edges = [
(1, 2, 3),
(1, 3, 2),
(2, 3, 4),
(3, 4, 1),
(2, 4, 5)
]
assert kruskal_min_cost(n, edges) == 6
def test_min_cost_case2():
n, m = 3, 3
edges = [
(1, 2, 1),
... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
0,
0,
0,
0,
0,
1,
0,
1,
1
] | 3 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n else:\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n xr... | trial_gpt4o_9 | {
"original_instruction": "In a certain country, there are n cities and m roads connecting some pairs of cities. Every road has an associated cost, which represents the fee travelers have to pay to use it. The government of the country wants to ensure that it is possible to travel between any two cities, but they als... | 0.629536 | Code_Contests_35779 | C | [
"find",
"union",
"kruskal_min_cost"
] | 3 | [
[
"kruskal_min_cost",
"find"
],
[
"kruskal_min_cost",
"union"
],
[
"union",
"find"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | e440ac1504cb3bb4e362082afff93e9acd8cf7cd | ac3c2b4206b2de5b6e04d716a1d54ddc1af24d2f | |||
v1.0 | complete | Code_Contests | Code_Contests_28296_C | from typing import List, Tuple
def time_to_minutes(time: str) -> int:
"""
Converts a time string in HH:MM format to the total number of minutes since midnight.
"""
hours, minutes = map(int, time.split(':'))
return hours * 60 + minutes
def is_time_within_range(crime_time: str, start_time: str, end_... | def time_to_minutes(time):
hours, minutes = map(int, time.split(':'))
return hours * 60 + minutes
def is_time_within_range(crime_time, start_time, end_time):
crime_time_minutes = time_to_minutes(crime_time)
start_time_minutes = time_to_minutes(start_time)
end_time_minutes = time_to_minutes(end_time... | def test_time_to_minutes():
assert time_to_minutes("12:30") == 750
assert time_to_minutes("00:00") == 0
assert time_to_minutes("23:59") == 1439
def test_is_time_within_range():
assert is_time_within_range("12:30", "12:00", "13:00") == True
assert is_time_within_range("11:59", "12:00", "13:00") == F... | [
{
"docstring": null,
"function_declaration": "def time_to_minutes(time):",
"function_name": "time_to_minutes",
"parameter_list": "(time)"
},
{
"docstring": null,
"function_declaration": "def is_time_within_range(crime_time, start_time, end_time):",
"function_name": "is_time_within_ra... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def time_to_minutes(time):\n hh, mm = time.split(':')\n return int(hh) * 60 + int(mm)\n\ndef is_alibi_cover(alibi, crime_time):\n start, end = ali... | trial_gpt4o_2 | {
"original_instruction": "Detective John is investigating a series of crimes in the city. He has a list of suspects, the date and time each crime was reported, and the alibi timeframes provided by each suspect. John needs to find out if any of the suspects could have committed a specific crime given their alibis.\n\... | 0.542985 | Code_Contests_28296 | C | [
"time_to_minutes",
"is_time_within_range",
"find_potential_suspects",
"solve"
] | 4 | [
[
"find_potential_suspects",
"is_time_within_range"
],
[
"is_time_within_range",
"time_to_minutes"
],
[
"solve",
"find_potential_suspects"
]
] | 3 | [] | false | [] | false | pytest | false | [] | true | cfe0beb64a8f96c23b7d9946f1e1546088d4c617 | 25600cd0f0fcd53de31f4402bb4f19cd15ab968e | |||
v1.0 | complete | Code_Contests | Code_Contests_36533_C | def shift_character(char, k):
"""
Shift a character by k positions in the alphabet.
"""
pass
def encrypt_string(s, k):
"""
Encrypt the string by shifting each character by k positions.
"""
pass
def process_cases(cases):
"""
Process multiple test cases.
"""
pass
def par... | def shift_character(char, k):
"""
Shift a character by k positions in the alphabet.
"""
return chr((ord(char) - ord('a') + k) % 26 + ord('a'))
def encrypt_string(s, k):
"""
Encrypt the string by shifting each character by k positions.
"""
return ''.join(shift_character(char, k) for char... | from solution import process_cases, parse_input
def test_encrypt_string():
cases = [
("abc", 2),
("xyz", 1),
("hello", 3)
]
expected = [
"cde",
"yza",
"khoor"
]
assert process_cases(cases) == expected
def test_parser_and_processor():
input_data =... | [
{
"docstring": "Shift a character by k positions in the alphabet.",
"function_declaration": "def shift_character(char, k):",
"function_name": "shift_character",
"parameter_list": "(char, k)"
},
{
"docstring": "Encrypt the string by shifting each character by k positions.",
"function_decl... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def encrypt_string(s, k):\n \"\"\"\n Encrypts the string s by shifting each character k positions to the right.\n The alphabet wraps around so tha... | trial_gpt4o_2 | {
"original_instruction": "Alyssa loves encryption and challenges her friends with puzzles. She invented a simple encryption technique based on shifting characters in a string. Given a string and an integer 'k', she shifts each character in the string by 'k' positions to the right where the alphabet wraps around (i.e... | 0.707461 | Code_Contests_36533 | C | [
"shift_character",
"encrypt_string",
"process_cases",
"parse_input"
] | 4 | [
[
"encrypt_string",
"shift_character"
],
[
"process_cases",
"encrypt_string"
]
] | 2 | [
"process_cases",
"parse_input"
] | false | [] | false | pytest | true | [] | true | c88980d6498e5b5e63f2e564a4a13ae9af4dfa8c | b997eef1e1a2b6f5da64c6893b6de7272109a6a8 | |||
v1.0 | complete | Code_Contests | Code_Contests_37202_C | from typing import List, Tuple
class TreeNode:
def __init__(self, value):
self.value = value
self.children = []
def build_tree(values: List[int], edges: List[Tuple[int, int]]) -> TreeNode:
nodes = [TreeNode(value) for value in values]
for u, v in edges:
u -= 1 # Convert to 0-based... | class TreeNode:
def __init__(self, value):
self.value = value
self.children = []
def build_tree(values, edges):
nodes = [TreeNode(value) for value in values]
for u, v in edges:
u -= 1 # Convert to 0-based indexing
v -= 1
nodes[u].children.append(nodes[v])
return... | from solution import find_max_sum_path
def test_example_case():
n = 5
node_values = [1, 2, 3, 4, 5]
edges = [(1, 2), (1, 3), (2, 4), (2, 5)]
assert find_max_sum_path(n, node_values, edges) == 8
def test_single_node():
n = 1
node_values = [10]
edges = []
assert find_max_sum_path(n, node... | [] | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, value):\n self.value = value\n self.children = []\n\ndef build_tree(values, edges):\n nodes = [Tre... | trial_gpt4o_0 | {
"original_instruction": "During his daily walk in the park, Alex found a peculiar tree with an interesting challenge. The tree has nodes and each node can have 0, 1, or 2 children. Each node contains a unique integer value. Alex challenges you with the task of finding the maximum sum path in the tree. A path is def... | 0.611139 | Code_Contests_37202 | C | [
"build_tree",
"max_sum_path",
"find_max_sum_path"
] | 3 | [
[
"find_max_sum_path",
"build_tree"
],
[
"find_max_sum_path",
"max_sum_path"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | bb1e733ada63b7e5f9f1a8322a8fe29e98c36f39 | e8160964c3d2a554b87a3ab2f844d082dbab2b9f | |||
v1.0 | complete | Code_Contests | Code_Contests_35964_C | def find_num_paths(N: int, M: int, grid_lines: List[str]) -> int:
""" Determine the number of distinct paths from the top-left corner to the bottom-right corner.
Constraints:
- All values in input are integers.
- 1 <= N, M <= 1000
- Each cell is either '1' (walkable) or '0' (not walkable).
... | def num_paths(grid):
if grid[0][0] == '0' or grid[-1][-1] == '0':
return 0
N = len(grid)
M = len(grid[0])
dp = [[0] * M for _ in range(N)]
dp[0][0] = 1
for i in range(N):
for j in range(M):
if grid[i][j] == '1':
if i > 0:
... | from solution import find_num_paths
def test_3x3_grid():
grid = [
"1 1 1",
"1 0 1",
"1 1 1"
]
assert find_num_paths(3, 3, grid) == 2
def test_2x2_grid():
grid = [
"1 0",
"1 1"
]
assert find_num_paths(2, 2, grid) == 1
def test_no_paths():
grid = [
... | [
{
"docstring": null,
"function_declaration": "def num_paths(grid):",
"function_name": "num_paths",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def find_num_paths(N, M, grid_lines):",
"function_name": "find_num_paths",
"parameter_list": "(N, M, grid... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def num_paths(grid):\n \"\"\"\n Returns the number of distinct paths from the top-left corner to the bottom-right corner\n of a given grid.\n \... | trial_gpt4o_1 | {
"original_instruction": "You are given a 2D grid of size N x M consisting of cells marked with either '1' or '0'. A cell marked with '1' is walkable, while a cell marked with '0' is not walkable. You start at the top-left corner (0, 0) and want to reach the bottom-right corner (N-1, M-1). You can only move right or... | 0.777519 | Code_Contests_35964 | C | [
"num_paths",
"find_num_paths"
] | 2 | [
[
"find_num_paths",
"num_paths"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a66d784cf27f1dd1e7df0c58eae449ddceba2d6b | 25ee793314ef1fe39989689414830b1f22219666 | |||
v1.0 | complete | Code_Contests | Code_Contests_32086_C | import heapq
from typing import List, Tuple
def dijkstra(n: int, adj: List[List[Tuple[int, int]]], src: int) -> List[int]:
"""
Helper function to perform Dijkstra's algorithm to find shortest paths from src to all nodes.
"""
dist = [float('inf')] * (n + 1)
dist[src] = 0
pq = [(0, src)] # prio... | import heapq
def dijkstra(n, adj, src):
dist = [float('inf')] * (n + 1)
dist[src] = 0
pq = [(0, src)] # priority queue as (distance, node)
while pq:
current_dist, u = heapq.heappop(pq)
if current_dist > dist[u]:
continue
for v, weight in adj[u]:
if dist[... | def test_find_shortest_path_with_removal():
n1 = 6
m1 = 7
edges1 = [
(1, 2, 2),
(2, 3, 2),
(3, 4, 2),
(4, 5, 2),
(5, 6, 2),
(1, 3, 4),
(3, 6, 4)
]
assert find_shortest_path_with_removal(n1, m1, edges1) == 8
n2 = 5
m2 = 6
edges2... | [
{
"docstring": null,
"function_declaration": "def dijkstra(n, adj, src):",
"function_name": "dijkstra",
"parameter_list": "(n, adj, src)"
},
{
"docstring": null,
"function_declaration": "def find_shortest_path_with_removal(n, m, edges):",
"function_name": "find_shortest_path_with_rem... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\nimport sys\nfrom collections import defaultdict\n\ndef dijkstra(graph, n, start):\n distances = [sys.maxsize] * (n + 1)\n distances[sta... | trial_gpt4o_2 | {
"original_instruction": "Robin has an undirected, weighted graph with n nodes and m edges. The graph is represented by an edge list where each edge has a source node u, a destination node v, and a weight w. Robin is interested in finding the shortest path from node 1 to node n but with a twist: Robin can remove at ... | 0.626803 | Code_Contests_32086 | C | [
"dijkstra",
"find_shortest_path_with_removal"
] | 2 | [
[
"find_shortest_path_with_removal",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | cbb45860787d8b64db6e78fa2b52f24b6287d906 | 908a89857c1a84b4e0d97b026f75a904650250e5 | |||
v1.0 | complete | Code_Contests | Code_Contests_36066_C | import re
from typing import List
def is_prime(n: int) -> bool:
"""Returns True if n is a prime number, False otherwise.
>>> is_prime(101)
True
>>> is_prime(103)
True
>>> is_prime(100)
False
>>> is_prime(1)
False
"""
pass
def is_palindrome(s: str) -> bool:
"""Returns Tr... | def is_prime(n):
"""Returns True if n is a prime number, False otherwise."""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6... | from solution import find_valid_sequences, process_input
def test_is_prime():
assert is_prime(101) == True
assert is_prime(103) == True
assert is_prime(100) == False
assert is_prime(1) == False
def test_is_palindrome():
assert is_palindrome("a") == True
assert is_palindrome("ab") == False
... | [
{
"docstring": "Returns True if n is a prime number, False otherwise.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns True if s is a palindrome, False otherwise.",
"function_declaration": "def is_palindrome(s):... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n if n <= 1:\n return False\n for i in range(2, int(n ** 0.5) + 1):\n if n % i == 0:\n return False\n re... | trial_gpt4o_2 | {
"original_instruction": "Alice is building a security system that only grants access when a correct password sequence is detected within an entered string. A correct password sequence is composed of the following conditions:\n\n1. The sequence must start with a prime number with exactly 3 digits (for example, 101, ... | 0.698771 | Code_Contests_36066 | C | [
"is_prime",
"is_palindrome",
"find_valid_sequences",
"process_input"
] | 4 | [
[
"find_valid_sequences",
"is_palindrome"
],
[
"find_valid_sequences",
"is_prime"
],
[
"process_input",
"find_valid_sequences"
]
] | 3 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | 5e81142dc833ebb4411cf9a9d2a42474a18afd3a | e9179c6cd7f0feaccdea95abd58649b2d8085df1 | |||
v1.0 | complete | Code_Contests | Code_Contests_32825_C | from typing import List, Tuple
def chemical_max_quantities(input_data: str) -> List[int]:
"""
Determines the maximum sum of quantities from the available containers
that does not exceed the target amount for each test case.
Args:
input_data (str): A multiline string where:
- The first ... | def max_quantity_under_limit(test_cases):
results = []
for case in test_cases:
N, M, quantities = case
quantities = sorted(quantities, reverse=True)
best_sum = 0
def find_best_sum(index, current_sum):
nonlocal best_sum
if current_sum... | from solution import chemical_max_quantities
def test_case_1():
input_data = """3
5 10
2 3 7 8 10
4 7
1 2 3 4
3 15
5 10 20"""
expected_output = [10, 7, 15]
assert chemical_max_quantities(input_data) == expected_output
def test_case_2():
input_data = """1
3 5
1 1 1"""
expected_output = [3]
asse... | [
{
"docstring": null,
"function_declaration": "def max_quantity_under_limit(test_cases):",
"function_name": "max_quantity_under_limit",
"parameter_list": "(test_cases)"
},
{
"docstring": null,
"function_declaration": "def parse_input(input_data):",
"function_name": "parse_input",
... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_sum_under_target(T, test_cases):\n def knapsack(weights, max_weight):\n n = len(weights)\n dp = [0] * (max_weight + 1)\n \n... | trial_gpt4o_1 | {
"original_instruction": "A scientist is conducting an experiment involving a large number of chemical reactions. For each reaction, a specific amount of a rare chemical ingredient is required. The experiment must re-use as much of the rare chemical as possible to avoid wastage.\n\nThe scientist has N random quantit... | 0.644983 | Code_Contests_32825 | C | [
"max_quantity_under_limit",
"parse_input",
"chemical_max_quantities"
] | 3 | [
[
"chemical_max_quantities",
"max_quantity_under_limit"
],
[
"chemical_max_quantities",
"parse_input"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 1532772ec3bd43be25b61e52a4a90f8420e2e510 | 57d2c5423190dc458457a4b671ed6884896e0177 | |||
v1.0 | complete | Code_Contests | Code_Contests_36930_C | from typing import List
def is_prime(n: int) -> bool:
"""
Returns True if n is a prime number, else False.
"""
pass
def sum_of_primes(numbers: List[int]) -> int:
"""
Returns the sum of all prime numbers in the input list that are less than 100.
>>> sum_of_primes([3, 11, 20, 17, 50, 99, 4... | def is_prime(n):
"""
Returns True if n is a prime number, else False.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return False
return True
def sum_of_prim... | from solution import is_prime, sum_of_primes
# Tests for is_prime
def test_is_prime():
assert is_prime(2)
assert not is_prime(1)
assert not is_prime(0)
assert is_prime(11)
assert not is_prime(4)
assert not is_prime(10)
assert is_prime(17)
assert not is_prime(98)
# Tests for sum_of_prim... | [
{
"docstring": "Returns True if n is a prime number, else False.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns the sum of all prime numbers in the input list that are less than 100.",
"function_declaration": ... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Returns True if n is a prime number, otherwise False.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n... | trial_gpt4o_2 | {
"original_instruction": "Your task is to write a program that reads a sequence of non-negative integers and computes the sum of all primes up to but not including the number 100. The input ends when you read a number that is either negative or greater than or equal to 100. Use a function to check for the primality ... | 0.780628 | Code_Contests_36930 | C | [
"is_prime",
"sum_of_primes"
] | 2 | [
[
"sum_of_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 1843e446a9e919c90fd2884a76910bb1888846f8 | 09f35c97e7c3273f92cab1e4518616b6b6514aa9 | |||
v1.0 | complete | Code_Contests | Code_Contests_37027_C | def calculate_final_position(steps: str) -> (int, int):
"""
This function takes a sequence of steps and calculates the final position of the robot.
Parameters:
steps (str): A string composed only of characters 'U', 'D', 'L', and 'R' which represent the steps of the robot.
Returns:
tupl... | def calculate_final_position(steps):
"""
This function takes a sequence of steps and calculates the final position of the robot.
:param steps: A string composed only of characters 'U', 'D', 'L', and 'R'
:return: A tuple of two integers representing the final coordinates (x, y)
"""
x, y = 0, 0
... | from solution import calculate_final_position, print_final_position
def test_final_position_only_up():
assert calculate_final_position('UUUU') == (0, 4)
def test_final_position_only_down():
assert calculate_final_position('DDDD') == (0, -4)
def test_final_position_only_left():
assert calculate_final_posi... | [
{
"docstring": "This function takes a sequence of steps and calculates the final position of the robot.\n:param steps: A string composed only of characters 'U', 'D', 'L', and 'R'\n:return: A tuple of two integers representing the final coordinates (x, y)",
"function_declaration": "def calculate_final_positi... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def calculate_final_position(steps):\n \"\"\"\n This function takes a sequence of steps and calculates the final position of the robot.\n :param s... | trial_gpt4o_0 | {
"original_instruction": "A large advanced robotics company is developing a new line of autonomous delivery robots, and they want to create a simulation of the robot's paths. Each robot will follow a predefined sequence of steps (as a string) and the company wants to know the final position of the robot after execut... | 0.575812 | Code_Contests_37027 | C | [
"calculate_final_position",
"print_final_position"
] | 2 | [
[
"print_final_position",
"calculate_final_position"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 220c88ad88492c904f05121b822cc93925a5f1af | 9d8542bbea5c68c66df5d7174e0ac387cadff987 | |||
v1.0 | complete | Code_Contests | Code_Contests_37281_C | def solution(n: int, m: int, edge_list: List[Tuple[int, int, int]]) -> int:
""" Given an undirected connected graph with n vertices and m edges,
determine the maximum value of the minimum edge weight that can be achieved
by removing exactly one edge. The remaining graph must still be connected after
rem... | def find_max_of_min_edge(n, m, edges):
def kruskal_mst(n, edges, ignore_edge=None):
parent = list(range(n))
def find(x):
if parent[x] != x:
parent[x] = find(parent[x])
return parent[x]
def union(x, y):
root_x = find(x)
... | from solution import solution
def test_solution_sample_case():
n, m = 4, 5
edge_list = [
(1, 2, 1),
(2, 3, 2),
(3, 4, 3),
(4, 1, 4),
(1, 3, 5)
]
assert solution(n, m, edge_list) == 2
def test_solution_no_edges():
n, m = 1, 0
edge_list = [
]
asser... | [
{
"docstring": null,
"function_declaration": "def find_max_of_min_edge(n, m, edges):",
"function_name": "find_max_of_min_edge",
"parameter_list": "(n, m, edges)"
},
{
"docstring": null,
"function_declaration": "def solution(n, m, edge_list):",
"function_name": "solution",
"parame... | [
0,
0,
0,
0,
0,
0,
1,
0,
0
] | 1 | hard | 0.111 | {
"trial_gpt4o_0": null,
"trial_gpt4o_1": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared1_results_combined.jsonl",
"solution_code": "def solve_max_min_edge_weight(n, m, edges):\n from collections import defaultdict\n import heapq\n\n def mst_kruskal(n, e... | trial_gpt4o_7 | {
"original_instruction": "Given an undirected connected graph with n vertices and m edges, each edge has a non-negative weight. Your goal is to determine the maximum value of the minimum edge weight that can be achieved by removing exactly one edge from the graph. The remaining graph must still be connected after re... | 0.723632 | Code_Contests_37281 | C | [
"find_max_of_min_edge",
"solution"
] | 2 | [
[
"solution",
"find_max_of_min_edge"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f1958ec8adfc03de82d5060c77b76fd29ad928b8 | bafdcf125c9499b37546f6fa76ea8fd3dab56388 | |||
v1.0 | complete | Code_Contests | Code_Contests_36893_C | def count_paths(n, m, obstacles):
"""
Returns the number of distinct paths from the top-left to the bottom-right
corner of the grid, avoiding obstacles.
"""
grid = [[0] * m for _ in range(n)]
if (1, 1) in obstacles or (n, m) in obstacles:
return 0
grid[0][0] = 1
for i i... | def count_paths(n, m, obstacles):
"""
Returns the number of distinct paths from the top-left to the bottom-right
corner of the grid, avoiding obstacles.
"""
grid = [[0] * m for _ in range(n)]
if (1, 1) in obstacles or (n, m) in obstacles:
return 0
grid[0][0] = 1
for i i... | def test_count_paths_no_obstacles():
input_str = "2 2\n0"
assert grid_paths(input_str) == 2
def test_count_paths_with_obstacle():
input_str = "3 3\n1\n2 2"
assert grid_paths(input_str) == 2
def test_count_paths_obstacle_at_start():
input_str = "3 3\n1\n1 1"
assert grid_paths(input_str) == 0
d... | [
{
"docstring": "Returns the number of distinct paths from the top-left to the bottom-right\ncorner of the grid, avoiding obstacles.",
"function_declaration": "def count_paths(n, m, obstacles):",
"function_name": "count_paths",
"parameter_list": "(n, m, obstacles)"
},
{
"docstring": null,
... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def unique_paths_with_obstacles(n, m, k, obstacles):\n # Initialize the grid with 0s\n grid = [[0] * m for _ in range(n)]\n\n # Mark the obstacles... | trial_gpt4o_1 | {
"original_instruction": "In a rectangular grid, you start at the top-left corner and at each step, you can move right or down. You need to navigate to the bottom-right corner of the grid. Given some cells marked as obstacles, find the number of distinct paths from the top-left to the bottom-right corner that do not... | 0.718661 | Code_Contests_36893 | C | [
"count_paths",
"parse_input",
"grid_paths"
] | 3 | [
[
"grid_paths",
"count_paths"
],
[
"grid_paths",
"parse_input"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | false | [] | true | df7698f737e5db2350ee17003fcb22fd7b69f3b1 | c6e5502567fba975c7693481dc714f0c6a1cd40c | |||
v1.0 | complete | Code_Contests | Code_Contests_38443_C | MOD = 10**9 + 7
def distinct_paths(H: int, W: int, grid_input: str) -> int:
"""Determine the number of distinct paths from the top-left corner to the bottom-right corner of a grid.
>>> distinct_paths(3, 3, "...\n.#.\n...")
2
>>> distinct_paths(2, 2, "..\n##")
0
>>> distinct_paths(1, 1, ".")
... | MOD = 10**9 + 7
def num_paths(grid, H, W):
# Initialize a DP table with 0
dp = [[0] * W for _ in range(H)]
# Start at dp[0][0]
if grid[0][0] == '.':
dp[0][0] = 1
# Fill the DP table
for i in range(H):
for j in range(W):
if grid[i][j] == '.':
... | def test_example_case():
H = 3
W = 3
grid_input = "...\n.#.\n..."
assert distinct_paths(H, W, grid_input) == 2
def test_no_path():
H = 2
W = 2
grid_input = "..\n##"
assert distinct_paths(H, W, grid_input) == 0
def test_single_cell():
H = 1
W = 1
grid_input = "."
ass... | [
{
"docstring": null,
"function_declaration": "def num_paths(grid, H, W):",
"function_name": "num_paths",
"parameter_list": "(grid, H, W)"
},
{
"docstring": null,
"function_declaration": "def distinct_paths(H, W, grid_input):",
"function_name": "distinct_paths",
"parameter_list": ... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def number_of_paths(H, W, grid):\n MOD = 10**9 + 7\n dp = [[0] * W for _ in range(H)]\n \n # If the starting or ending point is blocked, return... | trial_gpt4o_2 | {
"original_instruction": "You are given a rectangular grid with dimensions $ H \\times W $. In the grid, some cells are blocked, and some are open. The task is to move from the top-left corner to the bottom-right corner of the grid. You can move only to the right or down at each step. Determine the number of distinc... | 0.663279 | Code_Contests_38443 | C | [
"num_paths",
"distinct_paths"
] | 2 | [
[
"distinct_paths",
"num_paths"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 134431b16e45764c85dc96104e5f506800a26cee | 8d8c79cef76306a13d27588625be7af302e5cacc | |||
v1.0 | complete | Code_Contests | Code_Contests_36298_C | from typing import List, Tuple
def preprocess(prefix_sums: List[int], sequence: List[int]) -> None:
"""
Fill the prefix_sums array where prefix_sums[i] is the sum of all elements
from the beginning of the sequence up to and including index i-1.
"""
# Implement this function
def query_sum(prefix_su... | def preprocess(prefix_sums, sequence):
"""
Fill the prefix_sums array where prefix_sums[i] is the sum of all elements
from the beginning of the sequence up to and including index i-1.
"""
for i in range(1, len(sequence) + 1):
prefix_sums[i] = prefix_sums[i - 1] + sequence[i - 1]
def query_s... | from solution import preprocess, query_sum, process_queries
def test_preprocess():
sequence = [1, 2, 3, 4, 5]
prefix_sums = [0] * (len(sequence) + 1)
preprocess(prefix_sums, sequence)
assert prefix_sums == [0, 1, 3, 6, 10, 15]
def test_query_sum():
prefix_sums = [0, 1, 3, 6, 10, 15]
assert que... | [
{
"docstring": "Fill the prefix_sums array where prefix_sums[i] is the sum of all elements\nfrom the beginning of the sequence up to and including index i-1.",
"function_declaration": "def preprocess(prefix_sums, sequence):",
"function_name": "preprocess",
"parameter_list": "(prefix_sums, sequence)"... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def prefix_sum(arr):\n \"\"\"\n Function to compute prefix sums of the provided array.\n \"\"\"\n n = len(arr)\n prefix = [0] * (n+1)\n f... | trial_gpt4o_2 | {
"original_instruction": "You are given a sequence of n integers (a_1, a_2, ..., a_n) and a list of m queries. Each query is represented as a pair of integers l and r (1 ≤ l ≤ r ≤ n). To answer a query, you need to find the sum of all integers in the subsequence (a_l, a_{l+1}, ..., a_r). Write a program to efficient... | 0.6058 | Code_Contests_36298 | C | [
"preprocess",
"query_sum",
"process_queries"
] | 3 | [
[
"process_queries",
"preprocess"
],
[
"process_queries",
"query_sum"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | true | [] | true | 434875f630300c3813e4d7608c679d4918810d76 | 0d1f0084b54272a82b2329bda13d0edc10966197 | |||
v1.0 | complete | Code_Contests | Code_Contests_36803_C | def bfs(grid, start):
# Helper function to perform BFS and find word length
pass
def shortest_word_length(grid):
""" Find the length of the shortest word that can be formed by traversing the grid.
>>> shortest_word_length([['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i']])
1
>>> shortest_word_... | def bfs(grid, start):
from collections import deque
n = len(grid)
m = len(grid[0])
q = deque([start])
visited = set()
visited.add(start)
length = 1
directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]
while q:
x, y = q.popleft()
for dx, dy in directions:... | from solution import shortest_word_length, parse_input_data
def test_single_cell_grid():
input_data = "1 1\na"
grid = parse_input_data(input_data)
assert shortest_word_length(grid) == 1
def test_simple_grid():
input_data = "3 3\nabc\ndef\nghi"
grid = parse_input_data(input_data)
assert shortes... | [
{
"docstring": null,
"function_declaration": "def bfs(grid, start):",
"function_name": "bfs",
"parameter_list": "(grid, start)"
},
{
"docstring": null,
"function_declaration": "def shortest_word_length(grid):",
"function_name": "shortest_word_length",
"parameter_list": "(grid)"
... | [
0,
0,
0,
1,
0
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef shortest_word_length(n, m, grid):\n directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]\n \n def bfs(start_i, sta... | trial_gpt4o_3 | {
"original_instruction": "You are given a 2D grid of size n x m, where each cell contains a lowercase English letter. Your task is to find the length of the shortest word that can be formed by traversing this grid starting from any cell. The rule for traversal is that you can move to an adjacent cell (up, down, left... | 0.63371 | Code_Contests_36803 | C | [
"bfs",
"shortest_word_length",
"parse_input_data"
] | 3 | [
[
"shortest_word_length",
"bfs"
]
] | 1 | [
"parse_input_data"
] | false | [] | false | pytest | true | [] | true | df426679cb9e6aaf65ac3d0cd397194a1897a6ca | 3c15d819858bab9d36ba51a9e35a5b5cf8913516 | |||
v1.0 | complete | Code_Contests | Code_Contests_38001_C | def is_prime(n: int) -> bool:
"""Check if a number is a prime number.
>>> is_prime(11) == True
>>> is_prime(24) == False
>>> is_prime(9) == False
>>> is_prime(7) == True
>>> is_prime(10) == False
>>> is_prime(5) == True
>>> is_prime(2) == False # 2 is not an odd prime
>>> is_prime(3... | def is_prime(n):
"""Check if a number is a prime number."""
if n <= 1:
return False
if n == 2:
return False # 2 is not an odd prime number
if n % 2 == 0:
return False
sqrt_n = int(n**0.5) + 1
for i in range(3, sqrt_n, 2):
if n % i == 0:
return False
... | from solution import is_prime, sum_odd_primes
def test_is_prime():
assert is_prime(11) == True
assert is_prime(24) == False
assert is_prime(9) == False
assert is_prime(7) == True
assert is_prime(10) == False
assert is_prime(5) == True
assert is_prime(2) == False # 2 is not an odd prime
... | [
{
"docstring": "Check if a number is a prime number.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns the sum of all odd prime numbers in the array.",
"function_declaration": "def sum_odd_primes(arr):",
"fun... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import sys\nimport math\n\ndef is_prime(n):\n if n <= 1:\n return False\n if n <= 3:\n return n % 2 != 0 and n % 3 != 0\n if n % 2 =... | trial_gpt4o_1 | {
"original_instruction": "You are given an array of positive integers B of length M. You are required to find the sum of all odd prime numbers present in the array.\n\nConstraints:\n\n* All values in the input are integers.\n* 1 \\leq M \\leq 10^5\n* 1 \\leq B_i \\leq 10^6\n\nInput:\n\nInput is given from Standard I... | 0.76578 | Code_Contests_38001 | C | [
"is_prime",
"sum_odd_primes"
] | 2 | [
[
"sum_odd_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0605b5056417dd3d6e267db7bc3738f15087117c | d97874e69ac7d51c2b85e4a6690b3e652eb07ad2 | |||
v1.0 | complete | Code_Contests | Code_Contests_37548_C | from typing import List
def is_prime(number: int) -> bool:
"""
Returns True if the number is prime, else False.
"""
pass
def smallest_prime_sum(n: int, values: List[int]) -> int:
"""
Finds the smallest prime number sum of a subset of gemstones values, or -1 if no such prime sum exists.
"""... | from typing import List
from itertools import combinations
def is_prime(number: int) -> bool:
"""
Returns True if the number is prime, else False.
"""
if number <= 1:
return False
if number <= 3:
return True
if number % 2 == 0 or number % 3 == 0:
return False
i = 5
... | from solution import smallest_prime_sum
def test_example1():
assert smallest_prime_sum(5, [3, 7, 10, 2, 5]) == 2
def test_example2():
assert smallest_prime_sum(4, [4, 6, 8, 12]) == -1
def test_example3():
assert smallest_prime_sum(6, [11, 15, 3, 17, 20, 8]) == 3
def test_single_prime_element():
asse... | [
{
"docstring": "Returns True if the number is prime, else False.",
"function_declaration": "def is_prime(number):",
"function_name": "is_prime",
"parameter_list": "(number)"
},
{
"docstring": "Finds the smallest prime number sum of a subset of gemstones values, or -1 if no such prime sum exi... | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from itertools import combinations\nfrom typing import List\n\ndef is_prime(num: int) -> bool:\n if num <= 1:\n return False\n if num <= 3:\n ... | trial_gpt4o_4 | {
"original_instruction": "Alice is fond of prime numbers and she also loves collecting gemstones. One day, she came up with a game where she merges her two interests. The game consists of n gemstones, each with a distinct integer value. Alice wants to select a subset of the gemstones such that the sum of their value... | 0.679037 | Code_Contests_37548 | C | [
"is_prime",
"smallest_prime_sum"
] | 2 | [
[
"smallest_prime_sum",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | baefd2ba55adafb580ce7f5e71fd95f56cb26f5e | ab5b301224755716b761a68cce08e29baf930f27 | |||
v1.0 | complete | Code_Contests | Code_Contests_37514_C | def are_intersections(n: int, segments: List[Tuple[int, int, int, int]]) -> str:
""" Determine if any two of the provided streets intersect.
>>> are_intersections(3, [(0, 0, 3, 3), (1, 1, 2, 2), (0, 3, 3, 0)])
'YES'
>>> are_intersections(2, [(0, 0, 3, 3), (4, 4, 6, 6)])
'NO'
"""
pass
def te... | def orientation(p, q, r):
"""
To find the orientation of the ordered triplet (p, q, r).
The function returns:
0 -> p, q and r are collinear
1 -> Clockwise
2 -> Counterclockwise
"""
val = (q[1] - p[1]) * (r[0] - q[0]) - (q[0] - p[0]) * (r[1] - q[1])
if val == 0:
re... | def test_no_intersections():
assert are_intersections(2, [(0, 0, 3, 3), (4, 4, 6, 6)]) == "NO"
def test_intersections_within_same_line():
assert are_intersections(3, [(0, 0, 3, 3), (1, 1, 2, 2), (0, 3, 3, 0)]) == "YES"
def test_intersections_at_single_point():
assert are_intersections(3, [(0, 0, 3, 3), (0... | [
{
"docstring": "To find the orientation of the ordered triplet (p, q, r).\nThe function returns:\n 0 -> p, q and r are collinear\n 1 -> Clockwise\n 2 -> Counterclockwise",
"function_declaration": "def orientation(p, q, r):",
"function_name": "orientation",
"parameter_list": "(p, q, r)"
},... | [
0,
0,
0,
1,
0
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def orientation(p, q, r):\n \"\"\"\n Calculate the orientation of the triplet (p, q, r).\n 0 --> p, q and r are collinear\n 1 --> Clockwise\n ... | trial_gpt4o_3 | {
"original_instruction": "John is a city planner designing a new downtown area. He received a list of segments, where each segment represents a street. Each street can be defined by two endpoints in a 2-dimensional Cartesian coordinate system.\n\nJohn needs to ensure that there are no intersections between any two s... | 0.634828 | Code_Contests_37514 | C | [
"orientation",
"on_segment",
"do_intersect",
"are_intersections"
] | 4 | [
[
"are_intersections",
"do_intersect"
],
[
"do_intersect",
"on_segment"
],
[
"do_intersect",
"orientation"
]
] | 3 | [] | false | [] | false | pytest | false | [] | true | be7b7d258b67f0d6700d25bae680dcd9f74a4b20 | e66d8d779933f411cf2c65ee8ae32e4c46945ac0 | |||
v1.0 | complete | Code_Contests | Code_Contests_38180_C | from typing import List
def unique_paths_with_obstacles(grid: List[List[int]]) -> int:
""" Calculate the number of unique paths the robot can take to reach
the top-right corner from the bottom-left corner without hitting any obstacles.
>>> unique_paths_with_obstacles([
... [0, 0, 0],
... [0, 1... | def unique_paths_with_obstacles(grid):
n = len(grid)
m = len(grid[0])
if grid[0][0] == 1 or grid[n - 1][m - 1] == 1:
return 0
dp = [[0] * m for _ in range(n)]
dp[0][0] = 1
for i in range(n):
for j in range(m):
if grid[i][j] == 1:
dp... | from solution import unique_paths_with_obstacles, solve
def test_example_1():
grid = [
[0, 0, 0],
[0, 1, 0],
[0, 0, 0]
]
assert unique_paths_with_obstacles(grid) == 2
def test_example_2():
grid = [
[0, 1, 0],
[0, 1, 0],
[0, 0, 0]
]
assert unique_... | [
{
"docstring": null,
"function_declaration": "def unique_paths_with_obstacles(grid):",
"function_name": "unique_paths_with_obstacles",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def solve(data):",
"function_name": "solve",
"parameter_list": "(data... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def unique_paths_with_obstacles(grid):\n n = len(grid)\n m = len(grid[0])\n \n # Create a DP table initialized to zero\n dp = [[0]*m for _ i... | trial_gpt4o_2 | {
"original_instruction": "Chris is a robotics enthusiast who programs his robot to move around a grid. Chris's robot is initially located at the bottom-left corner of a grid, which is represented as (0, 0). The grid has obstacles in the form of certain cells that the robot cannot step on. The robot can only move up ... | 0.598157 | Code_Contests_38180 | C | [
"unique_paths_with_obstacles",
"solve"
] | 2 | [
[
"solve",
"unique_paths_with_obstacles"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f7ca3f45df0f364641e08b2a8d97902c4067fd39 | 5ec3b2a3ffdae9429f080561f67c41f8e06cc08e | |||
v1.0 | complete | Code_Contests | Code_Contests_42847_C | def is_palindrome(num: int) -> bool:
"""Determine if a number is a palindrome.
Args:
num (int): The input number.
Returns:
bool: True if the number is a palindrome, False otherwise.
>>> is_palindrome(121)
True
>>> is_palindrome(123)
False
"""
pass
def smallest... | from collections import Counter
def is_palindrome(num):
"""
Determine if a number is a palindrome.
"""
s = str(num)
return s == s[::-1]
def smallest_palindrome_permutation(N):
"""
Determine if the input number N is a palindrome.
If it is, return the smallest palindrome permutation of N... | from solution import is_palindrome, smallest_palindrome_permutation
def test_is_palindrome():
assert is_palindrome(121) == True
assert is_palindrome(12321) == True
assert is_palindrome(123) == False
assert is_palindrome(7) == True
assert is_palindrome(22) == True
def test_smallest_palindrome_permu... | [
{
"docstring": "Determine if a number is a palindrome.",
"function_declaration": "def is_palindrome(num):",
"function_name": "is_palindrome",
"parameter_list": "(num)"
},
{
"docstring": "Determine if the input number N is a palindrome.\nIf it is, return the smallest palindrome permutation of... | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import Counter\n\ndef is_palindrome(num):\n \"\"\"\n Returns True if the given number is a palindrome, else False.\n \"\"\"\n ... | trial_gpt4o_4 | {
"original_instruction": "Certain numbers are called palindrome numbers if they read the same forwards and backwards. For example, 121, 1331, and 7 are palindrome numbers. Your task is to determine whether an input number is a palindrome.\n\nFurther, if the input number is a palindrome, you need to determine the sma... | 0.74943 | Code_Contests_42847 | C | [
"is_palindrome",
"smallest_palindrome_permutation"
] | 2 | [
[
"smallest_palindrome_permutation",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4aeb8f969182a845c6856ff33628e8f64042cd76 | 46febdf61be25c7b0f9b919b898378893696c464 | |||
v1.0 | complete | Code_Contests | Code_Contests_42959_C | def is_prime(num: int) -> bool:
""" Determine if a given number is prime.
>>> is_prime(2)
True
>>> is_prime(3)
True
>>> is_prime(4)
False
>>> is_prime(31)
True
>>> is_prime(101)
True
"""
def is_palindrome(num: int) -> bool:
""" Determine if a given number is a pa... | def is_prime(num):
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
return False
i += 6
return True
def is_palindrome(num):
re... | from solution import is_prime, is_palindrome, smallest_prime_palindrome
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(31) == True
assert is_prime(101) == True
def test_is_palindrome():
assert is_palindrome(121) == True
... | [
{
"docstring": null,
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def is_palindrome(num):",
"function_name": "is_palindrome",
"parameter_list": "(num)"
},
{
"docstring... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome(x):\n \"\"\"\n Check if a given number x is a palindrome.\n \"\"\"\n s = str(x)\n return s == s[::-1]\n\ndef is_prime(x):\... | trial_gpt4o_1 | {
"original_instruction": "The Prime Palindrome Puzzle\n\nA palindrome is a string that reads the same forward and backward. A prime number is a natural number greater than 1 that is not divisible by any numbers other than 1 and itself. The task is to find the smallest prime number greater than or equal to a given in... | 0.6826 | Code_Contests_42959 | C | [
"is_prime",
"is_palindrome",
"smallest_prime_palindrome"
] | 3 | [
[
"smallest_prime_palindrome",
"is_palindrome"
],
[
"smallest_prime_palindrome",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 4e2ca5b1827ccc5304dc7dc68dc4a7c0415680fd | efddd8f39284cd026d7e493f4c0d9527670a9f3c | |||
v1.0 | complete | Code_Contests | Code_Contests_43162_C | def largest_rectangle_area(grid: List[str]) -> int:
"""Determine the size of the largest rectangle that can be formed using only one type of letter in a grid.
>>> largest_rectangle_area([
... "aab",
... "abb",
... "bbb"
... ])
4
>>> largest_rectangle_area([
... "abc... | def largest_rectangle_area(grid):
n = len(grid)
if n == 0:
return 0
m = len(grid[0])
if m == 0:
return 0
# Transform the grid into height matrix for each letter
heights = {chr(i): [0] * m for i in range(ord('a'), ord('z') + 1)}
max_area = 0
for i in range(n):
... | from solution import largest_rectangle_area
def test_largest_rectangle_area_case1():
grid = [
"aab",
"abb",
"bbb"
]
assert largest_rectangle_area(grid) == 4
def test_largest_rectangle_area_case2():
grid = [
"abcde",
"fghij",
"klmno",
"pqrst"
... | [
{
"docstring": null,
"function_declaration": "def largest_rectangle_area(grid):",
"function_name": "largest_rectangle_area",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def largest_histogram_area(heights):",
"function_name": "largest_histogram_area",
... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def largest_rectangle_area(grid):\n n = len(grid)\n m = len(grid[0])\n \n max_area = 0\n \n for row in range(n):\n heights = [0] *... | trial_gpt4o_1 | {
"original_instruction": "You are given a grid of size n × m, where each cell in the grid contains a single lowercase English letter. You need to determine the size of the largest rectangle that can be formed using only one type of letter.\n\nInput\n\nThe first line contains two integers n and m (1 ≤ n, m ≤ 1000) — ... | 0.652484 | Code_Contests_43162 | C | [
"largest_rectangle_area",
"largest_histogram_area"
] | 2 | [
[
"largest_rectangle_area",
"largest_histogram_area"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 1522d6657a2dd581d681087c06918dd65b14ed27 | 715a3b420360f0fc4a64cf565b1d9872891b6805 | |||
v1.0 | complete | Code_Contests | Code_Contests_43736_C | def is_palindromic(number: int) -> bool:
"""
Helper function to check if a number is palindromic.
>>> is_palindromic(121) == True
>>> is_palindromic(123) == False
>>> is_palindromic(1) == True
>>> is_palindromic(22) == True
>>> is_palindromic(10) == False
"""
def count_palindromic_numbe... | def is_palindromic(number):
"""
Helper function to check if a number is palindromic.
"""
return str(number) == str(number)[::-1]
def count_palindromic_numbers(L, R):
"""
Returns the count of palindromic numbers in the inclusive range [L, R].
"""
count = 0
for num in range(L, R + 1):... | from solution import is_palindromic, count_palindromic_numbers
def test_is_palindromic():
assert is_palindromic(121) == True
assert is_palindromic(123) == False
assert is_palindromic(1) == True
assert is_palindromic(22) == True
assert is_palindromic(10) == False
def test_count_palindromic_numbers_... | [
{
"docstring": "Helper function to check if a number is palindromic.",
"function_declaration": "def is_palindromic(number):",
"function_name": "is_palindromic",
"parameter_list": "(number)"
},
{
"docstring": "Returns the count of palindromic numbers in the inclusive range [L, R].",
"func... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def count_palindromic_numbers(L, R):\n \"\"\"\n Returns the count of palindromic numbers in the inclusive range [L, R].\n \"\"\"\n count = 0\n ... | trial_gpt4o_2 | {
"original_instruction": "Alice is learning about numerical operations and she is fascinated by the concept of palindromic numbers. A palindromic number is a number that remains the same when its digits are reversed. Alice wants to write a program to count how many numbers in a given range [L, R] are palindromic.\n\... | 0.748806 | Code_Contests_43736 | C | [
"is_palindromic",
"count_palindromic_numbers"
] | 2 | [
[
"count_palindromic_numbers",
"is_palindromic"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e0141f396604a2dd3b6667ed027c86f2d56cb347 | 03fccae50d2fcc49f34033278eaf15110785db1c | |||
v1.0 | complete | Code_Contests | Code_Contests_43731_C | def is_palindrome(n: str) -> bool:
"""Check if the given string representation of a number is a palindrome.
Args:
n (str): The string representation of the number.
Returns:
bool: True if the number is a palindrome, False otherwise.
"""
def check_palindromes(numbers: List[str]) -> List[... | def is_palindrome(n):
"""
Check if the given string representation of a number is a palindrome.
"""
return n == n[::-1]
def check_palindromes(numbers):
"""
Given a list of numbers in string format, check if each one is a palindrome.
"""
results = []
for number in numbers:
if... | from solution import check_palindromes
def test_basic_cases():
assert check_palindromes(["123", "121", "1001"]) == ["NO", "YES", "YES"]
def test_single_digit_numbers():
assert check_palindromes(["1", "2", "3", "4", "5", "6", "7", "8", "9"]) == ["YES"] * 9
def test_larger_numbers():
assert check_palindrom... | [
{
"docstring": "Check if the given string representation of a number is a palindrome.",
"function_declaration": "def is_palindrome(n):",
"function_name": "is_palindrome",
"parameter_list": "(n)"
},
{
"docstring": "Given a list of numbers in string format, check if each one is a palindrome.",... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome(num_str):\n \"\"\"\n Check if the given string representation of a number is a palindrome.\n \n Parameters:\n num_str (str... | trial_gpt4o_2 | {
"original_instruction": "You are given a large number, and you need to determine whether it is a palindrome. A number is a palindrome if it reads the same forwards and backwards. However, this number can get very large, and you might need to check multiple such numbers in a short amount of time. \n\nWrite a program... | 0.739892 | Code_Contests_43731 | C | [
"is_palindrome",
"check_palindromes"
] | 2 | [
[
"check_palindromes",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e3e4075969902de66051bd789ff573f76cc6a0f0 | 8b91ffbe20d9eb457acf84694bf2e317775d7270 | |||
v1.0 | complete | Code_Contests | Code_Contests_43756_C | from typing import List, Tuple
def process_appointments(m: int, n: int, grid: List[str], p: int, pets: List[Tuple[str, int, int, int]]) -> None:
"""
Prints the updated grid with appointments marked by pet ids. If an appointment can't be processed due to conflicts
or invalid slots, it indicates the booking ... | def update_appointment_grid(m, n, grid, pets):
"""
Updates the given species-booking grid with appointment slots marked by pet ids.
"""
for species, pet_id, row, col in pets:
if grid[row][col] == species:
grid[row][col] = str(pet_id)
else:
print(f'Booking failed f... | from solution import process_appointments
def test_basic_functionality():
assert process_appointments(3, 5, ["A....", "AA..B", "....B"], 3, [('A', 101, 1, 0), ('B', 202, 1, 4), ('A', 303, 0, 1)]) == None
def test_booking_conflict():
assert process_appointments(2, 3, [".C.", ".C."], 2, [('C', 101, 0, 1), ('C',... | [
{
"docstring": "Updates the given species-booking grid with appointment slots marked by pet ids.",
"function_declaration": "def update_appointment_grid(m, n, grid, pets):",
"function_name": "update_appointment_grid",
"parameter_list": "(m, n, grid, pets)"
},
{
"docstring": null,
"functio... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def update_appointment_grid(m, n, grid, pets):\n \"\"\"\n Updates the given species-booking grid with appointment slots marked by pet ids.\n \"\"\... | trial_gpt4o_0 | {
"original_instruction": "A veterinarian clinic is managing their appointments for various pets. Each pet is characterized by their species and a unique identification number. The clinic runs on a schedule represented by a grid, where each cell corresponds to a time slot available for an appointment. The rows repres... | 0.570661 | Code_Contests_43756 | C | [
"update_appointment_grid",
"process_appointments"
] | 2 | [
[
"process_appointments",
"update_appointment_grid"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 71cc1c5d74733e03ec5f54481186d0ea806e6d4f | b2cf286713d956a2716d70d4fe33cdee8aaa57f9 | |||
v1.0 | complete | Code_Contests | Code_Contests_43580_C | def max_submatrix_sum(matrix: List[List[int]]) -> int:
""" Given a matrix of integers, find the submatrix with the maximum sum.
>>> max_submatrix_sum([
... [1, 2, -1, -4, -20],
... [-8, -3, 4, 2, 1],
... [3, 8, 10, 1, 3],
... [-4, -1, 1, 7, -6]
... ])
29
>>> max_submatrix_sum([
... | def max_submatrix_sum(matrix):
"""
Returns the maximum sum of any submatrix of the given matrix.
"""
n = len(matrix)
m = len(matrix[0])
max_sum = float('-inf')
for left in range(m):
row_sum = [0] * n
for right in range(left, m):
for i in range(n):
... | from solution import max_submatrix_sum
def test_example_case_1():
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_example_case_2():
matrix = [
[-1, -2, -3],
[-4, -5... | [
{
"docstring": "Returns the maximum sum of any submatrix of the given matrix.",
"function_declaration": "def max_submatrix_sum(matrix):",
"function_name": "max_submatrix_sum",
"parameter_list": "(matrix)"
},
{
"docstring": null,
"function_declaration": "def kadane(arr):",
"function_n... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_sum_submatrix(matrix):\n \"\"\"\n Given a matrix of integers, find the submatrix with the maximum sum.\n \"\"\"\n n = len(matrix)\n ... | trial_gpt4o_1 | {
"original_instruction": "Given a matrix of integers, find the submatrix with the maximum sum.\n\nA submatrix is a rectangular portion of the matrix defined by a contiguous range of rows and columns. The sum of a submatrix is the sum of all elements within it.\n\n**Input**\n\n- The first line contains two integers, ... | 0.653424 | Code_Contests_43580 | C | [
"max_submatrix_sum",
"kadane"
] | 2 | [
[
"max_submatrix_sum",
"kadane"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a3173a36d42f3d843af535d0816ddedf9773c8c3 | dcfad4a66f9e88400ddbb462f30be3d675f72b48 | |||
v1.0 | complete | Code_Contests | Code_Contests_43584_C | def product_except_self(nums: List[int]) -> List[int]:
"""
Returns a list where each element at index i is the product of all the elements in the input list except nums[i].
"""
pass
def solve(test_cases: List[List[int]]) -> List[List[int]]:
"""
Processes multiple test cases and returns the resu... | def product_except_self(nums):
"""
Returns a list where each element at index i is the product of all the elements in the input list except nums[i].
"""
n = len(nums)
result = [1] * n
# Calculate prefix multiplication
prefix = 1
for i in range(n):
result[i] = prefix
... | import pytest
from solution import solve, parse_input, format_output
def test_case_1():
input_data = "2\n3\n1 2 3\n4\n2 3 4 5"
expected_output = "6 3 2\n60 40 30 24"
test_cases = parse_input(input_data)
results = solve(test_cases)
output = format_output(results)
assert output == expec... | [
{
"docstring": "Returns a list where each element at index i is the product of all the elements in the input list except nums[i].",
"function_declaration": "def product_except_self(nums):",
"function_name": "product_except_self",
"parameter_list": "(nums)"
},
{
"docstring": null,
"functi... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def product_except_self(nums):\n \"\"\"\n Given a list of numbers, returns a list where each element at index i\n contains the product of all the ... | trial_gpt4o_1 | {
"original_instruction": "You are given an array of integers `nums`. Your task is to create a new array `result` where each element at index `i` contains the product of all the elements in `nums` except `nums[i]`. You cannot use division and must complete it in O(n) time.\n\nInput:\n- The first line contains an inte... | 0.61241 | Code_Contests_43584 | C | [
"product_except_self",
"solve",
"parse_input",
"format_output"
] | 4 | [
[
"solve",
"product_except_self"
]
] | 1 | [
"parse_input",
"format_output"
] | false | [] | false | pytest | true | [] | true | df6f3bc77b6f5997269dda172152b011699b4612 | 6959827d55a5c49200968387321d67e616ed541a | |||
v1.0 | complete | Code_Contests | Code_Contests_43912_C | from typing import List, Tuple
def find_convex_hull_with_k_vertices(n: int, k: int, points: List[Tuple[int, int]]) -> str:
""" Given n points in a 2D plane, determine if there exists a subset of these points
whose convex hull has exactly k vertices. If such a subset exists, return "YES"
followed by the i... | from itertools import combinations
from math import atan2
def convex_hull(points):
points = sorted(points, key=lambda p: (p[0], p[1]))
def cross(o, a, b):
return (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0])
lower = []
for p in points:
while len(lower) >= 2 and cross(l... | from solution import find_convex_hull_with_k_vertices
def test_example_1():
n = 5
k = 3
points = [(0, 0), (1, 0), (0, 1), (1, 1), (2, 2)]
result = find_convex_hull_with_k_vertices(n, k, points)
assert result.startswith("YES")
def test_example_2():
n = 4
k = 4
points = [(0, 0), (1, 0), ... | [
{
"docstring": null,
"function_declaration": "def convex_hull(points):",
"function_name": "convex_hull",
"parameter_list": "(points)"
},
{
"docstring": null,
"function_declaration": "def find_convex_hull_with_k_vertices(n, k, points):",
"function_name": "find_convex_hull_with_k_verti... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import itertools\nfrom scipy.spatial import ConvexHull\n\ndef find_convex_hull_subset(n, k, points):\n # Check if it is possible to form a subset of k v... | trial_gpt4o_2 | {
"original_instruction": "Given n points in a 2D plane, your task is to determine if there exists a subset of these points whose convex hull has exactly k vertices.\n\nA convex hull of a set of points is the smallest convex polygon that can enclose all the points. For example, given points that form a \"star\" shape... | 0.564744 | Code_Contests_43912 | C | [
"convex_hull",
"find_convex_hull_with_k_vertices"
] | 2 | [
[
"find_convex_hull_with_k_vertices",
"convex_hull"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5a55e3785cb4480b6fa9530ab7082624f1ac7cf0 | 0f667bcecc154be7e733b7371270d369ef5ee28c | |||
v1.0 | complete | Code_Contests | Code_Contests_43882_C | def is_fibonacci(num: int) -> bool:
"""
Check if a number is a Fibonacci number.
>>> is_fibonacci(1) True
>>> is_fibonacci(2) True
>>> is_fibonacci(4) False
"""
def largest_fibonacci_divisor(n: int, collection: List[int]) -> int:
"""
Return the largest Fibonacci number in collection... | def is_fibonacci(num):
"""
Check if a number is a Fibonacci number.
"""
if num <= 0:
return False
a, b = 0, 1
while b < num:
a, b = b, a + b
return b == num
def largest_fibonacci_divisor(n, collection):
"""
Return the largest Fibonacci number in collection that divid... | import pytest
from solution import largest_fibonacci_divisor, is_fibonacci
def test_is_fibonacci():
assert is_fibonacci(1) == True
assert is_fibonacci(2) == True
assert is_fibonacci(4) == False
assert is_fibonacci(8) == True
assert is_fibonacci(13) == True
assert is_fibonacci(21) == True
as... | [
{
"docstring": "Check if a number is a Fibonacci number.",
"function_declaration": "def is_fibonacci(num):",
"function_name": "is_fibonacci",
"parameter_list": "(num)"
},
{
"docstring": "Return the largest Fibonacci number in collection that divides n.\nIf no such number exists, return -1.",... | [
0,
0,
0,
0,
1,
0,
0,
0,
0
] | 1 | hard | 0.111 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def largest_fibonacci_divisor(n, collection):\n def is_fibonacci(num):\n f1, f2 = 0, 1\n while f2 <= num:\n if f2 == num:\n ... | trial_gpt4o_5 | {
"original_instruction": "Adam loves Fibonacci numbers! A positive integer x is called Fibonacci if and only if it appears in the Fibonacci sequence.\n\n<image>\n\nLucy has a collection of positive integers, and she wants to perform a special operation. The operation involves finding the largest Fibonacci number in ... | 0.743882 | Code_Contests_43882 | C | [
"is_fibonacci",
"largest_fibonacci_divisor"
] | 2 | [
[
"largest_fibonacci_divisor",
"is_fibonacci"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4239e679a7097c9c7e815a6cee5181122ed054b1 | fd57ad530c6d02f16e08511eb600da025a09c209 | |||
v1.0 | complete | Code_Contests | Code_Contests_43957_C | MOD = 1000000007
def generalized_fibonacci(F1, F2, n):
""" Compute the nth number in the generalized Fibonacci sequence starting with F1 and F2.
>>> generalized_fibonacci(1, 1, 5)
5
>>> generalized_fibonacci(3, 7, 4)
17
"""
pass
def solve_generalized_fibonacci(test_cases):
""" Solve ge... | MOD = 1000000007
def generalized_fibonacci(F1, F2, n):
if n == 1:
return F1 % MOD
elif n == 2:
return F2 % MOD
dp = [0] * (n + 1)
dp[1] = F1
dp[2] = F2
for i in range(3, n + 1):
dp[i] = (dp[i-1] + dp[i-2]) % MOD
return dp[n]
def solve_generalized_... | from solution import generalized_fibonacci, solve_generalized_fibonacci
def test_case1():
assert generalized_fibonacci(1, 1, 5) == 5
def test_case2():
assert generalized_fibonacci(3, 7, 4) == 17
def test_case3():
assert generalized_fibonacci(0, 1, 10) == 34
def test_case4():
assert generalized_fibon... | [
{
"docstring": null,
"function_declaration": "def generalized_fibonacci(F1, F2, n):",
"function_name": "generalized_fibonacci",
"parameter_list": "(F1, F2, n)"
},
{
"docstring": null,
"function_declaration": "def solve_generalized_fibonacci(test_cases):",
"function_name": "solve_gene... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "MOD = 1000000007\n\ndef generalized_fibonacci(F1, F2, n):\n if n == 1:\n return F1 % MOD\n elif n == 2:\n return F2 % MOD\n \n dp... | trial_gpt4o_0 | {
"original_instruction": "The Fibonacci sequence is a famous and simple example of a series of numbers where every number after the first two is the sum of the two preceding ones. Given this, we can extend the Fibonacci sequence to a generalized Fibonacci sequence where you are given the first two numbers F1 and F2,... | 0.706188 | Code_Contests_43957 | C | [
"generalized_fibonacci",
"solve_generalized_fibonacci",
"read_input"
] | 3 | [
[
"solve_generalized_fibonacci",
"generalized_fibonacci"
]
] | 1 | [
"read_input"
] | false | [] | false | pytest | true | [] | true | 4318e5c7cf2bffd92393d00341aec6210600ea59 | 761f6cd45640e7062facd9ab3b3ac2c3371e75f3 | |||
v1.0 | complete | Code_Contests | Code_Contests_44104_C | def rotate_matrix(input_string: str) -> str:
""" Rotates a given square matrix clockwise by 90 degrees.
Args:
input_string (str): A formatted string representing the matrix size and its elements.
Returns:
str: A formatted string representing the rotated matrix.
Example:
>>> ro... | def rotate_matrix_clockwise(matrix):
"""
Rotates a given n x n matrix clockwise by 90 degrees.
:param matrix: List of lists representing the n x n matrix
:return: New n x n matrix rotated clockwise by 90 degrees
"""
n = len(matrix)
rotated_matrix = [[0] * n for _ in range(n)]
for i... | def test_rotate_3x3_matrix():
input_matrix = '''3
1 2 3
4 5 6
7 8 9'''
expected_output = '''7 4 1
8 5 2
9 6 3'''
assert rotate_matrix(input_matrix) == expected_output
def test_rotate_4x4_matrix():
input_matrix = '''4
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16'''
expected_output = '''13 9 5 1
14 10 6 2
... | [
{
"docstring": "Rotates a given n x n matrix clockwise by 90 degrees.\n\n:param matrix: List of lists representing the n x n matrix\n:return: New n x n matrix rotated clockwise by 90 degrees",
"function_declaration": "def rotate_matrix_clockwise(matrix):",
"function_name": "rotate_matrix_clockwise",
... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def rotate_90_clockwise(matrix):\n \"\"\"\n Rotates a given square matrix clockwise by 90 degrees.\n \n Args:\n matrix (list of list of int)... | trial_gpt4o_2 | {
"original_instruction": "Design a function to rotate a given square matrix clockwise by 90 degrees. \n\n**Input**\n\nThe first line of the input contains an integer n (1 ≤ n ≤ 100), the size of the square matrix. The next n lines contain n integers each, denoting the matrix elements.\n\n**Output**\n\nOutput the mat... | 0.598349 | Code_Contests_44104 | C | [
"rotate_matrix_clockwise",
"read_matrix_input",
"matrix_to_string",
"rotate_matrix"
] | 4 | [
[
"rotate_matrix",
"matrix_to_string"
],
[
"rotate_matrix",
"read_matrix_input"
],
[
"rotate_matrix",
"rotate_matrix_clockwise"
]
] | 3 | [] | false | [] | false | pytest | false | [] | true | 359fa794f3569cb0952211000306ea793b773224 | 1b460e6740351866b2e4713b5f8739180543bf46 | |||
v1.0 | complete | Code_Contests | Code_Contests_44169_C | class TreeNode:
def __init__(self, val=0):
self.val = val
self.left = None
self.right = None
def build_tree(N, parents):
nodes = [TreeNode(i) for i in range(1, N+1)]
root = None
for i, p in enumerate(parents):
if p == -1:
root = nodes[i]
else:
... | class TreeNode:
def __init__(self, val=0):
self.val = val
self.left = None
self.right = None
def build_tree(N, parents):
nodes = [TreeNode(i) for i in range(1, N+1)]
root = None
for i, p in enumerate(parents):
if p == -1:
root = nodes[i]
else:
... | from solution import is_balanced_binary_tree
def test_balanced_tree_example_one():
assert is_balanced_binary_tree(5, [-1, 1, 1, 2, 2]) == "Yes"
def test_unbalanced_tree_example_two():
assert is_balanced_binary_tree(3, [-1, 1, 2]) == "No"
def test_single_node_tree():
assert is_balanced_binary_tree(1, [-1]... | [] | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, x):\n self.val = x\n self.left = None\n self.right = None\n\ndef build_tree(parents):\n nod... | trial_gpt4o_2 | {
"original_instruction": "You are given a binary tree with N nodes. Each node has a unique value between 1 and N. Determine if this binary tree is a height-balanced binary tree. A binary tree is height-balanced if for each node in the tree, the difference in the height of its left and right subtrees is at most 1.\n\... | 0.757642 | Code_Contests_44169 | C | [
"build_tree",
"check_balanced_tree",
"is_balanced_binary_tree"
] | 3 | [
[
"is_balanced_binary_tree",
"build_tree"
],
[
"is_balanced_binary_tree",
"check_balanced_tree"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 85396c5d3149fe7b1978e3c3e7d4c6b7e0948d73 | 137b10ec9e5b506b69bad8c72229011dadb22da4 | |||
v1.0 | complete | Code_Contests | Code_Contests_44597_C | from typing import List
def can_be_palindrome(s: str) -> bool:
"""
Determines if a string can be rearranged to form a palindrome.
"""
def check_strings_for_palindrome(N: int, strings: List[str]) -> List[str]:
"""
For each string in a list, prints "Possible" if the string can be rearranged to form ... | def can_be_palindrome(s):
"""
Determines if a string can be rearranged to form a palindrome.
"""
from collections import Counter
count = Counter(s)
odd_count = sum(1 for element in count.values() if element % 2 != 0)
return odd_count <= 1
def check_strings_for_palindrome(N, strings):
""... | def test_can_be_palindrome():
assert can_be_palindrome("aabb") == True
assert can_be_palindrome("abc") == False
assert can_be_palindrome("racecar") == True
assert can_be_palindrome("aabbccdde") == True
assert can_be_palindrome("a") == True
assert can_be_palindrome("ab") == False
assert can_b... | [
{
"docstring": "Determines if a string can be rearranged to form a palindrome.",
"function_declaration": "def can_be_palindrome(s):",
"function_name": "can_be_palindrome",
"parameter_list": "(s)"
},
{
"docstring": "For each string in a list, prints \"Possible\" if the string can be rearrange... | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def can_form_palindrome(strings):\n \"\"\"\n Determines if each string in the list can be rearranged to form a palindrome.\n \n :param strings:... | trial_gpt4o_4 | {
"original_instruction": "Emily is a software developer who loves playing with strings. She recently came across a unique problem involving palindromes and now seeks your help to solve it.\n\nA palindrome is a word that reads the same forward and backward. Emily wants you to determine whether a string can be rearran... | 0.819174 | Code_Contests_44597 | C | [
"can_be_palindrome",
"check_strings_for_palindrome"
] | 2 | [
[
"check_strings_for_palindrome",
"can_be_palindrome"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 119e86fce7678ccae0ed0f5d50fd9e2a7ab553fe | 4110a8a9caca9a909eadd579232cb0f260950043 | |||
v1.0 | complete | Code_Contests | Code_Contests_44628_C | from typing import List, Tuple
def minimum_edges_to_remove(n: int, edges: List[Tuple[int, int, int]]) -> int:
""" Determine the smallest number of edges that need to be removed in order to make the graph acyclic.
>>> minimum_edges_to_remove(5, [(0, 1, 4), (0, 2, 3), (1, 2, 1), (1, 3, 2), (3, 4, 6), (2, 4, 5)])... | from collections import defaultdict
def find(parent, i):
if parent[i] == i:
return i
else:
parent[i] = find(parent, parent[i])
return parent[i]
def union(parent, rank, x, y):
xroot = find(parent, x)
yroot = find(parent, y)
if xroot != yroot:
if rank[xroot] < rank[y... | from solution import minimum_edges_to_remove
def test_case_1():
N = 5
edges = [
(0, 1, 4),
(0, 2, 3),
(1, 2, 1),
(1, 3, 2),
(3, 4, 6),
(2, 4, 5)
]
assert minimum_edges_to_remove(N, edges) == 2
def test_case_2():
N = 4
edges = [
(0, 1, 1),... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
0,
0,
0,
1,
1
] | 2 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_parent(parent, i):\n if parent[i] == i:\n return i\n else:\n parent[i] = find_parent(parent, parent[i])\n return parent... | trial_gpt4o_3 | {
"original_instruction": "You are given an undirected, weighted graph with N vertices and M edges. The vertices are numbered from 0 to N-1, and each edge connects two different vertices with a given weight. Your task is to determine the smallest number of edges that need to be removed in order to make the graph acyc... | 0.546172 | Code_Contests_44628 | C | [
"find",
"union",
"minimum_edges_to_remove",
"main"
] | 4 | [
[
"minimum_edges_to_remove",
"find"
],
[
"minimum_edges_to_remove",
"union"
],
[
"union",
"find"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 597503129dc981530110f56d2ecc60d367f9ee33 | e44d262d540530cd76584608f40cc8e3c26517cb | |||
v1.0 | complete | Code_Contests | Code_Contests_43687_C | import math
from typing import List
def has_perfect_square_subarray(N: int, arr: List[int]) -> str:
"""
Determines if there exists a non-empty subarray
whose product is a perfect square.
Args:
N : int : the number of elements in the array
arr : list of int : the array of positive integers... | import math
def has_perfect_square_subarray(N, arr):
"""
Determines if there exists a non-empty subarray
whose product is a perfect square.
Args:
N : int : the number of elements in the array
arr : list of int : the array of positive integers
Returns:
str : "Yes" if a subarra... | from solution import has_perfect_square_subarray, is_perfect_square
def test_has_perfect_square_subarray_example1():
assert has_perfect_square_subarray(5, [1, 3, 9, 4, 2]) == "Yes"
def test_has_perfect_square_subarray_example2():
assert has_perfect_square_subarray(4, [2, 3, 5, 7]) == "No"
def test_has_perfec... | [
{
"docstring": "Determines if there exists a non-empty subarray \nwhose product is a perfect square.\n\nArgs:\nN : int : the number of elements in the array\narr : list of int : the array of positive integers\n\nReturns:\nstr : \"Yes\" if a subarray whose product is a perfect square exists, otherwise \"No\"",
... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_perfect_square(x):\n \"\"\"\n Check if x is a perfect square.\n \"\"\"\n return int(x ** 0.5) ** 2 == x\n\ndef has_perfect_square_subarr... | trial_gpt4o_1 | {
"original_instruction": "Given an array of N positive integers, you need to determine if there exists a non-empty subarray whose product is a perfect square. \n\nA subarray is a contiguous part of an array and a perfect square is an integer that is the square of an integer.\n\nReturn \"Yes\" if there exists such a ... | 0.625902 | Code_Contests_43687 | C | [
"has_perfect_square_subarray",
"is_perfect_square"
] | 2 | [
[
"has_perfect_square_subarray",
"is_perfect_square"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a6989afbc61c2dcae6a802965b6a48378ed5fb30 | adaee4d62d145ae65e82d046793d8217bc2262a9 | |||
v1.0 | complete | Code_Contests | Code_Contests_44595_C | def find_minimum_cycle(N: int, M: int, connections: List[Tuple[int, int, int]]) -> int:
"""Find the minimum time required to complete a cycle in the barns' connections.
Returns -1 if no cycle exists.
Args:
N : int : The number of barns.
M : int : The number of connections.
connections : List[Tu... | import heapq
def find_minimum_cycle(N, M, connections):
def dijkstra(src):
""" Run Dijkstra's algorithm from a source node """
dist = [float('inf')] * (N + 1)
dist[src] = 0
priority_queue = [(0, src)]
while priority_queue:
current_dist, current_node = he... | from solution import find_minimum_cycle_helper
def test_example_1():
N, M = 4, 4
connections = [
(1, 2, 4),
(2, 3, 2),
(3, 4, 3),
(4, 2, 1)
]
assert find_minimum_cycle_helper(N, M, connections) == 6
def test_example_2():
N, M = 3, 3
connections = [
(1, 2... | [
{
"docstring": null,
"function_declaration": "def find_minimum_cycle(N, M, connections):",
"function_name": "find_minimum_cycle",
"parameter_list": "(N, M, connections)"
},
{
"docstring": null,
"function_declaration": "def find_minimum_cycle_helper(N, M, connections):",
"function_nam... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import sys\nimport heapq\n\ndef find_min_cycle(N, M, connections):\n def dijkstra(start):\n dist = [sys.maxsize] * (N + 1)\n dist[start] =... | trial_gpt4o_1 | {
"original_instruction": "Maxim the Farmer has recently built a series of connected barns for his cows. Each barn is a node, and each connection between two barns is an edge with a specific time it takes to travel between them. He wants to ensure that if a cow starts from a barn and goes through a sequence of connec... | 0.62588 | Code_Contests_44595 | C | [
"find_minimum_cycle",
"find_minimum_cycle_helper"
] | 2 | [
[
"find_minimum_cycle_helper",
"find_minimum_cycle"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | abe2840fb0bb9610b9c6f04b517bcca67d8b0b0a | b96ce40af317ba95682e23b08342b7797a2fb75d | |||
v1.0 | complete | Code_Contests | Code_Contests_49624_C | def kth_prime(k: int) -> int:
""" Tara loves playing with numbers, and she is particularly fond of prime numbers.
Write a function that takes an integer k and returns the k-th prime number.
Constraints:
* 1 ≤ k ≤ 200
Examples:
>>> kth_prime(5)
11
>>> kth_prime(10)
29
""... | 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 kth_prime(k):
count = 0
num = 1
... | from solution import kth_prime
def test_kth_prime_first_prime():
assert kth_prime(1) == 2
def test_kth_prime_small_primes():
assert kth_prime(2) == 3
assert kth_prime(3) == 5
assert kth_prime(4) == 7
assert kth_prime(5) == 11
def test_kth_prime_larger_prime():
assert kth_prime(10) == 29
def ... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def kth_prime(k):",
"function_name": "kth_prime",
"parameter_list": "(k)"
}
] | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n 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 ... | trial_gpt4o_0 | {
"original_instruction": "Tara loves playing with numbers, and she is particularly fond of prime numbers. She is generating a sequence of prime numbers and wants to know the k-th prime number in the generated sequence. Because prime numbers are a fundamental concept and useful in various fields, she decides to write... | 0.67885 | Code_Contests_49624 | C | [
"is_prime",
"kth_prime"
] | 2 | [
[
"kth_prime",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5e5dc571867cd1cd305789f078175c16b64fa335 | 10ddc8e9e3109b4fba1c67f1614637b3e08075a0 | |||
v1.0 | complete | Code_Contests | Code_Contests_49580_C | def min_operations(n, node_values, edges):
"""
Find the minimum number of operations required to convert the entire tree into a uniform binary tree.
Input:
- n: int, the number of nodes in the binary tree.
- node_values: List[int], the values assigned to the nodes in the tree.
... | def find_min_operations(n, node_values, edges):
from collections import defaultdict
graph = defaultdict(list)
for u, v in edges:
graph[u].append(v)
graph[v].append(u)
def dfs(node, parent):
count_0 = 0 if node_values[node - 1] else 1
count_1 = 1 if node_values[node - 1]... | def test_single_node():
assert min_operations(1, [0], []) == 0
assert min_operations(1, [1], []) == 0
def test_all_same():
assert min_operations(3, [0, 0, 0], [(1, 2), (1, 3)]) == 0
assert min_operations(3, [1, 1, 1], [(1, 2), (1, 3)]) == 0
def test_simple_case():
assert min_operations(3, [1, 0, 0... | [
{
"docstring": null,
"function_declaration": "def find_min_operations(n, node_values, edges):",
"function_name": "find_min_operations",
"parameter_list": "(n, node_values, edges)"
},
{
"docstring": null,
"function_declaration": "def min_operations(n, node_values, edges):",
"function_... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def min_operations_to_uniform_tree(n, values, edges):\n from collections import defaultdict\n\n # Build adjacency list for the tree\n tree = defau... | trial_gpt4o_2 | {
"original_instruction": "You are given a binary tree with n nodes. Each node is assigned a value, which is initially set to 0 or 1. You are allowed to perform certain operations to convert the tree into a uniform binary tree where all nodes have the same value.\n\nIn one operation, you can select any subtree of the... | 0.642273 | Code_Contests_49580 | C | [
"find_min_operations",
"min_operations"
] | 2 | [
[
"min_operations",
"find_min_operations"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | ec4fbd0ee8f3e6a7bd97ba176b3d794c44ca0b84 | 367649ce99e67592c4d6946700afdfc16798f808 | |||
v1.0 | complete | Code_Contests | Code_Contests_49635_C | def maximalRectangle(matrix):
""" Tommy wants to fence off the largest possible rectangular sub-garden of soil cells only.
Determine the area of this largest rectangular sub-garden.
>>> maximalRectangle([[1, 0, 1, 1, 1], [1, 1, 1, 1, 1], [0, 1, 1, 1, 0], [1, 1, 0, 1, 1]])
6
>>> maximalRectangle([[1,... | def maximalRectangle(matrix):
if not matrix:
return 0
n = len(matrix)
m = len(matrix[0])
heights = [0] * m
max_area = 0
for row in matrix:
for i in range(m):
if row[i] == 0:
heights[i] = 0
else:
heights[i] += ... | def test_maximalRectangle_small():
assert maximalRectangle([[1, 0, 1, 1, 1], [1, 1, 1, 1, 1], [0, 1, 1, 1, 0], [1, 1, 0, 1, 1]]) == 6
def test_maximalRectangle_single():
assert maximalRectangle([[1, 0, 1], [0, 1, 0], [1, 0, 1]]) == 1
def test_maximalRectangle_empty():
assert maximalRectangle([]) == 0
def... | [
{
"docstring": null,
"function_declaration": "def maximalRectangle(matrix):",
"function_name": "maximalRectangle",
"parameter_list": "(matrix)"
},
{
"docstring": null,
"function_declaration": "def largestRectangleArea(heights):",
"function_name": "largestRectangleArea",
"paramete... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def maximalRectangle(matrix):\n if not matrix:\n return 0\n\n n = len(matrix)\n m = len(matrix[0])\n \n max_area = 0\n heights = [... | trial_gpt4o_1 | {
"original_instruction": "Tommy is a passionate gardener. He has a rectangular garden of size \\(n \\times m\\) (n rows and m columns). Each cell in the garden either contains soil that can be cultivated, represented by 1, or a pond that cannot be used for planting, represented by 0.\n\nTommy wants to fence off the ... | 0.653437 | Code_Contests_49635 | C | [
"maximalRectangle",
"largestRectangleArea"
] | 2 | [
[
"maximalRectangle",
"largestRectangleArea"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | eb3ac114d4f034a0c6328d1e44c3e3dfe9c8b796 | 5ec16d72647cd672e9d58b9aa5ce8489c23e562b | |||
v1.0 | complete | Code_Contests | Code_Contests_49598_C | def minimum_spanning_tree(n: int, m: int, edges: List[Tuple[int, int, int]]) -> int:
"""Determine the sum of weights in the minimum spanning tree of the graph.
Args:
n (int): The number of vertices.
m (int): The number of edges.
edges (List[Tuple[int, int, int]]): List of edges where each edge is re... | def find(parent, i):
if parent[i] == i:
return i
else:
parent[i] = find(parent, parent[i])
return parent[i]
def union(parent, rank, x, y):
root_x = find(parent, x)
root_y = find(parent, y)
if rank[root_x] < rank[root_y]:
parent[root_x] = root_y
elif rank[roo... | from solution import minimum_spanning_tree
def test_example_case():
n = 4
m = 5
edges = [
(1, 2, 5),
(1, 3, 3),
(4, 2, 7),
(3, 4, 4),
(2, 3, 6)
]
assert minimum_spanning_tree(n, m, edges) == 12
def test_single_edge():
n = 2
m = 1
edges = [
... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef minimum_spanning_tree(n, m, edges):\n \"\"\"\n Returns the sum of weights in the minimum spanning tree of the graph.\n Uses Kr... | trial_gpt4o_4 | {
"original_instruction": "Given an undirected connected graph with `n` vertices and `m` edges, where each edge has a positive weight. Determine the sum of weights in the minimum spanning tree of the graph.\n\nInput\n\nThe first line contains integers `n` and `m` (`1 ≤ n ≤ 1000`, `0 ≤ m ≤ 10000`). The following `m` l... | 0.763464 | Code_Contests_49598 | C | [
"find",
"union",
"kruskal",
"minimum_spanning_tree"
] | 4 | [
[
"kruskal",
"find"
],
[
"kruskal",
"union"
],
[
"minimum_spanning_tree",
"kruskal"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | a882fe39ba74a4bcf4a2deaaa1127375dd3fc7c6 | 8ef16178d4d647dd38bf2aedddc1bb4d21dddaec | |||
v1.0 | complete | Code_Contests | Code_Contests_44685_C | class FenwickTree:
def __init__(self, size):
self.size = size
self.tree = [0] * (size + 1)
def update(self, index, delta):
while index <= self.size:
self.tree[index] += delta
index += index & -index
def prefix_sum(self, index):
total = 0
whil... | class FenwickTree:
def __init__(self, size):
self.size = size
self.tree = [0] * (size + 1)
def update(self, index, delta):
while index <= self.size:
self.tree[index] += delta
index += index & -index
def prefix_sum(self, index):
total = 0
whil... | def test_process_operations():
n = 5
operations = [
(2, 1, 3),
(1, 2, 4, 1),
(2, 2, 4),
(1, 3, 5, 2),
(2, 1, 5)
]
array = [1, 2, 3, 4, 5]
expected_output = [6, 12, 24]
assert process_operations(n, operations, array) == expected_output
def test_single_elem... | [] | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class SegmentTree:\n def __init__(self, data):\n self.n = len(data)\n self.tree = [0] * (2 * self.n)\n self.lazy = [0] * self.n\n ... | trial_gpt4o_1 | {
"original_instruction": "You are given an array of integers and two types of operations that can be performed on it. Your task is to write a program that can efficiently handle these operations and output the required results.\n\nOperation Types:\n1. Increase the value of a given range by a given value.\n2. Calcula... | 0.535904 | Code_Contests_44685 | C | [
"initialize_array_and_fenwick_tree",
"increase_range",
"sum_range",
"process_operations"
] | 4 | [
[
"process_operations",
"increase_range"
],
[
"process_operations",
"initialize_array_and_fenwick_tree"
],
[
"process_operations",
"sum_range"
]
] | 3 | [] | false | [
"FenwickTree"
] | true | pytest | false | [] | true | ed047fe3d7176a0471a4301d5815594ac73065ae | 51184147c8243084471b42df0eb8509dcae70143 | |||
v1.0 | complete | Code_Contests | Code_Contests_44471_C | from typing import List, Tuple
def find_item_positions(warehouse: List[List[int]]) -> dict:
""" Find the positions of all items in the warehouse grid.
Args:
warehouse: List[List[int]] - A 2D list of integers representing the warehouse grid.
Returns:
dict: A dictionary where keys are item ... | def find_item_positions(warehouse):
item_positions = {}
for i in range(len(warehouse)):
for j in range(len(warehouse[0])):
if warehouse[i][j] != 0:
item_positions[warehouse[i][j]] = (i, j)
return item_positions
def manhattan_distance(x1, y1, x2, y2):
return abs(x1 - ... | def test_find_item_positions():
warehouse = [
[1, 0, 3],
[0, 2, 0],
[4, 0, 5]
]
expected_positions = {1: (0, 0), 3: (0, 2), 2: (1, 1), 4: (2, 0), 5: (2, 2)}
assert find_item_positions(warehouse) == expected_positions
def test_manhattan_distance():
assert manhattan_distance(0... | [
{
"docstring": null,
"function_declaration": "def find_item_positions(warehouse):",
"function_name": "find_item_positions",
"parameter_list": "(warehouse)"
},
{
"docstring": null,
"function_declaration": "def manhattan_distance(x1, y1, x2, y2):",
"function_name": "manhattan_distance"... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def robot_pickup_path(warehouse, start_x, start_y, item_ids):\n def manhattan_distance(x1, y1, x2, y2):\n return abs(x1 - x2) + abs(y1 - y2)\n\n ... | trial_gpt4o_2 | {
"original_instruction": "A company is developing a new automated warehouse system. In this system, items are stored in racks that have specific positions marked by coordinates in a 2D grid. The robot can navigate the grid to pick and place items. Each rack has a unique coordinate (x, y) representing its position.\n... | 0.545022 | Code_Contests_44471 | C | [
"find_item_positions",
"manhattan_distance",
"robot_path"
] | 3 | [
[
"robot_path",
"find_item_positions"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 1a6c2633fcdc348b889d603c2de0e6c7f7724ee0 | 08f072026a0aaf8be8aeadceedf32012f830065f | |||
v1.0 | complete | Code_Contests | Code_Contests_49792_C | from typing import List, Tuple
def parse_input(input_lines: str) -> List[List[Tuple[int, int]]]:
""" Parse the input string and return the test cases data.
"""
def count_unique_squares(points: List[Tuple[int, int]]) -> int:
""" Count the number of unique squares that can be formed from the given points.
... | from collections import defaultdict
def count_unique_squares(points):
points_set = set((x, y) for x, y in points)
n = len(points)
lookup = defaultdict(int)
for i in range(n):
for j in range(i + 1, n):
(x1, y1) = points[i]
(x2, y2) = points[j]
if (x1 != x... | from solution import unique_squares, parse_input
def test_case_1():
input_data = "1\n4\n0 0\n0 1\n1 0\n1 1\n"
test_cases = parse_input(input_data)
assert unique_squares(test_cases) == [1]
def test_case_2():
input_data = "1\n5\n0 0\n0 1\n1 0\n1 1\n2 2\n"
test_cases = parse_input(input_data)
ass... | [
{
"docstring": null,
"function_declaration": "def count_unique_squares(points):",
"function_name": "count_unique_squares",
"parameter_list": "(points)"
},
{
"docstring": null,
"function_declaration": "def unique_squares(test_cases):",
"function_name": "unique_squares",
"parameter... | [
0,
0,
0,
0,
0,
0,
0,
1,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def count_unique_squares(points):\n \"\"\"\n Function to count unique squares that can be formed with the given points.\n points: List of tuples (... | trial_gpt4o_7 | {
"original_instruction": "You are given `N` points on a 2D coordinate plane. Each point can be represented as (x, y). Your task is to determine how many unique squares can be formed using these points as the vertices.\n\nNote: A square is defined as a quadrilateral with all four sides of equal length and all interna... | 0.553227 | Code_Contests_49792 | C | [
"count_unique_squares",
"unique_squares",
"parse_input"
] | 3 | [
[
"unique_squares",
"count_unique_squares"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | d79d412efd500cb22d95e9346d6cd4507fdf2375 | f641b90fc515b8b69d9c71aee04f5af837f6d8b7 | |||
v1.0 | complete | Code_Contests | Code_Contests_49724_C | def find_connected_components(n, edges):
"""
Find the number of connected components in an undirected graph.
"""
from collections import defaultdict, deque
def bfs(start):
queue = deque([start])
visited[start] = True
while queue:
node = queue.popleft()
... | def find_connected_components(n, edges):
"""
Find the number of connected components in an undirected graph.
"""
from collections import defaultdict, deque
def bfs(start):
queue = deque([start])
visited[start] = True
while queue:
node = queue.popleft()
... | from solution import min_new_paths_to_add, park_paths
def test_example_case_1():
assert park_paths(5, 3, ["1 2", "2 3", "4 5"]) == 1
def test_example_case_2():
assert park_paths(4, 1, ["1 2"]) == 2
def test_example_case_3():
assert park_paths(4, 4, ["1 2", "2 3", "3 4", "4 1"]) == 0
def test_single_land... | [
{
"docstring": "Find the number of connected components in an undirected graph.",
"function_declaration": "def find_connected_components(n, edges):",
"function_name": "find_connected_components",
"parameter_list": "(n, edges)"
},
{
"docstring": "Returns the minimum number of new paths that n... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_connected_components(n, edges):\n \"\"\"\n Find the number of connected components in an undirected graph.\n \"\"\"\n from collections... | trial_gpt4o_0 | {
"original_instruction": "Alex is a city planner responsible for designing a new park with a network of connected walking paths. The park can be represented as a undirected graph where vertices represent park landmarks, and edges represent walking paths between those landmarks. Due to certain construction constraint... | 0.634841 | Code_Contests_49724 | C | [
"find_connected_components",
"min_new_paths_to_add",
"park_paths"
] | 3 | [
[
"min_new_paths_to_add",
"find_connected_components"
],
[
"park_paths",
"min_new_paths_to_add"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | d94f62034209dc3d17a8f4fa36e0199e8d713ac9 | b714df862a460cc8b785db58ac4cb48101142ae7 | |||
v1.0 | complete | Code_Contests | Code_Contests_49785_C | from typing import List, Tuple
from collections import deque, defaultdict
def count_valid_start_islands(n: int, d: int, k: int, known_islands: List[int], bridges: List[Tuple[int, int]]) -> int:
""" In an enchanting forest, there are n mystical islands interconnected by exactly n-1 magical bridges.
Each bridge... | from collections import deque, defaultdict
def bfs_distance(n, start, edges):
# Using BFS to calculate distances from the start island
queue = deque([start])
distances = [-1] * (n + 1)
distances[start] = 0
while queue:
current = queue.popleft()
for neighbor in edges[cu... | from solution import count_valid_start_islands
def test_example_1():
n = 7
d = 3
k = 2
known_islands = [3, 4, 5]
bridges = [(1, 2), (2, 3), (3, 4), (4, 5), (5, 6), (6, 7)]
assert count_valid_start_islands(n, d, k, known_islands, bridges) == 3
def test_example_2():
n = 5
d = 2
k = 1... | [
{
"docstring": null,
"function_declaration": "def bfs_distance(n, start, edges):",
"function_name": "bfs_distance",
"parameter_list": "(n, start, edges)"
},
{
"docstring": null,
"function_declaration": "def count_valid_start_islands(n, d, k, known_islands, bridges):",
"function_name"... | [
0,
0,
0,
0,
0,
0,
0,
1,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_islands(n, d, k, q, bridges):\n from collections import defaultdict, deque\n \n def bfs(start, adjacency_list):\n # BFS to get dis... | trial_gpt4o_7 | {
"original_instruction": "In an enchanting forest, there are n mystical islands interconnected by exactly n-1 magical bridges. Each bridge links a pair of islands and it is possible to travel between any two islands using one or more bridges. The Great Wizard of the forest has a flying broomstick that can help him q... | 0.649858 | Code_Contests_49785 | C | [
"bfs_distance",
"count_valid_start_islands"
] | 2 | [
[
"count_valid_start_islands",
"bfs_distance"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 405671e8b01b341e51f6440cb0309fc81a3f359f | 66afc62489878d76f9d11e15245d21bc0b7de983 | |||
v1.0 | complete | Code_Contests | Code_Contests_49721_C | def min_cost_wall(M: int, N: int, cost_matrix: List[List[int]]) -> int:
"""
Find the minimum cost of building a continuous vertical wall from the top row to the bottom row
with allowed moves to directly below, diagonally left, or diagonally right cell.
Parameters:
M (int): The number of ro... | def min_cost_to_build_wall(cost):
if not cost or not cost[0]:
return 0
M, N = len(cost), len(cost[0])
dp = [[0]*N for _ in range(M)]
# Initialize the first row of dp array to the cost of the top row
for j in range(N):
dp[0][j] = cost[0][j]
# Build the dp array
... | from solution import min_cost_wall
def test_example_1():
cost_matrix = [
[1, 3, 1, 5],
[2, 2, 4, 1],
[5, 1, 2, 3]
]
assert min_cost_wall(3, 4, cost_matrix) == 4
def test_example_2():
cost_matrix = [
[10, 2, 1],
[1, 2, 10]
]
assert min_cost_wall(2, 3, cos... | [
{
"docstring": null,
"function_declaration": "def min_cost_to_build_wall(cost):",
"function_name": "min_cost_to_build_wall",
"parameter_list": "(cost)"
},
{
"docstring": null,
"function_declaration": "def min_cost_wall(M, N, cost_matrix):",
"function_name": "min_cost_wall",
"para... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def min_cost_to_build_wall(cost):\n if not cost or not cost[0]:\n return 0\n \n M, N = len(cost), len(cost[0])\n dp = [[0]*N for _ in ra... | trial_gpt4o_0 | {
"original_instruction": "You are given a matrix of size M x N where each cell represents the cost to build a wall on that cell. You need to find the minimum cost of building a continuous vertical wall from the top row to the bottom row. You are allowed to start from any cell in the top row and can move to the cell ... | 0.599212 | Code_Contests_49721 | C | [
"min_cost_to_build_wall",
"min_cost_wall"
] | 2 | [
[
"min_cost_wall",
"min_cost_to_build_wall"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 60590faa4246b27409796ab8d8dfbbbd74b702ec | 751b4bd1523af843dc454916a257592d1b502a7d | |||
v1.0 | complete | Code_Contests | Code_Contests_23766_C | from typing import List, Tuple
def is_prime(n: int) -> bool:
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 find_primes(numbers: List[int]) -... | def is_prime(n):
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 find_primes(numbers):
"""
Returns a tuple containing a list of prime n... | from solution import find_primes
def test_find_primes_example_case():
assert find_primes([-5, 0, 2, 3, 4, 5, 10, 11, 13, 16, 17]) == ([2, 3, 5, 11, 13, 17], 6)
def test_find_primes_no_primes():
assert find_primes([-5, 0, 1, 4, 6, 8, 10]) == ([], 0)
def test_find_primes_all_primes():
assert find_primes([2... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a tuple containing a list of prime numbers found in the input list\nand the count of prime numbers.",
"function_declaration": "def find_primes(... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Helper function to determine if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n ... | trial_gpt4o_2 | {
"original_instruction": "Create a function that takes a single list of integers as input and returns a new list containing only the prime numbers from the original list. The function should also return the count of prime numbers found.\n\n## Input format\nA single list containing integers, which may include negativ... | 0.771461 | Code_Contests_23766 | C | [
"is_prime",
"find_primes"
] | 2 | [
[
"find_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d996f39d404d32ac43a8c810a0eafe61b18f3594 | e445e1db9a468ea6c240f30c132e21855e724c4e | |||
v1.0 | complete | Evol | Evol_10_C | from typing import List
def is_prime(n: int) -> bool:
"""
Returns True if n is a prime number, otherwise False.
"""
pass
def sum_of_primes(input_array: List[int]) -> int:
"""
Returns the sum of all prime numbers in the input_array.
Example:
>>> sum_of_primes([10, 15, 3, 7, 19, 21,... | from typing import List
def is_prime(n: int) -> bool:
"""
Returns True if n is a prime number, otherwise False.
"""
if n <= 1:
return False
for i in range(2, int(n ** 0.5) + 1):
if n % i == 0:
return False
return True
def sum_of_primes(input_array: List[int]) -> int... | from solution import sum_of_primes, is_prime
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(29) == True
assert is_prime(1) == False
assert is_prime(0) == False
assert is_prime(-5) == False
def test_sum_of_primes():
... | [
{
"docstring": "Returns True if n is a prime number, otherwise False.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns the sum of all prime numbers in the input_array.",
"function_declaration": "def sum_of_prime... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl",
"solution_code": "from typing import List\n\ndef is_prime(num: int) -> bool:\n if num <= 1:\n return False\n if num == 2:\n return True\n if num % 2 == 0:\n ... | trial_gpt4o_9 | {
"original_instruction": "You are given a list of integers and you need to find and return the sum of all the prime numbers contained in the list. A prime number is defined as a number greater than 1 that has no positive divisors other than 1 and itself. Write a function that accomplishes this task.\ninput_array = [... | 0.760843 | Evol_10 | C | [
"is_prime",
"sum_of_primes"
] | 2 | [
[
"sum_of_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f0ff061a67b932c9aa93ccc21cfcb7360f5a0c79 | dc37f01d5608cae4b295f028a71f9dacf19bafd5 | |||
v1.0 | complete | Evol | Evol_14_C | def is_prime(n: int) -> bool:
"""
Determines if a given number is a prime number.
"""
pass
def sum_of_digits(n: int) -> int:
"""
Returns the sum of the digits of a given number.
"""
pass
def prime_digit_sum(lst: List[int]) -> Dict[int, int]:
"""
Returns a dictionary where the k... | def is_prime(n):
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return False
return True
def sum_of_digits(n):
return sum(int(digit) for digit in str(n))
def prime_digi... | from solution import prime_digit_sum
def test_prime_digit_sum_with_primes():
assert prime_digit_sum([2, 3, 5, 7, 11, 13, 17]) == {2: 2, 3: 3, 5: 5, 7: 7, 11: 2, 13: 4, 17: 8}
def test_prime_digit_sum_with_mixed_numbers():
assert prime_digit_sum([4, 6, 8, 9, 10, 11, 13]) == {11: 2, 13: 4}
def test_prime_digit... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def sum_of_digits(n):",
"function_name": "sum_of_digits",
"parameter_list": "(n)"
},
{
"docstring": "Retu... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Check if a number is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n ... | trial_gpt4o_1 | {
"original_instruction": "Develop a Python function that takes a list of integers and returns a dictionary. The dictionary keys should be the integers from the list that are prime numbers, and the value for each key should be the sum of the digits of that prime number. Ensure your function is optimized for efficienc... | 0.726854 | Evol_14 | C | [
"is_prime",
"sum_of_digits",
"prime_digit_sum"
] | 3 | [
[
"prime_digit_sum",
"is_prime"
],
[
"prime_digit_sum",
"sum_of_digits"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | e74d700fed2ff4a1e22b971389ed656c808586e8 | bb05cd4a6a790db0f85b200651934d5722691cd9 | |||
v1.0 | complete | Evol | Evol_25_C | def largest_prime_factors(lst):
""" Write a Python function that takes as input a list of integers and returns a list of the largest prime factor of each integer.
If an integer is prime or less than 2, return the integer itself.
>>> largest_prime_factors([10, 15, 3, 1, 28])
[5, 5, 3, 1, 7]
>>> ... | def largest_prime_factor(n):
if n <= 1:
return n
i = 2
while i * i <= n:
if n % i:
i += 1
else:
n //= i
return n
def largest_prime_factors(lst):
return [largest_prime_factor(n) for n in lst] | from solution import largest_prime_factors
def test_empty_list():
assert largest_prime_factors([]) == []
def test_prime_numbers():
assert largest_prime_factors([2, 3, 5, 7, 11, 13]) == [2, 3, 5, 7, 11, 13]
def test_composite_numbers():
assert largest_prime_factors([10, 15, 21, 28]) == [5, 5, 7, 7]
def t... | [
{
"docstring": null,
"function_declaration": "def largest_prime_factor(n):",
"function_name": "largest_prime_factor",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def largest_prime_factors(lst):",
"function_name": "largest_prime_factors",
"parameter_li... | [
1,
1,
0,
1,
1,
1,
1,
1,
0,
1
] | 8 | easy | 0.8 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl",
"solution_code": "import math\n\ndef is_prime(n):\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n return False\... | trial_gpt4o_9 | {
"original_instruction": "Write a Python function that takes as input a list of integers and returns a list of the largest prime factor of each integer. If an integer is prime or less than 2, return the integer itself. For the implementation, ensure that you consider efficiency by leveraging any mathematical optimiz... | 0.835551 | Evol_25 | C | [
"largest_prime_factor",
"largest_prime_factors"
] | 2 | [
[
"largest_prime_factors",
"largest_prime_factor"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b8e602e00d794de67f3089ca3bd2e767d0d190d3 | 3f8ee4acb483e00eeafc22762513e54f034ce950 | |||
v1.0 | complete | Evol | Evol_53_C | def sort_nested_dicts(data, key):
""" Sort a list of nested dictionaries by a specified key at any depth.
Returns the sorted list. If the key is not present in any of the dictionaries,
returns the original list.
>>> data = [
... {"level1": {"level2": {"id": 3, "value": "C"}}},
... {"leve... | def find_key(d, key):
"""
Helper function that recursively searches for the key in nested dictionaries.
Returns the value if the key is found, otherwise returns None.
"""
if key in d:
return d[key]
for k, v in d.items():
if isinstance(v, dict):
result = find_key(v, ke... | from solution import sort_nested_dicts
def test_sort_nested_dicts_with_present_key():
data = [
{"level1": {"level2": {"id": 3, "value": "C"}}},
{"level1": {"level2": {"id": 1, "value": "A"}}},
{"level1": {"level2": {"id": 2, "value": "B"}}},
{"level1": {"info": {"name": "D"}}}
]... | [
{
"docstring": "Helper function that recursively searches for the key in nested dictionaries.\nReturns the value if the key is found, otherwise returns None.",
"function_declaration": "def find_key(d, key):",
"function_name": "find_key",
"parameter_list": "(d, key)"
},
{
"docstring": "Sorts ... | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
1
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl",
"solution_code": "def sort_nested_dicts(data, key):\n \"\"\"\n Sorts a list of nested dictionaries by a specified key at any depth.\n \n Args:\n data (list): A list o... | trial_gpt4o_9 | {
"original_instruction": "Develop a Python function that sorts a list of nested dictionaries by a specified key at any depth, and returns the sorted list. The function should accept two arguments: the list of dictionaries and the key. If the key is not present in any of the dictionaries, the original list should be ... | 0.564322 | Evol_53 | C | [
"find_key",
"sort_nested_dicts"
] | 2 | [
[
"sort_nested_dicts",
"find_key"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 039c381653214f66825adf0459dec750583056e8 | 38e5c68ae02133dfc891a9dcec4b01f548ea6210 | |||
v1.0 | complete | Evol | Evol_70_C | def shift_string(s: str, shift: int = 3) -> str:
"""Returns a new string where each character is shifted by 'shift' positions in the alphabet.
Non-alphabetic characters remain unchanged.
Parameters:
s (str): The input string to be shifted.
shift (int): The number of positions to shift each ... | def shift_char(c, shift):
if c.islower():
return chr((ord(c) - ord('a') + shift) % 26 + ord('a'))
elif c.isupper():
return chr((ord(c) - ord('A') + shift) % 26 + ord('A'))
else:
return c
def shift_string(s, shift=3):
"""
Returns a new string where each character is shifted b... | from solution import shift_string
def test_shift_lowercase_letters():
assert shift_string("abc") == "def"
assert shift_string("xyz") == "abc"
def test_shift_uppercase_letters():
assert shift_string("ABC") == "DEF"
assert shift_string("XYZ") == "ABC"
def test_shift_mixed_case_letters():
assert shi... | [
{
"docstring": null,
"function_declaration": "def shift_char(c, shift):",
"function_name": "shift_char",
"parameter_list": "(c, shift)"
},
{
"docstring": "Returns a new string where each character is shifted by 'shift' positions in the alphabet.\nNon-alphabetic characters remain unchanged.\n... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl",
"solution_code": "def shift_string(input_str):\n \"\"\"\n Shifts each letter in the input string by 3 positions in the alphabet, maintaining the case.\n Non-alphabetic char... | trial_gpt4o_9 | {
"original_instruction": "Design a function that takes a string consisting of lowercase and uppercase letters and returns a new string where each character is shifted by 3 positions in the alphabet, maintaining the original case. For example, 'a' becomes 'd', 'Z' becomes 'C'. Include error handling for non-alphabeti... | 0.78387 | Evol_70 | C | [
"shift_char",
"shift_string"
] | 2 | [
[
"shift_string",
"shift_char"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8fba9e3aa0ce10e4442c0c68c943962e2e72ef86 | 6f54789697ce832fa137979a68f37e8bdd47144c | |||
v1.0 | complete | Evol | Evol_78_C | def evaluate_expressions(expressions: List[str]) -> List[int]:
""" Takes a list of arithmetic expression strings and returns the evaluated results as a list.
>>> evaluate_expressions(["3+5*2"]) == [13]
>>> evaluate_expressions(["3+5*2", "(2+3)*(5-2)", "10/2-1"]) == [13, 15, 4]
>>> evaluate_expressions([... | def evaluate_expression(expression):
"""
Evaluates a single arithmetic expression string and returns the result
"""
def apply_operator(operators, operands):
operator = operators.pop()
right_operand = operands.pop()
left_operand = operands.pop()
if operator == '+':
... | from solution import evaluate_expressions
def test_single_expression():
assert evaluate_expressions(["3+5*2"]) == [13]
def test_multiple_expressions():
expressions = ["3+5*2", "(2+3)*(5-2)", "10/2-1"]
results = [13, 15, 4]
assert evaluate_expressions(expressions) == results
def test_division_and_subt... | [
{
"docstring": "Evaluates a single arithmetic expression string and returns the result",
"function_declaration": "def evaluate_expression(expression):",
"function_name": "evaluate_expression",
"parameter_list": "(expression)"
},
{
"docstring": "Takes a list of arithmetic expression strings a... | [
0,
0,
0,
0,
0,
0,
0,
0,
1,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl",
"solution_code": "import operator\n\n# Helper function to perform arithmetic operations\ndef operate(a, b, op):\n if op == '+':\n return a + b\n elif op == '-':\n ... | trial_gpt4o_8 | {
"original_instruction": "Create a program that takes a list of strings as input, where each string represents an arithmetic expression consisting of non-negative integers and the operators '+', '-', '*', and '/'. The program should evaluate each expression and return a list of results corresponding to the input exp... | 0.708395 | Evol_78 | C | [
"evaluate_expression",
"evaluate_expressions"
] | 2 | [
[
"evaluate_expressions",
"evaluate_expression"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 26845f1116c94d7c060dd479f7d83cff0dec0f4c | 79707519c8eb218249ff3314d7a5a16fb5fc0943 | |||
v1.0 | complete | Evol | Evol_98_C | def sum_of_factorials(numbers: str) -> int:
"""Compute the sum of the factorials of each integer in the comma-separated input string.
>>> sum_of_factorials('1,2,3')
9
>>> sum_of_factorials('4,5')
144
>>> sum_of_factorials('6')
720
""" | def factorial(n):
"""
Helper function to compute the factorial of a given number n.
"""
if n == 0:
return 1
result = 1
for i in range(1, n + 1):
result *= i
return result
def sum_of_factorials(numbers: str) -> int:
"""
Compute the sum of the factorials of each intege... | from solution import sum_of_factorials
def test_sum_of_factorials():
assert sum_of_factorials('1,2,3') == 9 # 1! + 2! + 3! = 1 + 2 + 6 = 9
assert sum_of_factorials('4,5') == 144 # 4! + 5! = 24 + 120 = 144
assert sum_of_factorials('6') == 720 # 6! = 720
assert sum_of_factorials('0') == 1 #... | [
{
"docstring": "Helper function to compute the factorial of a given number n.",
"function_declaration": "def factorial(n):",
"function_name": "factorial",
"parameter_list": "(n)"
},
{
"docstring": "Compute the sum of the factorials of each integer in the comma-separated input string.",
"... | [
1,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl",
"solution_code": "def factorial(n):\n \"\"\"\n Helper function to compute the factorial of a given number n.\n \"\"\"\n if n == 0:\n return 1\n result = 1\n ... | trial_gpt4o_0 | {
"original_instruction": "Write a function that takes a string of comma-separated integers and returns the sum of the factorial of each integer. You can assume that the input string is always valid and contains at least one integer.\n\ndef sum_of_factorials(numbers: str) -> int:\n \"\"\"Compute the sum of the fac... | 0.705375 | Evol_98 | C | [
"factorial",
"sum_of_factorials"
] | 2 | [
[
"sum_of_factorials",
"factorial"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ca4b767493f50c7dd2849f80a20bfb1e7b0ec525 | fb5e9c1e8127cf7727395616a4c010955520c6d8 | |||
v1.0 | complete | Evol | Evol_77_C | def find_prime_numbers(start: int, end: int) -> List[int]:
"""
Write a Python function named `find_prime_numbers` that takes two integers, `start` and `end`, as parameters
and returns a list of all prime numbers between `start` and `end` (inclusive). A prime number is a natural
number greater than 1 t... | def is_prime(n):
"""
Helper function to check if a number is prime.
"""
if n <= 1:
return False
elif n <= 3:
return True
elif 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
... | from solution import find_prime_numbers
def test_primes_in_middle_range():
assert find_prime_numbers(10, 30) == [11, 13, 17, 19, 23, 29]
def test_no_primes():
assert find_prime_numbers(0, 1) == []
def test_single_prime_range():
assert find_prime_numbers(2, 2) == [2]
def test_large_prime_range():
ass... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list of all prime numbers between start and end (inclusive).",
"function_declaration": "def find_... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl",
"solution_code": "def find_prime_numbers(start, end):\n \"\"\"\n Returns a list of prime numbers between `start` and `end` (inclusive).\n \"\"\"\n def is_prime(n):\n ... | trial_gpt4o_9 | {
"original_instruction": "Write a Python function named `find_prime_numbers` that takes two integers, `start` and `end`, as parameters and returns a list of all prime numbers between `start` and `end` (inclusive). A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself... | 0.723593 | Evol_77 | C | [
"is_prime",
"find_prime_numbers"
] | 2 | [
[
"find_prime_numbers",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 82b44539dd349235c50c5a104348feb51e3c542e | dba5be32574f16f4de3ed08e5ef0d996af0d2944 | |||
v1.0 | complete | Evol | Evol_91_C | # Chat Server
import asyncio
import websockets
connected_clients = {}
async def broadcast(message):
if connected_clients:
await asyncio.wait([client.send(message) for client in connected_clients.values()])
async def handle_client(websocket, path):
client_id = websocket.remote_address
connected_cl... | # Chat Server
import asyncio
import websockets
connected_clients = {}
async def broadcast(message):
if connected_clients:
await asyncio.wait([client.send(message) for client in connected_clients.values()])
async def handle_client(websocket, path):
client_id = websocket.remote_address
connected_cl... | import asyncio
from websockets import connect, serve
import pytest
@pytest.mark.asyncio
async def test_chat_server():
async def mock_client(send_message):
uri = "ws://localhost:6789"
async with connect(uri) as websocket:
if send_message:
await websocket.send(send_message... | [] | [
1,
0,
0,
1,
1,
1,
0,
1,
1,
1
] | 7 | easy | 0.7 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl",
"solution_code": "import asyncio\nimport websockets\n\nconnected_clients = {}\n\nasync def broadcast_message(message, sender_ws):\n for client_ws in connected_clients:\n i... | trial_gpt4o_3 | {
"original_instruction": "Implement a simple chat application using WebSockets in Python. Your application should allow multiple clients to connect to the server and exchange messages in real-time. The server should broadcast each message it receives to all connected clients. Do not use any third-party libraries exc... | 0.562148 | Evol_91 | C | [
"broadcast",
"handle_client",
"main",
"send_message",
"receive_message",
"main"
] | 6 | [
[
"handle_client",
"broadcast"
]
] | 1 | [] | false | [] | false | pytest | false | [
"websockets"
] | false | 845ab5571845893d39dc1262a311f1bb57f28505 | 35d5dd21a82b3a8233c640cc63d012f09960b16a | |||
v1.0 | complete | Evol | Evol_96_C | def is_prime(n: int) -> bool:
""" Checks if a number is a prime.
>>> is_prime(2) True
>>> is_prime(4) False
"""
pass
def filter_primes(numbers: List[int]) -> List[int]:
""" Filters the prime numbers from a list of integers.
>>> filter_primes([2, 3, 5, 7]) [2, 3, 5, 7]
>>> filter_primes(... | def is_prime(n):
"""
Checks 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 += 6
return T... | from solution import filter_primes
def test_filter_primes_all_primes():
assert filter_primes([2, 3, 5, 7]) == [2, 3, 5, 7]
def test_filter_primes_no_primes():
assert filter_primes([4, 6, 8, 10]) == []
def test_filter_primes_mixed():
assert filter_primes([4, 6, 7, 10, 13]) == [7, 13]
def test_filter_prim... | [
{
"docstring": "Checks if a number is a prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Filters the prime numbers from a list of integers.",
"function_declaration": "def filter_primes(numbers):",
"function_n... | [
0,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 9 | easy | 0.9 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_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": "Implement 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. Ensure your solution is efficient for large lists of integers. Make use of list comprehensions and a helper function to check primality. Avo... | 0.793088 | Evol_96 | C | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 91e09698429e3fb7607ce94db0e2fe092043574e | b378ce69fe47e33b11eee6bde25e458083dce5ba | |||
v1.0 | complete | Evol | Evol_141_C | def is_prime(n: int) -> bool:
"""
Returns True if n is a prime number, False otherwise.
>>> is_prime(2) True
>>> is_prime(4) False
"""
def prime_factors(n: int) -> list:
"""
Returns a list of all prime factors of n in ascending order.
>>> prime_factors(28) [2, 2, 7]
>>> prime_factor... | def is_prime(n):
"""
Returns True if n is a prime number, False otherwise.
"""
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 prime_... | from solution import is_prime, prime_factors
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(11) == True
assert is_prime(1) == False
assert is_prime(0) == False
assert is_prime(-5) == False... | [
{
"docstring": "Returns True if n is a prime number, False otherwise.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list of all prime factors of n in ascending order.",
"function_declaration": "def prime_fa... | [
1,
1,
0,
1,
1,
1,
0,
1,
1,
1
] | 8 | easy | 0.8 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Returns True if the input integer n is a prime number, else returns False.\n \"\"\"\n if n <= 1:\n return False\n ... | trial_gpt4o_8 | {
"original_instruction": "Write a Python function named `is_prime` that takes a single integer argument `n` and returns `True` if `n` is a prime number, and `False` otherwise. Additionally, write a second function `prime_factors` that uses `is_prime` to return a list of all prime factors of a given integer `n` in as... | 0.762495 | Evol_141 | C | [
"is_prime",
"prime_factors"
] | 2 | [
[
"prime_factors",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 55feea0068459deb01c4fb6ab3f99b646901f3fd | e2f65d0f5d1a120d1d4e3e87b6f9eaacd2ca99d4 | |||
v1.0 | complete | Evol | Evol_135_C | import re
def is_valid_ipv4(ip: str) -> bool:
"""
Check if the given IP address is a valid IPv4 address.
>>> is_valid_ipv4("192.168.0.1") == True
>>> is_valid_ipv4("256.256.256.256") == False
"""
...
def filter_valid_ipv4_addresses(ip_addresses: list) -> list:
"""
Filters out the valid... | import re
def is_valid_ipv4(ip):
"""
Check if the given IP address is a valid IPv4 address.
"""
pattern = r'^(\d{1,3}\.){3}\d{1,3}$'
if re.match(pattern, ip):
parts = ip.split('.')
for part in parts:
if int(part) < 0 or int(part) > 255:
return False
... | from solution import filter_valid_ipv4_addresses, is_valid_ipv4
def test_is_valid_ipv4():
assert is_valid_ipv4("192.168.0.1") == True
assert is_valid_ipv4("256.256.256.256") == False
assert is_valid_ipv4("10.0.0.123") == True
assert is_valid_ipv4("192.168.1") == False
assert is_valid_ipv4("172.16.2... | [
{
"docstring": "Check if the given IP address is a valid IPv4 address.",
"function_declaration": "def is_valid_ipv4(ip):",
"function_name": "is_valid_ipv4",
"parameter_list": "(ip)"
},
{
"docstring": "Filters out the valid IPv4 addresses from the given list of IP addresses.\n\nParameters:\n ... | [
1,
1,
0,
1,
1,
1,
1,
1,
1,
1
] | 9 | easy | 0.9 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl",
"solution_code": "import re\n\ndef is_valid_ipv4(ip):\n \"\"\"\n Checks if the given IP address is a valid IPv4 address.\n \"\"\"\n try:\n parts = ip.split('.')\n... | trial_gpt4o_8 | {
"original_instruction": "You are given a list of strings, each representing a potentially valid IPv4 address. Write a Python function that filters out and returns only the valid IPv4 addresses from the list. Each string in the list should be checked to see if it follows the IPv4 format, which is four decimal number... | 0.70783 | Evol_135 | C | [
"is_valid_ipv4",
"filter_valid_ipv4_addresses"
] | 2 | [
[
"filter_valid_ipv4_addresses",
"is_valid_ipv4"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 289eef99a3857c6c8958446ff36ca83e1bcfb80f | 0d01bc158ca08895190428750b4415f559d246ae |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.