problem stringlengths 14 4.09k | solution stringlengths 1 802k | task_type stringclasses 3
values | problem_tokens int64 5 895 |
|---|---|---|---|
Solve the programming task below in a Python markdown code block.
For given three integers $a, b, c$, print the minimum value and the maximum value.
Constraints
* $-1,000,000,000 \leq a, b, c \leq 1,000,000,000$
Input
The input is given in the following format.
$a \; b \; c\;$
Three integers $a, b, c$ are given... | {"inputs": ["6 5 3", "6 5 1", "6 5 0", "6 8 0", "9 2 0", "2 1 0", "0 1 0", "0 7 0"], "outputs": ["3 6\n", "1 6\n", "0 6\n", "0 8\n", "0 9\n", "0 2\n", "0 1\n", "0 7\n"]} | coding | 144 |
Solve the programming task below in a Python markdown code block.
Create a function that interprets code in the esoteric language **Poohbear**
## The Language
Poohbear is a stack-based language largely inspired by Brainfuck. It has a maximum integer value of 255, and 30,000 cells. The original intention of Poohbear w... | {"functional": "_inputs = [['LQTcQAP>pQBBTAI-PA-PPL+P<BVPAL+T+P>PL+PBLPBP<DLLLT+P'], ['LLQT+P >LLLc+QIT-P AAAP P'], ['LLQT>+WN+<P>E'], ['cW>LQQT+P<pE'], ['+W>LQQT+P<-E'], ['+LTQII>+WN<P>+E'], ['+LTQIITTIWP-E'], ['LILcABNBpYDYYYYLLL+P-+W-EQNW-ELLQUTTTT+P'], ['++W-NE'], ['W>UQLIPNPPP45vSDFJLLIPNPqwVMT<E'], ['LLILQQLcYYD'... | coding | 588 |
Solve the programming task below in a Python markdown code block.
Read problems statements in mandarin chinese, russian and vietnamese as well.
Though our Head Chef retired from sport programming long back, but that did not affect his passion to contribute to the programming community. He still remains engaged by cre... | {"inputs": ["3 4\n1 2 3"], "outputs": ["5"]} | coding | 350 |
Solve the programming task below in a Python markdown code block.
# Introduction
Digital Cypher assigns to each letter of the alphabet unique number. For example:
```
a b c d e f g h i j k l m
1 2 3 4 5 6 7 8 9 10 11 12 13
n o p q r s t u v w x y z
14 15 16 17 18 19 20 21 22 23 24 ... | {"functional": "_inputs = [['scout', 1939], ['masterpiece', 1939]]\n_outputs = [[[20, 12, 18, 30, 21]], [[14, 10, 22, 29, 6, 27, 19, 18, 6, 12, 8]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isin... | coding | 752 |
Solve the programming task below in a Python markdown code block.
Each evening Roma plays online poker on his favourite website. The rules of poker on this website are a bit strange: there are always two players in a hand, there are no bets, and the winner takes 1 virtual bourle from the loser.
Last evening Roma start... | {"inputs": ["1 1\n?\n", "1 2\n?\n", "1 4\n?\n", "3 1\n??W\n", "6 1\nW??\n", "5 1\n??W\n", "6 1\nW@?\n", "6 1\n??W\n"], "outputs": ["W\n", "NO\n", "NO\n", "DDW\n", "NO\n", "NO\n", "NO\n", "NO\n"]} | coding | 472 |
Solve the programming task below in a Python markdown code block.
You are given a string $s$ of length $n$ consisting only of the characters 0 and 1.
You perform the following operation until the string becomes empty: choose some consecutive substring of equal characters, erase it from the string and glue the remainin... | {"inputs": ["3\n3 2 0\n000\n5 -2 5\n11001\n6 1 0\n100111\n", "3\n3 2 0\n000\n5 -1 5\n11001\n6 1 0\n100111\n", "3\n3 2 1\n000\n5 -2 5\n11001\n6 1 0\n110111\n", "3\n3 2 1\n010\n5 -2 4\n11000\n6 2 0\n100111\n", "3\n3 2 0\n000\n5 -2 5\n11001\n6 1 -4\n100111\n", "3\n3 2 0\n000\n5 -2 5\n11001\n6 1 -4\n110111\n", "3\n3 2 0\n0... | coding | 542 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer array nums, return the number of longest increasing subsequences.
Notice that the sequence has to be strictly increasing.
Please complete the following python code precisely:
```python
class Solutio... | {"functional": "def check(candidate):\n assert candidate(nums = [1,3,5,4,7]) == 2\n assert candidate(nums = [2,2,2,2,2]) == 5\n\n\ncheck(Solution().findNumberOfLIS)"} | coding | 76 |
Solve the programming task below in a Python markdown code block.
In this Kata, you will implement a function `count` that takes an integer and returns the number of digits in `factorial(n)`.
For example, `count(5) = 3`, because `5! = 120`, and `120` has `3` digits.
More examples in the test cases.
Brute force i... | {"functional": "_inputs = [[5], [50], [500], [5000], [50000], [500000], [5000000], [50000000]]\n_outputs = [[3], [65], [1135], [16326], [213237], [2632342], [31323382], [363233781]]\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_t... | coding | 137 |
Solve the programming task below in a Python markdown code block.
Create a function that takes 2 positive integers in form of a string as an input, and outputs the sum (also as a string):
If either input is an empty string, consider it as zero.
Also feel free to reuse/extend the following starter code:
```python
def s... | {"functional": "_inputs = [['4', '5'], ['34', '5'], ['9', ''], ['', '9']]\n_outputs = [['9'], ['39'], ['9'], ['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 ... | coding | 77 |
Solve the programming task below in a Python markdown code block.
Given is a md5 hash of a five digits long PIN. It is given as string.
Md5 is a function to hash your password:
"password123" ===> "482c811da5d5b4bc6d497ffa98491e38"
Why is this useful?
Hash functions like md5 can create a hash from string in a short tim... | {"functional": "_inputs = [['827ccb0eea8a706c4c34a16891f84e7b'], ['86aa400b65433b608a9db30070ec60cd']]\n_outputs = [['12345'], ['00078']]\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, (... | coding | 425 |
Solve the programming task below in a Python markdown code block.
Write a function that returns a sequence (index begins with 1) of all the even characters from a string. If the string is smaller than two characters or longer than 100 characters, the function should return "invalid string".
For example:
`````
"abcdef... | {"functional": "_inputs = [['a'], ['abcdefghijklm'], ['aBc_e9g*i-k$m'], [''], ['ab'], ['aiqbuwbjqwbckjdwbwkqbefhglqhfjbwqejbcadn.bcaw.jbhwefjbwqkvbweevkj.bwvwbhvjk.dsvbajdv.hwuvghwuvfhgw.vjhwncv.wecnaw.ecnvw.kejvhnw.evjkhweqv.kjhwqeev.kjbhdjk.vbaewkjva']]\n_outputs = [['invalid string'], [['b', 'd', 'f', 'h', 'j', 'l']... | coding | 123 |
Solve the programming task below in a Python markdown code block.
This is the easy version of the problem. The only difference between the two versions is that the harder version asks additionally for a minimum number of subsegments.
Tokitsukaze has a binary string $s$ of length $n$, consisting only of zeros and ones,... | {"inputs": ["5\n10\n1110011000\n8\n11001111\n2\n00\n2\n11\n6\n100110\n"], "outputs": ["3\n0\n0\n0\n3\n"]} | coding | 756 |
Solve the programming task below in a Python markdown code block.
You are given a matrix f with 4 rows and n columns. Each element of the matrix is either an asterisk (*) or a dot (.).
You may perform the following operation arbitrary number of times: choose a square submatrix of f with size k × k (where 1 ≤ k ≤ 4) an... | {"inputs": ["4\n1 1 1 1\n....\n....\n....\n....\n", "4\n1 1 1 1\n****\n****\n****\n****\n", "4\n1 1 2 1\n....\n....\n....\n....\n", "4\n1 1 0 1\n****\n****\n****\n****\n", "4\n1 1 3 1\n....\n....\n....\n....\n", "4\n0 1 1 1\n....\n....\n....\n....\n", "4\n2 1 1 1\n****\n****\n****\n****\n", "4\n1 0 0 1\n****\n****\n***... | coding | 494 |
Solve the programming task below in a Python markdown code block.
There are N cities numbered 1 through N, and M bidirectional roads numbered 1 through M. Road i connects City A_i and City B_i.
Snuke can perform the following operation zero or more times:
* Choose two distinct cities that are not directly connected b... | {"inputs": ["3 1\n1 1", "5 1\n1 1", "6 1\n1 1", "3 1\n3 2", "5 1\n3 2", "2 1\n1 2", "9 1\n1 2", "8 1\n2 4"], "outputs": ["2\n", "4\n", "5\n", "1\n", "3\n", "0\n", "7\n", "6\n"]} | coding | 249 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given the head of a non-empty linked list representing a non-negative integer without leading zeroes.
Return the head of the linked list after doubling it.
Please complete the following python code precisely... | {"functional": "def check(candidate):\n assert is_same_list(candidate(head = list_node([1,8,9])), list_node([3,7,8]))\n assert is_same_list(candidate(head = list_node([9,9,9])), list_node([1,9,9,8]))\n\n\ncheck(Solution().doubleIt)"} | coding | 122 |
Solve the programming task below in a Python markdown code block.
Chef has two non negative integers N and X. He now wants to find the number of integers K such that 0 ≤ K < N, and (N \oplus K) \And X = 0.
Note that \oplus denotes the bitwise XOR operator and \And denotes the bitwise AND operator.
Help Chef in findi... | {"inputs": ["3\n4 5\n8 4\n1 2\n"], "outputs": ["0\n4\n1\n"]} | coding | 612 |
Solve the programming task below in a Python markdown code block.
The development of algae in a pond is as follows.
Let the total weight of the algae at the beginning of the year i be x_i gram. For i≥2000, the following formula holds:
- x_{i+1} = rx_i - D
You are given r, D and x_{2000}. Calculate x_{2001}, ..., x_{20... | {"inputs": ["8 3 0", "8 0 0", "2 0 1", "1 1 1", "2 0 2", "4 0 2", "1 0 2", "2 1 0"], "outputs": ["-3\n-27\n-219\n-1755\n-14043\n-112347\n-898779\n-7190235\n-57521883\n-460175067\n", "0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n", "2\n4\n8\n16\n32\n64\n128\n256\n512\n1024\n", "0\n-1\n-2\n-3\n-4\n-5\n-6\n-7\n-8\n-9\n", "4\n8\n16\n32\n... | coding | 340 |
Solve the programming task below in a Python markdown code block.
Introduction
The GADERYPOLUKI is a simple substitution cypher used in scouting to encrypt messages. The encryption is based on short, easy to remember key. The key is written as paired letters, which are in the cipher simple replacement.
The most freq... | {"functional": "_inputs = [['Gug hgs g cgt', 'gaderypoluki'], ['Dkucr pu yhr ykbir', 'politykarenu'], ['ABCD', 'gaderypoluki'], ['Ala has a cat', 'gaderypoluki']]\n_outputs = [['Ala has a cat'], ['Dance on the table'], ['GBCE'], ['Gug hgs g cgt']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float)... | coding | 380 |
Solve the programming task below in a Python markdown code block.
Chef has closed his restaurant and decided to run a fruit stand instead. His signature dish is a fruit chaat consisting of 2 bananas and 1 apple. He currently has X bananas and Y apples. How many chaats can he make with the fruits he currently has?
---... | {"inputs": ["3\n72 50\n38 93\n51 4"], "outputs": ["36\n19\n4\n"]} | coding | 281 |
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 every tree node's tilt.
The tilt of a tree node is the absolute difference between the sum of all left subtree node values and all right subtree node values. If a nod... | {"functional": "def check(candidate):\n assert candidate(root = tree_node([1,2,3])) == 1\n assert candidate(root = tree_node([4,2,9,3,5,None,7])) == 15\n assert candidate(root = tree_node([21,7,14,1,1,2,2,3,3])) == 9\n\n\ncheck(Solution().findTilt)"} | coding | 184 |
Solve the programming task below in a Python markdown code block.
Given an array $A$ of size $N$ , count number of pairs of index $i,j$ such that $A_i$ is even, $A_j$ is odd and $i < j$
-----Input-----
- The first line of the input contains a single integer $T$ denoting the number of test cases.
- The first line of... | {"inputs": ["2\n4\n1 2 1 3\n5\n5 4 1 2 3"], "outputs": ["2\n3"]} | coding | 338 |
Solve the programming task below in a Python markdown code block.
Cooking Examinations Authority (C.E.A.) is conducting an Ordinary Cooking Level (O.C.L.) test, which tests the candidate skills on three different aspects - Appearance, Flavor and Texture. Chef is planning to appear in this coveted test.
O.C.L. is a 240... | {"inputs": ["3\n4 4 4\n5 5 5\n5 5 5\n10 8 6\n5 6 7\n5 6 7\n"], "outputs": ["300\n408\n240\n"]} | coding | 491 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two strings a and b that consist of lowercase letters. In one operation, you can change any character in a or b to any lowercase letter.
Your goal is to satisfy one of the following three conditions:
Ev... | {"functional": "def check(candidate):\n assert candidate(a = \"aba\", b = \"caa\") == 2\n assert candidate(a = \"dabadd\", b = \"cda\") == 3\n\n\ncheck(Solution().minCharacters)"} | coding | 150 |
Solve the programming task below in a Python markdown code block.
An NBA game runs 48 minutes (Four 12 minute quarters). Players do not typically play the full game, subbing in and out as necessary. Your job is to extrapolate a player's points per game if they played the full 48 minutes.
Write a function that takes tw... | {"functional": "_inputs = [[2, 5], [3, 9], [16, 27], [11, 19], [14, 33], [1, 7.5], [6, 13]]\n_outputs = [[19.2], [16.0], [28.4], [27.8], [20.4], [6.4], [22.2]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n... | coding | 235 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer array nums consisting of 2 * n integers.
You need to divide nums into n pairs such that:
Each element belongs to exactly one pair.
The elements present in a pair are equal.
Return true if nu... | {"functional": "def check(candidate):\n assert candidate(nums = [3,2,3,2,2,2]) == True\n assert candidate(nums = [1,2,3,4]) == False\n\n\ncheck(Solution().divideArray)"} | coding | 106 |
Solve the programming task below in a Python markdown code block.
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef is teaching a cooking course. There are $N$ students attending the course, numbered $1$ through $N$.
Before each lesson, Chef has to take atten... | {"inputs": ["1\n4\nhasan jaddouh\nfarhod khakimiyon\nkerim kochekov\nhasan khateeb"], "outputs": ["hasan jaddouh\nfarhod\nkerim\nhasan khateeb"]} | coding | 512 |
Solve the programming task below in a Python markdown code block.
Given a set of integers (it can contain equal elements).
You have to split it into two subsets $A$ and $B$ (both of them can contain equal elements or be empty). You have to maximize the value of $mex(A)+mex(B)$.
Here $mex$ of a set denotes the smalles... | {"inputs": ["4\n6\n0 2 1 5 0 1\n3\n0 1 2\n4\n0 2 0 1\n6\n1 2 3 4 5 6\n", "4\n6\n0 2 1 5 0 1\n3\n0 1 2\n4\n0 2 1 1\n6\n1 2 3 4 5 6\n", "4\n6\n0 2 1 5 0 1\n3\n0 1 2\n4\n0 2 1 1\n6\n1 2 0 4 5 7\n", "4\n6\n0 2 1 5 0 1\n3\n0 1 2\n4\n0 2 0 1\n6\n0 2 3 4 5 6\n", "4\n6\n0 2 1 5 0 1\n3\n0 1 2\n4\n1 2 0 1\n6\n0 2 3 5 5 8\n", "4\... | coding | 591 |
Solve the programming task below in a Python markdown code block.
«Bersoft» company is working on a new version of its most popular text editor — Bord 2010. Bord, like many other text editors, should be able to print out multipage documents. A user keys a sequence of the document page numbers that he wants to print out... | {"inputs": ["2\n", "1\n", "3\n", "5\n", "7\n", "37\n", "19\n", "30\n"], "outputs": ["2", "1", "3\n", "5\n", "7\n", "37", "19\n", "30\n"]} | coding | 455 |
Solve the programming task below in a Python markdown code block.
Hemose was shopping with his friends Samez, AhmedZ, AshrafEzz, TheSawan and O_E in Germany. As you know, Hemose and his friends are problem solvers, so they are very clever. Therefore, they will go to all discount markets in Germany.
Hemose has an array... | {"inputs": ["4\n3 3\n3 2 1\n4 3\n1 2 3 4\n5 2\n5 1 2 3 4\n5 4\n1 2 3 4 4\n"], "outputs": ["NO\nYES\nYES\nYES\n"]} | coding | 720 |
Solve the programming task below in a Python markdown code block.
Vus the Cossack has two binary strings, that is, strings that consist only of "0" and "1". We call these strings $a$ and $b$. It is known that $|b| \leq |a|$, that is, the length of $b$ is at most the length of $a$.
The Cossack considers every substring... | {"inputs": ["0\n1\n", "0\n1\n", "01100010\n00110\n", "01100010\n10110\n", "01100010\n10100\n", "01100010\n11100\n", "01100010\n11110\n", "01100010\n11111\n"], "outputs": ["0\n", "0", "3\n", "1\n", "3\n", "1\n", "3\n", "1\n"]} | coding | 592 |
Solve the programming task below in a Python markdown code block.
It is given a positive integer $n$. In $1$ move, one can select any single digit and remove it (i.e. one selects some position in the number and removes the digit located at this position). The operation cannot be performed if only one digit remains. If ... | {"inputs": ["5\n100\n71345\n3259\n50555\n2050047\n"], "outputs": ["0\n3\n1\n3\n2\n"]} | coding | 538 |
Solve the programming task below in a Python markdown code block.
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Daanish as always is busy creating and solving his favourite and interesting graph problems. Chef assigns each problem a difficulty — an integer betw... | {"inputs": ["5\n1 10 1 5 3 2 4 9 0 100\n100\n2 0 1 0 0 0 0 0 0 10\n12\n2 0 1 0 0 0 0 10 0 0\n0\n2 0 1 0 0 0 0 0 0 10\n10\n1 10 1 5 3 2 4 9 0 100\n125"], "outputs": ["8\n1\n8\n3\n2"]} | coding | 673 |
Solve the programming task below in a Python markdown code block.
White Falcon was amazed by what she can do with heavy-light decomposition on trees. As a resut, she wants to improve her expertise on heavy-light decomposition. Her teacher gave her an another assignment which requires path updates. As always, White Falc... | {"inputs": ["3 2\n0 1\n1 2\n1 0 2 1\n2 1 2\n"], "outputs": ["5\n"]} | coding | 475 |
Solve the programming task below in a Python markdown code block.
This question is similar to the $"Operation$ $on$ $a$ $Tuple"$ problem in this month's Long Challenge but with a slight variation.
Consider the following operations on a triple of integers. In one operation, you should:
- Choose a positive integer $d>0... | {"inputs": ["1\n2 2 1\n3 3 2"], "outputs": ["3"]} | coding | 379 |
Solve the programming task below in a Python markdown code block.
Two strings are said to be anagrams of each other if the letters of one string may be rearranged to make the other string. For example, the words 'elvis' and 'lives' are anagrams.
In this problem you’ll be given two strings. Your job is to find if the t... | {"inputs": ["2\nhello\nhelalo\na quick brown fox jumps over the lazy dog a quick brown fox jumps over the lazy dogaabbccddee\na", "18\nabcde\ncdeab\n121\n112\n1\nabcde\n1486\ncBaAC\na quick brown fox jumps over the lazy dog a quick brown fox jumps over the lazy dog87452117855477888\nabcdefghijklmnopqrstuvwxyzabcdefghij... | coding | 640 |
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, where candies[i] represents the flavor of the ith candy. Your mom wants you to share these candies with your little sister by giving her k consecutive candies, but you ... | {"functional": "def check(candidate):\n assert candidate(candies = [1,2,2,3,4,3], k = 3) == 3\n assert candidate(candies = [2,2,2,2,3,3], k = 2) == 2\n assert candidate(candies = [2,4,5], k = 0) == 3\n\n\ncheck(Solution().shareCandies)"} | coding | 129 |
Solve the programming task below in a Python markdown code block.
From a hidden array A of length N, Stack constructs an array B of length N such that:
For all i (1 ≤ i ≤ N), B_{i}=\max(A_{1},A_{2},\ldots,A_{i}) or B_{i}=\min(A_{1},A_{2},\ldots,A_{i}).
For the given array B of length N, Stack wants you to check whethe... | {"inputs": ["3\n1\n343\n4\n1 1 2 3\n3\n1 3 2\n", "2\n5\n1 1 1 1 1 \n5\n1 2 1 2 1\n"], "outputs": ["YES\nYES\nNO\n", "YES\nYES\n"]} | coding | 681 |
Solve the programming task below in a Python markdown code block.
Petya and Vasya decided to play a little. They found n red cubes and m blue cubes. The game goes like that: the players take turns to choose a cube of some color (red or blue) and put it in a line from left to right (overall the line will have n + m cube... | {"inputs": ["3 1\n", "2 4\n", "1 1\n", "2 1\n", "4 4\n", "1 2\n", "4 4\n", "1 2\n"], "outputs": ["2 1\n", "3 2\n", "0 1\n", "1 1\n", "3 4\n", "1 1\n", "3 4\n", "1 1\n"]} | coding | 476 |
Solve the programming task below in a Python markdown code block.
## Task
Given a positive integer, `n`, return the number of possible ways such that `k` positive integers multiply to `n`. Order matters.
**Examples**
```
n = 24
k = 2
(1, 24), (2, 12), (3, 8), (4, 6), (6, 4), (8, 3), (12, 2), (24, 1) -> 8
n = 100
k =... | {"functional": "_inputs = [[24, 2], [100, 1], [20, 3], [1, 2], [1000000, 3], [10, 2], [36, 4]]\n_outputs = [[8], [1], [18], [1], [784], [4], [100]]\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 isins... | coding | 380 |
Solve the programming task below in a Python markdown code block.
Alice guesses the strings that Bob made for her.
At first, Bob came up with the secret string $a$ consisting of lowercase English letters. The string $a$ has a length of $2$ or more characters. Then, from string $a$ he builds a new string $b$ and offers... | {"inputs": ["1\nassaad\n", "1\nassaad\n", "1\nbssaad\n", "1\ndaassb\n", "2\nabbaac\nac\n", "2\nabbaac\nac\n", "2\nabbaad\nac\n", "2\nabbaad\nca\n"], "outputs": ["asad\n", "asad\n", "bsad\n", "dasb\n", "abac\nac\n", "abac\nac\n", "abad\nac\n", "abad\nca\n"]} | coding | 558 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
For a binary tree T, we can define a flip operation as follows: choose any node, and swap the left and right child subtrees.
A binary tree X is flip equivalent to a binary tree Y if and only if we can make X equal to ... | {"functional": "def check(candidate):\n assert candidate(root1 = tree_node([1,2,3,4,5,6,None,None,None,7,8]), root2 = tree_node([1,3,2,None,6,4,5,None,None,None,None,8,7])) == True\n\n\ncheck(Solution().flipEquiv)"} | coding | 195 |
Solve the programming task below in a Python markdown code block.
You are given an integer sequence of length N, a_1,a_2,...,a_N.
For each 1≤i≤N, you have three choices: add 1 to a_i, subtract 1 from a_i or do nothing.
After these operations, you select an integer X and count the number of i such that a_i=X.
Maximiz... | {"inputs": ["1\n68972", "1\n99999", "7\n3 1 7 1 5 9 2", "7\n3 1 7 1 5 9 0", "7\n3 1 2 1 5 9 1", "7\n1 2 2 0 1 2 1", "7\n3 1 2 1 5 9 0", "7\n3 1 2 0 5 9 1"], "outputs": ["1\n", "1", "4\n", "3\n", "5\n", "7\n", "4\n", "4\n"]} | coding | 240 |
Solve the programming task below in a Python markdown code block.
Balph is learning to play a game called Buma. In this game, he is given a row of colored balls. He has to choose the color of one new ball and the place to insert it (between two balls, or to the left of all the balls, or to the right of all the balls).
... | {"inputs": ["A\n", "B\n", "C\n", "D\n", "@\n", "E\n", "F\n", "G\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | coding | 424 |
Solve the programming task below in a Python markdown code block.
The educational program (AHK Education) of the Aiz Broadcasting Association broadcasts a handicraft program for children, "Play with Tsukuro". This time I will make a box with sticks, but I would like to see if I can make a rectangular parallelepiped usi... | {"inputs": ["1 1 2 2 3 1 1 3 3 3 1 2", "1 1 3 4 8 9 7 3 3 5 5 5", "1 0 2 2 3 1 1 3 3 3 1 2", "1 1 3 7 8 9 7 3 3 5 5 5", "0 0 2 2 3 1 1 3 3 3 1 2", "1 1 2 2 5 1 2 3 3 3 1 2", "1 1 3 4 8 9 3 3 4 5 5 5", "1 1 2 2 3 1 2 3 2 3 1 2"], "outputs": ["no\n", "no\n", "no\n", "no\n", "no\n", "no\n", "no\n", "no\n"]} | coding | 283 |
Solve the programming task below in a Python markdown code block.
Read problems statements [Mandarin] , [Bengali] , [Hindi] , [Russian] and [Vietnamese] as well.
There are $N$ watchtowers built in a row. Each watchtower can only accommodate one person. Some of them are already occupied by members of the Night's Watch.... | {"inputs": ["2\n6\n010001\n11\n00101010000"], "outputs": ["1\n3"]} | coding | 467 |
Solve the programming task below in a Python markdown code block.
Chef is stuck on the minute hand of a giant clock. To escape from this clock he needs to get onto the hour hand which has an exit door.
Since the minute hand and and hour hand are not connected at any point, chef will surely need to make a jump. Since h... | {"inputs": ["3\n14:20\n02:10\n09:30"], "outputs": ["50 degree\n5 degree\n105 degree"]} | coding | 430 |
Solve the programming task below in a Python markdown code block.
Given is a positive integer N.
Find the number of pairs (A, B) of positive integers not greater than N that satisfy the following condition:
- When A and B are written in base ten without leading zeros, the last digit of A is equal to the first digit o... | {"inputs": ["0", "6", "9", "2", "3", "7", "5", "8"], "outputs": ["0\n", "6\n", "9\n", "2\n", "3\n", "7\n", "5\n", "8\n"]} | coding | 262 |
Solve the programming task below in a Python markdown code block.
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Zanka finds fun in everyday simple things. One fine day he got interested in a very trivial sequence. Given a natural number $k$, he considers the sequence $A... | {"inputs": ["1\n1"], "outputs": ["6"]} | coding | 422 |
Solve the programming task below in a Python markdown code block.
Petya has equal wooden bars of length n. He wants to make a frame for two equal doors. Each frame has two vertical (left and right) sides of length a and one top side of length b. A solid (i.e. continuous without breaks) piece of bar is needed for each s... | {"inputs": ["8\n1\n2\n", "5\n3\n4\n", "6\n4\n2\n", "1\n1\n1\n", "3\n1\n2\n", "3\n2\n1\n", "8\n3\n5\n", "5\n4\n2\n"], "outputs": ["1\n", "6\n", "4\n", "6\n", "3\n", "4\n", "3\n", "5\n"]} | coding | 351 |
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)"} | coding | 279 |
Solve the programming task below in a Python markdown code block.
Write a function that replaces 'two', 'too' and 'to' with the number '2'. Even if the sound is found mid word (like in octopus) or not in lowercase grandma still thinks that should be replaced with a 2. Bless her.
```text
'I love to text' becomes 'I lov... | {"functional": "_inputs = [['I love to text'], ['see you tomorrow'], ['look at that octopus'], ['BECAUSE I WANT TO']]\n_outputs = [['I love 2 text'], ['see you 2morrow'], ['look at that oc2pus'], ['BECAUSE I WANT 2']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n ... | coding | 151 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array of integers arr, a lucky integer is an integer that has a frequency in the array equal to its value.
Return the largest lucky integer in the array. If there is no lucky integer return -1.
Please compl... | {"functional": "def check(candidate):\n assert candidate(arr = [2,2,3,4]) == 2\n assert candidate(arr = [1,2,2,3,3,3]) == 3\n assert candidate(arr = [2,2,2,3,3]) == -1\n assert candidate(arr = [5]) == -1\n assert candidate(arr = [7,7,7,7,7,7,7]) == 7\n\n\ncheck(Solution().findLucky)"} | coding | 93 |
Solve the programming task below in a Python markdown code block.
Given a string `s` of uppercase letters, your task is to determine how many strings `t` (also uppercase) with length equal to that of `s` satisfy the followng conditions:
* `t` is lexicographical larger than `s`, and
* when you write both `s` and `t` in... | {"functional": "_inputs = [['XYZ'], ['ABC'], ['ABCD'], ['ZAZ'], ['XYZA']]\n_outputs = [[5], [16174], [402230], [25], [34480]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)... | coding | 200 |
Solve the programming task below in a Python markdown code block.
Tunnel formula
One day while exploring an abandoned mine, you found a long formula S written in the mine. If you like large numbers, you decide to take out the choke and add `(` or `)` so that the result of the formula calculation is as large as possibl... | {"inputs": ["0-(2+3-4+5)", "0-(2+3-3+5)", "2-(2+3-4+5)", "1-(3+2-4+5)", "2-(2-3+4+5)", "0-(3+4-4+5)", "3+(2-4-4+5)", "2-(2+2-4+5)"], "outputs": ["4\n", "3\n", "6\n", "5\n", "12\n", "2\n", "10\n", "7\n"]} | coding | 443 |
Solve the programming task below in a Python markdown code block.
Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible diverse words in lexicographical order.
A word is called d... | {"inputs": ["cba", "bca", "bac", "abd", "bad", "acb", "cab", "dba"], "outputs": ["cbad\n", "bcad\n", "bacd\n", "abdc\n", "badc\n", "acbd\n", "cabd\n", "dbac\n"]} | coding | 368 |
Solve the programming task below in a Python markdown code block.
You are given an integer $n$. Find a sequence of $n$ integers $a_1, a_2, \dots, a_n$ such that $1 \leq a_i \leq 10^9$ for all $i$ and $$a_1 \oplus a_2 \oplus \dots \oplus a_n = \frac{a_1 + a_2 + \dots + a_n}{n},$$ where $\oplus$ represents the bitwise XO... | {"inputs": ["3\n1\n4\n3\n"], "outputs": ["2 \n1 3 2 2 \n2 2 2 \n"]} | coding | 391 |
Solve the programming task below in a Python markdown code block.
It is nighttime and Joe the Elusive got into the country's main bank's safe. The safe has n cells positioned in a row, each of them contains some amount of diamonds. Let's make the problem more comfortable to work with and mark the cells with positive nu... | {"inputs": ["1 1 1\n0\n", "1 0 1\n0\n", "2 3 1\n2 2\n", "2 2 1\n2 2\n", "2 3 1\n2 3\n", "3 2 2\n1 1 3\n", "3 2 2\n0 1 3\n", "3 2 2\n4 1 3\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "1\n", "0\n", " 2"]} | coding | 677 |
Solve the programming task below in a Python markdown code block.
After acquiring an extraordinary amount of knowledge through programming contests, Malvika decided to harness her expertise to train the next generation of Indian programmers. So, she decided to hold a programming camp. In the camp, she held a discussion... | {"inputs": ["2\n2 1\n3 2"], "outputs": ["1\n4"]} | coding | 639 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 2D integer array orders, where each orders[i] = [pricei, amounti, orderTypei] denotes that amounti orders have been placed of type orderTypei at the price pricei. The orderTypei is:
0 if it is a batch... | {"functional": "def check(candidate):\n assert candidate(orders = [[10,5,0],[15,2,1],[25,1,1],[30,4,0]]) == 6\n assert candidate(orders = [[7,1000000000,1],[15,3,0],[5,999999995,0],[5,1,1]]) == 999999984\n\n\ncheck(Solution().getNumberOfBacklogOrders)"} | coding | 383 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given two strings low and high that represent two integers low and high where low <= high, return the number of strobogrammatic numbers in the range [low, high].
A strobogrammatic number is a number that looks the sam... | {"functional": "def check(candidate):\n assert candidate(low = \"50\", high = \"100\") == 3\n assert candidate(low = \"0\", high = \"0\") == 1\n\n\ncheck(Solution().strobogrammaticInRange)"} | coding | 116 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You have k servers numbered from 0 to k-1 that are being used to handle multiple requests simultaneously. Each server has infinite computational capacity but cannot handle more than one request at a time. The requests... | {"functional": "def check(candidate):\n assert candidate(k = 3, arrival = [1,2,3,4,5], load = [5,2,3,3,3] ) == [1] \n assert candidate(k = 3, arrival = [1,2,3,4], load = [1,2,1,2]) == [0]\n assert candidate(k = 3, arrival = [1,2,3], load = [10,12,11]) == [0,1,2]\n assert candidate(k = 3, arrival = [1,2,3,4,... | coding | 323 |
Solve the programming task below in a Python markdown code block.
There are total $N$ cars in a sequence with $ith$ car being assigned with an alphabet equivalent to the $ith$ alphabet of string $S$ . Chef has been assigned a task to calculate the total number of cars with alphabet having a unique even value in the giv... | {"inputs": ["bbccdd\n5\n1 2\n3 4\n5 6\n1 6\n2 5"], "outputs": ["1\n0\n1\n2\n2"]} | coding | 357 |
Solve the programming task below in a Python markdown code block.
Being a programmer, you like arrays a lot. For your birthday, your friends have given you an array a consisting of n distinct integers.
Unfortunately, the size of a is too small. You want a bigger array! Your friends agree to give you a bigger array, bu... | {"inputs": ["1\n1\n", "1\n1\n", "1\n2\n", "1\n3\n", "1\n5\n", "1\n0\n", "1\n10\n", "2\n1 2\n"], "outputs": ["yes\n1 1\n", "yes\n1 1\n", "yes\n1 1\n", "yes\n1 1\n", "yes\n1 1\n", "yes\n1 1\n", "yes\n1 1\n", "yes\n1 1\n"]} | coding | 480 |
Solve the programming task below in a Python markdown code block.
The Bitlandians are quite weird people. They do everything differently. They have a different alphabet so they have a different definition for a string.
A Bitlandish string is a string made only of characters "0" and "1".
BitHaval (the mayor of Bitland... | {"inputs": ["0\n1\n", "1\n1\n", "0\n0\n", "1\n0\n", "1\n1\n", "0\n0\n", "1\n0\n", "0\n1\n"], "outputs": ["NO\n", "YES\n", "YES\n", "NO\n", "YES\n", "YES\n", "NO\n", "NO\n"]} | coding | 396 |
Solve the programming task below in a Python markdown code block.
Your back at your newly acquired decrypting job for the secret organization when a new assignment comes in. Apparently the enemy has been communicating using a device they call "The Mirror".
It is a rudimentary device with encrypts the message by swi... | {"functional": "_inputs = [['Welcome home'], ['hello'], ['goodbye'], ['ngmlsoor'], ['gsrh rh z hvxivg'], ['Welcome home', 'w'], ['hello', 'abcdefgh'], ['goodbye', ''], ['CodeWars', '+-*/='], ['this is a secret', ' *']]\n_outputs = [['dvoxlnv slnv'], ['svool'], ['tllwybv'], ['mtnohlli'], ['this is a secret'], ['welcome ... | coding | 269 |
Solve the programming task below in a Python markdown code block.
A sequence of positive integers is called great for a positive integer $x$, if we can split it into pairs in such a way that in each pair the first number multiplied by $x$ is equal to the second number. More formally, a sequence $a$ of size $n$ is great... | {"inputs": ["1\n2 42951\n100000 132704\n", "1\n2 8\n600349032 507824960\n", "1\n2 50000\n90000 205032704\n", "1\n2 70000\n70000 605032704\n", "1\n2 800000\n800000 49872896\n", "1\n2 5\n705032704 1000000000\n", "1\n2 444\n902178848 98765432\n", "1\n2 500\n10000000 705032704\n"], "outputs": ["2\n", "2\n", "2\n", "2\n", "... | coding | 630 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two integer arrays nums1 and nums2 sorted in non-decreasing order and an integer k.
Define a pair (u, v) which consists of one element from the first array and one element from the second array.
Return t... | {"functional": "def check(candidate):\n assert candidate(nums1 = [1,7,11], nums2 = [2,4,6], k = 3) == [[1,2],[1,4],[1,6]]\n assert candidate(nums1 = [1,1,2], nums2 = [1,2,3], k = 2) == [[1,1],[1,1]]\n\n\ncheck(Solution().kSmallestPairs)"} | coding | 140 |
Solve the programming task below in a Python markdown code block.
Appy and Chef are participating in a contest. There are $N$ problems in this contest; each problem has a unique problem code between $1$ and $N$ inclusive. Appy and Chef decided to split the problems to solve between them ― Appy should solve the problems... | {"inputs": ["1\n6 2 3 3"], "outputs": ["Win"]} | coding | 469 |
Solve the programming task below in a Python markdown code block.
Read problem statements in [Russian], [Mandarin Chinese], [Bengali], and [Vietnamese] as well.
There are three distinct points - A, B, C in the X-Y plane. Initially, you are located at point A. You want to reach the point C satisfying the following cond... | {"inputs": ["4\n1 1\n1 3\n3 3\n0 0\n2 2\n3 4\n5 2\n3 2\n1 2\n1 1\n-1 1\n10000 10000\n"], "outputs": ["YES\nNO\nYES\nNO"]} | coding | 746 |
Solve the programming task below in a Python markdown code block.
Number of tanka
Wishing to die in the spring under the flowers
This is one of the famous tanka poems that Saigyo Hoshi wrote. Tanka is a type of waka poem that has been popular in Japan for a long time, and most of it consists of five phrases and thirt... | {"inputs": ["1\n2\n5\n390\n216\n442\n877438609014957\n0", "1\n2\n5\n390\n216\n763\n877438609014957\n0", "1\n2\n5\n390\n216\n442\n3724086920287233\n0", "1\n2\n5\n390\n216\n763\n1563679537664695\n0", "1\n3\n5\n390\n216\n763\n1563679537664695\n0", "1\n3\n6\n19\n216\n291\n34091156012094062\n0", "1\n3\n6\n19\n216\n291\n4542... | coding | 537 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a string s representing a list of words. Each letter in the word has one or more options.
If there is one option, the letter is represented as is.
If there is more than one option, then curly braces del... | {"functional": "def check(candidate):\n assert candidate(s = \"{a,b}c{d,e}f\") == [\"acdf\",\"acef\",\"bcdf\",\"bcef\"]\n assert candidate(s = \"abcd\") == [\"abcd\"]\n\n\ncheck(Solution().expand)"} | coding | 181 |
Solve the programming task below in a Python markdown code block.
Create your own mechanical dartboard that gives back your score based on the coordinates of your dart.
Task:
Use the scoring rules for a standard dartboard:
Finish method:
```python
def get_score(x,y):
```
The coordinates are `(x, y)` are always re... | {"functional": "_inputs = [[-133.69, -147.38], [4.06, 0.71], [2.38, -6.06], [-5.43, 117.95], [-73.905, -95.94], [55.53, -87.95], [-145.19, 86.53]]\n_outputs = [['X'], ['DB'], ['SB'], ['20'], ['7'], ['T2'], ['D9']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n ... | coding | 337 |
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 1\n", "1\n4 1\n", "2\n3 2\n3 2\n", "2\n3 1\n3 2\n", "2\n4 2\n4 1\n", "2\n5 2\n5 1\n", "2\n3 1\n3 2\n"], "outputs": ["1\n", "1\n", "1\n", "2\n", "2\n", "2\n", "2\n", "2\n"]} | coding | 636 |
Solve the programming task below in a Python markdown code block.
This time the Berland Team Olympiad in Informatics is held in a remote city that can only be reached by one small bus. Bus has n passenger seats, seat i can be occupied only by a participant from the city ai.
Today the bus has completed m trips, each ti... | {"inputs": ["1 3 2\n1\n", "1 7 10\n1\n", "1 10 2\n1\n", "1 9 10\n1\n", "2 4 1\n1 1\n", "1 10 10\n1\n", "2 4 1\n1 0\n", "1 18 10\n1\n"], "outputs": ["2\n", "3\n", "2\n", "1\n", "2\n", "0\n", "2\n", "10\n"]} | coding | 412 |
Solve the programming task below in a Python markdown code block.
Read problems statements [Mandarin] , [Bengali] , [Hindi] , [Russian] and [Vietnamese] as well.
Chef is participating in a pogo stick race. In this competition, there are $N$ squares (numbered $1$ through $N$) in a row. Chef must choose a starting squar... | {"inputs": ["2\n5 2\n3 6 4 7 2\n5 3\n3 -5 6 3 10"], "outputs": ["13\n10"]} | coding | 562 |
Solve the programming task below in a Python markdown code block.
Vasya plays the Geometry Horse.
The game goal is to destroy geometric figures of the game world. A certain number of points is given for destroying each figure depending on the figure type and the current factor value.
There are n types of geometric f... | {"inputs": ["1\n1 1000\n1\n2\n", "1\n1 1000\n1\n1\n", "1\n1 1100\n1\n2\n", "1\n4 10\n2\n3 6\n", "1\n9 10\n2\n3 6\n", "1\n4 10\n2\n1 6\n", "1\n9 10\n2\n2 6\n", "1\n4 10\n2\n2 6\n"], "outputs": ["1000\n", "1000\n", "1100\n", "50\n", "180\n", "70\n", "190\n", "60\n"]} | coding | 596 |
Solve the programming task below in a Python markdown code block.
C: Canisal cryptography
problem
Ebi-chan was given the string C obtained by encrypting a non-negative integer D with "canisal cipher". This cipher replaces each number in decimal notation with a fixed number (not necessarily different from the original... | {"inputs": ["2\n8", "2\n5", "2\n0", "2\n38", "2\n44", "2\n40", "2\n10", "2\n30"], "outputs": ["2", "2", "2", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n"]} | coding | 564 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Write a program to count the number of days between two dates.
The two dates are given as strings, their format is YYYY-MM-DD as shown in the examples.
Please complete the following python code precisely:
```python
... | {"functional": "def check(candidate):\n assert candidate(date1 = \"2019-06-29\", date2 = \"2019-06-30\") == 1\n assert candidate(date1 = \"2020-01-15\", date2 = \"2019-12-31\") == 15\n\n\ncheck(Solution().daysBetweenDates)"} | coding | 88 |
Solve the programming task below in a Python markdown code block.
In the previous Kata we discussed the OR case.
We will now discuss the AND case, where rather than calculating the probablility for either of two (or more) possible results, we will calculate the probability of receiving all of the viewed outcomes.
For... | {"functional": "_inputs = [[[['red', 'blue', 'yellow', 'green', 'red', 'blue', 'yellow', 'green', 'red', 'blue'], ['red', 'blue'], True]], [[['red', 'blue', 'yellow', 'green', 'red', 'blue', 'yellow', 'green', 'red', 'blue'], ['red', 'red'], True]], [[['red', 'red', 'yellow', 'green', 'red', 'red', 'yellow', 'green', '... | coding | 650 |
Solve the programming task below in a Python markdown code block.
The on-board computer on Polycarp's car measured that the car speed at the beginning of some section of the path equals v_1 meters per second, and in the end it is v_2 meters per second. We know that this section of the route took exactly t seconds to pa... | {"inputs": ["5 6\n4 2\n", "1 1\n5 1\n", "1 1\n5 2\n", "1 1\n2 1\n", "1 2\n2 1\n", "1 5\n3 2\n", "2 1\n2 2\n", "1 1\n3 5\n"], "outputs": ["26", "9", "13", "2", "3", "9", "3", "8"]} | coding | 457 |
Solve the programming task below in a Python markdown code block.
An SNS has N users - User 1, User 2, \cdots, User N.
Between these N users, there are some relationships - M friendships and K blockships.
For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i.
For each i = 1, 2,... | {"inputs": ["4 4 1\n2 1\n1 3\n3 3\n3 4\n4 1", "4 4 1\n2 0\n1 3\n3 3\n3 4\n4 1", "4 4 1\n2 1\n1 3\n3 2\n3 4\n4 1", "4 4 1\n2 1\n1 3\n3 2\n3 4\n4 1\n", "5 7 0\n1 2\n2 3\n2 4\n0 5\n0 2\n2 4\n2 0\n2 1\n1 2\n4 1", "5 10 0\n1 2\n1 3\n1 4\n1 5\n3 2\n2 4\n2 5\n4 3\n1 3\n4 5", "5 10 0\n1 2\n1 3\n2 4\n1 5\n3 2\n2 4\n2 5\n4 3\n1 ... | coding | 686 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given two integer arrays preorder and inorder where preorder is the preorder traversal of a binary tree and inorder is the inorder traversal of the same tree, construct and return the binary tree.
Please complete th... | {"functional": "def check(candidate):\n assert is_same_tree(candidate(preorder = [3,9,20,15,7], inorder = [9,3,15,20,7]), tree_node([3,9,20,None,None,15,7]))\n assert is_same_tree(candidate(preorder = [-1], inorder = [-1]), tree_node([-1]))\n\n\ncheck(Solution().buildTree)"} | coding | 141 |
Solve the programming task below in a Python markdown code block.
Write a function `take_umbrella()` that takes two arguments: a string representing the current weather and a float representing the chance of rain today.
Your function should return `True` or `False` based on the following criteria.
* You should take a... | {"functional": "_inputs = [['sunny', 0.4], ['rainy', 0.0], ['cloudy', 0.2]]\n_outputs = [[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(a, (list, tuple)):\n ... | coding | 202 |
Solve the programming task below in a Python markdown code block.
Vladimir would like to prepare a present for his wife: they have an anniversary! He decided to buy her exactly $n$ flowers.
Vladimir went to a flower shop, and he was amazed to see that there are $m$ types of flowers being sold there, and there is unlim... | {"inputs": ["1\n20 1\n1585117 913999333\n", "1\n19 1\n1585117 913999333\n", "1\n7 1\n107402237 913999333\n", "1\n7 1\n107402237 913999333\n", "1\n11 1\n107402237 913999333\n", "1\n11 1\n159441243 913999333\n", "1\n20 1\n159441243 913999333\n", "1\n20 1\n110656646 913999333\n"], "outputs": ["17367572444\n", "16453573111... | coding | 625 |
Solve the programming task below in a Python markdown code block.
Little Susie, thanks to her older brother, likes to play with cars. Today she decided to set up a tournament between them. The process of a tournament is described in the next paragraph.
There are n toy cars. Each pair collides. The result of a collisio... | {"inputs": ["1\n-1\n", "1\n-1\n", "2\n-1 0\n0 -1\n", "2\n-1 1\n2 -1\n", "2\n-1 2\n1 -1\n", "2\n-1 3\n3 -1\n", "2\n-1 1\n2 -1\n", "2\n-1 0\n0 -1\n"], "outputs": ["1\n1 ", "1\n1\n", "2\n1 2 ", "1\n2 ", "1\n1 ", "0\n", "1\n2\n", "2\n1 2\n"]} | coding | 497 |
Solve the programming task below in a Python markdown code block.
Write
```python
smaller(arr)
```
that given an array ```arr```, you have to return the amount of numbers that are smaller than ```arr[i]``` to the right.
For example:
```python
smaller([5, 4, 3, 2, 1]) == [4, 3, 2, 1, 0]
smaller([1, 2, 0]) == [1, 1, 0]
... | {"functional": "_inputs = [[[5, 4, 3, 2, 1]], [[1, 2, 3]], [[1, 2, 0]], [[1, 2, 1]], [[1, 1, -1, 0, 0]], [[5, 4, 7, 9, 2, 4, 4, 5, 6]]]\n_outputs = [[[4, 3, 2, 1, 0]], [[0, 0, 0]], [[1, 1, 0]], [[0, 1, 0]], [[3, 3, 0, 0, 0]], [[4, 1, 5, 5, 0, 0, 0, 0, 0]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(... | coding | 248 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You have n super washing machines on a line. Initially, each washing machine has some dresses or is empty.
For each move, you could choose any m (1 <= m <= n) washing machines, and pass one dress of each washing machi... | {"functional": "def check(candidate):\n assert candidate(machines = [1,0,5]) == 3\n assert candidate(machines = [0,3,0]) == 2\n assert candidate(machines = [0,2,0]) == -1\n\n\ncheck(Solution().findMinMoves)"} | coding | 164 |
Solve the programming task below in a Python markdown code block.
Petya 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.
Let next(x) be the minimum lucky n... | {"inputs": ["4 7\n", "1 9\n", "5 6\n", "1 2\n", "6 6\n", "3 4\n", "1 1\n", "4 8\n"], "outputs": ["25", "125", "14", "8", "7", "8\n", "4\n", "69\n"]} | coding | 334 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array of integers nums, half of the integers in nums are odd, and the other half are even.
Sort the array so that whenever nums[i] is odd, i is odd, and whenever nums[i] is even, i is even.
Return any answer ... | {"functional": "def check(candidate):\n assert candidate(nums = [4,2,5,7]) == [4,5,2,7]\n assert candidate(nums = [2,3]) == [2,3]\n\n\ncheck(Solution().sortArrayByParityII)"} | coding | 113 |
Solve the programming task below in a Python markdown code block.
Greatest common divisor GCD(a, b) of two positive integers a and b is equal to the biggest integer d such that both integers a and b are divisible by d. There are many efficient algorithms to find greatest common divisor GCD(a, b), for example, Euclid al... | {"inputs": ["1 2\n", "1 1\n", "2 2\n", "3 4\n", "1 1\n", "3 4\n", "2 2\n", "4 4\n"], "outputs": ["1\n", "1\n", "2\n", "1\n", "1\n", "1\n", "2\n", "4\n"]} | coding | 366 |
Solve the programming task below in a Python markdown code block.
This is the easy version of Problem F. The only difference between the easy version and the hard version is the constraints.
We will call a non-empty string balanced if it contains the same number of plus and minus signs. For example: strings "+--+" and... | {"inputs": ["5\n3\n+-+\n5\n-+---\n4\n----\n7\n--+---+\n6\n+++---\n"], "outputs": ["2\n4\n2\n7\n4\n"]} | coding | 631 |
Solve the programming task below in a Python markdown code block.
You are given an array of unique numbers. The numbers represent points. The higher the number the higher the points.
In the array [1,3,2] 3 is the highest point value so it gets 1st place. 2 is the second highest so it gets second place. 1 is the 3rd h... | {"functional": "_inputs = [[[1, 3, 2]], [[1, 2, 3, 4, 5]], [[3, 4, 1, 2, 5]], [[10, 20, 40, 50, 30]], [[1, 10]], [[22, 33, 18, 9, 110, 4, 1, 88, 6, 50]]]\n_outputs = [[[3, 1, 2]], [[5, 4, 3, 2, 1]], [[3, 2, 5, 4, 1]], [[5, 4, 2, 1, 3]], [[2, 1]], [[5, 4, 6, 7, 1, 9, 10, 2, 8, 3]]]\nimport math\ndef _deep_eq(a, b, tol=1... | coding | 339 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an m x n matrix M initialized with all 0's and an array of operations ops, where ops[i] = [ai, bi] means M[x][y] should be incremented by one for all 0 <= x < ai and 0 <= y < bi.
Count and return the num... | {"functional": "def check(candidate):\n assert candidate(m = 3, n = 3, ops = [[2,2],[3,3]]) == 4\n assert candidate(m = 3, n = 3, ops = [[2,2],[3,3],[3,3],[3,3],[2,2],[3,3],[3,3],[3,3],[2,2],[3,3],[3,3],[3,3]]) == 4\n assert candidate(m = 3, n = 3, ops = []) == 9\n\n\ncheck(Solution().maxCount)"} | coding | 133 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an array of positive integers price where price[i] denotes the price of the ith candy and a positive integer k.
The store sells baskets of k distinct candies. The tastiness of a candy basket is the small... | {"functional": "def check(candidate):\n assert candidate(price = [13,5,1,8,21,2], k = 3) == 8\n assert candidate(price = [1,3,1], k = 2) == 2\n assert candidate(price = [7,7,7,7], k = 2) == 0\n\n\ncheck(Solution().maximumTastiness)"} | coding | 122 |
Solve the programming task below in a Python markdown code block.
In your class, you have started lessons about [arithmetic progression](https://en.wikipedia.org/wiki/Arithmetic_progression). Since you are also a programmer, you have decided to write a function that will return the first `n` elements of the sequence wi... | {"functional": "_inputs = [[1, 2, 5], [1, 0, 5], [1, -3, 10], [100, -10, 10]]\n_outputs = [['1, 3, 5, 7, 9'], ['1, 1, 1, 1, 1'], ['1, -2, -5, -8, -11, -14, -17, -20, -23, -26'], ['100, 90, 80, 70, 60, 50, 40, 30, 20, 10']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):... | coding | 218 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a string title consisting of one or more words separated by a single space, where each word consists of English letters. Capitalize the string by changing the capitalization of each word such that:
If t... | {"functional": "def check(candidate):\n assert candidate(title = \"capiTalIze tHe titLe\") == \"Capitalize The Title\"\n assert candidate(title = \"First leTTeR of EACH Word\") == \"First Letter of Each Word\"\n assert candidate(title = \"i lOve leetcode\") == \"i Love Leetcode\"\n\n\ncheck(Solution().capitali... | coding | 128 |
Solve the programming task below in a Python markdown code block.
$Riggi$ is a spy of $KBI$ and he is on a secret mission, he is spying an Underworld Don $Anit$.
$Riggi$ is spying him since 5 years and he is not able to find any evidence against $Anit$.
$KBI$ told $Riggi$ they will send him a code string in a spe... | {"inputs": ["3+xy-bb3+yx-", "3+xy-bb3+xy-"], "outputs": ["Return", "Continue"]} | coding | 467 |
Solve the programming task below in a Python markdown code block.
Vasya has a beautiful garden where wonderful fruit trees grow and yield fantastic harvest every year. But lately thieves started to sneak into the garden at nights and steal the fruit too often. Vasya can’t spend the nights in the garden and guard the fr... | {"inputs": ["1 1\n1\n1 1\n", "1 1\n0\n1 1\n", "2 2\n1 1\n1 1\n1 1\n", "2 2\n1 0\n1 1\n1 1\n", "2 3\n1 0 1\n0 1 0\n3 2\n", "3 2\n1 1\n1 1\n1 0\n2 1\n", "2 3\n0 0 1\n0 1 0\n3 2\n", "2 3\n0 0 1\n1 1 0\n3 2\n"], "outputs": ["1", "0", "1\n", "0", "3", "1", "2\n", "3\n"]} | coding | 606 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an n x n matrix where each of the rows and columns is sorted in ascending order, return the kth smallest element in the matrix.
Note that it is the kth smallest element in the sorted order, not the kth distinct ... | {"functional": "def check(candidate):\n assert candidate(matrix = [[1,5,9],[10,11,13],[12,13,15]], k = 8) == 13\n assert candidate(matrix = [[-5]], k = 1) == -5\n\n\ncheck(Solution().kthSmallest)"} | coding | 120 |
Solve the programming task below in a Python markdown code block.
# Task
Given a number `n`, return a string representing it as a sum of distinct powers of three, or return `"Impossible"` if that's not possible to achieve.
# Input/Output
`[input]` integer `n`
A positive integer n.
`1 ≤ n ≤ 10^16`.
`[output]` a... | {"functional": "_inputs = [[4], [2], [28], [84], [1418194818], [87754], [531441], [8312964441463288], [5559060566575209], [243]]\n_outputs = [['3^1+3^0'], ['Impossible'], ['3^3+3^0'], ['3^4+3^1'], ['Impossible'], ['3^10+3^9+3^8+3^7+3^5+3^3+3^1+3^0'], ['3^12'], ['Impossible'], ['3^33+3^9+3^1'], ['3^5']]\nimport math\nde... | coding | 328 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.