Dataset Viewer
Auto-converted to Parquet Duplicate
task_id
stringlengths
7
9
prompt
stringlengths
237
6.2k
entry_point
stringlengths
2
37
test
stringlengths
70
6.28k
given_tests
sequencelengths
1
6
canonical_solution
stringclasses
1 value
difficulty
stringclasses
3 values
added_tests
sequencelengths
0
0
APPS/2590
def max_of_min_2d_array(n: int, m: int, array: List[List[int]]) -> int: """ =====Function Descriptions===== min The tool min returns the minimum value along a given axis. import numpy my_array = numpy.array([[2, 5], [3, 7], [1, 3], [4, 0]]) print numpy.min(my_...
max_of_min_2d_array
def check(candidate): assert candidate(4, 2, [[2, 5], [3, 7], [1, 3], [4, 0]]) == 3 check(max_of_min_2d_array)
[ "assert max_of_min_2d_array(4, 2, [[2, 5], [3, 7], [1, 3], [4, 0]]) == 3" ]
introductory
[]
APPS/3239
def guess_hat_color(a: str, b: str, c: str, d: str) -> int: """ # Task Four men, `a, b, c and d` are standing in a line, one behind another. There's a wall between the first three people (a, b and c) and the last one (d). a, b and c are lined up in order of height, so that person a can see...
guess_hat_color
def check(candidate): assert candidate('white', 'black', 'white', 'black') == 2 assert candidate('white', 'black', 'black', 'white') == 1 check(guess_hat_color)
[ "assert guess_hat_color('white', 'black', 'white', 'black') == 2" ]
introductory
[]
APPS/2468
def tictactoe(moves: List[List[int]]) -> str: """ Tic-tac-toe is played by two players A and B on a 3 x 3 grid. Here are the rules of Tic-Tac-Toe: Players take turns placing characters into empty squares (" "). The first player A always places "X" characters, while the second player B always pl...
tictactoe
def check(candidate): assert candidate([[0, 0], [2, 0], [1, 1], [2, 1], [2, 2]]) == 'A' assert candidate([[0, 0], [1, 1], [0, 1], [0, 2], [1, 0], [2, 0]]) == 'B' assert candidate([[0, 0], [1, 1], [2, 0], [1, 0], [1, 2], [2, 1], [0, 1], [0, 2], [2, 2]]) == 'Draw' assert candidate([[0, 0], [1, 1]]) == 'P...
[ "assert tictactoe([[0, 0], [2, 0], [1, 1], [2, 1], [2, 2]]) == 'A'", "assert tictactoe([[0, 0], [1, 1], [0, 1], [0, 2], [1, 0], [2, 0]]) == 'B'", "assert tictactoe([[0, 0], [1, 1], [2, 0], [1, 0], [1, 2], [2, 1], [0, 1], [0, 2], [2, 2]]) == 'Draw'", "assert tictactoe([[0, 0], [1, 1]]) == 'Pending'" ]
introductory
[]
APPS/3231
def case_unification(s: str) -> str: """ # Task Given an initial string `s`, switch case of the minimal possible number of letters to make the whole string written in the upper case or in the lower case. # Input/Output `[input]` string `s` String of odd length consisting of E...
case_unification
def check(candidate): assert candidate('asdERvT') == 'asdervt' assert candidate('oyTYbWQ') == 'OYTYBWQ' assert candidate('bbiIRvbcW') == 'bbiirvbcw' assert candidate('rWTmvcoRWEWQQWR') == 'RWTMVCORWEWQQWR' check(case_unification)
[ "assert case_unification('Aba') == 'aba'", "assert case_unification('ABa') == 'ABA'" ]
introductory
[]
APPS/2961
def complete_series(a: List[int]) -> List[int]: """ You are given an array of non-negative integers, your task is to complete the series from 0 to the highest number in the array. If the numbers in the sequence provided are not in order you should order them, but if a value repeats, then you must retur...
complete_series
def check(candidate): assert candidate([0, 1]) == [0, 1] assert candidate([1, 4, 6]) == [0, 1, 2, 3, 4, 5, 6] assert candidate([3, 4, 5]) == [0, 1, 2, 3, 4, 5] assert candidate([2, 1]) == [0, 1, 2] assert candidate([1, 4, 4, 6]) == [0] check(complete_series)
[ "assert complete_series([0, 1]) == [0, 1]", "assert complete_series([1, 4, 6]) == [0, 1, 2, 3, 4, 5, 6]", "assert complete_series([3, 4, 5]) == [0, 1, 2, 3, 4, 5]", "assert complete_series([0, 1, 0]) == [0]", "assert complete_series([2, 1]) == [0, 1, 2]", "assert complete_series([1, 4, 4, 6]) == [0]" ]
introductory
[]
APPS/3813
def does_fred_need_houseboat(x: int, y: int) -> int: """ # Task Fred Mapper is considering purchasing some land in Louisiana to build his house on. In the process of investigating the land, he learned that the state of Louisiana is actually shrinking by 50 square miles each year, due to erosion caused by th...
does_fred_need_houseboat
def check(candidate): assert candidate(1, 1) == 1 assert candidate(25, 0) == 20 check(does_fred_need_houseboat)
[ "assert does_fred_need_houseboat(1, 1) == 1", "assert does_fred_need_houseboat(25, 0) == 20" ]
introductory
[]
APPS/3513
def folding(a: int, b: int) -> int: """ # Task John was in math class and got bored, so he decided to fold some origami from a rectangular `a × b` sheet of paper (`a > b`). His first step is to make a square piece of paper from the initial rectangular piece of paper by folding the sheet along the bisector o...
folding
def check(candidate): assert candidate(2, 1) == 2 assert candidate(10, 7) == 6 assert candidate(3, 1) == 3 assert candidate(4, 1) == 4 assert candidate(3, 2) == 3 assert candidate(4, 2) == 2 assert candidate(1000, 700) == 6 assert candidate(1000, 999) == 1000 check(folding)
[ "assert folding(2, 1) == 2", "assert folding(10, 7) == 6" ]
introductory
[]
APPS/4035
def substring_test(first: str, second: str) -> bool: """ Given 2 strings, your job is to find out if there is a substring that appears in both strings. You will return true if you find a substring that appears in both strings, or false if you do not. We only care about substrings that are longer than one letter...
substring_test
def check(candidate): assert candidate('Something', 'Home') == True assert candidate('Something', 'Fun') == False assert candidate('Something', '') == False assert candidate('', 'Something') == False assert candidate('BANANA', 'banana') == True assert candidate('test', 'lllt') == False asse...
[ "assert substring_test('Something', 'Fun') == False", "assert substring_test('Something', 'Home') == True" ]
introductory
[]
APPS/2905
def nickname_generator(name: str) -> str: """ Nickname Generator Write a function, `nicknameGenerator` that takes a string name as an argument and returns the first 3 or 4 letters as a nickname. If the 3rd letter is a consonant, return the first 3 letters. If the 3rd letter is a vowel...
nickname_generator
def check(candidate): assert candidate('Jimmy') == 'Jim' assert candidate('Samantha') == 'Sam' assert candidate('Sam') == 'Error: Name too short' assert candidate('Kayne') == 'Kay' assert candidate('Melissa') == 'Mel' assert candidate('James') == 'Jam' assert candidate('Gregory') == 'Greg' ...
[ "assert nickname_generator('Robert') == 'Rob'", "assert nickname_generator('Jeannie') == 'Jean'" ]
introductory
[]
APPS/4907
def candles(candlesNumber: int, makeNew: int) -> int: """ # Task When a candle finishes burning it leaves a leftover. makeNew leftovers can be combined to make a new candle, which, when burning down, will in turn leave another leftover. You have candlesNumber candles in your possession. What's the ...
candles
def check(candidate): assert candidate(5, 2) == 9 check(candles)
[ "assert candles(5, 2) == 9" ]
introductory
[]
APPS/3776
def segment_cover(A: List[int], L: int) -> int: """ # Task Given some points(array `A`) on the same line, determine the minimum number of line segments with length `L` needed to cover all of the given points. A point is covered if it is located inside some segment or on its bounds. # Example ...
segment_cover
def check(candidate): assert candidate([1, 3, 4, 5, 8], 3) == 2 assert candidate([-7, -2, 0, -1, -6, 7, 3, 4], 4) == 3 assert candidate([1, 5, 2, 4, 3], 1) == 3 assert candidate([1, 10, 100, 1000], 1) == 4 check(segment_cover)
[ "assert segment_cover([1, 3, 4, 5, 8], 3) == 2" ]
introductory
[]
APPS/2718
def timed_reading(max_length: int, text: str) -> int: """ # Task Timed Reading is an educational tool used in many schools to improve and advance reading skills. A young elementary student has just finished his very first timed reading exercise. Unfortunately he's not a very good reader yet, so whenever he ...
timed_reading
def check(candidate): assert candidate(4, 'The Fox asked the stork, How is the soup?') == 7 assert candidate(1, '...') == 0 assert candidate(3, 'This play was good for us.') == 3 assert candidate(3, 'Suddenly he stopped, and glanced up at the houses') == 5 assert candidate(6, 'Zebras evolved among ...
[ "assert timed_reading(4, 'The Fox asked the stork, How is the soup?') == 7" ]
introductory
[]
APPS/3351
def evil_code_medal(user_time: str, gold: str, silver: str, bronze: str) -> str: """ # Task `EvilCode` is a game similar to `Codewars`. You have to solve programming tasks as quickly as possible. However, unlike `Codewars`, `EvilCode` awards you with a medal, depending on the time you took to solve the task...
evil_code_medal
def check(candidate): assert candidate("00:30:00", "00:15:00", "00:45:00", "01:15:00") == "Silver" assert candidate("01:15:00", "00:15:00", "00:45:00", "01:15:00") == "None" assert candidate("00:00:01", "00:00:10", "00:01:40", "01:00:00") == "Gold" assert candidate("00:10:01", "00:00:10", "00:01:40", "...
[ "assert evil_code_medal(\"00:30:00\", \"00:15:00\", \"00:45:00\", \"01:15:00\") == \"Silver\"" ]
introductory
[]
APPS/4630
def decrypt(s: str) -> str: """ # Task Smartphones software security has become a growing concern related to mobile telephony. It is particularly important as it relates to the security of available personal information. For this reason, Ahmed decided to encrypt phone numbers of contacts in such a ...
decrypt
def check(candidate): assert candidate('353') == '123' assert candidate('444') == '404' assert candidate('123456') == '738496' assert candidate('147') == '377' assert candidate('4334') == 'impossible' check(decrypt)
[ "assert decrypt('353') == '123'", "assert decrypt('123456') == '738496'", "assert decrypt('4334') == 'impossible'" ]
introductory
[]
APPS/2521
def reformat(s: str) -> str: """ Given alphanumeric string s. (Alphanumeric string is a string consisting of lowercase English letters and digits). You have to find a permutation of the string where no letter is followed by another letter and no digit is followed by another digit. That is, no two adjacent c...
reformat
def check(candidate): assert candidate('a0b1c2') == '0a1b2c' or candidate('a0b1c2') == 'a0b1c2' or candidate('a0b1c2') == '0c2a1b' assert candidate('leetcode') == '' assert candidate('1229857369') == '' assert candidate('covid2019') == 'c2o0v1i9d' or candidate('covid2019') == '2c0o1v9i' assert cand...
[ "assert reformat('a0b1c2') == '0a1b2c' or reformat('a0b1c2') == 'a0b1c2' or reformat('a0b1c2') == '0c2a1b'" ]
introductory
[]
APPS/2706
def pass_the_bill(total: int, conservative: int, reformist: int) -> int: """ # Story&Task There are three parties in parliament. The "Conservative Party", the "Reformist Party", and a group of independants. You are a member of the “Conservative Party” and you party is trying to pass a bill. The “Re...
pass_the_bill
def check(candidate): assert candidate(8, 3, 3) == 2 assert candidate(13, 4, 7) == -1 assert candidate(7, 4, 3) == 0 assert candidate(11, 4, 1) == 2 assert candidate(11, 5, 1) == 1 assert candidate(11, 6, 1) == 0 assert candidate(11, 4, 4) == 2 assert candidate(11, 5, 4) == 1 assert...
[ "assert pass_the_bill(8, 3, 3) == 2", "assert pass_the_bill(13, 4, 7) == -1" ]
introductory
[]
APPS/4536
def capitals_first(string: str) -> str: """ Create a function that takes an input String and returns a String, where all the uppercase words of the input String are in front and all the lowercase words at the end. The order of the uppercase and lowercase words should be the order in which they occur. ...
capitals_first
def check(candidate): assert candidate('hey You, Sort me Already') == 'You, Sort Already hey me' assert candidate('sense Does to That Make you?') == 'Does That Make sense to you?' assert candidate('i First need Thing In coffee The Morning') == 'First Thing In The Morning i need coffee' assert candidate...
[ "assert capitals_first('hey You, Sort me Already') == 'You, Sort Already hey me'" ]
introductory
[]
APPS/2496
def day_of_the_week(day: int, month: int, year: int) -> str: """ Given a date, return the corresponding day of the week for that date. The input is given as three integers representing the day, month and year respectively. Return the answer as one of the following values {"Sunday", "Monday", "Tuesday", ...
day_of_the_week
def check(candidate): assert candidate(31, 8, 2019) == 'Saturday' assert candidate(18, 7, 1999) == 'Sunday' assert candidate(15, 8, 1993) == 'Sunday' check(day_of_the_week)
[ "assert day_of_the_week(31, 8, 2019) == 'Saturday'", "assert day_of_the_week(18, 7, 1999) == 'Sunday'", "assert day_of_the_week(15, 8, 1993) == 'Sunday'" ]
introductory
[]
APPS/2370
def max_length_three_blocks_palindrome(t: int, cases: List[Tuple[int, List[int]]]) -> List[int]: """ The only difference between easy and hard versions is constraints. You are given a sequence $a$ consisting of $n$ positive integers. Let's define a three blocks palindrome as the sequence, cons...
max_length_three_blocks_palindrome
def check(candidate): assert candidate(6, [(8, [1, 1, 2, 2, 3, 2, 1, 1]), (3, [1, 3, 3]), (4, [1, 10, 10, 1]), (1, [26]), (2, [2, 1]), (3, [1, 1, 1])]) == [7, 2, 4, 1, 1, 3] check(max_length_three_blocks_palindrome)
[ "assert max_length_three_blocks_palindrome(6, [(8, [1, 1, 2, 2, 3, 2, 1, 1]), (3, [1, 3, 3]), (4, [1, 10, 10, 1]), (1, [26]), (2, [2, 1]), (3, [1, 1, 1])]) == [7, 2, 4, 1, 1, 3]" ]
introductory
[]
APPS/3791
def moment_of_time_in_space(moment: str) -> List[bool]: """ # Task You are given a `moment` in time and space. What you must do is break it down into time and space, to determine if that moment is from the past, present or future. `Time` is the sum of characters that increase time (i.e. numbers in ...
moment_of_time_in_space
def check(candidate): assert candidate('12:30 am') == [False, False, True] assert candidate('12:02 pm') == [False, True, False] assert candidate('01:00 pm') == [True, False, False] assert candidate('11:12 am') == [False, False, True] assert candidate('05:20 pm') == [False, False, True] assert c...
[ "assert moment_of_time_in_space('12:02 pm') == [False, True, False]", "assert moment_of_time_in_space('12:30 am') == [False, False, True]", "assert moment_of_time_in_space('01:00 pm') == [True, False, False]" ]
introductory
[]
APPS/2444
def max_distance_between_ones(n: int) -> int: """ Given a positive integer n, find and return the longest distance between any two adjacent 1's in the binary representation of n. If there are no two adjacent 1's, return 0. Two 1's are adjacent if there are only 0's separating them (possibly no 0's). The dis...
max_distance_between_ones
def check(candidate): assert candidate(22) == 2 assert candidate(5) == 2 assert candidate(8) == 0 check(max_distance_between_ones)
[ "assert max_distance_between_ones(22) == 2", "assert max_distance_between_ones(8) == 0", "assert max_distance_between_ones(5) == 2" ]
introductory
[]
APPS/4537
def bin2gray(bits: list) -> list: """ Gray code is a form of binary encoding where transitions between consecutive numbers differ by only one bit. This is a useful encoding for reducing hardware data hazards with values that change rapidly and/or connect to slower hardware as inputs. It is also useful for gener...
bin2gray
def check(candidate): assert candidate([1, 0, 1]) == [1, 1, 1] assert candidate([1, 1]) == [1, 0] assert candidate([1]) == [1] assert candidate([0]) == [0] assert candidate([1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0]) == [1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1] assert candidate([1, 0, 1, 0, 1,...
[ "assert bin2gray([1, 0, 1]) == [1, 1, 1]", "assert bin2gray([1, 1]) == [1, 0]" ]
introductory
[]
APPS/4329
def pig_latin(s: str) -> str: """ Pig Latin is an English language game where the goal is to hide the meaning of a word from people not aware of the rules. So, the goal of this kata is to wite a function that encodes a single word string to pig latin. The rules themselves are rather easy: ...
pig_latin
def check(candidate): assert candidate('Hello') == 'ellohay' assert candidate('CCCC') == 'ccccay' assert candidate('tes3t5') == None assert candidate('ay') == 'ayway' assert candidate('') == None assert candidate('YA') == 'ayay' assert candidate('123') == None assert candidate('ya1') ==...
[ "assert pig_latin('spaghetti') == 'aghettispay'" ]
introductory
[]
APPS/2473
def modifyString(s: str) -> str: """ Given a string s containing only lower case English letters and the '?' character, convert all the '?' characters into lower case letters such that the final string does not contain any consecutive repeating characters. You cannot modify the non '?' characters. It is gua...
modifyString
def check(candidate): assert candidate('?zs') == 'azs' assert candidate('ubv?w') == 'ubvaw' assert candidate('j?qg??b') == 'jaqgacb' assert candidate('??yw?ipkj?') == 'acywaipkja' check(modifyString)
[ "assert modifyString('?zs') == 'azs'", "assert modifyString('ubv?w') == 'ubvaw'", "assert modifyString('j?qg??b') == 'jaqgacb'", "assert modifyString('??yw?ipkj?') == 'acywaipkja'" ]
introductory
[]
APPS/2732
def blocks(s: str) -> str: """ ## Task You will receive a string consisting of lowercase letters, uppercase letters and digits as input. Your task is to return this string as blocks separated by dashes (`"-"`). The elements of a block should be sorted with respect to the hierarchy listed below, and eac...
blocks
def check(candidate): assert candidate('heyitssampletestkk') == 'aeiklmpsty-ehkst-s' assert candidate('dasf6ds65f45df65gdf651vdf5s1d6g5f65vqweAQWIDKsdds') == 'adefgqsvwADIKQW1456-dfgsv156-dfs56-dfs56-dfs56-df56-d5-d' assert candidate('SDF45648374RHF8BFVYg378rg3784rf87g3278bdqG') == 'bdfgqrBDFGHRSVY2345678-...
[ "assert blocks('21AxBz') == 'xzAB12'", "assert blocks('abacad') == 'abcd-a-a'", "assert blocks('->') == ''" ]
introductory
[]
APPS/2863
def AlanAnnoyingKid(sentence: str) -> str: """ Alan's child can be annoying at times. When Alan comes home and tells his kid what he has accomplished today, his kid never believes him. Be that kid. Your function 'AlanAnnoyingKid' takes as input a sentence spoken by Alan (a string). Th...
AlanAnnoyingKid
def check(candidate): assert candidate('Today I played football.') == "I don't think you played football today, I think you didn't play at all!" assert candidate("Today I didn't play football.") == "I don't think you didn't play football today, I think you did play it!" assert candidate("Today I didn't att...
[ "assert AlanAnnoyingKid('Today I played football.') == \"I don't think you played football today, I think you didn't play at all!\"", "assert AlanAnnoyingKid(\"Today I didn't attempt to hardcode this Kata.\") == \"I don't think you didn't attempt to hardcode this Kata today, I think you did attempt it!\"", "ass...
introductory
[]
APPS/3877
def T9(words: list, seq: str) -> list: """ The T9 typing predictor helps with suggestions for possible word combinations on an old-style numeric keypad phone. Each digit in the keypad (2-9) represents a group of 3-4 letters. To type a letter, press once the key which corresponds to the letter group that contain...
T9
def check(candidate): assert candidate(['hello', 'world'], '43556') == ['hello'] assert candidate(['good', 'home', 'new'], '4663') == ['good', 'home'] assert candidate(['gone', 'hood', 'good', 'old'], '4663') == ['gone', 'hood', 'good'] assert candidate(['Hello', 'world'], '43556') == ['Hello'] ass...
[ "assert T9(['hello', 'world'], '43556') == ['hello']", "assert T9(['good', 'home', 'new'], '4663') == ['good', 'home']", "assert T9(['Hello', 'world'], '43556') == ['Hello']", "assert T9([], '43556') == ['gdjjm']", "assert T9(['gold', 'word'], '4663') == ['gmmd']" ]
introductory
[]
APPS/2740
def wheat_from_chaff(values: list) -> list: """ # Scenario With **_Cereal crops_** like wheat or rice, before we can eat the grain kernel, we need to remove that inedible hull, or *to separate the wheat from the chaff*. ___ # Task **_Given_** a *sequence of n integers* , **_separa...
wheat_from_chaff
def check(candidate): assert candidate([2, -4, 6, -6]) == [-6, -4, 6, 2] assert candidate([7, -3, -10]) == [-10, -3, 7] assert candidate([7, -8, 1, -2]) == [-2, -8, 1, 7] assert candidate([8, 10, -6, -7, 9]) == [-7, -6, 10, 8, 9] assert candidate([-3, 4, -10, 2, -6]) == [-3, -6, -10, 2, 4] asse...
[ "assert wheat_from_chaff([7, -8, 1 ,-2]) == [-2, -8, 1, 7]", "assert wheat_from_chaff([-31, -5, 11 , -42, -22, -46, -4, -28 ]) == [-31, -5,- 28, -42, -22, -46 , -4, 11]", "assert wheat_from_chaff([-25, -48, -29, -25, 1, 49, -32, -19, -46, 1]) == [-25, -48, -29, -25, -46, -19, -32, 49, 1, 1]" ]
introductory
[]
APPS/2505
def is_rectangle_overlap(rec1: list, rec2: list) -> bool: """ An axis-aligned rectangle is represented as a list [x1, y1, x2, y2], where (x1, y1) is the coordinate of its bottom-left corner, and (x2, y2) is the coordinate of its top-right corner. Its top and bottom edges are parallel to the X-axis, and its left...
is_rectangle_overlap
def check(candidate): assert candidate([0, 0, 2, 2], [1, 1, 3, 3]) == True assert candidate([0, 0, 1, 1], [1, 0, 2, 1]) == False assert candidate([0, 0, 1, 1], [2, 2, 3, 3]) == False check(is_rectangle_overlap)
[ "assert is_rectangle_overlap([0, 0, 2, 2], [1, 1, 3, 3]) == True", "assert is_rectangle_overlap([0, 0, 1, 1], [1, 0, 2, 1]) == False", "assert is_rectangle_overlap([0, 0, 1, 1], [2, 2, 3, 3]) == False" ]
introductory
[]
APPS/2491
def buddy_strings(A: str, B: str) -> bool: """ Given two strings A and B of lowercase letters, return true if you can swap two letters in A so the result is equal to B, otherwise, return false. Swapping letters is defined as taking two indices i and j (0-indexed) such that i != j and swapping the characters...
buddy_strings
def check(candidate): assert candidate('ab', 'ba') == True assert candidate('ab', 'ab') == False assert candidate('aa', 'aa') == True assert candidate('aaaaaaabc', 'aaaaaaacb') == True assert candidate('', 'aa') == False check(buddy_strings)
[ "assert buddy_strings('ab', 'ba') == True", "assert buddy_strings('ab', 'ab') == False", "assert buddy_strings('aa', 'aa') == True", "assert buddy_strings('aaaaaaabc', 'aaaaaaacb') == True", "assert buddy_strings('', 'aa') == False" ]
introductory
[]
APPS/4777
def mystery_range(s: str, n: int) -> list[int]: """ In this kata, your task is to write a function that returns the smallest and largest integers in an unsorted string. In this kata, a range is considered a finite sequence of consecutive integers. Input Your function will receive two arguments: ...
mystery_range
def check(candidate): assert candidate('1568141291110137', 10) == [6, 15] check(mystery_range)
[ "assert mystery_range('1568141291110137', 10) == [6, 15]" ]
introductory
[]
APPS/2423
def min_start_value(nums: list[int]) -> int: """ Given an array of integers nums, you start with an initial positive value startValue. In each iteration, you calculate the step by step sum of startValue plus elements in nums (from left to right). Return the minimum positive value of startValue such that...
min_start_value
def check(candidate): assert candidate([-3, 2, -3, 4, 2]) == 5 assert candidate([1, 2]) == 1 assert candidate([1, -2, -3]) == 5 check(min_start_value)
[ "assert min_start_value([-3, 2, -3, 4, 2]) == 5", "assert min_start_value([1,2]) == 1", "assert min_start_value([1,-2,-3]) == 5" ]
introductory
[]
APPS/2956
def encode(stg: str) -> str: """ *Translations appreciated* ## Background information The Hamming Code is used to correct errors, so-called bit flips, in data transmissions. Later in the description follows a detailed explanation of how it works. In this Kata we will implement the Hamming ...
encode
def check(candidate): assert candidate('hey') == '000111111000111000000000000111111000000111000111000111111111111000000111' assert candidate('The Sensei told me that i can do this kata') == '000111000111000111000000000111111000111000000000000111111000000111000111000000111000000000000000000111000111000000111111...
[ "assert encode('hey') == '000111111000111000000000000111111000000111000111000111111111111000000111'" ]
introductory
[]
APPS/2480
def min_cost_to_move_chips(position: list[int]) -> int: """ We have n chips, where the position of the ith chip is position[i]. We need to move all the chips to the same position. In one step, we can change the position of the ith chip from position[i] to: position[i] + 2 or position[i] - 2 with co...
min_cost_to_move_chips
def check(candidate): assert candidate([1, 2, 3]) == 1 assert candidate([2, 2, 2, 3, 3]) == 2 assert candidate([1, 1000000000]) == 1 check(min_cost_to_move_chips)
[ "assert min_cost_to_move_chips([1, 2, 3]) == 1", "assert min_cost_to_move_chips([2,2,2,3,3]) == 2", "assert min_cost_to_move_chips([1,1000000000]) == 1" ]
introductory
[]
APPS/4715
def build_palindrome(s: str) -> str: """ ## Task Given a string, add the fewest number of characters possible from the front or back to make it a palindrome. ## Example For the input `cdcab`, the output should be `bacdcab` ## Input/Output Input is a string consisting...
build_palindrome
def check(candidate): assert candidate('abcdc') == 'abcdcba' assert candidate('ababa') == 'ababa' check(build_palindrome)
[ "assert build_palindrome('cdcab') == 'bacdcab'" ]
introductory
[]
APPS/2418
def containsDuplicate(nums: list[int]) -> bool: """ Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every element is distinct. Example 1: Input:...
containsDuplicate
def check(candidate): assert candidate([1, 2, 3, 1]) == True assert candidate([1, 2, 3, 4]) == False assert candidate([1, 1, 1, 3, 3, 4, 3, 2, 4, 2]) == True check(containsDuplicate)
[ "assert containsDuplicate([1, 2, 3, 1]) == True", "assert containsDuplicate([1, 2, 3, 4]) == False", "assert containsDuplicate([1, 1, 1, 3, 3, 4, 3, 2, 4, 2]) == True" ]
introductory
[]
APPS/3133
def vaccine_list(age: str, status: str, month: str) -> list[str]: """ ### Vaccinations for children under 5 You have been put in charge of administrating vaccinations for children in your local area. Write a function that will generate a list of vaccines for each child presented for vaccination, based on th...
vaccine_list
def check(candidate): assert candidate('12 weeks', 'up-to-date', 'december') == ['fiveInOne', 'rotavirus'] assert candidate('12 months', '16 weeks', 'june') == ['fiveInOne', 'hibMenC', 'measlesMumpsRubella', 'meningitisB', 'pneumococcal'] assert candidate('40 months', '12 months', 'october') == ['hibMenC',...
[ "assert vaccine_list('12 weeks', 'up-to-date', 'december') == ['fiveInOne', 'rotavirus']", "assert vaccine_list('12 months', '16 weeks', 'june') == ['fiveInOne', 'hibMenC', 'measlesMumpsRubella', 'meningitisB', 'pneumococcal']", "assert vaccine_list('40 months', '12 months', 'october') == ['hibMenC', 'measlesMu...
introductory
[]
APPS/2387
def max_burles_spent(t: int, test_cases: list[int]) -> list[int]: """ Mishka wants to buy some food in the nearby shop. Initially, he has $s$ burles on his card. Mishka can perform the following operation any number of times (possibly, zero): choose some positive integer number $1 \le x \le s$, buy foo...
max_burles_spent
def check(candidate): assert candidate(6, [1, 10, 19, 9876, 12345, 1000000000]) == [1, 11, 21, 10973, 13716, 1111111111] check(max_burles_spent)
[ "assert max_burles_spent(6, [1, 10, 19, 9876, 12345, 1000000000]) == [1, 11, 21, 10973, 13716, 1111111111]" ]
introductory
[]
APPS/4634
def pac_man(N: int, PM: list[int], enemies: list[list[int]]) -> int: """ # Task Pac-Man got lucky today! Due to minor performance issue all his enemies have frozen. Too bad Pac-Man is not brave enough to face them right now, so he doesn't want any enemy to see him. Given a gamefield of size `N` x `...
pac_man
def check(candidate): assert candidate(1, [0, 0], []) == 0 assert candidate(2, [0, 0], []) == 3 assert candidate(3, [0, 0], []) == 8 assert candidate(3, [1, 1], []) == 8 assert candidate(2, [0, 0], [[1, 1]]) == 0 assert candidate(3, [2, 0], [[1, 1]]) == 0 assert candidate(3, [2, 0], [[0, 2]...
[ "assert pac_man(1, [0, 0], []) == 0", "assert pac_man(10, [4, 6], [[0, 2], [5, 2], [5, 5]]) == 15", "assert pac_man(8, [1, 1], [[5, 4]]) == 19" ]
introductory
[]
APPS/2537
def distanceBetweenBusStops(distance: List[int], start: int, destination: int) -> int: """ A bus has n stops numbered from 0 to n - 1 that form a circle. We know the distance between all pairs of neighboring stops where distance[i] is the distance between the stops number i and (i + 1) % n. The bus goes alo...
distanceBetweenBusStops
def check(candidate): assert candidate([1, 2, 3, 4], 0, 1) == 1 assert candidate([1, 2, 3, 4], 0, 2) == 3 assert candidate([1, 2, 3, 4], 0, 3) == 4 check(distanceBetweenBusStops)
[ "assert distanceBetweenBusStops([1, 2, 3, 4], 0, 1) == 1", "assert distanceBetweenBusStops([1, 2, 3, 4], 0, 2) == 3", "assert distanceBetweenBusStops([1, 2, 3, 4], 0, 3) == 4" ]
introductory
[]
APPS/2520
def reverse(x: int) -> int: """ Given a 32-bit signed integer, reverse digits of an integer. Example 1: Input: 123 Output: 321 Example 2: Input: -123 Output: -321 Example 3: Input: 120 Output: 21 Note: A...
reverse
def check(candidate): assert candidate(123) == 321 assert candidate(-123) == -321 assert candidate(120) == 21 check(reverse)
[ "assert reverse(123) == 321", "assert reverse(-123) == -321", "assert reverse(120) == 21" ]
introductory
[]
APPS/2394
def min_moves_to_regular_bracket_sequence(t: int, test_cases: list[tuple[int, str]]) -> list[int]: """ You are given a bracket sequence $s$ of length $n$, where $n$ is even (divisible by two). The string $s$ consists of $\frac{n}{2}$ opening brackets '(' and $\frac{n}{2}$ closing brackets ')'. In one m...
min_moves_to_regular_bracket_sequence
def check(candidate): assert candidate(4, [(2, ')('), (4, '()()'), (8, '())()()('), (10, ')))((((())')]) == [1, 0, 1, 3] check(min_moves_to_regular_bracket_sequence)
[ "assert min_moves_to_regular_bracket_sequence(4, [(2, ')('), (4, '()()'), (8, '())()()('), (10, ')))((((())')]) == [1, 0, 1, 3]" ]
introductory
[]
APPS/2469
def checkIfExist(arr: list[int]) -> bool: """ Given an array arr of integers, check if there exists two integers N and M such that N is the double of M ( i.e. N = 2 * M). More formally check if there exists two indices i and j such that : i != j 0 <= i, j < arr.length arr[i] == 2 * arr[j] ...
checkIfExist
def check(candidate): assert candidate([10, 2, 5, 3]) == True assert candidate([7, 1, 14, 11]) == True assert candidate([3, 1, 7, 11]) == False check(checkIfExist)
[ "assert checkIfExist([10, 2, 5, 3]) == True", "assert checkIfExist([7, 1, 14, 11]) == True", "assert checkIfExist([3, 1, 7, 11]) == False" ]
introductory
[]
APPS/2379
def min_num_subsequences(t: int, test_cases: list[tuple[int, str]]) -> list[tuple[int, list[int]]]: """ You are given a binary string $s$ consisting of $n$ zeros and ones. Your task is to divide the given string into the minimum number of subsequences in such a way that each character of the string bel...
min_num_subsequences
def check(candidate): assert candidate(4, [(4, '0011'), (6, '111111'), (5, '10101'), (8, '01010000')]) == [(2, [1, 2, 2, 1]), (6, [1, 2, 3, 4, 5, 6]), (1, [1, 1, 1, 1, 1]), (4, [1, 1, 1, 1, 1, 2, 3, 4])] check(min_num_subsequences)
[ "assert min_num_subsequences(4, [(4, '0011'), (6, '111111'), (5, '10101'), (8, '01010000')]) == [(2, [1, 2, 2, 1]), (6, [1, 2, 3, 4, 5, 6]), (1, [1, 1, 1, 1, 1]), (4, [1, 1, 1, 1, 1, 2, 3, 4])]" ]
introductory
[]
APPS/4255
def make_upper_case(s: str) -> str: """ Write a function which converts the input string to uppercase. ~~~if:bf For BF all inputs end with \0, all inputs are lowercases and there is no space between. ~~~ """
make_upper_case
def check(candidate): assert candidate('hello') == 'HELLO' assert candidate('hello world') == 'HELLO WORLD' assert candidate('hello world !') == 'HELLO WORLD !' assert candidate('heLlO wORLd !') == 'HELLO WORLD !' assert candidate('1,2,3 hello world!') == '1,2,3 HELLO WORLD!' check(make_upper_case)...
[ "assert make_upper_case('hello world !') == 'HELLO WORLD !'" ]
introductory
[]
APPS/3843
def encrypt(text: str) -> str: """ For encrypting strings this region of chars is given (in this order!): * all letters (ascending, first all UpperCase, then all LowerCase) * all digits (ascending) * the following chars: `.,:;-?! '()$%&"` These are 77 chars! (This region is zero-based....
encrypt
def check(candidate): assert candidate('$-Wy,dM79H\'i\'o$n0C&I.ZTcMJw5vPlZc Hn!krhlaa:khV mkL;gvtP-S7Rt1Vp2RV:wV9VuhO Iz3dqb.U0w') == 'Do the kata "Kobayashi-Maru-Test!" Endless fun and excitement when finding a solution!' assert candidate('5MyQa9p0riYplZc') == 'This is a test!' assert candidate('5MyQa79H\...
[ "assert encrypt('$-Wy,dM79H\\'i\\'o$n0C&I.ZTcMJw5vPlZc Hn!krhlaa:khV mkL;gvtP-S7Rt1Vp2RV:wV9VuhO Iz3dqb.U0w') == 'Do the kata \"Kobayashi-Maru-Test!\" Endless fun and excitement when finding a solution!'" ]
introductory
[]
APPS/2431
def find_unique_k_diff_pairs(arr: list[int], k: int) -> int: """ Given an array of integers and an integer k, you need to find the number of unique k-diff pairs in the array. Here a k-diff pair is defined as an integer pair (i, j), where i and j are both numbers in the array and their absolute difference is k. ...
find_unique_k_diff_pairs
def check(candidate): assert candidate([3, 1, 4, 1, 5], 2) == 2 assert candidate([1, 2, 3, 4, 5], 1) == 4 assert candidate([1, 3, 1, 5, 4], 0) == 1 check(find_unique_k_diff_pairs)
[ "assert find_unique_k_diff_pairs([3, 1, 4, 1, 5], 2) == 2", "assert find_unique_k_diff_pairs([1, 2, 3, 4, 5], 1) == 4", "assert find_unique_k_diff_pairs([1, 3, 1, 5, 4], 0) == 1" ]
introductory
[]
APPS/1545
def check_parity_QC(n: int, cases: List[Tuple[int, int]]) -> List[int]: """ The Quark Codejam's number QC(n, m) represents the number of ways to partition a set of n things into m nonempty subsets. For example, there are seven ways to split a four-element set into two parts: {1, 2, 3} ∪ {4}, {1, 2, 4} ...
check_parity_QC
def check(candidate): assert candidate(1, [(4, 2)]) == [1] check(check_parity_QC)
[ "assert check_parity_QC(1, [(4, 2)]) == [1]" ]
interview
[]
APPS/910
def calculate_scales(T: int, test_cases: List[Tuple[str, int]]) -> List[int]: """ Recently, Chef got obsessed with piano. He is a just a rookie in this stuff and can not move his fingers from one key to other fast enough. He discovered that the best way to train finger speed is to play scales. There ar...
calculate_scales
def check(candidate): assert candidate(2, [('TTTT', 1), ('TTSTTTS', 3)]) == [4, 36] check(calculate_scales)
[ "assert calculate_scales(2, [('TTTT', 1), ('TTSTTTS', 3)]) == [4, 36]" ]
interview
[]
APPS/1037
def pawn_chess(T: int, test_cases: List[str]) -> List[str]: """ Ada is playing pawn chess with Suzumo. Pawn chess is played on a long board with N$N$ squares in one row. Initially, some of the squares contain pawns. Note that the colours of the squares and pawns do not matter in this game, but otherwise...
pawn_chess
def check(candidate): assert candidate(1, ['..P.P']) == ['Yes'] check(pawn_chess)
[ "assert pawn_chess(1, ['..P.P']) == ['Yes']" ]
interview
[]
APPS/1562
def minimize_m(T: int, test_cases: List[Tuple[int, List[int]]]) -> List[int]: """ "I'm a fan of anything that tries to replace actual human contact." - Sheldon. After years of hard work, Sheldon was finally able to develop a formula which would diminish the real human contact. He found k$k$ integers n1,...
minimize_m
def check(candidate): assert candidate(1, [(1, [5])]) == [2] check(minimize_m)
[ "assert minimize_m(1, [(1, [5])]) == [2]" ]
interview
[]
APPS/749
def min_additional_cost(N: int, costs: List[List[int]]) -> int: """ The Government of Siruseri is no different from any other when it comes to being "capital-centric" in its policies. Recently the government decided to set up a nationwide fiber-optic network to take Siruseri into the digital age. And as usual, ...
min_additional_cost
def check(candidate): assert candidate(4, [[0, 7, 8, 10], [7, 0, 4, 5], [8, 4, 0, 6], [10, 5, 6, 0]]) == 9 check(min_additional_cost)
[ "assert min_additional_cost(4, [[0, 7, 8, 10], [7, 0, 4, 5], [8, 4, 0, 6], [10, 5, 6, 0]]) == 9" ]
interview
[]
APPS/613
def count_bubbly_words(M: int, words: List[str]) -> int: """ -----Problem----- Nikki's latest work is writing a story of letters. However, she finds writing story so boring that, after working for three hours, she realized that all she has written are M long words consisting entirely of letters A and B...
count_bubbly_words
def check(candidate): assert candidate(3, ['ABAB', 'AABB', 'ABBA']) == 2 check(count_bubbly_words)
[ "assert count_bubbly_words(3, ['ABAB', 'AABB', 'ABBA']) == 2" ]
interview
[]
APPS/837
def sum_of_multiples(T: int, test_cases: List[int]) -> List[int]: """ Find sum of all the numbers that are multiples of 10 and are less than or equal to a given number "N". (quotes for clarity and be careful of integer overflow) -----Input----- Input will start with an integer T the count of test c...
sum_of_multiples
def check(candidate): assert candidate(1, [10]) == [10] assert candidate(2, [10, 20]) == [10, 30] assert candidate(1, [1]) == [0] assert candidate(3, [30, 40, 50]) == [60, 100, 150] check(sum_of_multiples)
[ "assert sum_of_multiples(1, [10]) == [10]" ]
interview
[]
APPS/725
def avoid_arrest(T: int, test_cases: List[Tuple[int, int, int, List[int]]]) -> List[int]: """ The Little Elephant and his friends from the Zoo of Lviv were returning from the party. But suddenly they were stopped by the policeman Big Hippo, who wanted to make an alcohol test for elephants. There were N elep...
avoid_arrest
def check(candidate): assert candidate(4, [(5, 3, 2, [1, 3, 1, 2, 1]), (5, 3, 3, [7, 7, 7, 7, 7]), (5, 3, 3, [7, 7, 7, 8, 8]), (4, 3, 1, [1, 3, 1, 2])]) == [0, 1, 1, -1] check(avoid_arrest)
[ "assert avoid_arrest(4, [(5, 3, 2, [1, 3, 1, 2, 1]), (5, 3, 3, [7, 7, 7, 7, 7]), (5, 3, 3, [7, 7, 7, 8, 8]), (4, 3, 1, [1, 3, 1, 2])]) == [0, 1, 1, -1]" ]
interview
[]
APPS/753
def max_nice_bouquet(T: int, test_cases: List[Tuple[List[int], List[int], List[int]]]) -> List[int]: """ It's autumn now, the time of the leaf fall. Sergey likes to collect fallen leaves in autumn. In his city, he can find fallen leaves of maple, oak and poplar. These leaves can be of three different colors...
max_nice_bouquet
def check(candidate): assert candidate(1, [([1, 2, 3], [3, 2, 1], [1, 3, 4])]) == [7] check(max_nice_bouquet)
[ "assert max_nice_bouquet(1, [([1, 2, 3], [3, 2, 1], [1, 3, 4])]) == [7]" ]
interview
[]
APPS/1419
def max_gcd_of_tracks(T: int, test_cases: List[Tuple[int, str, Tuple[int, int, int]]]) -> List[int]: """ Mr. Wilson was planning to record his new Progressive Rock music album called "Digits. Cannot. Separate". Xenny and PowerShell, popular pseudo-number-theoreticists from the Land of Lazarus were called by him...
max_gcd_of_tracks
def check(candidate): assert candidate(2, [(3, '474', (2, 1, 1)), (34, '6311861109697810998905373107116111', (10, 4, 25))]) == [2, 1] check(max_gcd_of_tracks)
[ "assert max_gcd_of_tracks(2, [(3, '474', (2, 1, 1)), (34, '6311861109697810998905373107116111', (10, 4, 25))]) == [2, 1]" ]
interview
[]
APPS/669
def count_trips(T: int, test_cases: List[Tuple[int, int, int, List[Tuple[int, int]], int, List[Tuple[int, int]]]]) -> List[int]: """ Nadaca is a country with N$N$ cities. These cities are numbered 1$1$ through N$N$ and connected by M$M$ bidirectional roads. Each city can be reached from every other city using t...
count_trips
def check(candidate): assert candidate(3, [ (4, 3, 3, [(1, 2), (1, 3), (1, 4)], 0, []), (4, 3, 3, [(1, 2), (1, 3), (1, 4)], 1, [(2, 2)]), (4, 3, 3, [(1, 2), (1, 3), (1, 4)], 1, [(2, 1)]) ]) == [28, 4, 6] check(count_trips)
[ "assert count_trips(3, [\n (4, 3, 3, [(1, 2), (1, 3), (1, 4)], 0, []),\n (4, 3, 3, [(1, 2), (1, 3), (1, 4)], 1, [(2, 2)]),\n (4, 3, 3, [(1, 2), (1, 3), (1, 4)], 1, [(2, 1)])\n]) == [28, 4, 6]\n" ]
interview
[]
APPS/1095
def min_moves_to_sort(N: int, books: List[int]) -> int: """ Indraneel has to sort the books in his library. His library has one long shelf. His books are numbered $1$ through $N$ and he wants to rearrange the books so that they appear in the sequence $1,2, ..., N$. He intends to do this by a sequence of mov...
min_moves_to_sort
def check(candidate): assert candidate(5, [2, 1, 4, 5, 3]) == 2 check(min_moves_to_sort)
[ "assert min_moves_to_sort(5, [2, 1, 4, 5, 3]) == 2" ]
interview
[]
APPS/407
def score_of_parentheses(S: str) -> int: """ Given a balanced parentheses string S, compute the score of the string based on the following rule: () has score 1 AB has score A + B, where A and B are balanced parentheses strings. (A) has score 2 * A, where A is a balanced parentheses string. ...
score_of_parentheses
def check(candidate): assert candidate('()') == 1 assert candidate('(())') == 2 assert candidate('()()') == 2 assert candidate('(()(()))') == 6 check(score_of_parentheses)
[ "assert score_of_parentheses('()') == 1", "assert score_of_parentheses('(())') == 2", "assert score_of_parentheses('()()') == 2", "assert score_of_parentheses('(()(()))') == 6" ]
interview
[]
APPS/1591
def factorial_modulo(T: int, numbers: List[int]) -> List[int]: """ Master Oogway has forseen that a panda named Po will be the dragon warrior, and the master of Chi. But he did not tell anyone about the spell that would make him the master of Chi, and has left Po confused. Now Po has to defeat Kai, who is the s...
factorial_modulo
def check(candidate): assert candidate(4, [1, 2, 3, 4]) == [1, 2, 6, 24] check(factorial_modulo)
[ "assert factorial_modulo(4, [1, 2, 3, 4]) == [1, 2, 6, 24]" ]
interview
[]
APPS/820
def expected_cost(T: int, test_cases: List[Tuple[int, int, List[Tuple[int, int]]]]) -> List[float]: """ The Little Elephant from the Zoo of Lviv is going to the Birthday Party of the Big Hippo tomorrow. Now he wants to prepare a gift for the Big Hippo. He has N balloons, numbered from 1 to N. The i-th...
expected_cost
def check(candidate): assert abs(candidate(2, [(2, 2, [(1, 4), (2, 7)]), (2, 1, [(1, 4), (2, 7)])]) - [11.000000000, 7.333333333]) < 1e-6 check(expected_cost)
[ "assert abs(expected_cost(2, [(2, 2, [(1, 4), (2, 7)]), (2, 1, [(1, 4), (2, 7)])]) - [11.000000000, 7.333333333]) < 1e-6" ]
interview
[]
APPS/992
def minimum_cost_to_seal(T: int, test_cases: List[Tuple[int, List[Tuple[int, int]], int, List[Tuple[int, int]]]]) -> List[int]: """ January and February are usually very cold in ChefLand. The temperature may reach -20 and even -30 degrees Celsius. Because of that, many people seal up windows in their houses. ...
minimum_cost_to_seal
def check(candidate): assert candidate(1, [(4, [(0, 0), (1000, 0), (1000, 2000), (0, 2000)], 2, [(1000, 10), (2000, 15)])]) == [50] check(minimum_cost_to_seal)
[ "assert minimum_cost_to_seal(1, [(4, [(0, 0), (1000, 0), (1000, 2000), (0, 2000)], 2, [(1000, 10), (2000, 15)])]) == [50]" ]
interview
[]
APPS/1427
def calculate_distances(N: int, M: int, catchers: List[Tuple[int, int]], S: str) -> List[int]: """ Today, puppy Tuzik is going to a new dog cinema. He has already left his home and just realised that he forgot his dog-collar! This is a real problem because the city is filled with catchers looking for stray dogs...
calculate_distances
def check(candidate): assert candidate(2, 3, [(1, 2), (0, 1)], 'RDL') == [4, 6, 6] check(calculate_distances)
[ "assert calculate_distances(2, 3, [(1, 2), (0, 1)], 'RDL') == [4, 6, 6]" ]
interview
[]
APPS/1090
def shortest_subsequence_length(T: int, test_cases: List[Tuple[int, int, List[int]]]) -> List[int]: """ You are given a sequence of n integers a1, a2, ..., an and an integer d. Find the length of the shortest non-empty contiguous subsequence with sum of elements at least d. Formally, you should find the sma...
shortest_subsequence_length
def check(candidate): assert candidate(2, [(5, 5, [1, 2, 3, 1, -5]), (5, 1, [1, 2, 3, 1, -5])]) == [2, 1] check(shortest_subsequence_length)
[ "assert shortest_subsequence_length(2, [(5, 5, [1, 2, 3, 1, -5]), (5, 1, [1, 2, 3, 1, -5])]) == [2, 1]" ]
interview
[]
APPS/968
def find_path_costs(N: int, parents: List[int], values: List[int]) -> List[int]: """ You are given a rooted tree on N vertices. The nodes are numbered from 1 to N, and Node 1 is the root. Each node u has an associated value attached to it: Au. For each vertex v, we consider the path going upwards from v to ...
find_path_costs
def check(candidate): assert candidate(8, [1, 1, 1, 1, 5, 8, 6], [1, 2, 3, 4, 5, 15, 70, 10]) == [1, 3, 4, 5, 6, 21, 96, 26] check(find_path_costs)
[ "assert find_path_costs(8, [1, 1, 1, 1, 5, 8, 6], [1, 2, 3, 4, 5, 15, 70, 10]) == [1, 3, 4, 5, 6, 21, 96, 26]" ]
interview
[]
APPS/1467
def min_lies(t: int, test_cases: List[Tuple[int, List[Tuple[str, int, str]]]]) -> List[int]: """ Alice and Johnny are playing a simple guessing game. Johnny picks an arbitrary positive integer n (1<=n<=109) and gives Alice exactly k hints about the value of n. It is Alice's task to guess n, based on the receive...
min_lies
def check(candidate): assert candidate(3, [(2, [('<', 100, 'No'), ('>', 100, 'No')]), (3, [('<', 2, 'Yes'), ('>', 4, 'Yes'), ('=', 3, 'No')]), (6, [('<', 2, 'Yes'), ('>', 1, 'Yes'), ('=', 1, 'Yes'), ('=', 1, 'Yes'), ('>', 1, 'Yes'), ('=', 1, 'Yes')])]) == [0, 1, 2] check(min_lies)
[ "assert min_lies(3, [(2, [('<', 100, 'No'), ('>', 100, 'No')]), (3, [('<', 2, 'Yes'), ('>', 4, 'Yes'), ('=', 3, 'No')]), (6, [('<', 2, 'Yes'), ('>', 1, 'Yes'), ('=', 1, 'Yes'), ('=', 1, 'Yes'), ('>', 1, 'Yes'), ('=', 1, 'Yes')])]) == [0, 1, 2]" ]
interview
[]
APPS/646
def min_string_length(T: int, test_cases: List[str]) -> List[int]: """ Given a string $s$. You can perform the following operation on given string any number of time. Delete two successive elements of the string if they are same. After performing the above operation you have to return the least poss...
min_string_length
def check(candidate): assert candidate(3, ['abccd', 'abbac', 'aaaa']) == [3, 1, 0] check(min_string_length)
[ "assert min_string_length(3, ['abccd', 'abbac', 'aaaa']) == [3, 1, 0]" ]
interview
[]
APPS/1561
def generate_tiles(T: int, cases: List[int]) -> List[str]: """ Chef Tobby asked Bhuvan to brush up his knowledge of statistics for a test. While studying some distributions, Bhuvan learns the fact that for symmetric distributions, the mean and the median are always the same. Chef Tobby asks Bhuvan out for a...
generate_tiles
def check(candidate): assert candidate(3, [1, 2, 3]) == ['1', '1 2', '1 2 3'] check(generate_tiles)
[ "assert generate_tiles(3, [1, 2, 3]) == ['1', '1 2', '1 2 3']" ]
interview
[]
APPS/1348
def shortest_average_path(T: int, test_cases: List[Tuple[int, int, List[Tuple[int, int, int]], Tuple[int, int]]]) -> List[float]: """ There are a lot of problems related to the shortest paths. Nevertheless, there are not much problems, related to the shortest paths in average. Consider a directed graph G, c...
shortest_average_path
def check(candidate): assert candidate(2, [(3, 3, [(1, 2, 1), (2, 3, 2), (3, 2, 3)], (1, 3)), (3, 3, [(1, 2, 10), (2, 3, 1), (3, 2, 1)], (1, 3))]) == [1.5, 1.0] check(shortest_average_path)
[ "assert shortest_average_path(2, [(3, 3, [(1, 2, 1), (2, 3, 2), (3, 2, 3)], (1, 3)), (3, 3, [(1, 2, 10), (2, 3, 1), (3, 2, 1)], (1, 3))]) == [1.5, 1.0]" ]
interview
[]
APPS/451
def check_reducible_anagrams(S: str, T: str) -> bool: """ Given two strings S and T, each of which represents a non-negative rational number, return True if and only if they represent the same number. The strings may use parentheses to denote the repeating part of the rational number. In general a rational ...
check_reducible_anagrams
def check(candidate): assert candidate("0.(52)", "0.5(25)") == True assert candidate("0.1666(6)", "0.166(66)") == True assert candidate("0.9(9)", "1.") == True check(check_reducible_anagrams)
[ "assert check_reducible_anagrams(\"0.(52)\", \"0.5(25)\") == True", "assert check_reducible_anagrams(\"0.1666(6)\", \"0.166(66)\") == True", "assert check_reducible_anagrams(\"0.9(9)\", \"1.\") == True" ]
interview
[]
APPS/1072
def check_reducible_anagrams(T: int, N: List[int]) -> List[str]: """ Problem description. Winston and Royce love sharing memes with each other. They express the amount of seconds they laughed ar a meme as the number of ‘XD’ subsequences in their messages. Being optimization freaks, they wanted to find the s...
check_reducible_anagrams
def check(candidate): assert candidate(1, [9]) == ['XXXDDD'] check(check_reducible_anagrams)
[ "assert check_reducible_anagrams(1, [9]) == ['XXXDDD']" ]
interview
[]
APPS/299
def min_cost(grid: List[List[int]]) -> int: """ Given a m x n grid. Each cell of the grid has a sign pointing to the next cell you should visit if you are currently in this cell. The sign of grid[i][j] can be: 1 which means go to the cell to the right. (i.e go from grid[i][j] to grid[i][j + 1]) 2 w...
min_cost
def check(candidate): assert candidate([[1,1,1,1],[2,2,2,2],[1,1,1,1],[2,2,2,2]]) == 3 assert candidate([[1,1,3],[3,2,2],[1,1,4]]) == 0 assert candidate([[1,2],[4,3]]) == 1 assert candidate([[2,2,2],[2,2,2]]) == 3 assert candidate([[4]]) == 0 check(min_cost)
[ "assert min_cost([[1,1,1,1],[2,2,2,2],[1,1,1,1],[2,2,2,2]]) == 3", "assert min_cost([[1,1,3],[3,2,2],[1,1,4]]) == 0", "assert min_cost([[1,2],[4,3]]) == 1", "assert min_cost([[2,2,2],[2,2,2]]) == 3", "assert min_cost([[4]]) == 0" ]
interview
[]
APPS/1565
def find_A_from_B(T: int, test_cases: List[Tuple[int, int, int, List[List[List[int]]]]]) -> List[List[List[int]]]: """ Suppose there is a X x Y x Z 3D matrix A of numbers having coordinates (i, j, k) where 0 ≤ i < X, 0 ≤ j < Y, 0 ≤ k < Z. Now another X x Y x Z matrix B is defined from A such that the (i, j, k) ...
find_A_from_B
def check(candidate): assert candidate(2, [(3, 1, 1, [[[1]], [[8]], [[22]]]), (1, 2, 3, [[[0, 9, 13], [18, 45, 51]]])]) == [[[1], [7], [14]], [[0, 9, 4], [18, 18, 2]]] check(find_A_from_B)
[ "assert find_A_from_B(2, [(3, 1, 1, [[[1]], [[8]], [[22]]]), (1, 2, 3, [[[0, 9, 13], [18, 45, 51]]])]) == [[[1], [7], [14]], [[0, 9, 4], [18, 18, 2]]]" ]
interview
[]
APPS/1314
def game_outcome(N: int, M: int, A: List[int], games: List[Tuple[str, int, str]]) -> str: """ Devu and Churu love to play games a lot. Today, they have an array A consisting of N positive integers. First they listed all N × (N+1) / 2 non-empty continuous subarrays of the array A on a piece of paper and then rep...
game_outcome
def check(candidate): assert candidate(3, 5, [1, 2, 3], [('>', 1, 'D'), ('<', 2, 'C'), ('=', 3, 'D'), ('>', 4, 'C'), ('<', 5, 'D')]) == 'DCDDC' check(game_outcome)
[ "assert game_outcome(3, 5, [1, 2, 3], [('>', 1, 'D'), ('<', 2, 'C'), ('=', 3, 'D'), ('>', 4, 'C'), ('<', 5, 'D')]) == 'DCDDC'" ]
interview
[]
APPS/986
def arrange_buildings(T: int, test_cases: List[Tuple[int, int]]) -> List[str]: """ Problem Statement:Captain America and Iron Man are at WAR and the rage inside Iron Man is rising. But Iron Man faces a problem to identify the location of Captain America. There are N buildings situtaed adjacent...
arrange_buildings
def check(candidate): assert candidate(3, [(2, 1), (3, 0), (3, 2)]) == ['2 1', '1 2 3', 'CAPTAIN AMERICA EVADES'] check(arrange_buildings)
[ "assert arrange_buildings(3, [(2, 1), (3, 0), (3, 2)]) == ['2 1', '1 2 3', 'CAPTAIN AMERICA EVADES']" ]
interview
[]
APPS/549
def min_cuts_sky_scrapers(n: int, heights: List[int]) -> int: """ In a fictitious city of CODASLAM there were many skyscrapers. The mayor of the city decided to make the city beautiful and for this he decided to arrange the skyscrapers in descending order of their height, and the order must be strictly decreasi...
min_cuts_sky_scrapers
def check(candidate): assert candidate(5, [1, 2, 3, 4, 5]) == 8 check(min_cuts_sky_scrapers)
[ "assert min_cuts_sky_scrapers(5, [1, 2, 3, 4, 5]) == 8" ]
interview
[]
APPS/558
def earliest_arrival_time(M: int, N: int, rows: List[Tuple[str, int]], cols: List[Tuple[str, int]], start: Tuple[int, int, int], destination: Tuple[int, int]) -> int: """ The city of Siruseri is impeccably planned. The city is divided into a rectangular array of cells with $M$ rows and $N$ columns. Each cell ha...
earliest_arrival_time
def check(candidate): assert candidate(3, 4, [('F', 3), ('S', 2), ('O', 2)], [('S', 1), ('F', 2), ('O', 2), ('F', 4)], (2, 3, 8), (1, 1)) == 15 check(earliest_arrival_time)
[ "assert earliest_arrival_time(3, 4, [('F', 3), ('S', 2), ('O', 2)], [('S', 1), ('F', 2), ('O', 2), ('F', 4)], (2, 3, 8), (1, 1)) == 15" ]
interview
[]
APPS/1231
def sum_of_digits_of_powers(T: int, numbers: List[int]) -> List[int]: """ The chef won a duet singing award at Techsurge & Mridang 2012. From that time he is obsessed with the number 2. He just started calculating the powers of two. And adding the digits of the results. But he got puzzled afte...
sum_of_digits_of_powers
def check(candidate): assert candidate(3, [5, 10, 4]) == [5, 7, 7] check(sum_of_digits_of_powers)
[ "assert sum_of_digits_of_powers(3, [5, 10, 4]) == [5, 7, 7]" ]
interview
[]
APPS/1159
def string_game_winner(T: int, test_cases: List[str]) -> List[str]: """ Abhi and his friends (Shanky,Anku and Pandey) love to play with strings. Abhi invented a simple game. He will give a string S to his friends. Shanky and Anku will play the game while Pandey is just a spectator. Shanky will traverse the stri...
string_game_winner
def check(candidate): assert candidate(3, ['google', 'breakraekb', 'aman']) == ['SHANKY', 'PANDEY', 'ANKU'] check(string_game_winner)
[ "assert string_game_winner(3, ['google', 'breakraekb', 'aman']) == ['SHANKY', 'PANDEY', 'ANKU']" ]
interview
[]
End of preview. Expand in Data Studio
README.md exists but content is empty.
Downloads last month
5