problem stringlengths 14 4.09k | solution stringlengths 1 802k | task_type stringclasses 3
values | problem_tokens int64 5 895 |
|---|---|---|---|
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 candies. Each element in the array denotes a pile of candies of size candies[i]. You can divide each pile into any number of sub piles, but you cannot merge two piles together.
... | {"functional": "def check(candidate):\n assert candidate(candies = [5,8,6], k = 3) == 5\n assert candidate(candies = [2,5], k = 11) == 0\n\n\ncheck(Solution().maximumCandies)"} | coding | 159 |
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian.
You are given two positive integers – A and B. You have to check whether A is divisible by all the prime divisors of B.
------ Input ------
The first line of the input contains an integer T ... | {"inputs": ["3\n215 16\n12 4\n4 4", "3\n153 7\n20 16\n3 5", "3\n120 16\n128 4\n4 4", "3\n215 16\n128 4\n4 4", "3\n215 16\n128 8\n4 4", "3\n153 75\n20 16\n3 3", "3\n215 16\n128 8\n6 4", "3\n153 29\n20 16\n3 3"], "outputs": ["No\nYes\nYes\n", "No\nYes\nNo\n", "Yes\nYes\nYes\n", "No\nYes\nYes\n", "No\nYes\nYes\n", "No\nYe... | coding | 386 |
Solve the programming task below in a Python markdown code block.
Polycarp and Vasiliy love simple logical games. Today they play a game with infinite chessboard and one pawn for each player. Polycarp and Vasiliy move in turns, Polycarp starts. In each turn Polycarp can move his pawn from cell (x, y) to (x - 1, y) or (... | {"inputs": ["2 1 2 2\n", "4 7 7 4\n", "0 1 0 2\n", "0 1 1 0\n", "0 1 1 1\n", "0 1 1 2\n", "0 1 2 0\n", "0 1 2 1\n"], "outputs": ["Polycarp\n", "Vasiliy\n", "Polycarp\n", "Polycarp\n", "Polycarp\n", "Polycarp\n", "Polycarp\n", "Polycarp\n"]} | coding | 444 |
Solve the programming task below in a Python markdown code block.
Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it?
The market analysts came up with a very smart plan: the name of the company should be identi... | {"inputs": ["Z\n", "A\n", "B\n", "C\n", "D\n", "E\n", "F\n", "G\n"], "outputs": ["NO\n", "YES\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]} | coding | 323 |
Solve the programming task below in a Python markdown code block.
Let's call (yet again) a string good if its length is even, and every character in odd position of this string is different from the next character (the first character is different from the second, the third is different from the fourth, and so on). For... | {"inputs": ["1\na\n", "1\nf\n", "1\na\n", "1\nf\n", "1\nb\n", "1\ng\n", "1\nc\n", "1\nh\n"], "outputs": ["1\n\n", "1\n\n", "1\n\n", "1\n\n", "1\n\n", "1\n\n", "1\n\n", "1\n\n"]} | coding | 300 |
Solve the programming task below in a Python markdown code block.
Pay attention to the non-standard memory limit in this problem.
In order to cut off efficient solutions from inefficient ones in this problem, the time limit is rather strict. Prefer to use compiled statically typed languages (e.g. C++). If you use Pyth... | {"inputs": ["7\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n", "7\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n", "7\n1\n1\n1\n1\n1\n0\n1\n1\n1\n1\n1\n1\n1\n1\n", "7\n1\n1\n1\n1\n1\n1\n1\n0\n1\n1\n1\n1\n1\n1\n", "7\n1\n1\n1\n1\n1\n1\n1\n0\n1\n1\n1\n1\n1\n0\n", "7\n1\n0\n1\n1\n1\n1\n1\n0\n1\n1\n1\n1\n1\n1\n", "5\n9\n3 1 4 1... | coding | 718 |
Solve the programming task below in a Python markdown code block.
You are given a string $s$ of even length $n$. String $s$ is binary, in other words, consists only of 0's and 1's.
String $s$ has exactly $\frac{n}{2}$ zeroes and $\frac{n}{2}$ ones ($n$ is even).
In one operation you can reverse any substring of $s$. ... | {"inputs": ["3\n2\n10\n4\n0110\n8\n11101000\n", "3\n2\n10\n4\n0110\n8\n11100001\n", "3\n2\n10\n4\n1010\n8\n11101000\n", "3\n2\n10\n4\n0011\n8\n11101000\n", "3\n2\n10\n4\n0101\n8\n11100001\n", "3\n2\n10\n4\n0101\n8\n11101000\n", "3\n2\n10\n4\n0011\n8\n11100001\n", "3\n2\n10\n4\n1001\n8\n11101000\n"], "outputs": ["0\n1\n... | coding | 507 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
A bus has n stops numbered from 0 to n - 1 that form a circle. We know the distance between all pairs of neighboring stops where distance[i] is the distance between the stops number i and (i + 1) % n.
The bus goes alo... | {"functional": "def check(candidate):\n assert candidate(distance = [1,2,3,4], start = 0, destination = 1) == 1\n assert candidate(distance = [1,2,3,4], start = 0, destination = 2) == 3\n assert candidate(distance = [1,2,3,4], start = 0, destination = 3) == 4\n\n\ncheck(Solution().distanceBetweenBusStops)"} | coding | 145 |
Solve the programming task below in a Python markdown code block.
There is an infinitely large pond, which we consider as a number line.
In this pond, there are N lotuses floating at coordinates 0, 1, 2, ..., N-2 and N-1.
On the lotus at coordinate i, an integer s_i is written.
You are standing on the lotus at coordina... | {"inputs": ["5\n0 2 5 0 0", "5\n0 2 5 1 0", "5\n0 2 5 1 0\n", "6\n0 7 -7 -4 0 0", "6\n0 2 -7 -1 -5 0", "6\n0 4 -7 -1 -3 0", "6\n0 4 -7 -1 -1 0", "6\n0 5 -7 -2 -1 0"], "outputs": ["2\n", "3", "3\n", "7\n", "0\n", "1\n", "3\n", "4\n"]} | coding | 634 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed 2D integer array transactions, where transactions[i] = [costi, cashbacki].
The array describes transactions, where each transaction must be completed exactly once in some order. At any given ... | {"functional": "def check(candidate):\n assert candidate(transactions = [[2,1],[5,0],[4,2]]) == 10\n assert candidate(transactions = [[3,0],[0,3]]) == 3\n\n\ncheck(Solution().minimumMoney)"} | coding | 165 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
There is a binary tree rooted at 0 consisting of n nodes. The nodes are labeled from 0 to n - 1. You are given a 0-indexed integer array parents representing the tree, where parents[i] is the parent of node i. Since n... | {"functional": "def check(candidate):\n assert candidate(parents = [-1,2,0,2,0]) == 3\n assert candidate(parents = [-1,2,0]) == 2\n\n\ncheck(Solution().countHighestScoreNodes)"} | coding | 200 |
Solve the programming task below in a Python markdown code block.
This is an easy version of the problem. In this version, all cards have the same color.
Alice has $n$ cards, each card is white, and the cards are stacked in a deck. Alice deals the cards to herself and to Bob, dealing at once several cards from the top... | {"inputs": ["5\n10\n6\n17\n8\n1000000\n"], "outputs": ["5 5\n1 5\n10 7\n3 5\n500202 499798\n"]} | coding | 396 |
Solve the programming task below in a Python markdown code block.
You are given an array that of arbitrary depth that needs to be nearly flattened into a 2 dimensional array. The given array's depth is also non-uniform, so some parts may be deeper than others.
All of lowest level arrays (most deeply nested) will conta... | {"functional": "_inputs = [[[[1]]], [[[1, 2, 3], [4, 5, 6]]], [[[1, 2, 3], [[4, 5], [[6], [7, 8]]]]], [[[[1, 2, 3], [9, 10]], [[4, 5], [6, 7, 8]]]]]\n_outputs = [[[[1]]], [[[1, 2, 3], [4, 5, 6]]], [[[1, 2, 3], [4, 5], [6], [7, 8]]], [[[1, 2, 3], [4, 5], [6, 7, 8], [9, 10]]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\... | coding | 231 |
Solve the programming task below in a Python markdown code block.
This program tests the life of an
evaporator containing a gas.
We know the content of the evaporator (content in ml),
the percentage of foam or gas lost every day (evap_per_day)
and the threshold (threshold) in percentage beyond which
the evaporator is... | {"functional": "_inputs = [[10, 10, 10], [10, 10, 5], [100, 5, 5], [50, 12, 1], [47.5, 8, 8], [100, 1, 1], [10, 1, 1], [100, 1, 5]]\n_outputs = [[22], [29], [59], [37], [31], [459], [459], [299]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclo... | coding | 203 |
Solve the programming task below in a Python markdown code block.
Switch/Case - Bug Fixing #6
Oh no! Timmy's evalObject function doesn't work. He uses Switch/Cases to evaluate the given properties of an object, can you fix timmy's function?
Also feel free to reuse/extend the following starter code:
```python
def eval_... | {"functional": "_inputs = [[{'a': 1, 'b': 1, 'operation': '+'}], [{'a': 1, 'b': 1, 'operation': '-'}], [{'a': 1, 'b': 1, 'operation': '/'}], [{'a': 1, 'b': 1, 'operation': '*'}], [{'a': 1, 'b': 1, 'operation': '%'}], [{'a': 1, 'b': 1, 'operation': '**'}]]\n_outputs = [[2], [0], [1], [1], [0], [1]]\nimport math\ndef _de... | coding | 79 |
Solve the programming task below in a Python markdown code block.
There are N sightseeing spots on the x-axis, numbered 1, 2, ..., N.
Spot i is at the point with coordinate A_i.
It costs |a - b| yen (the currency of Japan) to travel from a point with coordinate a to another point with coordinate b along the axis.
You p... | {"inputs": ["3\n3 5 -1\n", "5\n1 1 1 2 0\n", "6\n-679 -2409 -3258 3095 -3291 -4462\n"], "outputs": ["12\n8\n10\n", "4\n4\n4\n2\n4\n", "21630\n21630\n19932\n8924\n21630\n19288\n"]} | coding | 566 |
Solve the programming task below in a Python markdown code block.
Not so long ago, Vlad had a birthday, for which he was presented with a package of candies. There were $n$ types of candies, there are $a_i$ candies of the type $i$ ($1 \le i \le n$).
Vlad decided to eat exactly one candy every time, choosing any of the... | {"inputs": ["1\n1\n100000\n", "1\n3\n1 2 12212221\n", "6\n2\n2 3\n1\n2\n5\n1 6 2 4 3\n4\n2 2 2 1\n3\n1 1000000000 999999999\n1\n1\n"], "outputs": ["NO\n", "NO\n", "YES\nNO\nNO\nYES\nYES\nYES\n"]} | coding | 711 |
Solve the programming task below in a Python markdown code block.
This kata is blatantly copied from inspired by This Kata
Welcome
this is the second in the series of the string iterations kata!
Here we go!
---------------------------------------------------------------------------------
We have a string s
Let's... | {"functional": "_inputs = [['This is a string exemplification!', 0], ['String for test: incommensurability', 1], ['Ohh Man God Damn', 7], ['Ohh Man God Damnn', 19], ['I like it!', 1234], ['codingisfornerdsyounerd', 10101010], ['this_test_will_hurt_you', 12345678987654321]]\n_outputs = [['This is a string exemplificatio... | coding | 377 |
Solve the programming task below in a Python markdown code block.
Write function describeList which returns "empty" if the list is empty or "singleton" if it contains only one element or "longer"" if more.
Also feel free to reuse/extend the following starter code:
```python
def describeList(list):
``` | {"functional": "_inputs = [[[]], [[1]], [[1, 2, 5, 4]], [['one']], [['one', 'two']], [[[1, 2]]]]\n_outputs = [['empty'], ['singleton'], ['longer'], ['singleton'], ['longer'], ['singleton']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, ... | coding | 66 |
Solve the programming task below in a Python markdown code block.
Convert a hash into an array. Nothing more, Nothing less.
```
{name: 'Jeremy', age: 24, role: 'Software Engineer'}
```
should be converted into
```
[["name", "Jeremy"], ["age", 24], ["role", "Software Engineer"]]
```
```if:python,javascript,crystal
**... | {"functional": "_inputs = [[{'name': 'Jeremy'}], [{'name': 'Jeremy', 'age': 24}], [{'name': 'Jeremy', 'age': 24, 'role': 'Software Engineer'}], [{'product': 'CodeWars', 'power_level_over': 9000}], [{}]]\n_outputs = [[[['name', 'Jeremy']]], [[['age', 24], ['name', 'Jeremy']]], [[['age', 24], ['name', 'Jeremy'], ['role',... | coding | 127 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You have a graph of n nodes labeled from 0 to n - 1. You are given an integer n and a list of edges where edges[i] = [ai, bi] indicates that there is an undirected edge between nodes ai and bi in the graph.
Return tru... | {"functional": "def check(candidate):\n assert candidate(n = 5, edges = [[0,1],[0,2],[0,3],[1,4]]) == True\n assert candidate(n = 5, edges = [[0,1],[1,2],[2,3],[1,3],[1,4]]) == False\n\n\ncheck(Solution().validTree)"} | coding | 127 |
Solve the programming task below in a Python markdown code block.
One day, early in the morning, you decided to buy yourself a bag of chips in the nearby store. The store has chips of $n$ different flavors. A bag of the $i$-th flavor costs $a_i$ burles.
The store may run out of some flavors, so you'll decide which one... | {"inputs": ["1\n1\n5\n", "1\n1\n8\n", "1\n1\n2\n", "1\n1\n78\n", "1\n1\n46\n", "1\n1\n16\n", "1\n1\n37\n", "1\n1\n87\n"], "outputs": ["2\n", "3\n", "1\n", "26\n", "16\n", "6\n", "13\n", "29\n"]} | coding | 597 |
Solve the programming task below in a Python markdown code block.
In this kata the function returns an array/list like the one passed to it but with its nth element removed (with `0 <= n <= array/list.length - 1`). The function is already written for you and the basic tests pass, but random tests fail. Your task is to ... | {"functional": "_inputs = [[[9, 7, 6, 9], 0]]\n_outputs = [[[7, 6, 9]]]\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 | 201 |
Solve the programming task below in a Python markdown code block.
There are n cities situated along the main road of Berland. Cities are represented by their coordinates — integer numbers a_1, a_2, ..., a_{n}. All coordinates are pairwise distinct.
It is possible to get from one city to another only by bus. But all bu... | {"inputs": ["2\n1 2\n", "2\n1 2\n", "2\n0 2\n", "2\n1 6\n", "2\n9 3\n", "2\n1 3\n", "2\n9 2\n", "2\n7 9\n"], "outputs": ["1 1\n", "1 1\n", "2 1 ", "5 1 ", "6 1 ", "2 1 ", "7 1 ", "2 1 "]} | coding | 365 |
Solve the programming task below in a Python markdown code block.
You are given a valid XML document, and you have to print its score. The score is calculated by the sum of the score of each element. For any element, the score is equal to the number of attributes it has.
Input Format
The first line contains $N$, the... | {"inputs": ["6\n<feed xml:lang='en'>\n <title>HackerRank</title>\n <subtitle lang='en'>Programming challenges</subtitle>\n <link rel='alternate' type='text/html' href='http://hackerrank.com/'/>\n <updated>2013-12-25T12:00:00</updated>\n</feed>\n"], "outputs": ["5\n"]} | coding | 369 |
Solve the programming task below in a Python markdown code block.
Bobby has decided to hunt some Parrots. There are n horizontal branch of trees aligned parallel to each other. Branches are numbered 1 to n from top to bottom. On each branch there are some parrots sitting next to each other. Supposed there are a[i]$a[i]... | {"inputs": ["5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6\n3\n2 4 1\n1\n2 2"], "outputs": ["0\n12\n5\n0\n16\n3\n0\n3"]} | coding | 617 |
Solve the programming task below in a Python markdown code block.
There is an event in DUCS where boys get a chance to show off their skills to impress girls. The boy who impresses the maximum number of girls will be honoured with the title “Charming Boy of the year”.
There are $N$ girls in the department. Each girl gi... | {"inputs": ["2\n10\njohn berry berry thomas thomas john john berry thomas john\n4\nramesh suresh suresh ramesh"], "outputs": ["john\nramesh"]} | coding | 468 |
Solve the programming task below in a Python markdown code block.
You have invented a time-machine which has taken you back to ancient Rome. Caeser is impressed with your programming skills and has appointed you to be the new information security officer.
Caeser has ordered you to write a Caeser cipher to prevent Aste... | {"functional": "_inputs = [['This is a message', 0], ['who are you?', 18], ['..5tyu..', 25], ['..#$%^..', 0], ['..#$%^..', 26], ['final one', 9]]\n_outputs = [['THIS IS A MESSAGE'], ['OZG SJW QGM?'], ['..5SXT..'], ['..#$%^..'], ['..#$%^..'], ['ORWJU XWN']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(... | coding | 185 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed array of strings words and a 2D array of integers queries.
Each query queries[i] = [li, ri] asks us to find the number of strings present in the range li to ri (both inclusive) of words that ... | {"functional": "def check(candidate):\n assert candidate(words = [\"aba\",\"bcb\",\"ece\",\"aa\",\"e\"], queries = [[0,2],[1,4],[1,1]]) == [2,3,0]\n assert candidate(words = [\"a\",\"e\",\"i\"], queries = [[0,2],[0,1],[2,2]]) == [3,2,1]\n\n\ncheck(Solution().vowelStrings)"} | coding | 160 |
Solve the programming task below in a Python markdown code block.
Create a program that reads the sales unit price and sales quantity and outputs the total sales amount and the average sales quantity.
Input
The input is given in the following format:
Sales unit price, sales quantity
Sales unit price, sales quanti... | {"inputs": ["100,20\n50,10\n80,35", "100,20\n01,05\n80,35", "100,20\n01,05\n80,36", "100,20\n01,05\n81,35", "000,20\n01,05\n80,36", "100,20\n50,10\n81,35", "000,10\n01,05\n80,36", "100,20\n50,01\n81,35"], "outputs": ["5300\n22\n", "4805\n20\n", "4885\n20\n", "4840\n20\n", "2885\n20\n", "5335\n22\n", "2885\n17\n", "4885... | coding | 205 |
Solve the programming task below in a Python markdown code block.
Write a function to split a string and convert it into an array of words. For example:
```python
"Robin Singh" ==> ["Robin", "Singh"]
"I love arrays they are my favorite" ==> ["I", "love", "arrays", "they", "are", "my", "favorite"]
```
Also feel free t... | {"functional": "_inputs = [['Robin Singh'], ['CodeWars'], ['I love arrays they are my favorite'], ['1 2 3'], ['']]\n_outputs = [[['Robin', 'Singh']], [['CodeWars']], [['I', 'love', 'arrays', 'they', 'are', 'my', 'favorite']], [['1', '2', '3']], [['']]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, f... | coding | 101 |
Solve the programming task below in a Python markdown code block.
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exam... | {"inputs": ["1\n2 1\n", "1\n2 2\n", "2\n4 2\n4 1\n", "2\n3 2\n3 2\n", "2\n5 2\n5 1\n", "2\n3 1\n3 2\n", "2\n2 2\n4 1\n", "2\n3 2\n3 1\n"], "outputs": ["1", "2\n", "2", "2", "2", "2", "4\n", "2\n"]} | coding | 602 |
Solve the programming task below in a Python markdown code block.
Here your task is to Create a (nice) Christmas Tree.
You don't have to check errors or incorrect input values, every thing is ok without bad tricks, only one int parameter as input and a string to return;-)...
So what to do?First three easy examples:
``... | {"functional": "_inputs = [[5], [10], [8], [2]]\n_outputs = [[' *\\r\\n ***\\r\\n*****\\r\\n ###'], [' *\\r\\n ***\\r\\n *****\\r\\n ***\\r\\n *****\\r\\n *******\\r\\n *****\\r\\n *******\\r\\n*********\\r\\n ###'], [' *\\r\\n ***\\r\\n *****\\r\\n ***\\r\\n *****\\r\\n*******\\r\\n ###'], ['']]\nimp... | coding | 314 |
Solve the programming task below in a Python markdown code block.
You are given a permutation p_1,p_2,...,p_N consisting of 1,2,..,N.
You can perform the following operation any number of times (possibly zero):
Operation: Swap two adjacent elements in the permutation.
You want to have p_i ≠ i for all 1≤i≤N.
Find the mi... | {"inputs": ["2\n1 0", "2\n1 1", "2\n0 2", "2\n2 2", "2\n0 1", "2\n2 0", "2\n0 0", "2\n0 3"], "outputs": ["1\n", "1\n", "1\n", "1\n", "0\n", "0\n", "0\n", "0\n"]} | coding | 237 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed array of unique strings words.
A palindrome pair is a pair of integers (i, j) such that:
0 <= i, j < words.length,
i != j, and
words[i] + words[j] (the concatenation of the two strings) is a... | {"functional": "def check(candidate):\n assert candidate(words = [\"abcd\",\"dcba\",\"lls\",\"s\",\"sssll\"]) == [[0,1],[1,0],[3,2],[2,4]] \n assert candidate(words = [\"bat\",\"tab\",\"cat\"]) == [[0,1],[1,0]] \n assert candidate(words = [\"a\",\"\"]) == [[0,1],[1,0]]\n\n\ncheck(Solution().palindromePairs)"} | coding | 145 |
Solve the programming task below in a Python markdown code block.
Given a matrix (H × W) which contains only 1 and 0, find the area of the largest rectangle which only contains 0s.
Constraints
* 1 ≤ H, W ≤ 1,400
Input
H W
c1,1 c1,2 ... c1,W
c2,1 c2,2 ... c2,W
:
cH,1 cH,2 ... cH,W
In the first line, two integers ... | {"inputs": ["4 5\n0 0 1 0 0\n1 0 0 0 0\n0 0 0 0 0\n0 0 0 1 0", "4 5\n0 0 1 0 0\n1 0 0 0 0\n0 0 0 0 1\n0 0 0 1 0", "1 5\n0 0 1 0 0\n1 0 0 0 1\n0 0 0 1 0\n0 0 0 1 0", "4 5\n1 0 1 1 0\n1 0 0 0 0\n0 0 1 0 0\n0 0 0 1 0", "4 5\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 1 0", "4 5\n0 0 0 0 0\n1 1 0 0 0\n0 0 0 0 0\n0 0 0 1 0", "4... | coding | 213 |
Solve the programming task below in a Python markdown code block.
Problem Statement
We can describe detailed direction by repeating the directional names: north, south, east and west. For example, northwest is the direction halfway between north and west, and northnorthwest is between north and northwest.
In this pro... | {"inputs": ["north\nwest\nnorthwest\nnorthnorthwest\nwestwestwestnorth\n#"], "outputs": ["0\n90\n45\n45/2\n315/4"]} | coding | 461 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
A valid encoding of an array of words is any reference string s and array of indices indices such that:
words.length == indices.length
The reference string s ends with the '#' character.
For each index indices[i], th... | {"functional": "def check(candidate):\n assert candidate(words = [\"time\", \"me\", \"bell\"]) == 10\n assert candidate(words = [\"t\"]) == 2\n\n\ncheck(Solution().minimumLengthEncoding)"} | coding | 142 |
Solve the programming task below in a Python markdown code block.
You are given a sequence of a journey in London, UK. The sequence will contain bus **numbers** and TFL tube names as **strings** e.g.
```python
['Northern', 'Central', 243, 1, 'Victoria']
```
Journeys will always only contain a combination of tube names... | {"functional": "_inputs = [[[12, 'Central', 'Circle', 21]], [['Piccidilly', 56]], [['Northern', 'Central', 'Circle']], [['Piccidilly', 56, 93, 243]], [[386, 56, 1, 876]], [[]]]\n_outputs = [['\u00a37.80'], ['\u00a33.90'], ['\u00a37.20'], ['\u00a35.40'], ['\u00a33.00'], ['\u00a30.00']]\nimport math\ndef _deep_eq(a, b, t... | coding | 202 |
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$ consisting of $N$ positive integers.
He is playing a game with this sequence. The goal of the game is to maximize the greatest common divisor of all... | {"inputs": ["2\n2\n1 25\n5\n27 3 15 1024 15"], "outputs": ["1\n6"]} | coding | 384 |
Solve the programming task below in a Python markdown code block.
N candidates (numbered from 1 to N) join Chef's firm. The first 5 candidates join on the first day, and then, on every subsequent day, the next 5 candidates join in.
For example, if there are 12 candidates, candidates numbered 1 to 5 will join on day 1... | {"inputs": ["4\n7 3\n6 6\n2 1\n14 2"], "outputs": ["1\n0\n0\n2\n"]} | coding | 692 |
Solve the programming task below in a Python markdown code block.
For a permutation P of integers from 1 to N, let's define its value as (1 \oplus P_{1}) + (2 \oplus P_{2}) + \ldots + (N \oplus P_{N}).
Given N, find the maximum possible value of the permutation of integers from 1 to N.
As a reminder, \oplus denotes ... | {"inputs": ["5\n1\n2\n3\n4\n29012022"], "outputs": ["0\n6\n6\n20\n841697449540506"]} | coding | 510 |
Solve the programming task below in a Python markdown code block.
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
There is a large tree house in an unknown world. It is ruled by the great emperor KZS. It consists of $N$ nodes numbered from $1$ to $N$ in which the people o... | {"inputs": ["2\n4 1\n1 2\n1 3\n1 4\n8 1\n1 2\n1 3\n2 4\n2 5\n5 6\n5 7\n7 8"], "outputs": ["7\n11"]} | coding | 609 |
Solve the programming task below in a Python markdown code block.
The famous global economic crisis is approaching rapidly, so the states of Berman, Berance and Bertaly formed an alliance and allowed the residents of all member states to freely pass through the territory of any of them. In addition, it was decided that... | {"inputs": ["1 3\n231\n", "1 3\n231\n", "1 4\n12#3\n", "1 4\n12#3\n", "1 4\n3#21\n", "1 4\n3#12\n", "1 5\n1#2#3\n", "3 1\n3\n1\n2\n"], "outputs": ["0\n", "0\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "0\n"]} | coding | 523 |
Solve the programming task below in a Python markdown code block.
A festival will be held in a town's main street. There are n sections in the main street. The sections are numbered 1 through n from left to right. The distance between each adjacent sections is 1.
In the festival m fireworks will be launched. The i-th ... | {"inputs": ["10 2 1\n1 1000 4\n9 1000 4\n", "10 2 1\n1 1000 4\n9 1000 4\n", "50 3 1\n49 1 1\n26 1 4\n6 1 6\n", "50 3 1\n49 1 1\n26 1 4\n8 1 6\n", "50 3 1\n49 1 1\n26 1 4\n4 1 6\n", "50 3 2\n49 1 1\n26 1 4\n6 1 6\n", "50 3 2\n49 1 1\n26 1 4\n4 1 6\n", "65 3 0\n49 1 1\n26 1 2\n4 1 6\n"], "outputs": ["1992\n", " ... | coding | 500 |
Solve the programming task below in a Python markdown code block.
You are given an integer $n$. You have to calculate the number of binary (consisting of characters 0 and/or 1) strings $s$ meeting the following constraints.
For every pair of integers $(i, j)$ such that $1 \le i \le j \le n$, an integer $a_{i,j}$ is gi... | {"inputs": ["2\n0 0\n2\n", "2\n1 0\n2\n", "2\n1 2\n2\n", "3\n1 0 2\n1 0\n1\n", "3\n1 1 2\n1 0\n1\n", "3\n1 2 1\n1 0\n1\n", "3\n2 0 2\n0 1\n1\n", "3\n0 0 0\n2 0\n2\n"], "outputs": ["0\n", "0\n", "0\n", "6\n", "2\n", "0\n", "0\n", "0\n"]} | coding | 543 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
The chess knight has a unique movement, it may move two squares vertically and one square horizontally, or two squares horizontally and one square vertically (with both forming the shape of an L). The possible movemen... | {"functional": "def check(candidate):\n assert candidate(n = 1) == 10\n assert candidate(n = 2) == 20\n assert candidate(n = 3131) == 136006598\n\n\ncheck(Solution().knightDialer)"} | coding | 217 |
Solve the programming task below in a Python markdown code block.
Chef has an array of N integers. He wants to play a special game. In this game he needs to make all the integers in the array greater than or equal to 0.
Chef can use two types of operations. The first type is to increase all the integers of the given ... | {"inputs": ["3\n2 3 0\n2", "3\n2 3 0\n3", "3\n2 3 0\n6", "3\n0 1 -2\n4", "3\n1 0 -1\n3", "3\n1 1 -7\n1", "3\n1 1 -9\n1", "3\n0 0 -2\n4"], "outputs": ["0\n", "0\n", "0\n", "2\n", "1\n", "7\n", "9\n", "2\n"]} | coding | 309 |
Solve the programming task below in a Python markdown code block.
— Do you have a wish?
— I want people to stop gifting each other arrays.
O_o and Another Young Boy
An array of $n$ positive integers $a_1,a_2,\ldots,a_n$ fell down on you from the skies, along with a positive integer $k \le n$.
You can apply the foll... | {"inputs": ["6\n3 1\n2 4 1\n3 2\n1 9 84\n3 1\n10 2 6\n3 2\n179 17 1000000000\n2 1\n5 9\n2 2\n4 2\n"], "outputs": ["4\n168\n10\n1000000000\n9\n1000000000\n"]} | coding | 670 |
Solve the programming task below in a Python markdown code block.
You are given circular array a0, a1, ..., an - 1. There are two types of operations with it:
* inc(lf, rg, v) — this operation increases each element on the segment [lf, rg] (inclusively) by v;
* rmq(lf, rg) — this operation returns minimal value ... | {"inputs": ["1\n1\n1\n0 0 0\n", "4\n1 2 3 4\n4\n3 0\n3 0 -1\n0 1\n2 1\n", "1\n-1\n10\n0 0 -1\n0 0\n0 0 1\n0 0\n0 0 1\n0 0\n0 0 0\n0 0\n0 0 -1\n0 0 1\n", "2\n-1 -1\n10\n0 0\n0 0\n0 0 1\n0 0\n1 1\n0 0 -1\n0 0 0\n0 0 1\n1 1 0\n0 0 -1\n"], "outputs": ["", "1\n0\n0\n", "-2\n-1\n0\n0\n", "-1\n-1\n0\n-1\n"]} | coding | 406 |
Solve the programming task below in a Python markdown code block.
You are given a string $s$ of length $n$ consisting of characters a and/or b.
Let $\operatorname{AB}(s)$ be the number of occurrences of string ab in $s$ as a substring. Analogically, $\operatorname{BA}(s)$ is the number of occurrences of ba in $s$ as a... | {"inputs": ["4\nb\naabbbabaa\nabbb\nabbaab\n", "4\nb\naabbbabaa\nabbb\nabbaab\n", "4\na\naabbbabaa\nabbb\nabbaab\n", "4\nb\naabbbabaa\nabbb\nabbabb\n", "4\na\naabababaa\nabbb\nabbaab\n", "4\nb\naabbbacaa\nabbb\nabbabb\n", "4\nc\naabbbacaa\nabbb\nabbabb\n", "4\nc\naacabbbaa\nabbb\nabbabb\n"], "outputs": ["b\naabbbabaa\n... | coding | 656 |
Solve the programming task below in a Python markdown code block.
There are n pearls in a row. Let's enumerate them with integers from 1 to n from the left to the right. The pearl number i has the type a_{i}.
Let's call a sequence of consecutive pearls a segment. Let's call a segment good if it contains two pearls of ... | {"inputs": ["3\n1 1 1\n", "3\n1 1 1\n", "3\n2 1 1\n", "3\n3 1 1\n", "3\n3 1 2\n", "3\n1 1 2\n", "3\n1 1 3\n", "3\n1 1 4\n"], "outputs": ["1\n1 3\n", "1\n1 3\n", "1\n1 3\n", "1\n1 3\n", "-1\n", "1\n1 3\n", "1\n1 3\n", "1\n1 3\n"]} | coding | 437 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You're given strings jewels representing the types of stones that are jewels, and stones representing the stones you have. Each character in stones is a type of stone you have. You want to know how many of the stones ... | {"functional": "def check(candidate):\n assert candidate(jewels = \"aA\", stones = \"aAAbbbb\") == 3\n assert candidate(jewels = \"z\", stones = \"ZZ\") == 0\n\n\ncheck(Solution().numJewelsInStones)"} | coding | 125 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given two binary search trees root1 and root2, return a list containing all the integers from both trees sorted in ascending order.
Please complete the following python code precisely:
```python
# Definition for a b... | {"functional": "def check(candidate):\n assert candidate(root1 = tree_node([2,1,4]), root2 = tree_node([1,0,3])) == [0,1,1,2,3,4]\n assert candidate(root1 = tree_node([1,None,8]), root2 = tree_node([8,1])) == [1,1,8,8]\n\n\ncheck(Solution().getAllElements)"} | coding | 132 |
Solve the programming task below in a Python markdown code block.
Given a matrix (H × W) which contains only 1 and 0, find the area of the largest square matrix which only contains 0s.
Constraints
* 1 ≤ H, W ≤ 1,400
Input
H W
c1,1 c1,2 ... c1,W
c2,1 c2,2 ... c2,W
:
cH,1 cH,2 ... cH,W
In the first line, two integ... | {"inputs": ["4 5\n0 0 1 0 0\n1 0 0 0 1\n0 0 0 1 0\n0 0 0 1 0", "4 5\n0 0 1 0 0\n1 0 1 0 1\n0 0 0 1 0\n0 0 0 1 0", "3 5\n0 0 1 0 0\n1 0 0 0 1\n0 0 0 1 0\n0 0 0 1 0", "4 5\n0 0 1 0 0\n1 0 0 0 0\n0 0 0 1 0\n0 0 0 1 0", "4 5\n0 0 1 0 0\n1 0 0 0 1\n0 0 0 1 0\n0 -1 0 1 0", "4 5\n0 0 1 0 0\n1 0 0 0 0\n0 0 0 1 -1\n0 0 0 1 0", ... | coding | 214 |
Solve the programming task below in a Python markdown code block.
Eugene has to do his homework. But today, he is feeling very lazy and wants to you do his homework. His homework has the following given maths problem.
You are given three integers: A, N, M. You write the number A appended to itself N times in a row. Let... | {"inputs": ["2\n12 2 17\n523 3 11\n\n"], "outputs": ["5\n6"]} | coding | 432 |
Solve the programming task below in a Python markdown code block.
You are given a fair coin and two integers X and N.
You repeatedly flip the coin and perform the following operation based on the result:
If it lands on heads, then X will increase by 1. However, if X = N then X will not change.
If it lands on tails, X ... | {"inputs": ["4\n1 3\n2 2\n12 12\n568 57800"], "outputs": ["0\n2\n132\n65223144\n"]} | coding | 403 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed string array words, where words[i] consists of lowercase English letters.
In one operation, select any index i such that 0 < i < words.length and words[i - 1] and words[i] are anagrams, and d... | {"functional": "def check(candidate):\n assert candidate(words = [\"abba\",\"baba\",\"bbaa\",\"cd\",\"cd\"]) == [\"abba\",\"cd\"]\n assert candidate(words = [\"a\",\"b\",\"c\",\"d\",\"e\"]) == [\"a\",\"b\",\"c\",\"d\",\"e\"]\n\n\ncheck(Solution().removeAnagrams)"} | coding | 202 |
Solve the programming task below in a Python markdown code block.
Chef and his friends are playing the game AMONG US. They all have chosen their names as numbers. There are N people in Chef’s group including him, and each swears that he is not the imposter. However, it turns out there were N+1 people in the game. Now a... | {"inputs": ["3\n4 2 5\n4 2 3 5"], "outputs": ["3"]} | coding | 224 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed array nums comprising of n non-negative integers.
In one operation, you must:
Choose an integer i such that 1 <= i < n and nums[i] > 0.
Decrease nums[i] by 1.
Increase nums[i - 1] by 1.
Ret... | {"functional": "def check(candidate):\n assert candidate(nums = [3,7,1,6]) == 5\n assert candidate(nums = [10,1]) == 10\n\n\ncheck(Solution().minimizeArrayValue)"} | coding | 131 |
Solve the programming task below in a Python markdown code block.
This kata is from check py.checkio.org
You are given an array with positive numbers and a number N. You should find the N-th power of the element in the array with the index N. If N is outside of the array, then return -1. Don't forget that the first el... | {"functional": "_inputs = [[[1, 2, 3, 4], 2], [[1, 3, 10, 100], 3], [[0, 1], 0], [[0, 1], 1], [[1, 2], 2], [[1, 2], 3], [[0], 0], [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1], 9], [[1, 1, 1, 1, 1, 1, 1, 1, 1, 100], 9], [[29, 82, 45, 10], 3], [[6, 31], 3], [[75, 68, 35, 61, 9, 36, 89, 0, 30], 10]]\n_outputs = [[9], [1000000], [1], [... | coding | 176 |
Solve the programming task below in a Python markdown code block.
Jack stays in a n-storey hostel. His dorm room is on the jth floor. Every morning, he is in so much hurry for classes that he cannot not decide whether to take Lift or Stairs to reach ground-floor. He asks you to help him choose either Stairs or Lift bas... | {"inputs": ["32\n10 5 5 U\n10 5 5 D\n10 3 3 D\n10 9 9 U\n10 10 10 U\n10 10 10 D\n100 80 20 U\n100 80 45 U\n100 80 46 U\n100 80 40 D\n100 80 0 D\n100 80 79 D\n100 100 3 U\n100 100 4 U\n100 100 5 U\n100 100 2 U\n100 100 1 D\n100 53 100 U\n100 52 100 U\n100 51 100 U\n100 54 100 U\n100 51 99 U\n100 53 99 U\n100 54 99 U\n10... | coding | 743 |
Solve the programming task below in a Python markdown code block.
Squirrel Liss is interested in sequences. She also has preferences of integers. She thinks n integers a_1, a_2, ..., a_{n} are good.
Now she is interested in good sequences. A sequence x_1, x_2, ..., x_{k} is called good if it satisfies the following th... | {"inputs": ["1\n1\n", "1\n4\n", "1\n1\n", "1\n4\n", "1\n2\n", "1\n3\n", "1\n5\n", "1\n6\n"], "outputs": ["1\n", "1\n", "1", "1", "1\n", "1\n", "1\n", "1\n"]} | coding | 414 |
Solve the programming task below in a Python markdown code block.
A trick of fate caused Hatsumi and Taku to come to know each other. To keep the encounter in memory, they decided to calculate the difference between their ages. But the difference in ages varies depending on the day it is calculated. While trying again ... | {"inputs": ["0 1 2\n2 0 0", "0 0 2\n4 0 0", "0 1 2\n1 0 0", "0 1 2\n12 0 0", "0 -1 2\n2 0 0", "7 0 1\n-1 0 0", "-9 0 3\n58 0 1", "0 1 -7\n96 0 0"], "outputs": ["2\n", "4\n", "1\n", "12\n", "3\n", "9\n", "67\n", "96\n"]} | coding | 415 |
Solve the programming task below in a Python markdown code block.
The customer telephone support center of the computer sales company called JAG is now in- credibly confused. There are too many customers who request the support, and they call the support center all the time. So, the company wants to figure out how many... | {"inputs": ["3 300\n100 46 150\n110 50 150\n001 97 261\n3 300\n100 50 150\n100 50 267\n168 50 88\n9 18\n2 1 1\n3 2 1\n3 0 2\n4 010 1\n5 100 1\n5 100 1\n10 5 3\n10 5 3\n1 7 1000\n10 18\n1 3 3\n2 3 4\n3 3 5\n3 5 6\n5 6 7\n6 7 8\n7 8 9\n8 9 10\n9 10 6\n17 11 12\n0 0", "3 300\n100 46 150\n100 50 150\n101 50 150\n3 300\n100... | coding | 767 |
Solve the programming task below in a Python markdown code block.
You have a total of 3N balls of colours Red, Blue and Green. There are exactly N balls of each colour.
These 3N balls are now distributed to 3 boxes such that each box contains exactly N balls. You are given the contents of each box.
You would like the... | {"inputs": ["2\n3\n3 0 0\n0 3 0\n0 0 3\n5\n2 1 2\n1 4 0\n2 0 3"], "outputs": ["0\n3"]} | coding | 750 |
Solve the programming task below in a Python markdown code block.
Given an integer, take the (mean) average of each pair of consecutive digits. Repeat this process until you have a single integer, then return that integer. e.g.
Note: if the average of two digits is not an integer, round the result **up** (e.g. the ave... | {"functional": "_inputs = [[246], [89], [2], [245], [345], [346], [3700]]\n_outputs = [[4], [9], [2], [4], [5], [5], [4]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n... | coding | 240 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given the root of a binary tree, return the bottom-up level order traversal of its nodes' values. (i.e., from left to right, level by level from leaf to root).
Please complete the following python code precisely:
``... | {"functional": "def check(candidate):\n assert candidate(root = tree_node([3,9,20,None,None,15,7])) == [[15,7],[9,20],[3]]\n assert candidate(root = tree_node([1])) == [[1]]\n assert candidate(root = tree_node([])) == []\n\n\ncheck(Solution().levelOrderBottom)"} | coding | 141 |
Solve the programming task below in a Python markdown code block.
In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbered from 1 from lower to upper floors. That is, the first ... | {"inputs": ["1 0\n", "2 0\n", "3 0\n", "3 0\n", "6 0\n", "9 0\n", "2 0\n", "2 0\n"], "outputs": ["1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n"]} | coding | 571 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array of points where points[i] = [xi, yi] represents a point on the X-Y plane, return the maximum number of points that lie on the same straight line.
Please complete the following python code precisely:
`... | {"functional": "def check(candidate):\n assert candidate(points = [[1,1],[2,2],[3,3]]) == 3\n assert candidate(points = [[1,1],[3,2],[5,3],[4,1],[2,3],[1,4]]) == 4\n\n\ncheck(Solution().maxPoints)"} | coding | 87 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two strings word1 and word2. You want to construct a string merge in the following way: while either word1 or word2 are non-empty, choose one of the following options:
If word1 is non-empty, append the ... | {"functional": "def check(candidate):\n assert candidate(word1 = \"cabaa\", word2 = \"bcaaa\") == \"cbcabaaaaa\"\n assert candidate(word1 = \"abcabc\", word2 = \"abdcaba\") == \"abdcabcabcaba\"\n\n\ncheck(Solution().largestMerge)"} | coding | 298 |
Solve the programming task below in a Python markdown code block.
You are given string $\boldsymbol{\mathrm{~s~}}$ and number $\boldsymbol{\mbox{k}}$.
Consider a substring $\boldsymbol{p}$ of string $\boldsymbol{\mathrm{~S~}}$. For each position of string $\boldsymbol{\mathrm{~S~}}$ mark it if there is an occurence o... | {"inputs": ["abaab\n2\n"], "outputs": ["3\n"]} | coding | 432 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given two non-negative integers low and high. Return the count of odd numbers between low and high (inclusive).
Please complete the following python code precisely:
```python
class Solution:
def countOdds(self, ... | {"functional": "def check(candidate):\n assert candidate(low = 3, high = 7) == 3\n assert candidate(low = 8, high = 10) == 1\n\n\ncheck(Solution().countOdds)"} | coding | 75 |
Solve the programming task below in a Python markdown code block.
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
There is a grid of size 10^{5} \times 10^{5}, covered completely in railway tracks. Tom is riding in a train, currently in cell (a, b), and Jerry is tied up i... | {"inputs": ["3\n1 1 2 2 2\n1 1 2 3 4\n1 1 1 0 3"], "outputs": ["YES\nNO\nYES"]} | coding | 548 |
Solve the programming task below in a Python markdown code block.
Your task in order to complete this Kata is to write a function which formats a duration, given as a number of seconds, in a human-friendly way.
The function must accept a non-negative integer. If it is zero, it just returns `"now"`. Otherwise, the dur... | {"functional": "_inputs = [[0], [1], [62], [120], [3600], [3662], [15731080], [132030240], [205851834], [253374061], [242062374], [101956166], [33243586]]\n_outputs = [['now'], ['1 second'], ['1 minute and 2 seconds'], ['2 minutes'], ['1 hour'], ['1 hour, 1 minute and 2 seconds'], ['182 days, 1 hour, 44 minutes and 40 ... | coding | 508 |
Solve the programming task below in a Python markdown code block.
Write a function that accepts two square (`NxN`) matrices (two dimensional arrays), and returns the product of the two. Only square matrices will be given.
How to multiply two square matrices:
We are given two matrices, A and B, of size 2x2 (note: tes... | {"functional": "_inputs = [[[[1, 2], [3, 2]], [[3, 2], [1, 1]]], [[[9, 7], [0, 1]], [[1, 1], [4, 12]]], [[[1, 2, 3], [3, 2, 1], [2, 1, 3]], [[4, 5, 6], [6, 5, 4], [4, 6, 5]]]]\n_outputs = [[[[5, 4], [11, 8]]], [[[37, 93], [4, 12]]], [[[28, 33, 29], [28, 31, 31], [26, 33, 31]]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5... | coding | 610 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given the strings key and message, which represent a cipher key and a secret message, respectively. The steps to decode message are as follows:
Use the first appearance of all 26 lowercase English letters in ... | {"functional": "def check(candidate):\n assert candidate(key = \"the quick brown fox jumps over the lazy dog\", message = \"vkbs bs t suepuv\") == \"this is a secret\"\n assert candidate(key = \"eljuxhpwnyrdgtqkviszcfmabo\", message = \"zwx hnfx lqantp mnoeius ycgk vcnjrdb\") == \"the five boxing wizards jump qui... | coding | 213 |
Solve the programming task below in a Python markdown code block.
It’s still hot every day, but September has already come. It’s autumn according to the calendar. Looking around, I see two red dragonflies at rest on the wall in front of me. It’s autumn indeed.
When two red dragonflies’ positional information as measur... | {"inputs": ["0 0", "50 0", "58 0", "26 0", "50 6", "84 6", "6 -1", "84 0"], "outputs": ["0\n", "50\n", "58\n", "26\n", "44\n", "78\n", "7\n", "84\n"]} | coding | 207 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given three positive integers: n, index, and maxSum. You want to construct an array nums (0-indexed) that satisfies the following conditions:
nums.length == n
nums[i] is a positive integer where 0 <= i < n.
a... | {"functional": "def check(candidate):\n assert candidate(n = 4, index = 2, maxSum = 6) == 2\n assert candidate(n = 6, index = 1, maxSum = 10) == 3\n\n\ncheck(Solution().maxValue)"} | coding | 180 |
Solve the programming task below in a Python markdown code block.
You are given a string $s$ consisting of lowercase letters of the English alphabet. You must perform the following algorithm on $s$:
Let $x$ be the length of the longest prefix of $s$ which occurs somewhere else in $s$ as a contiguous substring (the oth... | {"inputs": ["6\nabcabdc\na\nbbbbbbbbbb\ncodeforces\ncffcfccffccfcffcfccfcffccffcfccf\nzyzyzwxxyyxxyyzzyzzxxwzxwywxwzxxyzzw\n"], "outputs": ["abdc\na\nb\ndeforces\ncf\nxyzzw\n"]} | coding | 630 |
Solve the programming task below in a Python markdown code block.
Your math teacher gave you the following problem:
There are $n$ segments on the $x$-axis, $[l_1; r_1], [l_2; r_2], \ldots, [l_n; r_n]$. The segment $[l; r]$ includes the bounds, i.e. it is a set of such $x$ that $l \le x \le r$. The length of the segmen... | {"inputs": ["1\n2\n999999997 999999998\n999999999 1000000000\n", "1\n2\n999999997 999999998\n999999999 1000000000\n", "1\n2\n905303520 999999998\n999999999 1000000000\n", "1\n2\n905303520 999999998\n999999999 1000000001\n", "1\n1\n905303520 999999998\n999999999 1000000001\n", "1\n2\n71083781 1824489928\n999999999 10000... | coding | 636 |
Solve the programming task below in a Python markdown code block.
You have an initially empty cauldron, and you want to brew a potion in it. The potion consists of two ingredients: magic essence and water. The potion you want to brew should contain exactly $k\ \%$ magic essence and $(100 - k)\ \%$ water.
In one step, ... | {"inputs": ["3\n3\n100\n25\n", "3\n5\n100\n25\n", "3\n5\n100\n26\n", "3\n3\n100\n25\n", "100\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3... | coding | 453 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed integer array nums. A subarray of nums is called continuous if:
Let i, i + 1, ..., j be the indices in the subarray. Then, for each pair of indices i <= i1, i2 <= j, 0 <= |nums[i1] - nums[i2... | {"functional": "def check(candidate):\n assert candidate(nums = [5,4,2,4]) == 8\n assert candidate(nums = [1,2,3]) == 6\n\n\ncheck(Solution().continuousSubarrays)"} | coding | 147 |
Solve the programming task below in a Python markdown code block.
# Task
Imagine a standard chess board with only two white and two black knights placed in their standard starting positions: the white knights on b1 and g1; the black knights on b8 and g8.
There are two players: one plays for `white`, the other for `b... | {"functional": "_inputs = [['b1;g1;b8;g8'], ['c3;g1;b8;g8'], ['g1;g2;g3;g4'], ['f8;h1;f3;c2']]\n_outputs = [[True], [False], [True], [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(... | coding | 321 |
Solve the programming task below in a Python markdown code block.
We have the following sequence:
```python
f(0) = 0
f(1) = 1
f(2) = 1
f(3) = 2
f(4) = 4;
f(n) = f(n-1) + f(n-2) + f(n-3) + f(n-4) + f(n-5);
```
Your task is to give the number of total values for the odd terms of the sequence up to the n-th term (includ... | {"functional": "_inputs = [[0], [1], [2]]\n_outputs = [[0], [1], [1]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n r... | coding | 369 |
Solve the programming task below in a Python markdown code block.
The Chef has a huge square napkin of size 2n X 2n. He folds the napkin n-3 times. Each time he folds its bottom side over its top side, and then its right side over its left side. After each fold, the side length of the napkin is reduced by half. The Che... | {"inputs": ["3\n3\n01000010\n11000001\n00000000\n00011000\n00011000\n00010100\n00001000\n00000000\n4\n01000010\n11000001\n00000000\n00011000\n00011000\n00010100\n00001000\n00000000\n1000000000\n11111111\n11111111\n11111111\n11111111\n11111111\n11111111\n11111111\n11111111\n\n"], "outputs": ["6\n22\n1"]} | coding | 771 |
Solve the programming task below in a Python markdown code block.
Today, as a friendship gift, Bakry gave Badawy $n$ integers $a_1, a_2, \dots, a_n$ and challenged him to choose an integer $X$ such that the value $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$ is minimum possible, where $\oplus$ denotes the bitwise X... | {"inputs": ["2\n1 5\n", "2\n1 0\n", "2\n0 5\n", "2\n1 1\n", "2\n1 5\n", "3\n1 2 3\n", "3\n1 1 3\n", "3\n0 1 9\n"], "outputs": ["4\n", "1\n", "4\n", "0\n", "4", "2\n", "2\n", "8\n"]} | coding | 310 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer array nums and two integers left and right, return the number of contiguous non-empty subarrays such that the value of the maximum array element in that subarray is in the range [left, right].
The tes... | {"functional": "def check(candidate):\n assert candidate(nums = [2,1,4,3], left = 2, right = 3) == 3\n assert candidate(nums = [2,9,2,5,6], left = 2, right = 8) == 7\n\n\ncheck(Solution().numSubarrayBoundedMax)"} | coding | 122 |
Solve the programming task below in a Python markdown code block.
You are given an HTML code snippet of $N$ lines.
Your task is to detect and print all the HTML tags, attributes and attribute values.
Print the detected items in the following format:
Tag1
Tag2
-> Attribute2[0] > Attribute_value2[0]
-> Attribute2[1] >... | {"inputs": ["9\n<head>\n<title>HTML</title>\n</head>\n<object type=\"application/x-flash\" \n data=\"your-file.swf\" \n width=\"0\" height=\"0\">\n <!-- <param name=\"movie\" value=\"your-file.swf\" /> -->\n <param name=\"quality\" value=\"high\"/>\n</object>\n"], "outputs": ["head\ntitle\nobject\n-> type > applica... | coding | 522 |
Solve the programming task below in a Python markdown code block.
Vasya is reading a e-book. The file of the book consists of $n$ pages, numbered from $1$ to $n$. The screen is currently displaying the contents of page $x$, and Vasya wants to read the page $y$. There are two buttons on the book which allow Vasya to scr... | {"inputs": ["1\n11 0 0 9\n", "1\n7 0 0 22\n", "1\n11 0 11 9\n", "1\n11 0 0 18\n", "1\n11 0 0 22\n", "1\n5 0 -1 22\n", "1\n7 0 -1 22\n", "1\n11 11 11 9\n"], "outputs": ["0\n", "0\n", "2\n", "0\n", "0\n", "-1\n", "-1\n", "0\n"]} | coding | 498 |
Solve the programming task below in a Python markdown code block.
There are 2N squares arranged from left to right. You are given a string of length 2N representing the color of each of the squares.
The color of the i-th square from the left is black if the i-th character of S is `B`, and white if that character is `W... | {"inputs": ["2\nBWWB", "4\nBWWWBBWB", "4\nBWBBWBWW", "4\nBWBBWBWX", "4\nBWBBWCWW", "4\nBWABWCWW", "4\nBWABVCWW", "4\nBBAWVCWW"], "outputs": ["4", "288\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | coding | 363 |
Solve the programming task below in a Python markdown code block.
Initially, there is a magical stone of mass 2^{N} lying at the origin of the number line. For the next N seconds, the following event happens:
Let us define the *decomposition* of a magical stone as follows: If there is a magical stone of mass M > 1 ly... | {"inputs": ["3\n2 -2 2\n2 0 2\n150000 48 48\n"], "outputs": ["1 0 2 0 1\n2 0 1\n122830846\n"]} | coding | 659 |
Solve the programming task below in a Python markdown code block.
There are $N$ buckets numbered $1$ through $N$. The buckets contain balls; each ball has a color between $1$ and $K$. Let's denote the number of balls with color $j$ that are initially in bucket $i$ by $a_{i, j}$.
For each $i$ from $1$ to $N-1$ (in this ... | {"inputs": ["2 2\n0 1\n1 1"], "outputs": ["0.333333 0.666667"]} | coding | 469 |
Solve the programming task below in a Python markdown code block.
According to a recent survey, Biryani is the most ordered food. Chef wants to learn how to make world-class Biryani from a MasterChef. Chef will be required to attend the MasterChef's classes for X weeks, and the cost of classes per week is Y coins. What... | {"inputs": ["4\n1 10\n1 15\n2 10\n2 15"], "outputs": ["10\n15\n20\n30\n"]} | coding | 453 |
Solve the programming task below in a Python markdown code block.
Yup!! The problem name reflects your task; just add a set of numbers. But you may feel yourselves condescended, to write a C/C++ program just to add a set of numbers. Such a problem will simply question your erudition. So, lets add some flavor of ingenui... | {"functional": "_inputs = [[[1, 2, 3]], [[1, 2, 3, 4]], [[1, 2, 3, 4, 5]]]\n_outputs = [[9], [19], [33]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a)... | coding | 306 |
Solve the programming task below in a Python markdown code block.
any()
This expression returns True if any element of the iterable is true.
If the iterable is empty, it will return False.
Code
>>> any([1>0,1==0,1<0])
True
>>> any([1<0,2<1,3<2])
False
all()
This expression returns True if all of the elements of... | {"inputs": ["5\n12 9 61 5 14\n"], "outputs": ["True\n"]} | coding | 337 |
Solve the programming task below in a Python markdown code block.
Well, the series which Stepan watched for a very long time, ended. In total, the series had n episodes. For each of them, Stepan remembers either that he definitely has watched it, or that he definitely hasn't watched it, or he is unsure, has he watched ... | {"inputs": ["1 1\nY\n", "1 1\nN\n", "1 1\n?\n", "1 0\n?\n", "1 0\nN\n", "1 0\nY\n", "1 0\nY\n", "1 1\nY\n"], "outputs": ["NO\n", "YES\n", "YES\n", "YES\n", "NO\n", "YES\n", "YES\n", "NO\n"]} | coding | 442 |
Solve the programming task below in a Python markdown code block.
You are at the top left cell $(1, 1)$ of an $n \times m$ labyrinth. Your goal is to get to the bottom right cell $(n, m)$. You can only move right or down, one cell per step. Moving right from a cell $(x, y)$ takes you to the cell $(x, y + 1)$, while mov... | {"inputs": ["1 1\n.\n", "1 1\n.\n", "1 3\n.R.\n", "1 3\n.R.\n", "2 2\n.R\nR.\n", "2 2\n.R\nR.\n", "2 2\n.R\n.R\n", "2 2\nR.\n.R\n"], "outputs": ["1\n", "1\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | coding | 521 |
Solve the programming task below in a Python markdown code block.
Problem Statement:
You are one of the organizers of Pragyan.Having worked so hard to ensure
success of the event, you are able to spot the word "pragyan" in any text.
You are given a stream of character strings and you need to output them
till you find ... | {"inputs": ["PRAGyAN", "The\nquick\nbrown\nfox\npragyan\njumped\nover\nthe\nlazy\ndog", "The\nquick\nbrown\nfox\njumped\nover\nthe\nlazy\ndog\npragya\npragy\npra\nragyan\noragyan\npragyam\npRaGYAN\nAny\ninput\nbeyond\nthis\nshould\nnot\nbe\nprocessed", "Far\nout\nin\nthe\nuncharted\nbackwaters\nof\nthe\nunfashionable\n... | coding | 217 |
Solve the programming task below in a Python markdown code block.
You are teaching a class of $N$ students. Today, during the morning prayer, all the students are standing in a line. You are given a string $s$ with length $N$; for each valid $i$, the $i$-th character of this string is 'b' if the $i$-th student in the l... | {"inputs": ["3\ngb\nbgg\nbbgg"], "outputs": ["1\n2\n6"]} | coding | 576 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.