task_type stringclasses 1
value | problem stringlengths 261 3.34k | answer stringlengths 35 6.15k | problem_tokens int64 62 774 | answer_tokens int64 12 2.04k |
|---|---|---|---|---|
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well
You are given a binary string $S$ with length $N$ and an integer $K$, which is a divisor of $N$. A string is said to be $K$*-foldable* if it can be c... | {"inputs": ["2\n8 2\n00011101\n6 2\n100111"], "outputs": ["01100110\nIMPOSSIBLE"]} | 662 | 48 |
coding | Solve the programming task below in a Python markdown code block.
You've got a string a_1, a_2, ..., a_n, consisting of zeros and ones.
Let's call a sequence of consecutive elements a_i, a_{i + 1}, …, a_j (1≤ i≤ j≤ n) a substring of string a.
You can apply the following operations any number of times:
* Choose so... | {"inputs": ["1 3 2\n1\n", "1 1 0\n1\n", "1 5 0\n1\n", "1 2 1\n1\n", "1 1 0\n0\n", "1 5 1\n1\n", "2 1 2\n01\n", "1 20 1\n1\n"], "outputs": ["0", "0", "0", "0", "0\n", "0\n", "2", "0"]} | 620 | 114 |
coding | Solve the programming task below in a Python markdown code block.
Find the largest integer that can be formed with exactly N matchsticks, under the following conditions:
- Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9).
- The number of matchsticks used to form digits 1, 2,... | {"inputs": ["6965 1\n3\n", "1685 1\n3\n", "4 7\n4 4 7", "9 6\n7 5 6", "5 7\n7 3 6", "8 6\n7 5 6", "5 7\n5 3 6", "15 4\n5 4 6"], "outputs": ["33333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333... | 350 | 1,860 |
coding | Solve the programming task below in a Python markdown code block.
The electrical resistance is the opposition to the passage of electric current. If two resistors with resistance R1 and R2 are connected to each other, the resultant resistance R depends on how their ends are connected. If they are connected in Series, t... | {"inputs": ["3\n1 8\n1 7\n101 00010", "3\n1 8\n1 7\n001 10010", "3\n1 8\n1 6\n100 10010", "3\n1 10\n2 3\n100 10010", "3\n1 14\n2 3\n100 10011", "3\n1 14\n4 3\n100 10011", "3\n1 14\n4 3\n100 11011", "3\n1 10\n2 3\n100 11010"], "outputs": ["1/1\n1/1\n6/1\n", "1/1\n1/1\n1/1\n", "1/1\n1/1\n5501/5775\n", "1/1\n2/0\n5501/577... | 439 | 326 |
coding | Solve the programming task below in a Python markdown code block.
Regional College is having N branches, where each branches have positive integral student. A minimize operation is performed on the branch such that all of them are reduced by the minimum number student in a branch.
Suppose we have 5 branches and all of... | {"inputs": ["6\n5 4 4 2 2 8", "1000\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1... | 277 | 2,042 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer array nums and an integer k. Find the largest even sum of any subsequence of nums that has a length of k.
Return this sum, or -1 if such a sum does not exist.
A subsequence is an array that ca... | {"functional": "def check(candidate):\n assert candidate(nums = [4,1,5,3,1], k = 3) == 12\n assert candidate(nums = [4,6,2], k = 3) == 12\n assert candidate(nums = [1,3,5], k = 1) == -1\n\n\ncheck(Solution().largestEvenSum)"} | 126 | 90 |
coding | Solve the programming task below in a Python markdown code block.
Toad Zitz has an array of integers, each integer is between $0$ and $m-1$ inclusive. The integers are $a_1, a_2, \ldots, a_n$.
In one operation Zitz can choose an integer $k$ and $k$ indices $i_1, i_2, \ldots, i_k$ such that $1 \leq i_1 < i_2 < \ldots <... | {"inputs": ["1 1\n0\n", "1 1\n0\n", "1 2\n0\n", "2 1\n0 0\n", "2 2\n0 1\n", "2 2\n1 0\n", "2 2\n1 0\n", "2 2\n0 1\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "1\n", "1\n", "0\n"]} | 488 | 112 |
coding | Solve the programming task below in a Python markdown code block.
If `a = 1, b = 2, c = 3 ... z = 26`
Then `l + o + v + e = 54`
and `f + r + i + e + n + d + s + h + i + p = 108`
So `friendship` is twice stronger than `love` :-)
The input will always be in lowercase and never be empty.
Also feel free to reuse/extend... | {"functional": "_inputs = [['attitude'], ['friends'], ['family'], ['selfness'], ['knowledge']]\n_outputs = [[100], [75], [66], [99], [96]]\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, ... | 126 | 187 |
coding | Solve the programming task below in a Python markdown code block.
Implement a function which behaves like the uniq command in UNIX.
It takes as input a sequence and returns a sequence in which all duplicate elements following each other have been reduced to one instance.
Example:
```
["a", "a", "b", "b", "c", "a", "... | {"functional": "_inputs = [[['a', 'a', 'b', 'b', 'c', 'a', 'b', 'c', 'c']], [['a', 'a', 'a', 'b', 'b', 'b', 'c', 'c', 'c']], [[]], [['foo']], [['bar']], [['']], [[None, 'a', 'a']]]\n_outputs = [[['a', 'b', 'c', 'a', 'b', 'c']], [['a', 'b', 'c']], [[]], [['foo']], [['bar']], [['']], [[None, 'a']]]\nimport math\ndef _dee... | 121 | 268 |
coding | Solve the programming task below in a Python markdown code block.
problem
You have to play a darts game with the following rules.
You can throw up to four arrows towards the target. You don't have to throw all four, you don't have to throw one. The target is divided into N parts. The score P1, ..., PN is written in e... | {"inputs": ["4 36\n6\n0\n28\n1\n3 21\n2\n9\n2\n0 0", "4 76\n6\n27\n1\n6\n3 21\n5\n16\n0\n0 0", "4 55\n6\n1\n21\n9\n3 4\n16\n11\n2\n0 0", "4 58\n6\n19\n28\n1\n3 9\n5\n16\n2\n0 0", "4 9\n3\n20\n10\n9\n3 22\n16\n3\n3\n0 0", "4 55\n6\n1\n26\n3\n3 4\n16\n11\n2\n0 0", "4 76\n6\n27\n1\n6\n3 21\n3\n16\n0\n0 0", "4 58\n6\n14\n1... | 393 | 314 |
coding | Solve the programming task below in a Python markdown code block.
**Principal Diagonal** -- The principal diagonal in a matrix identifies those elements of the matrix running from North-West to South-East.
**Secondary Diagonal** -- the secondary diagonal of a matrix identifies those elements of the matrix running from... | {"functional": "_inputs = [[[[2, 2, 2], [4, 2, 6], [8, 8, 2]]], [[[7, 2, 2], [4, 2, 6], [1, 8, 1]]], [[[1, 2, 3], [4, 5, 6], [7, 8, 9]]], [[[1, 2, 2, 5, 1], [4, 1, 6, 1, 1], [1, 8, 5, 6, 2], [1, 5, 2, 1, 2], [1, 8, 2, 6, 1]]], [[[88, 2, 2, 5, 1, 1, 2, 2, 5, 1], [4, 1, 6, 1, 1, 1, 2, 2, 7, 1], [1, 8, 1, 6, 2, 1, 2, 1, 5... | 229 | 1,456 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
You work as an engineer. You were given an empty board with $K$ consecutive cells; at any moment, each cell can display one character.
You want the board to display a string... | {"inputs": ["3\n6 3\naabbcc\n5 2\nabccc\n4 3\naabb"], "outputs": ["4\n3\n1"]} | 716 | 38 |
coding | Solve the programming task below in a Python markdown code block.
Sergey attends lessons of the N-ish language. Each lesson he receives a hometask. This time the task is to translate some sentence to the N-ish language. Sentences of the N-ish language can be represented as strings consisting of lowercase Latin letters ... | {"inputs": ["z\n0\n", "abaca\n1\nab\n", "ababa\n1\nab\n", "nllnrlrnll\n1\nrl\n", "nnllrlrnll\n1\nrl\n", "nnllrlrnll\n1\nrk\n", "nollrlrnll\n1\nrk\n", "nomlrlrnll\n1\nrk\n"], "outputs": ["0", "1\n", "2", "1", "2\n", "0\n", "0\n", "0\n"]} | 556 | 120 |
coding | Solve the programming task below in a Python markdown code block.
You have been speeding on a motorway and a police car had to stop you. The policeman is a funny guy that likes to play games. Before issuing penalty charge notice he gives you a choice to change your penalty.
Your penalty charge is a combination of num... | {"functional": "_inputs = [[['45', '30', '50', '1']], [['100', '10', '1']], [['32', '3']], [['70', '46', '4', '19']], [['71', '82', '42', '34', '90']], [['31', '97', '6', '78']], [['72', '7', '7', '78', '79', '709', '94']]]\n_outputs = [['1304550'], ['100101'], ['323'], ['1944670'], ['3442718290'], ['3167897'], ['70972... | 248 | 329 |
coding | Solve the programming task below in a Python markdown code block.
Chef recently solved his first problem on CodeChef. The problem he solved has N test cases. He gets a score for his submission according to the following rules:
1) If Chef’s code passes all the N test cases, he gets 100 points.
2) If Chef’s code does n... | {"inputs": ["4\n4 2 50\n1 0 1 1\n3 2 50\n1 1 0\n4 2 50\n1 1 1 1\n5 3 30\n1 1 0 1 1\n"], "outputs": ["0\n50\n100\n0\n"]} | 546 | 83 |
coding | Solve the programming task below in a Python markdown code block.
Vinay loves stories on serial killers. He is hypnotized to the stories of The Zodiac Killer. Zodiac was a serial killer in USA in late 1960s and early 1970s. He never revealed his original identity but named himself as Zodiac on the letters he posted to ... | {"inputs": ["10\n21\n182 223 158 146 223 165 144 155 150 158 156 223 172 143 154 158 148 150 145 152 209\n82\n182 223 158 146 223 139 151 154 223 144 145 154 223 136 151 144 223 148 150 147 147 154 155 223 139 151 144 140 154 223 139 154 154 145 158 152 154 141 140 223 150 145 223 139 151 154 223 179 158 148 154 140 15... | 408 | 1,877 |
coding | Solve the programming task below in a Python markdown code block.
You are given array $a$ of length $n$. You can choose one segment $[l, r]$ ($1 \le l \le r \le n$) and integer value $k$ (positive, negative or even zero) and change $a_l, a_{l + 1}, \dots, a_r$ by $k$ each (i.e. $a_i := a_i + k$ for each $l \le i \le r$... | {"inputs": ["2 1\n1 2\n", "2 1\n1 2\n", "2 0\n1 2\n", "3 2\n6 2 6\n", "3 2\n6 2 0\n", "3 2\n6 2 6\n", "1 1\n500000\n", "1 1\n500000\n"], "outputs": ["2\n", "2\n", "1\n", "2\n", "2\n", "2\n", "1\n", "1\n"]} | 378 | 130 |
coding | Solve the programming task below in a Python markdown code block.
Ehab has an array $a$ of length $n$. He has just enough free time to make a new array consisting of $n$ copies of the old array, written back-to-back. What will be the length of the new array's longest increasing subsequence?
A sequence $a$ is a subsequ... | {"inputs": ["2\n2\n1 1\n1\n1\n", "2\n2\n1 1\n1\n1\n", "1\n5\n1 3 4 5 2\n", "1\n5\n1 3 4 5 2\n", "1\n5\n2 3 4 5 2\n", "1\n5\n1 3 4 8 2\n", "1\n5\n1 3 4 5 1\n", "1\n5\n3 3 4 5 2\n"], "outputs": ["1\n1\n", "1\n1\n", "5\n", "5\n", "4\n", "5\n", "4\n", "4\n"]} | 421 | 166 |
coding | Solve the programming task below in a Python markdown code block.
Mehta is a very rich guy. He has $N$ types of coins, and each type of coin is available in an unlimited supply.
So Mehta goes to a supermarket to buy monthly groceries. There he sees that every item has a unique price, that is, no two items have the s... | {"inputs": ["4\n2\n3\n4\n5\n3\n1 10\n2 20\n3 7\n"], "outputs": ["8\n14\n4\n"]} | 628 | 43 |
coding | Solve the programming task below in a Python markdown code block.
Today, Chef woke up to find that he had no clean socks. Doing laundry is such a turn-off for Chef, that in such a situation, he always buys new socks instead of cleaning the old dirty ones. He arrived at the fashion store with money rupees in his pocket ... | {"inputs": ["0 2 3", "1 2 9", "1 1 9", "1 2 7", "0 2 6", "2 2 9", "2 1 9", "1 2 5"], "outputs": ["Unlucky Chef\n", "Lucky Chef\n", "Lucky Chef\n", "Unlucky Chef\n", "Unlucky Chef\n", "Unlucky Chef\n", "Unlucky Chef\n", "Lucky Chef\n"]} | 517 | 115 |
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 nums of length n.
You can perform the following operation as many times as you want:
Pick an index i that you haven’t picked before, and pick a prime p strictly less than nums[... | {"functional": "def check(candidate):\n assert candidate(nums = [4,9,6,10]) == True\n assert candidate(nums = [6,8,11,12]) == True\n assert candidate(nums = [5,8,3]) == False\n\n\ncheck(Solution().primeSubOperation)"} | 143 | 72 |
coding | Solve the programming task below in a Python markdown code block.
Description:
The mean (or average) is the most popular measure of central tendency; however it does not behave very well when the data is skewed (i.e. wages distribution). In such cases, it's better to use the median.
Your task for this kata is to find... | {"functional": "_inputs = [[[1, 2, 3, 4]], [[3, 4, 1, 2, 5]], [[10, 29, 23, 94, 76, 96, 5, 85, 4, 33, 47, 41, 87]], [[1]], [[1, -1]]]\n_outputs = [[2.5], [3], [41], [1], [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,... | 186 | 252 |
coding | Solve the programming task below in a Python markdown code block.
------Read problems statements in Hindi,
Mandarin chinese
, Russian and Vietnamese as well. ------
Sheokand is good at mathematics. One day, to test his math skills, Kaali gave him an integer $N$. To impress Kaali, Sheokand has to convert $N$ into an i... | {"inputs": ["3\n10\n22\n4"], "outputs": ["0\n2\n1"]} | 508 | 24 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a list of words, list of single letters (might be repeating) and score of every character.
Return the maximum score of any valid set of words formed by using the given letters (words[i] cannot be used two or mo... | {"functional": "def check(candidate):\n assert candidate(words = [\"dog\",\"cat\",\"dad\",\"good\"], letters = [\"a\",\"a\",\"c\",\"d\",\"d\",\"d\",\"g\",\"o\",\"o\"], score = [1,0,9,5,0,0,3,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0]) == 23\n assert candidate(words = [\"xxxz\",\"ax\",\"bx\",\"cx\"], letters = [\"z\",... | 169 | 302 |
coding | Solve the programming task below in a Python markdown code block.
While purchasing certain items, a discount of 10% is offered if the quantity purchased is more than 1000.
If the quantity and price per item are input, write a program to calculate the total expenses.
------ Input Format ------
The first line contain... | {"inputs": ["3 \n100 4\n31 36\n390 40", "3 \n100 4\n31 36\n441 40", "3 \n001 215\n10 20\n25 19", "3 \n001 215\n10 22\n25 19", "3 \n001 215\n10 29\n25 19", "3 \n100 17\n16 36\n390 40", "3 \n011 15\n10 20\n128 42", "3 \n001 215\n10 41\n25 19"], "outputs": ["400.000000\n1116.000000\n15600.000000\n", "400.000000\n1116.0000... | 218 | 486 |
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 number of reverse pairs in the array.
A reverse pair is a pair (i, j) where:
0 <= i < j < nums.length and
nums[i] > 2 * nums[j].
Please complete the following python code pr... | {"functional": "def check(candidate):\n assert candidate(nums = [1,3,2,3,1]) == 2\n assert candidate(nums = [2,4,3,5,1]) == 3\n\n\ncheck(Solution().reversePairs)"} | 97 | 59 |
coding | Solve the programming task below in a Python markdown code block.
You know combinations: for example,
if you take 5 cards from a 52 cards deck you have 2,598,960 different combinations.
In mathematics the number of x combinations you can take from a set of n elements
is called the binomial coefficient of n and x, or ... | {"functional": "_inputs = [[1, 6], [6, 4], [4, 4], [4, 2], [35, 7], [36, 7], [184756, 20], [184756, 10], [3268760, 25], [155117520, 30], [155117530, 30]]\n_outputs = [[0], [2], [1], [-1], [3], [-1], [10], [-1], [10], [15], [-1]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, f... | 658 | 289 |
coding | Solve the programming task below in a Python markdown code block.
You are given a sequence with N integers: A = \{ A_1, A_2, \cdots, A_N \}.
For each of these N integers, we will choose a color and paint the integer with that color. Here the following condition must be satisfied:
- If A_i and A_j (i < j) are painted w... | {"inputs": ["4\n1\n0\n0\n0", "4\n0\n0\n1\n0", "4\n2\n0\n0\n0", "4\n0\n0\n1\n1", "4\n0\n0\n0\n0", "4\n0\n0\n0\n0\n", "4\n0\n-1\n0\n0", "4\n1\n-1\n0\n0"], "outputs": ["4\n", "3\n", "4\n", "2\n", "4", "4\n", "3\n", "3\n"]} | 237 | 128 |
coding | Solve the programming task below in a Python markdown code block.
Input
The input contains two integers a1, a2 (0 ≤ ai ≤ 109), separated by a single space.
Output
Output a single integer.
Examples
Input
3 14
Output
44
Input
27 12
Output
48
Input
100 200
Output
102 | {"inputs": ["0 0\n", "2 3\n", "1 3\n", "2 14\n", "3 12\n", "2 21\n", "3 19\n", "2 19\n"], "outputs": ["0\n", "5\n", "4\n", "43\n", "24\n", "14\n", "94\n", "93\n"]} | 90 | 96 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
We define the usage of capitals in a word to be right when one of the following cases holds:
All letters in this word are capitals, like "USA".
All letters in this word are not capitals, like "leetcode".
Only the fir... | {"functional": "def check(candidate):\n assert candidate(word = \"USA\") == True\n assert candidate(word = \"FlaG\") == False\n\n\ncheck(Solution().detectCapitalUse)"} | 124 | 44 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
There is a bi-directional graph with n vertices, where each vertex is labeled from 0 to n - 1 (inclusive). The edges in the graph are represented as a 2D integer array edges, where each edges[i] = [ui, vi] denotes a b... | {"functional": "def check(candidate):\n assert candidate(n = 3, edges = [[0,1],[1,2],[2,0]], source = 0, destination = 2) == True\n assert candidate(n = 6, edges = [[0,1],[0,2],[3,5],[5,4],[4,3]], source = 0, destination = 5) == False\n\n\ncheck(Solution().validPath)"} | 196 | 99 |
coding | Solve the programming task below in a Python markdown code block.
This is a simplified version of the problem B2. Perhaps you should read the problem B2 before you start solving B1.
Paul and Mary have a favorite string $s$ which consists of lowercase letters of the Latin alphabet. They want to paint it using pieces of... | {"inputs": ["1\naa\n", "1\naa\n", "1\nab\n", "1\ndscnjksdcnsjkvndfjkvndfjkvnkdfnv\n", "1\ndscnjksdcnsjkvndfjkvndfjkvnkdfnv\n", "1\ndscnjksdcnsjkvndfjkvndfjkvnkdfnu\n", "1\ndscnjksdcnsjkvndfjkvnefjkvnkdfnu\n", "1\ndscnjksdcnsjjvndfjkvoefjkwnkdfnu\n"], "outputs": ["1\n", "1\n", "1\n", "8\n", "8\n", "8\n", "9\n", "10\n"]} | 657 | 176 |
coding | Solve the programming task below in a Python markdown code block.
In a far away kingdom young pages help to set the table for the King. As they are terribly mischievous, one needs to keep an eye on the control whether they have set everything correctly. This time the royal chef Gerasim had the impression that the pages... | {"inputs": ["1\n0\n", "2\n1\n0\n", "2\n1\n2\n", "2\n0\n1\n", "2\n1\n1\n", "2\n0\n0\n", "2\n0\n2\n", "2\n2\n0\n"], "outputs": ["Exemplary pages.\n", "Unrecoverable configuration.\n", "Unrecoverable configuration.\n", "Unrecoverable configuration.\n", "Exemplary pages.\n", "Exemplary pages.\n", "1 ml. from cup #1 to cup ... | 567 | 146 |
coding | Solve the programming task below in a Python markdown code block.
Summer is coming! It's time for Iahub and Iahubina to work out, as they both want to look hot at the beach. The gym where they go is a matrix a with n lines and m columns. Let number a[i][j] represents the calories burned by performing workout at the cel... | {"inputs": ["3 3\n3 1 2\n3 2 0\n2 3 2\n", "3 3\n9 0 9\n0 9 9\n9 9 9\n", "3 3\n3 1 2\n3 2 0\n2 3 2\n", "3 3\n9 0 9\n0 9 9\n9 9 9\n", "3 3\n3 1 2\n3 2 0\n1 3 2\n", "3 3\n9 0 9\n0 9 9\n9 5 9\n", "3 3\n3 1 3\n3 2 0\n1 3 2\n", "3 3\n0 0 9\n0 9 9\n9 5 9\n"], "outputs": ["16", "54", "16\n", "54\n", "15\n", "50\n", "16\n", "41... | 558 | 236 |
coding | Solve the programming task below in a Python markdown code block.
Oleg the bank client checks share prices every day. There are n share prices he is interested in. Today he observed that each second exactly one of these prices decreases by k rubles (note that each second exactly one price changes, but at different seco... | {"inputs": ["2 1\n2 3\n", "2 4\n3 7\n", "2 3\n2 4\n", "2 3\n1 6\n", "2 3\n5 8\n", "2 3\n6 9\n", "2 3\n1 8\n", "2 3\n2 5\n"], "outputs": ["1\n", "1\n", "-1\n", "-1\n", "1\n", "1\n", "-1\n", "1\n"]} | 555 | 118 |
coding | Solve the programming task below in a Python markdown code block.
A boy named Vasya wants to play an old Russian solitaire called "Accordion". In this solitaire, the player must observe the following rules:
* A deck of n cards is carefully shuffled, then all n cards are put on the table in a line from left to right;... | {"inputs": ["1\n3C\n", "1\n3D\n", "1\n4C\n", "2\n3S 2C\n", "4\n2C 3D 4D 5C\n", "4\n2C 4D 4D 5C\n", "4\n2D 4D 4D 5C\n", "4\n2S 2S 2C 2C\n"], "outputs": ["YES\n", "YES\n", "YES\n", "NO\n", "NO\n", "NO\n", "NO\n", "YES\n"]} | 646 | 133 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a non-negative integer x, return the square root of x rounded down to the nearest integer. The returned integer should be non-negative as well.
You must not use any built-in exponent function or operator.
For e... | {"functional": "def check(candidate):\n assert candidate(x = 4) == 2\n assert candidate(x = 8) == 2\n\n\ncheck(Solution().mySqrt)"} | 117 | 44 |
coding | Solve the programming task below in a Python markdown code block.
n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number o... | {"inputs": ["2 2\n0 0\n0 0\n", "2 2\n0 0\n0 1\n", "2 2\n1 1\n1 0\n", "2 2\n2 1\n1 0\n", "2 2\n2 0\n1 0\n", "2 2\n0 1\n1 0\n", "2 2\n0 0\n0 -1\n", "3 2\n1 2 2\n3 4\n"], "outputs": ["0\n", "1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "13\n"]} | 731 | 153 |
coding | Solve the programming task below in a Python markdown code block.
Chef has an array A of length N. Chef wants to select some disjoint, non-empty subarrays from A such that:
The mex of each of the selected subarray is the same.
Note that the selected subarrays need not cover all the elements of the array.
For e.g. if... | {"inputs": ["2\n4\n0 1 1 0\n6\n0 0 3 1 2 0\n"], "outputs": ["2\n3\n"]} | 595 | 40 |
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 nums representing the initial positions of some marbles. You are also given two 0-indexed integer arrays moveFrom and moveTo of equal length.
Throughout moveFrom.length steps, y... | {"functional": "def check(candidate):\n assert candidate(nums = [1,6,7,8], moveFrom = [1,7,2], moveTo = [2,9,5]) == [5,6,8,9]\n assert candidate(nums = [1,1,3,3], moveFrom = [1,3], moveTo = [2,2]) == [2]\n\n\ncheck(Solution().relocateMarbles)"} | 181 | 99 |
coding | Solve the programming task below in a Python markdown code block.
# Task
Given a sequence of 0s and 1s, determine if it is a prefix of Thue-Morse sequence.
The infinite Thue-Morse sequence is obtained by first taking a sequence containing a single 0 and then repeatedly concatenating the current sequence with its bin... | {"functional": "_inputs = [[[0, 1, 1, 0, 1]], [[0]], [[1]], [[0, 1, 0, 0]]]\n_outputs = [[True], [True], [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)):\... | 322 | 196 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a string s representing a list of words. Each letter in the word has one or more options.
If there is one option, the letter is represented as is.
If there is more than one option, then curly braces del... | {"functional": "def check(candidate):\n assert candidate(s = \"{a,b}c{d,e}f\") == [\"acdf\",\"acef\",\"bcdf\",\"bcef\"]\n assert candidate(s = \"abcd\") == [\"abcd\"]\n\n\ncheck(Solution().expand)"} | 181 | 66 |
coding | Solve the programming task below in a Python markdown code block.
# Leaderboard climbers
In this kata you will be given a leaderboard of unique names for example:
```python
['John',
'Brian',
'Jim',
'Dave',
'Fred']
```
Then you will be given a list of strings for example:
```python
['Dave +1', 'Fred +4', 'Brian ... | {"functional": "_inputs = [[['John', 'Brian', 'Jim', 'Dave', 'Fred'], ['Dave +1', 'Fred +4', 'Brian -1']], [['Bob', 'Larry', 'Kevin', 'Jack', 'Max'], ['Max +3', 'Kevin -1', 'Kevin +3']]]\n_outputs = [[['Fred', 'John', 'Dave', 'Brian', 'Jim']], [['Bob', 'Kevin', 'Max', 'Larry', 'Jack']]]\nimport math\ndef _deep_eq(a, b,... | 295 | 244 |
coding | Solve the programming task below in a Python markdown code block.
# Task
A newspaper is published in Walrusland. Its heading is `s1` , it consists of lowercase Latin letters.
Fangy the little walrus wants to buy several such newspapers, cut out their headings, glue them one to another in order to get one big string. ... | {"functional": "_inputs = [['abc', 'bcac'], ['abc', 'xyz'], ['abc', 'abcabc'], ['abc', 'abccba'], ['abc', 'aaaaaa']]\n_outputs = [[2], [-1], [2], [4], [6]]\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 ... | 352 | 201 |
coding | Solve the programming task below in a Python markdown code block.
Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at a_1 percent and second one is charged at a_2 percent. You can connect charger to a joystick only at the beginning of each min... | {"inputs": ["3 5\n", "4 4\n", "1 4\n", "1 1\n", "8 8\n", "7 2\n", "1 2\n", "2 1\n"], "outputs": ["6\n", "5\n", "2\n", "0\n", "13\n", "7\n", "1\n", "1\n"]} | 540 | 87 |
coding | Solve the programming task below in a Python markdown code block.
Monocarp is a little boy who lives in Byteland and he loves programming.
Recently, he found a permutation of length $n$. He has to come up with a mystic permutation. It has to be a new permutation such that it differs from the old one in each position.
... | {"inputs": ["4\n3\n1 2 3\n5\n2 3 4 5 1\n4\n2 3 1 4\n1\n1\n"], "outputs": ["2 3 1\n1 2 3 4 5\n1 2 4 3\n-1\n"]} | 683 | 73 |
coding | Solve the programming task below in a Python markdown code block.
There are $n + 1$ cities, numbered from $0$ to $n$. $n$ roads connect these cities, the $i$-th road connects cities $i - 1$ and $i$ ($i \in [1, n]$).
Each road has a direction. The directions are given by a string of $n$ characters such that each charac... | {"inputs": ["2\n6\nLRRRLL\n3\nLRL\n", "2\n6\nLLRRRL\n3\nLRL\n", "2\n6\nLLRRRL\n3\nRLL\n", "2\n6\nLRRRLL\n3\nRLL\n", "2\n6\nLLRRRL\n3\nLLR\n", "2\n6\nLRRRLL\n3\nLLR\n", "2\n6\nLRLRRL\n3\nLRL\n", "2\n6\nRRLRLL\n3\nRLL\n"], "outputs": ["1 3 2 3 1 3 2\n1 4 1 4\n", "1 2 3 2 3 1 3\n1 4 1 4\n", "1 2 3 2 3 1 3\n3 1 3 2\n", "1 ... | 614 | 323 |
coding | Solve the programming task below in a Python markdown code block.
A smelt fishing tournament was held at Lake Hibara. The winner is the one who wins the most smelt.
Create a program that reads the list of participant numbers and the number of fish caught and outputs the number of winners and the number of fish caught.... | {"inputs": ["6\n2 3\n2 6\n2 1\n4 3\n5 31\n6 89", "6\n2 0\n2 6\n3 1\n2 3\n5 61\n6 57", "6\n2 1\n2 8\n3 1\n2 3\n4 61\n1 57", "6\n2 1\n2 8\n3 1\n2 3\n4 61\n1 69", "6\n3 2\n6 8\n4 1\n2 3\n3 29\n1 54", "6\n1 14\n2 6\n3 3\n4 3\n5 40\n6 37", "6\n2 14\n2 6\n3 1\n4 3\n5 31\n6 37", "6\n2 14\n2 6\n3 0\n4 3\n5 31\n6 57"], "outputs... | 226 | 297 |
coding | Solve the programming task below in a Python markdown code block.
You are given array a with n elements and the number m. Consider some subsequence of a and the value of least common multiple (LCM) of its elements. Denote LCM as l. Find any longest subsequence of a with the value l ≤ m.
A subsequence of a is an array ... | {"inputs": ["1 1\n2\n", "1 3\n5\n", "1 2\n3\n", "1 3\n2\n", "1 6\n5\n", "1 3\n5\n", "1 1\n2\n", "1 2\n3\n"], "outputs": ["1 0\n\n", "1 0\n\n", "1 0\n\n", "2 1\n1\n", "5 1\n1\n", "1 0\n", "1 0\n", "1 0\n"]} | 336 | 125 |
coding | Solve the programming task below in a Python markdown code block.
Problem
Mr. ukuku1333 is a little sloppy, so when I expanded the product of the linear expressions of x, I couldn't figure out the original linear expression.
Given the nth degree polynomial of x, factor it into the product of the original linear expres... | {"inputs": ["x^1-2", "x^1-1", "x^1-3", "x^1-4", "x^2-4", "x^1-5", "x^1-6", "x^1+6"], "outputs": ["(x-2)\n", "(x-1)\n", "(x-3)\n", "(x-4)\n", "(x-2)(x+2)\n", "(x-5)\n", "(x-6)\n", "(x+6)\n"]} | 576 | 123 |
coding | Solve the programming task below in a Python markdown code block.
# A wolf in sheep's clothing
Wolves have been reintroduced to Great Britain. You are a sheep farmer, and are now plagued by wolves which pretend to be sheep. Fortunately, you are good at spotting them.
Warn the sheep in front of the wolf that it is ab... | {"functional": "_inputs = [[['sheep', 'sheep', 'sheep', 'sheep', 'sheep', 'wolf', 'sheep', 'sheep']], [['sheep', 'wolf', 'sheep', 'sheep', 'sheep', 'sheep', 'sheep']], [['wolf', 'sheep', 'sheep', 'sheep', 'sheep', 'sheep', 'sheep']], [['sheep', 'wolf', 'sheep']], [['sheep', 'sheep', 'wolf']]]\n_outputs = [['Oi! Sheep n... | 328 | 348 |
coding | Solve the programming task below in a Python markdown code block.
You are given a number $n$ and an array $b_1, b_2, \ldots, b_{n+2}$, obtained according to the following algorithm:
some array $a_1, a_2, \ldots, a_n$ was guessed;
array $a$ was written to array $b$, i.e. $b_i = a_i$ ($1 \le i \le n$);
The $(n+1)$-th ... | {"inputs": ["4\n3\n2 3 7 9 2\n4\n9 1 7 1 6 5\n5\n18 2 2 3 2 9 2\n3\n2 6 9 2 1\n", "4\n3\n2 3 7 12 2\n4\n9 1 7 1 6 5\n5\n18 2 2 3 2 9 2\n3\n2 6 9 2 1\n", "4\n3\n2 3 7 12 2\n4\n9 1 7 1 6 5\n5\n18 2 2 3 2 9 2\n3\n2 6 9 2 1\n", "1\n6\n1000010101 1100000000 1000000000 1000000100 1000000000 1000010000 1111000000 70194680\n",... | 601 | 756 |
coding | Solve the programming task below in a Python markdown code block.
Absent-minded Masha got set of n cubes for her birthday.
At each of 6 faces of each cube, there is exactly one digit from 0 to 9. Masha became interested what is the largest natural x such she can make using her new cubes all integers from 1 to x.
To m... | {"inputs": ["1\n5 2 2 5 6 7\n", "1\n7 6 5 8 9 0\n", "1\n2 5 9 6 7 9\n", "1\n6 3 1 9 4 9\n", "1\n1 9 8 3 7 8\n", "1\n4 6 9 8 2 7\n", "1\n5 3 8 0 2 6\n", "1\n7 9 5 0 4 6\n"], "outputs": ["0", "0", "0", "1", "1", "0", "0", "0"]} | 400 | 158 |
coding | Solve the programming task below in a Python markdown code block.
Given an integer N, find the number of tuples (w, x, y, z) such that 1 ≤ w, x, y, z ≤ N and \frac{w}{x} + \frac{y}{z} is an integer.
For example, if N = 2, the tuple (1,2,1,2) satisfies both conditions, i.e. \frac{1}{2} + \frac{1}{2} = 1 is an integer, ... | {"inputs": ["3\n2\n3\n7"], "outputs": ["10\n31\n355\n"]} | 567 | 27 |
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 citizen of Arrayland. Your President (Mr. P) has given you a mundane problem:
You're given an array a with size N (1-based indexing). You are allowed to perform an... | {"inputs": ["1\n6\n1 2 3 4 5 6"], "outputs": ["1"]} | 420 | 26 |
coding | Solve the programming task below in a Python markdown code block.
Christy is interning at HackerRank. One day she has to distribute some chocolates to her colleagues. She is biased towards her friends and plans to give them more than the others. One of the program managers hears of this and tells her to make sure every... | {"inputs": ["1\n4\n2 2 3 7\n", "1\n3\n10 7 12\n"], "outputs": ["2\n", "3\n"]} | 687 | 42 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two strings s and t. In one step, you can append any character to either s or t.
Return the minimum number of steps to make s and t anagrams of each other.
An anagram of a string is a string that contain... | {"functional": "def check(candidate):\n assert candidate(s = \"leetcode\", t = \"coats\") == 7\n assert candidate(s = \"night\", t = \"thing\") == 0\n\n\ncheck(Solution().minSteps)"} | 116 | 54 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given two strings s and goal, return true if and only if s can become goal after some number of shifts on s.
A shift on s consists of moving the leftmost character of s to the rightmost position.
For example, if s = ... | {"functional": "def check(candidate):\n assert candidate(s = \"abcde\", goal = \"cdeab\") == True\n assert candidate(s = \"abcde\", goal = \"abced\") == False\n\n\ncheck(Solution().rotateString)"} | 117 | 56 |
coding | Solve the programming task below in a Python markdown code block.
Ichigo is receiving special training from Kisuke Urahara to beat Aizen. This time, Kisuke took (P * Q * R) identical cubes and made them into a big box of dimensions P x Q x R. Moreover, it happened quite by chance that P, Q, R were all pairwise coprime,... | {"inputs": ["3\n1 1 1\n2 1 3\n5 3 2\n"], "outputs": ["1\n5\n15\n"]} | 513 | 37 |
coding | Solve the programming task below in a Python markdown code block.
The Little Elephant from the Zoo of Lviv currently is on the military mission. There are N enemy buildings placed in a row and numbered from left to right strating from 0. Each building i (except the first and the last) has exactly two adjacent buildings... | {"inputs": ["3\n3\n010\n5\n10001\n7\n0000000", "3\n3\n011\n5\n10001\n7\n0000000", "3\n3\n010\n5\n10001\n7\n0010000", "3\n3\n010\n5\n10001\n7\n1010000", "3\n3\n010\n5\n10000\n7\n1010000", "3\n3\n010\n5\n10011\n7\n0000000", "3\n3\n001\n5\n10101\n7\n0000000", "3\n3\n010\n5\n00011\n7\n1010000"], "outputs": ["0\n1\n7", "0\n... | 318 | 285 |
coding | Solve the programming task below in a Python markdown code block.
You are given three sticks with positive integer lengths of a, b, and c centimeters. You can increase length of some of them by some positive integer number of centimeters (different sticks can be increased by a different length), but in total by at most... | {"inputs": ["1 2 1 5\n", "2 7 8 4\n", "2 5 8 4\n", "2 2 3 1\n", "1 1 1 2\n", "1 2 3 1\n", "4 2 5 28\n", "3 1 29 1\n"], "outputs": ["20\n", "25\n", "16\n", "3\n", "4\n", "2\n", "1893\n", "0\n"]} | 338 | 126 |
coding | Solve the programming task below in a Python markdown code block.
Your friend has been out shopping for puppies (what a time to be alive!)... He arrives back with multiple dogs, and you simply do not know how to respond!
By repairing the function provided, you will find out exactly how you should respond, depending on... | {"functional": "_inputs = [[26], [8], [14], [80], [100], [50], [10], [101]]\n_outputs = [['More than a handful!'], ['Hardly any'], ['More than a handful!'], [\"Woah that's a lot of dogs!\"], [\"Woah that's a lot of dogs!\"], ['More than a handful!'], ['Hardly any'], ['101 DALMATIONS!!!']]\nimport math\ndef _deep_eq(a, ... | 237 | 252 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
There are n pieces arranged in a line, and each piece is colored either by 'A' or by 'B'. You are given a string colors of length n where colors[i] is the color of the ith piece.
Alice and Bob are playing a game where... | {"functional": "def check(candidate):\n assert candidate(colors = \"AAABABB\") == True\n assert candidate(colors = \"AA\") == False\n assert candidate(colors = \"ABBBBBBBAAA\") == False\n\n\ncheck(Solution().winnerOfGame)"} | 244 | 58 |
coding | Solve the programming task below in a Python markdown code block.
There are n problems prepared for the next Codeforces round. They are arranged in ascending order by their difficulty, and no two problems have the same difficulty. Moreover, there are m pairs of similar problems. Authors want to split problems between t... | {"inputs": ["2 0\n", "3 0\n", "4 0\n", "2 0\n", "4 0\n", "3 0\n", "7 0\n", "5 0\n"], "outputs": ["1\n", "2\n", "3\n", "1\n", "3\n", "2\n", "6\n", "4\n"]} | 556 | 86 |
coding | Solve the programming task below in a Python markdown code block.
Description
In English we often use "neutral vowel sounds" such as "umm", "err", "ahh" as fillers in conversations to help them run smoothly.
Bob always finds himself saying "err". Infact he adds an "err" to every single word he says that ends in a con... | {"functional": "_inputs = [['r r r r r r r r'], ['THIS, is crazy!'], ['hI, hi. hI hi skY! sky? skY sky'], ['Hello, I am Mr Bob.'], ['This, is. another! test? case to check your beautiful code.'], ['Hello from the other siiiiideeee'], ['Punctuation? is, important! double space also']]\n_outputs = [['rerr rerr rerr rerr... | 255 | 350 |
coding | Solve the programming task below in a Python markdown code block.
You are given a grid of size M x N, where each square is colored with some random color among K colors with each having equal probability.
A Good Rectangle is defined as one where all squares lying on the inner border are of the same color.
What is the... | {"inputs": ["1 3 1"], "outputs": ["6"]} | 162 | 16 |
coding | Solve the programming task below in a Python markdown code block.
There is a grid, consisting of n rows and m columns. Each cell of the grid is either free or blocked. One of the free cells contains a lab. All the cells beyond the borders of the grid are also blocked.
A crazy robot has escaped from this lab. It is cur... | {"inputs": ["4\n3 3\n...\n.L.\n...\n4 5\n#....\n..##L\n...#.\n.....\n1 1\nL\n1 9\n.#..L....\n", "4\n3 3\n...\n.L.\n...\n4 5\n#....\n..##L\n.#...\n.....\n1 1\nL\n1 9\n.#..L....\n", "4\n3 3\n...\n..L\n...\n4 5\n#....\n..##L\n.#...\n.....\n1 1\nL\n1 9\n.#..L....\n", "4\n3 3\n...\n..L\n...\n4 5\n#....\n..##L\n..#..\n.....\... | 679 | 664 |
coding | Solve the programming task below in a Python markdown code block.
Little Artem has invented a time machine! He could go anywhere in time, but all his thoughts of course are with computer science. He wants to apply this time machine to a well-known data structure: multiset.
Artem wants to create a basic multiset of int... | {"inputs": ["3\n1 1 1\n2 2 1\n3 6 1\n", "3\n1 1 1\n3 2 1\n3 7 1\n", "3\n1 1 1\n3 2 0\n3 7 1\n", "3\n1 1 1\n1 2 1\n3 3 1\n", "3\n1 1 1\n2 2 1\n3 7 1\n", "3\n1 1 1\n2 2 1\n3 9 1\n", "3\n1 1 1\n1 2 1\n3 9 1\n", "3\n1 1 1\n3 2 2\n3 7 1\n"], "outputs": ["0\n", "1\n1\n", "0\n1\n", "2\n", "0\n", "0\n", "2\n", "0\n1\n"]} | 706 | 220 |
coding | Solve the programming task below in a Python markdown code block.
Ivan has a robot which is situated on an infinite grid. Initially the robot is standing in the starting cell (0, 0). The robot can process commands. There are four types of commands it can perform: U — move from the cell (x, y) to (x, y + 1); D — move ... | {"inputs": ["1\nU\n", "1\nD\n", "1\nU\n", "1\nD\n", "2\nLR\n", "2\nLR\n", "2\nRL\n", "4\nLDUR\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "2\n", "2\n", "2\n", "4\n"]} | 351 | 87 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two positive integers left and right with left <= right. Calculate the product of all integers in the inclusive range [left, right].
Since the product may be very large, you will abbreviate it following ... | {"functional": "def check(candidate):\n assert candidate(left = 1, right = 4) == \"24e0\"\n assert candidate(left = 2, right = 11) == \"399168e2\"\n assert candidate(left = 371, right = 375) == \"7219856259e3\"\n\n\ncheck(Solution().abbreviateProduct)"} | 360 | 100 |
coding | Solve the programming task below in a Python markdown code block.
Polycarpus participates in a competition for hacking into a new secure messenger. He's almost won.
Having carefully studied the interaction protocol, Polycarpus came to the conclusion that the secret key can be obtained if he properly cuts the public ke... | {"inputs": ["23\n2 3\n", "23\n2 3\n", "604\n6 4\n", "604\n6 4\n", "604\n6 2\n", "604\n4 2\n", "604\n4 1\n", "120\n12 1\n"], "outputs": ["YES\n2\n3\n", "YES\n2\n3\n", "YES\n60\n4\n", "YES\n60\n4\n", "YES\n60\n4\n", "YES\n60\n4\n", "YES\n60\n4\n", "NO\n"]} | 493 | 150 |
coding | Solve the programming task below in a Python markdown code block.
# Task
You are given an array of integers. Your task is to determine the minimum number of its elements that need to be changed so that elements of the array will form an arithmetic progression. Note that if you swap two elements, you're changing both o... | {"functional": "_inputs = [[[1, 2, 3]], [[1, 3, 0, 7, 9]], [[1, 10, 2, 12, 3, 14, 4, 16, 5]], [[7, 7, 7, 7, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 9, 7, 7, 7, 7, 7, 7]], [[2, -1, -4, 12, 1, -13, -16, -19, -6, -25]], [[-1, 2, 5, 8, 11, 14, 17, -6, 23, 26, -25, 32]], [[-10, -21, -20, -25, -13, 14, 2, 6, -50, -55, -60, -65, -70, -... | 420 | 1,072 |
coding | Solve the programming task below in a Python markdown code block.
As a part of this Kata, you need to create a function that when provided with a triplet, returns the index of the numerical element that lies between the other two elements.
The input to the function will be an array of three distinct numbers (Haskell: ... | {"functional": "_inputs = [[[2, 3, 1]], [[5, 10, 14]], [[1, 3, 4]], [[15, 10, 14]], [[-0.41, -23, 4]], [[-15, -10, 14]]]\n_outputs = [[0], [1], [1], [2], [0], [1]]\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=to... | 205 | 235 |
coding | Solve the programming task below in a Python markdown code block.
You take your son to the forest to see the monkeys. You know that there are a certain number there (n), but your son is too young to just appreciate the full number, he has to start counting them from 1.
As a good parent, you will sit and count with him... | {"functional": "_inputs = [[5], [3], [9], [10], [20]]\n_outputs = [[[1, 2, 3, 4, 5]], [[1, 2, 3]], [[1, 2, 3, 4, 5, 6, 7, 8, 9]], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isin... | 174 | 319 |
coding | Solve the programming task below in a Python markdown code block.
Ramesh and Suresh are best friends. But they are fighting over money now. Suresh has given some money to Ramesh but he has forgotten how much money he had given. So Ramesh made a plan that he will give Re. 1 to every rectangle Suresh makes in a N x M are... | {"inputs": ["100\n14 17\n28 26\n24 26\n17 13\n10 2\n3 8\n21 20\n24 17\n1 7\n23 17\n12 9\n28 10\n3 21\n3 14\n8 26\n30 13\n13 19\n30 28\n14 17\n2 23\n10 4\n22 30\n15 8\n9 15\n6 1\n24 17\n2 21\n27 4\n3 21\n17 2\n16 16\n15 28\n27 6\n17 10\n14 18\n25 16\n13 16\n15 28\n15 15\n4 21\n8 19\n7 9\n9 25\n4 12\n15 20\n13 1\n27 19\n... | 343 | 1,089 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a string s, and an array of pairs of indices in the string pairs where pairs[i] = [a, b] indicates 2 indices(0-indexed) of the string.
You can swap the characters at any pair of indices in the given pair... | {"functional": "def check(candidate):\n assert candidate(s = \"dcab\", pairs = [[0,3],[1,2]]) == \"bacd\"\n assert candidate(s = \"dcab\", pairs = [[0,3],[1,2],[0,2]]) == \"abcd\"\n assert candidate(s = \"cba\", pairs = [[0,1],[1,2]]) == \"abc\"\n\n\ncheck(Solution().smallestStringWithSwaps)"} | 144 | 102 |
coding | Solve the programming task below in a Python markdown code block.
Consider a tic-tac-toe on a 3x3 board. Tic-tac-toe is a two-player battle game. Decide the first attack and the second attack, one hits Kuroishi and one hits Shiraishi. The winner is the person who puts stones one by one on the board alternately and arra... | {"inputs": ["bbw\nwbw\n+b+\nbwb\nwbx\nwbw\n0", "bbw\nbww\n+b+\nbwb\nwbx\nwbw\n0", "bbw\nwwb\n+a+\nbwb\nxbw\nwvb\n0", "bbw\nwbw\n+b+\nbbw\nwcw\nbww\n0", "bbw\nwcw\n+c+\nwbb\nwcw\nwwb\n0", "cwb\nwwb\n++b\nbwb\nwbw\nxyb\n0", "bbw\nwbw\n+b+\nbwb\nwcw\nwbw\n0", "cbw\nwbw\n+b+\nbwb\nwbx\nwbw\n0"], "outputs": ["b\nNA\n", "NA\... | 324 | 216 |
coding | Solve the programming task below in a Python markdown code block.
# Definition
A **number** is called **_Automorphic number_** if and only if *its square ends in the same digits as the number itself*.
___
# Task
**_Given_** a **number** *determine if it Automorphic or not* .
___
# Warm-up (Highly recommended)
# [P... | {"functional": "_inputs = [[1], [3], [6], [9], [25], [53], [76], [95], [625], [225]]\n_outputs = [['Automorphic'], ['Not!!'], ['Automorphic'], ['Not!!'], ['Automorphic'], ['Not!!'], ['Automorphic'], ['Not!!'], ['Automorphic'], ['Not!!']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinst... | 675 | 227 |
coding | Solve the programming task below in a Python markdown code block.
Chefland is a $1D$ city where each of the $N$ houses is located at a distinct positive integer coordinate $A_{1}, A_{2}, \ldots A_{N}$. The chef is planning to create $K$ hills in the city. Note that two hills cannot be present at the same location but t... | {"inputs": ["3\n3 1\n1 2 3\n1 5\n1\n2 2\n1 5"], "outputs": ["2\n2\n5"]} | 586 | 40 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a string s, return the number of unique palindromes of length three that are a subsequence of s.
Note that even if there are multiple ways to obtain the same subsequence, it is still only counted once.
A palindr... | {"functional": "def check(candidate):\n assert candidate(s = \"aabca\") == 3\n assert candidate(s = \"adc\") == 0\n assert candidate(s = \"bbcbaba\") == 4\n\n\ncheck(Solution().countPalindromicSubsequence)"} | 161 | 63 |
coding | Solve the programming task below in a Python markdown code block.
Snackdown 2019 is coming! People have started to spread the word and tell other people about the contest.
There are $N$ people numbered $1$ through $N$. Initially, only person $1$ knows about Snackdown. On each day, everyone who already knows about Snack... | {"inputs": ["2\n7\n2 1 1 5 5 5 5\n5\n5 1 3 2 1"], "outputs": ["2\n1"]} | 572 | 42 |
coding | Solve the programming task below in a Python markdown code block.
You are given an array of $n$ integers $a_1$, $a_2$, ..., $a_n$, and a set $b$ of $k$ distinct integers from $1$ to $n$.
In one operation, you may choose two integers $i$ and $x$ ($1 \le i \le n$, $x$ can be any integer) and assign $a_i := x$. This oper... | {"inputs": ["1 0\n1337\n", "1 0\n1337\n", "1 0\n2501\n", "1 1\n35\n1\n", "1 1\n120\n1\n", "1 1\n1337\n1\n", "1 1\n1337\n1\n", "5 0\n4 3 1 2 3\n"], "outputs": ["0\n", "0\n", "0", "0", "0", "0\n", "0\n", "2\n"]} | 491 | 133 |
coding | Solve the programming task below in a Python markdown code block.
In Chefland, a tennis game involves 4 referees.
Each referee has to point out whether he considers the ball to be inside limits or outside limits. The ball is considered to be IN if and only if all the referees agree that it was inside limits.
Given t... | {"inputs": ["4\n1 1 0 0\n0 0 0 0\n0 0 0 1\n1 1 1 1\n"], "outputs": ["OUT\nIN\nOUT\nOUT\n"]} | 440 | 52 |
coding | Solve the programming task below in a Python markdown code block.
Given a positive integer $k$, two arrays are called $k$-similar if:
they are strictly increasing;
they have the same length;
all their elements are positive integers between $1$ and $k$ (inclusive);
they differ in exactly one position.
You are given... | {"inputs": ["1 1 4\n3\n1 1\n", "1 1 20\n3\n1 1\n", "1 1 20\n3\n1 1\n", "1 1 20\n5\n1 1\n", "1 1 39\n3\n1 1\n", "1 1 31\n2\n1 1\n", "1 1 26\n3\n1 1\n", "1 1 23\n2\n1 1\n"], "outputs": ["3\n", "19\n", "19\n", "19\n", "38\n", "30\n", "25\n", "22\n"]} | 529 | 164 |
coding | Solve the programming task below in a Python markdown code block.
Chef and his girlfriend go on a date. Chef took X dollars with him, and was quite sure that this would be enough to pay the bill. At the end, the waiter brought a bill of Y dollars. Print "YES" if Chef has enough money to pay the bill, or "NO" if he has ... | {"inputs": ["4\n1 1\n1 2\n2 1\n50 100\n"], "outputs": ["YES\nNO\nYES\nNO\n"]} | 399 | 39 |
coding | Solve the programming task below in a Python markdown code block.
In this Kata, you will be given an array of numbers in which two numbers occur once and the rest occur only twice. Your task will be to return the sum of the numbers that occur only once.
For example, `repeats([4,5,7,5,4,8]) = 15` because only the numb... | {"functional": "_inputs = [[[4, 5, 7, 5, 4, 8]], [[9, 10, 19, 13, 19, 13]], [[16, 0, 11, 4, 8, 16, 0, 11]], [[5, 17, 18, 11, 13, 18, 11, 13]], [[5, 10, 19, 13, 10, 13]]]\n_outputs = [[15], [19], [12], [22], [24]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n ... | 341 | 291 |
coding | Solve the programming task below in a Python markdown code block.
Let {\rm comb}(n,r) be the number of ways to choose r objects from among n objects, disregarding order.
From n non-negative integers a_1, a_2, ..., a_n, select two numbers a_i > a_j so that {\rm comb}(a_i,a_j) is maximized.
If there are multiple pairs th... | {"inputs": ["2\n010 0", "2\n001 0", "2\n101 0", "2\n111 0", "2\n110 0", "2\n110 1", "2\n100 1", "2\n010 1"], "outputs": ["10 0\n", "1 0\n", "101 0\n", "111 0\n", "110 0\n", "110 1\n", "100 1\n", "10 1\n"]} | 391 | 138 |
coding | Solve the programming task below in a Python markdown code block.
You want to build a standard house of cards, but you don't know how many cards you will need. Write a program which will count the minimal number of cards according to the number of floors you want to have. For example, if you want a one floor house, you... | {"functional": "_inputs = [[1], [2], [3]]\n_outputs = [[7], [15], [26]]\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 ... | 246 | 170 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a positive integer n, that is initially placed on a board. Every day, for 109 days, you perform the following procedure:
For each number x present on the board, find all numbers 1 <= i <= n such that x ... | {"functional": "def check(candidate):\n assert candidate(n = 5) == 4\n assert candidate(n = 3 ) == 2\n\n\ncheck(Solution().distinctIntegers)"} | 177 | 44 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
The appeal of a string is the number of distinct characters found in the string.
For example, the appeal of "abbca" is 3 because it has 3 distinct characters: 'a', 'b', and 'c'.
Given a string s, return the total ap... | {"functional": "def check(candidate):\n assert candidate(s = \"abbca\") == 28\n assert candidate(s = \"code\") == 20\n\n\ncheck(Solution().appealSum)"} | 122 | 47 |
coding | Solve the programming task below in a Python markdown code block.
In another Kata I came across a weird `sort` function to implement. We had to sort characters as usual ( 'A' before 'Z' and 'Z' before 'a' ) except that the `numbers` had to be sorted **after** the `letters` ( '0' after 'z') !!!
(After a couple of hours... | {"functional": "_inputs = [[['0', '9', '8', '1', '7', '2', '6', '3', '5', '4']], [['3', '2', '1', 'c', 'b', 'a']], [['c', 'b', 'a', '9', '5', '0', 'X', 'Y', 'Z']], [[3, '3', '2', 2, '2', '1', 1, 'a', 'b', 'c']], [[]], [[1]], [['a']]]\n_outputs = [[['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']], [['a', 'b', 'c', '1... | 443 | 379 |
coding | Solve the programming task below in a Python markdown code block.
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Bob and Alice are playing a game with the following rules:
Initially, they have an integer sequence $A_{1}, A_{2}, \ldots, A_{N}$; in addition, Bob h... | {"inputs": ["2\n5 3 2\n1 2 3 4 5\n5 2 4\n1 2 3 4 5"], "outputs": ["ALICE\nBOB"]} | 541 | 48 |
coding | Solve the programming task below in a Python markdown code block.
A coordinate line has n segments, the i-th segment starts at the position l_{i} and ends at the position r_{i}. We will denote such a segment as [l_{i}, r_{i}].
You have suggested that one of the defined segments covers all others. In other words, there... | {"inputs": ["2\n3 5\n1 2\n", "2\n3 5\n1 2\n", "2\n3 4\n1 2\n", "1\n1 100000\n", "1\n1 100000\n", "3\n1 1\n2 2\n3 3\n", "3\n2 5\n3 4\n2 3\n", "3\n3 6\n2 4\n1 5\n"], "outputs": ["-1\n", "-1\n", "-1\n", "1\n", "1\n", "-1\n", "1\n", "-1\n"]} | 361 | 149 |
coding | Solve the programming task below in a Python markdown code block.
This challenge extends the previous [repeater()](https://www.codewars.com/kata/thinkful-string-drills-repeater) challenge. Just like last time, your job is to write a function that accepts a string and a number as arguments. This time, however, you shoul... | {"functional": "_inputs = [['yo', 3], ['WuB', 6], ['code, eat, code, sleep... ', 2]]\n_outputs = [['\"yo\" repeated 3 times is: \"yoyoyo\"'], ['\"WuB\" repeated 6 times is: \"WuBWuBWuBWuBWuBWuB\"'], ['\"code, eat, code, sleep... \" repeated 2 times is: \"code, eat, code, sleep... code, eat, code, sleep... \"']]\nimport... | 168 | 255 |
coding | Solve the programming task below in a Python markdown code block.
Move every letter in the provided string forward 10 letters through the alphabet.
If it goes past 'z', start again at 'a'.
Input will be a string with length > 0.
Also feel free to reuse/extend the following starter code:
```python
def move_ten(st):
``... | {"functional": "_inputs = [['testcase'], ['codewars'], ['exampletesthere'], ['returnofthespacecamel'], ['bringonthebootcamp'], ['weneedanofficedog']]\n_outputs = [['docdmkco'], ['mynogkbc'], ['ohkwzvodocdrobo'], ['bodebxypdroczkmomkwov'], ['lbsxqyxdrolyydmkwz'], ['goxoonkxyppsmonyq']]\nimport math\ndef _deep_eq(a, b, t... | 74 | 242 |
coding | Solve the programming task below in a Python markdown code block.
Bleatrix Trotter the sheep has devised a strategy that helps her fall asleep faster. First, she picks a number N. Then she starts naming N, 2 × N, 3 × N, and so on.
Whenever she names a number, she thinks about all of the digits in that number. She keeps... | {"functional": "_inputs = [[1692], [2], [7], [100], [1], [11], [163444], [206929], [459923], [691520], [0], [12500], [1250000]]\n_outputs = [[5076], [90], [70], [900], [10], [110], [653776], [620787], [4139307], [2074560], ['INSOMNIA'], [900000], [90000000]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstanc... | 383 | 310 |
coding | Solve the programming task below in a Python markdown code block.
There is one apple tree in Arkady's garden. It can be represented as a set of junctions connected with branches so that there is only one way to reach any junctions from any other one using branches. The junctions are enumerated from $1$ to $n$, the junc... | {"inputs": ["1\n\n", "1\n\n", "2\n1\n", "2\n1\n", "3\n1 1\n", "3\n1 2\n", "3\n1 1\n", "5\n1 1 3 3\n"], "outputs": ["1 \n", "1 \n", "1 1 \n", "1 1 \n", "1 1 2 \n", "1 1 1\n", "1 1 2 \n", "1 1 1 2 3 \n"]} | 582 | 127 |
coding | Solve the programming task below in a Python markdown code block.
A Pythagorean triple is a triple of integer numbers $(a, b, c)$ such that it is possible to form a right triangle with the lengths of the first cathetus, the second cathetus and the hypotenuse equal to $a$, $b$ and $c$, respectively. An example of the Py... | {"inputs": ["1\n3\n", "1\n6\n", "1\n23\n", "1\n32\n", "1\n48\n", "1\n79\n", "1\n86\n", "1\n847\n"], "outputs": ["0\n", "1\n", "2\n", "3\n", "4\n", "5\n", "6\n", "20\n"]} | 542 | 94 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
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 ... | {"functional": "def check(candidate):\n assert candidate(position = [1,2,3]) == 1\n assert candidate(position = [2,2,2,3,3]) == 2\n assert candidate(position = [1,1000000000]) == 1\n\n\ncheck(Solution().minCostToMoveChips)"} | 152 | 82 |
coding | Solve the programming task below in a Python markdown code block.
Learning to code around your full time job is taking over your life. You realise that in order to make significant steps quickly, it would help to go to a coding bootcamp in London.
Problem is, many of them cost a fortune, and those that don't still inv... | {"functional": "_inputs = [['Can I have a sabbatical?', 5, 5], ['Why are you shouting?', 7, 2], ['What do you mean I cant learn to code??', 8, 9], ['Please calm down', 9, 1], ['I can?! Nice. FaC..Im coming :D', 9, 9]]\n_outputs = [['Sabbatical! Boom!'], ['Back to your desk, boy.'], ['Sabbatical! Boom!'], ['Back to your... | 297 | 266 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.