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.
It is the easy version of the problem. The difference is that in this version, there are no nodes with already chosen colors.
Theofanis is starving, and he wants to eat his favorite food, sheftalia. However, he should first finish his homework. Can you ... | {"inputs": ["3\n", "1\n", "2\n", "4\n", "2\n", "1\n", "4\n", "5\n"], "outputs": ["24576\n", "6\n", "96\n", "610612729\n", "96\n", "6\n", "610612729\n", "218379003\n"]} | coding | 482 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.
An input string is valid if:
Open brackets must be closed by the same type of brackets.
Open br... | {"functional": "def check(candidate):\n assert candidate(s = \"()\") == True\n assert candidate(s = \"()[]{}\") == True\n assert candidate(s = \"(]\") == False\n\n\ncheck(Solution().isValid)"} | coding | 116 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Seven different symbols represent Roman numerals with the following values:
Symbol
Value
I
1
V
5
X
10
L
50
C
100
D
500
M
1000
Roman numerals are formed by appending the conversions of decimal pla... | {"functional": "def check(candidate):\n assert candidate(num = 3) == \"III\"\n assert candidate(num = 4) == \"IV\"\n assert candidate(num = 9) == \"IX\"\n assert candidate(num = 58) == \"LVIII\"\n assert candidate(num = 1994) == \"MCMXCIV\"\n\n\ncheck(Solution().intToRoman)"} | coding | 388 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer array nums where the largest integer is unique.
Determine whether the largest element in the array is at least twice as much as every other number in the array. If it is, return the index of t... | {"functional": "def check(candidate):\n assert candidate(nums = [3,6,1,0]) == 1\n assert candidate(nums = [1,2,3,4]) == -1\n\n\ncheck(Solution().dominantIndex)"} | coding | 103 |
Solve the programming task below in a Python markdown code block.
Create a function which accepts one arbitrary string as an argument, and return a string of length 26.
The objective is to set each of the 26 characters of the output string to either `'1'` or `'0'` based on the fact whether the Nth letter of the alphab... | {"functional": "_inputs = [['a **& bZ'], ['Abc e $$ z'], ['!!a$%&RgTT'], [''], ['abcdefghijklmnopqrstuvwxyz'], ['aaaaaaaaaaa'], ['&%&%/$%$%$%$%GYtf67fg34678hgfdyd']]\n_outputs = [['11000000000000000000000001'], ['11101000000000000000000001'], ['10000010000000000101000000'], ['00000000000000000000000000'], ['11111111... | coding | 230 |
Solve the programming task below in a Python markdown code block.
It's bonus time in the big city! The fatcats are rubbing their paws in anticipation... but who is going to make the most money?
Build a function that takes in two arguments (salary, bonus). Salary will be an integer, and bonus a boolean.
If bonus is t... | {"functional": "_inputs = [[10000, True], [25000, True], [10000, False], [60000, False], [2, True], [78, False], [67890, True]]\n_outputs = [['$100000'], ['$250000'], ['$10000'], ['$60000'], ['$20'], ['$78'], ['$678900']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\... | coding | 192 |
Solve the programming task below in a Python markdown code block.
Consider a number X on which K Mag-Inc operations are to be performed. In a Mag-Inc operation, the number X undergoes an increment of A/B times of X where A and B are two integers.
There is a numerator and a denominator array of size K which contain the... | {"inputs": ["2\n100 1\n1\n4\n100 2\n1 1\n2 3"], "outputs": ["20\n50"]} | coding | 434 |
Solve the programming task below in a Python markdown code block.
Chef has made a list for his monthly expenses. The list has N expenses with index 1 to N. The money spent on each expense depends upon the monthly income of Chef.
Chef spends 50\% of his total income on the expense with index 1.
The money spent on the i... | {"inputs": ["4\n1 2\n1 3\n2 3\n3 4\n"], "outputs": ["2\n4\n2\n2"]} | coding | 676 |
Solve the programming task below in a Python markdown code block.
The chef is having one string of English lower case alphabets only. The chef wants to remove all "abc" special pairs where a,b,c are occurring consecutively. After removing the pair, create a new string and again remove "abc" special pair from a newly fo... | {"inputs": ["2\naabcc\nbababccc"], "outputs": ["ac\nbc"]} | coding | 262 |
Solve the programming task below in a Python markdown code block.
Soroush and Keshi each have a labeled and rooted tree on n vertices. Both of their trees are rooted from vertex 1.
Soroush and Keshi used to be at war. After endless decades of fighting, they finally became allies to prepare a Codeforces round. To celeb... | {"inputs": ["4\n4\n1 2 3\n1 2 3\n5\n1 2 3 4\n1 1 1 1\n6\n1 2 1 1 2\n1 2 1 2 2\n7\n1 1 3 4 4 5\n1 2 1 4 2 5\n", "4\n4\n1 2 3\n1 2 3\n5\n1 2 3 4\n1 1 1 1\n6\n1 2 1 1 2\n1 2 1 2 2\n7\n1 1 3 4 4 5\n1 2 1 4 4 5\n", "4\n4\n1 2 3\n1 2 3\n5\n1 4 3 4\n1 1 1 1\n6\n1 1 1 1 2\n1 2 1 2 2\n7\n1 1 3 4 4 5\n1 2 1 4 2 5\n", "4\n4\n1 2 ... | coding | 631 |
Solve the programming task below in a Python markdown code block.
Piegirl was asked to implement two table join operation for distributed database system, minimizing the network traffic.
Suppose she wants to join two tables, A and B. Each of them has certain number of rows which are distributed on different number of ... | {"inputs": ["2 2\n2 6\n3 100\n", "1 1\n1889\n2867\n", "1 1\n1889\n2867\n", "2 2\n2 6\n3 100\n", "2 3\n10 10\n1 1 1\n", "2 3\n10 10\n1 1 2\n", "2 3\n10 10\n0 1 2\n", "2 3\n10 10\n0 1 0\n"], "outputs": ["11\n", "1889\n", "1889\n", "11\n", "6\n", "8\n", "6\n", "2\n"]} | coding | 386 |
Solve the programming task below in a Python markdown code block.
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef and his friend Bharat have decided to play the game "The Chefora Spell".
In the game, a positive integer N (in decimal system) is considered a "Chefora"... | {"inputs": ["2\n1 2\n9 11"], "outputs": ["1\n541416750"]} | coding | 533 |
Solve the programming task below in a Python markdown code block.
Kicker (table football) is a board game based on football, in which players control the footballers' figures mounted on rods by using bars to get the ball into the opponent's goal. When playing two on two, one player of each team controls the goalkeeper ... | {"inputs": ["1 1\n2 2\n3 3\n2 2\n", "3 3\n2 2\n1 1\n2 2\n", "8 7\n1 5\n7 4\n8 8\n", "8 3\n4 9\n6 1\n5 6\n", "6 2\n7 5\n5 4\n8 6\n", "4 1\n4 3\n6 4\n2 8\n", "8 7\n1 5\n7 4\n8 8\n", "4 1\n4 3\n6 4\n2 8\n"], "outputs": ["Team 2\n", "Draw\n", "Draw\n", "Team 1\n", "Draw\n", "Team 2\n", "Draw\n", "Team 2\n"]} | coding | 643 |
Solve the programming task below in a Python markdown code block.
Consider integer coordinates x, y in the Cartesian plan and three functions f, g, h
defined by:
```
f: 1 <= x <= n, 1 <= y <= n --> f(x, y) = min(x, y)
g: 1 <= x <= n, 1 <= y <= n --> g(x, y) = max(x, y)
h: 1 <= x <= n, 1 <= y <= n --> h(x, y) = x + y
``... | {"functional": "_inputs = [[5], [6], [8], [15], [100], [365], [730], [4000]]\n_outputs = [[55], [91], [204], [1240], [338350], [16275715], [129938905], [21341334000]]\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 | 713 |
Solve the programming task below in a Python markdown code block.
One day, little Vasya found himself in a maze consisting of (n + 1) rooms, numbered from 1 to (n + 1). Initially, Vasya is at the first room and to get out of the maze, he needs to get to the (n + 1)-th one.
The maze is organized as follows. Each room o... | {"inputs": ["1\n1\n", "1\n1\n", "2\n1 2\n", "2\n1 1\n", "2\n1 2\n", "3\n1 1 3\n", "3\n1 1 3\n", "3\n1 1 2\n"], "outputs": ["2\n", "2\n", "4\n", "6\n", "4\n", "8\n", "8\n", "12\n"]} | coding | 478 |
Solve the programming task below in a Python markdown code block.
Patrick has just finished writing a message to his sweetheart Stacey when he noticed that the message didn't look fancy. Patrick was nervous while writing the message, so some of the letters there were lowercase and some of them were uppercase.
Patrick ... | {"inputs": ["P\n", "t\n", "O\n", "s\n", "N\n", "r\n", "M\n", "q\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | coding | 289 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array of string words, return all strings in words that is a substring of another word. You can return the answer in any order.
A substring is a contiguous sequence of characters within a string
Please comp... | {"functional": "def check(candidate):\n assert candidate(words = [\"mass\",\"as\",\"hero\",\"superhero\"]) == [\"as\",\"hero\"]\n assert candidate(words = [\"leetcode\",\"et\",\"code\"]) == [\"et\",\"code\"]\n assert candidate(words = [\"blue\",\"green\",\"bu\"]) == []\n\n\ncheck(Solution().stringMatching)"} | coding | 90 |
Solve the programming task below in a Python markdown code block.
You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes.
You know two languages, and the professor is giving the lecture in the first one. The words in both lang... | {"inputs": ["1 1\na c\na\n", "1 1\na c\na\n", "1 1\namit am\namit\n", "1 1\namit am\namit\n", "1 1\namit ma\namit\n", "1 1\namit la\namit\n", "5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll\n", "5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll\n"], "outputs": ["a\n", "a "... | coding | 562 |
Solve the programming task below in a Python markdown code block.
*Debug* function `getSumOfDigits` that takes positive integer to calculate sum of it's digits. Assume that argument is an integer.
### Example
```
123 => 6
223 => 7
1337 => 15
```
Also feel free to reuse/extend the following starter code:
```python
... | {"functional": "_inputs = [[123], [223], [0]]\n_outputs = [[6], [7], [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 ... | coding | 98 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given two strings s and t, your goal is to convert s into t in k moves or less.
During the ith (1 <= i <= k) move you can:
Choose any index j (1-indexed) from s, such that 1 <= j <= s.length and j has not been chosen... | {"functional": "def check(candidate):\n assert candidate(s = \"input\", t = \"ouput\", k = 9) == True\n assert candidate(s = \"abc\", t = \"bcd\", k = 10) == False\n assert candidate(s = \"aab\", t = \"bbb\", k = 27) == True\n\n\ncheck(Solution().canConvertString)"} | coding | 250 |
Solve the programming task below in a Python markdown code block.
In this Kata, you will be given two integers `n` and `k` and your task is to remove `k-digits` from `n` and return the lowest number possible, without changing the order of the digits in `n`. Return the result as a string.
Let's take an example of `solv... | {"functional": "_inputs = [[123056, 1], [123056, 2], [123056, 3], [123056, 4], [1284569, 1], [1284569, 2], [1284569, 3], [1284569, 4]]\n_outputs = [['12056'], ['1056'], ['056'], ['05'], ['124569'], ['12456'], ['1245'], ['124']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, fl... | coding | 242 |
Solve the programming task below in a Python markdown code block.
You are given two points $P$ and $Q$ and an opaque sphere in a three-dimensional space. The point $P$ is not moving, while $Q$ is moving in a straight line with constant velocity. You are also given a direction vector $d$ with the following meaning: the ... | {"inputs": ["1\n3 0 0 -10 -10 0 0 10 0 0 -3 0 3"], "outputs": ["1.0000000000"]} | coding | 566 |
Solve the programming task below in a Python markdown code block.
You are given a grid with $R$ rows (numbered $1$ through $R$) and $C$ columns (numbered $1$ through $C$). A cell in row $r$ and column $c$ is denoted by $(r, c)$. Two cells in the grid are adjacent if they have a common side. For each valid $i$ and $j$, ... | {"inputs": ["2\n3 3\n1 2 1\n2 3 2\n1 2 1\n3 4\n0 0 0 0\n0 0 0 0\n0 0 4 0"], "outputs": ["Stable\nUnstable"]} | coding | 506 |
Solve the programming task below in a Python markdown code block.
-----Problem Statement-----
You all must have played the game candy crush. So here is a bomb which works much the fruit bomb in candy crush. A designer, Anton, designed a very powerful bomb. The bomb, when placed on a location $(x, y)$ in a $R \times C$ ... | {"inputs": ["2 3 3\n1 1\n0 0\n0 2"], "outputs": ["3"]} | coding | 421 |
Solve the programming task below in a Python markdown code block.
You are going to be given a string. Your job is to return that string in a certain order that I will explain below:
Let's say you start with this: `012345`
The first thing you do is reverse it:`543210`
Then you will take the string from the 1st posit... | {"functional": "_inputs = [['012'], ['012345'], ['0123456789'], ['Hello']]\n_outputs = [['201'], ['504132'], ['9081726354'], ['oHlel']]\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, (li... | coding | 229 |
Solve the programming task below in a Python markdown code block.
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese] and [Bengali] as well.
Chef Ada is training to defend her title of World Chess Champion.
To train her calculation skills, Ada placed a king on a chessboard. Remember that ... | {"inputs": ["1\n1 3 1"], "outputs": ["6"]} | coding | 394 |
Solve the programming task below in a Python markdown code block.
In this Kata, you will be given a string and your task is to determine if that string can be a palindrome if we rotate one or more characters to the left.
```Haskell
solve("4455") = true, because after 1 rotation, we get "5445" which is a palindrome
sol... | {"functional": "_inputs = [['aaab'], ['abcabc'], ['4455'], ['zazcbaabc'], ['223456776543'], ['432612345665'], ['qponmlkjihgfeeiefghijklmnopqrsttsr']]\n_outputs = [[False], [False], [True], [True], [True], [False], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):... | coding | 149 |
Solve the programming task below in a Python markdown code block.
Given is a string S consisting of `0` and `1`. Find the number of strings, modulo 998244353, that can result from applying the following operation on S between 0 and K times (inclusive):
* Choose a pair of integers i, j (1\leq i < j\leq |S|) such that t... | {"inputs": ["0111 1", "0111 0", "0011 1", "0001 1", "0011 2", "0101 5", "0011 0", "0101 1"], "outputs": ["2\n", "1\n", "3\n", "4\n", "6\n", "5\n", "1\n", "4"]} | coding | 346 |
Solve the programming task below in a Python markdown code block.
You can perfectly predict the price of a certain stock for the next N days. You would like to profit on this knowledge, but only want to transact one share of stock per day. That is, each day you will either buy one share, sell one share, or do nothing. ... | {"inputs": ["2\n4 2\n", "2\n3 2\n", "2\n5 2\n", "2\n5 4\n", "2\n5 0\n", "2\n4 77\n", "2\n4 77\n", "2\n10 0\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "73\n", "73\n", "0\n"]} | coding | 377 |
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"]} | coding | 619 |
Solve the programming task below in a Python markdown code block.
Chef has a calculator which has two screens and two buttons. Initially, each screen shows the number zero. Pressing the first button increments the number on the first screen by 1, and each click of the first button consumes 1 unit of energy.
Pressing th... | {"inputs": ["3\n10 2\n8 5\n6 1"], "outputs": ["12\n3\n9"]} | coding | 489 |
Solve the programming task below in a Python markdown code block.
An n × n table a is defined as follows:
The first row and the first column contain ones, that is: a_{i}, 1 = a_{1, }i = 1 for all i = 1, 2, ..., n. Each of the remaining numbers in the table is equal to the sum of the number above it and the number t... | {"inputs": ["1\n", "5\n", "2\n", "3\n", "4\n", "6\n", "7\n", "9\n"], "outputs": ["1", "70", "2", "6", "20", "252", "924", "12870"]} | coding | 345 |
Solve the programming task below in a Python markdown code block.
Calculate the value of the sum: n mod 1 + n mod 2 + n mod 3 + ... + n mod m. As the result can be very large, you should print the value modulo 10^9 + 7 (the remainder when divided by 10^9 + 7).
The modulo operator a mod b stands for the remainder after... | {"inputs": ["3 4\n", "4 4\n", "1 1\n", "3 3\n", "4 1\n", "3 4\n", "4 4\n", "1 1\n"], "outputs": ["4\n", "1\n", "0\n", "1", "0", "4\n", "1\n", "0\n"]} | coding | 194 |
Solve the programming task below in a Python markdown code block.
Three companies decided to order a billboard with pictures of their logos. A billboard is a big square board. A logo of each company is a rectangle of a non-zero area.
Advertisers will put up the ad only if it is possible to place all three logos on th... | {"inputs": ["5 1 2 5 5 2\n", "4 4 2 6 4 2\n", "1 3 1 3 3 1\n", "2 4 1 4 1 4\n", "7 2 7 2 7 3\n", "2 1 3 1 2 2\n", "1 2 2 4 3 2\n", "7 4 3 3 4 3\n"], "outputs": ["5\nAAAAA\nBBBBB\nBBBBB\nCCCCC\nCCCCC\n", "6\nBBBBBB\nBBBBBB\nAAAACC\nAAAACC\nAAAACC\nAAAACC\n", "3\nAAA\nBBB\nCCC\n", "4\nAAAA\nAAAA\nBBBB\nCCCC\n", "7\nAAAAA... | coding | 535 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
A string is beautiful if:
It consists of the first k letters of the English lowercase alphabet.
It does not contain any substring of length 2 or more which is a palindrome.
You are given a beautiful string s of leng... | {"functional": "def check(candidate):\n assert candidate(s = \"abcz\", k = 26) == \"abda\"\n assert candidate(s = \"dc\", k = 4) == \"\"\n\n\ncheck(Solution().smallestBeautifulString)"} | coding | 213 |
Solve the programming task below in a Python markdown code block.
We have a permutation of the integers from 1 through N, p_1, p_2, .., p_N.
We also have M pairs of two integers between 1 and N (inclusive), represented as (x_1,y_1), (x_2,y_2), .., (x_M,y_M).
AtCoDeer the deer is going to perform the following operation... | {"inputs": ["3 2\n3 2 1\n1 2\n2 3\n", "5 1\n1 2 3 4 5\n1 5\n", "5 2\n5 3 1 4 2\n1 3\n5 4\n", "10 8\n5 3 6 8 7 10 9 1 2 4\n3 1\n4 1\n5 9\n2 5\n6 5\n3 5\n8 9\n7 9\n"], "outputs": ["3\n", "5\n", "2\n", "8\n"]} | coding | 387 |
Solve the programming task below in a Python markdown code block.
The integer ```64``` is the first integer that has all of its digits even and furthermore, is a perfect square.
The second one is ```400``` and the third one ```484```.
Give the numbers of this sequence that are in the range ```[a,b] ```(both values in... | {"functional": "_inputs = [[100, 1000], [1000, 4000], [10000, 40000]]\n_outputs = [[[400, 484]], [[]], [[26244, 28224, 40000]]]\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, tupl... | coding | 243 |
Solve the programming task below in a Python markdown code block.
Iroha has a sequence of N strings S_1, S_2, ..., S_N. The length of each string is L.
She will concatenate all of the strings in some order, to produce a long string.
Among all strings that she can produce in this way, find the lexicographically smallest... | {"inputs": ["3 3\ndxx\naxx\ndxx", "3 3\ndxx\naxx\nxxd", "3 3\ndxx\nxxa\nxxd", "3 3\ncxx\nxxa\nxxd", "3 3\ndxx\n`xx\ncxx", "3 3\nxdx\naxx\ndxx", "3 3\nxxd\naxx\nxxd", "3 3\nxxd\nxxa\nxxd"], "outputs": ["axxdxxdxx\n", "axxdxxxxd\n", "dxxxxaxxd\n", "cxxxxaxxd\n", "`xxcxxdxx\n", "axxdxxxdx\n", "axxxxdxxd\n", "xxaxxdxxd\n"]... | coding | 319 |
Solve the programming task below in a Python markdown code block.
Cowboy Vlad has a birthday today! There are $n$ children who came to the celebration. In order to greet Vlad, the children decided to form a circle around him. Among the children who came, there are both tall and low, so if they stand in a circle arbitra... | {"inputs": ["2\n8 1\n", "2\n5 32\n", "2\n5 42\n", "2\n5 28\n", "2\n5 16\n", "2\n5 27\n", "2\n5 17\n", "2\n9 17\n"], "outputs": ["1 8\n", "5 32\n", "5 42\n", "5 28\n", "5 16\n", "5 27\n", "5 17\n", "9 17\n"]} | coding | 558 |
Solve the programming task below in a Python markdown code block.
You are an upcoming movie director, and you have just released your first movie. You have also launched a simple review site with two buttons to press — upvote and downvote.
However, the site is not so simple on the inside. There are two servers, each w... | {"inputs": ["1\n1\n2\n", "1\n1\n2\n", "1\n1\n3\n", "1\n1\n1\n", "4\n1\n2\n3\n1 2 3\n5\n1 1 1 1 1\n3\n3 3 2\n", "4\n1\n2\n3\n1 3 3\n5\n1 1 1 1 1\n3\n3 3 2\n", "4\n1\n1\n3\n1 3 3\n5\n1 1 1 1 1\n3\n3 3 2\n", "4\n1\n1\n3\n1 3 3\n5\n1 1 1 1 1\n3\n3 3 3\n"], "outputs": ["0\n", "0\n", "1\n", "1\n", "0\n2\n5\n2\n", "0\n3\n5\n2... | coding | 674 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer array arr and an integer k, modify the array by repeating it k times.
For example, if arr = [1, 2] and k = 3 then the modified array will be [1, 2, 1, 2, 1, 2].
Return the maximum sub-array sum in the... | {"functional": "def check(candidate):\n assert candidate(arr = [1,2], k = 3) == 9\n assert candidate(arr = [1,-2,1], k = 5) == 2\n assert candidate(arr = [-1,-2], k = 7) == 0\n\n\ncheck(Solution().kConcatenationMaxSum)"} | coding | 169 |
Solve the programming task below in a Python markdown code block.
Takahashi has a lot of peculiar devices. These cylindrical devices receive balls from left and right. Each device is in one of the two states A and B, and for each state, the device operates as follows:
* When a device in state A receives a ball from ei... | {"inputs": ["5 1\nAAAAA", "5 2\nAAABA", "5 1\nAAABA", "5 3\nAAABA", "5 1\nAAAAB", "5 2\nAAAAA", "5 1\nAAABB", "5 3\nAAAAA"], "outputs": ["BAAAA\n", "BBABA\n", "BAABA\n", "ABABA\n", "BAAAB\n", "BBBBA\n", "BAABB\n", "AAABA\n"]} | coding | 525 |
Solve the programming task below in a Python markdown code block.
Pak Chanek has a prime number$^\dagger$ $n$. Find a prime number $m$ such that $n + m$ is not prime.
$^\dagger$ A prime number is a number with exactly $2$ factors. The first few prime numbers are $2,3,5,7,11,13,\ldots$. In particular, $1$ is not a prim... | {"inputs": ["1\n65777\n", "3\n7\n2\n75619\n", "55\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n"], "outputs": ["65777\n", "7\n2\n75619\n", "7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\... | coding | 418 |
Solve the programming task below in a Python markdown code block.
Luba has to do n chores today. i-th chore takes a_{i} units of time to complete. It is guaranteed that for every $i \in [ 2 . . n ]$ the condition a_{i} ≥ a_{i} - 1 is met, so the sequence is sorted.
Also Luba can work really hard on some chores. She ca... | {"inputs": ["1 1 1\n100\n", "1 1 1\n100\n", "1 1 1\n110\n", "1 1 2\n100\n", "1 1 2\n110\n", "1 1 2\n101\n", "4 2 2\n3 6 7 10\n", "4 4 2\n3 6 7 10\n"], "outputs": ["1\n", "1\n", "1\n", "2\n", "2\n", "2\n", "13\n", "8\n"]} | coding | 514 |
Solve the programming task below in a Python markdown code block.
Find the length between 2 co-ordinates. The co-ordinates are made of integers between -20 and 20 and will be given in the form of a 2D array:
(0,0) and (5,-7) would be [ [ 0 , 0 ] , [ 5, -7 ] ]
The function must return the answer rounded to 2 decimal ... | {"functional": "_inputs = [[[[0, 0], [1, 1]]], [[[0, 0], [-5, -6]]], [[[0, 0], [10, 15]]], [[[0, 0], [5, 1]]], [[[0, 0], [5, 4]]], [[[0, 0], [-7, 4]]], [[[0, 0], [0, 0]]], [[[-3, 4], [10, 5]]]]\n_outputs = [['1.41'], ['7.81'], ['18.03'], ['5.10'], ['6.40'], ['8.06'], ['0.00'], ['13.04']]\nimport math\ndef _deep_eq(a, b... | coding | 175 |
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)"} | coding | 217 |
Solve the programming task below in a Python markdown code block.
Let's say take 2 strings, A and B, and define the similarity of the strings to be the length of the longest prefix common to both strings. For example, the similarity of strings `abc` and `abd` is 2, while the similarity of strings `aaa` and `aaab` is 3.... | {"functional": "_inputs = [['aa'], ['abc'], ['ababaa'], ['aaaa'], ['aaaaa'], ['aaaaaa'], ['mnsomn'], ['apple'], ['a'], ['pippi']]\n_outputs = [[3], [3], [11], [10], [15], [21], [8], [5], [1], [8]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.iscl... | coding | 286 |
Solve the programming task below in a Python markdown code block.
Katie, Kuro and Shiro are best friends. They have known each other since kindergarten. That's why they often share everything with each other and work together on some very hard problems.
Today is Shiro's birthday. She really loves pizza so she wants to... | {"inputs": ["3\n", "4\n", "0\n", "1\n", "2\n", "7\n", "8\n", "2\n"], "outputs": ["2", "5", "0", "1", "3", "4", "9", "3\n"]} | coding | 394 |
Solve the programming task below in a Python markdown code block.
You are given a book with n chapters.
Each chapter has a specified list of other chapters that need to be understood in order to understand this chapter. To understand a chapter, you must read it after you understand every chapter on its required list.
... | {"inputs": ["5\n4\n1 2\n0\n2 1 4\n1 2\n5\n1 5\n1 1\n1 1\n1 3\n1 4\n5\n0\n0\n2 1 2\n1 2\n2 2 1\n4\n2 2 3\n0\n0\n2 3 2\n5\n1 2\n1 3\n1 4\n1 5\n0\n", "5\n4\n1 2\n0\n2 1 4\n1 2\n5\n1 5\n1 1\n1 1\n1 3\n1 4\n5\n0\n0\n2 1 2\n1 2\n2 2 1\n4\n2 2 3\n0\n0\n2 3 2\n5\n1 2\n1 3\n1 4\n1 3\n0\n", "5\n4\n1 2\n0\n2 1 4\n1 2\n5\n1 5\n1 1... | coding | 652 |
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 fronts and backs of length n, where the ith card has the positive integer fronts[i] printed on the front and backs[i] printed on the back. Initially, each card is placed on a... | {"functional": "def check(candidate):\n assert candidate(fronts = [1,2,4,4,7], backs = [1,3,4,1,3]) == 2\n assert candidate(fronts = [1], backs = [1]) == 0\n\n\ncheck(Solution().flipgame)"} | coding | 178 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer array nums, return the sum of floor(nums[i] / nums[j]) for all pairs of indices 0 <= i, j < nums.length in the array. Since the answer may be too large, return it modulo 109 + 7.
The floor() function ... | {"functional": "def check(candidate):\n assert candidate(nums = [2,5,9]) == 10\n assert candidate(nums = [7,7,7,7,7,7,7]) == 49\n\n\ncheck(Solution().sumOfFlooredPairs)"} | coding | 118 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an array points containing the coordinates of points on a 2D plane, sorted by the x-values, where points[i] = [xi, yi] such that xi < xj for all 1 <= i < j <= points.length. You are also given an integer... | {"functional": "def check(candidate):\n assert candidate(points = [[1,3],[2,0],[5,10],[6,-10]], k = 1) == 4\n assert candidate(points = [[0,0],[3,0],[9,2]], k = 3) == 3\n\n\ncheck(Solution().findMaxValueOfEquation)"} | coding | 180 |
Solve the programming task below in a Python markdown code block.
Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese] and [Bengali] as well.
A permutation is an array consisting of $N$ distinct integers from $1$ to $N$ in arbitrary order.
Chef has two permutation arrays $A$ and $P$ of length $N$. ... | {"inputs": ["1\n 3\n 1 2 3\n 2 3 1\n 3\n 1\n 2 2 3\n 3 1"], "outputs": ["3"]} | coding | 568 |
Solve the programming task below in a Python markdown code block.
Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number a and Antisimon receives number b. They also have a heap of n stones. The players take turns to make... | {"inputs": ["1 1 2\n", "2 2 1\n", "2 1 1\n", "2 1 2\n", "4 2 5\n", "1 2 1\n", "9 5 1\n", "1 1 1\n"], "outputs": ["1\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | coding | 586 |
Solve the programming task below in a Python markdown code block.
Let us consider a grid of squares with 10^9 rows and N columns. Let (i, j) be the square at the i-th column (1 \leq i \leq N) from the left and j-th row (1 \leq j \leq 10^9) from the bottom.
Snuke has cut out some part of the grid so that, for each i = ... | {"inputs": ["2\n4 2", "2\n2 2", "5\n2 1 2 1 2", "9\n3 3 5 4 1 2 4 2 1", "9\n2 3 7 4 1 2 4 2 1", "9\n2 3 4 4 1 2 4 2 1", "9\n2 3 2 4 1 2 4 2 1", "9\n2 3 2 4 1 2 4 2 2"], "outputs": ["24", "6", "256", "11520", "51200", "6400", "23040", "20736"]} | coding | 462 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a binary string binary. A subsequence of binary is considered good if it is not empty and has no leading zeros (with the exception of "0").
Find the number of unique good subsequences of binary.
For exa... | {"functional": "def check(candidate):\n assert candidate(binary = \"001\") == 2\n assert candidate(binary = \"11\") == 2\n assert candidate(binary = \"101\") == 5\n\n\ncheck(Solution().numberOfUniqueGoodSubsequences)"} | coding | 221 |
Solve the programming task below in a Python markdown code block.
You have decided to watch the best moments of some movie. There are two buttons on your player: Watch the current minute of the movie. By pressing this button, you watch the current minute of the movie and the player automatically proceeds to the next ... | {"inputs": ["1 1\n1 1\n", "1 3\n5 6\n", "1 2\n1 1\n", "1 1\n1 1\n", "1 3\n5 6\n", "1 2\n1 1\n", "1 3\n3 6\n", "1 4\n3 6\n"], "outputs": ["1\n", "3\n", "1\n", "1\n", "3\n", "1\n", "6\n", "6\n"]} | coding | 593 |
Solve the programming task below in a Python markdown code block.
Find the sum of the weights of edges of the Minimum-Cost Arborescence with the root r for a given weighted directed graph G = (V, E).
Constraints
* 1 ≤ |V| ≤ 100
* 0 ≤ |E| ≤ 1,000
* 0 ≤ wi ≤ 10,000
* G has arborescence(s) with the root r
Input
|V| |... | {"inputs": ["4 6 0\n0 1 3\n0 2 2\n2 0 1\n2 3 2\n3 0 1\n3 1 5", "4 6 0\n0 1 1\n0 2 2\n2 0 1\n2 3 2\n3 0 1\n3 1 5", "4 6 0\n0 1 1\n0 2 2\n3 1 1\n2 3 3\n3 0 0\n0 1 7", "4 6 0\n0 1 1\n0 2 2\n2 0 1\n2 3 0\n3 1 1\n3 1 5", "4 5 0\n0 1 4\n0 2 2\n3 1 1\n1 3 3\n3 0 0\n0 1 9", "4 5 0\n0 1 2\n0 2 3\n3 1 1\n1 3 3\n3 0 0\n0 1 9", "4... | coding | 371 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed m x n binary matrix grid.
In one operation, you can choose any i and j that meet the following conditions:
0 <= i < m
0 <= j < n
grid[i][j] == 1
and change the values of all cells in row i ... | {"functional": "def check(candidate):\n assert candidate(grid = [[1,1,1],[1,1,1],[0,1,0]]) == 2\n assert candidate(grid = [[0,1,0],[1,0,1],[0,1,0]]) == 2\n assert candidate(grid = [[0,0],[0,0]]) == 0\n\n\ncheck(Solution().removeOnes)"} | coding | 135 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an array nums consisting of positive integers.
You can perform the following operation on the array any number of times:
Choose any two adjacent elements and replace them with their sum.
For example,... | {"functional": "def check(candidate):\n assert candidate(nums = [4,3,2,1,2,3,1]) == 2\n assert candidate(nums = [1,2,3,4]) == 3\n\n\ncheck(Solution().minimumOperations)"} | coding | 132 |
Solve the programming task below in a Python markdown code block.
Consider an array A consisting of N positive elements. The *frequency array* of A is the array B of size N such that B_{i} = *frequency* of element A_{i} in A.
For example, if A = [4, 7, 4, 11, 2, 7, 7], the *frequency array* B = [2, 3, 2, 1, 1, 3, 3].
... | {"inputs": ["5\n5\n2 3 3 3 2\n5\n1 1 1 1 1\n5\n5 5 5 5 5\n3\n1 2 4\n8\n1 3 2 3 2 2 2 3"], "outputs": ["1 2 2 2 1\n1 2 3 4 5\n1 1 1 1 1\n-1\n1 2 3 2 3 4 4 2\n"]} | coding | 761 |
Solve the programming task below in a Python markdown code block.
Thanos wants to destroy the avengers base, but he needs to destroy the avengers along with their base.
Let we represent their base with an array, where each position can be occupied by many avengers, but one avenger can occupy only one position. Length ... | {"inputs": ["1 1 5 6\n1\n", "1 1 5 6\n1\n", "1 1 7 6\n1\n", "1 1 5 2\n1\n", "1 1 7 0\n1\n", "2 1 5 2\n1\n", "1 1 7 -1\n1\n", "1 1 7 -2\n2\n"], "outputs": ["11\n", "11", "12\n", "4\n", "0\n", "8\n", "-2\n", "-4\n"]} | coding | 650 |
Solve the programming task below in a Python markdown code block.
You have given an array $a$ of length $n$ and an integer $x$ to a brand new robot. What the robot does is the following: it iterates over the elements of the array, let the current element be $q$. If $q$ is divisible by $x$, the robot adds $x$ copies of ... | {"inputs": ["2\n1 2\n12\n4 2\n4 6 8 2\n", "2\n1 2\n12\n4 2\n4 6 4 2\n", "2\n1 2\n12\n4 2\n7 6 4 2\n", "2\n1 2\n12\n4 2\n7 6 5 2\n", "2\n1 2\n12\n4 2\n7 6 3 2\n", "2\n1 2\n12\n4 2\n7 6 6 2\n", "2\n1 2\n1\n4 2\n2 11 8 2\n", "2\n1 2\n12\n4 4\n7 6 3 1\n"], "outputs": ["36\n44\n", "36\n36\n", "36\n19\n", "36\n20\n", "36\n18... | coding | 626 |
Solve the programming task below in a Python markdown code block.
After a long journey, the super-space-time immigrant ship carrying you finally discovered a planet that seems to be habitable. The planet, named JOI, is a harsh planet with three types of terrain, "Jungle," "Ocean," and "Ice," as the name implies. A simp... | {"inputs": ["4 7\n4\nJIOJOIJ\nIOJOIJO\nJOIJOOI\nOOJJIJO\n5 5 4 7\n2 2 3 6\n2 2 2 2\n1 1 4 7", "4 7\n4\nJIOJOIJ\nOJIOJOI\nJOIJOOI\nOOJJIJO\n5 5 4 7\n2 2 3 6\n2 2 2 2\n1 1 4 7", "4 7\n4\nJIOJOIJ\nOJIOJOI\nJOIJOOI\nOOJJIJO\n5 7 4 7\n2 2 3 6\n2 2 2 2\n1 1 1 7", "4 7\n4\nJIOJOIJ\nOJIOJOI\nJOIJOOI\nOOJJIJO\n5 7 4 7\n2 2 3 6\... | coding | 654 |
Solve the programming task below in a Python markdown code block.
Pupils decided to go to amusement park. Some of them were with parents. In total, n people came to the park and they all want to get to the most extreme attraction and roll on it exactly once.
Tickets for group of x people are sold on the attraction, th... | {"inputs": ["1 2 2\n1\n", "1 2 2\n1\n", "1 4 2\n1\n", "1 6 2\n1\n", "1 2 4\n1\n", "1 4 0\n1\n", "1 6 1\n1\n", "1 2 5\n1\n"], "outputs": ["2\n", "2\n", "4\n", "6\n", "2\n", "4\n", "6\n", "2\n"]} | coding | 539 |
Solve the programming task below in a Python markdown code block.
Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct the minimal number of... | {"inputs": ["1\n1\n", "1\n2\n", "1\n1000\n", "3\n1 2 2\n", "3\n1 2 1\n", "3\n1 2 3\n", "3\n2 1 16\n", "3\n3 1 16\n"], "outputs": ["1 1\n", "1 1\n", "1 1\n", "2 2\n", "2 2\n", "1 3\n", "1 3\n", "1 3\n"]} | coding | 218 |
Solve the programming task below in a Python markdown code block.
There is a new mobile game that starts with consecutively numbered clouds. Some of the clouds are thunderheads and others are cumulus. The player can jump on any cumulus cloud having a number that is equal to the number of the current cloud plus $\mbox... | {"inputs": ["6\n0 0 0 0 1 0\n", "7\n0 0 1 0 0 1 0\n"], "outputs": ["3\n", "4\n"]} | coding | 572 |
Solve the programming task below in a Python markdown code block.
You are given a spreadsheet that contains a list of $N$ athletes and their details (such as age, height, weight and so on). You are required to sort the data based on the $K^{th}$ attribute and print the final resulting table. Follow the example given be... | {"inputs": ["5 3\n10 2 5\n7 1 0\n9 9 9\n1 23 12\n6 5 9\n1\n"], "outputs": ["7 1 0\n10 2 5\n6 5 9\n9 9 9\n1 23 12\n"]} | coding | 375 |
Solve the programming task below in a Python markdown code block.
Probably everyone has experienced an awkward situation due to shared armrests between seats in cinemas. A highly accomplished cinema manager named "Chef" decided to solve this problem.
When a customer wants to buy a ticket, the clerk at the ticket windo... | {"inputs": ["2\n2 2 3 2 1 1\n3 3 1 2 0 9"], "outputs": ["4\n8"]} | coding | 531 |
Solve the programming task below in a Python markdown code block.
Skyscraper "MinatoHarukas"
Mr. Port plans to start a new business renting one or more floors of the new skyscraper with one giga floors, MinatoHarukas. He wants to rent as many vertically adjacent floors as possible, because he wants to show advertiseme... | {"inputs": ["15\n6\n2\n3\n2360136\n434020716\n332845831\n6280939\n987698769\n999999999\n0", "15\n16\n2\n3\n8678728\n223092870\n332845831\n6280939\n987698769\n999999999\n0", "15\n16\n2\n3\n8678728\n434020716\n332845831\n6280939\n987698769\n999999999\n0", "15\n6\n2\n3\n9699690\n116276261\n840868300\n986291783\n565625340\... | coding | 753 |
Solve the programming task below in a Python markdown code block.
## Story
> "You have serious coding skillz? You wannabe a [scener](https://en.wikipedia.org/wiki/Demoscene)? Complete this mission and u can get in teh crew!"
You have read a similar message on your favourite [diskmag](https://en.wikipedia.org/wiki/Dis... | {"functional": "_inputs = [['Hello World!', 3, 10], [\"I'm a Codewars warrior lately...\", 5, 18]]\n_outputs = [[' H\\n e\\n l\\n l\\n o\\n \\n W\\no\\nr\\n l\\n d\\n !'], [\" I\\n '\\n m\\n \\n a\\n \\n C\\n o\\n d\\n e\... | coding | 498 |
Solve the programming task below in a Python markdown code block.
Everyone Knows AdFly and their Sister Sites.
If we see the Page Source of an ad.fly site we can see this perticular line:
Believe it or not This is actually the Encoded url which you would skip to.
The Algorithm is as Follows:
```
1) The ysmm value is ... | {"functional": "_inputs = [['O=T0ZToPdRHJRmwdcOz1oGvTL22lFzkRZhih5GsbezSw9kndbvyR50wYawHIAF/SdhT1'], ['N=z0dDoMdyHIRmwac1zMolvWLz2RFmkMZiiZ5HsZeySw9kndbvyR50wYawHIAF/SdhT1'], ['lololol']]\n_outputs = [['http://yahoo.com'], ['http://google.com'], ['Invalid']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstanc... | coding | 326 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
There is a hotel with n rooms. The rooms are represented by a 2D integer array rooms where rooms[i] = [roomIdi, sizei] denotes that there is a room with room number roomIdi and size equal to sizei. Each roomIdi is gua... | {"functional": "def check(candidate):\n assert candidate(rooms = [[2,2],[1,2],[3,2]], queries = [[3,1],[3,3],[5,2]]) == [3,-1,3]\n assert candidate(rooms = [[1,4],[2,3],[3,5],[4,1],[5,2]], queries = [[2,3],[2,4],[2,5]]) == [2,1,3]\n\n\ncheck(Solution().closestRoom)"} | coding | 246 |
Solve the programming task below in a Python markdown code block.
Little Raju recently learnt about binary numbers. After spending some time with it, he decided to count in how many ways he can make N digit numbers that is formed by ones and zeroes. But zeroes can not be next to each other. Help him finding in how many... | {"inputs": ["5\n2\n8\n12\n16\n34", "5\n99\n44\n18\n999\n66", "4\n4521\n994\n5000\n10000"], "outputs": ["3\n55\n377\n2584\n14930352", "573147844013817084101\n1836311903\n6765\n7033036771142281582183525487718354977018126983635873274260490508715453711819693357974224949456261173348775044924176599108818636326545022364710601... | coding | 188 |
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian.
Recently Chef bought a bunch of robot-waiters. And now he needs to know how much to pay for the electricity that robots use for their work. All waiters serve food from the kitchen (which is in ... | {"inputs": ["2\n3 3\n3 4", "2\n3 3\n3 0", "2\n5 3\n3 0", "2\n5 3\n6 0", "2\n5 3\n6 1", "2\n5 2\n6 1", "2\n3 2\n6 1", "2\n1 2\n6 1"], "outputs": ["6\n7", "6\n7\n", "10\n7\n", "10\n12\n", "10\n13\n", "11\n13\n", "7\n13\n", "3\n13\n"]} | coding | 321 |
Solve the programming task below in a Python markdown code block.
Chef has a grid of size N \times M.
In one move, Chef can move from his current cell to an adjacent cell. If the Chef is currently at (i, j) then, in one move, Chef can move to (i + 1, j), (i - 1, j), (i, j + 1) or (i, j - 1).
There are also K *specia... | {"inputs": ["2\n3 3 0\n3 3 2\n2 2\n2 3\n"], "outputs": ["4\n3\n"]} | coding | 691 |
Solve the programming task below in a Python markdown code block.
This is the hard version of this problem. The only difference between the easy and hard versions is the constraints on $k$ and $m$. In this version of the problem, you need to output the answer by modulo $10^9+7$.
You are given a sequence $a$ of length ... | {"inputs": ["3\n1 1 1\n1\n1 1 1\n1\n1 1 1\n1\n", "4\n4 3 2\n1 2 4 3\n4 2 1\n1 1 1 1\n1 1 1\n1\n10 4 3\n5 6 1 3 2 9 8 1 2 4\n", "4\n4 3 2\n1 2 4 3\n4 3 2\n1 1 1 1\n1 3 1\n1\n10 3 2\n5 6 1 3 2 9 8 1 2 4\n"], "outputs": ["1\n1\n1\n", "2\n6\n1\n20\n", "2\n4\n0\n15\n"]} | coding | 702 |
Solve the programming task below in a Python markdown code block.
A population of bears consists of black bears, brown bears, and white bears.
The input is an array of two elements.
Determine whether the offspring of the two bears will return `'black'`, `'brown'`, `'white'`, `'dark brown'`, `'grey'`, `'light brown'`... | {"functional": "_inputs = [[['black', 'black']], [['white', 'white']], [['brown', 'brown']], [['black', 'brown']], [['black', 'white']], [['white', 'brown']], [['pink', 'black']]]\n_outputs = [['black'], ['white'], ['brown'], ['dark brown'], ['grey'], ['light brown'], ['unknown']]\nimport math\ndef _deep_eq(a, b, tol=1... | coding | 226 |
Solve the programming task below in a Python markdown code block.
Gru has not been in the limelight for a long time and is, therefore, planning something particularly nefarious. Frustrated by his minions' incapability which has kept him away from the limelight, he has built a transmogrifier — a machine which mutates mi... | {"inputs": ["1\n5 2\n0 4 1 3 1", "1\n5 0\n0 4 0 7 1", "1\n5 0\n1 0 0 0 0", "1\n5 3\n2 4 1 3 1", "1\n5 3\n2 4 0 3 1", "1\n5 3\n0 4 0 3 1", "1\n5 3\n0 4 1 3 1", "1\n5 2\n0 4 1 5 1"], "outputs": ["0\n", "3\n", "4\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | coding | 396 |
Solve the programming task below in a Python markdown code block.
Create the function ```consecutive(arr)``` that takes an array of integers and return the minimum number of integers needed to make the contents of ```arr``` consecutive from the lowest number to the highest number.
For example: If ```arr``` contains [4... | {"functional": "_inputs = [[[4, 8, 6]], [[1, 2, 3, 4]], [[]], [[1]], [[-10]], [[1, -1]], [[-10, -9]], [[0]], [[10, -10]], [[-10, 10]]]\n_outputs = [[2], [0], [0], [0], [0], [1], [0], [0], [19], [19]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.i... | coding | 139 |
Solve the programming task below in a Python markdown code block.
Bohan loves milk tea so much and he drinks one cup of milk tea every day. The local shop sells milk tea in two sizes: a Medium cup for $3 and a Large cup for $4. For every cup of milk tea purchased Bohan receives a promotional stamp. Bohan may redeem 6 s... | {"inputs": ["3\nMLM\nMMLLMMLL\nMMMMMMML"], "outputs": ["10\n24\n22"]} | coding | 355 |
Solve the programming task below in a Python markdown code block.
You are given an array with $N$ integers: $A[1], A[2], \ldots, A[N]$ (where $N$ is even). You are allowed to permute the elements however you want. Say, after permuting the elements, you end up with the array $A'[1], A'[2], \ldots, A'[N]$. Your goal is t... | {"inputs": ["1\n4\n1 -3 2 -3"], "outputs": ["9"]} | coding | 583 |
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 has two strings a and b of... | {"inputs": ["7\n4\n", "7\n7\n", "4\n7\n", "4\n4\n", "4\n46\n", "47\n77\n", "47\n47\n", "47\n44\n"], "outputs": ["1\n", "0\n", "1\n", "0\n", "0\n", "1\n", "0\n", "1\n"]} | coding | 342 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two positive integer arrays nums and numsDivide. You can delete any number of elements from nums.
Return the minimum number of deletions such that the smallest element in nums divides all the elements of... | {"functional": "def check(candidate):\n assert candidate(nums = [2,3,2,4,3], numsDivide = [9,6,9,3,15]) == 2\n assert candidate(nums = [4,3,6], numsDivide = [8,2,6,10]) == -1\n\n\ncheck(Solution().minOperations)"} | coding | 126 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are climbing a staircase. It takes n steps to reach the top.
Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?
Please complete the following python code precisely:
... | {"functional": "def check(candidate):\n assert candidate(n = 2) == 2\n assert candidate(n = 3) == 3\n\n\ncheck(Solution().climbStairs)"} | coding | 88 |
Solve the programming task below in a Python markdown code block.
ChthollyNotaSeniorious received a special gift from AquaMoon: $n$ binary arrays of length $m$. AquaMoon tells him that in one operation, he can choose any two arrays and any position $pos$ from $1$ to $m$, and swap the elements at positions $pos$ in thes... | {"inputs": ["3\n3 4\n1 1 1 0\n0 0 1 0\n1 0 0 1\n4 3\n1 0 0\n0 1 1\n0 0 1\n0 0 0\n2 2\n0 0\n0 1\n"], "outputs": ["1\n2 1 1\n1\n4 2 2\n-1\n"]} | coding | 686 |
Solve the programming task below in a Python markdown code block.
Problem statement:
Kiran P.S wrote some text on a piece of paper and now he wants to know
how many star characters are in the text.
If you think of the paper as the plane and a letter as a curve on the plane, then each letter divides the plane into re... | {"inputs": ["5\nBACKTOTHEFUTURE\nPIRAMIDOFEGYPT\nROMANCE\nINSTITUTEOFELECTRICALANDELECTRONICSENGINEERING\nTHISISTHETESTCASEEERING", "5\nOAXTJYRHRPXKBZCRTSQTUSTQPQZWOMXGPUPMYTOZEKFJPANKMK\nGATLIOYAJSKNAAQVRBDVCXJNLRKSGWANRIIVIEMCIIYZJJMXNSNZXWYSQLXFNHTLJKDR\nHWOKJWVEHBKRYRDIKVHLAVCCKV\nUPHWPQKUBCUDOQNVKBAPIGDCZFOZEGCDPO... | coding | 302 |
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
You are given a score log of a football match between two teams. Every time when one of the teams scored a goal, the name of that team was written in the score log on a separ... | {"inputs": ["2\n4\nab\nbc\nbc\nab\n3\nxxx\nyyy\nyyy"], "outputs": ["Draw\nyyy"]} | coding | 361 |
Solve the programming task below in a Python markdown code block.
On Children's Day, the child got a toy from Delayyy as a present. However, the child is so naughty that he can't wait to destroy the toy.
The toy consists of n parts and m ropes. Each rope links two parts, but every pair of parts is linked by at most on... | {"inputs": ["1 0\n545\n", "1 0\n493\n", "1 0\n358\n", "1 0\n420\n", "1 0\n149\n", "1 0\n249\n", "1 0\n654\n", "1 0\n294\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | coding | 613 |
Solve the programming task below in a Python markdown code block.
Given a tree T with non-negative weight, find the height of each node of the tree. For each node, the height is the distance to the most distant leaf from the node.
Constraints
* 1 ≤ n ≤ 10,000
* 0 ≤ wi ≤ 1,000
Input
n
s1 t1 w1
s2 t2 w2
:
sn-1 tn-1 ... | {"inputs": ["4\n0 2 2\n1 2 1\n1 3 3", "4\n0 1 2\n1 2 2\n1 3 3", "4\n0 1 2\n1 2 1\n2 3 3", "4\n0 1 2\n1 2 0\n1 3 3", "4\n0 2 2\n1 2 1\n2 3 3", "4\n0 1 2\n1 2 0\n0 3 3", "4\n0 1 0\n1 2 0\n1 3 3", "4\n0 1 2\n0 2 0\n0 3 3"], "outputs": ["6\n3\n4\n6\n", "5\n3\n5\n5\n", "6\n4\n3\n6\n", "5\n3\n3\n5\n", "5\n4\n3\n5\n", "3\n5\n... | coding | 249 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two integer arrays, source and target, both of length n. You are also given an array allowedSwaps where each allowedSwaps[i] = [ai, bi] indicates that you are allowed to swap the elements at index ai and... | {"functional": "def check(candidate):\n assert candidate(source = [1,2,3,4], target = [2,1,4,5], allowedSwaps = [[0,1],[2,3]]) == 1\n assert candidate(source = [1,2,3,4], target = [1,3,2,4], allowedSwaps = []) == 2\n assert candidate(source = [5,1,2,4,3], target = [1,5,4,2,3], allowedSwaps = [[0,4],[4,2],[1,3]... | coding | 224 |
Solve the programming task below in a Python markdown code block.
A dial lock is a kind of lock which has some dials with printed numbers. It has a special sequence of numbers, namely an unlocking sequence, to be opened.
You are working at a manufacturer of dial locks. Your job is to verify that every manufactured loc... | {"inputs": ["4\n1357 1908\n0\n509138 5249\n0", "4\n1357 1908\n0\n509138 1663\n0", "4\n1357 2529\n0\n509138 1663\n0", "4\n1155 2529\n0\n509138 1663\n0", "4\n1155 2529\n0\n463161 1663\n0", "4\n5501 3524\n0\n829953 5963\n0", "4\n1772 9224\n0\n637757 358\n-1", "4\n1772 7811\n0\n637757 358\n-1"], "outputs": ["3\n", "3\n", "... | coding | 582 |
Solve the programming task below in a Python markdown code block.
Two students of AtCoder Kindergarten are fighting over candy packs.
There are three candy packs, each of which contains a, b, and c candies, respectively.
Teacher Evi is trying to distribute the packs between the two students so that each student gets th... | {"inputs": ["4 45 8", "1 45 8", "1 57 8", "77 1 1", "77 1 2", "4 30 8", "1 45 5", "4 24 20"], "outputs": ["No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "Yes\n"]} | coding | 231 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
The diameter of a tree is the number of edges in the longest path in that tree.
There is an undirected tree of n nodes labeled from 0 to n - 1. You are given a 2D array edges where edges.length == n - 1 and edges[i] =... | {"functional": "def check(candidate):\n assert candidate(edges = [[0,1],[0,2]]) == 2\n assert candidate(edges = [[0,1],[1,2],[2,3],[1,4],[4,5]]) == 4\n\n\ncheck(Solution().treeDiameter)"} | coding | 138 |
Solve the programming task below in a Python markdown code block.
You have N apples, called Apple 1, Apple 2, Apple 3, ..., Apple N. The flavor of Apple i is L+i-1, which can be negative.
You can make an apple pie using one or more of the apples. The flavor of the apple pie will be the sum of the flavors of the apples ... | {"inputs": ["5 4", "5 7", "5 9", "8 9", "8 7", "3 8", "4 0", "2 2"], "outputs": ["26\n", "38\n", "46\n", "91\n", "77\n", "19\n", "6\n", "3\n"]} | coding | 390 |
Solve the programming task below in a Python markdown code block.
Kyoya Ootori has a bag with n colored balls that are colored with k different colors. The colors are labeled from 1 to k. Balls of the same color are indistinguishable. He draws balls from the bag one by one until the bag is empty. He noticed that he dre... | {"inputs": ["1\n1\n", "1\n5\n", "1\n5\n", "1\n1\n", "1\n3\n", "1\n2\n", "1\n4\n", "1\n6\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | coding | 350 |
Solve the programming task below in a Python markdown code block.
Bear Limak prepares problems for a programming competition. Of course, it would be unprofessional to mention the sponsor name in the statement. Limak takes it seriously and he is going to change some words. To make it still possible to read, he will try ... | {"inputs": ["1\nZ\n", "1\nK\n", "1\nV\n", "1\nY\n", "1\nL\n", "2\nKV\n", "2\nVK\n", "2\nVL\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "1\n", "0\n"]} | coding | 499 |
Solve the programming task below in a Python markdown code block.
Inna loves sleeping very much, so she needs n alarm clocks in total to wake up. Let's suppose that Inna's room is a 100 × 100 square with the lower left corner at point (0, 0) and with the upper right corner at point (100, 100). Then the alarm clocks are... | {"inputs": ["1\n0 0\n", "1\n0 0\n", "4\n0 0\n0 1\n0 2\n1 0\n", "4\n0 0\n0 1\n1 0\n1 1\n", "4\n1 1\n1 2\n2 3\n3 3\n", "4\n0 0\n0 1\n1 1\n1 1\n", "4\n1 1\n1 2\n2 3\n4 3\n", "4\n0 0\n0 1\n0 3\n1 0\n"], "outputs": ["1\n", "1", "2\n", "2\n", "3\n", "2\n", "3\n", "2\n"]} | coding | 603 |
Solve the programming task below in a Python markdown code block.
# A History Lesson
The Pony Express was a mail service operating in the US in 1859-60.
It reduced the time for messages to travel between the Atlantic and Pacific coasts to about 10 days, before it was made obsolete by the [transcontinental telegrap... | {"functional": "_inputs = [[[18, 15]], [[43, 23, 40, 13]], [[33, 8, 16, 47, 30, 30, 46]], [[6, 24, 6, 8, 28, 8, 23, 47, 17, 29, 37, 18, 40, 49]], [[50, 50]], [[50, 50, 25, 50, 24]], [[50, 50, 25, 50, 25]], [[50, 50, 25, 50, 26]], [[90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, ... | coding | 251 |
Solve the programming task below in a Python markdown code block.
Format any integer provided into a string with "," (commas) in the correct places.
**Example:**
``` csharp
Kata.NumberFormat(100000); // return "100,000"
Kata.NumberFormat(5678545); // return "5,678,545"
Kata.NumberFormat(-420902); // return "-420,902"
... | {"functional": "_inputs = [[100000], [5678545], [-420902], [-3], [-1003]]\n_outputs = [['100,000'], ['5,678,545'], ['-420,902'], ['-3'], ['-1,003']]\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... | coding | 489 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.