problem stringlengths 14 4.09k | solution stringlengths 1 802k | task_type stringclasses 3
values | problem_tokens int64 5 895 |
|---|---|---|---|
Solve the programming task below in a Python markdown code block.
Chef is very organised in whatever he does and likes to maintain statistics of his work. Chef has expertise in web development and hence is a regular contributor on a forum. Chef sometimes makes multiple contributions in a single day.. Each day chef make... | {"inputs": ["1\n7\n20 6 5 3 3 1 1"], "outputs": ["1: 2\n3: 2\n5: 1\n6: 1\n20: 1"]} | coding | 310 |
Solve the programming task below in a Python markdown code block.
Recently, the Fair Nut has written k strings of length n, consisting of letters "a" and "b". He calculated c — the number of strings that are prefixes of at least one of the written strings. Every string was counted only one time.
Then, he lost his shee... | {"inputs": ["1 1\na\na\n", "1 2\na\na\n", "1 2\na\nb\n", "2 4\naa\nab\n", "2 4\naa\nbb\n", "3 3\naba\nabb\n", "3 3\naba\nbba\n", "4 5\nabbb\nbbaa\n"], "outputs": ["1\n", "1\n", "2\n", "3\n", "6\n", "4\n", "8\n", "14\n"]} | coding | 444 |
Solve the programming task below in a Python markdown code block.
You are walking through a parkway near your house. The parkway has $n+1$ benches in a row numbered from $1$ to $n+1$ from left to right. The distance between the bench $i$ and $i+1$ is $a_i$ meters.
Initially, you have $m$ units of energy. To walk $1$ m... | {"inputs": ["1\n1 1\n3\n", "1\n1 1\n2\n", "1\n1 1\n69\n", "1\n2 1\n99 99\n", "1\n5 3\n1 91 99 80 5\n", "1\n5 100\n1 99 99 80 5\n", "1\n5 100\n1 91 99 80 5\n", "3\n3 1\n1 2 1\n4 5\n3 3 5 2\n5 16\n1 2 3 4 5\n"], "outputs": ["2\n", "1\n", "68\n", "197\n", "273\n", "184\n", "176\n", "3\n8\n0\n"]} | coding | 583 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
There are n uniquely-sized sticks whose lengths are integers from 1 to n. You want to arrange the sticks such that exactly k sticks are visible from the left. A stick is visible from the left if there are no longer st... | {"functional": "def check(candidate):\n assert candidate(n = 3, k = 2) == 3\n assert candidate(n = 5, k = 5) == 1\n assert candidate(n = 20, k = 11) == 647427950\n\n\ncheck(Solution().rearrangeSticks)"} | coding | 177 |
Solve the programming task below in a Python markdown code block.
There is a collection of rocks where each rock has various minerals embeded in it. Each type of mineral is designated by a lowercase letter in the range $a s c i i[a-z]$. There may be multiple occurrences of a mineral in a rock. A mineral is called a ge... | {"inputs": ["3 \nabcdde \nbaccd\neeabg\n"], "outputs": ["2\n"]} | coding | 391 |
Solve the programming task below in a Python markdown code block.
#Bubbleing around
Since everybody hates chaos and loves sorted lists we should implement some more sorting algorithms. Your task is to implement a Bubble sort (for some help look at https://en.wikipedia.org/wiki/Bubble_sort) and return a list of snapsho... | {"functional": "_inputs = [[[]], [[1, 2, 3, 4, 5, 6, 7, 8, 9]], [[1, 3, 3, 7, 4, 2]]]\n_outputs = [[[]], [[]], [[[1, 3, 3, 4, 7, 2], [1, 3, 3, 4, 2, 7], [1, 3, 3, 2, 4, 7], [1, 3, 2, 3, 4, 7], [1, 2, 3, 3, 4, 7]]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n ... | coding | 220 |
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,... | coding | 295 |
Solve the programming task below in a Python markdown code block.
There are N numbers written on a blackboard.
In one operation, Chef can:
Choose any 3 integers A, B, and C written on the blackboard.
Erase them from the blackboard.
Write A \oplus B, B \oplus C, and C \oplus A on the blackboard. Here, \oplus denotes ... | {"inputs": ["1\n6\n0 1 2 3 2 0"], "outputs": ["2\n2 3 2\n1 1 1\n"]} | coding | 584 |
Solve the programming task below in a Python markdown code block.
> When no more interesting kata can be resolved, I just choose to create the new kata, to solve their own, to enjoy the process --myjinxin2015 said
# Description:
In this Kata, we have to try to create a mysterious pattern.
Given a positive integer `... | {"functional": "_inputs = [[5, 5], [12, 4], [4, 5], [10, 1]]\n_outputs = [[' o\\noo\\n o\\n o'], [' o o\\noo o oo o\\n o o\\n o o'], ['oo\\n o\\n o'], ['oooooooooo']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.iscl... | coding | 518 |
Solve the programming task below in a Python markdown code block.
Write a program that reads numbers until -1 is not given.
The program finds how many of the given numbers are more than 30, $N$.
It also finds the average weighted sum of even numbers, $A$.
The weight of the $i$th number is defined as the position of the... | {"inputs": ["1\n33 100 77 42 12 -1"], "outputs": ["4 38.91"]} | coding | 384 |
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese here
Read problems statements in Russian here
------ Problem Statement ------
One day Chef is waiting his girlfriend on the bus station. The girlfriend said that she will be at time_{1}. Chef went to the ... | {"inputs": ["3\n10:00\n09:00\n6\n10:00\n09:00\n48\n10:00\n09:00\n60", "3\n10:00\n09:00\n6\n10:00\n09:00\n56\n10:00\n09:00\n60", "3\n10:00\n09:00\n6\n10:00\n09:00\n56\n10:00\n09:00\n54", "3\n10:01\n09:00\n7\n10:00\n09:00\n48\n10:00\n09:00\n60", "3\n10:00\n09:00\n8\n10:00\n08:00\n48\n10:00\n09:00\n60", "3\n10:01\n09:00\n... | coding | 564 |
Solve the programming task below in a Python markdown code block.
You are given a string $s$ consisting of $n$ characters. Each character of $s$ is either 0 or 1.
A substring of $s$ is a contiguous subsequence of its characters.
You have to choose two substrings of $s$ (possibly intersecting, possibly the same, possi... | {"inputs": ["4\n0000\n", "5\n11010\n", "5\n10110\n", "5\n10111\n", "5\n11011\n", "5\n11000\n", "5\n10000\n", "5\n10110\n"], "outputs": ["0\n", "11111\n", "11111\n", "11111\n", "11111\n", "11110\n", "11000\n", "11111\n"]} | coding | 586 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two string arrays positive_feedback and negative_feedback, containing the words denoting positive and negative feedback, respectively. Note that no word is both positive and negative.
Initially every stu... | {"functional": "def check(candidate):\n assert candidate(positive_feedback = [\"smart\",\"brilliant\",\"studious\"], negative_feedback = [\"not\"], report = [\"this student is studious\",\"the student is smart\"], student_id = [1,2], k = 2) == [1,2]\n assert candidate(positive_feedback = [\"smart\",\"brilliant\",... | coding | 240 |
Solve the programming task below in a Python markdown code block.
Little Petya loves inequations. Help him find n positive integers a1, a2, ..., an, such that the following two conditions are satisfied:
* a12 + a22 + ... + an2 ≥ x
* a1 + a2 + ... + an ≤ y
Input
The first line contains three space-separated integ... | {"inputs": ["1 1 1\n", "5 1 4\n", "2 1 1\n", "1 1 2\n", "1 1 4\n", "5 0 4\n", "2 6 2\n", "2 3 2\n"], "outputs": ["1\n", "-1\n", "-1\n", "2\n", "4\n", "-1\n", "-1\n", "-1\n"]} | coding | 255 |
Solve the programming task below in a Python markdown code block.
The bear decided to store some raspberry for the winter. He cunningly found out the price for a barrel of honey in kilos of raspberry for each of the following n days. According to the bear's data, on the i-th (1 ≤ i ≤ n) day, the price for one barrel of... | {"inputs": ["2 0\n2 1\n", "2 5\n5 4\n", "2 0\n2 1\n", "2 5\n5 4\n", "2 2\n7 0\n", "2 5\n5 5\n", "2 5\n7 5\n", "2 2\n7 5\n"], "outputs": ["1\n", "0\n", "1\n", "0\n", "5\n", "0\n", "0\n", "0\n"]} | coding | 609 |
Solve the programming task below in a Python markdown code block.
Gag
Segtree has $ N $ of "gags", each with a value of $ V_i $.
Segtree decided to publish all the gags in any order.
Here, the "joy" you get when you publish the $ i $ th gag to the $ j $ th is expressed as $ V_i --j $.
Find the maximum sum of the "j... | {"inputs": ["1\n2", "1\n1", "1\n4", "1\n6", "1\n7", "1\n9", "1\n3", "1\n8"], "outputs": ["1\n", "0\n", "3\n", "5\n", "6\n", "8\n", "2\n", "7\n"]} | coding | 282 |
Solve the programming task below in a Python markdown code block.
Ivan has $n$ songs on his phone. The size of the $i$-th song is $a_i$ bytes. Ivan also has a flash drive which can hold at most $m$ bytes in total. Initially, his flash drive is empty.
Ivan wants to copy all $n$ songs to the flash drive. He can compress... | {"inputs": ["1 1\n2 1\n", "1 1\n3 2\n", "1 3\n2 1\n", "1 2\n3 1\n", "1 2\n3 1\n", "1 3\n2 1\n", "1 1\n3 2\n", "1 1\n2 1\n"], "outputs": ["1\n", "-1\n", "0\n", "1\n", "1\n", "0\n", "-1\n", "1\n"]} | coding | 692 |
Solve the programming task below in a Python markdown code block.
Squid loves painting vertices in graphs.
There is a simple undirected graph consisting of N vertices numbered 1 through N, and M edges. Initially, all the vertices are painted in color 0. The i-th edge bidirectionally connects two vertices a_i and b_i. ... | {"inputs": ["7 7\n1 2\n1 3\n1 4\n4 5\n5 6\n5 7\n2 3\n2\n6 0 1\n1 2 2", "7 7\n1 2\n1 3\n1 4\n4 5\n5 3\n5 7\n2 3\n2\n6 0 1\n1 2 1", "7 7\n1 2\n1 3\n1 4\n4 6\n5 6\n5 7\n2 3\n2\n6 0 1\n1 2 2", "7 7\n1 2\n1 3\n1 3\n4 5\n5 3\n5 7\n2 3\n2\n6 0 1\n1 2 1", "7 7\n1 1\n2 3\n1 4\n4 5\n5 5\n5 7\n2 3\n2\n6 1 1\n1 2 2", "7 7\n1 2\n1 ... | coding | 499 |
Solve the programming task below in a Python markdown code block.
Given the triangle of consecutive odd numbers:
```
1
3 5
7 9 11
13 15 17 19
21 23 25 27 29
...
```
Calculate the row sums of this triangle from the row index (starting at index 1) e.g.:
... | {"functional": "_inputs = [[1], [2], [13], [19], [41], [42], [74], [86], [93], [101]]\n_outputs = [[1], [8], [2197], [6859], [68921], [74088], [405224], [636056], [804357], [1030301]]\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... | coding | 174 |
Solve the programming task below in a Python markdown code block.
You've got an undirected graph, consisting of n vertices and m edges. We will consider the graph's vertices numbered with integers from 1 to n. Each vertex of the graph has a color. The color of the i-th vertex is an integer c_{i}.
Let's consider all ve... | {"inputs": ["3 1\n2 13 4\n1 2\n", "3 1\n13 13 4\n1 2\n", "2 1\n500 300\n1 2\n", "3 1\n13 13 4\n1 2\n", "2 1\n500 300\n1 2\n", "6 1\n10 1 1 2 3 4\n2 3\n", "6 1\n10 1 1 2 3 4\n2 3\n", "6 1\n10 1 2 2 3 4\n2 3\n"], "outputs": ["2\n", "4\n", "300\n", "4", "300", "1\n", "1", "1\n"]} | coding | 551 |
Solve the programming task below in a Python markdown code block.
You are given a binary string A of length N.
You can perform the following type of operation on the string A:
Choose two different indices i and j (1≤ i,j≤ N);
Change A_{i} and A_{j} to A_{i} \oplus A_{j}. Here \oplus represents the [bitwise XOR] operat... | {"inputs": ["4\n5\n11011\n7\n0111010\n1\n1\n4\n1100"], "outputs": ["0\n1\n0\n1"]} | coding | 619 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed string s consisting of only lowercase English letters, and an integer count. A substring of s is said to be an equal count substring if, for each unique letter in the substring, it appears ex... | {"functional": "def check(candidate):\n assert candidate(s = \"aaabcbbcc\", count = 3) == 3\n assert candidate(s = \"abcd\", count = 2) == 0\n assert candidate(s = \"a\", count = 5) == 0\n\n\ncheck(Solution().equalCountSubstrings)"} | coding | 131 |
Solve the programming task below in a Python markdown code block.
Kate and Michael want to buy a pizza and share it. Depending on the price of the pizza, they are going to divide the costs:
* If the pizza is less than €5,- Michael invites Kate, so Michael pays the full price.
* Otherwise Kate will contribute 1/3 of th... | {"functional": "_inputs = [[15], [4], [4.99], [5], [30], [80], [22], [5.9181], [28.789], [4.325]]\n_outputs = [[10], [4], [4.99], [3.33], [20], [70], [14.67], [3.95], [19.19], [4.33]]\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... | coding | 134 |
Solve the programming task below in a Python markdown code block.
Alice and Bob went to a pet store. There are N animals in the store where the i^{th} animal is of type A_{i}.
Alice decides to buy some of these N animals. Bob decides that he will buy all the animals left in the store after Alice has made the purchase.... | {"inputs": ["4\n3\n4 4 4\n4\n2 3 3 2\n4\n1 2 2 3\n6\n5 5 1 5 1 5\n"], "outputs": ["NO\nYES\nNO\nYES\n"]} | coding | 692 |
Solve the programming task below in a Python markdown code block.
A sequence of integers is called a wonderful sequence if all the integers in it are positive and it is a strictly increasing sequence.
Given a sequence of integers, you have to make it a wonderful sequence. For that you can change any element you want, ... | {"inputs": ["3\n2\n1 2\n3\n3 2 1\n5\n10 5 6 7 8", "4\n2\n1 2\n3\n3 2 1\n5\n10 5 6 7 8\n4\n2 2 2 2"], "outputs": ["0\n2\n1", "0\n2\n1\n3"]} | coding | 300 |
Solve the programming task below in a Python markdown code block.
Chef wants to buy a new phone, but he is not willing to spend a lot of money. Instead, he checks the price of his chosen model everyday and waits for the price to drop to an acceptable value. So far, he has observed the price for $N$ days (numbere $1$ th... | {"inputs": ["1\n7\n375 750 723 662 647 656 619"], "outputs": ["2"]} | coding | 545 |
Solve the programming task below in a Python markdown code block.
You get an array of numbers, return the sum of all of the positives ones.
Example `[1,-4,7,12]` => `1 + 7 + 12 = 20`
Note: if there is nothing to sum, the sum is default to `0`.
Also feel free to reuse/extend the following starter code:
```python
def p... | {"functional": "_inputs = [[[1, 2, 3, 4, 5]], [[1, -2, 3, 4, 5]], [[-1, 2, 3, 4, -5]], [[]], [[-1, -2, -3, -4, -5]]]\n_outputs = [[15], [13], [9], [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 ... | coding | 95 |
Solve the programming task below in a Python markdown code block.
You've got a 5 × 5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to a... | {"inputs": ["0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n", "0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n", "0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0\n", "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 1\n", "0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n", "1 0 0 0 0\n0... | coding | 411 |
Solve the programming task below in a Python markdown code block.
The rgb function is incomplete. Complete it so that passing in RGB decimal values will result in a hexadecimal representation being returned. Valid decimal values for RGB are 0 - 255. Any values that fall out of that range must be rounded to the closest ... | {"functional": "_inputs = [[0, 0, 0], [1, 2, 3], [255, 255, 255], [254, 253, 252], [-20, 275, 125]]\n_outputs = [['000000'], ['010203'], ['FFFFFF'], ['FEFDFC'], ['00FF7D']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, a... | coding | 241 |
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... | coding | 81 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
We are given n different types of stickers. Each sticker has a lowercase English word on it.
You would like to spell out the given string target by cutting individual letters from your collection of stickers and rearr... | {"functional": "def check(candidate):\n assert candidate( stickers = [\"with\",\"example\",\"science\"], target = \"thehat\") == 3\n assert candidate(stickers = [\"notice\",\"possible\"], target = \"basicbasic\") == -1\n\n\ncheck(Solution().minStickers)"} | coding | 179 |
Solve the programming task below in a Python markdown code block.
Malek has recently found a treasure map. While he was looking for a treasure he found a locked door. There was a string s written on the door consisting of characters '(', ')' and '#'. Below there was a manual on how to open the door. After spending a lo... | {"inputs": ["#\n", "#\n", "(#)\n", "(#(\n", "(#(\n", "#()\n", "(#)\n", "((#(\n"], "outputs": ["-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1", "-1\n", "-1\n"]} | coding | 367 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array of distinct integers arr, find all pairs of elements with the minimum absolute difference of any two elements.
Return a list of pairs in ascending order(with respect to pairs), each pair [a, b] follows
... | {"functional": "def check(candidate):\n assert candidate(arr = [4,2,1,3]) == [[1,2],[2,3],[3,4]]\n assert candidate(arr = [1,3,6,10,15]) == [[1,3]]\n assert candidate(arr = [3,8,-10,23,19,-4,-14,27]) == [[-14,-10],[19,23],[23,27]]\n\n\ncheck(Solution().minimumAbsDifference)"} | coding | 123 |
Solve the programming task below in a Python markdown code block.
Write a function taking in a string like `WOW this is REALLY amazing` and returning `Wow this is really amazing`. String should be capitalized and properly spaced. Using `re` and `string` is not allowed.
Examples:
```python
filter_words('HELLO... | {"functional": "_inputs = [['HELLO world!'], ['This will not pass '], ['NOW THIS is a VERY EXCITING test!']]\n_outputs = [['Hello world!'], ['This will not pass'], ['Now this is a very exciting test!']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n r... | coding | 137 |
Solve the programming task below in a Python markdown code block.
Once upon a time a child got a test consisting of multiple-choice questions as homework. A multiple-choice question consists of four choices: A, B, C and D. Each choice has a description, and the child should find out the only one that is correct.
Fortu... | {"inputs": ["A.a\nB.b\nC.c\nD.d\n", "A.a\nB.b\nC.c\nD.d\n", "a.A\nB.b\nC.c\nD.d\n", "A.c\nB.cc\nC.c\nD.c\n", "A.c\nB.cc\nC.c\nD.c\n", "A.aa\nB.bb\nC.cc\nD.ddd\n", "A.aa\nB.bb\nC.cc\nD.ddd\n", "A.ab\nB.abcde\nC.ab\nD.abc\n"], "outputs": ["C\n", "C\n", "C\n", "B\n", "B", "C\n", "C\n", "C\n"]} | coding | 536 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer n, you must transform it into 0 using the following operations any number of times:
Change the rightmost (0th) bit in the binary representation of n.
Change the ith bit in the binary representation o... | {"functional": "def check(candidate):\n assert candidate(n = 3) == 2\n assert candidate(n = 6) == 4\n\n\ncheck(Solution().minimumOneBitOperations)"} | coding | 142 |
Solve the programming task below in a Python markdown code block.
Finish the solution so that it sorts the passed in array of numbers. If the function passes in an empty array or null/nil value then it should return an empty array.
For example:
```python
solution([1,2,3,10,5]) # should return [1,2,3,5,10]
solution(No... | {"functional": "_inputs = [[[1, 2, 3, 10, 5]], [None], [[]], [[20, 2, 10]], [[2, 20, 10]]]\n_outputs = [[[1, 2, 3, 5, 10]], [[]], [[]], [[2, 10, 20]], [[2, 10, 20]]]\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=... | coding | 162 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given two integer arrays inorder and postorder where inorder is the inorder traversal of a binary tree and postorder is the postorder traversal of the same tree, construct and return the binary tree.
Please complete... | {"functional": "def check(candidate):\n assert is_same_tree(candidate(inorder = [9,3,15,20,7], postorder = [9,15,7,20,3]), tree_node([3,9,20,None,None,15,7]))\n assert is_same_tree(candidate(inorder = [-1], postorder = [-1]), tree_node([-1]))\n\n\ncheck(Solution().buildTree)"} | coding | 145 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
There are n employees in a company, numbered from 0 to n - 1. Each employee i has worked for hours[i] hours in the company.
The company requires each employee to work for at least target hours.
You are given a 0-index... | {"functional": "def check(candidate):\n assert candidate(hours = [0,1,2,3,4], target = 2) == 3\n assert candidate(hours = [5,1,4,2,2], target = 6) == 0\n\n\ncheck(Solution().numberOfEmployeesWhoMetTarget)"} | coding | 140 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two 0-indexed arrays of strings startWords and targetWords. Each string consists of lowercase English letters only.
For each string in targetWords, check if it is possible to choose a string from startWo... | {"functional": "def check(candidate):\n assert candidate(startWords = [\"ant\",\"act\",\"tack\"], targetWords = [\"tack\",\"act\",\"acti\"]) == 2\n assert candidate(startWords = [\"ab\",\"a\"], targetWords = [\"abc\",\"abcd\"]) == 1\n\n\ncheck(Solution().wordCount)"} | coding | 311 |
Solve the programming task below in a Python markdown code block.
Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.
Given a sequence a consisting of n integers. The player can make several steps. In a single step... | {"inputs": ["2\n1 2\n", "3\n1 2 3\n", "1\n100000\n", "5\n3 3 4 5 4\n", "5\n5 3 5 3 4\n", "5\n4 2 3 2 5\n", "5\n3 3 8 5 4\n", "5\n5 3 5 5 4\n"], "outputs": ["2\n", "4\n", "100000\n", "11\n", "16\n", "9\n", "19\n", "18\n"]} | coding | 337 |
Solve the programming task below in a Python markdown code block.
Integer sequence $\boldsymbol{a}$ having length $2n+2$ is defined as follows:
$a_{0}=0$
$a_{1}=C$
$a_{i+2}=(a_{i+1}+a_i)\ \text{\% M}$, where $0\leq i<2n$
Write a function generator, $gen$, to generate the remaining values for $a_2$ through $a_{2n+1}$.... | {"inputs": ["4 5 3\n"], "outputs": ["2\n"]} | coding | 720 |
Solve the programming task below in a Python markdown code block.
Jeff got 2n real numbers a1, a2, ..., a2n as a birthday present. The boy hates non-integer numbers, so he decided to slightly "adjust" the numbers he's got. Namely, Jeff consecutively executes n operations, each of them goes as follows:
* choose index... | {"inputs": ["1\n1.100 1.200\n", "1\n0.061 0.330\n", "1\n0.900 0.900\n", "1\n0.001 0.001\n", "1\n6418.669 157.986\n", "1\n6418.000 157.986\n", "1\n6418.000 157.000\n", "2\n0.001 0.001 0.001 0.001\n"], "outputs": ["0.700\n", "0.609\n", "0.800\n", "0.998\n", "0.655\n", "0.014\n", "0.000\n", "1.996\n"]} | coding | 539 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an array nums. You can rotate it by a non-negative integer k so that the array becomes [nums[k], nums[k + 1], ... nums[nums.length - 1], nums[0], nums[1], ..., nums[k-1]]. Afterward, any entries that are... | {"functional": "def check(candidate):\n assert candidate(nums = [2,3,1,4,0]) == 3\n assert candidate(nums = [1,3,0,2,4]) == 0\n\n\ncheck(Solution().bestRotation)"} | coding | 249 |
Solve the programming task below in a Python markdown code block.
Problem
There are N villages. Each village is numbered from 1 to N. Due to the recent merger boom, several villages have been merged. Two or more merged villages will become one new city, and villages that are not merged with any village will remain vil... | {"inputs": ["4 0", "7 0", "8 0", "0 0", "5 0", "13 0", "26 0", "16 0"], "outputs": ["4\n", "7\n", "8\n", "0\n", "5", "13\n", "26\n", "16\n"]} | coding | 462 |
Solve the programming task below in a Python markdown code block.
You are a lover of bacteria. You want to raise some bacteria in a box.
Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split into two bacteria. You hope to see ... | {"inputs": ["5\n", "8\n", "1\n", "2\n", "3\n", "4\n", "6\n", "7\n"], "outputs": ["2\n", "1\n", "1\n", "1\n", "2\n", "1\n", "2\n", "3\n"]} | coding | 254 |
Solve the programming task below in a Python markdown code block.
Given three arrays of integers, return the sum of elements that are common in all three arrays.
For example:
```
common([1,2,3],[5,3,2],[7,3,2]) = 5 because 2 & 3 are common in all 3 arrays
common([1,2,2,3],[5,3,2,2],[7,3,2,2]) = 7 because 2,2 & 3 are... | {"functional": "_inputs = [[[1, 2, 3], [5, 3, 2], [7, 3, 2]], [[1, 2, 2, 3], [5, 3, 2, 2], [7, 3, 2, 2]], [[1], [1], [1]], [[1], [1], [2]]]\n_outputs = [[5], [7], [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, a... | coding | 155 |
Solve the programming task below in a Python markdown code block.
In this Kata, you will be given two strings `a` and `b` and your task will be to return the characters that are not common in the two strings.
For example:
```Haskell
solve("xyab","xzca") = "ybzc"
--The first string has 'yb' which is not in the second... | {"functional": "_inputs = [['xyab', 'xzca'], ['xyabb', 'xzca'], ['abcd', 'xyz'], ['xxx', 'xzca']]\n_outputs = [['ybzc'], ['ybbzc'], ['abcdxyz'], ['zca']]\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... | coding | 198 |
Solve the programming task below in a Python markdown code block.
Your task is to determine how many files of the copy queue you will be able to save into your Hard Disk Drive. The files must be saved in the order they appear in the queue.
### Input:
* Array of file sizes `(0 <= s <= 100)`
* Capacity of the HD `(0 <... | {"functional": "_inputs = [[[4, 4, 4, 3, 3], 12], [[4, 4, 4, 3, 3], 11], [[4, 8, 15, 16, 23, 42], 108], [[13], 13], [[1, 2, 3, 4], 250], [[100], 500], [[11, 13, 15, 17, 19], 8], [[45], 12]]\n_outputs = [[3], [2], [6], [1], [4], [1], [0], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or i... | coding | 234 |
Solve the programming task below in a Python markdown code block.
Chef's new friend hErd gave him two functions f and g.
The function f is defined over x (x≥ 1) as:
f(x) = \begin{cases}
0, & \text{if } x = 1 \\
f( \frac{x}{2} ) + 1, & \text{if } x \text{ is even} \\
f( \lfloor \frac{x}{2} \rfloor ), & \text{if } x ... | {"inputs": ["3\n1 1\n1 2\n1 20"], "outputs": ["1\n4\n35"]} | coding | 573 |
Solve the programming task below in a Python markdown code block.
AtCoDeer the deer found two positive integers, a and b.
Determine whether the product of a and b is even or odd.
-----Constraints-----
- 1 ≤ a,b ≤ 10000
- a and b are integers.
-----Input-----
Input is given from Standard Input in the following forma... | {"inputs": ["4 4", "2 4", "3 0", "0 0", "0 1", "0 2", "1 2", "1 1"], "outputs": ["Even\n", "Even\n", "Even\n", "Even\n", "Even\n", "Even\n", "Even\n", "Odd\n"]} | coding | 133 |
Solve the programming task below in a Python markdown code block.
Прошло много лет, и на вечеринке снова встретились n друзей. С момента последней встречи техника шагнула далеко вперёд, появились фотоаппараты с автоспуском, и теперь не требуется, чтобы один из друзей стоял с фотоаппаратом, и, тем самым, оказывался не з... | {"inputs": ["1\n1 1\n", "1\n5 10\n", "1\n1 1000\n", "1\n1000 1\n", "2\n1 1\n1 1\n", "2\n2 1\n3 1\n", "2\n4 3\n2 1\n", "1\n1000 1000\n"], "outputs": ["1\n", "50\n", "1000\n", "1000\n", "2\n", "5\n", "15\n", "1000000\n"]} | coding | 513 |
Solve the programming task below in a Python markdown code block.
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if th... | {"inputs": ["3\nmike 1\nandrew 5\nmike 2\n", "3\nmike 1\nandsew 5\nmike 2\n", "3\nmike 3\nandrew 5\nmike 2\n", "3\neikm 0\nwesdna 12\nejkm 0\n", "3\nemki 0\nwdsena 12\nejmk 0\n", "3\nelkh 0\nwdsema 12\nemjk 0\n", "3\nmike 1\nandsew 10\nmike 2\n", "3\nmike 1\nandsew 12\nmike 2\n"], "outputs": ["andrew\n", "andsew\n", "a... | coding | 371 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given the root of a binary search tree, rearrange the tree in in-order so that the leftmost node in the tree is now the root of the tree, and every node has no left child and only one right child.
Please complete th... | {"functional": "def check(candidate):\n assert is_same_tree(candidate(root = tree_node([5,3,6,2,4,None,8,1,None,None,None,7,9])), tree_node([1,None,2,None,3,None,4,None,5,None,6,None,7,None,8,None,9]))\n assert is_same_tree(candidate(root = tree_node([5,1,7])), tree_node([1,None,5,None,7]))\n\n\ncheck(Solution().... | coding | 145 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given n orders, each order consists of a pickup and a delivery service.
Count all valid pickup/delivery possible sequences such that delivery(i) is always after of pickup(i).
Since the answer may be too large, return... | {"functional": "def check(candidate):\n assert candidate(n = 1) == 1\n assert candidate(n = 2) == 6\n assert candidate(n = 3) == 90\n\n\ncheck(Solution().countOrders)"} | coding | 106 |
Solve the programming task below in a Python markdown code block.
Alice and Bob are playing a game on a sequence $a_1, a_2, \dots, a_n$ of length $n$. They move in turns and Alice moves first.
In the turn of each player, he or she should select an integer and remove it from the sequence. The game ends when there is no... | {"inputs": ["4\n3\n1 3 5\n4\n1 3 5 7\n4\n1 2 3 4\n4\n10 20 30 40\n", "1\n100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n"], "outputs": ["Alice\nAlice\nBob\nAlice... | coding | 451 |
Solve the programming task below in a Python markdown code block.
# Let's watch a parade!
## Brief
You're going to watch a parade, but you only care about one of the groups marching. The parade passes through the street where your house is. Your house is at number `location` of the street. Write a function `parade_time... | {"functional": "_inputs = [[['a', 'b', 'c', 'd', 'e', 'f'], 3, 2, 'c'], [['c', 'b', 'c', 'd', 'e', 'f'], 3, 2, 'c'], [['a', 'b', 'c', 'd', 'e', 'f'], 3, 2, 'g'], [['a', 'b', 'c', 'c', 'e', 'c'], 7, 1, 'c'], [['a', 'b', 'c', 'd', 'e', 'f'], 1, 2, 'b'], [['a', 'b', 'c', 'd', 'e', 'b'], 1, 2, 'b']]\n_outputs = [[[3]], [[2... | coding | 467 |
Solve the programming task below in a Python markdown code block.
Let's define the permutation of length n as an array p = [p1, p2, ..., pn] consisting of n distinct integers from range from 1 to n. We say that this permutation maps value 1 into the value p1, value 2 into the value p2 and so on.
Kyota Ootori has just ... | {"inputs": ["2 2\n", "9 1\n", "4 2\n", "1 1\n", "5 8\n", "3 3\n", "5 1\n", "7 2\n"], "outputs": ["2 1\n", "1 2 3 4 5 6 7 8 9\n", "1 2 4 3\n", "1\n", "2 1 4 3 5\n", "2 1 3\n", "1 2 3 4 5\n", "1 2 3 4 5 7 6\n"]} | coding | 647 |
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Limak is a little polar bear, who loves eating cookies and drinking milk.
For this reason he often visits Chef's kitchen.
Limak is going to spend N minutes in the kitchen.
E... | {"inputs": ["4\n7\ncookie milk milk cookie milk cookie milk\n5\ncookie cookie milk milk milk\n4\nmilk milk milk milk\n1\ncookie"], "outputs": ["YES\nNO\nYES\nNO"]} | coding | 611 |
Solve the programming task below in a Python markdown code block.
There is a tree with N vertices, numbered 1 through N. The i-th of the N-1 edges connects vertices a_i and b_i.
Currently, there are A_i stones placed on vertex i. Determine whether it is possible to remove all the stones from the vertices by repeatedly... | {"inputs": ["3\n2 2 1\n1 2\n2 3", "3\n1 1 1\n1 2\n2 3", "3\n1 2 0\n1 2\n2 3", "3\n2 2 2\n1 2\n2 3", "3\n2 1 1\n1 2\n2 3", "3\n0 2 0\n1 2\n2 3", "3\n3 1 1\n1 2\n2 3", "3\n2 2 0\n1 2\n2 3"], "outputs": ["NO\n", "YES\n", "NO\n", "YES\n", "NO\n", "NO\n", "NO\n", "NO\n"]} | coding | 372 |
Solve the programming task below in a Python markdown code block.
# Task
Four men, `a, b, c and d` are standing in a line, one behind another.
There's a wall between the first three people (a, b and c) and the last one (d).
a, b and c are lined up in order of height, so that person a can see the backs of b and ... | {"functional": "_inputs = [['white', 'black', 'white', 'black'], ['white', 'black', 'black', 'white']]\n_outputs = [[2], [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=tol)\n if isinstance(a, (list, tuple)... | coding | 403 |
Solve the programming task below in a Python markdown code block.
## Check Digits
Some numbers are more important to get right during data entry than others: a common example is product codes.
To reduce the possibility of mistakes, product codes can be crafted in such a way that simple errors are detected. This is do... | {"functional": "_inputs = [['036532'], ['12388878'], ['111111111'], ['9735597355'], ['2356'], ['6789']]\n_outputs = [['0365327'], ['123888782'], ['1111111118'], ['97355973550'], ['23566'], ['6789X']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.i... | coding | 573 |
Solve the programming task below in a Python markdown code block.
In genetics 2 differents DNAs sequences can code for the same protein.
This is due to the redundancy of the genetic code, in fact 2 different tri-nucleotide can code for the same amino-acid.
For example the tri-nucleotide 'TTT' and the tri-nucleotide '... | {"functional": "_inputs = [['ATGTCGTCAATTTAA', 'ATGTCGTCAATTTAA'], ['ATGTTTTAA', 'ATGTTCTAA'], ['ATGTTTTAA', 'ATGATATAA'], ['ATGTTTGGGAATAATTAAGGGTAA', 'ATGTTCGGGAATAATGGGAGGTAA']]\n_outputs = [[True], [True], [False], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, fl... | coding | 304 |
Solve the programming task below in a Python markdown code block.
The territory of Berland is represented by a rectangular field n × m in size. The king of Berland lives in the capital, located on the upper left square (1, 1). The lower right square has coordinates (n, m). One day the king decided to travel through the... | {"inputs": ["1 3\n", "1 2\n", "3 2\n", "3 1\n", "6 3\n", "2 3\n", "3 4\n", "2 1\n"], "outputs": ["1\n1 3 1 1\n1 1\n1 2\n1 3\n1 1\n", "0\n1 1\n1 2\n1 1\n", "0\n1 1\n2 1\n3 1\n3 2\n2 2\n1 2\n1 1\n", "1\n3 1 1 1\n1 1\n2 1\n3 1\n1 1\n", "0\n1 1\n1 2\n1 3\n2 3\n2 2\n3 2\n3 3\n4 3\n4 2\n5 2\n5 3\n6 3\n6 2\n6 1\n5 1\n4 1\n3 1... | coding | 606 |
Solve the programming task below in a Python markdown code block.
Consider the following series:
`0,1,2,3,4,5,6,7,8,9,10,22,11,20,13,24...`There is nothing special between numbers `0` and `10`.
Let's start with the number `10` and derive the sequence. `10` has digits `1` and `0`. The next possible number that does n... | {"functional": "_inputs = [[1], [5], [11], [100], [500]]\n_outputs = [[1], [5], [22], [103], [476]]\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) != l... | coding | 454 |
Solve the programming task below in a Python markdown code block.
The city of Hackerland has formed a new football club and wants to participate in the upcoming Football League of their country. The coach is worried that they will not be able to qualify because they don't have a famous footballer in their team. The ass... | {"inputs": ["5\n3 2\n4 5\n7 4\n34534985349875439875439875349875 93475349759384754395743975349573495\n34543987529435983745230948023948 3498573497543987543985743989120393097595572309482304\n"], "outputs": ["9\n1024\n2401\n735851262\n985546465\n"]} | coding | 665 |
Solve the programming task below in a Python markdown code block.
Ash is on his way to becoming the Pokemon Master. His pokemon can perform the following moves:
- Tackle - Deal damage worth $X$ points
- Grow - Increase damage by $Y$ points i.e. $X$ = $X$ + $Y$
But, it can only perform Grow first (0 or more times) ... | {"inputs": ["2\n101 10 10\n11 3 3"], "outputs": ["6\n-1"]} | coding | 525 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Let's define a function countUniqueChars(s) that returns the number of unique characters in s.
For example, calling countUniqueChars(s) if s = "LEETCODE" then "L", "T", "C", "O", "D" are the unique characters since t... | {"functional": "def check(candidate):\n assert candidate(s = \"LEETCODE\") == 92\n\n\ncheck(Solution().uniqueLetterString)"} | coding | 185 |
Solve the programming task below in a Python markdown code block.
Let's define the cost of a simple undirected graph as the sum of the costs of its nodes. The cost of a node is defined as DK, where D is its degree.
You are given N and K. You need to find the sum of the costs of all possible simple undirected graphs wi... | {"inputs": ["5\n1 1\n2 3\n3 2\n6 5\n20 20\n"], "outputs": ["0\n2\n36\n67584000\n956922563\n"]} | coding | 706 |
Solve the programming task below in a Python markdown code block.
One day Prof. Slim decided to leave the kingdom of the GUC to join the kingdom of the GIU. He was given an easy online assessment to solve before joining the GIU. Citizens of the GUC were happy sad to see the prof leaving, so they decided to hack into th... | {"inputs": ["4\n7\n7 3 2 -11 -13 -17 -23\n6\n4 10 25 47 71 96\n6\n71 -35 7 -4 -11 -25\n6\n-45 9 -48 -67 -55 7\n", "8\n2\n-59 -9\n1\n11\n3\n-41 -26 -2\n3\n22 33 54\n3\n-56 -6 55\n5\n36 15 9 14 -71\n3\n-7 40 47\n5\n-19 54 -5 7 -29\n"], "outputs": ["NO\nYES\nYES\nNO\n", "YES\nYES\nYES\nYES\nYES\nNO\nYES\nNO\n"]} | coding | 739 |
Solve the programming task below in a Python markdown code block.
Our brave travelers reached an island where pirates had buried treasure. However as the ship was about to moor, the captain found out that some rat ate a piece of the treasure map.
The treasure map can be represented as a rectangle n × m in size. Each c... | {"inputs": ["3 3\n###\n#A#\n###\n1\nN 1\n", "3 3\n###\n#A#\n###\n1\nN 0\n", "3 4\n####\n#-A#\n####\n2\nW 1\nN 2\n", "3 4\n####\n#-A#\n####\n2\nW 2\nN 2\n", "3 4\n####\n#.A#\n####\n2\nW 1\nN 2\n", "4 9\n#########\n#AB#CDEF#\n#.......#\n#########\n1\nW 3\n", "4 9\n#########\n#AB#CDEF#\n#.......#\n#########\n1\nS 1\n", "4... | coding | 650 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed string s consisting of only lowercase English letters, where each letter in s appears exactly twice. You are also given a 0-indexed integer array distance of length 26.
Each letter in the alp... | {"functional": "def check(candidate):\n assert candidate(s = \"abaccb\", distance = [1,3,0,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]) == True\n assert candidate(s = \"aa\", distance = [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]) == False\n\n\ncheck(Solution().checkDistances)"} | coding | 202 |
Solve the programming task below in a Python markdown code block.
Find \displaystyle{\sum_{a=1}^{K}\sum_{b=1}^{K}\sum_{c=1}^{K} \gcd(a,b,c)}.
Here \gcd(a,b,c) denotes the greatest common divisor of a, b, and c.
-----Constraints-----
- 1 \leq K \leq 200
- K is an integer.
-----Input-----
Input is given from Standard... | {"inputs": ["4", "8", "3", "5", "7", "0", "1", "9"], "outputs": ["76\n", "624\n", "30\n", "141\n", "400\n", "0\n", "1\n", "885\n"]} | coding | 267 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an m x n binary matrix grid. An island is a group of 1's (representing land) connected 4-directionally (horizontal or vertical.) You may assume all four edges of the grid are surrounded by water.
An isla... | {"functional": "def check(candidate):\n assert candidate(grid = [[1,1,0,0,0],[1,0,0,0,0],[0,0,0,0,1],[0,0,0,1,1]]) == 1\n assert candidate(grid = [[1,1,0,0,0],[1,1,0,0,0],[0,0,0,1,1],[0,0,0,1,1]]) == 1\n\n\ncheck(Solution().numDistinctIslands2)"} | coding | 160 |
Solve the programming task below in a Python markdown code block.
There are four towns, numbered 1,2,3 and 4. Also, there are three roads. The i-th road connects different towns a_i and b_i bidirectionally. No two roads connect the same pair of towns. Other than these roads, there is no way to travel between these town... | {"inputs": ["4 3\n1 3\n2 3", "1 1\n3 2\n4 3", "1 2\n3 2\n4 3", "1 2\n2 2\n4 3", "3 2\n2 4\n1 4", "1 1\n3 2\n4 1", "1 4\n2 2\n4 3", "3 2\n3 4\n1 4"], "outputs": ["NO\n", "YES\n", "YES\n", "NO\n", "YES\n", "NO\n", "YES\n", "YES\n"]} | coding | 303 |
Solve the programming task below in a Python markdown code block.
There are N hills in a row numbered 1 through N from left to right. Each hill has a height; for each valid i, the height of the i-th hill is Hi. Chef is initially on the leftmost hill (hill number 1). He can make an arbitrary number of jumps (including z... | {"inputs": ["3\n5 3 2\n2 5 2 6 3\n5 2 3\n4 4 4 4 4\n5 2 7\n1 4 3 2 1"], "outputs": ["3\n5\n1"]} | coding | 616 |
Solve the programming task below in a Python markdown code block.
Takahashi wants to gain muscle, and decides to work out at AtCoder Gym.
The exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up.
These buttons are numbered 1 through N.
When Button i is lighten up and you press it, the... | {"inputs": ["3\n3\n1\n3", "3\n2\n2\n1", "3\n3\n2\n3", "3\n1\n2\n6", "3\n3\n2\n1", "3\n1\n1\n6", "3\n1\n2\n1", "3\n1\n0\n6"], "outputs": ["-1\n", "1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n"]} | coding | 279 |
Solve the programming task below in a Python markdown code block.
In this kata, your task is to write a function `to_bytes(n)` (or `toBytes(n)` depending on language) that produces a list of bytes that represent a given non-negative integer `n`. Each byte in the list is represented by a string of `'0'` and `'1'` of len... | {"functional": "_inputs = [[0], [1]]\n_outputs = [[['00000000']], [['00000001']]]\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 Fals... | coding | 136 |
Solve the programming task below in a Python markdown code block.
You are given a permutation p_1, p_2, …, p_n.
In one move you can swap two adjacent values.
You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer... | {"inputs": ["1\n1\n", "3\n3 2 1\n", "3\n2 3 1\n", "3\n3 1 2\n", "3\n2 1 3\n", "3\n1 3 2\n", "3\n1 2 3\n", "5\n5 4 3 1 2\n"], "outputs": ["0\n", "0 1 3\n", "0 2 2\n", "0 0 2\n", "0 1 1\n", "0 1 1\n", "0 0 0\n", "0 0 2 5 9\n"]} | coding | 325 |
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian as well.
Petr, Nikita G. and Nikita are the most influential music critics in Saint-Petersburg. They have recently downloaded their favorite band's new album and going to listen to it. Nikita cla... | {"inputs": ["3\n1\n2\n3", "3\n1\n2\n2", "3\n1\n2\n6", "3\n2\n2\n2", "3\n1\n3\n2", "3\n1\n3\n6", "3\n1\n1\n2", "3\n1\n1\n6"], "outputs": ["1.0\n3.0\n5.5", "1.0\n3.0\n3.0\n", "1.0\n3.0\n14.7\n", "3.0\n3.0\n3.0\n", "1.0\n5.5\n3.0\n", "1.0\n5.5\n14.7\n", "1.0\n1.0\n3.0\n", "1.0\n1.0\n14.7\n"]} | coding | 543 |
Solve the programming task below in a Python markdown code block.
You are given a string S of length N, containing lowercase Latin letters. You are also given an integer K.
You would like to create a new string S' by following the following process:
First, partition S into exactly K non-empty [subsequences] S_{1}, S_{... | {"inputs": ["3\n6 1\nwhizzy\n14 2\naaacdecdebacde\n4 3\ndbca\n"], "outputs": ["whizzy\naaaaccdecdebde\nabcd"]} | coding | 598 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Alice manages a company and has rented some floors of a building as office space. Alice has decided some of these floors should be special floors, used for relaxation only.
You are given two integers bottom and top, w... | {"functional": "def check(candidate):\n assert candidate(bottom = 2, top = 9, special = [4,6]) == 3\n assert candidate(bottom = 6, top = 8, special = [7,6,8]) == 0\n\n\ncheck(Solution().maxConsecutive)"} | coding | 151 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer n.
Each number from 1 to n is grouped according to the sum of its digits.
Return the number of groups that have the largest size.
Please complete the following python code precisely:
```pyth... | {"functional": "def check(candidate):\n assert candidate(n = 13) == 4\n assert candidate(n = 2) == 2\n assert candidate(n = 15) == 6\n assert candidate(n = 24) == 5\n\n\ncheck(Solution().countLargestGroup)"} | coding | 84 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
The Game of Master Mind is played as follows:
The computer has four slots, and each slot will contain a ball that is red (R). yellow (Y). green (G) or blue (B). For example, the computer might have RGGB (Slot #1 is re... | {"functional": "def check(candidate):\n assert candidate(solution=\"RGBY\",guess=\"GGRR\") == [1,1]\n\n\ncheck(Solution().masterMind)"} | coding | 294 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
We define the lcp matrix of any 0-indexed string word of n lowercase English letters as an n x n grid such that:
lcp[i][j] is equal to the length of the longest common prefix between the substrings word[i,n-1] and wo... | {"functional": "def check(candidate):\n assert candidate(lcp = [[4,0,2,0],[0,3,0,1],[2,0,2,0],[0,1,0,1]]) == \"abab\"\n assert candidate(lcp = [[4,3,2,1],[3,3,2,1],[2,2,2,1],[1,1,1,1]]) == \"aaaa\"\n assert candidate(lcp = [[4,3,2,1],[3,3,2,1],[2,2,2,1],[1,1,1,3]]) == \"\"\n\n\ncheck(Solution().findTheString)"... | coding | 232 |
Solve the programming task below in a Python markdown code block.
Write a method that returns true if a given parameter is a power of 4, and false if it's not. If parameter is not an Integer (eg String, Array) method should return false as well.
(In C# Integer means all integer Types like Int16,Int32,.....)
### Examp... | {"functional": "_inputs = [[2], [4], [40], [1], [4.2], [-25], ['pippi'], [256]]\n_outputs = [[False], [True], [False], [True], [False], [False], [False], [True]]\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)... | coding | 146 |
Solve the programming task below in a Python markdown code block.
Given a sequence of numbers a1, a2, a3, ..., an, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a contiquous subsequence.
Input
The input consists of multiple datasets. Each data set... | {"inputs": ["7\n-5\n0\n6\n0\n6\n-6\n0\n9\n2\n2\n0\n2\n-4\n-1\n1\n1\n6\n2\n0\n-3\n4\n3\n0000\n-200\n397\n0", "7\n-5\n0\n6\n4\n9\n-6\n0\n13\n1\n2\n1\n2\n-2\n-1\n1\n2\n6\n2\n1\n-3\n2\n3\n0000\n-200\n201\n0", "7\n-5\n0\n6\n4\n6\n-6\n0\n13\n1\n2\n1\n2\n-2\n-1\n1\n2\n6\n2\n1\n-3\n2\n3\n0000\n-200\n201\n0", "7\n-5\n0\n6\n4\n6... | coding | 234 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a string s, return the last substring of s in lexicographical order.
Please complete the following python code precisely:
```python
class Solution:
def lastSubstring(self, s: str) -> str:
``` | {"functional": "def check(candidate):\n assert candidate(s = \"abab\") == \"bab\"\n assert candidate(s = \"leetcode\") == \"tcode\"\n\n\ncheck(Solution().lastSubstring)"} | coding | 64 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two 0-indexed integer arrays nums1 and nums2 of length n.
A range [l, r] (inclusive) where 0 <= l <= r < n is balanced if:
For every i in the range [l, r], you pick either nums1[i] or nums2[i].
The sum ... | {"functional": "def check(candidate):\n assert candidate(nums1 = [1,2,5], nums2 = [2,6,3]) == 3\n assert candidate(nums1 = [0,1], nums2 = [1,0]) == 4\n\n\ncheck(Solution().countSubranges)"} | coding | 267 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array of intervals where intervals[i] = [starti, endi], merge all overlapping intervals, and return an array of the non-overlapping intervals that cover all the intervals in the input.
Please complete the f... | {"functional": "def check(candidate):\n assert candidate(intervals = [[1,3],[2,6],[8,10],[15,18]]) == [[1,6],[8,10],[15,18]]\n assert candidate(intervals = [[1,4],[4,5]]) == [[1,5]]\n\n\ncheck(Solution().merge)"} | coding | 93 |
Solve the programming task below in a Python markdown code block.
Find the number of integers between 1 and N (inclusive) that contains exactly K non-zero digits when written in base ten.
-----Constraints-----
- 1 \leq N < 10^{100}
- 1 \leq K \leq 3
-----Input-----
Input is given from Standard Input in the followin... | {"inputs": ["9\n1\n", "9\n2\n", "25\n1", "25\n4", "25\n5", "25\n3", "25\n9", "25\n7"], "outputs": ["9\n", "0\n", "11\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | coding | 173 |
Solve the programming task below in a Python markdown code block.
Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?
Given a n × n checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the... | {"inputs": ["1\no\n", "1\no\n", "1\nn\n", "1\np\n", "1\nm\n", "1\nl\n", "1\nk\n", "1\nq\n"], "outputs": ["YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n"]} | coding | 215 |
Solve the programming task below in a Python markdown code block.
One of the first algorithm used for approximating the integer square root of a positive integer `n` is known as "Hero's method",
named after the first-century Greek mathematician Hero of Alexandria who gave the first description
of the method. Hero's me... | {"functional": "_inputs = [[25, 1], [125348, 300], [125348981764, 356243], [236, 12], [48981764, 8000], [6999, 700], [16000, 400], [16000, 100], [2500, 60], [250000, 600], [95367431640625, 1], [9094947017729282379150390625, 1], [835871232077058, 1], [246391990316004, 1], [403832254158749, 1], [217414278071071, 1], [639... | coding | 501 |
Solve the programming task below in a Python markdown code block.
collections.namedtuple()
Basically, namedtuples are easy to create, lightweight object types.
They turn tuples into convenient containers for simple tasks.
With namedtuples, you don’t have to use integer indices for accessing members of a tuple.
Ex... | {"inputs": ["5\nMARKS CLASS NAME ID \n92 2 Calum 1 \n82 5 Scott 2 \n94 2 Jason 3 \n55 8 Glenn 4 \n82 2 Fergus 5\n", "5\nID MARKS NAME CLA... | coding | 693 |
Solve the programming task below in a Python markdown code block.
Write a function that accepts an array of 10 integers (between 0 and 9), that returns a string of those numbers in the form of a phone number.
Example:
```python
create_phone_number([1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) # => returns "(123) 456-7890"
```
```f... | {"functional": "_inputs = [[[1, 2, 3, 4, 5, 6, 7, 8, 9, 0]], [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]], [[0, 2, 3, 0, 5, 6, 0, 8, 9, 0]], [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]]\n_outputs = [['(123) 456-7890'], ['(111) 111-1111'], ['(023) 056-0890'], ['(000) 000-0000']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a... | coding | 207 |
Solve the programming task below in a Python markdown code block.
Find the union of two sets $A = \\{a_0, a_1, ..., a_{n-1}\\}$ and $B = \\{b_0, b_1, ..., b_{m-1}\\}$.
Constraints
* $1 \leq n, m \leq 200,000$
* $0 \leq a_0 < a_1 < ... < a_{n-1} \leq 10^9$
* $0 \leq b_0 < b_1 < ... < b_{m-1} \leq 10^9$
Input
The inp... | {"inputs": ["3\n1 5 8\n2\n5 8", "3\n1 3 8\n2\n5 8", "3\n1 5 8\n2\n4 9", "3\n1 6 8\n2\n5 8", "3\n1 3 8\n2\n2 8", "3\n1 5 8\n2\n3 9", "3\n2 3 8\n2\n5 8", "3\n1 3 8\n2\n3 8"], "outputs": ["1\n5\n8\n", "1\n3\n5\n8\n", "1\n4\n5\n8\n9\n", "1\n5\n6\n8\n", "1\n2\n3\n8\n", "1\n3\n5\n8\n9\n", "2\n3\n5\n8\n", "1\n3\n8\n"]} | coding | 273 |
Solve the programming task below in a Python markdown code block.
ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists a substring (contiguous segment of letters) of it of length 26 where each letter of English alphabet appears exactly once. In particular, if the string has length st... | {"inputs": ["A\n", "A\n", "B\n", "C\n", "AA\n", "AB\n", "AA\n", "AB\n"], "outputs": ["-1", "-1\n", "-1", "-1", "-1", "-1", "-1\n", "-1\n"]} | coding | 584 |
Solve the programming task below in a Python markdown code block.
You are given two binary strings $a$ and $b$ of the same length. You can perform the following two operations on the string $a$:
Swap any two bits at indices $i$ and $j$ respectively ($1 \le i, j \le n$), the cost of this operation is $|i - j|$, that ... | {"inputs": ["1\n0\n1\n", "1\n1\n1\n", "1\n1\n1\n", "1\n0\n1\n", "2\n10\n01\n", "2\n10\n00\n", "2\n10\n01\n", "2\n10\n00\n"], "outputs": ["1\n", "0\n", "0\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | coding | 500 |
Solve the programming task below in a Python markdown code block.
We call a string good, if after merging all the consecutive equal characters, the resulting string is palindrome. For example, "aabba" is good, because after the merging step it will become "aba".
Given a string, you have to find two values: the number... | {"inputs": ["a\n", "a\n", "b\n", "bb\n", "aa\n", "bb\n", "ab\n", "ba\n"], "outputs": ["0 1\n", "0 1\n", "0 1\n", "1 2\n", "1 2\n", "1 2\n", "0 2\n", "0 2\n"]} | coding | 434 |
Solve the programming task below in a Python markdown code block.
On every CodeChef user's profile page, the list of problems that they have set, tested, and written editorials for, is listed at the bottom.
Given the number of problems in each of these 3 categories as X, Y, and Z respectively (where all three integer... | {"inputs": ["4\n5 3 2\n1 2 4\n2 5 1\n9 4 5\n"], "outputs": ["Setter\nEditorialist\nTester\nSetter"]} | coding | 495 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.