task_type stringclasses 1
value | problem stringlengths 209 3.39k | answer stringlengths 35 6.15k | problem_tokens int64 60 774 | answer_tokens int64 12 2.04k |
|---|---|---|---|---|
coding | Solve the programming task below in a Python markdown code block.
The number ```12``` is the first number in having six divisors, they are: ```1, 2, 3, 4, 6 and 12.```
Your challenge for this kata is to find the minimum number that has a certain number of divisors.
For this purpose we have to create the function
```f... | {"functional": "_inputs = [[6], [10], [12], [13]]\n_outputs = [[12], [48], [60], [4096]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): retu... | 300 | 182 |
coding | Solve the programming task below in a Python markdown code block.
Algorithmic predicament - Bug Fixing #9
Oh no! Timmy's algorithim has gone wrong! help Timmy fix his algorithim!
Task
Your task is to fix timmy's algorithim so it returns the group name with the highest total age.
You will receive two groups of `peo... | {"functional": "_inputs = [[[{'name': 'kay', 'age': 1}, {'name': 'john', 'age': 13}, {'name': 'kay', 'age': 76}], [{'name': 'john', 'age': 1}, {'name': 'alice', 'age': 77}]], [[{'name': 'kay', 'age': 1}, {'name': 'john', 'age': 13}, {'name': 'kay', 'age': 76}], [{'name': 'john', 'age': 1}, {'name': 'alice', 'age': 76}]... | 179 | 506 |
coding | Solve the programming task below in a Python markdown code block.
Aayush has recently started teaching Latin Dance. Today, he will be teaching Salsa. For this, he needs to divide the people attending his dance class into pairs. Usually in Salsa, the dance pairs consist of one girl and one boy. But Aayush doesn't find t... | {"inputs": ["2\n5 8\n7 10"], "outputs": ["5\n6\n"]} | 412 | 24 |
coding | Solve the programming task below in a Python markdown code block.
You are given $n$ elements numbered from $1$ to $n$, the element $i$ has value $a_i$ and color $c_i$, initially, $c_i = 0$ for all $i$.
The following operation can be applied:
Select three elements $i$, $j$ and $k$ ($1 \leq i < j < k \leq n$), such tha... | {"inputs": ["3\n1 1 2\n", "3\n1 1 1\n", "3\n1 2 1\n", "3\n1 2 2\n", "3\n1 2 3\n", "7\n1 2 1 2 7 4 7\n", "13\n1 2 3 2 1 3 3 4 5 5 5 4 7\n"], "outputs": ["0\n", "1\n", "1\n", "0\n", "0\n", "2\n", "7\n"]} | 386 | 133 |
coding | Solve the programming task below in a Python markdown code block.
Given three distinct integers $a$, $b$, and $c$, find the medium number between all of them.
The medium number is the number that is neither the minimum nor the maximum of the given three numbers.
For example, the median of $5,2,6$ is $5$, since the mi... | {"inputs": ["1\n1 3 2\n", "1\n1 2 3\n", "1\n1 3 4\n", "1\n2 3 4\n", "1\n1 2 4\n", "1\n17 2 3\n", "2\n1 2 3\n2 3 1\n", "3\n1 2 3\n1 2 3\n1 2 3\n"], "outputs": ["2\n", "2\n", "3\n", "3\n", "2\n", "3\n", "2\n2\n", "2\n2\n2\n"]} | 279 | 143 |
coding | Solve the programming task below in a Python markdown code block.
Write a function that accepts a square matrix (`N x N` 2D array) and returns the determinant of the matrix.
How to take the determinant of a matrix -- it is simplest to start with the smallest cases:
A 1x1 matrix `|a|` has determinant `a`.
A 2x2 matri... | {"functional": "_inputs = [[[[5]]]]\n_outputs = [[5]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_... | 388 | 157 |
coding | Solve the programming task below in a Python markdown code block.
###Story
Sometimes we are faced with problems when we have a big nested dictionary with which it's hard to work. Now, we need to solve this problem by writing a function that will flatten a given dictionary.
###Info
Python dictionaries are a convenient ... | {"functional": "_inputs = [[{'key': 'value'}], [{'key': {'deeper': {'more': {'enough': 'value'}}}}], [{'empty': {}}], [{'additional': {'place': {'cell': '2', 'zone': '1'}}, 'job': 'scout', 'name': {'last': 'Drone', 'first': 'One'}, 'recent': {}}], [{'job': {'1': 'scout', '2': 'worker', '3': 'writer', '4': 'reader', '5'... | 461 | 1,001 |
coding | Solve the programming task below in a Python markdown code block.
There are N sightseeing spots on the x-axis, numbered 1, 2, ..., N.
Spot i is at the point with coordinate A_i.
It costs |a - b| yen (the currency of Japan) to travel from a point with coordinate a to another point with coordinate b along the axis.
You p... | {"inputs": ["3\n3 5 -1\n", "5\n1 1 1 2 0\n", "6\n-679 -2409 -3258 3095 -3291 -4462\n"], "outputs": ["12\n8\n10\n", "4\n4\n4\n2\n4\n", "21630\n21630\n19932\n8924\n21630\n19288\n"]} | 566 | 123 |
coding | Solve the programming task below in a Python markdown code block.
You are given a directed graph consisting of n vertices and m edges (each edge is directed, so it can be traversed in only one direction). You are allowed to remove at most one edge from it.
Can you make this graph acyclic by removing at most one edge f... | {"inputs": ["2 2\n1 2\n2 1\n", "2 2\n1 2\n2 1\n", "3 3\n2 3\n2 1\n3 2\n", "3 3\n2 3\n2 1\n3 2\n", "3 4\n1 2\n2 3\n3 2\n3 1\n", "3 4\n1 2\n2 1\n1 3\n3 1\n", "4 4\n1 2\n2 1\n3 4\n4 3\n", "3 4\n3 2\n1 2\n2 3\n1 3\n"], "outputs": ["YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "NO\n", "NO\n", "YES\n"]} | 375 | 190 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a 2D integer array nums where nums[i] is a non-empty array of distinct positive integers, return the list of integers that are present in each array of nums sorted in ascending order.
Please complete the follo... | {"functional": "def check(candidate):\n assert candidate(nums = [[3,1,2,4,5],[1,2,3,4],[3,4,5,6]]) == [3,4]\n assert candidate(nums = [[1,2,3],[4,5,6]]) == []\n\n\ncheck(Solution().intersection)"} | 89 | 79 |
coding | Solve the programming task below in a Python markdown code block.
A histogram is made of a number of contiguous bars, which have same width.
For a given histogram with $N$ bars which have a width of 1 and a height of $h_i$ = $h_1, h_2, ... , h_N$ respectively, find the area of the largest rectangular area.
Constraint... | {"inputs": ["3\n3 0 1", "3\n5 0 0", "3\n0 0 0", "3\n0 0 1", "3\n2 0 2", "3\n6 1 0", "3\n4 1 2", "3\n7 2 1"], "outputs": ["3\n", "5\n", "0\n", "1\n", "2\n", "6\n", "4\n", "7\n"]} | 192 | 110 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given the head of a linked list and an integer val, remove all the nodes of the linked list that has Node.val == val, and return the new head.
Please complete the following python code precisely:
```python
# Definit... | {"functional": "def check(candidate):\n assert is_same_list(candidate(head = list_node([1,2,6,3,4,5,6]), val = 6), list_node([1,2,3,4,5]))\n assert is_same_list(candidate(head = list_node([]), val = 1), list_node([]))\n assert is_same_list(candidate(head = list_node([7,7,7,7]), val = 7), list_node([]))\n\n\nch... | 128 | 117 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer array nums, return the sum of divisors of the integers in that array that have exactly four divisors. If there is no such integer in the array, return 0.
Please complete the following python code pr... | {"functional": "def check(candidate):\n assert candidate(nums = [21,4,7]) == 32\n\n\ncheck(Solution().sumFourDivisors)"} | 89 | 39 |
coding | Solve the programming task below in a Python markdown code block.
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 received hints.
Alice often has a serious pr... | {"inputs": ["3\n2\n< 100 No\n> 100 No\n3\n< 2 Yes\n> 4 Yes\n= 3 No\n6\n< 2 Yes\n> 1 Yes\n= 1 Yes\n= 1 Yes\n> 1 Yes\n= 1 Yes", "3\n2\n< 100 No\n> 100 No\n3\n< 2 Yes\n> 4 Yes\n= 3 No\n6\n< 2 Yes\n> 1 Yes\n= 1 Yes\n= 1 Yes\n= 1 Yes\n= 1 Yes", "3\n2\n< 100 No\n? 100 No\n3\n< 2 Yes\n> 4 Yes\n= 3 No\n6\n< 2 Yes\n> 1 Yes\n= 1... | 502 | 619 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
There are n cars on an infinitely long road. The cars are numbered from 0 to n - 1 from left to right and each car is present at a unique point.
You are given a 0-indexed string directions of length n. directions[i] c... | {"functional": "def check(candidate):\n assert candidate(directions = \"RLRSLL\") == 5\n assert candidate(directions = \"LLRR\") == 0\n\n\ncheck(Solution().countCollisions)"} | 245 | 49 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an m x n binary matrix grid where each cell is either 0 (empty) or 1 (occupied).
You are then given stamps of size stampHeight x stampWidth. We want to fit the stamps such that they follow the given rest... | {"functional": "def check(candidate):\n assert candidate(grid = [[1,0,0,0],[1,0,0,0],[1,0,0,0],[1,0,0,0],[1,0,0,0]], stampHeight = 4, stampWidth = 3) == True\n assert candidate(grid = [[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]], stampHeight = 2, stampWidth = 2 ) == False \n\n\ncheck(Solution().possibleToStamp)"} | 189 | 135 |
coding | Solve the programming task below in a Python markdown code block.
An Ironman Triathlon is one of a series of long-distance triathlon races organized by the World Triathlon Corporaion (WTC).
It consists of a 2.4-mile swim, a 112-mile bicycle ride and a marathon (26.2-mile) (run, raced in that order and without a break. ... | {"functional": "_inputs = [[36], [103], [0], [2], [151]]\n_outputs = [[{'Bike': '104.60 to go!'}], [{'Bike': '37.60 to go!'}], ['Starting Line... Good Luck!'], [{'Swim': '138.60 to go!'}], [\"You're done! Stop running!\"]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):... | 312 | 234 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a string of English letters s, return the greatest English letter which occurs as both a lowercase and uppercase letter in s. The returned letter should be in uppercase. If no such letter exists, return an empty... | {"functional": "def check(candidate):\n assert candidate(s = \"lEeTcOdE\") == \"E\"\n assert candidate(s = \"arRAzFif\") == \"R\"\n assert candidate(s = \"AbCdEfGhIjK\") == \"\"\n\n\ncheck(Solution().greatestLetter)"} | 111 | 75 |
coding | Solve the programming task below in a Python markdown code block.
A New Year party is not a New Year party without lemonade! As usual, you are expecting a lot of guests, and buying lemonade has already become a pleasant necessity.
Your favorite store sells lemonade in bottles of n different volumes at different costs.... | {"inputs": ["1 1\n1\n", "1 1\n1\n", "2 3\n10 1\n", "2 3\n10 5\n", "2 3\n10 5\n", "2 3\n10 1\n", "2 3\n13 5\n", "2 2\n10 1\n"], "outputs": ["1\n", "1\n", "2\n", "10\n", "10\n", "2\n", "10\n", "1\n"]} | 547 | 123 |
coding | Solve the programming task below in a Python markdown code block.
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.
In a single second, he can ... | {"inputs": ["6 3\n", "8 5\n", "4 3\n", "5 4\n", "4 3\n", "5 4\n", "8 5\n", "6 3\n"], "outputs": ["4\n", "3\n", "3\n", "3\n", "3\n", "3\n", "3\n", "4\n"]} | 469 | 86 |
coding | Solve the programming task below in a Python markdown code block.
You stumbled upon a new kind of chess puzzles. The chessboard you are given is not necesserily $8 \times 8$, but it still is $N \times N$. Each square has some number written on it, all the numbers are from $1$ to $N^2$ and all the numbers are pairwise d... | {"inputs": ["3\n1 9 3\n8 6 7\n4 2 5\n", "3\n1 5 8\n9 2 4\n3 6 7\n", "3\n1 4 7\n6 9 2\n3 8 5\n", "3\n1 6 3\n7 2 9\n4 8 5\n", "3\n1 6 3\n4 9 8\n7 2 5\n", "3\n8 6 3\n9 1 5\n2 4 7\n", "3\n1 5 2\n7 6 3\n4 8 9\n", "3\n1 4 8\n7 2 6\n5 9 3\n"], "outputs": ["12 1\n", "12 1\n", "9 1\n", "11 2\n", "9 1\n", "13 2\n", "11 0\n", "11... | 632 | 236 |
coding | Solve the programming task below in a Python markdown code block.
Write a function that merges two sorted arrays into a single one. The arrays only contain integers. Also, the final outcome must be sorted and not have any duplicate.
Also feel free to reuse/extend the following starter code:
```python
def merge_arrays(f... | {"functional": "_inputs = [[[1, 3, 5], [2, 4, 6]], [[2, 4, 8], [2, 4, 6]], [[1, 2, 3], []], [[], []]]\n_outputs = [[[1, 2, 3, 4, 5, 6]], [[2, 4, 6, 8]], [[1, 2, 3]], [[]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, ab... | 69 | 241 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
There is a row of n houses, where each house can be painted one of three colors: red, blue, or green. The cost of painting each house with a certain color is different. You have to paint all the houses such that no tw... | {"functional": "def check(candidate):\n assert candidate(costs = [[17,2,17],[16,16,5],[14,3,19]]) == 10\n assert candidate(costs = [[7,6,2]]) == 2\n\n\ncheck(Solution().minCost)"} | 181 | 72 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
The minimum absolute difference of an array a is defined as the minimum value of |a[i] - a[j]|, where 0 <= i < j < a.length and a[i] != a[j]. If all elements of a are the same, the minimum absolute difference is -1.
... | {"functional": "def check(candidate):\n assert candidate(nums = [1,3,4,8], queries = [[0,1],[1,2],[2,3],[0,3]]) == [2,1,4,1]\n assert candidate(nums = [4,5,2,2,7,10], queries = [[2,3],[0,2],[0,5],[3,5]]) == [-1,1,1,3]\n\n\ncheck(Solution().minDifference)"} | 276 | 112 |
coding | Solve the programming task below in a Python markdown code block.
## Your task
You are given a dictionary/hash/object containing some languages and your test results in the given languages. Return the list of languages where your test score is at least `60`, in descending order of the results.
Note: the scores will a... | {"functional": "_inputs = [[{'Java': 10, 'Ruby': 80, 'Python': 65}], [{'Hindi': 60, 'Greek': 71, 'Dutch': 93}], [{'C++': 50, 'ASM': 10, 'Haskell': 20}]]\n_outputs = [[['Ruby', 'Python']], [['Dutch', 'Greek', 'Hindi']], [[]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float... | 245 | 237 |
coding | Solve the programming task below in a Python markdown code block.
Consider the sequence `a(1) = 7, a(n) = a(n-1) + gcd(n, a(n-1)) for n >= 2`:
`7, 8, 9, 10, 15, 18, 19, 20, 21, 22, 33, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 69, 72, 73...`.
Let us take the differences between successive elements of the sequence ... | {"functional": "_inputs = [[1], [10], [100], [200], [1000], [10000], [100000]]\n_outputs = [[1], [8], [90], [184], [975], [9968], [99955]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, ... | 674 | 220 |
coding | Solve the programming task below in a Python markdown code block.
The beauty of a sequence a of length n is defined as a_1 \oplus \cdots \oplus a_n, where \oplus denotes the bitwise exclusive or (XOR).
You are given a sequence A of length N. Snuke will insert zero or more partitions in A to divide it into some number ... | {"inputs": ["3\n2 2 0", "3\n1 4 2", "3\n1 2 0", "3\n1 8 2", "3\n1 6 2", "3\n1 0 0", "3\n1 6 3", "3\n0 0 3"], "outputs": ["3\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | 378 | 110 |
coding | Solve the programming task below in a Python markdown code block.
## Find Mean
Find the mean (average) of a list of numbers in an array.
## Information
To find the mean (average) of a set of numbers add all of the numbers together and divide by the number of values in the list.
For an example list of `1, 3, 5, 7`
... | {"functional": "_inputs = [[[1]], [[1, 3, 5, 7]], [[-1, 3, 5, -7]], [[5, 7, 3, 7]], [[]]]\n_outputs = [[1], [4], [0], [5.5], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tu... | 177 | 207 |
coding | Solve the programming task below in a Python markdown code block.
There is only little time left until the New Year! For that reason, Chef decided to make a present for his best friend. He made a connected and undirected simple graph with N$N$ vertices and M$M$ edges.
Since Chef does not like odd numbers and his friend... | {"inputs": ["2\n4 4\n1 2\n1 3\n2 4\n3 4\n3 3\n1 2\n2 3\n1 3"], "outputs": ["0 0 1 1\n-1"]} | 622 | 57 |
coding | Solve the programming task below in a Python markdown code block.
At an arcade, Takahashi is playing a game called RPS Battle, which is played as follows:
- The player plays N rounds of Rock Paper Scissors against the machine. (See Notes for the description of Rock Paper Scissors. A draw also counts as a round.)
- Ea... | {"inputs": ["3 2\n1 8 6\nssr\n", "5 2\n8 7 2\nrsrpr", "5 2\n8 7 6\nrsrpr", "5 2\n8 7 6\nrsrpr\n", "5 2\n12 7 2\nrsrpr", "5 2\n14 7 2\nrsrpr", "5 2\n18 7 2\nrsrpr", "5 2\n18 7 1\nrsrpr"], "outputs": ["8\n", "19\n", "27", "27\n", "23\n", "25\n", "29\n", "27\n"]} | 592 | 169 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given the head of a non-empty linked list representing a non-negative integer without leading zeroes.
Return the head of the linked list after doubling it.
Please complete the following python code precisely... | {"functional": "def check(candidate):\n assert is_same_list(candidate(head = list_node([1,8,9])), list_node([3,7,8]))\n assert is_same_list(candidate(head = list_node([9,9,9])), list_node([1,9,9,8]))\n\n\ncheck(Solution().doubleIt)"} | 122 | 77 |
coding | Solve the programming task below in a Python markdown code block.
Note : This question carries $100$ $points$
CodeLand is celebrating a festival by baking cakes! In order to avoid wastage, families follow a unique way of distributing cakes.
For $T$ families in the locality, $i$-th family (1 <= $i$ <= $T$) has $N$ membe... | {"inputs": ["5\n100 4 2 2\n100 4 3 2\n100 4 3 3\n200 4 4 2\n10 3 2 2"], "outputs": ["POSSIBLE 70\nPOSSIBLE 55\nIMPOSSIBLE 20\nPOSSIBLE 140\nIMPOSSIBLE 4\nPOSSIBLE"]} | 731 | 100 |
coding | Solve the programming task below in a Python markdown code block.
Tonight is brain dinner night and all zombies will gather together to scarf down some delicious brains. The artful Heidi plans to crash the party, incognito, disguised as one of them. Her objective is to get away with at least one brain, so she can analy... | {"inputs": ["1\n", "4\n", "2\n", "3\n", "5\n", "6\n", "7\n", "8\n"], "outputs": ["1\n", "2\n", "1\n", "2\n", "3\n", "3\n", "4\n", "4\n"]} | 574 | 70 |
coding | Solve the programming task below in a Python markdown code block.
Does the card fit in a snack? (Are Cards Snacks?)
square1001 You have $ N $ cards.
Each of these cards has an integer written on it, and the integer on the $ i $ th card is $ A_i $.
square1001 Your random number today is $ K $. square1001 You want to ... | {"inputs": ["7 9\n8 6 9 1 2", "5 9\n8 6 9 1 0", "7 9\n8 6 7 1 2", "7 9\n8 6 1 1 1", "7 9\n8 6 8 0 3", "7 9\n8 6 1 2 1", "7 9\n8 6 8 1 3", "6 9\n8 6 1 2 1"], "outputs": ["2\n", "2\n", "2\n", "2\n", "1\n", "2\n", "2\n", "2\n"]} | 559 | 158 |
coding | Solve the programming task below in a Python markdown code block.
Chef made $N$ pieces of cakes, numbered them $1$ through $N$ and arranged them in a row in this order. There are $K$ possible types of flavours (numbered $1$ through $K$); for each valid $i$, the $i$-th piece of cake has a flavour $A_i$.
Chef wants to se... | {"inputs": ["2\n6 2\n1 1 1 2 2 1\n5 3\n1 1 2 2 1"], "outputs": ["3\n5"]} | 423 | 44 |
coding | Solve the programming task below in a Python markdown code block.
You are given three non-negative integers $X$, $Y$ and $N$. Find the number of integers $Z$ such that $0 \le Z \le N$ and $(X \oplus Z) < (Y \oplus Z)$, where $\oplus$ denotes the bitwise XOR operation.
-----Input-----
- The first line of the input cont... | {"inputs": ["3\n1 2 10\n2 1 10\n0 0 7"], "outputs": ["6\n5\n0"]} | 281 | 36 |
coding | Solve the programming task below in a Python markdown code block.
You are given a square map as a matrix of integer strings. Each cell of the map has a value denoting its depth. We will call a cell of the map a cavity if and only if this cell is not on the border of the map and each cell adjacent to it has strictly sma... | {"inputs": ["4\n1112\n1912\n1892\n1234\n"], "outputs": ["1112\n1X12\n18X2\n1234\n"]} | 451 | 52 |
coding | Solve the programming task below in a Python markdown code block.
Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise.
You are given geometric progression b defined by two integers b_1 and q. Remind that a geometric progression is a sequence of integers b_1, b_2, b_3, ..., ... | {"inputs": ["2 2 4 1\n2\n", "0 8 5 1\n9\n", "2 0 1 1\n2\n", "2 0 2 1\n2\n", "4 0 4 1\n0\n", "2 2 4 1\n3\n", "0 1 1 1\n0\n", "3 1 3 1\n5\n"], "outputs": ["1", "inf", "0", "inf", "1", "2", "0", "inf"]} | 701 | 126 |
coding | Solve the programming task below in a Python markdown code block.
You are given a string $s$ consisting of $n$ characters. Each character of $s$ is either 0 or 1.
A substring of $s$ is a contiguous subsequence of its characters.
You have to choose two substrings of $s$ (possibly intersecting, possibly the same, possi... | {"inputs": ["4\n0000\n", "5\n11010\n", "5\n10110\n", "5\n10111\n", "5\n11011\n", "5\n11000\n", "5\n10000\n", "5\n10110\n"], "outputs": ["0\n", "11111\n", "11111\n", "11111\n", "11111\n", "11110\n", "11000\n", "11111\n"]} | 586 | 145 |
coding | Solve the programming task below in a Python markdown code block.
Andrewid the Android is a galaxy-famous detective. He is now investigating the case of vandalism at the exhibition of contemporary art.
The main exhibit is a construction of n matryoshka dolls that can be nested one into another. The matryoshka dolls ar... | {"inputs": ["1 1\n1 1\n", "1 1\n1 1\n", "3 2\n2 1 2\n1 3\n", "3 2\n1 2\n2 1 3\n", "3 2\n1 2\n2 1 3\n", "3 2\n2 1 2\n1 3\n", "5 3\n1 4\n3 1 2 3\n1 5\n", "5 3\n1 4\n3 1 2 3\n1 5\n"], "outputs": ["0\n", "0", "1\n", "3\n", "3", "1", "2\n", "2"]} | 742 | 162 |
coding | Solve the programming task below in a Python markdown code block.
Watson gives Sherlock an array of integers. His challenge is to find an element of the array such that the sum of all elements to the left is equal to the sum of all elements to the right.
Example
$arr=[5,6,8,11]$
$8$ is between two subarrays t... | {"inputs": ["2\n3\n1 2 3\n4\n1 2 3 3\n", "3\n5\n1 1 4 1 1\n4\n2 0 0 0\n4\n0 0 2 0 \n"], "outputs": ["NO\nYES\n", "YES\nYES\nYES\n"]} | 536 | 79 |
coding | Solve the programming task below in a Python markdown code block.
It seems that Borya is seriously sick. He is going visit n doctors to find out the exact diagnosis. Each of the doctors needs the information about all previous visits, so Borya has to visit them in the prescribed order (i.e. Borya should first visit doc... | {"inputs": ["1\n1 1\n", "1\n1 1\n", "1\n8 3\n", "1\n8 1\n", "1\n10 3\n", "1\n10 10\n", "1\n10 10\n", "1\n10 13\n"], "outputs": ["1\n", "1\n", "8\n", "8\n", "10\n", "10\n", "10\n", "10\n"]} | 370 | 113 |
coding | Solve the programming task below in a Python markdown code block.
You are given a rectangular board of M × N squares. Also you are given an unlimited number of standard domino pieces of 2 × 1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet th... | {"inputs": ["2 6\n", "1 5\n", "3 6\n", "2 5\n", "2 7\n", "4 4\n", "5 7\n", "2 2\n"], "outputs": ["6\n", "2\n", "9\n", "5\n", "7\n", "8\n", "17\n", "2\n"]} | 204 | 87 |
coding | Solve the programming task below in a Python markdown code block.
A cheetah and a cheater are going to play the game of Nim. In this game they use N piles of stones. Initially the i-th pile contains a_i stones. The players take turns alternately, and the cheetah plays first. In each turn, the player chooses one of the ... | {"inputs": ["3\n3\n3\n4", "3\n2\n3\n3", "3\n2\n1\n3", "3\n4\n5\n8", "3\n3\n5\n4", "3\n3\n4\n4", "3\n3\n5\n8", "3\n3\n1\n4"], "outputs": ["-1\n", "2\n", "0\n", "3\n", "-1\n", "-1\n", "2\n", "2\n"]} | 299 | 111 |
coding | Solve the programming task below in a Python markdown code block.
Let's call a binary string $T$ of length $m$ indexed from $1$ to $m$ paranoid if we can obtain a string of length $1$ by performing the following two kinds of operations $m-1$ times in any order :
Select any substring of $T$ that is equal to 01, and the... | {"inputs": ["5\n1\n1\n2\n01\n3\n100\n4\n1001\n5\n11111\n"], "outputs": ["1\n3\n4\n8\n5\n"]} | 619 | 52 |
coding | Solve the programming task below in a Python markdown code block.
Just in case somebody missed it: this winter is totally cold in Nvodsk! It is so cold that one gets funny thoughts. For example, let's say there are strings with the length exactly n, based on the alphabet of size m. Any its substring with length equal t... | {"inputs": ["5 2 5\n", "5 4 5\n", "3 5 3\n", "3 3 3\n", "7 2 7\n", "5 5 5\n", "4 4 1\n", "5 5 1\n"], "outputs": ["8", "64", "25", "9", "16", "125", "256", "3125"]} | 310 | 104 |
coding | Solve the programming task below in a Python markdown code block.
Arkady wants to water his only flower. Unfortunately, he has a very poor watering system that was designed for $n$ flowers and so it looks like a pipe with $n$ holes. Arkady can only use the water that flows from the first hole.
Arkady can block some of... | {"inputs": ["1 1 1\n1\n", "1 2 1\n1\n", "1 2 1\n1\n", "1 1 1\n1\n", "1 2 1\n2\n", "1 1 1\n2\n", "1 2 2\n2\n", "1 2 2\n4\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | 551 | 118 |
coding | Solve the programming task below in a Python markdown code block.
Write
```python
function repeating_fractions(numerator, denominator)
```
that given two numbers representing the numerator and denominator of a fraction, return the fraction in string format. If the fractional part has repeated digits, replace those digi... | {"functional": "_inputs = [[0, 1], [18018018, 80000000000], [1, 1], [1, 2], [1, 3], [1554, 70]]\n_outputs = [['0.0'], ['0.(0)(2)5(2)5(2)5'], ['1.0'], ['0.5'], ['0.(3)'], ['22.2']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol... | 171 | 252 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array of integers arr and an integer k.
A value arr[i] is said to be stronger than a value arr[j] if |arr[i] - m| > |arr[j] - m| where m is the median of the array.
If |arr[i] - m| == |arr[j] - m|, then arr[i... | {"functional": "def check(candidate):\n assert candidate(arr = [1,2,3,4,5], k = 2) == [5,1]\n assert candidate(arr = [1,1,3,5,5], k = 2) == [5,5]\n assert candidate(arr = [6,7,11,7,6,8], k = 5) == [11,8,6,6,7]\n assert candidate(arr = [6,-3,7,2,11], k = 3) == [-3,11,2]\n assert candidate(arr = [-7,22,17,... | 370 | 176 |
coding | Solve the programming task below in a Python markdown code block.
Ram and Shyam are sitting next to each other, hoping to cheat on an exam. However, the examination board has prepared $p$ different sets of questions (numbered $0$ through $p-1$), which will be distributed to the students in the following way:
- The stud... | {"inputs": ["1\n2 6"], "outputs": ["3"]} | 365 | 16 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
You are a poor person in ChocoLand. Here, people eat chocolates daily instead of normal food. There is only one shop near your home; this shop is closed on Sunday, but open o... | {"inputs": ["2\n16 2 10\n50 48 7"], "outputs": ["2\n-1"]} | 499 | 31 |
coding | Solve the programming task below in a Python markdown code block.
A famous Berland's painter Kalevitch likes to shock the public. One of his last obsessions is chess. For more than a thousand years people have been playing this old game on uninteresting, monotonous boards. Kalevitch decided to put an end to this tradit... | {"inputs": ["BBBBBBBB\nWBWWBBBW\nBBBBBBBB\nWBWWBBBW\nWBWWBBBW\nWBWWBBBW\nWBWWBBBW\nBBBBBBBB\n", "BBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBWBBWBWB\n", "BBBBBBBB\nWWWBBBBB\nWWWBBBBB\nBBBBBBBB\nWWWBBBBB\nWWWBBBBB\nBBBBBBBB\nBBBBBBBB\n", "BBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBB... | 542 | 298 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed integer array forts of length n representing the positions of several forts. forts[i] can be -1, 0, or 1 where:
-1 represents there is no fort at the ith position.
0 indicates there is an en... | {"functional": "def check(candidate):\n assert candidate(forts = [1,0,0,-1,0,0,0,0,1]) == 4\n assert candidate(forts = [0,0,1,-1]) == 0\n\n\ncheck(Solution().captureForts)"} | 246 | 68 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a directed acyclic graph, with n vertices numbered from 0 to n-1, and an array edges where edges[i] = [fromi, toi] represents a directed edge from node fromi to node toi.
Find the smallest set of vertices from w... | {"functional": "def check(candidate):\n assert candidate(n = 6, edges = [[0,1],[0,2],[2,5],[3,4],[4,2]]) == [0,3]\n assert candidate(n = 5, edges = [[0,1],[2,1],[3,1],[1,4],[2,4]]) == [0,2,3]\n\n\ncheck(Solution().findSmallestSetOfVertices)"} | 156 | 101 |
coding | Solve the programming task below in a Python markdown code block.
The little girl loves the problems on array queries very much.
One day she came across a rather well-known problem: you've got an array of n elements (the elements of the array are indexed starting from 1); also, there are q queries, each one is defined... | {"inputs": ["3 2\n1 2 3\n2 3\n1 2\n", "3 2\n1 2 3\n2 3\n1 2\n", "3 2\n1 4 3\n2 3\n1 2\n", "3 2\n1 2 5\n2 3\n1 2\n", "3 2\n1 7 3\n2 3\n1 2\n", "3 3\n5 3 2\n1 2\n2 3\n1 3\n", "3 3\n5 3 3\n1 2\n2 3\n1 3\n", "3 3\n5 3 2\n1 2\n2 3\n1 2\n"], "outputs": ["9\n", "9\n", "12\n", "13\n", "18\n", "25\n", "27\n", "23\n"]} | 431 | 216 |
coding | Solve the programming task below in a Python markdown code block.
A: four tea
problem
Tea is indispensable for programming contests. Tea has the effect of relieving constant tension [citation needed]
There are N players participating in the contest, so I would like to prepare tea for this number of people. There are... | {"inputs": ["10\n1 2 3 2\n1 2 4 8", "10\n1 1 3 2\n0 2 3 8", "10\n1 2 3 4\n1 3 4 8", "10\n1 1 3 2\n0 2 3 1", "10\n0 2 1 4\n0 1 0 8", "10\n1 2 3 2\n0 0 4 3", "10\n1 1 6 2\n1 1 2 1", "10\n1 1 5 1\n0 1 6 1"], "outputs": ["4\n", "3\n", "6\n", "5\n", "8\n", "7\n", "10\n", "9\n"]} | 550 | 199 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two 0-indexed arrays nums1 and nums2 of length n, both of which are permutations of [0, 1, ..., n - 1].
A good triplet is a set of 3 distinct values which are present in increasing order by position both... | {"functional": "def check(candidate):\n assert candidate(nums1 = [2,0,1,3], nums2 = [0,1,2,3]) == 1\n assert candidate(nums1 = [4,0,1,3,2], nums2 = [4,1,0,2,3]) == 4\n\n\ncheck(Solution().goodTriplets)"} | 219 | 86 |
coding | Solve the programming task below in a Python markdown code block.
Calculate the trace of a square matrix. A square matrix has `n` rows and `n` columns, where `n` is any integer > 0. The entries of the matrix can contain any number of integers. The function should return the calculated trace of the matrix, or `nil/None`... | {"functional": "_inputs = [[[[1, 2, 3], [4, 5, 6], [7, 8, 9]]], [[[0, 0], [0, 0]]], [[[0, 0, 0], [0, 0, 0], [0, 0, 0]]], [[[1, 0, 0], [0, 1, 0], [0, 0, -2]]], [[[0]]], [[[1]]], [[[-300]]], [[]], [[[]]], [[[1, 2], [1, 2], [1, 2]]], [[[1, 2, 3], [1, 2, 3]]]]\n_outputs = [[15], [0], [0], [0], [0], [1], [-300], [None], [No... | 367 | 339 |
coding | Solve the programming task below in a Python markdown code block.
# Task
Pero has been into robotics recently, so he decided to make a robot that checks whether a deck of poker cards is complete.
He’s already done a fair share of work - he wrote a programme that recognizes the suits of the cards. For simplicity’s sa... | {"functional": "_inputs = [['P01K02H03H04'], ['H02H10P11H02'], ['P10K10H10T01'], ['P05P01P02P03P13P09P11P07K01P12K03K02K13K12K10K08H03H02H13H12H10H08T01T03T02T13T12T10T08P04K07H02T07H06T11K11T05K05H05H11'], ['P01K02P03P11K09K10P13P10']]\n_outputs = [[[12, 12, 11, 13]], [[-1, -1, -1, -1]], [[12, 12, 12, 12]], [[-1, -1, ... | 570 | 413 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed binary string s of length n on which you can apply two types of operations:
Choose an index i and invert all characters from index 0 to index i (both inclusive), with a cost of i + 1
Choose ... | {"functional": "def check(candidate):\n assert candidate(s = \"0011\") == 2\n assert candidate(s = \"010101\") == 9\n\n\ncheck(Solution().minimumCost)"} | 169 | 51 |
coding | Solve the programming task below in a Python markdown code block.
A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward as forward. Examples of numerical palindromes are:
2332
110011
54322345
For a given number ```num```, write a function which returns the number of nu... | {"functional": "_inputs = [[2], [141221001], [1551], [13598], ['ACCDDCCA'], ['1551'], [-4505]]\n_outputs = [[0], [5], [2], [0], ['Not valid'], ['Not valid'], ['Not valid']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, a... | 294 | 217 |
coding | Solve the programming task below in a Python markdown code block.
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without ... | {"inputs": ["3 0\n", "2 1\n", "1 9\n", "1 0\n", "1 1\n", "1 2\n", "1 8\n", "2 0\n"], "outputs": ["-1 -1\n", "10 10\n", "9 9\n", "0 0\n", "1 1\n", "2 2\n", "8 8\n", "-1 -1\n"]} | 200 | 105 |
coding | Solve the programming task below in a Python markdown code block.
Your job is to write a function that takes a string and a maximum number of characters per line and then inserts line breaks as necessary so that no line in the resulting string is longer than the specified limit.
If possible, line breaks should not spl... | {"functional": "_inputs = [['test', 7], ['hello world', 7], ['a lot of words for a single line', 10], ['this is a test', 4], ['a longword', 6], ['areallylongword', 6], ['aa', 3], ['aaa', 3], ['aaaa', 3], ['a a', 3], ['a aa', 3], ['a aaa', 3], ['a aaaa', 3], ['a aaaaa', 3], ['a a a', 3], ['a aa a', 3], ['a aaa a', 3], [... | 349 | 584 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array of integers cost and an integer target, return the maximum integer you can paint under the following rules:
The cost of painting a digit (i + 1) is given by cost[i] (0-indexed).
The total cost used mus... | {"functional": "def check(candidate):\n assert candidate(cost = [4,3,2,5,6,7,2,5,5], target = 9) == \"7772\"\n assert candidate(cost = [7,6,5,5,5,6,8,7,8], target = 12) == \"85\"\n assert candidate(cost = [2,4,6,2,4,6,4,4,4], target = 5) == \"0\"\n assert candidate(cost = [6,10,15,40,40,40,40,40,40], target... | 148 | 174 |
coding | Solve the programming task below in a Python markdown code block.
Sunuke received a d-dimensional hypercube with a side length of l1 × ... × ld as a birthday present. Sunuke placed this rectangular parallelepiped so that the range of the i-th coordinate was 0 or more and li or less, and ate the part that satisfied x1 +... | {"inputs": ["2\n6\n3\n3", "2\n1\n6\n3", "2\n1\n6\n0", "2\n6\n3\n7", "2\n6\n6\n1", "2\n2\n6\n5", "2\n6\n3\n4", "2\n11\n3\n7"], "outputs": ["9\n", "5\n", "0\n", "32\n", "1\n", "16\n", "15", "33\n"]} | 278 | 114 |
coding | Solve the programming task below in a Python markdown code block.
There were and still are many problem in CW about palindrome numbers and palindrome strings. We suposse that you know which kind of numbers they are. If not, you may search about them using your favourite search engine.
In this kata you will be given a ... | {"functional": "_inputs = [[11], [188], [191], [2541]]\n_outputs = [[22], [191], [202], [2552]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b... | 205 | 188 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
An integer array is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same.
For example, [1,3,5,7,9], [7,7,7,7], and [3,-1,-5,-9] are arithm... | {"functional": "def check(candidate):\n assert candidate(nums = [1,2,3,4]) == 3\n assert candidate(nums = [1]) == 0\n\n\ncheck(Solution().numberOfArithmeticSlices)"} | 143 | 52 |
coding | Solve the programming task below in a Python markdown code block.
Appleman has n cards. Each card has an uppercase letter written on it. Toastman must choose k cards from Appleman's cards. Then Appleman should give Toastman some coins depending on the chosen cards. Formally, for each Toastman's card i you should calcul... | {"inputs": ["1 1\nV\n", "1 1\nV\n", "1 1\nU\n", "2 1\nWT\n", "2 2\nBL\n", "2 2\nBL\n", "2 1\nWT\n", "2 2\nLB\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "2\n", "2\n", "1\n", "2\n"]} | 277 | 102 |
coding | Solve the programming task below in a Python markdown code block.
This is simple version of harder [Square Sums](/kata/square-sums).
# Square sums
Write function `square_sums_row` (or `squareSumsRow`/`SquareSumsRow` depending on language rules) that, given integer number `N` (in range `2..43`), returns array of integ... | {"functional": "_inputs = [[5], [24]]\n_outputs = [[False], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n re... | 622 | 163 |
coding | Solve the programming task below in a Python markdown code block.
Enter a positive integer n of 4,000 or less, with a pair of integers a, b, c, d in the range 0-1000.
a + b + c + d = n
Create a program that outputs the number of combinations that satisfy the conditions.
Input
Given multiple datasets. Each datas... | {"inputs": ["2\n0\n8", "2\n0\n1", "2\n1\n8", "2\n2\n8", "2\n1\n1", "2\n4\n8", "2\n1\n2", "2\n4\n1"], "outputs": ["10\n1\n165\n", "10\n1\n4\n", "10\n4\n165\n", "10\n10\n165\n", "10\n4\n4\n", "10\n35\n165\n", "10\n4\n10\n", "10\n35\n4\n"]} | 158 | 146 |
coding | Solve the programming task below in a Python markdown code block.
group()
A group() expression returns one or more subgroups of the match.
Code
>>> import re
>>> m = re.match(r'(\w+)@(\w+)\.(\w+)','username@hackerrank.com')
>>> m.group(0) # The entire match
'username@hackerrank.com'
>>> m.group(1) # Th... | {"inputs": ["..12345678910111213141516171820212223\n"], "outputs": ["1\n"]} | 510 | 49 |
coding | Solve the programming task below in a Python markdown code block.
Vasily exited from a store and now he wants to recheck the total price of all purchases in his bill. The bill is a string in which the names of the purchases and their prices are printed in a row without any spaces. Check has the format "name_1price_1nam... | {"inputs": ["a1.01\n", "a0.11\n", "a0.01\n", "a0.40\n", "a0.11\n", "a0.40\n", "a1.01\n", "a0.01\n"], "outputs": ["1.01\n", "0.11\n", "0.01\n", "0.40\n", "0.11", "0.40", "1.01", "0.01"]} | 547 | 122 |
coding | Solve the programming task below in a Python markdown code block.
Given the list of numbers, you are to sort them in non decreasing order.
-----Input-----
t – the number of numbers in list, then t lines follow [t <= 10^6].
Each line contains one integer: N [0 <= N <= 10^6]
-----Output-----
Output given numbers in n... | {"inputs": ["5\n5\n3\n6\n7\n1", "5\n5\n3\n3\n7\n1", "5\n0\n3\n3\n7\n1", "5\n1\n3\n3\n7\n1", "5\n1\n3\n3\n7\n2", "5\n1\n1\n3\n7\n2", "5\n1\n2\n4\n1\n1", "5\n1\n2\n4\n1\n0"], "outputs": ["1\n3\n5\n6\n7", "1\n3\n3\n5\n7\n", "0\n1\n3\n3\n7\n", "1\n1\n3\n3\n7\n", "1\n2\n3\n3\n7\n", "1\n1\n2\n3\n7\n", "1\n1\n1\n2\n4\n", "0\n... | 112 | 205 |
coding | Solve the programming task below in a Python markdown code block.
A piece of paper contains an array of n integers a1, a2, ..., an. Your task is to find a number that occurs the maximum number of times in this array.
However, before looking for such number, you are allowed to perform not more than k following operatio... | {"inputs": ["1 0\n0\n", "1 1\n0\n", "1 1\n1\n", "1 2\n0\n", "1 2\n1\n", "1 3\n0\n", "1 0\n1\n", "3 4\n5 5 5\n"], "outputs": ["1 0\n", "1 0\n\n", "1 1\n\n", "1 0\n\n", "1 1\n\n", "1 0\n\n", "1 1\n\n", "3 5\n"]} | 556 | 128 |
coding | Solve the programming task below in a Python markdown code block.
$n$ heroes fight against each other in the Arena. Initially, the $i$-th hero has level $a_i$.
Each minute, a fight between two different heroes occurs. These heroes can be chosen arbitrarily (it's even possible that it is the same two heroes that were f... | {"inputs": ["1\n3\n90 91 92\n", "1\n3\n90 91 92\n", "1\n3\n90 56 92\n", "1\n3\n90 75 92\n", "1\n3\n49 75 92\n", "1\n3\n90 43 92\n", "1\n3\n90 57 92\n", "1\n3\n49 75 180\n"], "outputs": ["2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n"]} | 440 | 159 |
coding | Solve the programming task below in a Python markdown code block.
Read problem statements in [Bengali], [Russian], [Mandarin] and [Vietnamese] as well.
You are given a binary string S. You can perform the following operations on S:
Flip: Pick an index i (1 ≤ i ≤ |S|) and flip the i-th character (i.e change 1 to 0 or ... | {"inputs": ["3\n100011\n1110011\n000101110\n"], "outputs": ["2\n2\n3\n"]} | 758 | 43 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a string expression representing a Lisp-like expression to return the integer value of.
The syntax for these expressions is given as follows.
An expression is either an integer, let expression, add expr... | {"functional": "def check(candidate):\n assert candidate(expression = \"(let x 2 (mult x (let x 3 y 4 (add x y))))\") == 14\n assert candidate(expression = \"(let x 3 x 2 x)\") == 2\n assert candidate(expression = \"(let x 1 y 2 x (add x y) (add x y))\") == 5\n\n\ncheck(Solution().evaluate)"} | 445 | 102 |
coding | Solve the programming task below in a Python markdown code block.
There are n kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as large as the size of kangaroo who is held.
Eac... | {"inputs": ["1\n1\n", "1\n2\n", "3\n1\n2\n4\n", "3\n1\n3\n4\n", "3\n1\n3\n5\n", "3\n1\n6\n5\n", "3\n1\n6\n9\n", "3\n1\n11\n9\n"], "outputs": ["1\n", "1\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n"]} | 257 | 111 |
coding | Solve the programming task below in a Python markdown code block.
Create a function that takes a string and returns that
string with the first half lowercased and the last half uppercased.
eg: foobar == fooBAR
If it is an odd number then 'round' it up to find which letters to uppercase. See example below.
sillyc... | {"functional": "_inputs = [['foobar'], ['codewars'], ['jAvASCript'], ['brian'], ['jabberwock'], ['SCOTland'], ['WeLlDoNe']]\n_outputs = [['fooBAR'], ['codeWARS'], ['javasCRIPT'], ['briAN'], ['jabbeRWOCK'], ['scotLAND'], ['wellDONE']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance... | 131 | 221 |
coding | Solve the programming task below in a Python markdown code block.
Problem
GPA is an abbreviation for "Galaxy Point of Aizu" and takes real numbers from 0 to 4.
GPA rock-paper-scissors is a game played by two people. After each player gives a signal of "rock-paper-scissors, pon (hoi)" to each other's favorite move, goo... | {"inputs": ["3\n1.000\n2.000\n3.000", "3\n1.000\n3.000\n3.000", "3\n1.000\n2.000\n3.4274102096399073", "3\n1.3153899733914476\n3.000\n3.000", "3\n1.000\n3.000\n3.1230319554116766", "3\n1.000\n2.000\n3.9759367558439593", "3\n1.000\n2.5451927881659007\n3.000", "3\n1.6470390157297516\n3.000\n3.000"], "outputs": ["0\n3\n6"... | 403 | 314 |
coding | Solve the programming task below in a Python markdown code block.
Dr. Evil kidnapped Mahmoud and Ehab in the evil land because of their performance in the Evil Olympiad in Informatics (EOI). He decided to give them some problems to let them go.
Dr. Evil is interested in sets, He has a set of n integers. Dr. Evil calls... | {"inputs": ["1 0\n0\n", "1 0\n0\n", "1 100\n0\n", "1 0\n100\n", "2 2\n0 2\n", "2 1\n1 2\n", "2 2\n0 2\n", "2 1\n1 2\n"], "outputs": ["1\n", "1\n", "99\n", "0\n", "2\n", "2\n", "2\n", "2\n"]} | 428 | 115 |
coding | Solve the programming task below in a Python markdown code block.
In a strategic computer game "Settlers II" one has to build defense structures to expand and protect the territory. Let's take one of these buildings. At the moment the defense structure accommodates exactly n soldiers. Within this task we can assume tha... | {"inputs": ["1 5\n1\n", "1 5\n4\n", "1 1\n1\n", "1 8\n1\n", "1 2\n1\n", "1 3\n1\n", "1 4\n1\n", "1 6\n1\n"], "outputs": ["4\n", "1\n", "0\n", "7\n", "1\n", "2\n", "3\n", "5\n"]} | 499 | 102 |
coding | Solve the programming task below in a Python markdown code block.
Shivani is interning at HackerEarth. One day she has to distribute some chocolates to her colleagues. She is biased towards her friends and may have distributed the chocolates unequally. One of the program managers gets to know this and orders Shivani to... | {"inputs": ["1\n4\n2 2 3 7"], "outputs": ["2"]} | 403 | 22 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Alice is texting Bob using her phone. The mapping of digits to letters is shown in the figure below.
In order to add a letter, Alice has to press the key of the corresponding digit i times, where i is the position of... | {"functional": "def check(candidate):\n assert candidate(pressedKeys = \"22233\") == 8\n assert candidate(pressedKeys = \"222222222222222222222222222222222222\") == 82876089\n\n\ncheck(Solution().countTexts)"} | 259 | 94 |
coding | Solve the programming task below in a Python markdown code block.
An L-shape is a figure on gridded paper that looks like the first four pictures below. An L-shape contains exactly three shaded cells (denoted by *), which can be rotated in any way.
You are given a rectangular grid. Determine if it contains L-shapes on... | {"inputs": ["1\n4 4\n.**.\n*..*\n*..*\n.**.\n", "1\n4 5\n..*..\n.*.*.\n.*.*.\n..*..\n", "1\n6 6\n..**..\n.*..*.\n*....*\n*....*\n.*..*.\n..**..\n", "10\n6 10\n........**\n.**......*\n..*..*....\n.....**...\n...*.....*\n..**....**\n6 10\n....*...**\n.**......*\n..*..*....\n.....**...\n...*.....*\n..**....**\n3 3\n...\n*... | 517 | 316 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
There is an integer array nums sorted in ascending order (with distinct values).
Prior to being passed to your function, nums is possibly rotated at an unknown pivot index k (1 <= k < nums.length) such that the result... | {"functional": "def check(candidate):\n assert candidate(nums = [4,5,6,7,0,1,2], target = 0) == 4\n assert candidate(nums = [4,5,6,7,0,1,2], target = 3) == -1\n assert candidate(nums = [1], target = 0) == -1\n\n\ncheck(Solution().search)"} | 222 | 93 |
coding | Solve the programming task below in a Python markdown code block.
# Your Task
You have a Petri dish with bacteria, and you are preparing to dive into the harsh micro-world. But, unfortunately, you don't have any microscope nearby, so you can't watch them.
You know that you have `n` bacteria in the Petri dish and size ... | {"functional": "_inputs = [[[101, 53, 42, 102, 101, 55, 54], 1], [[20, 15, 10, 15, 20, 25], 5], [[5, 3, 1, 5], 1]]\n_outputs = [[3], [1], [4]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance... | 564 | 234 |
coding | Solve the programming task below in a Python markdown code block.
You have an infinitely long digital panel. Using various combinations of 7 segments, we can represent each digit. The picture shows how all 10 decimal digits are displayed.
Initially, all segments in the panel are off. You are given seven integers A, B... | {"inputs": ["3\n10 1 31 21 5 3 12 9\n69697 1 2 3 4 5 6 7\n3964083074239146524786 1 41 31 21 11 1 41\n"], "outputs": ["48\n5\n72\n"]} | 601 | 102 |
coding | Solve the programming task below in a Python markdown code block.
You have recently discovered that horses travel in a unique pattern - they're either running (at top speed) or resting (standing still).
Here's an example of how one particular horse might travel:
```
The horse Blaze can run at 14 metres/second for 60 ... | {"functional": "_inputs = [[1000, 10, 127, 14], [1000, 10, 0, 10], [25, 50, 120, 18], [35869784, 90, 100, 5], [1234567, 4, 3, 11], [100000000, 21, 5, 14], [0, 100, 10, 14], [250, 0, 5, 14], [100, 10, 0, 14], [500, 100, 10, 0]]\n_outputs = [[1120], [10000], [450], [84954920], [7760148], [1130769276], [0], [0], [1400], [... | 221 | 392 |
coding | Solve the programming task below in a Python markdown code block.
There are some rabbits in Singapore Zoo. To feed them, Zookeeper bought $n$ carrots with lengths $a_1, a_2, a_3, \ldots, a_n$. However, rabbits are very fertile and multiply very quickly. Zookeeper now has $k$ rabbits and does not have enough carrots to ... | {"inputs": ["1 1\n1\n", "1 1\n1\n", "1 4\n6\n", "1 4\n19\n", "1 8\n19\n", "1 4\n19\n", "1 15\n19\n", "3 6\n5 3 1\n"], "outputs": ["1\n", "1\n", "10\n", "91\n", "47\n", "91\n", "27\n", "15\n"]} | 440 | 117 |
coding | Solve the programming task below in a Python markdown code block.
collections.deque()
A deque is a double-ended queue. It can be used to add or remove elements from both ends.
Deques support thread safe, memory efficient appends and pops from either side of the deque with approximately the same $O(1)$ performance i... | {"inputs": ["6\nappend 1\nappend 2\nappend 3\nappendleft 4\npop\npopleft\n"], "outputs": ["1 2\n"]} | 479 | 38 |
coding | Solve the programming task below in a Python markdown code block.
Vika has n jars with paints of distinct colors. All the jars are numbered from 1 to n and the i-th jar contains a_{i} liters of paint of color i.
Vika also has an infinitely long rectangular piece of paper of width 1, consisting of squares of size 1 × 1... | {"inputs": ["2\n2 3\n", "2\n2 3\n", "2\n4 3\n", "2\n1 3\n", "2\n4 1\n", "2\n1 6\n", "2\n7 1\n", "2\n1 1\n"], "outputs": ["5\n", "5\n", "7\n", "3\n", "3\n", "3\n", "3\n", "2\n"]} | 538 | 102 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array nums that represents a permutation of integers from 1 to n. We are going to construct a binary search tree (BST) by inserting the elements of nums in order into an initially empty BST. Find the number o... | {"functional": "def check(candidate):\n assert candidate(nums = [2,1,3]) == 1\n assert candidate(nums = [3,4,5,1,2]) == 5\n assert candidate(nums = [1,2,3]) == 0\n\n\ncheck(Solution().numOfWays)"} | 222 | 73 |
coding | Solve the programming task below in a Python markdown code block.
A sequence $(b_1, b_2, \ldots, b_k)$ is called strange, if the absolute difference between any pair of its elements is greater than or equal to the maximum element in the sequence. Formally speaking, it's strange if for every pair $(i, j)$ with $1 \le i<... | {"inputs": ["1\n1\n0\n", "1\n1\n0\n", "1\n1\n1\n", "1\n1\n2\n", "1\n2\n0 1\n", "1\n2\n0 1\n", "1\n3\n0 0 3\n", "1\n3\n0 0 4\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "2\n", "2\n", "2\n", "2\n"]} | 701 | 114 |
coding | Solve the programming task below in a Python markdown code block.
There are three cells on an infinite 2-dimensional grid, labeled $A$, $B$, and $F$. Find the length of the shortest path from $A$ to $B$ if:
in one move you can go to any of the four adjacent cells sharing a side;
visiting the cell $F$ is forbidden (it... | {"inputs": ["7\n\n1 2\n3 3\n2 2\n\n2 5\n0 0\n2 3\n\n0000 16\n1010 1\n1010 1000\n\n1 10\n0 10\n2 10\n\n3 8\n8 2\n3 7\n\n2 0\n2 1\n1 1\n\n1 578\n1 6\n0 1\n", "7\n\n1 2\n3 3\n2 2\n\n2 5\n0 0\n2 3\n\n0000 16\n1010 1\n1010 1000\n\n1 10\n0 17\n2 10\n\n3 8\n8 2\n3 7\n\n2 0\n2 1\n1 1\n\n1 578\n1 6\n0 1\n", "7\n\n1 2\n3 3\n2 2\... | 516 | 1,081 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You would like to make dessert and are preparing to buy the ingredients. You have n ice cream base flavors and m types of toppings to choose from. You must follow these rules when making your dessert:
There must be e... | {"functional": "def check(candidate):\n assert candidate(baseCosts = [1,7], toppingCosts = [3,4], target = 10) == 10\n assert candidate(baseCosts = [2,3], toppingCosts = [4,5,100], target = 18) == 17\n assert candidate(baseCosts = [3,10], toppingCosts = [2,5], target = 9) == 8\n assert candidate(baseCosts =... | 250 | 146 |
coding | Solve the programming task below in a Python markdown code block.
Let's define a split of $n$ as a nonincreasing sequence of positive integers, the sum of which is $n$.
For example, the following sequences are splits of $8$: $[4, 4]$, $[3, 3, 2]$, $[2, 2, 1, 1, 1, 1]$, $[5, 2, 1]$.
The following sequences aren't spl... | {"inputs": ["7\n", "8\n", "9\n", "1\n", "2\n", "3\n", "1\n", "3\n"], "outputs": ["4\n", "5\n", "5\n", "1\n", "2\n", "2\n", "1\n", "2\n"]} | 459 | 70 |
coding | Solve the programming task below in a Python markdown code block.
You are given a text consisting of n lines. Each line contains some space-separated words, consisting of lowercase English letters.
We define a syllable as a string that contains exactly one vowel and any arbitrary number (possibly none) of consonants. ... | {"inputs": ["1\n1\naa\n", "1\n1\naa\n", "1\n2\naa\n", "1\n0\naa\n", "1\n0\na`\n", "1\n0\n`a\n", "1\n1\naaa\n", "1\n1\naaa\n"], "outputs": ["NO\n", "NO\n", "YES\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]} | 626 | 104 |
coding | Solve the programming task below in a Python markdown code block.
After lessons Nastya decided to read a book. The book contains $n$ chapters, going one after another, so that one page of the book belongs to exactly one chapter and each chapter contains at least one page.
Yesterday evening Nastya did not manage to fin... | {"inputs": ["1\n1 7\n4\n", "1\n1 2\n1\n", "1\n1 7\n7\n", "1\n1 1\n1\n", "1\n1 7\n1\n", "1\n1 5\n1\n", "1\n1 5\n1\n", "1\n1 2\n1\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | 602 | 118 |
coding | Solve the programming task below in a Python markdown code block.
Bob has ladder. He wants to climb this ladder, but being a precocious child, he wonders about exactly how many ways he could to climb this `n` size ladder using jumps of up to distance `k`.
Consider this example...
n = 5\
k = 3
Here, Bob has ladder of... | {"functional": "_inputs = [[1, 3], [3, 3], [2, 3], [5, 3], [4, 3], [10, 6], [14, 7]]\n_outputs = [[1], [4], [2], [13], [7], [492], [7936]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, ... | 287 | 220 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.