task_type stringclasses 4
values | problem stringlengths 14 5.23k | solution stringlengths 1 8.29k | problem_tokens int64 9 1.02k | solution_tokens int64 1 1.98k |
|---|---|---|---|---|
coding | Solve the programming task below in a Python markdown code block.
π (spelled pi in English) is a mathematical constant representing the circumference of a circle whose di- ameter is one unit length. The name π is said to come from the first letter of the Greek words περιφέρεια (meaning periphery) and περίμετρος (perime... | {"inputs": ["0.15\n0.05\n0.0", "1.052205526162189\n0.05\n0.0", "0.15\n0.892857233308306\n0.0", "0.15\n0.897940711549928\n0.0", "1.0557371636651482\n0.05\n0.0", "0.4926473169582818\n0.05\n0.0", "0.5656950408067312\n0.05\n0.0", "1.0653255099845902\n0.05\n0.0"], "outputs": ["3/1\n19/6", "3/1\n19/6\n", "3/1\n3/1\n", "3/1\n... | 488 | 306 |
coding | Solve the programming task below in a Python markdown code block.
Our chef has recently opened a new restaurant with a unique style. The restaurant is divided into K compartments (numbered from 1 to K) and each compartment can be occupied by at most one customer.
Each customer that visits the restaurant has a strongly... | {"inputs": ["2\n3 3\n1 3 1\n4 6 2\n7 10 3\n4 2\n10 100 1\n100 200 2\n150 500 2\n200 300 2"], "outputs": ["3\n3"]} | 537 | 80 |
coding | Solve the programming task below in a Python markdown code block.
Sig has built his own keyboard. Designed for ultimate simplicity, this keyboard only has 3 keys on it: the 0 key, the 1 key and the backspace key.
To begin with, he is using a plain text editor with this keyboard. This editor always displays one string (... | {"inputs": ["3\n1", "3\n2", "3\n4", "3\n8", "3\n3", "3\n6", "3\n0", "3\n0\n"], "outputs": ["5\n", "5\n", "5\n", "5\n", "5\n", "5\n", "5", "5\n"]} | 433 | 78 |
coding | Solve the programming task below in a Python markdown code block.
Two players play a game. The game is played on a rectangular board with n × m squares. At the beginning of the game two different squares of the board have two chips. The first player's goal is to shift the chips to the same square. The second player aim... | {"inputs": ["5 5 1 1 5 4\n", "6 2 6 1 1 2\n", "6 6 1 1 1 6\n", "5 5 1 1 5 3\n", "6 6 1 1 6 1\n", "5 4 1 4 5 1\n", "4 5 1 1 4 5\n", "5 5 1 5 4 1\n"], "outputs": ["Second\n", "Second\n", "Second\n", "First\n", "Second\n", "Second\n", "Second\n", "Second\n"]} | 606 | 150 |
coding | Solve the programming task below in a Python markdown code block.
Continuing the trend, this year too we present a 'Mystery' for you to solve!
You will be given two numbers: a and b; and you have to output a single integer. See the sample test cases for hints.
Input:
The first line of the input will contain an integ... | {"inputs": ["15\n0 5\n0 3\n5 10\n1 10\n9 10\n999 10\n999 22\n65 65\n66 65\n222 222\n652 999\n1 1000\n253 999\n256 53\n987 57"], "outputs": ["0\n0\n5\n1\n9\n9\n9\n0\n1\n0\n652\n1\n253\n44\n18"]} | 206 | 141 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer array nums. The adjacent integers in nums will perform the float division.
For example, for nums = [2,3,4], we will evaluate the expression "2/3/4".
However, you can add any number of parent... | {"functional": "def check(candidate):\n assert candidate(nums = [1000,100,10,2]) == \"1000/(100/10/2)\"\n assert candidate(nums = [2,3,4]) == \"2/(3/4)\"\n\n\ncheck(Solution().optimalDivision)"} | 152 | 80 |
coding | Solve the programming task below in a Python markdown code block.
Daisy loves playing games with words. Recently, she has been playing the following Deletive Editing word game with Daniel.
Daisy picks a word, for example, "DETERMINED". On each game turn, Daniel calls out a letter, for example, 'E', and Daisy removes t... | {"inputs": ["10\nGK GK\nF F\nH D\nZQ QZ\nC C\nFN NF\nS S\nC C\nEM C\nXO C\n", "6\nDETERMINED TRME\nDETERMINED TERM\nPSEUDOPSEUDOHYPOPARATHYROIDISM PEPA\nDEINSTITUTIONALIZATION DONATION\nCONTEST CODE\nSOLUTION SOLUTION\n"], "outputs": ["YES\nYES\nNO\nNO\nYES\nNO\nYES\nYES\nNO\nNO\n", "YES\nNO\nNO\nYES\nNO\nYES\n"]} | 485 | 132 |
coding | Solve the programming task below in a Python markdown code block.
The game of Berland poker is played with a deck of $n$ cards, $m$ of which are jokers. $k$ players play this game ($n$ is divisible by $k$).
At the beginning of the game, each player takes $\frac{n}{k}$ cards from the deck (so each card is taken by exac... | {"inputs": ["1\n49 7 7\n", "1\n49 7 7\n", "1\n48 7 4\n", "1\n48 3 6\n", "1\n49 9 7\n", "1\n48 0 6\n", "1\n71 9 7\n", "1\n48 1 4\n"], "outputs": ["7\n", "7\n", "7\n", "3\n", "6\n", "0\n", "9\n", "1\n"]} | 637 | 126 |
coding | Solve the programming task below in a Python markdown code block.
You are the gym teacher in the school.
There are $n$ students in the row. And there are two rivalling students among them. The first one is in position $a$, the second in position $b$. Positions are numbered from $1$ to $n$ from left to right.
Since th... | {"inputs": ["1\n5 2 3 2\n", "1\n5 2 3 2\n", "1\n7 2 3 2\n", "1\n7 0 3 2\n", "1\n7 1 3 2\n", "1\n3 1 1 2\n", "1\n5 2 1 2\n", "1\n6 1 3 2\n"], "outputs": ["3\n", "3\n", "3\n", "1\n", "2\n", "2\n", "3\n", "2\n"]} | 422 | 134 |
coding | Solve the programming task below in a Python markdown code block.
Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the di... | {"inputs": ["1\nz\n", "1\nz\n", "1\ny\n", "1\n{\n", "1\n|\n", "1\n}\n", "1\n~\n", "1\n\u007f\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]} | 398 | 91 |
coding | Solve the programming task below in a Python markdown code block.
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
You are given a tree with $N$ vertices (numbered $1$ through $N$). Its edges are numbered $1$ through $N-1$. For each valid $i$, there is an integer ... | {"inputs": ["1\n3\n1 2 4\n2 3 7\n1 5 10"], "outputs": ["1"]} | 762 | 33 |
coding | Solve the programming task below in a Python markdown code block.
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the... | {"inputs": ["1\n3\n", "1\n1\n", "1\n2\n", "1\n4\n", "1\n5\n", "1\n9\n", "1\n6\n", "1\n7\n"], "outputs": ["1\n", "2\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | 214 | 86 |
coding | Solve the programming task below in a Python markdown code block.
Mary wrote a recipe book and is about to publish it, but because of a new European law, she needs to update and include all measures in grams.
Given all the measures in tablespoon (`tbsp`) and in teaspoon (`tsp`), considering `1 tbsp = 15g` and `1 tsp =... | {"functional": "_inputs = [['2 tbsp of butter'], ['Add to the mixing bowl and coat well with 1 tbsp of olive oil & 1/2 tbsp of dried dill'], ['1/2 tsp of baking powder'], ['In another bowl, add 2 tsp of vanilla extract, 3 tsp of baking soda and 1/2 tsp of salt'], ['10 tbsp of cocoa powder'], ['1/8 tbsp of baking soda']... | 258 | 402 |
coding | Solve the programming task below in a Python markdown code block.
Alice and Bob have participated to a Rock Off with their bands. A jury of true metalheads rates the two challenges, awarding points to the bands on a scale from 1 to 50 for three categories: Song Heaviness, Originality, and Members' outfits.
For each on... | {"functional": "_inputs = [[[47, 7, 2], [47, 7, 2]], [[47, 50, 22], [26, 47, 12]], [[25, 50, 22], [34, 49, 50]], [[8, 8, 11], [3, 8, 10]], [[20, 32, 18], [48, 25, 40]], [[5, 6, 7], [3, 6, 10]], [[21, 39, 15], [50, 1, 12]], [[0, 1, 2], [1, 2, 0]]]\n_outputs = [['0, 0: that looks like a \"draw\"! Rock on!'], ['3, 0: Alic... | 357 | 443 |
coding | Solve the programming task below in a Python markdown code block.
Companies always have a lot of equipment, furniture and other things. All of them should be tracked. To do this, there is an inventory number assigned with each item. It is much easier to create a database by using those numbers and keep the track of eve... | {"inputs": ["1\n2\n", "1\n3\n", "1\n6\n", "1\n1\n", "1\n5\n", "1\n7\n", "1\n2\n", "2\n1 4\n"], "outputs": ["1 \n", "1\n", "1\n", "1\n", "1\n", "1\n", "1 \n", "1 2 \n"]} | 452 | 93 |
coding | Solve the programming task below in a Python markdown code block.
Every day, N passengers arrive at Takahashi Airport. The i-th passenger arrives at time T_i.
Every passenger arrived at Takahashi airport travels to the city by bus. Each bus can accommodate up to C passengers. Naturally, a passenger cannot take a bus t... | {"inputs": ["5 5 5\n1\n1\n4\n6\n4", "5 5 5\n1\n1\n0\n6\n3", "5 3 5\n1\n7\n3\n6\n1", "5 3 5\n1\n4\n3\n6\n12", "5 5 5\n1\n4\n3\n6\n12", "5 5 5\n1\n1\n3\n6\n12", "5 5 5\n1\n1\n3\n6\n18", "5 5 5\n1\n1\n0\n6\n18"], "outputs": ["1\n", "2\n", "2\n", "3\n", "2\n", "2\n", "2\n", "3\n"]} | 357 | 179 |
coding | Solve the programming task below in a Python markdown code block.
Recently a top secret mission to Mars has taken place. As a result, scientists managed to obtain some information about the Martian DNA. Now we know that any Martian DNA contains at most m different nucleotides, numbered from 1 to m. Special characterist... | {"inputs": ["3 3 0\n", "5000 3 0\n", "6984 3 0\n", "6984 4 0\n", "2 1 1\naa\n", "100000 52 0\n", "100000 34 0\n", "3 4 2\nab\nba\n"], "outputs": ["27\n", "22443616\n", "170353494", "63989708", "0\n", "378241178\n", "486606280", "50"]} | 634 | 165 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has a sequence A containing N integers A_{1}, A_{2}, ..., A_{N}.
Chef is playing a game with this sequence. In this game, he may perform the following operation any num... | {"inputs": ["2\n2\n1 2\n5\n7 4 3 2 6"], "outputs": ["2\n1"]} | 337 | 32 |
coding | Solve the programming task below in a Python markdown code block.
You are given an array $a$ of size $n$.
You can perform the following operation on the array:
Choose two different integers $i, j$ $(1 \leq i < j \leq n$), replace $a_i$ with $x$ and $a_j$ with $y$. In order not to break the array, $a_i | a_j = x | y$ ... | {"inputs": ["4\n3\n1 3 2\n5\n1 2 4 8 16\n2\n6 6\n3\n3 5 6\n"], "outputs": ["3\n31\n6\n7\n"]} | 531 | 56 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given coordinates, a string that represents the coordinates of a square of the chessboard. Below is a chessboard for your reference.
Return true if the square is white, and false if the square is black.
The c... | {"functional": "def check(candidate):\n assert candidate(coordinates = \"a1\") == False\n assert candidate(coordinates = \"h3\") == True\n assert candidate(coordinates = \"c7\") == False\n\n\ncheck(Solution().squareIsWhite)"} | 117 | 56 |
coding | Solve the programming task below in a Python markdown code block.
Write a function that accepts two square matrices (`N x N` two dimensional arrays), and return the sum of the two. Both matrices being passed into the function will be of size `N x N` (square), containing only integers.
How to sum two matrices:
Take ea... | {"functional": "_inputs = [[[[1, 2, 3], [3, 2, 1], [1, 1, 1]], [[2, 2, 1], [3, 2, 3], [1, 1, 3]]], [[[1, 2], [1, 2]], [[2, 3], [2, 3]]], [[[1]], [[2]]]]\n_outputs = [[[[3, 4, 4], [6, 4, 4], [2, 2, 4]]], [[[3, 5], [3, 5]]], [[[3]]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b... | 265 | 283 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a string of English letters s, return the greatest English letter which occurs as both a lowercase and uppercase letter in s. The returned letter should be in uppercase. If no such letter exists, return an empty... | {"functional": "def check(candidate):\n assert candidate(s = \"lEeTcOdE\") == \"E\"\n assert candidate(s = \"arRAzFif\") == \"R\"\n assert candidate(s = \"AbCdEfGhIjK\") == \"\"\n\n\ncheck(Solution().greatestLetter)"} | 111 | 75 |
coding | Solve the programming task below in a Python markdown code block.
You are given a string $S$. Find the number of ways to choose an unordered pair of non-overlapping non-empty substrings of this string (let's denote them by $s_1$ and $s_2$ in such a way that $s_2$ starts after $s_1$ ends) such that their concatenation $... | {"inputs": ["abba"], "outputs": ["7"]} | 335 | 13 |
coding | Solve the programming task below in a Python markdown code block.
Chef is now a corporate person. He has to attend office regularly. But chef does not want to go to office, rather he wants to stay home and discover different recipes and cook them.
In the office where chef works, has two guards who count how many times... | {"inputs": ["1\n19 17"], "outputs": ["19 36"]} | 336 | 22 |
coding | Solve the programming task below in a Python markdown code block.
One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems.
But there are too many problems, to do it manually. Alex asks you to write ... | {"inputs": ["A\n", "A\n", "@\n", "aa\n", "aa\n", "ab\n", "ac\n", "Ann\n"], "outputs": ["NO", "NO\n", "NO\n", "NO", "NO\n", "NO\n", "NO\n", "YES"]} | 232 | 67 |
coding | Solve the programming task below in a Python markdown code block.
You are a king and you are at war. If the enemy breaks through your frontline you lose.
Enemy can break the line only if the sum of morale of any $K$ continuous soldiers is strictly less than $M$. So, you being a motivational orator decides to boost thei... | {"inputs": ["6 2 5\n1 1 1 1 1 1"], "outputs": ["2"]} | 337 | 28 |
coding | Solve the programming task below in a Python markdown code block.
Jack and Daniel are friends. Both of them like letters, especially uppercase ones.
They are cutting uppercase letters from newspapers, and each one of them has his collection of letters stored in a stack.
One beautiful day, Morgan visited Jack and Da... | {"inputs": ["2\nJACK\nDANIEL\nABACABA\nABACABA\n"], "outputs": ["DAJACKNIEL\nAABABACABACABA\n"]} | 539 | 41 |
coding | Solve the programming task below in a Python markdown code block.
Polycarpus participates in a competition for hacking into a new secure messenger. He's almost won.
Having carefully studied the interaction protocol, Polycarpus came to the conclusion that the secret key can be obtained if he properly cuts the public ke... | {"inputs": ["23\n2 3\n", "23\n2 3\n", "604\n6 4\n", "604\n6 4\n", "604\n6 2\n", "604\n4 2\n", "604\n4 1\n", "120\n12 1\n"], "outputs": ["YES\n2\n3\n", "YES\n2\n3\n", "YES\n60\n4\n", "YES\n60\n4\n", "YES\n60\n4\n", "YES\n60\n4\n", "YES\n60\n4\n", "NO\n"]} | 493 | 150 |
coding | Solve the programming task below in a Python markdown code block.
Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with.
String a is the divisor of string b if and only if there exists a positive integer x such that if we write out str... | {"inputs": ["a\na\n", "a\nb\n", "c\nc\n", "a\nc\n", "b\nc\n", "c\nb\n", "b\nd\n", "c\nd\n"], "outputs": ["1", "0", "1\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | 280 | 84 |
coding | Solve the programming task below in a Python markdown code block.
## Task:
You have to create a function `isPronic` to check whether the argument passed is a Pronic Number and return true if it is & false otherwise.
### Description:
`Pronic Number` -A pronic number, oblong number, rectangular number or heteromecic nu... | {"functional": "_inputs = [[2], [3], [4], [5], [6], [-3], [-27]]\n_outputs = [[True], [False], [False], [False], [True], [False], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, ... | 314 | 192 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed integer array arr, and an m x n integer matrix mat. arr and mat both contain all the integers in the range [1, m * n].
Go through each index i in arr starting from index 0 and paint the cell ... | {"functional": "def check(candidate):\n assert candidate(arr = [1,3,4,2], mat = [[1,4],[2,3]]) == 2\n assert candidate(arr = [2,8,7,4,1,3,5,6,9], mat = [[3,2,5],[1,4,6],[8,7,9]]) == 3\n\n\ncheck(Solution().firstCompleteIndex)"} | 138 | 98 |
coding | Solve the programming task below in a Python markdown code block.
You are given a sequence of $n$ integers $a_1, \, a_2, \, \dots, \, a_n$.
Does there exist a sequence of $n$ integers $b_1, \, b_2, \, \dots, \, b_n$ such that the following property holds?
For each $1 \le i \le n$, there exist two (not necessarily dis... | {"inputs": ["1\n2\n1 1\n", "1\n2\n1 1\n", "1\n2\n2 1\n", "1\n2\n2 2\n", "1\n2\n0 1\n", "1\n2\n2 3\n", "1\n2\n1 2\n", "1\n2\n0 2\n"], "outputs": ["YES\n", "YES\n", "NO\n", "YES\n", "YES\n", "NO\n", "NO\n", "YES\n"]} | 616 | 118 |
coding | Solve the programming task below in a Python markdown code block.
Your classmate, whom you do not like because he is boring, but whom you respect for his intellect, has two strings: $s$ of length $n$ and $t$ of length $m$.
A sequence $p_1, p_2, \ldots, p_m$, where $1 \leq p_1 < p_2 < \ldots < p_m \leq n$, is called be... | {"inputs": ["2 2\nab\nab\n", "2 2\nba\nba\n", "2 2\nab\nab\n", "3 3\ncad\ncad\n", "3 3\ncad\ncad\n", "5 2\naaaaa\naa\n", "4 3\ndbbd\ndbd\n", "5 2\nddaca\nda\n"], "outputs": ["1\n", "1\n", "\n1\n", "1\n", "1\n", "4\n", "2\n", "4\n"]} | 518 | 129 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer n, return the decimal value of the binary string formed by concatenating the binary representations of 1 to n in order, modulo 109 + 7.
Please complete the following python code precisely:
```python... | {"functional": "def check(candidate):\n assert candidate(n = 1) == 1\n assert candidate(n = 3) == 27\n assert candidate(n = 12) == 505379714\n\n\ncheck(Solution().concatenatedBinary)"} | 84 | 67 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a string array features where features[i] is a single word that represents the name of a feature of the latest product you are working on. You have made a survey where users have reported which features ... | {"functional": "def check(candidate):\n assert candidate(features = [\"cooler\",\"lock\",\"touch\"], responses = [\"i like cooler cooler\",\"lock touch cool\",\"locker like touch\"]) == [\"touch\",\"cooler\",\"lock\"]\n assert candidate(features = [\"a\",\"aa\",\"b\",\"c\"], responses = [\"a\",\"a aa\",\"a a a a ... | 198 | 112 |
coding | Solve the programming task below in a Python markdown code block.
Moscow is hosting a major international conference, which is attended by n scientists from different countries. Each of the scientists knows exactly one language. For convenience, we enumerate all languages of the world with integers from 1 to 10^9.
In ... | {"inputs": ["1\n8\n1\n10\n3\n", "1\n8\n1\n17\n3\n", "1\n10\n1\n10\n3\n", "2\n1 6\n1\n6\n1\n", "1\n10\n1\n10\n3\n", "2\n1 6\n1\n6\n1\n", "1\n19\n1\n10\n3\n", "2\n1 6\n1\n3\n1\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | 730 | 148 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian.
The problem is completely unrelated to its problem code :).
Let us build an infinite string D that is simply a concatenation of the decimal representations of all positive integers without lea... | {"inputs": ["2\n78910\n9930"], "outputs": ["7\n2679"]} | 458 | 28 |
coding | Solve the programming task below in a Python markdown code block.
Chef is very fond of horses. He enjoys watching them race. As expected, he has a stable full of horses. He, along with his friends, goes to his stable during the weekends to watch a few of these horses race. Chef wants his friends to enjoy the race and s... | {"inputs": ["1\n5\n7 4 2 29 5", "1\n5\n0 7 0 8 14", "1\n5\n7 9 1 13 0", "1\n5\n7 4 4 29 5", "1\n5\n1 7 0 8 14", "1\n5\n0 9 1 4 14", "1\n5\n7 9 0 13 0", "1\n5\n7 4 4 29 7"], "outputs": ["1\n", "0\n", "1\n", "0\n", "1\n", "1\n", "0\n", "0\n"]} | 356 | 166 |
coding | Solve the programming task below in a Python markdown code block.
Reverse every other word in a given string, then return the string. Throw away any leading or trailing whitespace, while ensuring there is exactly one space between each word. Punctuation marks should be treated as if they are a part of the word in this ... | {"functional": "_inputs = [['Did it work?'], ['I really hope it works this time...'], ['Reverse this string, please!'], ['Have a beer'], [' '], ['This is not a test '], ['This is a test ']]\n_outputs = [['Did ti work?'], ['I yllaer hope ti works siht time...'], ['Reverse siht string, !esaelp'], ['Have a beer']... | 87 | 249 |
coding | Solve the programming task below in a Python markdown code block.
Implement `String#digit?` (in Java `StringUtils.isDigit(String)`), which should return `true` if given object is a digit (0-9), `false` otherwise.
Also feel free to reuse/extend the following starter code:
```python
def is_digit(n):
``` | {"functional": "_inputs = [[''], ['7'], [' '], ['a'], ['a5'], ['14'], ['!'], ['\"'], ['#'], ['$'], ['%'], ['&'], [\"'\"], ['('], [')'], ['*'], ['+'], [','], ['-'], ['.'], ['/'], ['0'], ['1'], ['2'], ['3'], ['4'], ['5'], ['6'], ['8'], ['9'], [':'], [';'], ['<'], ['='], ['>'], ['?'], ['@'], ['A'], ['B'], ['C'], ['D'], ['... | 73 | 765 |
coding | Solve the programming task below in a Python markdown code block.
You have initially a string of N characters, denoted by A1,A2...AN. You have to print the size of the largest subsequence of string A such that all the characters in that subsequence are distinct ie. no two characters in that subsequence should be same.
... | {"inputs": ["2\nabc\naba", "2\nabd\naba", "2\nabc\naaa", "2\ncca\naaa", "2\nccb\naab", "2\nccb\ncba", "2\nbbb\nbaa", "2\nbbb\naaa"], "outputs": ["3\n2", "3\n2\n", "3\n1\n", "2\n1\n", "2\n2\n", "2\n3\n", "1\n2\n", "1\n1\n"]} | 268 | 111 |
coding | Solve the programming task below in a Python markdown code block.
Consider creating the following number pattern.
4 8 2 3 1 0 8 3 7 6
2 0 5 4 1 8 1 0 3
2 5 9 5 9 9 1 3
7 4 4 4 8 0 4
1 8 8 2 8 4
9 6 0 0 2
5 6 0 2
1 6 2
7 8
Five
This pattern follows the rules below.
A B
C
In the sequence of numbers, C is the ones... | {"inputs": ["4823108376\n2273064329\n0123456789", "4823108376\n2314825047\n0123456789", "4823108376\n1842094049\n0123456789", "4823108376\n2704372300\n0123456789", "4823108376\n2811474872\n0123456789", "4823108376\n1472363412\n0123456789", "4823108376\n5495669921\n0123456789", "4823108376\n2337446006\n0123456789"], "ou... | 356 | 342 |
coding | Solve the programming task below in a Python markdown code block.
In Chefland, a tennis game involves 4 referees.
Each referee has to point out whether he considers the ball to be inside limits or outside limits. The ball is considered to be IN if and only if all the referees agree that it was inside limits.
Given t... | {"inputs": ["4\n1 1 0 0\n0 0 0 0\n0 0 0 1\n1 1 1 1\n"], "outputs": ["OUT\nIN\nOUT\nOUT\n"]} | 440 | 52 |
coding | Solve the programming task below in a Python markdown code block.
There are N piles where the i^{th} pile consists of A_{i} stones.
Chef and Chefina are playing a game taking alternate turns with Chef starting first.
In his/her turn, a player can choose any non-empty pile and remove exactly 1 stone from it.
The ga... | {"inputs": ["3\n2\n2 2\n1\n10\n3\n1 5 6\n"], "outputs": ["CHEFINA\nCHEFINA\nCHEF\n"]} | 454 | 42 |
coding | Solve the programming task below in a Python markdown code block.
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside.
The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $... | {"inputs": ["a\n", "z\n", "z\n", "a\n", "b\n", "c\n", "cc\n", "zy\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "2\n", "1\n"]} | 628 | 70 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an n x n integer matrix grid.
Generate an integer matrix maxLocal of size (n - 2) x (n - 2) such that:
maxLocal[i][j] is equal to the largest value of the 3 x 3 matrix in grid centered around row i + 1 ... | {"functional": "def check(candidate):\n assert candidate(grid = [[9,9,8,1],[5,6,2,6],[8,2,6,4],[6,2,2,2]]) == [[9,9],[8,6]]\n assert candidate(grid = [[1,1,1,1,1],[1,1,1,1,1],[1,1,2,1,1],[1,1,1,1,1],[1,1,1,1,1]]) == [[2,2,2],[2,2,2],[2,2,2]]\n\n\ncheck(Solution().largestLocal)"} | 150 | 148 |
coding | Solve the programming task below in a Python markdown code block.
You're on your way to the market when you hear beautiful music coming from a nearby street performer. The notes come together like you wouln't believe as the musician puts together patterns of tunes. As you wonder what kind of algorithm you could use to ... | {"functional": "_inputs = [['Your girlscout cookies are ready to ship. Your total comes to tree fiddy'], [\"Howdy Pardner. Name's Pete Lexington. I reckon you're the kinda stiff who carries about tree fiddy?\"], [\"I'm from Scottland. I moved here to be with my family sir. Please, $3.50 would go a long way to help me f... | 301 | 439 |
coding | Solve the programming task below in a Python markdown code block.
In this problem at each moment you have a set of intervals. You can move from interval (a, b) from our set to interval (c, d) from our set if and only if c < a < d or c < b < d. Also there is a path from interval I1 from our set to interval I2 from our s... | {"inputs": ["5\n1 1 5\n1 8 11\n2 1 2\n1 2 9\n2 1 2\n", "5\n1 1 4\n1 8 11\n1 1 2\n1 3 9\n2 1 2\n", "5\n1 1 4\n1 8 11\n2 1 2\n1 2 9\n2 1 2\n", "5\n1 1 4\n1 8 11\n2 1 2\n1 3 9\n2 1 2\n", "5\n1 1 5\n1 5 13\n2 1 2\n1 2 9\n2 1 2\n", "5\n1 0 5\n1 8 11\n2 1 2\n1 2 9\n2 1 2\n", "5\n1 1 2\n1 8 11\n2 1 2\n1 2 9\n2 1 2\n", "5\n1 1... | 361 | 332 |
coding | Solve the programming task below in a Python markdown code block.
You are given an array consisting of all integers from $[l, r]$ inclusive. For example, if $l = 2$ and $r = 5$, the array would be $[2, 3, 4, 5]$. What's the minimum number of elements you can delete to make the bitwise AND of the array non-zero?
A bitw... | {"inputs": ["5\n1 2\n2 8\n4 5\n1 5\n100000 200000\n", "5\n1 2\n2 8\n4 5\n2 5\n100000 200000\n", "5\n1 2\n2 8\n4 5\n4 5\n100000 200000\n", "5\n2 2\n2 8\n4 5\n2 5\n100000 200000\n", "5\n1 2\n2 8\n4 5\n4 5\n110000 200000\n", "5\n2 2\n2 8\n4 5\n2 5\n100100 200000\n", "5\n1 2\n2 8\n4 5\n1 5\n100001 200000\n", "5\n1 2\n2 8\n... | 486 | 402 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
A value-equal string is a string where all characters are the same.
For example, "1111" and "33" are value-equal strings.
In contrast, "123" is not a value-equal string.
Given a digit string s, decompose the string ... | {"functional": "def check(candidate):\n assert candidate(s = \"000111000\") == False\n assert candidate(s = \"00011111222\") == True\n assert candidate(s = \"01110002223300\") == False\n\n\ncheck(Solution().isDecomposable)"} | 173 | 85 |
coding | Solve the programming task below in a Python markdown code block.
Complete the function that takes a string as an input, and return a list of all the unpaired characters (i.e. they show up an odd number of times in the string), in the order they were encountered as an array.
In case of multiple appearances to choose ... | {"functional": "_inputs = [['Hello World'], ['Codewars'], ['woowee'], ['wwoooowweeee'], ['racecar'], ['Mamma'], ['Mama'], ['\u00bc x 4 = 1'], ['\u00bc x 4 = 1 and \u00bd x 4 = 2']]\n_outputs = [[['H', 'e', ' ', 'W', 'r', 'l', 'd']], [['C', 'o', 'd', 'e', 'w', 'a', 'r', 's']], [[]], [[]], [['e']], [['M']], [['M', 'm']],... | 262 | 329 |
coding | Solve the programming task below in a Python markdown code block.
"I have only one rule, never submit partially correct code" -Barney Stinson
The religious act which Barney and his friends hold most sacred, XORING the natural numbers in the given range. This time Barney is a bit busy with picking up some girls, so he ... | {"inputs": ["4\n1 4\n2 6\n3 3\n2 3"], "outputs": ["Even\nEven\nOdd\nOdd"]} | 335 | 34 |
coding | Solve the programming task below in a Python markdown code block.
You have recently discovered that horses travel in a unique pattern - they're either running (at top speed) or resting (standing still).
Here's an example of how one particular horse might travel:
```
The horse Blaze can run at 14 metres/second for 60 ... | {"functional": "_inputs = [[1000, 10, 127, 14], [1000, 10, 0, 10], [25, 50, 120, 18], [35869784, 90, 100, 5], [1234567, 4, 3, 11], [100000000, 21, 5, 14], [0, 100, 10, 14], [250, 0, 5, 14], [100, 10, 0, 14], [500, 100, 10, 0]]\n_outputs = [[1120], [10000], [450], [84954920], [7760148], [1130769276], [0], [0], [1400], [... | 221 | 392 |
coding | Solve the programming task below in a Python markdown code block.
Tattah is asleep if and only if Tattah is attending a lecture. This is a well-known formula among Tattah's colleagues.
On a Wednesday afternoon, Tattah was attending Professor HH's lecture. At 12:21, right before falling asleep, he was staring at the di... | {"inputs": ["04:50\n", "02:17\n", "12:14\n", "03:44\n", "00:17\n", "15:51\n", "23:31\n", "07:56\n"], "outputs": ["05:50\n", "02:20\n", "12:21\n", "04:40\n", "01:10\n", "20:02\n", "23:32\n", "10:01\n"]} | 320 | 134 |
coding | Solve the programming task below in a Python markdown code block.
The construction of subway in Bertown is almost finished! The President of Berland will visit this city soon to look at the new subway himself.
There are n stations in the subway. It was built according to the Bertown Transport Law:
For each station ... | {"inputs": ["1\n1\n", "1\n1\n", "2\n1 2\n", "2\n2 1\n", "2\n1 2\n", "2\n2 1\n", "3\n2 1 3\n", "3\n1 2 3\n"], "outputs": ["1\n", "1", "4\n", "4\n", "4", "4\n", "9\n", "5\n"]} | 538 | 100 |
coding | Solve the programming task below in a Python markdown code block.
There is a string $s$ of length $3$, consisting of uppercase and lowercase English letters. Check if it is equal to "YES" (without quotes), where each letter can be in any case. For example, "yES", "Yes", "yes" are all allowable.
-----Input-----
The f... | {"inputs": ["1\nvop\n", "1\nhac\n", "1\nNNy\n", "1\nHAC\n", "1\nyeQ\n", "1\nHAm\n", "1\nxxx\n", "1\nxxy\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]} | 320 | 93 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed integer array costs where costs[i] is the cost of hiring the ith worker.
You are also given two integers k and candidates. We want to hire exactly k workers according to the following rules:
... | {"functional": "def check(candidate):\n assert candidate(costs = [17,12,10,2,7,2,11,20,8], k = 3, candidates = 4) == 11\n assert candidate(costs = [1,2,4,1], k = 3, candidates = 3) == 4\n\n\ncheck(Solution().totalCost)"} | 308 | 93 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given the array queries of positive integers between 1 and m, you have to process all queries[i] (from i=0 to i=queries.length-1) according to the following rules:
In the beginning, you have the permutation P=[1,2,3,... | {"functional": "def check(candidate):\n assert candidate(queries = [3,1,2,1], m = 5) == [2,1,2,1] \n assert candidate(queries = [4,1,2,2], m = 4) == [3,1,2,0]\n assert candidate(queries = [7,5,5,8,3], m = 8) == [6,5,0,7,5]\n\n\ncheck(Solution().processQueries)"} | 175 | 117 |
coding | 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)"} | 169 | 82 |
coding | Solve the programming task below in a Python markdown code block.
For Diwali, Chef arranges all $K$ laddus in a row in his sweet shop. Whenever a customer comes to buy laddus, chef follows a rule that each customer must buy all laddus on odd position. After the selection of the laddu, a new row is formed, and again out... | {"inputs": ["3\n1\n5\n8"], "outputs": ["1\n4\n8"]} | 309 | 22 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Nearly everyone has used the Multiplication Table. The multiplication table of size m x n is an integer matrix mat where mat[i][j] == i * j (1-indexed).
Given three integers m, n, and k, return the kth smallest elemen... | {"functional": "def check(candidate):\n assert candidate(m = 3, n = 3, k = 5) == 3\n assert candidate(m = 2, n = 3, k = 6) == 6\n\n\ncheck(Solution().findKthNumber)"} | 118 | 65 |
coding | Solve the programming task below in a Python markdown code block.
You are playing some computer game. One of its levels puts you in a maze consisting of n lines, each of which contains m cells. Each cell either is free or is occupied by an obstacle. The starting cell is in the row r and column c. In one step you can mo... | {"inputs": ["1 1\n1 1\n0 0\n.\n", "1 1\n1 1\n0 0\n.\n", "1 1\n1 1\n31 42\n.\n", "1 1\n1 1\n31 42\n.\n", "1 7\n1 1\n0 3\n.......\n", "1 7\n1 1\n0 3\n.......\n", "4 4\n2 2\n0 1\n....\n..*.\n....\n....\n", "4 4\n2 2\n0 1\n....\n..*.\n....\n....\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "4\n", "4\n", "7\n", "7\n"]} | 521 | 194 |
coding | Solve the programming task below in a Python markdown code block.
Ksusha the Squirrel is standing at the beginning of a straight road, divided into n sectors. The sectors are numbered 1 to n, from left to right. Initially, Ksusha stands in sector 1.
Ksusha wants to walk to the end of the road, that is, get to sector ... | {"inputs": ["2 1\n..\n", "2 1\n..\n", "2 2\n..\n", "2 2\n..\n", "2 4\n..\n", "2 8\n..\n", "2 1\n..\n", "3 1\n.#.\n"], "outputs": ["YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "NO\n"]} | 345 | 103 |
coding | Solve the programming task below in a Python markdown code block.
With one die of 6 sides we will have six different possible results:``` 1, 2, 3, 4, 5, 6``` .
With 2 dice of six sides, we will have 36 different possible results:
```
(1,1),(1,2),(2,1),(1,3),(3,1),(1,4),(4,1),(1,5),
(5,1), (1,6),(6,1),(2,2),(2,3),(3,... | {"functional": "_inputs = [[[6, 6]], [[5, 6, 4]], [[3, 15, 8, 20]], [[6]], [[3, 3]], [[20]], [[3, 6]]]\n_outputs = [[3], [5], [44], [0], [0], [1], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if i... | 695 | 218 |
coding | Solve the programming task below in a Python markdown code block.
Find the longest substring in alphabetical order.
Example: the longest alphabetical substring in `"asdfaaaabbbbcttavvfffffdf"` is `"aaaabbbbctt"`.
There are tests with strings up to `10 000` characters long so your code will need to be efficient.
The ... | {"functional": "_inputs = [['asd'], ['nab'], ['abcdeapbcdef'], ['asdfaaaabbbbcttavvfffffdf'], ['asdfbyfgiklag'], ['z'], ['zyba']]\n_outputs = [['as'], ['ab'], ['abcde'], ['aaaabbbbctt'], ['fgikl'], ['z'], ['z']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n r... | 128 | 216 |
coding | Solve the programming task below in a Python markdown code block.
An electronics shop sells red and blue lamps. A red lamp costs X rupees and a blue lamp costs Y rupees.
Chef is going to buy exactly N lamps from this shop. Find the minimum amount of money Chef needs to pay such that at least K of the lamps bought are ... | {"inputs": ["4\n2 2 5 1\n4 1 3 1\n3 0 4 7\n5 2 3 4\n"], "outputs": ["10\n6\n12\n15\n"]} | 364 | 55 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a positive integer n, generate an n x n matrix filled with elements from 1 to n2 in spiral order.
Please complete the following python code precisely:
```python
class Solution:
def generateMatrix(self, n: ... | {"functional": "def check(candidate):\n assert candidate(n = 3) == [[1,2,3],[8,9,4],[7,6,5]]\n assert candidate(n = 1) == [[1]]\n\n\ncheck(Solution().generateMatrix)"} | 74 | 63 |
coding | Solve the programming task below in a Python markdown code block.
Chef has a string S with him. Chef is happy if the string contains a contiguous substring of length strictly greater than 2 in which all its characters are vowels.
Determine whether Chef is happy or not.
Note that, in english alphabet, vowels are a, e... | {"inputs": ["4\naeiou\nabxy\naebcdefghij\nabcdeeafg\n"], "outputs": ["Happy\nSad\nSad\nHappy\n"]} | 405 | 38 |
coding | Solve the programming task below in a Python markdown code block.
# Description
Write a function that accepts the current position of a knight in a chess board, it returns the possible positions that it will end up after 1 move. The resulted should be sorted.
## Example
"a1" -> ["b3", "c2"]
Also feel free to reuse/... | {"functional": "_inputs = [['a1'], ['f7'], ['c3']]\n_outputs = [[['b3', 'c2']], [['d6', 'd8', 'e5', 'g5', 'h6', 'h8']], [['a2', 'a4', 'b1', 'b5', 'd1', 'd5', 'e2', 'e4']]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, ab... | 90 | 227 |
coding | Solve the programming task below in a Python markdown code block.
Spoonerize... with numbers... numberize?... numboonerize?... noonerize? ...anyway! If you don't yet know what a spoonerism is and haven't yet tried my spoonerism kata, please do [check it out](http://www.codewars.com/kata/spoonerize-me) first.
You will... | {"functional": "_inputs = [[[12, 34]], [[55, 63]], [[357, 579]], [[1000000, 9999999]], [[1000000, 'hello']], [['pippi', 9999999]], [['pippi', 'hello']], [[1, 1]], [[1, 0]], [[0, 1]]]\n_outputs = [[18], [12], [178], [7000001], ['invalid array'], ['invalid array'], ['invalid array'], [0], [1], [1]]\nimport math\ndef _dee... | 259 | 287 |
coding | Solve the programming task below in a Python markdown code block.
n evenly spaced points have been marked around the edge of a circle. There is a number written at each point. You choose a positive real number k. Then you may repeatedly select a set of 2 or more points which are evenly spaced, and either increase all n... | {"inputs": ["3\n000\n", "3\n007\n", "3\n007\n", "3\n000\n", "3\n111\n", "3\n100\n", "3\n001\n", "3\n101\n"], "outputs": ["YES\n", "NO\n", "NO\n", "YES\n", "YES\n", "NO\n", "NO\n", "NO\n"]} | 404 | 102 |
coding | Solve the programming task below in a Python markdown code block.
A string is called bracket sequence if it does not contain any characters other than "(" and ")". A bracket sequence is called regular if it it is possible to obtain correct arithmetic expression by inserting characters "+" and "1" into this sequence. Fo... | {"inputs": ["3\n1\n4\n3\n", "0\n0\n0\n0\n", "1\n2\n3\n4\n", "0\n0\n1\n0\n", "4\n3\n2\n1\n", "1\n2\n2\n1\n", "2\n0\n2\n0\n", "1\n0\n1\n1\n"], "outputs": ["1\n", "1\n", "0\n", "0\n", "0\n", "1\n", "0\n", "1\n"]} | 422 | 118 |
coding | Solve the programming task below in a Python markdown code block.
Petya and his friend, robot Petya++, like to solve exciting math problems.
One day Petya++ came up with the numbers $n$ and $x$ and wrote the following equality on the board: $$n\ \&\ (n+1)\ \&\ \dots\ \&\ m = x,$$ where $\&$ denotes the bitwise AND ope... | {"inputs": ["1\n0 1\n", "5\n10 8\n10 10\n10 42\n20 16\n1000000000000000000 0\n"], "outputs": ["-1\n", "12\n10\n-1\n24\n1152921504606846976\n"]} | 496 | 102 |
coding | Solve the programming task below in a Python markdown code block.
Chef has a stick of length N.
He can break the stick into 2 or more parts such that the [parity] of length of each part is same. For example, a stick of length 11 can be broken into three sticks of lengths \{3, 3, 5\} since each part is odd, but it cann... | {"inputs": ["3\n6 1\n3 2\n4 3\n"], "outputs": ["YES\nNO\nYES\n"]} | 442 | 30 |
coding | Solve the programming task below in a Python markdown code block.
People in the Tomskaya region like magic formulas very much. You can see some of them below.
Imagine you are given a sequence of positive integer numbers p_1, p_2, ..., p_{n}. Lets write down some magic formulas:$q_{i} = p_{i} \oplus(i \operatorname{mod... | {"inputs": ["1\n0\n", "1\n0\n", "1\n1\n", "1\n3\n", "1\n5\n", "1\n6\n", "1\n8\n", "1\n2\n"], "outputs": ["0\n", "0", "1\n", "3\n", "5\n", "6\n", "8\n", "2\n"]} | 350 | 85 |
coding | Solve the programming task below in a Python markdown code block.
A bracket sequence is called regular if it is possible to obtain correct arithmetic expression by inserting characters «+» and «1» into this sequence. For example, sequences «(())()», «()» and «(()(()))» are regular, while «)(», «(()» and «(()))(» are no... | {"inputs": ["(\n", ")\n", ")(()(\n", "()(()\n", "((())\n", "())((\n", "))(((\n", "(())(\n"], "outputs": ["0\n", "0\n", "2\n", "4\n", "4\n", "2\n", "0\n", "4\n"]} | 183 | 79 |
coding | Solve the programming task below in a Python markdown code block.
John is new to Mathematics and does not know how to calculate GCD of numbers. So he wants you to help him in a few GCD calculations. John has a list A of numbers, indexed 1 to N. He wants to create another list B having N+1 numbers, indexed from 1 to N+1... | {"inputs": ["2\n3\n1 2 3\n3\n5 10 5\n"], "outputs": ["1 2 6 3\n5 10 10 5\n"]} | 470 | 47 |
coding | Solve the programming task below in a Python markdown code block.
Pair of gloves
=============
Winter is coming, you must prepare your ski holidays. The objective of this kata is to determine the number of pair of gloves you can constitute from the gloves you have in your drawer.
A pair of gloves is constituted of tw... | {"functional": "_inputs = [[['red', 'red']], [['red', 'green', 'blue']], [['gray', 'black', 'purple', 'purple', 'gray', 'black']], [[]], [['red', 'green', 'blue', 'blue', 'red', 'green', 'red', 'red', 'red']]]\n_outputs = [[1], [0], [3], [0], [4]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float)... | 200 | 228 |
coding | Solve the programming task below in a Python markdown code block.
This contest is `CODE FESTIVAL`. However, Mr. Takahashi always writes it `CODEFESTIVAL`, omitting the single space between `CODE` and `FESTIVAL`.
So he has decided to make a program that puts the single space he omitted.
You are given a string s with 1... | {"inputs": ["ETAUDARGTSOP", "AACDEFGHIJKL", "COCEFESTIVAL", "POSTGRADUATF", "ALCDEFGHIJKA", "COCEFESTIV@L", "POSTGRAUDATF", "AKJIHGFEDCLA"], "outputs": ["ETAU DARGTSOP\n", "AACD EFGHIJKL\n", "COCE FESTIVAL\n", "POST GRADUATF\n", "ALCD EFGHIJKA\n", "COCE FESTIV@L\n", "POST GRAUDATF\n", "AKJI HGFEDCLA\n"]} | 221 | 140 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a string text and an array of strings words, return an array of all index pairs [i, j] so that the substring text[i...j] is in words.
Return the pairs [i, j] in sorted order (i.e., sort them by their first coord... | {"functional": "def check(candidate):\n assert candidate(text = \"thestoryofleetcodeandme\", words = [\"story\",\"fleet\",\"leetcode\"]) == [[3,7],[9,13],[10,17]]\n assert candidate(text = \"ababa\", words = [\"aba\",\"ab\"]) == [[0,1],[0,2],[2,3],[2,4]]\n\n\ncheck(Solution().indexPairs)"} | 124 | 100 |
coding | Solve the programming task below in a Python markdown code block.
Gerald has n younger brothers and their number happens to be even. One day he bought n^2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer k from 1 to n^2 he has exactly one bag wit... | {"inputs": ["2\n", "4\n", "6\n", "8\n", "4\n", "6\n", "8\n", "2\n"], "outputs": ["1 4\n2 3\n", "1 16 2 15\n3 14 4 13\n5 12 6 11\n7 10 8 9\n", "1 36 2 35 3 34\n4 33 5 32 6 31\n7 30 8 29 9 28\n10 27 11 26 12 25\n13 24 14 23 15 22\n16 21 17 20 18 19\n", "1 64 2 63 3 62 4 61\n5 60 6 59 7 58 8 57\n9 56 10 55 11 54 12 53\n13... | 311 | 712 |
coding | Solve the programming task below in a Python markdown code block.
You have an array a of length n. For every positive integer x you are going to perform the following operation during the x-th second:
* Select some distinct indices i_{1}, i_{2}, …, i_{k} which are between 1 and n inclusive, and add 2^{x-1} to each c... | {"inputs": ["3\n4\n1 7 6 5\n5\n1 2 3 4 5\n2\n0 -7\n", "3\n4\n1 7 6 5\n5\n1 2 1 4 5\n2\n0 -7\n", "3\n4\n1 7 0 5\n5\n1 2 1 4 5\n2\n0 -7\n", "3\n4\n1 7 0 5\n5\n1 2 1 4 5\n2\n1 -7\n", "3\n4\n1 7 6 5\n5\n1 2 6 4 5\n2\n0 -4\n", "3\n4\n1 7 6 5\n5\n1 2 5 4 5\n2\n0 -7\n", "3\n4\n1 7 6 5\n5\n1 4 1 4 5\n2\n0 -7\n", "3\n4\n1 7 1 5... | 529 | 326 |
coding | Solve the programming task below in a Python markdown code block.
When you look at photographs of watches and clocks, you'll find that they almost always show the time 10:10. There are lots of theories and even urban legends about this. For example, when showing 10:10, the hands look like a smile, and so you are more i... | {"inputs": ["2\n2 3\n3 3\n"], "outputs": ["3\n62\n"]} | 445 | 25 |
coding | Solve the programming task below in a Python markdown code block.
Ashton appeared for a job interview and is asked the following question. Arrange all the distinct substrings of a given string in lexicographical order and concatenate them. Print the $k^{th}$ character of the concatenated string. It is assured that giv... | {"inputs": ["1\ndbac\n3\n"], "outputs": ["c\n"]} | 566 | 19 |
coding | Solve the programming task below in a Python markdown code block.
A binary string is called a self-destructing string if it can reduced to an empty string by performing the following operation some number of times (possibly zero): Choose a valid integer $i$ such that the $i$-th character of the current string is differ... | {"inputs": ["3\n001101\n1101\n110"], "outputs": ["0\n1\n-1"]} | 564 | 33 |
coding | Solve the programming task below in a Python markdown code block.
The NumPy (Numeric Python) package helps us manipulate large arrays and matrices of numeric data.
To use the NumPy module, we need to import it using:
import numpy
Arrays
A NumPy array is a grid of values. They are similar to lists, except that ev... | {"inputs": ["1 2 3 4 -8 -10\n"], "outputs": ["[-10. -8. 4. 3. 2. 1.]\n"]} | 272 | 49 |
coding | Solve the programming task below in a Python markdown code block.
There is data of up to 100 characters per line, consisting of half-width alphabetic character strings. Some lines are symmetric (same whether read from the left edge or the right edge). Create a program that reads this data and outputs the number of symm... | {"inputs": ["abcba\nsx\nabcddcba\nrstrd", "abcca\nsw\nabcddcba\nrstrd", "abcca\nxt\nadcbdcba\nrdsrt", "abcba\nsw\nabcddcba\nrstrd", "accba\nsw\nabcddcba\nrstrd", "accba\nsx\nabcddcba\nrstrd", "accba\ntx\nabcddcba\nrstrd", "accba\ntx\nabcddcba\nrsdrt"], "outputs": ["2\n", "1\n", "0\n", "2\n", "1\n", "1\n", "1\n", "1\n"]... | 143 | 153 |
coding | Solve the programming task below in a Python markdown code block.
Create a function `longer` that accepts a string and sorts the words in it based on their respective lengths in an ascending order. If there are two words of the same lengths, sort them alphabetically. Look at the examples below for more details.
```pyt... | {"functional": "_inputs = [['Another Green World'], ['Darkness on the edge of Town'], ['Have you ever Seen the Rain'], ['Like a Rolling Stone'], ['This will be our Year'], ['hello Hello']]\n_outputs = [['Green World Another'], ['of on the Town edge Darkness'], ['the you Have Rain Seen ever'], ['a Like Stone Rolling'], ... | 198 | 225 |
coding | Solve the programming task below in a Python markdown code block.
Chef visited a grocery store for fresh supplies. There are N items in the store where the i^{th} item has a freshness value A_{i} and cost B_{i}.
Chef has decided to purchase all the items having a freshness value greater than equal to X. Find the total... | {"inputs": ["4\n2 20\n15 67\n10 90\n3 1\n1 2 3\n1 2 3\n3 100\n10 90 50\n30 7 93\n4 50\n12 78 50 40\n40 30 20 10\n"], "outputs": ["90\n6\n0\n50\n"]} | 554 | 107 |
coding | Solve the programming task below in a Python markdown code block.
Chef's playlist contains 3 songs named A, B, and C, each of duration exactly X minutes. Chef generally plays these 3 songs in loop, i.e, A \rightarrow B \rightarrow C \rightarrow A \rightarrow B \rightarrow C \rightarrow A \rightarrow \dots
Chef went on... | {"inputs": ["5\n6 1\n5 1\n11 2\n5 8\n100 9\n"], "outputs": ["2\n1\n1\n0\n3\n"]} | 457 | 45 |
coding | Solve the programming task below in a Python markdown code block.
Problem Statement:Captain America and Iron Man are at WAR and the rage inside Iron Man is rising.
But Iron Man faces a problem to identify the location of Captain America.
There are N buildings situtaed adjacently to each other and Captain America can ... | {"inputs": ["3\n2 1\n3 0\n3 2"], "outputs": ["2 1\n1 2 3\nCAPTAIN AMERICA EVADES"]} | 354 | 41 |
coding | Solve the programming task below in a Python markdown code block.
Sarthak has a set S of N distinct prime numbers. He grew very fond of that set, and now he only likes a positive integer X if all of its prime factors belong to S. Given the set and a positive integer M, can you find out how many integers he likes which ... | {"inputs": ["1\n2 10\n3 5\n"], "outputs": ["4"]} | 329 | 22 |
coding | Solve the programming task below in a Python markdown code block.
Let F(S) denote the number of distinct elements in the array S. For example, F([1, 2, 3, 2]) = 3, F([1, 2]) = 2.
You are given an array A containing N integers. Find if it is possible to divide the elements of the array A into two arrays B and C such th... | {"inputs": ["3\n2\n1 2\n3\n1 2 3\n4\n3 1 1 2\n"], "outputs": ["YES\nNO\nYES\n"]} | 500 | 42 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer array nums. The range of a subarray of nums is the difference between the largest and smallest element in the subarray.
Return the sum of all subarray ranges of nums.
A subarray is a contiguou... | {"functional": "def check(candidate):\n assert candidate(nums = [1,2,3]) == 4\n assert candidate(nums = [1,3,3]) == 4\n assert candidate(nums = [4,-2,-3,4,1]) == 59\n\n\ncheck(Solution().subArrayRanges)"} | 105 | 73 |
coding | Solve the programming task below in a Python markdown code block.
It is known that there are k fish species in the polar ocean, numbered from 1 to k. They are sorted by non-decreasing order of their weight, which is a positive number. Let the weight of the i-th type of fish be wi, then 0 < w1 ≤ w2 ≤ ... ≤ wk holds.
Po... | {"inputs": ["1 1 1\n1\n1\n", "3 3 3\n2 2 4\n1 1 3\n", "3 3 3\n2 2 4\n1 1 1\n", "3 3 3\n2 2 4\n1 1 2\n", "3 3 3\n2 2 2\n1 1 3\n", "5 4 5\n1 2 2 3 4\n1 3 4 5\n", "5 5 10\n8 2 8 5 9\n9 1 7 5 1\n", "5 5 10\n8 2 8 5 1\n9 1 7 5 1\n"], "outputs": ["NO\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n"]} | 478 | 214 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
There is an m x n grid, where (0, 0) is the top-left cell and (m - 1, n - 1) is the bottom-right cell. You are given an integer array startPos where startPos = [startrow, startcol] indicates that initially, a robot is... | {"functional": "def check(candidate):\n assert candidate(startPos = [1, 0], homePos = [2, 3], rowCosts = [5, 4, 3], colCosts = [8, 2, 6, 7]) == 18\n assert candidate(startPos = [0, 0], homePos = [0, 0], rowCosts = [5], colCosts = [26]) == 0\n\n\ncheck(Solution().minCost)"} | 306 | 114 |
coding | Solve the programming task below in a Python markdown code block.
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef has A units of solid and B units of liquid. He combines them to create a mixture. What kind of mixture does Chef produce: a solution, a solid, or a liqui... | {"inputs": ["3\n10 5\n0 3\n3 0\n"], "outputs": ["Solution\nLiquid\nSolid\n"]} | 363 | 31 |
coding | Solve the programming task below in a Python markdown code block.
n hobbits are planning to spend the night at Frodo's house. Frodo has n beds standing in a row and m pillows (n ≤ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not alway... | {"inputs": ["4 6 2\n", "3 6 1\n", "3 3 3\n", "1 1 1\n", "3 3 3\n", "1 1 1\n", "3 8 3\n", "3 6 1\n"], "outputs": ["2\n", "3\n", "1\n", "1\n", "1\n", "1\n", "3\n", "3\n"]} | 378 | 102 |
coding | Solve the programming task below in a Python markdown code block.
In mathematics, the factorial of integer 'n' is written as 'n!'.
It is equal to the product of n and every integer preceding it.
For example: **5! = 1 x 2 x 3 x 4 x 5 = 120**
Your mission is simple: write a function that takes an integer 'n' and returns... | {"functional": "_inputs = [[-1]]\n_outputs = [[None]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_... | 175 | 155 |
coding | Solve the programming task below in a Python markdown code block.
You like the way the Python `+` operator easily handles adding different numeric types, but you need a tool to do that kind of addition without killing your program with a `TypeError` exception whenever you accidentally try adding incompatible types like... | {"functional": "_inputs = [[1, 3.414], [42, ' is the answer.'], [10, '2']]\n_outputs = [[4.414], [None], [None]]\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 i... | 194 | 188 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.