Dataset Viewer
Auto-converted to Parquet Duplicate
gpt_difficulty
stringclasses
3 values
prompt
listlengths
1
1
prompt_tokens
int64
21
984
question_id
stringlengths
8
23
style
stringclasses
1 value
subset
stringclasses
12 values
test
stringlengths
130
3.64k
easy
[ { "content": "You are given an array of integers representing the heights of the buildings in a city skyline. The array is structured such that heights[i] is the height of the ith building. \n\nWrite a program that calculates the maximum area of a rectangle formed by any combination of contiguous buildings.\n\n...
85
Leetcode_23789_I
instruct
Leetcode
from solution import maxRectangleArea def test_single_building(): assert maxRectangleArea([5]) == 5 def test_two_buildings_same_height(): assert maxRectangleArea([2, 2]) == 4 def test_two_buildings_different_heights(): assert maxRectangleArea([2, 1]) == 2 def test_three_buildings_increasing_height(): ...
easy
[ { "content": "### Context\nAn online platform aims to assist users in managing their daily tasks by organizing them into different priority levels. Users can add tasks with varying levels of priority and the system needs to find and report the three highest priority tasks.\n\n### Problem Statement\nWrite a func...
548
Algorithm_12011_I
instruct
Algorithm
from solution import top_three_tasks def test_example_cases(): assert top_three_tasks([("Task A", 2), ("Task B", 5), ("Task C", 3)]) == ["Task B", "Task C", "Task A"] assert top_three_tasks([("Go for a walk", 1)]) == ["Go for a walk"] assert top_three_tasks([("Task A", 1), ("Task B", 2), ("Task C", 3), ("T...
easy
[ { "content": "Given a matrix of integers, write a Python program to find all unique rows that have the highest sum of elements. If there are multiple rows with the same highest sum, include all of them in the output. Also, check if any of the rows are exactly the same (i.e., identical elements in the respective...
85
Filter_35279_I
instruct
Filter
from solution import find_unique_rows_with_highest_sum def test_all_unique_rows_highest_sum(): matrix = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] result = find_unique_rows_with_highest_sum(matrix) assert result == [[7, 8, 9]] def test_multiple_identical_highest_sum_rows(): matrix...
medium
[ { "content": "Create a function that takes a string input and returns the string in reverse order with all special characters removed.", "role": "user" } ]
33
Prefill_17448_I
instruct
Prefill
from solution import reverse_and_remove_special_characters def test_reverse_and_remove_special_characters_only_alphanumeric(): assert reverse_and_remove_special_characters("abcdef") == "fedcba" assert reverse_and_remove_special_characters("12345") == "54321" def test_reverse_and_remove_special_characters_mixe...
easy
[ { "content": "Write a Python function that takes a list of integers and returns the product of all the unique numbers in it. If the list is empty, return 1.\n\n#### Function Signature\n\n```python\ndef product_of_unique_numbers(nums: List[int]) -> int:\n pass\n```\n\n#### Input\n\n- `nums` (List[int]): A lis...
313
Code_Contests_42828_I
instruct
Code_Contests
from solution import product_of_unique_numbers def test_product_of_unique_numbers_normal_case(): assert product_of_unique_numbers([2, 3, 4, 3, 2, 1]) == 24 def test_product_of_unique_numbers_single_repeated_element(): assert product_of_unique_numbers([7, 7, 7]) == 7 def test_product_of_unique_numbers_include...
hard
[ { "content": "You are given a string consisting of lowercase alphabets and digits. Write a function that counts the number of vowels (a, e, i, o, u) and the number of digits in the string, and returns them as a tuple (number_of_vowels, number_of_digits).\n\nThe function should be implemented as follows:\n- Defi...
146
Codeforces_16328_I
instruct
Codeforces
from solution import count_vowels_and_digits def test_vowels_and_digits(): assert count_vowels_and_digits('hello123') == (2, 3) assert count_vowels_and_digits('abcde') == (2, 0) assert count_vowels_and_digits('12345') == (0, 5) def test_no_vowels_and_no_digits(): assert count_vowels_and_digits('bcdfgh...
easy
[ { "content": "Can you provide a Python function to convert an integer to a string?", "role": "user" } ]
26
Filter_70506_I
instruct
Filter
from solution import int_to_string def test_int_to_string_positive(): assert int_to_string(123) == "123" def test_int_to_string_negative(): assert int_to_string(-456) == "-456" def test_int_to_string_zero(): assert int_to_string(0) == "0"
easy
[ { "content": "Create a function that reverses a string passed as an argument and returns the reversed string. The function should handle both uppercase and lowercase letters, and ignore any non-alphabetic characters. For example, reversing the string \"Hello, World!\" should return \"!dlroW ,olleH\".", "rol...
70
Prefill_23652_I
instruct
Prefill
def test_reverse_string_simple(): assert reverse_string("abc") == "cba" def test_reverse_string_with_punctuation(): assert reverse_string("Hello, World!") == "!dlroW ,olleH" def test_reverse_string_with_numbers(): assert reverse_string("123abc") == "cba321" def test_reverse_string_with_mixed_case(): ...
medium
[ { "content": "Can you generate a code snippet in Python for a function that reads a CSV file and returns a list of dictionaries, where each dictionary represents a row in the CSV file?", "role": "user" } ]
46
Filter_78863_I
instruct
Filter
import pytest from solution import read_csv_file import csv import os # Helper function to create a temporary CSV file for testing def create_temp_csv(filename, content): with open(filename, mode='w', newline='') as file: writer = csv.DictWriter(file, fieldnames=content[0].keys()) writer.writeheade...
easy
[ { "content": "Create a function that takes two arguments - a list and a number. The function should return a new list with the number inserted at the beginning of the list.", "role": "user" } ]
44
Prefill_26235_I
instruct
Prefill
from solution import insert_at_beginning def test_insert_at_beginning_with_empty_list(): assert insert_at_beginning([], 5) == [5] def test_insert_at_beginning_with_non_empty_list(): assert insert_at_beginning([1, 2, 3], 0) == [0, 1, 2, 3] def test_insert_at_beginning_with_negative_number(): assert insert...
medium
[ { "content": "Can you help me with a coding challenge I'm stuck on? I need to reverse the words in a sentence in Python but keep the order of the words the same. For example, if I input \"Hello world\", I want to get \"olleH dlrow\". How can I achieve this?", "role": "user" } ]
72
Filter_57017_I
instruct
Filter
from solution import reverse_words_in_sentence def test_reverse_words_single_word(): assert reverse_words_in_sentence("Hello") == "olleH" def test_reverse_words_multiple_words(): assert reverse_words_in_sentence("Hello world") == "olleH dlrow" assert reverse_words_in_sentence("Python is fun") == "nohtyP s...
easy
[ { "content": "Create a function that returns the number of non-overlapping sub-strings of length 3 that can be formed from a given string.", "role": "user" } ]
39
Prefill_25368_I
instruct
Prefill
from solution import count_non_overlapping_substrings def test_count_short_string(): assert count_non_overlapping_substrings("") == 0 assert count_non_overlapping_substrings("ab") == 0 def test_count_exact_length(): assert count_non_overlapping_substrings("abc") == 1 assert count_non_overlapping_subst...
easy
[ { "content": "You are given an integer array `heights` representing the heights of buildings situated on a street. Your task is to determine the maximum area of a rectangular block that can be formed between these buildings, considering each building has a width of 1. The area of the block is given by the heigh...
101
Leetcode_39704_I
instruct
Leetcode
def test_max_rectangular_area(): assert max_rectangular_area([2, 1, 5, 6, 2, 3]) == 10 assert max_rectangular_area([2, 4]) == 4 assert max_rectangular_area([1, 1, 1, 1, 1, 1]) == 6 assert max_rectangular_area([6, 5, 4, 3, 2, 1]) == 12 assert max_rectangular_area([1, 2, 3, 4, 5, 6]) == 12 assert ...
easy
[ { "content": "### Rotated String Check\n\nYou are given two strings `s1` and `s2`. Your task is to determine if `s2` is a rotation of `s1`. A string rotation involves shifting the characters of a string to the left or the right to form another string. For example, \"abcde\" shifted left by 2 characters becomes ...
383
Data_Structure_45231_I
instruct
Data_Structure
from solution import is_rotated def test_identical_strings(): assert is_rotated("abc", "abc") == True def test_simple_rotation(): assert is_rotated("hello", "llohe") == True def test_not_rotation(): assert is_rotated("hello", "helol") == False def test_empty_strings(): assert is_rotated("", "") == T...
easy
[ { "content": "### Context\nA leetcode problem involves generating all possible subsets of a given list of distinct integers. This problem assesses your understanding of bit manipulation and the ability to generate power sets efficiently.\n\n### Task\nWrite a function `generate_subsets(nums)` that takes in a lis...
315
Data_Structure_31747_I
instruct
Data_Structure
def test_generate_subsets_empty(): assert generate_subsets([]) == {()} def test_generate_subsets_single_element(): assert generate_subsets([1]) == {(), (1,)} def test_generate_subsets_two_elements(): assert generate_subsets([1, 2]) == {(), (1,), (2,), (1, 2)} def test_generate_subsets_three_elements(): ...
easy
[ { "content": "Implement a function called `replace_elements` that takes a list of integers `nums` and an integer `val`, and replaces every occurrence of `val` in the list with double its value. The function should return the updated list. The function should iterate over the list one time only (O(n) time comple...
327
Package_941_I
instruct
Package
def test_replace_elements_basic(): assert replace_elements([1, 2, 3, 2, 4], 2) == [1, 4, 3, 4, 4] def test_replace_elements_single_occurrence(): assert replace_elements([5, 6, 7, 8], 7) == [5, 6, 14, 8] def test_replace_elements_no_occurrence(): assert replace_elements([1, 2, 3, 4], 5) == [1, 2, 3, 4] de...
easy
[ { "content": "Write a function that takes a list of integers and returns a new list containing only the even numbers from the original list.\n\n``` \nInput: [1, 2, 3, 4, 5, 6]\nOutput: [2, 4, 6]\n```", "role": "user" } ]
73
Taco_55515_I
instruct
Taco
from solution import filter_even_numbers def test_filter_even_numbers_mixed(): assert filter_even_numbers([1, 2, 3, 4, 5, 6]) == [2, 4, 6] def test_filter_even_numbers_all_odd(): assert filter_even_numbers([1, 3, 5, 7]) == [] def test_filter_even_numbers_all_even(): assert filter_even_numbers([2, 4, 6, 8...
easy
[ { "content": "**Question: Advanced Sequence and Mapping Manipulation**\n\nGiven a list of dictionaries, each dictionary representing information about an item, write a function `process_items` that performs the following tasks:\n1. **Filter**: Remove dictionaries that do not contain a specified key `required_ke...
859
Docs: Python310_30016_I
instruct
Docs
from solution import process_items def test_process_items_example_case(): items = [ {'name': 'apple', 'price': 120, 'quantity': 5}, {'name': 'banana', 'price': 30, 'quantity': 10}, {'name': 'orange', 'price': 60, 'quantity': 15}, {'name': 'mango', 'price': 150, 'quantity': 7, 'disco...
easy
[ { "content": "Write a Python function that takes a list of dictionaries, where each dictionary represents a product with keys like 'id', 'name', 'price', and 'category'. The function should filter products based on a given category and return a list of dictionaries containing only the products from that categor...
84
Filter_74949_I
instruct
Filter
from solution import filter_and_sort_products def test_filter_and_sort_products_single_category(): products = [ {'id': 1, 'name': 'Product A', 'price': 100, 'category': 'Electronics'}, {'id': 2, 'name': 'Product B', 'price': 50, 'category': 'Electronics'}, {'id': 3, 'name': 'Product C', 'pr...
easy
[ { "content": "### Question\n\nYou are tasked with implementing a function that determines whether a given string follows a specific pattern. This scenario is common when ensuring that strings conform to template constraints, like validating formatted data input.\n\nWrite a function `word_pattern(pattern: str, i...
457
Data_Structure_12462_I
instruct
Data_Structure
from solution import word_pattern def test_pattern_with_valid_mapping(): assert word_pattern("abba", "dog cat cat dog") == True def test_pattern_with_invalid_mapping(): assert word_pattern("abba", "dog cat cat fish") == False def test_pattern_with_all_same_characters_and_different_words(): assert word_pa...
easy
[ { "content": "Given an `m x n` integer matrix, define the distance between two cells `(i1, j1)` and `(i2, j2)` as the absolute difference in their values. Find the maximum distance you can achieve between any two distinct cells in the matrix such that the value in the first cell is greater than the value in the...
104
Leetcode_38763_I
instruct
Leetcode
from solution import max_distance def test_basic_case(): matrix = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] assert max_distance(matrix) == 8 def test_negative_numbers(): matrix = [ [-1, -2, -3], [-4, -5, -6] ] assert max_distance(matrix) == 5 def test_mix...
medium
[ { "content": "[Problem:] Given a string of digits, determine if it's a valid phone number.\n\n[Input format:] A string containing only digits.\n\n[Output format:] A boolean value: `True` if the string represents a valid phone number, `False` otherwise.\n\n[Valid phone number definition:] A valid phone number me...
229
Filter_83217_I
instruct
Filter
from solution import is_valid_phone_number def test_valid_phone_number(): assert is_valid_phone_number("2125551212") == True def test_invalid_phone_number_too_short(): assert is_valid_phone_number("212555") == False def test_invalid_phone_number_too_long(): assert is_valid_phone_number("212555121234") ==...
easy
[ { "content": "### String Segmentation with Dictionary Words\n\nIn natural language processing, the problem of segmenting a string into meaningful words is quite common. Given a string without spaces and a dictionary of valid words, the goal is to determine if the string can be segmented into a sequence of valid...
402
Package_2660_I
instruct
Package
from solution import word_break def test_word_break_example1(): assert word_break("applepenapple", ["apple", "pen"]) == True def test_word_break_example2(): assert word_break("catsandog", ["cats", "dog", "sand", "and", "cat"]) == False def test_word_break_empty_string(): assert word_break("", ["apple", "...
medium
[ { "content": "### Problem: Dynamic Programming Binomial Coefficient\n\nYou are required to implement a function to compute the binomial coefficient \\( C(n, k) \\) using a dynamic programming approach. The binomial coefficient represents the number of ways to choose \\( k \\) items from \\( n \\) items without ...
606
Data_Structure_32048_I
instruct
Data_Structure
from solution import dp_binomial_coefficient def test_binomial_coefficient_base_cases(): assert dp_binomial_coefficient(5, 0) == 1 assert dp_binomial_coefficient(5, 5) == 1 def test_binomial_coefficient_small_numbers(): assert dp_binomial_coefficient(5, 2) == 10 assert dp_binomial_coefficient(8, 2) ==...
hard
[ { "content": "# Task\n\nGiven a string `s` consisting of lower-case alphabets and digits, find the longest substring that contains equal numbers of alphabets and digits. If there are multiple substrings with the same length, return the leftmost one. If there is no such substring, return an empty string.\n\n# Ex...
220
Apps_3223_I
instruct
Apps
def test_longest_balanced_substring_example1(): assert longest_balanced_substring("a1b2c") == "a1b2" def test_longest_balanced_substring_example2(): assert longest_balanced_substring("abc123") == "abc123" def test_longest_balanced_substring_example3(): assert longest_balanced_substring("a123bc45") == "a12...
hard
[ { "content": "You are given a list of intervals `intervals` where each interval is a pair of integers `[start, end]` representing a time period during which a job is being performed. Determine _the minimum number of intervals you need to remove_ to make the remaining intervals non-overlapping. Return _the numbe...
82
Leetcode_6620_I
instruct
Leetcode
from solution import min_intervals_to_remove def test_no_intervals(): assert min_intervals_to_remove([]) == 0 def test_non_overlapping_intervals(): assert min_intervals_to_remove([[1, 2], [3, 4], [5, 6]]) == 0 def test_all_intervals_overlapping(): assert min_intervals_to_remove([[1, 3], [1, 2], [1, 4]]) ...
easy
[ { "content": "Write a python function to print out all Fibonacci numbers below a certain number n.", "role": "user" } ]
28
Prefill_35310_I
instruct
Prefill
from solution import fibonacci_below_n def test_fibonacci_below_10(): assert fibonacci_below_n(10) == [0, 1, 1, 2, 3, 5, 8] def test_fibonacci_below_1(): assert fibonacci_below_n(1) == [0] def test_fibonacci_below_0(): assert fibonacci_below_n(0) == [] def test_fibonacci_below_20(): assert fibonacci...
medium
[ { "content": "Write a python function to remove duplicates from a string.", "role": "user" } ]
23
Prefill_42915_I
instruct
Prefill
from solution import remove_duplicates def test_remove_duplicates_all_unique(): assert remove_duplicates("abcdef") == "abcdef" def test_remove_duplicates_with_duplicates(): assert remove_duplicates("aabbcc") == "abc" assert remove_duplicates("banana") == "ban" def test_remove_duplicates_empty_string(): ...
easy
[ { "content": "Write a Python function that finds the second smallest element in an unsorted list of integers. The function should return the second smallest unique element. If the list does not contain at least two unique elements, the function should raise a ValueError.", "role": "user" } ]
59
Filter_70905_I
instruct
Filter
from solution import second_smallest def test_second_smallest_normal_case(): assert second_smallest([4, 1, 3, 2, 5]) == 2 def test_second_smallest_with_duplicates(): assert second_smallest([4, 1, 3, 2, 5, 2, 3, 4]) == 2 def test_second_smallest_with_negative_numbers(): assert second_smallest([-1, -3,...
easy
[ { "content": "### Matrix Rotation and Sum Challenge\n\nYou are tasked with implementing a function to rotate a square matrix by 90 degrees clockwise and then calculate the sum of the elements of the rotated matrix.\n\n#### Task:\n\nImplement the following function:\n1. `rotate_and_sum(matrix: List[List[int]]) -...
401
Algorithm_35844_I
instruct
Algorithm
def test_rotate_and_sum(): assert rotate_and_sum([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) == 45 assert rotate_and_sum([[1, 2], [3, 4]]) == 10 assert rotate_and_sum([[1]]) == 1 assert rotate_and_sum([]) == 0 assert rotate_and_sum([[0, 0, 0], [0, 0, 0], [0, 0, 0]]) == 0 assert rotate_and_sum([[1, -1], [...
easy
[ { "content": "Write a Python function to calculate the factorial of a given number 'n'. Ensure your function handles edge cases and performs error checking for invalid inputs. The function should be efficient and use recursion where appropriate. Define the function as follows:\n\n```python\ndef factorial(n):\n ...
192
Taco_63393_I
instruct
Taco
from solution import factorial import pytest def test_factorial_positive_integers(): assert factorial(5) == 120 assert factorial(4) == 24 def test_factorial_zero(): assert factorial(0) == 1 def test_factorial_one(): assert factorial(1) == 1 def test_factorial_large_number(): assert factorial(10)...
easy
[ { "content": "**Context**:\nYou are developing an application that handles sorted lists of integers. One critical operation in this application is to insert a new number in the correct position to maintain the list's sorted order. To do this efficiently, you need to determine the correct index at which the new ...
607
Data_Structure_47216_I
instruct
Data_Structure
def test_insert_index_middle(): assert insert_index([1, 3, 5, 6], 5) == 2 def test_insert_index_before_existing(): assert insert_index([1, 3, 5, 6], 2) == 1 def test_insert_index_end(): assert insert_index([1, 3, 5, 6], 7) == 4 def test_insert_index_beginning(): assert insert_index([1, 3, 5, 6], 0) =...
easy
[ { "content": "Mark has recently developed an interest in string compression algorithms. He came across a simple run-length encoding technique and decided to implement it himself. However, Mark is stuck and needs your help to write a function that uses the run-length encoding to compress a given string.\n\n### P...
451
Taco_26419_I
instruct
Taco
def test_run_length_encode_single_character(): assert run_length_encode("A") == "A1" def test_run_length_encode_continuous_run(): assert run_length_encode("AAAAA") == "A5" def test_run_length_encode_multiple_runs(): assert run_length_encode("AABBBCCCC") == "A2B3C4" def test_run_length_encode_no_repeats()...
hard
[ { "content": "In an autonomous vehicle system, the vehicle needs to navigate through a grid with different terrains that have varying traversal costs. The grid is represented by a two-dimensional list where each integer value corresponds to the cost of traversing that cell. The vehicle can only move right or do...
347
Codeforces_2102_I
instruct
Codeforces
from solution import min_cost_path def test_min_cost_path_example(): grid = [ [1, 3, 1], [1, 5, 1], [4, 2, 1] ] assert min_cost_path(grid) == 7 def test_min_cost_path_single_row(): grid = [[1, 2, 3, 4]] assert min_cost_path(grid) == 10 def test_min_cost_path_single_column(...
hard
[ { "content": "Please suggest a Python code snippet that performs a simple Monte Carlo simulation. A Monte Carlo simulation can be used to estimate the value of π (pi) by randomly generating points within a square and determining the ratio of points that fall inside a quarter circle to the total number of points...
68
Filter_67074_I
instruct
Filter
from solution import estimate_pi import math def test_estimate_pi_small_samples(): result = estimate_pi(1000) assert result > 2 and result < 4, f"Expected result to be between 2 and 4, but got {result}" def test_estimate_pi_medium_samples(): result = estimate_pi(10000) assert result > 3 and result < 3...
easy
[ { "content": "Create a function that returns the compliment of a DNA string (A-T and G-C) by mapping each letter of the DNA string to its compliment.", "role": "user" } ]
42
Filter_41601_I
instruct
Filter
from solution import complement_dna def test_complement_all_bases(): assert complement_dna('ATGC') == 'TACG' def test_complement_repeated_bases(): assert complement_dna('AAA') == 'TTT' assert complement_dna('GGG') == 'CCC' assert complement_dna('TTT') == 'AAA' assert complement_dna('CCC') == 'GGG'...
easy
[ { "content": "### Question\n\n#### Context\nSearching within a sorted array is a common task in many applications. The Binary Search algorithm is efficient for this purpose with a time complexity of O(log n). In this problem, you will implement a variant of Binary Search that not only determines the presence of...
448
Algorithm_11036_I
instruct
Algorithm
from solution import binary_search_first_occurrence def test_target_present(): assert binary_search_first_occurrence([1, 2, 4, 4, 4, 5, 6], 4) == 2 def test_target_absent(): assert binary_search_first_occurrence([1, 2, 3, 5, 6], 4) == -1 def test_empty_list(): assert binary_search_first_occurrence([], 4)...
easy
[ { "content": "Create a Python function that takes a dictionary with some keys and values, and returns a new dictionary where the keys and values are swapped. If a value is not unique, append the keys to a list. For example, given the dictionary `{'a': 1, 'b': 2, 'c': 1}`, the function should return `{1: ['a', '...
99
Filter_49295_I
instruct
Filter
from solution import swap_dict_keys_values def test_unique_values(): assert swap_dict_keys_values({'a': 1, 'b': 2, 'c': 3}) == {1: 'a', 2: 'b', 3: 'c'} def test_duplicate_values(): assert swap_dict_keys_values({'a': 1, 'b': 2, 'c': 1}) == {1: ['a', 'c'], 2: 'b'} def test_all_duplicate_values(): assert sw...
easy
[ { "content": "I will provide you with a list of strings. I want to create a function that can take this list of strings as input, and return a new list with all the strings that contain the character 'a' or 'A' (case insensitive). \n\nHere's my code so far:\n\n```python\ndef find_strings_with_a(strings):\n r...
161
Filter_7630_I
instruct
Filter
from solution import find_strings_with_a def test_strings_with_single_case(): strings = ["hello", "world", "apple", "Application", "123"] result = find_strings_with_a(strings) assert result == ["apple", "Application"] def test_strings_with_no_match(): strings = ["hello", "world", "123"] result = f...
hard
[ { "content": "You are given a string representing a simple mathematical expression containing non-negative integers and the operators `+`, `-`, and `*`. Write a function to evaluate this expression and return the result as an integer. The input string is guaranteed to be a valid expression.\n\n## Examples\n```p...
176
Apps_13045_I
instruct
Apps
from solution import evaluate_expression def test_evaluate_simple_addition(): assert evaluate_expression("3+2") == 5 def test_evaluate_simple_subtraction(): assert evaluate_expression("5-3") == 2 def test_evaluate_simple_multiplication(): assert evaluate_expression("4*2") == 8 def test_evaluate_simple_d...
medium
[ { "content": "You are given a list of integers representing the height of buildings in a city, where each building's width is the same. The goal is to find the maximum amount of water that can be trapped between the buildings after it rains. Write a function that takes the list of building heights and returns t...
80
Leetcode_2516_I
instruct
Leetcode
from solution import trap def test_trap_empty(): assert trap([]) == 0 def test_trap_no_trapping(): assert trap([1, 1, 1, 1]) == 0 assert trap([5, 4, 3, 2, 1]) == 0 def test_trap_basic_cases(): assert trap([0, 2, 0, 2]) == 2 assert trap([1, 3, 2, 1, 2, 3, 1]) == 4 def test_trap_complex_cases(): ...
hard
[ { "content": "You are given a list of integers representing the heights of students standing in a line, and your task is to determine the number of buildings that have an unobstructed view of the horizon.\n\nA building has an unobstructed view of the horizon if there are no taller buildings to the right of it.\...
310
Code_Contests_31119_I
instruct
Code_Contests
from solution import count_unobstructed_view def test_unobstructed_view_example1(): assert count_unobstructed_view([3, 7, 8, 3, 6, 1]) == 3 def test_unobstructed_view_example2(): assert count_unobstructed_view([1, 2, 3, 4, 5]) == 1 def test_unobstructed_view_example3(): assert count_unobstructed_view([5,...
easy
[ { "content": "### Coding Question\n\n#### Objective\nWrite a Python function that determines whether a list contains any duplicate elements.\n\n### Function Signature\n```python\ndef contains_duplicates(input_list: list) -> bool:\n \"\"\"\n Checks if a list contains any duplicate elements.\n \"\"\"\n``...
345
Algorithm_39793_I
instruct
Algorithm
from solution import contains_duplicates def test_contains_duplicates_no_duplicates(): assert contains_duplicates([1, 2, 3, 4, 5]) == False def test_contains_duplicates_with_duplicates(): assert contains_duplicates([1, 2, 2, 4, 5]) == True def test_contains_duplicates_with_strings(): assert contains_dupl...
easy
[ { "content": "Implement a function to determine the number of ways a given positive integer can be decomposed into a sum of non-negative integers. The function should be optimized for performance and use dynamic programming concepts.\n\n#### Function Signature:\n```python\ndef num_decompositions(n: int) -> int:...
209
Data_Structure_13680_I
instruct
Data_Structure
from solution import num_decompositions def test_num_decompositions_base_case(): assert num_decompositions(1) == 1 assert num_decompositions(2) == 2 assert num_decompositions(3) == 3 def test_num_decompositions_examples(): assert num_decompositions(4) == 5 assert num_decompositions(5) == 7 ass...
easy
[ { "content": "Write a Python function that takes two strings as input and returns True if one string is a permutation of the other, False otherwise. A permutation is a rearrangement of letters. The function must be case-sensitive and consider whitespace as valid characters. Implement this by verifying both stri...
113
Evol_5431_I
instruct
Evol
from solution import are_permutations def test_identical_strings(): assert are_permutations("abc", "abc") == True def test_different_strings(): assert are_permutations("abc", "def") == False def test_permutations_with_whitespace(): assert are_permutations("abc def", "fed cba") == True def test_case_sens...
easy
[ { "content": "Create a function that checks if a given number is a perfect square. If it is, return the square root of the number. If it is not, return -1. This function should work for both positive and negative integers. For negative numbers, the function should simply return -1.", "role": "user" } ]
70
Prefill_20226_I
instruct
Prefill
from solution import check_perfect_square def test_positive_perfect_square(): assert check_perfect_square(16) == 4 assert check_perfect_square(25) == 5 assert check_perfect_square(1) == 1 def test_positive_non_perfect_square(): assert check_perfect_square(15) == -1 assert check_perfect_square(26) ...
easy
[ { "content": "Implement a function called `merge_sorted_arrays` that takes two parameters:\n\n1. `arr1`: A list of integers sorted in non-decreasing order.\n2. `arr2`: A list of integers sorted in non-decreasing order.\n\nThe function should return a single list containing all the elements from both `arr1` and ...
256
Package_6344_I
instruct
Package
from solution import merge_sorted_arrays def test_merge_both_empty(): assert merge_sorted_arrays([], []) == [] def test_merge_first_empty(): assert merge_sorted_arrays([], [1, 2, 3]) == [1, 2, 3] def test_merge_second_empty(): assert merge_sorted_arrays([1, 2, 3], []) == [1, 2, 3] def test_merge_no_over...
easy
[ { "content": "Write a Python function that takes an input dictionary and returns a new dictionary with all the diagonal elements of a square matrix represented by the input dictionary. The keys in the dictionary represent the positions of the elements in the matrix, formatted as 'row,col' where row and col are ...
94
Filter_75390_I
instruct
Filter
from solution import get_diagonal_elements def test_get_diagonal_elements_3x3(): input_dict = { '0,0': 1, '0,1': 2, '0,2': 3, '1,0': 4, '1,1': 5, '1,2': 6, '2,0': 7, '2,1': 8, '2,2': 9 } expected_output = {'0,0': 1, '1,1': 5, '2,2': 9} assert get_diagonal_elements(input_dict) ==...
easy
[ { "content": "This program calculates the area of a triangle given its base and height.\n\nFunction:\n Takes two input arguments: `base` and `height`.\n Calculates the area using the formula: `area = 0.5 base height`.\n Returns the calculated area.\n\nCode (Python):\n\n```python\ndef triangle_area(base, heigh...
418
Filter_86128_I
instruct
Filter
from solution import triangle_area def test_triangle_area_positive_numbers(): assert triangle_area(10, 5) == 25.0 assert triangle_area(3, 4) == 6.0 def test_triangle_area_with_zero(): try: triangle_area(0, 5) except ValueError as e: assert str(e) == "Base must be a positive number." ...
hard
[ { "content": "You are given a string `str` containing only lowercase letters. A string is called **balanced** if every letter appears in it exactly the same number of times. Your task is to determine whether the given string is balanced. Return `true` _if_ `str` _is balanced_. Otherwise, return `false`.", "...
77
Leetcode_16535_I
instruct
Leetcode
from solution import is_balanced def test_empty_string(): assert is_balanced("") == True def test_single_character(): assert is_balanced("a") == True def test_balanced_string(): assert is_balanced("aabb") == True assert is_balanced("abcabc") == True assert is_balanced("zzxxcc") == True def test_...
easy
[ { "content": "I've been trying to solve a problem where I have to calculate the number of permutations of a multiset, or a set with repeated elements. I have found the formula for calculating it, but I need a Python code to implement this formula.", "role": "user" } ]
61
Filter_13046_I
instruct
Filter
from solution import multiset_permutations def test_distinct_elements(): assert multiset_permutations([1, 2, 3]) == 6 def test_all_same_element(): assert multiset_permutations([1, 1, 1]) == 1 def test_two_kinds_of_elements(): assert multiset_permutations([1, 1, 2, 2]) == 6 def test_three_kinds_of_elemen...
hard
[ { "content": "Given a matrix of dimensions `n x n` representing the connections in an undirected, weighted graph, where `matrix[i][j]` contains the weight of the edge between nodes `i` and `j`, and `matrix[i][j] = 0` indicates no direct edge exists between node `i` and node `j`. Design an algorithm to find the ...
137
Leetcode_41_I
instruct
Leetcode
from solution import dijkstra_shortest_path def test_no_path(): matrix = [ [0, 0, 0], [0, 0, 0], [0, 0, 0] ] assert dijkstra_shortest_path(matrix, 0, 1) == -1 def test_single_node(): matrix = [ [0] ] assert dijkstra_shortest_path(matrix, 0, 0) == 0 def test...
easy
[ { "content": "Manipulate the string \"Hello, World!\" using the correct Python function that will replace the word \"Hello\" with \"Goodbye\". Remember to consider different cases such as the string being in all uppercase or all lowercase, and ensure that the function can handle such cases. Additionally, make s...
117
Filter_41872_I
instruct
Filter
from solution import replace_hello_with_goodbye def test_replace_single_hello(): assert replace_hello_with_goodbye("Hello, World!") == "Goodbye, World!" def test_replace_single_hello_with_punctuation(): assert replace_hello_with_goodbye("Hello... World!") == "Goodbye... World!" def test_replace_hello_with_di...
easy
[ { "content": "Write a function `compare_adjacent` that takes an integer `n` and an array of `n` integers as input. The function should return a new array where every element is the product of adjacent elements from the input array. The input array will always contain at least two elements.\n\nExample:\n\n`compa...
362
Taco_98729_I
instruct
Taco
from solution import compare_adjacent def test_compare_adjacent_basic_cases(): assert compare_adjacent(5, [1, 2, 3, 4, 5]) == [2, 6, 12, 20] assert compare_adjacent(3, [10, 20, 30]) == [200, 600] assert compare_adjacent(4, [3, 7, 1, 8]) == [21, 7, 8] def test_compare_adjacent_min_cases(): assert compa...
easy
[ { "content": "Write a Python function that converts a string to a floating-point number. The function should handle both positive and negative numbers, as well as scientific notation. It should also raise a ValueError if the input string is not a valid floating-point number.", "role": "user" } ]
60
Filter_75347_I
instruct
Filter
from solution import string_to_float def test_string_to_float_valid(): assert string_to_float("3.14") == 3.14 assert string_to_float("-2.71") == -2.71 assert string_to_float("0.0") == 0.0 assert string_to_float("1e3") == 1000.0 assert string_to_float("-1.5e-2") == -0.015 def test_string_to_float_i...
easy
[ { "content": "Create a function that takes a list of integers and return the third largest number in the list. If the list has less than 3 unique numbers, return the maximum number in the list. If the list is empty, return an empty list. Use Python to solve this problem.", "role": "user" } ]
68
Prefill_18692_I
instruct
Prefill
from solution import third_largest def test_third_largest_with_three_or_more_unique_numbers(): assert third_largest([3, 1, 2, 4, 5]) == 3 assert third_largest([5, 4, 3, 2, 1]) == 3 assert third_largest([10, 8, 6, 4, 2]) == 6 def test_third_largest_with_less_than_three_unique_numbers(): assert third_la...
easy
[ { "content": "### FizzBuzz Variants\n\n#### Context:\nFizzBuzz is a popular problem used to teach and assess understanding of basic programming principles. You are asked to extend this basic problem in a manner that requires more advanced handling.\n\n#### Problem:\nWrite a function `fizzbuzz_variant(n, rules)`...
508
Data_Structure_20471_I
instruct
Data_Structure
from solution import fizzbuzz_variant def test_fizzbuzz_variant_basic(): assert fizzbuzz_variant(15, [(3, "Fizz"), (5, "Buzz")]) == [1, 2, "Fizz", 4, "Buzz", "Fizz", 7, 8, "Fizz", "Buzz", 11, "Fizz", 13, 14, "FizzBuzz"] def test_fizzbuzz_variant_different_rules(): assert fizzbuzz_variant(10, [(2, "Even"), (3,...
medium
[ { "content": "### Problem Statement\nYou are given a non-negative integer `num`. Your task is to implement a function that converts the number into its equivalent binary string and then counts the number of consecutive sequences of '1's within that binary representation. \n\n### Function Signature\n```python\nd...
362
Algorithm_12543_I
instruct
Algorithm
from solution import count_consecutive_ones def test_count_consecutive_ones_case_29(): assert count_consecutive_ones(29) == 2 # Binary: '11101' def test_count_consecutive_ones_case_15(): assert count_consecutive_ones(15) == 1 # Binary: '1111' def test_count_consecutive_ones_case_0(): assert count_conse...
easy
[ { "content": "Design a function that takes a list of strings representing names of members in a project team including their roles, and categorizes the members into distinct categories based on their roles. Each category should contain names of the team members assigned to that role. Ensure to handle cases wher...
92
Evol_384_I
instruct
Evol
def test_categorize_team_members_base_case(): members = [ "Alice Developer", "Bob Developer", "Charlie Manager", "Diana Designer" ] expected_output = { "Developer": ["Alice", "Bob"], "Manager": ["Charlie"], "Designer": ["Diana"] } ass...
medium
[ { "content": "You are given an array of integers `heights` representing the heights of buildings, each building being 1 unit wide. The goal is to find the **maximum area of water** that can be contained between the buildings when it rains. The amount of water that can be contained between two buildings is deter...
105
Leetcode_7843_I
instruct
Leetcode
from solution import max_area def test_max_area_example_case(): assert max_area([1,8,6,2,5,4,8,3,7]) == 49 def test_max_area_all_equal(): assert max_area([1,1,1,1]) == 3 def test_max_area_decreasing_heights(): assert max_area([4,3,2,1]) == 4 def test_max_area_mixed_heights(): assert max_area([1,2,4,...
medium
[ { "content": "You are developing an application that interacts with an online bookstore's API. One of the requirements is to implement a caching mechanism to minimize the number of API requests. The cache should store the results of API calls and return the cached result for subsequent requests with the same pa...
467
Package_2336_I
instruct
Package
import pytest from unittest.mock import patch, MagicMock from solution import get_book_details, cache @patch('solution.requests.get') def test_get_book_details_from_api(mock_get): # Mock API response book_id = 123 mock_response = MagicMock() mock_response.status_code = 200 mock_response.json.return...
easy
[ { "content": "Write a function to convert a number from binary to decimal in Python. You should handle both positive and negative binary numbers. How would you structure the function to manage both cases?", "role": "user" } ]
47
Prefill_10997_I
instruct
Prefill
from solution import binary_to_decimal def test_positive_binary(): assert binary_to_decimal('101') == 5 assert binary_to_decimal('1101') == 13 assert binary_to_decimal('0') == 0 def test_negative_binary(): assert binary_to_decimal('-101') == -5 assert binary_to_decimal('-1101') == -13 assert b...
easy
[ { "content": "Here is the list of strings that I have:\n```python\nmy_strings = ['apple', 'banana', 'cherry', 'date', 'elderberry', 'fig', 'grape']\n```\nI need to write a function that will return a new list containing only the words that have more than 5 characters. \n\nHere is my attempt at writing this func...
194
Filter_6212_I
instruct
Filter
def test_get_long_strings(): # Sample input and expected output my_strings = ['apple', 'banana', 'cherry', 'date', 'elderberry', 'fig', 'grape'] expected_output = ['banana', 'cherry', 'elderberry'] assert get_long_strings(my_strings) == expected_output def test_empty_list(): # Test with an empty l...
hard
[ { "content": "Given an array of integers `nums` and an integer `target`, find two distinct indices `i` and `j` in the array such that `nums[i] + nums[j] = target`. Return the indices `(i, j)` as a tuple. If no such indices exist, return `None`.", "role": "user" } ]
75
Leetcode_17698_I
instruct
Leetcode
from solution import two_sum def test_two_sum_exists(): assert two_sum([2, 7, 11, 15], 9) == (0, 1) def test_two_sum_no_solution(): assert two_sum([1, 2, 3, 4], 10) == None def test_two_sum_with_negative_numbers(): assert two_sum([-1, -2, -3, -4, -5], -8) == (2, 4) def test_two_sum_multiple_pairs(): ...
medium
[ { "content": "Write a function to check if a given string `s` matches the pattern `aabbcc...`, where `a`, `b`, `c`, etc. are any characters and each character appears exactly twice consecutively. The length of the string will not exceed 100.", "role": "user" } ]
71
Prefill_5052_I
instruct
Prefill
from solution import is_pattern_aabbcc def test_is_pattern_aabbcc_valid_patterns(): assert is_pattern_aabbcc("aabbcc") == True assert is_pattern_aabbcc("zzyyxx") == True assert is_pattern_aabbcc("ppqqrr") == True def test_is_pattern_aabbcc_invalid_patterns(): assert is_pattern_aabbcc("aabbc") == False...
medium
[ { "content": "Write a function `calculate_checksum` that takes an array of integers `numbers` as input. The array can contain any non-negative integers. The function should compute and return a checksum by summing all the integers at even indices and subtracting the sum of all the integers at odd indices.\n\nFo...
156
Apps_10248_I
instruct
Apps
from solution import calculate_checksum def test_calculate_checksum_example_1(): assert calculate_checksum([1, 2, 3, 4, 5]) == 3 def test_calculate_checksum_example_2(): assert calculate_checksum([10, 20, 30, 40]) == -20 def test_calculate_checksum_single_element(): assert calculate_checksum([5]) == 5 d...
medium
[ { "content": "### Coding Challenge: Find the Nth Digit\n\nYou are given an infinite sequence of digits formed by concatenating positive integers in ascending order starting from 1:\n`123456789101112131415...`\n\nWrite a function `find_nth_digit(n)` to find the nth digit (1-indexed) in this infinite sequence. \n...
412
Data_Structure_21975_I
instruct
Data_Structure
def test_find_nth_digit_basic(): assert find_nth_digit(1) == 1 assert find_nth_digit(2) == 2 assert find_nth_digit(9) == 9 def test_find_nth_digit_edge_cases(): assert find_nth_digit(10) == 1 assert find_nth_digit(11) == 0 assert find_nth_digit(12) == 1 def test_find_nth_digit_large_numbers():...
easy
[ { "content": "### Scenario\n\nThe local library maintains a list of books ordered by their ISBN numbers, which is a unique identifier. To keep the bookshelves tidy, you need to sort this list periodically. The list may sometimes be nearly sorted, only requiring minimal adjustments. You decide to use Insertion S...
384
Data_Structure_37164_I
instruct
Data_Structure
from solution import insertion_sort def test_insertion_sort_empty_list(): assert insertion_sort([]) == [] def test_insertion_sort_single_element(): assert insertion_sort([5]) == [5] def test_insertion_sort_already_sorted(): assert insertion_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] def test_insertion_sor...
hard
[ { "content": "You are given a list of integers `nums` and an integer `k`. A best friend is defined as a distinct number within `nums` that differs from a given number by at most `k`. Return the total number of best friends for each number in `nums`. Two different numbers are considered best friends if the absol...
114
Leetcode_26139_I
instruct
Leetcode
from solution import count_best_friends def test_all_unique_elements(): nums = [1, 5, 9, 14] k = 3 assert count_best_friends(nums, k) == [0, 0, 0, 0] def test_some_best_friends(): nums = [1, 4, 7, 10] k = 3 assert count_best_friends(nums, k) == [1, 2, 2, 1] def test_all_numbers_the_same(): ...
easy
[ { "content": "#### Context\nYou are working on a low-level embedded system project. The project involves manipulating specific bits within integers to set flags or achieve efficient state management. To perform these operations effectively, you need to write functions that handle bit manipulation reliably and e...
680
Data_Structure_15101_I
instruct
Data_Structure
def test_bit_manipulation_get(): assert bit_manipulation(5, 0, 'get') == 1 # 5 in binary is 101, 0th bit is 1 assert bit_manipulation(5, 1, 'get') == 0 # 5 in binary is 101, 1st bit is 0 assert bit_manipulation(5, 2, 'get') == 1 # 5 in binary is 101, 2nd bit is 1 def test_bit_manipulation_set(): ass...
easy
[ { "content": "Your task is to implement the function `findTriplets`. The function takes an array of integers and a target sum as arguments. The function should return `True` if there exists a triplet in the array which sums up to the target sum, otherwise it should return `False`.\n\nExample 1:\nInput:\narr = [...
350
Taco_97241_I
instruct
Taco
from solution import findTriplets def test_example1(): arr = [12, 3, 4, 1, 6, 9] target = 24 assert findTriplets(arr, target) == True def test_example2(): arr = [1, 2, 3, 4, 5] target = 10 assert findTriplets(arr, target) == True def test_example3(): arr = [1, 2, 3, 4, 5] target = 20 ...
easy
[ { "content": "Write a function that takes an integer array `nums`, representing the current scores of various players in a game, and an integer `extraPoints`, denoting the extra points a player can gain. Return a list of booleans where each boolean indicates whether, after adding the `extraPoints` to the corres...
243
Taco_53728_I
instruct
Taco
from solution import can_have_highest_score def test_example1(): assert can_have_highest_score([2, 3, 5, 1, 3], 3) == [True, True, True, False, True] def test_example2(): assert can_have_highest_score([4, 2, 1, 1, 2], 1) == [True, False, False, False, False] def test_example3(): assert can_have_highest_s...
easy
[ { "content": "Write a function that takes a list of integers as input and returns a list of strings where each string represents the corresponding integer in binary format, prefixed with '0b'.\n\nFor example:\n\n```\n[3, 7, 10, 16] --> [\"0b11\", \"0b111\", \"0b1010\", \"0b10000\"]\n```\n\nInput will always be ...
124
Apps_5294_I
instruct
Apps
from solution import int_to_binary_strings def test_single_element_list(): assert int_to_binary_strings([1]) == ["0b1"] assert int_to_binary_strings([2]) == ["0b10"] def test_multiple_elements_list(): assert int_to_binary_strings([3, 7, 10, 16]) == ["0b11", "0b111", "0b1010", "0b10000"] def test_empty_li...
easy
[ { "content": "# Task\n You are given a list of integers where every integer appears twice, except for one. Find the integer that appears only once.\n\n# Example\n\n For `a = [4, 1, 2, 1, 2]`, the result should be `4`\n ```\nYou have 5 integers: \n [4, 1, 2, 1, 2]\n \n4...
192
Taco_5905_I
instruct
Taco
from solution import find_single_number def test_single_number_simple(): assert find_single_number([4, 1, 2, 1, 2]) == 4 def test_single_number_all_twice_except_one(): assert find_single_number([2, 2, 3, 4, 3]) == 4 def test_single_number_bigger_numbers(): assert find_single_number([10000, 99999, 10000, ...
hard
[ { "content": "Kate is putting together a special gift for her friend. She has a collection of M gift boxes each with a certain value of goodies. She wants to select some of these boxes such that their combined value matches exactly her desired value V. However, from the selection of these boxes, there must be n...
437
Taco_51329_I
instruct
Taco
from solution import canPickGiftBoxes def test_example_1(): M = 5 V = 9 A = [3, 2, 5, 10, 7] assert canPickGiftBoxes(M, V, A) == "Yes" def test_example_2(): M = 3 V = 10 A = [1, 2, 3] assert canPickGiftBoxes(M, V, A) == "No" def test_exact_value_but_adjacent(): M = 4 V = 5 ...
easy
[ { "content": "Define a function that takes a list of strings representing dates in \"dd-mm-yyyy\" format and returns a list of the same dates sorted in chronological order. Your function should correctly handle edge cases such as leap years and varying month lengths. \n\nYou should write self-contained code sta...
80
Package_8959_I
instruct
Package
from solution import sort_dates def test_sort_dates_basic(): assert sort_dates(["01-02-2020", "03-01-2020", "02-02-2020"]) == [ "03-01-2020", "01-02-2020", "02-02-2020" ] def test_sort_dates_same_day(): assert sort_dates(["02-02-2020", "02-02-2020"]) == [ "02-02-2020", "02-02-2020" ] ...
easy
[ { "content": "Write a Python function that takes in two parameters, `x` and `y`, and returns their sum. Ensure your code is well-documented, including a docstring that explains what the function does, its parameters, and what it returns.", "role": "user" } ]
61
Filter_48924_I
instruct
Filter
from solution import sum_two_numbers def test_sum_two_numbers_positive(): assert sum_two_numbers(1, 2) == 3 assert sum_two_numbers(10, 20) == 30 def test_sum_two_numbers_with_zero(): assert sum_two_numbers(0, 5) == 5 assert sum_two_numbers(5, 0) == 5 assert sum_two_numbers(0, 0) == 0 def test_sum...
easy
[ { "content": "Write a function that takes a list of strings representing file paths and returns a dictionary where the keys are the directory paths and the values are lists of files found in those directories. The file paths will always be complete paths and you may assume that directory paths in the input list...
226
Apps_18602_I
instruct
Apps
from solution import directory_files def test_directory_files_simple_case(): file_paths = [ "/home/user/documents/file1.txt", "/home/user/documents/file2.txt", "/home/user/music/song1.mp3", "/home/user/music/song2.mp3", "/home/user/music/song3.mp3", "/var/log/system....
easy
[ { "content": "How can I create a Python function that checks if a given string is a palindrome? I want the function to return `True` if the string is a palindrome and `False` otherwise. Additionally, the function should ignore spaces, punctuation, and capitalization. Can you provide a code snippet for this?", ...
73
Filter_55854_I
instruct
Filter
from solution import is_palindrome def test_is_palindrome_basic(): assert is_palindrome("racecar") == True def test_is_palindrome_with_spaces(): assert is_palindrome("A man a plan a canal Panama") == True def test_is_palindrome_with_punctuation(): assert is_palindrome("Madam, in Eden, I'm Adam") ...
easy
[ { "content": "### Decomposing Sparse Matrices\nFor a sparse matrix \\( A \\) with \\( m \\) rows and \\( n \\) columns, where most elements are zero, we can decompose it into three vectors, \\( I \\), \\( J \\), and \\( V \\), of the same length. In these vectors, \\( I \\) contains the row indices, \\( J \\) c...
124
Filter_19552_I
instruct
Filter
from solution import decompose_sparse_matrix def test_decompose_sparse_matrix_all_zero(): matrix = [ [0, 0], [0, 0] ] I, J, V = decompose_sparse_matrix(matrix) assert I == [] assert J == [] assert V == [] def test_decompose_sparse_matrix_basic(): matrix = [ [1, 0], ...
easy
[ { "content": "Is it possible to create a function in Python that can accept a variable number of arguments and return the sum of all the arguments? If yes, then how can we do it? If no, then why not?", "role": "user" } ]
55
Filter_80252_I
instruct
Filter
from solution import sum_of_args def test_sum_of_args_no_arguments(): assert sum_of_args() == 0 def test_sum_of_args_single_argument(): assert sum_of_args(5) == 5 def test_sum_of_args_multiple_arguments(): assert sum_of_args(1, 2, 3, 4) == 10 def test_sum_of_args_with_negative_numbers(): assert sum_...
easy
[ { "content": "Assuming there is a square matrix of size n x n that represents a gray-scale image, write a code snippet to flip the colors of the pixels on the secondary diagonal from black to white and from white to black. The values in the matrix can range from 0 to 255, where 0 represents black and 255 repres...
85
Filter_25612_I
instruct
Filter
from solution import flip_secondary_diagonal def test_flip_secondary_diagonal(): matrix = [ [ 0, 50, 100], [150, 0, 200], [255, 250, 0] ] expected_output = [ [ 0, 50, 155], [150, 255, 200], [ 0, 250, 0] ] assert flip_secondary_diagonal(matr...
easy
[ { "content": "Write a function to find the first occurrence of an element in an array that is greater than a given number. If no such element exists, return -1.", "role": "user" } ]
44
Prefill_8427_I
instruct
Prefill
from solution import find_first_greater def test_find_first_greater_basic(): assert find_first_greater([1, 2, 3, 4, 5], 3) == 3 def test_find_first_greater_no_greater_element(): assert find_first_greater([1, 2, 3, 4, 5], 5) == -1 def test_find_first_greater_all_smaller(): assert find_first_greater([1, 2,...
medium
[ { "content": "### Sorting Integers with Custom Comparator\n\nYou are given a list of integers and a custom comparator function that defines a specific sorting order based on some criteria. Your task is to write a function that sorts the integers according to the provided comparator.\n\n#### Objective:\nImplemen...
583
Algorithm_24481_I
instruct
Algorithm
from solution import custom_sort def test_custom_sort_ascending(): lst = [4, 2, 3, 1, 5] cmp = lambda x, y: x - y assert custom_sort(lst, cmp) == [1, 2, 3, 4, 5] def test_custom_sort_descending(): lst = [4, 2, 3, 1, 5] cmp = lambda x, y: y - x assert custom_sort(lst, cmp) == [5, 4, 3, 2, 1] d...
easy
[ { "content": "You have been hired to design a simple text editor. One of the features of this text editor is to count the frequency of each word in a given document and output the word counts in descending order. Specifically, if two words have the same frequency, they should be sorted in ascending lexicographi...
296
Taco_42274_I
instruct
Taco
from solution import word_frequency def test_single_sentence(): document = "Hello, world! World is great. Hello again, world." expected = [("world", 3), ("hello", 2), ("again", 1), ("great", 1), ("is", 1)] assert word_frequency(document) == expected def test_multiple_sentences(): document = "The quick...
easy
[ { "content": "Write a function to reverse the words in a given sentence. The sentence will only consist of alphanumeric characters and spaces. Words are defined as sequences of characters separated by spaces.\n\nThe function should be based on the following specifications:\n\nreverseWords(sentence)\n1. Split th...
205
Taco_16012_I
instruct
Taco
from solution import reverseWords def test_reverse_single_word(): assert reverseWords("hello") == "hello" def test_reverse_two_words(): assert reverseWords("hello world") == "world hello" def test_reverse_multiple_words(): assert reverseWords("a quick brown fox jumps over the lazy dog") == "dog lazy the ...
medium
[ { "content": "### Problem Statement\nYou are to implement a function that normalizes a list of numerical values. Normalization is a process that adjusts the values in a dataset to a common scale, typically within the range [0, 1], without distorting the differences in the ranges of values.\n\n### The context\nA...
379
Algorithm_11889_I
instruct
Algorithm
from solution import normalize_list def test_normalize_list_ascending(): assert normalize_list([1, 2, 3, 4, 5]) == [0.0, 0.25, 0.5, 0.75, 1.0] def test_normalize_list_descending(): assert normalize_list([5, 4, 3, 2, 1]) == [1.0, 0.75, 0.5, 0.25, 0.0] def test_normalize_list_mixed(): assert normalize_list...
hard
[ { "content": "You are tasked with creating a Python function that parses a list of URLs and organizes them into a dictionary based on their domain names. This task assesses your understanding of string manipulation, dictionary operations, and URL parsing.\n\n**Function Specification:**\n\nName: `organize_urls_b...
379
Package_3578_I
instruct
Package
from solution import organize_urls_by_domain def test_organize_urls_by_domain_example(): urls = [ "https://www.example.com/path/to/page", "http://subdomain.example.com/another/page", "https://www.test.com/home", "http://example.com/contact", "https://test.com/about" ] ...
easy
[ { "content": "### Task\nYou are given two strings `str1` and `str2` both of the same length, comprising only lowercase letters of the English alphabet. Your task is to determine if these strings can be made equal by swapping at most two characters within `str1`.\n\n### Example\nGiven two strings:\n\n```python\n...
277
Taco_89435_I
instruct
Taco
from solution import can_be_equal_by_swapping def test_can_be_equal_by_swapping_simple_swap(): assert can_be_equal_by_swapping('ab', 'ba') == True def test_can_be_equal_by_swapping_no_swap_needed(): assert can_be_equal_by_swapping('ab', 'ab') == True def test_can_be_equal_by_swapping_no_possible_swap(): ...
medium
[ { "content": "Write a function to determine if a given string contains balanced parentheses. A string with balanced parentheses has every opening parenthesis '(' matched with a closing parenthesis ')' in the correct order. \n\n### Input\n- A single input string consisting of characters 'a-z', 'A-Z', '0-9', '(',...
161
Evol_4728_I
instruct
Evol
from solution import is_balanced def test_balanced_with_letters(): assert is_balanced("abc(def)ghi") == True def test_unbalanced_extra_closing(): assert is_balanced("a(b)c)d(") == False def test_balanced_mixed_characters(): assert is_balanced("(a+b)*(c+d)") == True def test_unbalanced_only_closing_first...
medium
[ { "content": "### Problem Context\nA non-profit organization is trying to identify the most frequent donors who have not donated in the past week. They have a list of donor ids where some ids repeat if a donor has contributed multiple times during that week. They need to identify the first donor who contributed...
319
Data_Structure_34229_I
instruct
Data_Structure
# Import the function from the solution code from solution import first_unique_char def test_first_unique_char(): # Test cases from the prompt assert first_unique_char("abcabc") == -1 assert first_unique_char("aabcbd") == 3 assert first_unique_char("z") == 0 assert first_unique_char("") == -1 ...
easy
[ { "content": "Write a python function to find the second largest number in a list. If the list has less than two elements or all elements are the same, return None.", "role": "user" } ]
44
Prefill_36774_I
instruct
Prefill
from solution import second_largest def test_second_largest_with_two_desc(): assert second_largest([2, 1]) == 1 def test_second_largest_with_two_asc(): assert second_largest([1, 2]) == 1 def test_second_largest_with_duplicates(): assert second_largest([2, 2, 1, 1]) == 1 def test_second_largest_with_diff...
easy
[ { "content": "A private bank uses a nested system of account numbers to identify its clients. Each account number consists of a series of digits. Sometimes, due to network errors, zeros get added to the start of these account numbers. \n\nYour task is to help the bank implement a function to validate the accoun...
318
Codeforces_00022735_I
instruct
Codeforces
def test_account_number_with_leading_zeros(): assert validate_account_number("0001234500") == "1234500" def test_account_number_all_zeros(): assert validate_account_number("0000") == "0" assert validate_account_number("0000000000") == "0" def test_account_number_without_leading_zeros(): assert validat...
medium
[ { "content": "### Scenario\nYou are developing a word-processing application and need to implement a feature to find and replace a specified word in a given text with another word. This involves creating a function that efficiently processes the text to handle multiple occurrences of the target word and replace...
544
Algorithm_16840_I
instruct
Algorithm
from solution import replace_word def test_case_sensitive_replacement(): assert replace_word("Hello World! Hello everyone.", "Hello", "Hi", True) == "Hi World! Hi everyone." def test_case_insensitive_replacement(): assert replace_word("Hello World! Hello everyone.", "hello", "Hi", False) == "Hi World! Hi ever...
easy
[ { "content": "You are tasked with writing a function `strip_url_params(url: str, params_to_strip: Optional[List[str]] = None) -> str` that removes any duplicate query string parameters from the URL and removes any query string parameters specified in the second argument (an optional list).\n\nThe function shoul...
412
Data_Structure_44967_I
instruct
Data_Structure
from solution import strip_url_params def test_no_params_to_strip(): assert strip_url_params('http://example.com?a=1&b=2&a=2') == 'http://example.com?a=1&b=2' def test_strip_one_param(): assert strip_url_params('http://example.com?a=1&b=2&c=3&a=2', ['b']) == 'http://example.com?a=1&c=3' def test_strip_multip...
easy
[ { "content": "How can I efficiently calculate the Levenshtein distance between two strings in Python, considering performance and ease of implementation? Additionally, could you provide a brief explanation of what Levenshtein distance is and its common applications?", "role": "user" } ]
57
Filter_51929_I
instruct
Filter
from solution import levenshtein_distance def test_levenshtein_same_string(): assert levenshtein_distance("kitten", "kitten") == 0 def test_levenshtein_simple_case(): assert levenshtein_distance("kitten", "sitting") == 3 assert levenshtein_distance("flaw", "lawn") == 2 def test_levenshtein_empty_strings(...
easy
[ { "content": "Write a program to check if a given number is a palindrome or not. The program should work for both positive and negative numbers, and it should not convert the number to a string at any point. Use Python for the implementation.", "role": "user" } ]
58
Filter_45616_I
instruct
Filter
from solution import is_palindrome_number def test_positive_palindrome_numbers(): assert is_palindrome_number(121) == True assert is_palindrome_number(1221) == True assert is_palindrome_number(12321) == True assert is_palindrome_number(1) == True def test_positive_non_palindrome_numbers(): assert ...
easy
[ { "content": "**Anagram Checker with Extended Character Set**\n\nGiven two strings, determine if they are anagrams of each other. The strings may contain any printable ASCII characters, and the check should be case-insensitive. You must handle all edge cases, including empty strings and strings with special cha...
336
Data_Structure_27775_I
instruct
Data_Structure
def test_extended_anagram_case_insensitive(): assert extended_anagram("Apple", "pleap") == True def test_extended_anagram_with_special_characters(): assert extended_anagram("apple", "apple!") == False def test_extended_anagram_empty_strings(): assert extended_anagram("", "") == True def test_extended_ana...
medium
[ { "content": "In this problem, you are given a list of integers and a target number. The task is to find the pair of numbers in the list that add up to the target number.\n\nExample:\n\nInput: nums = [2, 7, 11, 15], target = 9\nOutput: [2, 7]\n\nBecause 2 + 7 = 9\n\nHere is a simple solution to this problem:\n\...
184
Filter_9219_I
instruct
Filter
from solution import two_sum def test_two_sum_pair_exists(): assert two_sum([2, 7, 11, 15], 9) == [2, 7] assert two_sum([1, 2, 3, 4, 5], 9) == [4, 5] def test_two_sum_no_pair_exists(): assert two_sum([1, 2, 3], 7) == None assert two_sum([5, 6, 8], 100) == None def test_two_sum_multiple_pairs(): a...
End of preview. Expand in Data Studio

Qwen3.5 KodCode RLVR 1K

Deterministically sampled from KodCode/KodCode-Light-RL-10K at revision dcf78a8bbba9a613b596ce993c4921a38687dfcc after removing SFT and public benchmark overlap.

  • Prompts: 1,000
  • Seed: 42
  • Maximum completion length: 2,048

The payload contains prompts, metadata, and public tests. It does not contain reference solutions.

Downloads last month
9