task_type stringclasses 4
values | problem stringlengths 14 5.23k | solution stringlengths 1 8.29k | problem_tokens int64 9 1.02k | solution_tokens int64 1 1.98k |
|---|---|---|---|---|
coding | Solve the programming task below in a Python markdown code block.
An adult game master and N children are playing a game on an ice rink. The game consists of K rounds. In the i-th round, the game master announces:
* Form groups consisting of A_i children each!
Then the children who are still in the game form as man... | {"inputs": ["4\n3 3 2 2", "4\n4 3 2 2", "4\n3 5 3 2", "4\n1 1 2 2", "4\n3 4 2 2", "4\n3 6 2 2", "4\n3 6 4 2", "4\n3 4 3 2"], "outputs": ["3 5\n", "4 7\n", "6 11\n", "2 3\n", "-1\n", "-1\n", "-1\n", "6 8"]} | 372 | 136 |
coding | Solve the programming task below in a Python markdown code block.
$k$ people want to split $n$ candies between them. Each candy should be given to exactly one of them or be thrown away.
The people are numbered from $1$ to $k$, and Arkady is the first of them. To split the candies, Arkady will choose an integer $x$ and... | {"inputs": ["2 2 1 1\n", "9 2 2 3\n", "9 2 2 3\n", "2 2 1 1\n", "20 4 5 2\n", "30 9 4 1\n", "31 3 2 8\n", "31 3 2 8\n"], "outputs": ["1\n", "4\n", "4\n", "1\n", "8\n", "4\n", "10\n", "10\n"]} | 624 | 124 |
coding | Solve the programming task below in a Python markdown code block.
Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the en... | {"inputs": ["4\n", "5\n", "3\n", "2\n", "8\n", "6\n", "1\n", "24\n"], "outputs": ["Rajesh", "Howard", "Penny", "Leonard", "Leonard\n", "Sheldon", "Sheldon", "Penny"]} | 362 | 72 |
coding | Solve the programming task below in a Python markdown code block.
Write a program which solve a simultaneous equation:
ax + by = c
dx + ey = f
The program should print x and y for given a, b, c, d, e and f (-1,000 ≤ a, b, c, d, e, f ≤ 1,000). You can suppose that given equation has a unique solution.
Input
The in... | {"inputs": ["1 2 3 4 5 6\n2 -1 -2 0 -1 -5", "1 2 3 4 5 6\n2 -1 -2 0 -1 -4", "1 2 3 4 6 4\n2 -1 -4 -1 0 -5", "1 2 3 3 5 6\n2 -1 -2 0 -1 -4", "1 2 3 4 0 4\n2 -1 -4 -1 0 -5", "2 1 3 5 5 4\n4 -1 -4 -1 0 -5", "1 2 3 3 5 6\n2 -1 -2 -1 0 -4", "2 1 1 5 5 4\n4 -1 -4 -1 0 -5"], "outputs": ["-1.000 2.000\n1.500 5.000\n", "-1.000 ... | 282 | 420 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an m x n matrix mat, return an array of all the elements of the array in a diagonal order.
Please complete the following python code precisely:
```python
class Solution:
def findDiagonalOrder(self, mat: Li... | {"functional": "def check(candidate):\n assert candidate(mat = [[1,2,3],[4,5,6],[7,8,9]]) == [1,2,4,7,5,3,6,8,9]\n assert candidate(mat = [[1,2],[3,4]]) == [1,2,3,4]\n\n\ncheck(Solution().findDiagonalOrder)"} | 75 | 91 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a positive integer, check whether it has alternating bits: namely, if two adjacent bits will always have different values.
Please complete the following python code precisely:
```python
class Solution:
def... | {"functional": "def check(candidate):\n assert candidate(n = 5) == True\n assert candidate(n = 7) == False\n assert candidate(n = 11) == False\n\n\ncheck(Solution().hasAlternatingBits)"} | 73 | 55 |
coding | Solve the programming task below in a Python markdown code block.
Gargi is thinking of a solution to a problem. Meanwhile, her friend asks her to solve another problem. Since Gargi is busy in her own problem, she seeks your help to solve the new problem.
You are given a string S containing characters a-z (lower case l... | {"inputs": ["1\nabba"], "outputs": ["2"]} | 416 | 15 |
coding | Solve the programming task below in a Python markdown code block.
Sherlock Holmes is bored to death as there aren't any interesting cases to solve. Dr Watson finding it impossible to be around Sherlock goes out to get some fresh air. Just as he lays his feet out of the door, he is thrown right back into his house by th... | {"inputs": ["2 00010\n"], "outputs": ["2\n"]} | 456 | 20 |
coding | Solve the programming task below in a Python markdown code block.
You are given two arrays $a$ and $b$ of length $n$. Array $a$ contains each odd integer from $1$ to $2n$ in an arbitrary order, and array $b$ contains each even integer from $1$ to $2n$ in an arbitrary order.
You can perform the following operation on t... | {"inputs": ["3\n2\n3 1\n4 2\n3\n5 3 1\n2 4 6\n5\n7 5 9 1 3\n2 4 6 10 8\n"], "outputs": ["0\n2\n3\n"]} | 710 | 65 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer array arr, return the mean of the remaining integers after removing the smallest 5% and the largest 5% of the elements.
Answers within 10-5 of the actual answer will be considered accepted.
Please c... | {"functional": "def check(candidate):\n assert candidate(arr = [1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3]) == 2.00000\n assert candidate(arr = [6,2,7,5,1,2,0,3,10,2,5,0,5,5,0,8,7,6,8,0]) == 4.00000\n assert candidate(arr = [6,0,7,0,7,5,7,8,3,4,0,7,8,1,6,8,1,1,2,4,8,1,9,5,4,3,8,5,10,8,6,6,1,0,6,10,8,2,3,4]) == 4... | 94 | 559 |
coding | Solve the programming task below in a Python markdown code block.
Snuke has two boards, each divided into a grid with N rows and N columns. For both of these boards, the square at the i-th row from the top and the j-th column from the left is called Square (i,j).
There is a lowercase English letter written in each squ... | {"inputs": ["2\nab\nda", "2\nab\nad", "2\nab\nac", "2\nba\nca", "2\nbb\nca", "2\nbb\nac", "2\ncb\nac", "2\ncb\nab"], "outputs": ["2\n", "0\n", "0\n", "0\n", "0\n", "0\n", "2\n", "0\n"]} | 506 | 96 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer array nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once. You can return the answer in any order.
You mus... | {"functional": "def check(candidate):\n assert candidate(nums = [1,2,1,3,2,5]) == [3,5]\n assert candidate(nums = [-1,0]) == [-1,0]\n assert candidate(nums = [0,1]) == [1,0]\n\n\ncheck(Solution().singleNumber)"} | 110 | 78 |
coding | Solve the programming task below in a Python markdown code block.
In this Kata, you will create a function that converts a string with letters and numbers to the inverse of that string (with regards to Alpha and Numeric characters). So, e.g. the letter `a` will become `1` and number `1` will become `a`; `z` will become... | {"functional": "_inputs = [['25abcd26'], ['18zyz14'], ['a1b2c3d4'], ['5a8p17'], ['w6aa4ct24m5'], ['17dh'], ['25gj8sk6r17'], ['18zzz14'], ['y17kg5et11'], ['abcdefghijklmnopqrstuvwxyz'], ['1a2b3c4d5e6f7g8h9i10j11k12l13m14n15o16p17q18r19s20t21u22v23w24x25y26z'], ['h15q4pc6yw23nmx19y'], ['p16k11o25x7m6m20ct9'], ['nv15u19d5... | 257 | 887 |
coding | Solve the programming task below in a Python markdown code block.
There are n students who have taken part in an olympiad. Now it's time to award the students.
Some of them will receive diplomas, some wiil get certificates, and others won't receive anything. Students with diplomas and certificates are called winners. ... | {"inputs": ["1 1\n", "5 3\n", "2 1\n", "7 2\n", "9 1\n", "5 1\n", "1 1\n", "7 2\n"], "outputs": ["0 0 1\n", "0 0 5\n", "0 0 2\n", "1 2 4\n", "2 2 5\n", "1 1 3\n", "0 0 1\n", "1 2 4\n"]} | 440 | 118 |
coding | Solve the programming task below in a Python markdown code block.
You are given a connected undirected weighted graph consisting of $n$ vertices and $m$ edges.
You need to print the $k$-th smallest shortest path in this graph (paths from the vertex to itself are not counted, paths from $i$ to $j$ and from $j$ to $i$ a... | {"inputs": ["2 1 1\n1 2 123456789\n", "2 1 1\n1 2 123456789\n", "6 10 5\n2 5 1\n5 3 9\n6 2 2\n1 3 1\n5 1 8\n6 5 10\n1 6 5\n6 4 6\n3 6 2\n3 4 5\n", "6 10 5\n2 5 1\n5 3 9\n6 2 2\n1 3 1\n5 1 8\n6 5 10\n1 6 5\n6 4 6\n3 6 2\n3 4 5\n", "7 15 18\n2 6 3\n5 7 4\n6 5 4\n3 6 9\n6 7 7\n1 6 4\n7 1 6\n7 2 1\n4 3 2\n3 2 8\n5 3 6\n2 5... | 678 | 638 |
coding | Solve the programming task below in a Python markdown code block.
You are given a sequence of N integer numbers A. Calculate the sum of A_{i} AND A_{j} for all the pairs (i, j) where i < j.
The AND operation is the Bitwise AND operation, defined as in here.
------ Input ------
The first line of input consists of t... | {"inputs": ["5\n1 2 3 4 5", "5\n2 2 3 4 5", "5\n2 2 6 4 5", "5\n0 2 6 4 5", "5\n1 2 5 4 6", "5\n0 2 3 4 5", "5\n2 2 6 6 5", "5\n1 2 8 4 6"], "outputs": ["9", "11\n", "18\n", "14\n", "15\n", "7\n", "24\n", "6\n"]} | 256 | 146 |
coding | Solve the programming task below in a Python markdown code block.
*This kata is based on [Project Euler Problem #349](https://projecteuler.net/problem=349). You may want to start with solving [this kata](https://www.codewars.com/kata/langtons-ant) first.*
---
[Langton's ant](https://en.wikipedia.org/wiki/Langton%27s_... | {"functional": "_inputs = [[0], [1], [2], [10], [100], [1000], [10000], [100000], [1000000], [10000000]]\n_outputs = [[0], [1], [2], [6], [20], [118], [720], [11108], [114952], [1153412]]\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,... | 312 | 257 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given two integer arrays pushed and popped each with distinct values, return true if this could have been the result of a sequence of push and pop operations on an initially empty stack, or false otherwise.
Please c... | {"functional": "def check(candidate):\n assert candidate(pushed = [1,2,3,4,5], popped = [4,5,3,2,1]) == True\n assert candidate(pushed = [1,2,3,4,5], popped = [4,3,5,1,2]) == False\n\n\ncheck(Solution().validateStackSequences)"} | 94 | 87 |
coding | Solve the programming task below in a Python markdown code block.
Tanish is the president of the chemistry club at his school. He considers everyone who doesn't like chemistry as his enemy. After years of research, he has invented a lethal poison, which he named success. Now Tanish plans to kill all his enemies with hi... | {"inputs": ["2\n2\n9 3\n3\n3 2 9"], "outputs": ["6.00000000\n4.00000000"]} | 574 | 46 |
coding | Solve the programming task below in a Python markdown code block.
In this Kata, you will be given an integer `n` and your task will be to return `the largest integer that is <= n and has the highest digit sum`.
For example:
```
solve(100) = 99. Digit Sum for 99 = 9 + 9 = 18. No other number <= 100 has a higher digit s... | {"functional": "_inputs = [[79320], [99004], [99088], [99737], [29652], [100], [48], [521], [1], [2], [3], [39188], [5], [10], [1000], [10000], [999999999992], [59195], [19930], [110], [1199], [120], [18], [2090], [72694]]\n_outputs = [[78999], [98999], [98999], [98999], [28999], [99], [48], [499], [1], [2], [3], [3899... | 177 | 433 |
coding | Solve the programming task below in a Python markdown code block.
It is the Indian version of the famous heist “The Italian Job”. N robbers have already broken into the National Museum and are just about to get inside the main vault which is full of jewels. They were lucky that just as they broke into the museum, the g... | {"inputs": ["2\n3 4\n2 4 2\n3 2\n2 4 2\n"], "outputs": ["YES\nNO\n"]} | 548 | 36 |
coding | Solve the programming task below in a Python markdown code block.
You are given a matrix f with 4 rows and n columns. Each element of the matrix is either an asterisk (*) or a dot (.).
You may perform the following operation arbitrary number of times: choose a square submatrix of f with size k × k (where 1 ≤ k ≤ 4) an... | {"inputs": ["4\n1 1 1 1\n....\n....\n....\n....\n", "4\n1 1 1 1\n****\n****\n****\n****\n", "4\n1 1 2 1\n....\n....\n....\n....\n", "4\n1 1 0 1\n****\n****\n****\n****\n", "4\n1 1 3 1\n....\n....\n....\n....\n", "4\n0 1 1 1\n....\n....\n....\n....\n", "4\n2 1 1 1\n****\n****\n****\n****\n", "4\n1 0 0 1\n****\n****\n***... | 494 | 228 |
coding | Solve the programming task below in a Python markdown code block.
A bracket sequence is a string containing only characters "(" and ")".
A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original characters of t... | {"inputs": ["1\n)(\n", "1\n()\n", "1\n)(\n", "1\n()\n", "1\n((\n", "1\n))\n", "2\n()\n()\n", "2\n((\n))\n"], "outputs": ["0\n", "1\n", "0\n", "1\n", "0\n", "0\n", "4\n", "1\n"]} | 475 | 96 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 2D integer array ranges and two integers left and right. Each ranges[i] = [starti, endi] represents an inclusive interval between starti and endi.
Return true if each integer in the inclusive range [le... | {"functional": "def check(candidate):\n assert candidate(ranges = [[1,2],[3,4],[5,6]], left = 2, right = 5) == True\n assert candidate(ranges = [[1,10],[10,20]], left = 21, right = 21) == False\n\n\ncheck(Solution().isCovered)"} | 154 | 85 |
coding | Solve the programming task below in a Python markdown code block.
## Story
Your company migrated the last 20 years of it's *very important data* to a new platform, in multiple phases. However, something went wrong: some of the essential time-stamps were messed up! It looks like that some servers were set to use the `d... | {"functional": "_inputs = [[[]]]\n_outputs = [[[0, 0, 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, tuple)):\n if len(a) != len(b): return False\n return all(_... | 445 | 160 |
coding | Solve the programming task below in a Python markdown code block.
Given is a string S. Let T be the concatenation of K copies of S. We can repeatedly perform the following operation: choose a character in T and replace it with a different character. Find the minimum number of operations required to satisfy the followin... | {"inputs": ["oo\n4", "oo\n7", "rq\n81", "oo\n13", "qq\n81", "rr\n552", "rr\n826", "rr\n757"], "outputs": ["4\n", "7\n", "0\n", "13\n", "81", "552\n", "826\n", "757\n"]} | 208 | 94 |
coding | Solve the programming task below in a Python markdown code block.
Of the real numbers, those with a circular decimal part and those with a finite number of digits can be expressed as fractions.
Given a real number that can be represented by a fraction, write a program that outputs an irreducible fraction equal to t... | {"inputs": ["1.0", "0.(2)", "1.(3)", "1.(2)", "0.(3)", "0.0739", "3.2(145)", "3.3(145)"], "outputs": ["1/1", "2/9\n", "4/3\n", "11/9\n", "1/3", "739/10000", "32113/9990\n", "16556/4995\n"]} | 352 | 124 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given two integers, num and t. A number is achievable if it can become equal to num after applying the following operation:
Increase or decrease the number by 1, and simultaneously increase or decrease num by 1.
Ret... | {"functional": "def check(candidate):\n assert candidate(num = 4, t = 1) == 6\n assert candidate(num = 3, t = 2) == 7\n\n\ncheck(Solution().theMaximumAchievableX)"} | 112 | 56 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Implement a function signFunc(x) that returns:
1 if x is positive.
-1 if x is negative.
0 if x is equal to 0.
You are given an integer array nums. Let product be the product of all values in the array nums.
Return s... | {"functional": "def check(candidate):\n assert candidate(nums = [-1,-2,-3,-4,3,2,1]) == 1\n assert candidate(nums = [1,5,0,2,-3]) == 0\n assert candidate(nums = [-1,1,-1,1,-1]) == -1\n\n\ncheck(Solution().arraySign)"} | 106 | 83 |
coding | Solve the programming task below in a Python markdown code block.
In the 17th century, Fermat wrote that he proved for any integer $n \geq 3$, there exist no positive integers $x$, $y$, $z$ such that $x^n + y^n = z^n$. However he never disclosed the proof. Later, this claim was named Fermat's Last Theorem or Fermat's C... | {"inputs": ["6\n6\n2\n0", "6\n6\n0\n0", "6\n4\n4\n0", "6\n5\n2\n0", "6\n0\n0\n1", "6\n3\n2\n0", "6\n5\n0\n1", "6\n7\n4\n0"], "outputs": ["27\n27\n6\n", "27\n27\n", "27\n10\n10\n", "27\n34\n6\n", "27\n", "27\n11\n6\n", "27\n34\n", "27\n2\n10\n"]} | 555 | 150 |
coding | Solve the programming task below in a Python markdown code block.
Let us begin with an example:
A man has a rather old car being worth $2000.
He saw a secondhand car being worth $8000. He wants to keep his old car until he can buy the secondhand one.
He thinks he can save $1000 each month but the prices of his old
... | {"functional": "_inputs = [[2000, 8000, 1000, 1.5], [8000, 12000, 500, 1], [18000, 32000, 1500, 1.25], [7500, 32000, 300, 1.55]]\n_outputs = [[[6, 766]], [[8, 597]], [[8, 332]], [[25, 122]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a,... | 725 | 275 |
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.
Chef and his friend Chefu decided to go on a trip. The trip takes place over the next $N$ days (numbered 1 through $N$). There are $K$ different plac... | {"inputs": ["5\n5 3\n-1 -1 -1 -1 -1\n4 5\n1 2 3 5\n3 2\n1 -1 2\n4 2\n1 -1 -1 1\n6 4\n-1 -1 4 -1 2 -1"], "outputs": ["YES\n1 2 1 2 1\nYES\n1 2 3 5\nNO\nNO\nYES\n1 2 4 1 2 1"]} | 768 | 116 |
coding | Solve the programming task below in a Python markdown code block.
Given a string of integers, return the number of odd-numbered substrings that can be formed.
For example, in the case of `"1341"`, they are `1, 1, 3, 13, 41, 341, 1341`, a total of `7` numbers.
`solve("1341") = 7`. See test cases for more examples.
... | {"functional": "_inputs = [['1341'], ['1357'], ['13471'], ['134721'], ['1347231'], ['13472315']]\n_outputs = [[7], [10], [12], [13], [20], [28]]\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 isinstan... | 215 | 217 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in mandarin chinese, russian and vietnamese as well.
Though our Head Chef retired from sport programming long back, but that did not affect his passion to contribute to the programming community. He still remains engaged by cre... | {"inputs": ["3 4\n1 2 3"], "outputs": ["5"]} | 350 | 20 |
coding | Solve the programming task below in a Python markdown code block.
Vasiliy is fond of solving different tasks. Today he found one he wasn't able to solve himself, so he asks you to help.
Vasiliy is given n strings consisting of lowercase English letters. He wants them to be sorted in lexicographical order (as in the di... | {"inputs": ["2\n1 2\nba\nac\n", "2\n1 1\naa\naa\n", "2\n1 1\naa\naa\n", "2\n1 1\naa\na`\n", "2\n1 2\nab\nac\n", "2\n2 1\naa\na`\n", "2\n1 2\n`b\nac\n", "2\n2 1\naa\n`a\n"], "outputs": ["1\n", "0\n", "0", "-1\n", "0\n", "-1\n", "0\n", "-1\n"]} | 585 | 137 |
coding | Solve the programming task below in a Python markdown code block.
Omy and Ish were learning the pattern printing. In order to learn they give themselves a task. In this task they are given a string and they have to form a pyramid with the pattern as follows:
RowNumber are one based indexed.
-
If (RowNumber % 3 == 0) t... | {"inputs": ["5\nCODING\n2\n1 C\n2 D"], "outputs": ["1\n1"]} | 410 | 25 |
coding | Solve the programming task below in a Python markdown code block.
A manufacturing project consists of exactly $K$ tasks. The board overviewing the project wants to hire $K$ teams of workers — one for each task. All teams begin working simultaneously.
Obviously, there must be at least one person in each team. For a team... | {"inputs": ["2\n2 3\n2 6"], "outputs": ["4\n5"]} | 527 | 22 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a string word and an array of strings forbidden.
A string is called valid if none of its substrings are present in forbidden.
Return the length of the longest valid substring of the string word.
A substr... | {"functional": "def check(candidate):\n assert candidate(word = \"cbaaaabc\", forbidden = [\"aaa\",\"cb\"]) == 4\n assert candidate(word = \"leetcode\", forbidden = [\"de\",\"le\",\"e\"]) == 4\n\n\ncheck(Solution().longestValidSubstring)"} | 110 | 67 |
coding | Solve the programming task below in a Python markdown code block.
When you divide the successive powers of `10` by `13` you get the following remainders of the integer divisions:
`1, 10, 9, 12, 3, 4`.
Then the whole pattern repeats.
Hence the following method:
Multiply the right most digit of the number with the ... | {"functional": "_inputs = [[8529], [85299258], [5634], [1111111111], [987654321]]\n_outputs = [[79], [31], [57], [71], [30]]\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))... | 413 | 213 |
coding | Solve the programming task below in a Python markdown code block.
Lot of museum allow you to be a member, for a certain amount `amount_by_year` you can have unlimitted acces to the museum.
In this kata you should complete a function in order to know after how many visit it will be better to take an annual pass. The f... | {"functional": "_inputs = [[40, 15], [30, 10], [80, 15]]\n_outputs = [[3], [3], [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 if isinstance(a, (list, tuple)):\n if len(a) != len(b): return F... | 112 | 183 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given two integers n and k, return the kth lexicographically smallest integer in the range [1, n].
Please complete the following python code precisely:
```python
class Solution:
def findKthNumber(self, n: int, k... | {"functional": "def check(candidate):\n assert candidate(n = 13, k = 2) == 10\n assert candidate(n = 1, k = 1) == 1\n\n\ncheck(Solution().findKthNumber)"} | 77 | 57 |
coding | Solve the programming task below in a Python markdown code block.
This kata is all about adding numbers.
You will create a function named add. It will return the sum of all the arguments. Sounds easy, doesn't it?
Well Here's the Twist. The inputs will gradually decrease with their index as parameter to the function.
... | {"functional": "_inputs = [[100, 200, 300], [2], [4, -3, -2], [-1, -2, -3, -4]]\n_outputs = [[300], [2], [2], [-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(a, (list, tuple)):\n ... | 225 | 200 |
coding | Solve the programming task below in a Python markdown code block.
There are three friend living on the straight line Ox in Lineland. The first friend lives at the point x_1, the second friend lives at the point x_2, and the third friend lives at the point x_3. They plan to celebrate the New Year together, so they need ... | {"inputs": ["7 1 4\n", "1 2 3\n", "1 3 2\n", "4 2 6\n", "6 9 3\n", "8 1 9\n", "3 5 4\n", "2 1 3\n"], "outputs": ["6\n", "2\n", "2\n", "4\n", "6\n", "8\n", "2\n", "2\n"]} | 314 | 102 |
coding | Solve the programming task below in a Python markdown code block.
Squirrel Liss lived in a forest peacefully, but unexpected trouble happens. Stones fall from a mountain. Initially Squirrel Liss occupies an interval [0, 1]. Next, n stones will fall and Liss will escape from the stones. The stones are numbered from 1 to... | {"inputs": ["l\n", "r\n", "l\n", "r\n", "llrlr\n", "rrlll\n", "lrlrr\n", "rlrll\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "3\n5\n4\n2\n1\n", "1\n2\n5\n4\n3\n", "2\n4\n5\n3\n1\n", "1\n3\n5\n4\n2\n"]} | 440 | 110 |
coding | Solve the programming task below in a Python markdown code block.
In this exercise, a string is passed to a method and a new string has to be returned with the first character of each word in the string.
For example:
```
"This Is A Test" ==> "TIAT"
```
Also feel free to reuse/extend the following starter code:
```pyt... | {"functional": "_inputs = [['sees eyes xray yoat'], ['brown eyes are nice'], ['cars are very nice'], ['kaks de gan has a big head']]\n_outputs = [['sexy'], ['bean'], ['cavn'], ['kdghabh']]\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... | 81 | 194 |
coding | Solve the programming task below in a Python markdown code block.
You have an array a with length n, you can perform operations. Each operation is like this: choose two adjacent elements from a, say x and y, and replace one of them with gcd(x, y), where gcd denotes the [greatest common divisor](https://en.wikipedia.org... | {"inputs": ["1\n1\n", "1\n3\n", "1\n5\n", "1\n6\n", "1\n8\n", "1\n11\n", "1\n10\n", "2\n1 1\n"], "outputs": ["0\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "0\n"]} | 397 | 90 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a binary string s. You are allowed to perform two types of operations on the string in any sequence:
Type-1: Remove the character at the start of the string s and append it to the end of the string.
Typ... | {"functional": "def check(candidate):\n assert candidate(s = \"111000\") == 2\n assert candidate(s = \"010\") == 0\n assert candidate(s = \"1110\") == 1\n\n\ncheck(Solution().minFlips)"} | 194 | 66 |
coding | Solve the programming task below in a Python markdown code block.
Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it:
* deletes all the vow... | {"inputs": ["g\n", "D\n", "h\n", "Ba\n", "ab\n", "aB\n", "bA\n", "Ab\n"], "outputs": [".g\n", ".d\n", ".h\n", ".b\n", ".b\n", ".b\n", ".b\n", ".b\n"]} | 257 | 73 |
coding | Solve the programming task below in a Python markdown code block.
An array is beautiful if both of the following two conditions meet:
there are at least $l_1$ and at most $r_1$ elements in the array equal to its minimum;
there are at least $l_2$ and at most $r_2$ elements in the array equal to its maximum.
For examp... | {"inputs": ["1\n40 40 40 40\n", "1\n14 17 15 50\n", "7\n3 5 4 6\n5 8 5 5\n3 3 10 12\n1 5 3 3\n1 1 2 2\n2 2 1 1\n6 6 6 6\n"], "outputs": ["40\n", "15\n", "4\n5\n13\n3\n3\n3\n6\n"]} | 649 | 127 |
coding | Solve the programming task below in a Python markdown code block.
Mainak has an array $a_1, a_2, \ldots, a_n$ of $n$ positive integers. He will do the following operation to this array exactly once:
Pick a subsegment of this array and cyclically rotate it by any amount.
Formally, he can do the following exactly once:... | {"inputs": ["1\n2\n1 10\n", "1\n3\n3 2 1\n", "1\n3\n7 3 1\n", "1\n4\n8 2 2 1\n", "1\n3\n100 3 1\n", "1\n3\n999 2 1\n", "1\n3\n999 3 1\n", "1\n3\n999 100 1\n"], "outputs": ["9\n", "1\n", "4\n", "6\n", "97\n", "997\n", "996\n", "899\n"]} | 668 | 152 |
coding | Solve the programming task below in a Python markdown code block.
You are given an array $a$ consisting of $n$ integers. Each $a_i$ is one of the six following numbers: $4, 8, 15, 16, 23, 42$.
Your task is to remove the minimum number of elements to make this array good.
An array of length $k$ is called good if $k$ i... | {"inputs": ["1\n4\n", "1\n4\n", "1\n8\n", "1\n42\n", "1\n42\n", "1\n15\n", "1\n16\n", "1\n23\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | 690 | 91 |
coding | Solve the programming task below in a Python markdown code block.
Problem statement
AOR Ika got a cabbage with $ N $ leaves. The leaves of this cabbage are numbered $ 1, \ ldots, N $ in order from the outside, and the dirtiness of the $ i $ th leaf is $ D_i $. The larger this value is, the worse the degree of dirt is.... | {"inputs": ["5 3 6 9\n9 1 5 3 1", "5 3 6 9\n9 1 6 3 1", "8 3 6 9\n9 1 6 3 1", "2 3 6 9\n9 7 5 3 1", "5 3 6 8\n9 1 5 3 1", "5 3 6 9\n9 7 5 3 1", "9 3 1 9\n22 2 6 2 0", "8 3 6 9\n15 1 6 3 1"], "outputs": ["1\n", "1\n", "1\n", "0\n", "1\n", "2", "4\n", "1\n"]} | 707 | 191 |
coding | Solve the programming task below in a Python markdown code block.
Chef has a sequence $A_1, A_2, \ldots, A_N$. For a positive integer $M$, sequence $B$ is defined as $B = A*M$ that is, appending $A$ exactly $M$ times. For example, If $A = [1, 2]$ and $M = 3$, then $B = A*M = [1, 2, 1, 2, 1, 2]$
You have to help him to ... | {"inputs": ["3\n2\n2 1\n2\n1 2\n5\n1 3 2 1 2"], "outputs": ["2\n1\n2"]} | 458 | 40 |
coding | Solve the programming task below in a Python markdown code block.
Stuart is obsessed to numbers. He like all type of numbers in fact he is having a great collection of numbers in his room. His collection includes N different large numbers. But today he is searching for a number which is having maximum frequency of digi... | {"inputs": ["2\n5\n345 1323 165 98 456\n3\n5\n335 876 98 1323 349\n3"], "outputs": ["1323\n335"]} | 369 | 67 |
coding | Solve the programming task below in a Python markdown code block.
A palindrome is a word that reads the same forward and backward. Given a string s, you need to make it a palindrome by adding 0 or more characters to the end of s, and remember, we want the palindrome to be as short as possible.
INPUT
First line is T, ... | {"inputs": ["6\nabdfhdyrbdbsdfghjkllkjhgfds\nzazazazazazazazazazazazazazazazazazazazazazazazaza\nbacba\na\nadwuaaxcnleegluqvsczaguujoppchwecusmevz\nkoikijiikmmkmonkiinnjlijmiimnniokikimikkkkjkmiinii"], "outputs": ["38\n51\n9\n1\n77\n95"]} | 184 | 120 |
coding | Solve the programming task below in a Python markdown code block.
The "BerCorp" company has got n employees. These employees can use m approved official languages for the formal correspondence. The languages are numbered with integers from 1 to m. For each employee we have the list of languages, which he knows. This li... | {"inputs": ["2 2\n0\n0\n", "3 3\n0\n0\n0\n", "2 2\n1 2\n0\n", "2 2\n1 2\n1 1\n", "3 100\n0\n0\n0\n", "2 3\n1 2\n1 1\n", "3 101\n0\n0\n0\n", "3 001\n0\n0\n0\n"], "outputs": ["2\n", "3\n", "1\n", "1\n", "3\n", "1\n", "3\n", "3\n"]} | 476 | 142 |
coding | Solve the programming task below in a Python markdown code block.
One day n cells of some array decided to play the following game. Initially each cell contains a number which is equal to it's ordinal number (starting from 1). Also each cell determined it's favourite number. On it's move i-th cell can exchange it's val... | {"inputs": ["1\n1\n1\n", "1\n1\n2\n", "2\n2 1\n2 2\n", "2\n2 1\n1 1\n", "2\n1 2\n1 1\n", "2\n1 2\n2 2\n", "2\n2 1\n1 2\n", "4\n1 2 3 4\n1 1 1 1\n"], "outputs": ["YES\n", "YES\n", "NO\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n"]} | 333 | 134 |
coding | Solve the programming task below in a Python markdown code block.
You are given nonnegative integers a and b (a ≤ b), and a positive integer x.
Among the integers between a and b, inclusive, how many are divisible by x?
-----Constraints-----
- 0 ≤ a ≤ b ≤ 10^{18}
- 1 ≤ x ≤ 10^{18}
-----Input-----
The input is given... | {"inputs": ["0 5 2", "0 2 2", "0 2 4", "9 7 2", "1 3 4", "4 8 2", "9 9 2", "0 5 1"], "outputs": ["3\n", "2\n", "1\n", "-1\n", "0\n", "3", "0", "6"]} | 167 | 91 |
coding | Solve the programming task below in a Python markdown code block.
A hero is on his way to the castle to complete his mission. However, he's been told that the castle is surrounded with a couple of powerful dragons! each dragon takes 2 bullets to be defeated, our hero has no idea how many bullets he should carry.. Assum... | {"functional": "_inputs = [[10, 5], [7, 4], [4, 5], [100, 40], [1500, 751], [0, 1]]\n_outputs = [[True], [False], [False], [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 isin... | 125 | 210 |
coding | Solve the programming task below in a Python markdown code block.
Given an integer $n$, find the maximum value of integer $k$ such that the following condition holds:
$n$ & ($n-1$) & ($n-2$) & ($n-3$) & ... ($k$) = $0$
where & denotes the bitwise AND operation.
-----Input-----
The first line contains a single integ... | {"inputs": ["1\n6\n", "1\n2\n", "1\n7\n", "1\n90\n", "1\n16\n", "1\n52\n", "1\n70\n", "1\n82\n"], "outputs": ["3\n", "1\n", "3\n", "63\n", "15\n", "31\n", "63\n", "63\n"]} | 306 | 96 |
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 you can swap two letters in s so the result is equal to goal, otherwise, return false.
Swapping letters is defined as taking two indices i and j (0-indexed) such that i != ... | {"functional": "def check(candidate):\n assert candidate(s = \"ab\", goal = \"ba\") == True\n assert candidate(s = \"ab\", goal = \"ab\") == False\n assert candidate(s = \"aa\", goal = \"aa\") == True\n\n\ncheck(Solution().buddyStrings)"} | 136 | 68 |
coding | Solve the programming task below in a Python markdown code block.
Example
Input
4
Durett 7
Gayles 3
Facenda 6
Daughtery 0
1
+ Mccourtney 2
Output
Mccourtney is not working now.
Durett is working hard now. | {"inputs": ["4\nDurett 7\nGayles 3\nFacenda 6\nyrethguaD 0\n1\n+ Mccourtney 2", "4\nDurett 7\nGayles 3\nFacenda 6\nDaughtery 0\n1\n+ yentruoccM 3", "4\nDurett 7\nGaylds 3\nFbccnda 2\nyrethguaD 0\n1\n+ yeotruoccM 2", "4\nDurett 7\nGaylds 3\nFbccnda 2\nyrdthguaD 0\n1\n+ yeMtruocco 2", "4\nDurett 7\nGaylds 3\nFbccnda 2\ny... | 70 | 474 |
coding | Solve the programming task below in a Python markdown code block.
How many days are we represented in a foreign country?
My colleagues make business trips to a foreign country. We must find the number of days our company is represented in a country. Every day that one or more colleagues are present in the country is a... | {"functional": "_inputs = [[[[10, 15], [25, 35]]], [[[2, 8], [220, 229], [10, 16]]]]\n_outputs = [[17], [24]]\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 l... | 244 | 201 |
coding | Solve the programming task below in a Python markdown code block.
You have an N \times M grid consisting of N rows numbered 1 to N from top to bottom and M columns numbered 1 to M from left to right. Each cell of the grid is initially white.
You can perform the following operation any number of times (possibly zero):
... | {"inputs": ["2\n3 5 13\n3627 17424 27008005"], "outputs": ["YES\nNO"]} | 454 | 41 |
coding | Solve the programming task below in a Python markdown code block.
You are given a multiset $S$ initially consisting of $n$ distinct non-negative integers. A multiset is a set, that can contain some elements multiple times.
You will perform the following operation $k$ times:
Add the element $\lceil\frac{a+b}{2}\rceil$... | {"inputs": ["1\n1 0\n0\n", "1\n1 0\n0\n", "1\n1 0\n1\n", "1\n1 1\n4\n", "1\n1 0\n2\n", "1\n1 1\n1\n", "1\n1 2\n4\n", "1\n1 0\n4\n"], "outputs": ["1\n", "1\n", "1\n", "2\n", "1\n", "1\n", "2\n", "1\n"]} | 700 | 118 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a m x n binary matrix mat, find the 0-indexed position of the row that contains the maximum count of ones, and the number of ones in that row.
In case there are multiple rows that have the maximum count of ones,... | {"functional": "def check(candidate):\n assert candidate(mat = [[0,1],[1,0]]) == [0,1]\n assert candidate(mat = [[0,0,0],[0,1,1]]) == [1,2]\n assert candidate(mat = [[0,0],[1,1],[0,0]]) == [1,2]\n\n\ncheck(Solution().rowAndMaximumOnes)"} | 132 | 93 |
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. In one operation, you can:
Choose two different indices i and j such that 0 <= i, j < nums.length.
Choose a non-negative integer k such that the kth bit (0-indexed) in th... | {"functional": "def check(candidate):\n assert candidate(nums = [4,3,1,2,4]) == 2\n assert candidate(nums = [1,10,4]) == 0\n\n\ncheck(Solution().beautifulSubarrays)"} | 189 | 57 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given the root of a binary tree, invert the tree, and return its root.
Please complete the following python code precisely:
```python
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, v... | {"functional": "def check(candidate):\n assert is_same_tree(candidate(root = tree_node([4,2,7,1,3,6,9])), tree_node([4,7,2,9,6,3,1]))\n assert is_same_tree(candidate(root = tree_node([2,1,3])), tree_node([2,3,1]))\n assert is_same_tree(candidate(root = tree_node([])), tree_node([]))\n\n\ncheck(Solution().inver... | 119 | 109 |
coding | Solve the programming task below in a Python markdown code block.
In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams.
After pr... | {"inputs": ["1 3 2 1 2 1\n", "0 0 0 0 0 0\n", "4 4 4 4 5 4\n", "2 2 2 2 2 1\n", "1 1 1 1 1 5\n", "8 1 1 3 3 0\n", "1 1 2 2 3 3\n", "1 2 2 5 2 5\n"], "outputs": ["YES\n", "YES\n", "NO\n", "NO\n", "NO\n", "NO\n", "YES\n", "NO\n"]} | 340 | 150 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer array gifts denoting the number of gifts in various piles. Every second, you do the following:
Choose the pile with the maximum number of gifts.
If there is more than one pile with the maximu... | {"functional": "def check(candidate):\n assert candidate(gifts = [25,64,9,4,100], k = 4) == 29\n assert candidate(gifts = [1,1,1,1], k = 4) == 4\n\n\ncheck(Solution().pickGifts)"} | 139 | 77 |
coding | Solve the programming task below in a Python markdown code block.
There are $N$ friends in a group. Each of them have $A_{i}$ candies.
Can they share all of these candies among themselves such that each one of them have equal no. of candies.
-----Input:-----
- First line will contain $T$, number of testcases. Then the... | {"inputs": ["1\n3\n1 2 3"], "outputs": ["Yes"]} | 259 | 20 |
coding | Solve the programming task below in a Python markdown code block.
Chef is throwing a party for his N friends. There is a pizza store nearby and he wants to buy pizza for his friends. Each pizza has exactly K slices. Chef's friends get sad if one gets more slices than the other. Also, Chef gets sad if there are some piz... | {"inputs": ["3\n2 2\n2 3\n4 2\n"], "outputs": ["1\n2\n2\n"]} | 552 | 30 |
coding | Solve the programming task below in a Python markdown code block.
You are given a string $s$, consisting only of characters '0' and '1'.
You have to choose a contiguous substring of $s$ and remove all occurrences of the character, which is a strict minority in it, from the substring.
That is, if the amount of '0's in... | {"inputs": ["1\n00000000000000\n", "4\n01\n1010101010111\n00110001000\n1\n", "1\n00000000000000000011111111111111111111\n", "1\n1101010101111010110101010101001010111010\n", "1\n10101010101010101010101010101001010101010101010101010101010101010101010000\n", "1\n101010101010101010101010101010010101010101010101010101010101... | 577 | 341 |
coding | Solve the programming task below in a Python markdown code block.
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya calls a mask of a positive... | {"inputs": ["1 4\n", "4 4\n", "7 7\n", "7 4\n", "4 7\n", "0 7\n", "1 7\n", "44 4\n"], "outputs": ["4\n", "14\n", "17\n", "14\n", "7\n", "7\n", "7\n", "45\n"]} | 289 | 91 |
coding | Solve the programming task below in a Python markdown code block.
.difference()
The tool .difference() returns a set with all the elements from the set that are not in an iterable.
Sometimes the - operator is used in place of the .difference() tool, but it only operates on the set of elements in set.
Set is immuta... | {"inputs": ["9\n1 2 3 4 5 6 7 8 9\n9\n10 1 2 3 11 21 55 6 8\n"], "outputs": ["4\n"]} | 567 | 56 |
coding | Solve the programming task below in a Python markdown code block.
Imagine that you have an array of 3 integers each representing a different person. Each number can be 0, 1, or 2 which represents the number of hands that person holds up.
Now imagine there is a sequence which follows these rules:
* None of the people h... | {"functional": "_inputs = [[54], [98], [3]]\n_outputs = [[[0, 0, 0]], [[2, 2, 1]], [[0, 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, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b... | 340 | 186 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
There is a row of m houses in a small city, each house must be painted with one of the n colors (labeled from 1 to n), some houses that have been painted last summer should not be painted again.
A neighborhood is a ma... | {"functional": "def check(candidate):\n assert candidate(houses = [0,0,0,0,0], cost = [[1,10],[10,1],[10,1],[1,10],[5,1]], m = 5, n = 2, target = 3) == 9\n assert candidate(houses = [0,2,1,2,0], cost = [[1,10],[10,1],[10,1],[1,10],[5,1]], m = 5, n = 2, target = 3) == 11\n assert candidate(houses = [0,0,0,0,0],... | 268 | 271 |
coding | Solve the programming task below in a Python markdown code block.
You are given an integer $N$ followed by $N$ email addresses. Your task is to print a list containing only valid email addresses in lexicographical order.
Valid email addresses must follow these rules:
It must have the username@websitename.extension fo... | {"inputs": ["3\nlara@hackerrank.com\nbrian-23@hackerrank.com\nbritts_54@hackerrank.com\n"], "outputs": ["['brian-23@hackerrank.com', 'britts_54@hackerrank.com', 'lara@hackerrank.com']\n"]} | 451 | 77 |
coding | Solve the programming task below in a Python markdown code block.
Chef has a stick of length L. Chef wants to break the stick into K parts such that each part has a non-zero length.
Let the lengths of the K parts be A_{1}, A_{2}, \ldots, A_{K} (Note that A_{1} + A_{2} + \ldots + A_{K} = L and A_{i} is a positive inte... | {"inputs": ["2\n4 3\n2 2\n"], "outputs": ["1\n0\n"]} | 516 | 24 |
coding | Solve the programming task below in a Python markdown code block.
You are given a string S of length N.
You can apply the following operation on the string any number of times:
Choose an index i (1≤ i < N), and swap S_{i} with S_{i+1}, if S_{i} and S_{i+1} contain adjacent characters.
For example, a and b are adjace... | {"inputs": ["2\n5\ncbaba\n6\ndbbced"], "outputs": ["bbcaa\ncdbbde"]} | 619 | 30 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given the root of a binary search tree and an array queries of size n consisting of positive integers.
Find a 2D array answer of size n where answer[i] = [mini, maxi]:
mini is the largest value in the tree th... | {"functional": "def check(candidate):\n assert candidate(root = tree_node([6,2,13,1,4,9,15,None,None,None,None,None,None,14]), queries = [2,5,16]) == [[2,2],[4,6],[15,-1]]\n assert candidate(root = tree_node([4,None,9]), queries = [3]) == [[-1,4]]\n\n\ncheck(Solution().closestNodes)"} | 217 | 106 |
coding | Solve the programming task below in a Python markdown code block.
Polycarp decided to relax on his weekend and visited to the performance of famous ropewalkers: Agafon, Boniface and Konrad.
The rope is straight and infinite in both directions. At the beginning of the performance, Agafon, Boniface and Konrad are locate... | {"inputs": ["5 2 6 3\n", "3 1 5 6\n", "8 3 3 2\n", "1 3 2 5\n", "2 3 1 6\n", "9 6 2 5\n", "1 1 1 1\n", "1 2 1 1\n"], "outputs": ["2\n", "8\n", "2\n", "8\n", "10\n", "3\n", "2\n", "1\n"]} | 572 | 119 |
coding | Solve the programming task below in a Python markdown code block.
In this challenge, the task is to debug the existing code to successfully execute all provided test files.
Given two strings consisting of digits 0 and 1 only, find the XOR of the two strings.
To know more about XOR Click Here
Debug the given function... | {"inputs": ["10101\n00101\n"], "outputs": ["10000\n"]} | 322 | 28 |
coding | Solve the programming task below in a Python markdown code block.
Vasya is preparing a contest, and now he has written a statement for an easy problem. The statement is a string of length $n$ consisting of lowercase Latin latters. Vasya thinks that the statement can be considered hard if it contains a subsequence hard;... | {"inputs": ["3\nxdd\n1 2 3\n", "3\nxdd\n1 2 3\n", "3\nxdd\n2 2 3\n", "3\nxdd\n2 3 3\n", "3\nxdd\n1 3 3\n", "3\nxdd\n1 4 3\n", "3\nxdd\n1 8 3\n", "3\nxdd\n1 8 4\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | 559 | 134 |
coding | Solve the programming task below in a Python markdown code block.
Consider the array `[3,6,9,12]`. If we generate all the combinations with repetition that sum to `12`, we get `5` combinations: `[12], [6,6], [3,9], [3,3,6], [3,3,3,3]`. The length of the sub-arrays (such as `[3,3,3,3]` should be less than or equal to th... | {"functional": "_inputs = [[[1, 2, 3], 10], [[1, 2, 3], 7], [[1, 2, 3], 5], [[3, 6, 9, 12], 12], [[1, 4, 5, 8], 8], [[3, 6, 9, 12], 15], [[3, 6, 9, 12, 14, 18], 30]]\n_outputs = [[0], [2], [3], [5], [3], [5], [21]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n ... | 298 | 280 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a string s and an array of strings words, return the number of words[i] that is a subsequence of s.
A subsequence of a string is a new string generated from the original string with some characters (can be none)... | {"functional": "def check(candidate):\n assert candidate(s = \"abcde\", words = [\"a\",\"bb\",\"acd\",\"ace\"]) == 3\n assert candidate(s = \"dsahjpjauf\", words = [\"ahjpjau\",\"ja\",\"ahbwzgqnuk\",\"tnmlanowax\"]) == 2\n\n\ncheck(Solution().numMatchingSubseq)"} | 129 | 88 |
coding | Solve the programming task below in a Python markdown code block.
You are the top spy of AtCoder Kingdom. To prevent the stolen secret from being handed to AlDebaran Kingdom, you have sneaked into the party where the transaction happens.
There are N attendees in the party, and they are given attendee numbers from 1 thr... | {"inputs": ["6\n2 3 6 1 3 1", "6\n5 2 2 2 8 8", "6\n2 5 3 1 3 1", "6\n3 6 3 1 6 1", "6\n2 6 6 1 3 1", "6\n2 5 3 2 3 1", "6\n2 6 3 1 3 1", "6\n2 5 3 2 3 2"], "outputs": ["3\n", "0\n", "2\n", "1\n", "2\n", "0\n", "2\n", "0\n"]} | 383 | 158 |
coding | Solve the programming task below in a Python markdown code block.
On his trip to Luxor and Aswan, Sagheer went to a Nubian market to buy some souvenirs for his friends and relatives. The market has some strange rules. It contains n different items numbered from 1 to n. The i-th item has base cost a_{i} Egyptian pounds.... | {"inputs": ["1 7\n7\n", "1 7\n5\n", "1 1\n1\n", "1 1\n1\n", "1 7\n5\n", "1 7\n9\n", "1 3\n9\n", "1 7\n7\n"], "outputs": ["0 0\n", "1 6\n", "0 0\n", "0 0", "1 6", "0 0\n", "0 0\n", "0 0"]} | 550 | 115 |
coding | Solve the programming task below in a Python markdown code block.
Snuke is visiting a shop in Tokyo called 109 to buy some logs.
He wants n logs: one of length 1, one of length 2, ..., and one of length n.
The shop has n+1 logs in stock: one of length 1, one of length 2, \dots, and one of length n+1. Each of these logs... | {"inputs": ["4\n", "1\n", "2\n", "3\n", "5\n", "11200\n", "39435\n", "812742\n"], "outputs": ["3\n", "1\n", "1\n", "2\n", "3\n", "11052\n", "39156\n", "811469\n"]} | 337 | 96 |
coding | Solve the programming task below in a Python markdown code block.
Takahashi has a tower which is divided into N layers. Initially, all the layers are uncolored. Takahashi is going to paint some of the layers in red, green or blue to make a beautiful tower. He defines the beauty of the tower as follows:
* The beauty of... | {"inputs": ["2 5 6 1", "2 9 7 0", "4 1 3 5", "4 1 1 5", "4 1 1 7", "1 2 2 2", "6 1 1 7", "4 2 2 5"], "outputs": ["0\n", "1\n", "24\n", "56\n", "8\n", "2\n", "792\n", "0\n"]} | 414 | 114 |
coding | Solve the programming task below in a Python markdown code block.
By 2312 there were n Large Hadron Colliders in the inhabited part of the universe. Each of them corresponded to a single natural number from 1 to n. However, scientists did not know what activating several colliders simultaneously could cause, so the col... | {"inputs": ["100 1\n+ 51\n", "100 1\n+ 94\n", "100 1\n+ 68\n", "4 2\n+ 2\n+ 4\n", "100000 1\n+ 7528\n", "100000 1\n+ 8355\n", "100001 1\n+ 7528\n", "100000 1\n+ 2505\n"], "outputs": ["Success\n", "Success\n", "Success\n", "Success\nConflict with 2\n", "Success\n", "Success\n", "Success\n", "Success\n"]} | 743 | 168 |
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.
Chef has a sequence of integers $A_{1}, A_{2}, \ldots, A_{N}$. He takes a sheet of paper and for each non-empty subsequence $B$ of this sequence, he ... | {"inputs": ["3\n3\n2 2 3\n2\n1 2\n3\n1 2 2"], "outputs": ["0 6 1\n2 1\n3 4 0"]} | 678 | 48 |
coding | Solve the programming task below in a Python markdown code block.
You are given n patterns p_1, p_2, ..., p_n and m strings s_1, s_2, ..., s_m. Each pattern p_i consists of k characters that are either lowercase Latin letters or wildcard characters (denoted by underscores). All patterns are pairwise distinct. Each stri... | {"inputs": ["2 1 1\ns\nb\nb 1\n", "2 1 1\ns\na\nb 1\n", "2 1 1\ns\nb\nc 1\n", "2 1 1\ns\na\nb 2\n", "2 1 1\nt\na\nb 1\n", "1 1 3\n__d\ncba 1\n", "1 1 3\n_c_\ncba 1\n", "1 1 3\n__c\ncba 1\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "\nNO\n"]} | 674 | 166 |
coding | Solve the programming task below in a Python markdown code block.
A tuple of positive integers (a, b, c) is said to be a *bad tuple* if a, b, c are distinct, a divides b, and b divides c. For example, (1, 2, 4) and (7, 21, 42) are bad tuples while (1, 2, 3) and (2, 4, 4) are not.
Chef has the N integers from 1 to N wi... | {"inputs": ["2\n", "4\n"], "outputs": ["4\n", "14\n"]} | 371 | 23 |
coding | Solve the programming task below in a Python markdown code block.
The prison of your city has n prisoners. As the prison can't accommodate all of them, the city mayor has decided to transfer c of the prisoners to a prison located in another city.
For this reason, he made the n prisoners to stand in a line, with a numb... | {"inputs": ["1 1 1\n2\n", "1 0 1\n2\n", "1 1 1\n2\n", "1 -1 1\n2\n", "1 -2 1\n2\n", "1 228 1\n1\n", "1 228 1\n1\n", "1 230 1\n1\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "1\n", "1\n", "1\n"]} | 391 | 124 |
coding | Solve the programming task below in a Python markdown code block.
Polycarpus has n markers and m marker caps. Each marker is described by two numbers: xi is the color and yi is the diameter. Correspondingly, each cap is described by two numbers: aj is the color and bj is the diameter. Cap (aj, bj) can close marker (xi,... | {"inputs": ["1 1\n1 1\n1 1\n", "1 1\n1 1\n2 2\n", "1 1\n1 1\n1 2\n", "1 1\n1 2\n2 2\n", "1 1\n2 1\n1 2\n", "1 1\n1 2\n1 2\n", "1 1\n0 1\n1 2\n", "1 1\n0 1\n2 2\n"], "outputs": ["1 1\n", "0 0\n", "0 0\n", "1 0\n", "0 0\n", "1 1\n", "0 0\n", "0 0\n"]} | 491 | 166 |
coding | Solve the programming task below in a Python markdown code block.
In telecomunications we use information coding to detect and prevent errors while sending data.
A parity bit is a bit added to a string of binary code that indicates whether the number of 1-bits in the string is even or odd. Parity bits are used as the... | {"functional": "_inputs = [['01011001'], ['00110001'], ['11111111'], ['00000000'], ['11100111'], ['00111100 00111101'], ['00001111 11100001'], ['01011110 00011000'], ['11111111 11011100 11100011'], ['00111110 00110100 00111011'], ['01101110 01100000 01010110 10001111 01100011'], ['10100011 00111001 11001100 01010100 10... | 463 | 569 |
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.
Bitsetbaba Ashiq works in a power grid, which consists of $2^{K}$ power stations (numbered $0$ through $2^{K}-1$). Initially, there are no connection... | {"inputs": ["2\n2 1\n0\n2 1\n2"], "outputs": ["4\n2"]} | 574 | 26 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given two integer arrays arr1 and arr2, and the integer d, return the distance value between the two arrays.
The distance value is defined as the number of elements arr1[i] such that there is not any element arr2[j] w... | {"functional": "def check(candidate):\n assert candidate(arr1 = [4,5,8], arr2 = [10,9,1,8], d = 2) == 2\n assert candidate(arr1 = [1,4,2,3], arr2 = [-4,-3,6,10,20,30], d = 3) == 2\n assert candidate(arr1 = [2,1,100,3], arr2 = [-5,-2,10,-3,7], d = 6) == 1\n\n\ncheck(Solution().findTheDistanceValue)"} | 123 | 140 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array of integers citations where citations[i] is the number of citations a researcher received for their ith paper, return the researcher's h-index.
According to the definition of h-index on Wikipedia: The h... | {"functional": "def check(candidate):\n assert candidate(citations = [3,0,6,1,5]) == 3 \n assert candidate(citations = [1,3,1]) == 1\n\n\ncheck(Solution().hIndex)"} | 120 | 58 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.