task_type stringclasses 1
value | problem stringlengths 209 3.39k | answer stringlengths 35 6.15k | problem_tokens int64 60 774 | answer_tokens int64 12 2.04k |
|---|---|---|---|---|
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Masha has $N$ minions. Each minion has two characteristics: power $a$ and endurance $b$. Masha thinks that a non-empty set of minions $\{m_{1}, m_{2}, \dots, m_{k}\}$ with ch... | {"inputs": ["2\n3\n1 4\n3 3\n2 1\n2\n3 5\n1 4"], "outputs": ["2\n0"]} | 535 | 38 |
coding | Solve the programming task below in a Python markdown code block.
How many bees are in the beehive?
* bees can be facing UP, DOWN, LEFT, or RIGHT
* bees can share parts of other bees
Examples
Ex1
```
bee.bee
.e..e..
.b..eeb
```
*Answer: 5*
Ex2
```
bee.bee
e.e.e.e
eeb.eeb
```
*Answer: 8*
# Notes
* The ... | {"functional": "_inputs = [[None]]\n_outputs = [[0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_e... | 162 | 157 |
coding | Solve the programming task below in a Python markdown code block.
In Takahashi Kingdom, there is a east-west railroad and N cities along it, numbered 1, 2, 3, ..., N from west to east.
A company called AtCoder Express possesses M trains, and the train i runs from City L_i to City R_i (it is possible that L_i = R_i).
Ta... | {"inputs": ["2 3 1\n1 1\n1 2\n2 2\n1 2", "2 3 1\n1 1\n1 2\n2 2\n1 2\n", "10 3 2\n0 8\n2 8\n0 9\n1 2\n3 3", "10 3 2\n0 8\n2 8\n0 9\n1 2\n2 3", "10 3 2\n0 8\n2 8\n0 9\n1 2\n2 6", "10 0 2\n0 8\n2 8\n0 9\n1 2\n2 6", "10 0 2\n0 8\n2 8\n0 9\n1 2\n2 9", "10 0 2\n0 8\n0 8\n0 9\n1 2\n2 9"], "outputs": ["3", "3\n", "0\n0\n", "0\... | 437 | 264 |
coding | Solve the programming task below in a Python markdown code block.
Chef's last task in his internship requires him to construct 2 permutations, each having length N, such that the [bitwise AND] of each pair of elements at every index is the same.
Formally, if the permutations are A and B, then, the value A_{i} \& B_{i}... | {"inputs": ["3\n1\n2\n3\n"], "outputs": ["1\n1\n1 2\n2 1\n-1\n"]} | 474 | 33 |
coding | Solve the programming task below in a Python markdown code block.
Instead of writing,$a \times (b+c) = a \times b + a \times c$, Joe by mistakenly swapped the $\times$ and + signs on the left hand side. The equation became, $a+(b \times c)= a \times b + a \times c$ ?
Joe somehow knew the value of a, but forgot the val... | {"inputs": ["2"], "outputs": ["4\n"]} | 232 | 13 |
coding | Solve the programming task below in a Python markdown code block.
This is the easy version of the problem. The difference between the versions is in the constraints on the array elements. You can make hacks only if all versions of the problem are solved.
You are given an array [a_1, a_2, ..., a_n].
Your goal is to f... | {"inputs": ["1\n1\n", "7\n1 2 3 3 3 2 1\n", "7\n2 2 3 3 3 2 1\n", "7\n2 4 3 3 3 2 1\n", "7\n1 1 4 4 3 4 3\n", "7\n1 1 2 2 3 4 3\n", "7\n1 1 4 2 3 4 3\n", "7\n2 4 6 3 3 2 1\n"], "outputs": ["0\n", "3\n", "7\n", "3\n", "5\n", "7\n", "7\n", "7\n"]} | 431 | 170 |
coding | Solve the programming task below in a Python markdown code block.
For encoding an even-length binary string into a sequence of A, T, C, and G, we iterate from left to right and replace the characters as follows:
00 is replaced with A
01 is replaced with T
10 is replaced with C
11 is replaced with G
Given a binary stri... | {"inputs": ["4\n2\n00\n4\n0011\n6\n101010\n4\n1001\n"], "outputs": ["A\nAG\nCCC\nCT"]} | 445 | 47 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given the root of a binary tree, return the sum of values of its deepest leaves.
Please complete the following python code precisely:
```python
# Definition for a binary tree node.
# class TreeNode:
# def __init... | {"functional": "def check(candidate):\n assert candidate(root = tree_node([1,2,3,4,5,None,6,7,None,None,None,None,8])) == 15\n assert candidate(root = tree_node([6,7,8,2,7,1,3,9,None,1,4,None,None,None,5])) == 19\n\n\ncheck(Solution().deepestLeavesSum)"} | 120 | 95 |
coding | Solve the programming task below in a Python markdown code block.
R3D3 spent some time on an internship in MDCS. After earning enough money, he decided to go on a holiday somewhere far, far away. He enjoyed suntanning, drinking alcohol-free cocktails and going to concerts of popular local bands. While listening to "The... | {"inputs": ["4 1 2\n", "2 1 5\n", "3 1 1\n", "5 5 5\n", "4 0 0\n", "6 0 6\n", "6 6 0\n", "2 1 2\n"], "outputs": ["12\n", "6\n", "5\n", "60\n", "0\n", "30\n", "30\n", "3\n"]} | 517 | 106 |
coding | Solve the programming task below in a Python markdown code block.
In ACM-ICPC contests, there are usually three people in a team. For each person in the team, you know their scores in three skills - hard work, intelligence and persistence.
You want to check whether it is possible to order these people (assign them numb... | {"inputs": ["3\n1 2 3\n2 3 4\n2 3 5\n1 2 3\n2 3 4\n2 3 4\n5 6 5\n1 2 3\n2 3 4"], "outputs": ["yes\nno\nyes"]} | 437 | 70 |
coding | Solve the programming task below in a Python markdown code block.
In one school with Vasya there is a student Kostya. Kostya does not like physics, he likes different online games. Every day, having come home, Kostya throws his bag in the farthest corner and sits down at his beloved computer. Kostya even eats glued to ... | {"inputs": ["1 2 0 2\nb\na\n1 a\n1 b\n", "1 1 1 1\na\nb: a 1\n1 a\n", "1 1 1 1\na\nc: a 1\n1 a\n", "1 1 1 1\na\nc: a 2\n1 a\n", "10 1 1 3\na\nb: a 2\n1 a\n1 a\n1 a\n", "20 1 1 3\na\nb: a 2\n1 a\n1 a\n1 a\n", "10 1 1 3\na\nc: a 2\n1 a\n1 a\n1 a\n", "20 1 1 3\na\nc: a 2\n1 a\n1 a\n1 a\n"], "outputs": ["2\na 1\nb 1\n", "1... | 767 | 397 |
coding | Solve the programming task below in a Python markdown code block.
You have a given picture with size $w \times h$. Determine if the given picture has a single "+" shape or not. A "+" shape is described below:
A "+" shape has one center nonempty cell. There should be some (at least one) consecutive non-empty cells i... | {"inputs": ["1 1\n*\n", "1 1\n*\n", "2 2\n..\n..\n", "2 2\n..\n..\n", "3 3\n*.*\n***\n*.*\n", "3 3\n...\n...\n...\n", "3 3\n...\n..*\n.**\n", "3 3\n.*.\n***\n.*.\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "YES\n"]} | 467 | 133 |
coding | Solve the programming task below in a Python markdown code block.
In Japan, temperature is usually expressed using the Celsius (℃) scale. In America, they used the Fahrenheit (℉) scale instead. $20$ degrees Celsius is roughly equal to $68$ degrees Fahrenheit. A phrase such as "Today’s temperature is $68$ degrees" is co... | {"inputs": ["6", "82", "60", "85", "51", "96", "65", "57"], "outputs": ["-12\n", "26\n", "15\n", "27\n", "10\n", "33\n", "17\n", "13\n"]} | 285 | 78 |
coding | Solve the programming task below in a Python markdown code block.
Chef recently printed directions from his home to a hot new restaurant across the town, but forgot to print the directions to get back home. Help Chef to transform the directions to get home from the restaurant.
A set of directions consists of several in... | {"inputs": ["2\n4\nBegin on Road A\nRight on Road B\nRight on Road C\nLeft on Road D\n6\nBegin on Old Madras Road\nLeft on Domlur Flyover\nLeft on 100 Feet Road\nRight on Sarjapur Road\nRight on Hosur Road\nRight on Ganapathi Temple Road\n"], "outputs": ["Begin on Road D\nRight on Road C\nLeft on Road B\nLeft on Road A... | 503 | 146 |
coding | Solve the programming task below in a Python markdown code block.
Think of New York as a rectangular grid consisting of N vertical avenues numerated from 1 to N and M horizontal streets numerated 1 to M. C friends are staying at C hotels located at some street-avenue crossings. They are going to celebrate birthday of o... | {"inputs": ["1 1\n1\n1 1\n1\n1 1\n", "1 1\n1\n1 1\n1\n1 1\n", "1 1\n1\n1 1\n1\n2 1\n", "100 100\n1\n1 100\n1\n1 100\n", "100 100\n1\n1 100\n1\n1 100\n", "101 100\n1\n1 100\n1\n1 100\n", "111 100\n1\n1 100\n1\n1 100\n", "100 101\n1\n1 100\n1\n1 100\n"], "outputs": ["0\n1\n", "0\n1\n", "1\n1\n", "0\n1\n", "0\n1\n", "0\n1... | 354 | 238 |
coding | Solve the programming task below in a Python markdown code block.
The palindrome is a string that can be read the same way from left to right and from right to left. For example, strings "aaaaa", "1221", "bbaabb" are palindromes, however the string "chef" is not a palindrome because if we read it from right to left, we... | {"inputs": ["2\n2\n4", "2\n2\n0", "2\n4\n0", "2\n8\n0", "2\n0\n0", "2\n6\n1", "2\n0\n2", "2\n6\n2"], "outputs": ["2\n4", "2\n0\n", "4\n0\n", "8\n0\n", "0\n0\n", "6\n0\n", "0\n2\n", "6\n2\n"]} | 400 | 109 |
coding | Solve the programming task below in a Python markdown code block.
There is a house with 4 levels.
In that house there is an elevator.
You can program this elevator to go up or down,
depending on what button the user touches inside the elevator.
Valid levels must be only these numbers: `0,1,2,3`
Valid buttons must be ... | {"functional": "_inputs = [[0, '0'], [0, '1'], [0, '2'], [0, '3'], [1, '0'], [1, '1'], [1, '2'], [1, '3'], [2, '0'], [2, '1'], [2, '2'], [2, '3'], [3, '0'], [3, '1'], [3, '2'], [3, '3'], [0, '4'], [0, None], [1, '4'], [1, None], [2, '4'], [2, None], [3, '4'], [3, None], [4, '2'], [None, '2'], [[], '2'], [3, {}], ['2', ... | 400 | 432 |
coding | Solve the programming task below in a Python markdown code block.
According to the new tax scheme, a new tax called the binary string tax was introduced! JJ has a binary string S of length N. According to the tax scheme, for every occurrence of 01 in S, a tax of X rupees will be charged, while for every occurrence of 1... | {"inputs": ["2\n4 7 3\n1101\n5 3 4\n00000\n"], "outputs": ["3\n0\n"]} | 462 | 39 |
coding | Solve the programming task below in a Python markdown code block.
For a positive integer n, let us define f(n) as the number of digits in base 10.
You are given an integer S.
Count the number of the pairs of positive integers (l, r) (l \leq r) such that f(l) + f(l + 1) + ... + f(r) = S, and find the count modulo 10^9 +... | {"inputs": ["4", "3", "6", "8", "1", "2", "1\n", "2\n"], "outputs": ["9096\n", "908\n", "900993\n", "90009092\n", "9", "98", "9\n", "98\n"]} | 186 | 81 |
coding | Solve the programming task below in a Python markdown code block.
So the Chef has become health conscious and is now lifting weights at the gym. But its his first time so the trainer gives him a simple job to do.
He has been given a weight lifting rod and N heavy weights, each weighing 20, 21, .... , 2n-1. He has to ... | {"inputs": ["3\n2\n5\n18"], "outputs": ["3\n945\n221643095476699771875"]} | 276 | 45 |
coding | Solve the programming task below in a Python markdown code block.
You are given a string S of length 2N, containing N occurrences of `a` and N occurrences of `b`.
You will choose some of the characters in S. Here, for each i = 1,2,...,N, it is not allowed to choose exactly one of the following two: the i-th occurrence... | {"inputs": ["3\nbabbaa", "3\naabbba", "3\nbababa", "3\naaabbb", "3\nbbaaba", "3\naabbab", "3\nababab", "3\nabbbaa"], "outputs": ["bbaa\n", "ba\n", "bababa\n", "ab\n", "bbaaba\n", "abab\n", "ababab\n", "bbaa\n"]} | 271 | 103 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a string s consisting of lowercase English letters, return the first letter to appear twice.
Note:
A letter a appears twice before another letter b if the second occurrence of a is before the second occurrence ... | {"functional": "def check(candidate):\n assert candidate(s = \"abccbaacz\") == \"c\"\n assert candidate(s = \"abcdd\") == \"d\"\n\n\ncheck(Solution().repeatedCharacter)"} | 101 | 50 |
coding | Solve the programming task below in a Python markdown code block.
# Task
Changu and Mangu are great buddies. Once they found an infinite paper which had 1,2,3,4,5,6,7,8,......... till infinity, written on it.
Both of them did not like the sequence and started deleting some numbers in the following way.
```
First th... | {"functional": "_inputs = [[1], [5], [8], [9], [13], [15], [134], [289]]\n_outputs = [[True], [False], [False], [False], [True], [False], [False], [True]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n i... | 329 | 203 |
coding | Solve the programming task below in a Python markdown code block.
One day, Tanya was studying graph theory. She is very inquisitive, so the following problem soon came to her mind.
Find the number of undirected unweighted connected simple graphs with $N$ vertices (numbered $1$ through $N$) and $M$ edges, such that for ... | {"inputs": ["3\n4 3\n1 2 1\n4 6\n1 2 1\n3 2\n2 2"], "outputs": ["2\n0\n0"]} | 596 | 44 |
coding | Solve the programming task below in a Python markdown code block.
There is a grid, consisting of $2$ rows and $m$ columns. The rows are numbered from $1$ to $2$ from top to bottom. The columns are numbered from $1$ to $m$ from left to right.
The robot starts in a cell $(1, 1)$. In one second, it can perform either of ... | {"inputs": ["4\n3\n0 0 1\n4 3 2\n5\n0 4 8 12 16\n2 6 10 14 18\n4\n0 10 10 10\n10 10 10 10\n2\n0 0\n0 0\n"], "outputs": ["5\n19\n17\n3\n"]} | 574 | 98 |
coding | Solve the programming task below in a Python markdown code block.
Programmers working on a large project have just received a task to write exactly m lines of code. There are n programmers working on a project, the i-th of them makes exactly ai bugs in every line of code that he writes.
Let's call a sequence of non-n... | {"inputs": ["1 1 1 1\n0\n", "1 1 1 1\n2\n", "1 2 1 1\n2\n", "2 2 1 1\n2\n", "1 5 1 10\n1\n", "1 5 1 13\n1\n", "1 5 5 1000\n1\n", "1 1 0 1000\n0\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "1\n", "1\n"]} | 419 | 142 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a string s, return true if the s can be palindrome after deleting at most one character from it.
Please complete the following python code precisely:
```python
class Solution:
def validPalindrome(self, s: ... | {"functional": "def check(candidate):\n assert candidate(s = \"aba\") == True\n assert candidate(s = \"abca\") == True\n assert candidate(s = \"abc\") == False\n\n\ncheck(Solution().validPalindrome)"} | 69 | 53 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given string num representing a non-negative integer num, and an integer k, return the smallest possible integer after removing k digits from num.
Please complete the following python code precisely:
```python
class... | {"functional": "def check(candidate):\n assert candidate(num = \"1432219\", k = 3) == \"1219\"\n assert candidate(num = \"10200\", k = 1) == \"200\"\n assert candidate(num = \"10\", k = 2) == \"0\"\n\n\ncheck(Solution().removeKdigits)"} | 79 | 90 |
coding | Solve the programming task below in a Python markdown code block.
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya calls a mask of a positive... | {"inputs": ["1 4\n", "4 4\n", "7 7\n", "7 4\n", "4 7\n", "0 7\n", "1 7\n", "44 4\n"], "outputs": ["4\n", "14\n", "17\n", "14\n", "7\n", "7\n", "7\n", "45\n"]} | 289 | 91 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a string s and an integer k, return true if s is a k-palindrome.
A string is k-palindrome if it can be transformed into a palindrome by removing at most k characters from it.
Please complete the following pyth... | {"functional": "def check(candidate):\n assert candidate(s = \"abcdeca\", k = 2) == True\n assert candidate(s = \"abbababa\", k = 1) == True\n\n\ncheck(Solution().isValidPalindrome)"} | 95 | 55 |
coding | Solve the programming task below in a Python markdown code block.
A line on the plane is described by an equation Ax + By + C = 0. You are to find any point on this line, whose coordinates are integer numbers from - 5·1018 to 5·1018 inclusive, or to find out that such points do not exist.
Input
The first line contai... | {"inputs": ["0 2 3\n", "2 5 4\n", "4 5 4\n", "0 2 2\n", "0 2 4\n", "2 5 3\n", "0 -1 -2\n", "-1 1 -2\n"], "outputs": ["-1\n\n", "8 -4", "4 -4", "0 -1", "0 -2", "6 -3\n", "0 -2\n", "0 2\n"]} | 166 | 114 |
coding | Solve the programming task below in a Python markdown code block.
It is the easy version of the problem. The only difference is that in this version $k = 3$.
You are given a positive integer $n$. Find $k$ positive integers $a_1, a_2, \ldots, a_k$, such that:
$a_1 + a_2 + \ldots + a_k = n$
$LCM(a_1, a_2, \ldots, a_k)... | {"inputs": ["3\n3 3\n8 3\n14 3\n"], "outputs": ["1 1 1\n4 2 2\n2 6 6\n"]} | 306 | 43 |
coding | Solve the programming task below in a Python markdown code block.
## Task
Given a positive integer `n`, calculate the following sum:
```
n + n/2 + n/4 + n/8 + ...
```
All elements of the sum are the results of integer division.
## Example
```
25 => 25 + 12 + 6 + 3 + 1 = 47
```
Also feel free to reuse/extend th... | {"functional": "_inputs = [[25], [127], [38], [1], [320], [13], [15], [47], [101], [257]]\n_outputs = [[47], [247], [73], [1], [638], [23], [26], [89], [198], [512]]\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=... | 115 | 236 |
coding | Solve the programming task below in a Python markdown code block.
A [Mersenne prime](https://en.wikipedia.org/wiki/Mersenne_prime) is a prime number that can be represented as:
Mn = 2^(n) - 1. Therefore, every Mersenne prime is one less than a power of two.
Write a function that will return whether the given integer ... | {"functional": "_inputs = [[2], [3], [5], [7], [11], [13], [17], [19], [21], [23], [31], [49], [61], [89], [107], [127], [221], [521], [607], [1279]]\n_outputs = [[True], [True], [True], [True], [False], [True], [True], [True], [False], [False], [True], [False], [True], [True], [True], [True], [False], [True], [True], ... | 130 | 293 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an m x n picture consisting of black 'B' and white 'W' pixels and an integer target, return the number of black lonely pixels.
A black lonely pixel is a character 'B' that located at a specific position (r, c) w... | {"functional": "def check(candidate):\n assert candidate(picture = [[\"W\",\"B\",\"W\",\"B\",\"B\",\"W\"],[\"W\",\"B\",\"W\",\"B\",\"B\",\"W\"],[\"W\",\"B\",\"W\",\"B\",\"B\",\"W\"],[\"W\",\"W\",\"B\",\"W\",\"B\",\"W\"]], target = 3) == 6\n assert candidate(picture = [[\"W\",\"W\",\"B\"],[\"W\",\"W\",\"B\"],[\"W\... | 142 | 132 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an m x n binary matrix grid.
In one operation, you can choose any row or column and flip each value in that row or column (i.e., changing all 0's to 1's, and all 1's to 0's).
Return true if it is possibl... | {"functional": "def check(candidate):\n assert candidate(grid = [[0,1,0],[1,0,1],[0,1,0]]) == True\n assert candidate(grid = [[1,1,0],[0,0,0],[0,0,0]]) == False\n assert candidate(grid = [[0]]) == True\n\n\ncheck(Solution().removeOnes)"} | 128 | 85 |
coding | Solve the programming task below in a Python markdown code block.
# SpeedCode #2 - Array Madness
## Objective
Given two **integer arrays** ```a, b```, both of ```length >= 1```, create a program that returns ```true``` if the **sum of the squares** of each element in ```a``` is **strictly greater than** the **sum of ... | {"functional": "_inputs = [[[4, 5, 6], [1, 2, 3]]]\n_outputs = [[True]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n ... | 203 | 171 |
coding | Solve the programming task below in a Python markdown code block.
The legendary Farmer John is throwing a huge party, and animals from all over the world are hanging out at his house. His guests are hungry, so he instructs his cow Bessie to bring out the snacks! Moo!
There are $n$ snacks flavors, numbered with integer... | {"inputs": ["2 1\n1 2\n", "2 1\n1 2\n", "4 2\n1 2\n2 3\n", "4 2\n1 3\n2 4\n", "4 2\n1 3\n2 4\n", "4 2\n1 2\n2 3\n", "4 2\n2 3\n2 4\n", "4 2\n1 2\n2 4\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | 525 | 142 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array nums and an integer target, return the maximum number of non-empty non-overlapping subarrays such that the sum of values in each subarray is equal to target.
Please complete the following python code ... | {"functional": "def check(candidate):\n assert candidate(nums = [1,1,1,1,1], target = 2) == 2\n assert candidate(nums = [-1,3,5,1,4,2,-9], target = 6) == 2\n assert candidate(nums = [-2,6,6,3,5,4,1,2,8], target = 10) == 3\n assert candidate(nums = [0,0,0], target = 0) == 3\n\n\ncheck(Solution().maxNonOverla... | 90 | 130 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a 0-indexed integer array nums, return true if it can be made strictly increasing after removing exactly one element, or false otherwise. If the array is already strictly increasing, return true.
The array nums ... | {"functional": "def check(candidate):\n assert candidate(nums = [1,2,10,5,7]) == True\n assert candidate(nums = [2,3,1,2]) == False\n assert candidate(nums = [1,1,1]) == False\n assert candidate(nums = [1,2,3]) == True\n\n\ncheck(Solution().canBeIncreasing)"} | 117 | 87 |
coding | Solve the programming task below in a Python markdown code block.
Your task is to write an update for a lottery machine. Its current version produces a sequence of random letters and integers (passed as a string to the function). Your code must filter out all letters and return **unique** integers as a string, in their... | {"functional": "_inputs = [['wQ8Hy0y5m5oshQPeRCkG'], ['ffaQtaRFKeGIIBIcSJtg'], ['555'], ['HappyNewYear2020'], ['20191224isXmas'], ['']]\n_outputs = [['805'], ['One more run!'], ['5'], ['20'], ['20194'], ['One more run!']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\... | 168 | 239 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
An experiment is being conducted in a lab. To ensure accuracy, there are two sensors collecting data simultaneously. You are given two arrays sensor1 and sensor2, where sensor1[i] and sensor2[i] are the ith data point... | {"functional": "def check(candidate):\n assert candidate(sensor1 = [2,3,4,5], sensor2 = [2,1,3,4]) == 1\n assert candidate(sensor1 = [2,2,2,2,2], sensor2 = [2,2,2,2,5]) == -1\n assert candidate(sensor1 = [2,3,2,2,3,2], sensor2 = [2,3,2,3,2,7]) == 2\n\n\ncheck(Solution().badSensor)"} | 290 | 124 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given the root of a binary search tree (BST) and an integer val.
Find the node in the BST that the node's value equals val and return the subtree rooted with that node. If such a node does not exist, return nu... | {"functional": "def check(candidate):\n assert is_same_tree(candidate(root = tree_node([4,2,7,1,3]), val = 2), tree_node([2,1,3]))\n assert is_same_tree(candidate(root = tree_node([4,2,7,1,3]), val = 5), tree_node([]))\n\n\ncheck(Solution().searchBST)"} | 157 | 88 |
coding | Solve the programming task below in a Python markdown code block.
You are now in a bookshop with your friend Alice to buy a book, "The Winning Strategy for the Programming Koshien Contest,” just released today. As you definitely want to buy it, you are planning to borrow some money from Alice in case the amount you hav... | {"inputs": ["1 1110 3", "0 1100 3", "1 1100 2", "350 7 354", "0 1110 13", "0 1110 20", "0 1110 10", "1 1110 10"], "outputs": ["2\n", "3\n", "1\n", "4\n", "13\n", "20\n", "10\n", "9\n"]} | 330 | 126 |
coding | Solve the programming task below in a Python markdown code block.
Two coordinates (a1, a2) and (b1, b2) on a two-dimensional grid of r × c are given. The cost of moving from a cell (e, f) to one of the cells (e + 1, f), (e-1, f), (e, f + 1), (e, f-1) is 1. And. You can also move between (e, c-1) and (e, 0), and between... | {"inputs": ["4 1 0 0 1 1", "4 4 1 0 3 3", "2 3 0 0 1 1", "2 1 0 0 1 1", "4 7 0 0 1 2", "4 4 0 0 1 1", "4 4 0 0 3 3", "2 3 0 0 1 2"], "outputs": ["1\n", "6\n", "4\n", "2\n", "3\n", "2", "2", "4"]} | 335 | 139 |
coding | Solve the programming task below in a Python markdown code block.
We have N+M balls, each of which has an integer written on it.
It is known that:
- The numbers written on N of the balls are even.
- The numbers written on M of the balls are odd.
Find the number of ways to choose two of the N+M balls (disregarding ... | {"inputs": ["1 2", "4 0", "0 5", "1 3", "0 0", "2 2", "4 6", "2 3"], "outputs": ["1\n", "6\n", "10\n", "3\n", "0\n", "2\n", "21\n", "4\n"]} | 274 | 80 |
coding | Solve the programming task below in a Python markdown code block.
A permutation of size $n$ is an array of size $n$ such that each integer from $1$ to $n$ occurs exactly once in this array. An inversion in a permutation $p$ is a pair of indices $(i, j)$ such that $i > j$ and $a_i < a_j$. For example, a permutation $[4,... | {"inputs": ["1\n1\n", "1\n1\n", "1\n-1\n", "1\n-1\n", "2\n1 2\n", "2\n2 1\n", "2\n1 2\n", "2\n-1 2\n"], "outputs": ["0\n", " 0", "0\n", " 0", "0\n", "1\n", " ... | 688 | 100 |
coding | Solve the programming task below in a Python markdown code block.
We have an H \times W grid whose squares are painted black or white. The square at the i-th row from the top and the j-th column from the left is denoted as (i, j).
Snuke would like to play the following game on this grid. At the beginning of the game, t... | {"inputs": ["3 3\n..#\n..\n...", "3 3\n..#\n.#.\n...", "1 3\n..#\n#..\n...", "3 3\n..#\n#..\n...", "3 3\n..#\n#..\n...\n", "6 37\n.....................................\n...#...####...####..###...###...###..\n..#.#..#...#.##....#...#.#...#.#...#.\n..#.#..#...#.#.....#...#.#...#.#...#.\n.###.#.###.#.#...#.....#.##..#.#..... | 331 | 574 |
coding | Solve the programming task below in a Python markdown code block.
Karan's company makes software that provides different features based on the version of operating system of the user.
For finding which version is more recent, Karan uses the following method:
While this function worked for OS versions 10.6, 10.7, 10.8... | {"functional": "_inputs = [['11', '10'], ['11', '11'], ['10.4.6', '10.4'], ['10.4', '10.4.8'], ['10.4', '11'], ['10.4.9', '10.5'], ['4.3.3', '4.3.3.1'], ['10.4.9', '104.9'], ['10.15', '10.12']]\n_outputs = [[True], [True], [True], [False], [False], [False], [False], [False], [True]]\nimport math\ndef _deep_eq(a, b, tol... | 477 | 288 |
coding | Solve the programming task below in a Python markdown code block.
*This kata is based on [Project Euler Problem #349](https://projecteuler.net/problem=349). You may want to start with solving [this kata](https://www.codewars.com/kata/langtons-ant) first.*
---
[Langton's ant](https://en.wikipedia.org/wiki/Langton%27s_... | {"functional": "_inputs = [[0], [1], [2], [10], [100], [1000], [10000], [100000], [1000000], [10000000]]\n_outputs = [[0], [1], [2], [6], [20], [118], [720], [11108], [114952], [1153412]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b,... | 312 | 257 |
coding | Solve the programming task below in a Python markdown code block.
Jzzhu is the president of country A. There are n cities numbered from 1 to n in his country. City 1 is the capital of A. Also there are m roads connecting the cities. One can go from city ui to vi (and vise versa) using the i-th road, the length of this ... | {"inputs": ["2 1 1\n1 2 1\n2 1000000000\n", "2 1 1\n1 2 1\n2 1100000000\n", "2 1 1\n1 2 1\n2 1100000100\n", "3 2 2\n1 2 4\n2 3 4\n2 2\n3 6\n", "3 2 2\n1 3 4\n2 3 4\n2 2\n3 2\n", "3 2 2\n1 3 4\n2 3 4\n2 2\n3 6\n", "3 2 2\n1 2 100\n2 3 1\n2 1\n3 3\n", "2 2 3\n1 2 2\n2 1 3\n2 2\n2 2\n2 3\n"], "outputs": ["1", "1\n", "1\n"... | 456 | 262 |
coding | Solve the programming task below in a Python markdown code block.
Pasha got a very beautiful string s for his birthday, the string consists of lowercase Latin letters. The letters in the string are numbered from 1 to |s| from left to right, where |s| is the length of the given string.
Pasha didn't like his present ver... | {"inputs": ["abcdef\n1\n2\n", "abcdef\n1\n1\n", "abdcef\n1\n2\n", "abcdef\n1\n2\n", "vwxyz\n2\n2 2\n", "vwwyz\n2\n2 2\n", "vwwyz\n2\n2 1\n", "vwxyz\n2\n2 2\n"], "outputs": ["aedcbf\n", "fedcba\n", "aecdbf\n", "aedcbf\n", "vwxyz\n", "vwwyz\n", "zwwyv\n", "vwxyz\n"]} | 365 | 131 |
coding | Solve the programming task below in a Python markdown code block.
Chef has invited Alice for his birthday party. Now, Alice is thinking about what to give Chef as a present. She should obviously choose a sequence ― what could possibly be a better birthday gift than a sequence!
After some thinking, Alice chose a sequenc... | {"inputs": ["2\n2\n2 3\n4\n2 6 7 7"], "outputs": ["2\n64"]} | 472 | 31 |
coding | Solve the programming task below in a Python markdown code block.
Alice has a standard deck of 52 cards. She wants to play a card game with K-1 of her friends. This particular game requires each person to have an equal number of cards, so Alice needs to discard a certain number of cards from her deck so that she can eq... | {"inputs": ["4\n3\n50\n2\n14\n"], "outputs": ["1\n2\n0\n10\n"]} | 413 | 31 |
coding | Solve the programming task below in a Python markdown code block.
### Task:
You have to write a function `pattern` which returns the following Pattern(See Examples) upto (2n-1) rows, where n is parameter.
* Note:`Returning` the pattern is not the same as `Printing` the pattern.
#### Parameters:
pattern( ... | {"functional": "_inputs = [[3], [15], [-3], [-25], [0]]\n_outputs = [['1 1\\n 2 2 \\n 3 \\n 2 2 \\n1 1'], ['1 1\\n 2 2 \\n 3 3 \\n 4 4 \\n 5 5 \\n 6 6 \\n 7 ... | 634 | 446 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef is so good at programming that he won almost all competitions. With all the prizes, Chef bought a new house. The house looks like a grid of size N (1-indexed) which cons... | {"inputs": ["3\n1\n2\n3"], "outputs": ["2\n12\n36"]} | 472 | 24 |
coding | Solve the programming task below in a Python markdown code block.
User ainta loves to play with cards. He has a cards containing letter "o" and b cards containing letter "x". He arranges the cards in a row, and calculates the score of the deck by the formula below.
1. At first, the score is 0.
2. For each block o... | {"inputs": ["1 2\n", "1 0\n", "4 9\n", "4 7\n", "2 1\n", "4 3\n", "8 6\n", "2 2\n"], "outputs": ["-1\nxox\n", "1\no\n", "-13\nxxoxxoxxoxxox\n", "-7\nxxxoooxxoxx\n", "3\nxoo\n", "11\nxxoooox\n", "46\nxxxooooooooxxx\n", "2\nxoox\n"]} | 500 | 125 |
coding | Solve the programming task below in a Python markdown code block.
We will call a string that can be obtained by concatenating two equal strings an even string.
For example, xyzxyz and aaaaaa are even, while ababab and xyzxy are not.
You are given an even string S consisting of lowercase English letters.
Find the length... | {"inputs": ["xxxy", "xxwx", "yyxx", "xxvx", "xxyy", "yyxw", "yyyx", "yywx"], "outputs": ["2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n"]} | 270 | 72 |
coding | 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)"} | 125 | 66 |
coding | Solve the programming task below in a Python markdown code block.
Having written another programming contest, three Rabbits decided to grab some lunch. The coach gave the team exactly k time units for the lunch break.
The Rabbits have a list of n restaurants to lunch in: the i-th restaurant is characterized by two int... | {"inputs": ["1 5\n1 7\n", "1 2\n0 8\n", "1 7\n1 7\n", "1 5\n1 7\n", "1 5\n1 13\n", "1 4\n1 13\n", "1 4\n0 13\n", "1 2\n0 13\n"], "outputs": ["-1\n", "-6\n", "1\n", "-1\n", "-7\n", "-8\n", "-9\n", "-11\n"]} | 413 | 124 |
coding | Solve the programming task below in a Python markdown code block.
Anton likes to play chess, and so does his friend Danik.
Once they have played n games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie.
Now Anton wonders, who won more games, he or Danik? Help ... | {"inputs": ["1\nA\n", "1\nD\n", "1\nA\n", "1\nD\n", "2\nDA\n", "2\nDA\n", "2\nDA\n", "2\nAD\n"], "outputs": ["Anton\n", "Danik\n", "Anton\n", "Danik\n", "Friendship\n", "Friendship\n", "Friendship\n", "Friendship\n"]} | 381 | 94 |
coding | Solve the programming task below in a Python markdown code block.
For given two segments s1 and s2, print "1" if they are intersect, "0" otherwise.
s1 is formed by end points p0 and p1, and s2 is formed by end points p2 and p3.
Constraints
* 1 ≤ q ≤ 1000
* -10000 ≤ xpi, ypi ≤ 10000
* p0 ≠ p1 and p2 ≠ p3.
Input
The... | {"inputs": ["3\n0 0 3 0 1 1 2 0\n0 0 0 0 3 1 3 -1\n0 0 6 1 1 -2 5 0", "3\n0 0 3 0 1 1 2 -1\n0 0 3 0 3 1 3 -1\n0 0 6 0 3 -2 5 0", "3\n0 0 3 0 1 1 2 -1\n0 0 0 0 3 1 3 -1\n0 0 6 0 1 -2 5 0", "3\n1 0 3 0 1 1 0 -1\n0 0 3 0 3 1 3 -1\n0 0 6 0 2 -4 5 0", "3\n-1 -1 4 0 2 1 4 1\n2 1 0 0 0 0 3 0\n0 2 6 2 1 -2 5 0", "3\n0 0 3 0 1 ... | 252 | 479 |
coding | Solve the programming task below in a Python markdown code block.
Chef has N empty bottles where each bottle has a capacity of X litres.
There is a water tank in Chefland having K litres of water. Chef wants to fill the empty bottles using the water in the tank.
Assuming that Chef does not spill any water while fi... | {"inputs": ["3\n5 2 8\n10 5 4\n3 1 4"], "outputs": ["4\n0\n3"]} | 375 | 35 |
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 board where the cells are labeled from 1 to n2 in a Boustrophedon style starting from the bottom left of the board (i.e. board[n - 1][0]) and alternating direction each row.
You s... | {"functional": "def check(candidate):\n assert candidate(board = [[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,35,-1,-1,13,-1],[-1,-1,-1,-1,-1,-1],[-1,15,-1,-1,-1,-1]]) == 4\n assert candidate(board = [[-1,-1],[-1,3]]) == 1\n\n\ncheck(Solution().snakesAndLadders)"} | 406 | 127 |
coding | Solve the programming task below in a Python markdown code block.
You are given a sequence of integers $a_1, a_2, \dots, a_n$. You need to paint elements in colors, so that: If we consider any color, all elements of this color must be divisible by the minimal element of this color. The number of used colors must be ... | {"inputs": ["1\n1\n", "1\n1\n", "1\n2\n", "1\n100\n", "2\n1 1\n", "2\n1 2\n", "1\n100\n", "2\n1 1\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | 674 | 96 |
coding | Solve the programming task below in a Python markdown code block.
A Hackerrank number is a magic number that can be used to get sudo permissions on the site. We are going to generate a hackerrank number from two integers A & B. Each number has two parts to it - the left (L) & the right side (R).
For eg: for the numb... | {"inputs": ["2 4\n"], "outputs": ["14502\n"]} | 745 | 20 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a string s of lowercase English letters and an integer array shifts of the same length.
Call the shift() of a letter, the next letter in the alphabet, (wrapping around so that 'z' becomes 'a').
For exam... | {"functional": "def check(candidate):\n assert candidate(s = \"abc\", shifts = [3,5,9]) == \"rpl\"\n\n\ncheck(Solution().shiftingLetters)"} | 168 | 43 |
coding | Solve the programming task below in a Python markdown code block.
Chef loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Chef has a positive integer N. He c... | {"inputs": ["3\n4\n5\n0", "3\n0\n7\n61", "3\n0\n8\n24", "3\n0\n12\n5", "3\n3\n4\n70", "3\n32\n5\n7", "3\n1\n7\n44", "3\n1\n5\n44"], "outputs": ["0\n1\n1\n", "1\n0\n2\n", "1\n1\n1\n", "1\n2\n1\n", "1\n0\n1\n", "2\n1\n0\n", "1\n0\n0\n", "1\n1\n0\n"]} | 268 | 149 |
coding | Solve the programming task below in a Python markdown code block.
You are given a tree with N nodes and each has a value associated with it. You are given Q queries, each of which is either an update or a retrieval operation.
Initially all node values are zero.
The update query is of the format
a1 d1 a2 d2 A B
T... | {"inputs": ["7 2\n1 2\n1 3\n2 4\n2 6\n4 5\n6 7\n1 4\n1 1 1 1 4 6\n4 5\n2 7\n4 7\n5 3\n"], "outputs": ["1\n44\n45\n9\n"]} | 649 | 80 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Design an algorithm to figure out if someone has won a game of tic-tac-toe. Input is a string array of size N x N, including characters " ", "X" and "O", where " " represents a empty grid.
The rules of tic-tac-toe are... | {"functional": "def check(candidate):\n assert candidate(board = [\"O X\",\" XO\",\"X O\"]) == \"X\"\n assert candidate(board = [\"OOX\",\"XXO\",\"OXO\"]) == \"Draw\"\n assert candidate(board = [\"OOX\",\"XXO\",\"OX \"]) == \"Pending\"\n\n\ncheck(Solution().tictactoe)"} | 253 | 85 |
coding | Solve the programming task below in a Python markdown code block.
Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was n integers a_1, a_2, ..., a_{n}. These numbers mean that Greg needs to do exactly n exercises today. Besides, Greg should repeat the i-th in order exercise a_{... | {"inputs": ["1\n10\n", "1\n19\n", "1\n19\n", "1\n10\n", "1\n19\n", "1\n35\n", "1\n14\n", "1\n70\n"], "outputs": ["chest\n", "chest\n", "chest\n", "chest\n", "chest\n", "chest\n", "chest\n", "chest\n"]} | 488 | 94 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an array books where books[i] = [thicknessi, heighti] indicates the thickness and height of the ith book. You are also given an integer shelfWidth.
We want to place these books in order onto bookcase she... | {"functional": "def check(candidate):\n assert candidate(books = [[1,1],[2,3],[2,3],[1,1],[1,1],[1,1],[1,2]], shelfWidth = 4) == 6\n\n\ncheck(Solution().minHeightShelves)"} | 279 | 66 |
coding | Solve the programming task below in a Python markdown code block.
Find the 2nd largest integer in array
If the array has no 2nd largest integer then return nil.
Reject all non integers elements and then find the 2nd largest integer in array
find_2nd_largest([1,2,3]) => 2
find_2nd_largest([1,1,1,1,1]) => nil
because a... | {"functional": "_inputs = [[[1, 2, 3]], [[1, 1, 1, 1, 1, 1, 1]], [[1, 'a', '2', 3, 3, 4, 5, 'b']], [[1, 'a', '2', 3, 3, 3333333333333333333334, 544444444444444444444444444444, 'b']]]\n_outputs = [[2], [None], [4], [3333333333333333333334]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isin... | 222 | 314 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are entering a competition, and are given two positive integers initialEnergy and initialExperience denoting your initial energy and initial experience respectively.
You are also given two 0-indexed integer arrays... | {"functional": "def check(candidate):\n assert candidate(initialEnergy = 5, initialExperience = 3, energy = [1,4,3,2], experience = [2,6,3,1]) == 8\n assert candidate(initialEnergy = 2, initialExperience = 4, energy = [1], experience = [3]) == 0\n\n\ncheck(Solution().minNumberOfHours)"} | 242 | 90 |
coding | Solve the programming task below in a Python markdown code block.
Kolya got string s for his birthday, the string consists of small English letters. He immediately added k more characters to the right of the string.
Then Borya came and said that the new string contained a tandem repeat of length l as a substring. How ... | {"inputs": ["aaba\n2\n", "ayi\n10\n", "ayi\n10\n", "ayi\n11\n", "yai\n20\n", "abaa\n2\n", "yai\n11\n", "aaab\n2\n"], "outputs": ["6\n", "12\n", "12\n", "14\n", "22\n", "6\n", "14\n", "4\n"]} | 280 | 104 |
coding | Solve the programming task below in a Python markdown code block.
Luba needs your help again! Luba has n TV sets. She knows that i-th TV set will be working from moment of time li till moment ri, inclusive.
Luba wants to switch off one of TV sets in order to free the socket. Let's call some TV set redundant if after s... | {"inputs": ["1\n0 0\n", "1\n8 9\n", "1\n8 17\n", "1\n16 17\n", "2\n1 2\n1 3\n", "2\n1 3\n1 6\n", "2\n1 3\n2 4\n", "2\n2 2\n1 3\n"], "outputs": ["-1\n", "-1\n", "-1\n", "-1\n", "1\n", "1\n", "-1\n", "1\n"]} | 431 | 122 |
coding | Solve the programming task below in a Python markdown code block.
You are in charge of the cake for a child's birthday. You have decided the cake will have one candle for each year of their total age. They will only be able to blow out the tallest of the candles. Count how many candles are tallest.
Example
$candl... | {"inputs": ["4\n3 2 1 3\n"], "outputs": ["2\n"]} | 310 | 22 |
coding | Solve the programming task below in a Python markdown code block.
You are given a string S consisting of 0 and 1.
Find the maximum integer K not greater than |S| such that we can turn all the characters of S into 0 by repeating the following operation some number of times.
- Choose a contiguous segment [l,r] in S whos... | {"inputs": ["011", "111", "101", "001", "000", "110", "100", "010"], "outputs": ["2\n", "3\n", "2\n", "2\n", "3\n", "2\n", "2\n", "2"]} | 336 | 77 |
coding | Solve the programming task below in a Python markdown code block.
Have you ever tried to explain to the coordinator, why it is eight hours to the contest and not a single problem has been prepared yet? Misha had. And this time he has a really strong excuse: he faced a space-time paradox! Space and time replaced each ot... | {"inputs": ["1 5 4 3 2\n", "6 0 0 2 8\n", "5 8 2 1 3\n", "2 0 0 1 3\n", "1 5 6 2 1\n", "5 0 0 6 7\n", "6 0 1 6 7\n", "3 5 1 1 2\n"], "outputs": ["YES\n", "NO\n", "NO\n", "NO\n", "YES\n", "YES\n", "NO\n", "NO\n"]} | 591 | 134 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Solve a given equation and return the value of 'x' in the form of a string "x=#value". The equation contains only '+', '-' operation, the variable 'x' and its coefficient. You should return "No solution" if there is n... | {"functional": "def check(candidate):\n assert candidate(equation = \"x+5-3+x=6+x-2\") == \"x=2\"\n assert candidate(equation = \"x=x\") == \"Infinite solutions\"\n assert candidate(equation = \"2x=x\") == \"x=0\"\n\n\ncheck(Solution().solveEquation)"} | 144 | 84 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a 0-indexed string word and a character ch, reverse the segment of word that starts at index 0 and ends at the index of the first occurrence of ch (inclusive). If the character ch does not exist in word, do noth... | {"functional": "def check(candidate):\n assert candidate(word = \"abcdefd\", ch = \"d\") == \"dcbaefd\"\n assert candidate(word = \"xyxzxe\", ch = \"z\") == \"zxyxxe\"\n assert candidate(word = \"abcd\", ch = \"z\") == \"abcd\"\n\n\ncheck(Solution().reversePrefix)"} | 152 | 81 |
coding | Solve the programming task below in a Python markdown code block.
Xenia the programmer has a tree consisting of n nodes. We will consider the tree nodes indexed from 1 to n. We will also consider the first node to be initially painted red, and the other nodes — to be painted blue.
The distance between two tree nodes v... | {"inputs": ["5 4\n1 2\n2 3\n2 4\n4 5\n2 1\n2 5\n1 2\n2 1\n", "5 4\n1 2\n2 3\n2 4\n4 5\n2 1\n2 1\n1 2\n2 1\n", "5 4\n1 2\n2 3\n2 4\n1 5\n2 1\n2 5\n1 2\n2 5\n", "5 4\n1 2\n2 3\n2 4\n4 5\n2 1\n1 5\n1 2\n2 1\n", "5 4\n1 2\n2 3\n2 4\n1 5\n2 2\n2 5\n1 2\n2 5\n", "5 4\n1 2\n2 3\n1 4\n4 5\n2 1\n2 5\n1 2\n2 1\n", "5 4\n1 2\n2 3... | 402 | 370 |
coding | Solve the programming task below in a Python markdown code block.
Vasya claims that he had a paper square. He cut it into two rectangular parts using one vertical or horizontal cut. Then Vasya informed you the dimensions of these two rectangular parts. You need to check whether Vasya originally had a square. In other w... | {"inputs": ["1\n5 2\n3 14\n", "1\n5 1\n3 14\n", "1\n5 12\n5 0\n", "1\n5 1\n5 14\n", "1\n5 12\n5 1\n", "1\n5 9\n41 14\n", "1\n8 9\n41 14\n", "1\n5 3\n41 14\n"], "outputs": ["No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n"]} | 388 | 145 |
coding | Solve the programming task below in a Python markdown code block.
You are given a positive integer $n$. You have to find $4$ positive integers $a, b, c, d$ such that
$a + b + c + d = n$, and
$\gcd(a, b) = \operatorname{lcm}(c, d)$.
If there are several possible answers you can output any of them. It is possible to s... | {"inputs": ["5\n4\n7\n8\n9\n10\n"], "outputs": ["1 1 1 1\n4 1 1 1\n5 1 1 1\n6 1 1 1\n7 1 1 1\n"]} | 582 | 63 |
coding | Solve the programming task below in a Python markdown code block.
You are given a permutation $p_1, p_2, \dots, p_n$. Recall that sequence of $n$ integers is called a permutation if it contains all integers from $1$ to $n$ exactly once.
Find three indices $i$, $j$ and $k$ such that: $1 \le i < j < k \le n$; $p_i < ... | {"inputs": ["3\n4\n2 1 4 3\n6\n4 6 1 2 5 3\n5\n5 3 1 2 4\n", "3\n4\n2 1 4 3\n6\n4 6 1 2 5 3\n5\n5 3 1 2 4\n", "3\n4\n2 1 4 3\n6\n4 6 1 2 5 3\n5\n5 2 1 2 4\n", "3\n4\n2 1 4 3\n6\n4 6 1 2 5 3\n5\n8 3 1 2 4\n", "3\n4\n2 1 4 3\n6\n4 6 1 2 5 3\n5\n6 3 1 2 4\n", "3\n4\n2 1 4 3\n6\n4 6 1 2 5 3\n5\n5 3 1 2 5\n", "3\n4\n2 1 4 3... | 394 | 486 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.
An input string is valid if:
Open brackets must be closed by the same type of brackets.
Open br... | {"functional": "def check(candidate):\n assert candidate(s = \"()\") == True\n assert candidate(s = \"()[]{}\") == True\n assert candidate(s = \"(]\") == False\n\n\ncheck(Solution().isValid)"} | 116 | 54 |
coding | Solve the programming task below in a Python markdown code block.
Consider an array A consisting of N positive elements. The *frequency array* of A is the array B of size N such that B_{i} = *frequency* of element A_{i} in A.
For example, if A = [4, 7, 4, 11, 2, 7, 7], the *frequency array* B = [2, 3, 2, 1, 1, 3, 3].
... | {"inputs": ["5\n5\n2 3 3 3 2\n5\n1 1 1 1 1\n5\n5 5 5 5 5\n3\n1 2 4\n8\n1 3 2 3 2 2 2 3"], "outputs": ["1 2 2 2 1\n1 2 3 4 5\n1 1 1 1 1\n-1\n1 2 3 2 3 4 4 2\n"]} | 761 | 122 |
coding | Solve the programming task below in a Python markdown code block.
DZY loves chessboard, and he enjoys playing with it.
He has a chessboard of n rows and m columns. Some cells of the chessboard are bad, others are good. For every good cell, DZY wants to put a chessman on it. Each chessman is either white or black. Afte... | {"inputs": ["1 1\n.\n", "1 1\n-\n", "1 1\n-\n", "1 1\n.\n", "2 2\n..\n..\n", "3 1\n-\n.\n.\n", "3 1\n-\n.\n.\n", "2 2\n..\n-.\n"], "outputs": ["B\n", "-\n", "-\n", "B\n", "BW\nWB\n", "-\nW\nB\n", "-\nW\nB\n", "BW\n-B\n"]} | 434 | 127 |
coding | Solve the programming task below in a Python markdown code block.
A Sumo wrestling championship is scheduled to be held this winter in the HackerCity where N wrestlers from different parts of the world are going to participate. The rules state that two wrestlers can fight against each other if and only if the differenc... | {"inputs": ["5 2\n1 3 4 3 0\n3\n0 1\n1 3\n0 4\n"], "outputs": ["1\n3\n6\n"]} | 539 | 44 |
coding | Solve the programming task below in a Python markdown code block.
The goal of this Kata is to reduce the passed integer to a single digit (if not already) by converting the number to binary, taking the sum of the binary digits, and if that sum is not a single digit then repeat the process.
- n will be an integer such ... | {"functional": "_inputs = [[5], [999], [1234444123], [443566], [565656565], [9889345778311094737448], [4868872], [234234235], [567448], [10000000000]]\n_outputs = [[5], [8], [1], [2], [3], [2], [8], [2], [7], [3]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n ... | 315 | 282 |
coding | Solve the programming task below in a Python markdown code block.
One of the games that uses the Hyakunin Isshu tag is "Buddhist turning". It is a simple game that uses only picture cards, so it is widely enjoyed. There are various derivative types of rules, but the shaved turn considered here is performed by N partici... | {"inputs": ["2\nSSSSSSSSSSSSSSSLLLLLLLLLLLLLLLLLLLLLMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM\n2\nSSSSSSSSSSSSSSLLLLLLLLLLLLLLLLLLLLMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMSL\n5\nMMMMMMSLSLLMMMSMMSLMMMLMMMMLSLLLLMLSMMLMMLLMSSSLMMMMLMLSSLMSMMMMMMMMMMMMMMLMMMMMSMMMLMMLMMMMMM... | 682 | 1,171 |
coding | Solve the programming task below in a Python markdown code block.
Write a simple parser that will parse and run Deadfish.
Deadfish has 4 commands, each 1 character long:
* `i` increments the value (initially `0`)
* `d` decrements the value
* `s` squares the value
* `o` outputs the value into the return array
Invali... | {"functional": "_inputs = [['ooo'], ['ioioio'], ['idoiido'], ['isoisoiso'], ['codewars']]\n_outputs = [[[0, 0, 0]], [[1, 2, 3]], [[0, 1]], [[1, 4, 25]], [[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... | 128 | 207 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
The Game of Master Mind is played as follows:
The computer has four slots, and each slot will contain a ball that is red (R). yellow (Y). green (G) or blue (B). For example, the computer might have RGGB (Slot #1 is re... | {"functional": "def check(candidate):\n assert candidate(solution=\"RGBY\",guess=\"GGRR\") == [1,1]\n\n\ncheck(Solution().masterMind)"} | 294 | 39 |
coding | Solve the programming task below in a Python markdown code block.
Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them.
Beroffice works only with small English letters (i.e. with 26 letters from a to z). ... | {"inputs": ["a\n", "b\n", "x\n", "b\n", "x\n", "a\n", "c\n", "y\n"], "outputs": ["a \n", "b \n", "x \n", "b\n", "x\n", "a\n", "c\n", "y\n"]} | 453 | 73 |
coding | Solve the programming task below in a Python markdown code block.
You are given a sequence $s$ consisting of $n$ digits from $1$ to $9$.
You have to divide it into at least two segments (segment — is a consecutive sequence of elements) (in other words, you have to place separators between some digits of the sequence) ... | {"inputs": ["1\n3\n333\n", "1\n3\n333\n", "1\n3\n343\n", "1\n3\n218\n", "1\n3\n242\n", "1\n4\n3333\n", "1\n4\n5234\n", "1\n4\n9999\n"], "outputs": ["YES\n2\n3 33\n", "YES\n2\n3 33\n", "YES\n2\n3 43\n", "YES\n2\n2 18\n", "YES\n2\n2 42\n", "YES\n2\n3 333\n", "YES\n2\n5 234\n", "YES\n2\n9 999\n"]} | 691 | 180 |
coding | Solve the programming task below in a Python markdown code block.
People in Chefland have three different eye colors, namely brown, blue, and green. green is the rarest of the eye colors whereas brown is most common.
The eye color of the child of two people is most likely to be the most common eye color between them. ... | {"inputs": ["R B\n", "B B\n", "G B\n"], "outputs": ["R", "B", "B"]} | 393 | 30 |
coding | Solve the programming task below in a Python markdown code block.
Debug the functions
Should be easy, begin by looking at the code. Debug the code and the functions should work.
There are three functions: ```Multiplication (x)``` ```Addition (+)``` and ```Reverse (!esreveR)```
i {
font-size:16px;
}
#heading {
pad... | {"functional": "_inputs = [[[8, 2, 5]]]\n_outputs = [[80]]\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(_... | 140 | 161 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
A parentheses string is a non-empty string consisting only of '(' and ')'. It is valid if any of the following conditions is true:
It is ().
It can be written as AB (A concatenated with B), where A and B are valid pa... | {"functional": "def check(candidate):\n assert candidate(s = \"))()))\", locked = \"010100\") == True\n assert candidate(s = \"()()\", locked = \"0000\") == True\n assert candidate(s = \")\", locked = \"0\") == False\n\n\ncheck(Solution().canBeValid)"} | 212 | 78 |
coding | Solve the programming task below in a Python markdown code block.
Last summer, Feluda gifted Lalmohan-Babu a balanced bracket sequence $s$ of length $2 n$.
Topshe was bored during his summer vacations, and hence he decided to draw an undirected graph of $2 n$ vertices using the balanced bracket sequence $s$. For any t... | {"inputs": ["4\n1\n()\n3\n()(())\n3\n((()))\n4\n(())(())\n"], "outputs": ["1\n2\n3\n3\n"]} | 576 | 44 |
coding | Solve the programming task below in a Python markdown code block.
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
You are given a binary string $S$. Chef defines $\mathrm{MEX}(S)$ as the smallest non-negative integer such that its binary representation (without leading '0... | {"inputs": ["2\n1001011\n1111"], "outputs": ["1100\n0"]} | 525 | 30 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.