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.
# Definition (Primorial Of a Number)
*Is similar to factorial of a number*, **_In primorial_**, not all the natural numbers get multiplied, **_only prime numbers are multiplied to calculate the primorial of a number_**. It's denoted with **_P_****_#_** ... | {"functional": "_inputs = [[3], [4], [5], [8], [9]]\n_outputs = [[30], [210], [2310], [9699690], [223092870]]\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 l... | coding | 585 |
Solve the programming task below in a Python markdown code block.
You are given a string $t$ and a set $S$ of $N$ different strings. You need to separate $t$ such that each part is included in $S$.
For example, the following 4 separation methods satisfy the condition when $t = abab$ and $S = \\{a, ab, b\\}$.
* $a,b,a... | {"inputs": ["3\na\nb\nc\nxy{", "3\nb\nb\nc\nxy{", "3\nb\nb\nc\nyx{", "3\nb\nb\nc\nxx{", "3\nb\nb\nd\nxx{", "3\nb\nb\nd\nx{x", "3\nb\na\nd\nx{x", "3\na\nb\nc\nzyx"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | coding | 517 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
The product sum of two equal-length arrays a and b is equal to the sum of a[i] * b[i] for all 0 <= i < a.length (0-indexed).
For example, if a = [1,2,3,4] and b = [5,2,3,1], the product sum would be 1*5 + 2*2 + 3*3 +... | {"functional": "def check(candidate):\n assert candidate(nums1 = [5,3,4,2], nums2 = [4,2,2,5]) == 40\n assert candidate(nums1 = [2,1,4,5,7], nums2 = [3,2,4,8,6]) == 65\n\n\ncheck(Solution().minProductSum)"} | coding | 184 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer n, return the number of structurally unique BST's (binary search trees) which has exactly n nodes of unique values from 1 to n.
Please complete the following python code precisely:
```python
class S... | {"functional": "def check(candidate):\n assert candidate(n = 3) == 5\n assert candidate(n = 1) == 1\n\n\ncheck(Solution().numTrees)"} | coding | 80 |
Solve the programming task below in a Python markdown code block.
Polycarp has n dice d_1, d_2, ..., d_{n}. The i-th dice shows numbers from 1 to d_{i}. Polycarp rolled all the dice and the sum of numbers they showed is A. Agrippina didn't see which dice showed what number, she knows only the sum A and the values d_1, ... | {"inputs": ["1 3\n5\n", "1 1\n3\n", "1 2\n3\n", "1 5\n5\n", "1 1\n3\n", "1 2\n3\n", "1 5\n5\n", "1 1\n1\n"], "outputs": ["4 ", "2 ", "2 ", "4 ", "2\n", "2\n", "4\n", "0"]} | coding | 565 |
Solve the programming task below in a Python markdown code block.
Recently Irina arrived to one of the most famous cities of Berland — the Berlatov city. There are n showplaces in the city, numbered from 1 to n, and some of them are connected by one-directional roads. The roads in Berlatov are designed in a way such th... | {"inputs": ["2 1 1\n1 2 1\n", "2 1 1\n1 2 1\n", "2 1 2\n1 2 1\n", "4 3 13\n1 2 5\n2 3 7\n2 4 8\n", "4 3 13\n1 2 5\n2 3 7\n2 4 8\n", "4 4 3\n1 2 1\n2 3 1\n3 4 1\n1 3 1\n", "4 4 2\n1 2 1\n2 3 1\n3 4 1\n1 3 1\n", "4 4 2\n1 2 1\n2 3 1\n3 4 1\n1 3 1\n"], "outputs": ["2\n1 2 \n", "2\n1 2 ", "2\n1 2\n", "3\n1 2 4 \n", "3\n1 2... | coding | 665 |
Solve the programming task below in a Python markdown code block.
Iahub recently has learned Bubble Sort, an algorithm that is used to sort a permutation with n elements a_1, a_2, ..., a_{n} in ascending order. He is bored of this so simple algorithm, so he invents his own graph. The graph (let's call it G) initially h... | {"inputs": ["3\n3 1 2\n", "3\n3 1 3\n", "3\n2 1 3\n", "3\n3 1 2\n", "5\n4 2 1 3 5\n", "5\n4 2 1 3 5\n", "5\n4 2 1 2 5\n", "10\n1 9 8 10 2 3 4 6 5 7\n"], "outputs": ["2\n", "2\n", "2\n", "2\n", "3\n", "3\n", "3\n", "6\n"]} | coding | 496 |
Solve the programming task below in a Python markdown code block.
You are given a permutation p of length n. Also you are given m foe pairs (a_{i}, b_{i}) (1 ≤ a_{i}, b_{i} ≤ n, a_{i} ≠ b_{i}).
Your task is to count the number of different intervals (x, y) (1 ≤ x ≤ y ≤ n) that do not contain any foe pairs. So you sho... | {"inputs": ["2 1\n1 2\n1 2\n", "2 1\n1 2\n1 2\n", "4 2\n1 3 2 4\n3 2\n2 4\n", "4 2\n1 3 2 4\n3 2\n2 1\n", "4 2\n1 3 2 4\n1 2\n2 1\n", "4 2\n1 3 2 4\n3 2\n4 1\n", "4 2\n1 3 2 4\n3 2\n2 4\n", "3 4\n1 2 3\n1 3\n1 2\n1 3\n2 3\n"], "outputs": ["2\n", "2", "5\n", "6\n", "8\n", "6\n", "5", "3\n"]} | coding | 561 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You want to build some obstacle courses. You are given a 0-indexed integer array obstacles of length n, where obstacles[i] describes the height of the ith obstacle.
For every index i between 0 and n - 1 (inclusive), f... | {"functional": "def check(candidate):\n assert candidate(obstacles = [1,2,3,2]) == [1,2,3,3]\n assert candidate(obstacles = [2,2,1]) == [1,2,1]\n assert candidate(obstacles = [3,1,5,6,4,2]) == [1,1,2,3,2,2]\n\n\ncheck(Solution().longestObstacleCourseAtEachPosition)"} | coding | 204 |
Solve the programming task below in a Python markdown code block.
Given an array A consisting of N integers A_{1},A_{2},…,A_{N}, determine if you can sort this array by applying the following operation several times (possibly, zero):
Pick a pair of indices (i,j) with i \neq j and A_{i} \mathbin{\&} A_{j} \neq 0,... | {"inputs": ["4\n3\n6 4 2\n6\n9 34 4 24 1 6\n6\n9 34 24 4 1 6\n2\n1 0"], "outputs": ["Yes\nYes\nNo\nNo"]} | coding | 602 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You have a long flowerbed in which some of the plots are planted, and some are not. However, flowers cannot be planted in adjacent plots.
Given an integer array flowerbed containing 0's and 1's, where 0 means empty an... | {"functional": "def check(candidate):\n assert candidate(flowerbed = [1,0,0,0,1], n = 1) == True\n assert candidate(flowerbed = [1,0,0,0,1], n = 2) == False\n\n\ncheck(Solution().canPlaceFlowers)"} | coding | 145 |
Solve the programming task below in a Python markdown code block.
Lesha plays the recently published new version of the legendary game hacknet. In this version character skill mechanism was introduced. Now, each player character has exactly n skills. Each skill is represented by a non-negative integer ai — the current ... | {"inputs": ["2 6 0 1 4\n5 1\n", "1 100 1 2 30\n1\n", "1 100 1 2 30\n0\n", "1 100 1 2 59\n0\n", "1 100 2 2 59\n1\n", "1 100 0 2 30\n1\n", "1 100 1 2 42\n0\n", "1 100 0 4 30\n1\n"], "outputs": ["5\n5 5 \n", "62\n31 \n", "60\n30\n", "118\n59\n", "120\n60\n", "62\n31\n", "84\n42\n", "124\n31\n"]} | coding | 488 |
Solve the programming task below in a Python markdown code block.
You are given a grid with dimension $n$ x $m$ and two points with coordinates $X(x1,y1)$ and $Y(x2,y2)$ . Your task is to find the number of ways in which one can go from point $A(0, 0)$ to point $B (n, m)$ using the $shortest$ possible path such that th... | {"inputs": ["1\n3 3 1 1 1 2"], "outputs": ["5"]} | coding | 383 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an array of strings nums and an integer k. Each string in nums represents an integer without leading zeros.
Return the string that represents the kth largest integer in nums.
Note: Duplicate numbers shou... | {"functional": "def check(candidate):\n assert candidate(nums = [\"3\",\"6\",\"7\",\"10\"], k = 4) == \"3\"\n assert candidate(nums = [\"2\",\"21\",\"12\",\"1\"], k = 3) == \"2\"\n assert candidate(nums = [\"0\",\"0\"], k = 2) == \"0\"\n\n\ncheck(Solution().kthLargestNumber)"} | coding | 142 |
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef lives in Chefcity. Chefcity can be represented as a straight line with Chef's house at point 0 on this line. There is an infinite number of subway stations in Chefcity, ... | {"inputs": ["4\n1\n2\n3\n9"], "outputs": ["1\n2\n2\n5"]} | coding | 525 |
Solve the programming task below in a Python markdown code block.
Consider a set, $\mbox{S}$, consisting of $\boldsymbol{\mbox{k}}$ integers. The set is beautiful if at least one of the following conditions holds true for every $x\in S$:
$x-1\in S$
$x+1\in S$
For example, $S=\{1,2,50,51\}$ is beautiful but $S=\{1,5,9... | {"inputs": ["2\n6 4\n27 2\n"], "outputs": ["6\n26\n"]} | coding | 626 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Strings s1 and s2 are k-similar (for some non-negative integer k) if we can swap the positions of two letters in s1 exactly k times so that the resulting string equals s2.
Given two anagrams s1 and s2, return the smal... | {"functional": "def check(candidate):\n assert candidate(s1 = \"ab\", s2 = \"ba\") == 1\n assert candidate(s1 = \"abc\", s2 = \"bca\") == 2\n\n\ncheck(Solution().kSimilarity)"} | coding | 122 |
Solve the programming task below in a Python markdown code block.
RSJ has a sequence $a$ of $n$ integers $a_1,a_2, \ldots, a_n$ and an integer $s$. For each of $a_2,a_3, \ldots, a_{n-1}$, he chose a pair of non-negative integers $x_i$ and $y_i$ such that $x_i+y_i=a_i$ and $(x_i-s) \cdot (y_i-s) \geq 0$.
Now he is inte... | {"inputs": ["10\n5 0\n2 0 1 3 4\n5 1\n5 3 4 3 5\n7 2\n7 6 5 4 3 2 1\n5 1\n1 2 3 4 5\n5 2\n1 2 3 4 5\n4 0\n0 1 1 1\n5 5\n4 3 5 6 4\n4 1\n0 2 1 0\n3 99999\n200000 200000 200000\n6 8139\n7976 129785 12984 78561 173685 15480\n"], "outputs": ["0\n18\n32\n11\n14\n0\n16\n0\n40000000000\n2700826806\n"]} | coding | 714 |
Solve the programming task below in a Python markdown code block.
When preparing a tournament, Codeforces coordinators try treir best to make the first problem as easy as possible. This time the coordinator had chosen some problem and asked $n$ people about their opinions. Each person answered whether this problem is e... | {"inputs": ["1\n0\n", "1\n1\n", "1\n1\n", "1\n0\n", "2\n0 0\n", "2\n0 0\n", "3\n0 0 1\n", "3\n0 0 0\n"], "outputs": ["EASY\n", "HARD\n", "HARD\n", "EASY\n", "EASY\n", "EASY\n", "HARD\n", "EASY\n"]} | coding | 355 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a string array words, return an array of all characters that show up in all strings within the words (including duplicates). You may return the answer in any order.
Please complete the following python code pr... | {"functional": "def check(candidate):\n assert candidate(words = [\"bella\",\"label\",\"roller\"]) == [\"e\",\"l\",\"l\"]\n assert candidate(words = [\"cool\",\"lock\",\"cook\"]) == [\"c\",\"o\"]\n\n\ncheck(Solution().commonChars)"} | coding | 83 |
Solve the programming task below in a Python markdown code block.
Today is Chocolate day and Kabir and Tara are visiting a Valentine fair. Upon arriving, they find a stall with an interesting game.
There are N$N$ jars having some chocolates in them. To win the game, one has to select the maximum number of consecutive j... | {"inputs": ["1\n6 5\n1 3 3 1 1 5"], "outputs": ["3"]} | coding | 412 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an array of integers nums represents the numbers written on a chalkboard.
Alice and Bob take turns erasing exactly one number from the chalkboard, with Alice starting first. If erasing a number causes th... | {"functional": "def check(candidate):\n assert candidate(nums = [1,1,2]) == False\n assert candidate(nums = [0,1]) == True\n assert candidate(nums = [1,2,3]) == True\n\n\ncheck(Solution().xorGame)"} | coding | 182 |
Solve the programming task below in a Python markdown code block.
We have N colored balls arranged in a row from left to right; the color of the i-th ball from the left is c_i.
You are given Q queries. The i-th query is as follows: how many different colors do the l_i-th through r_i-th balls from the left have?
-----C... | {"inputs": ["4 1\n1 2 1 3\n1 3\n2 4\n3 3", "4 2\n1 2 1 3\n1 3\n2 4\n3 3", "4 3\n1 1 1 3\n1 3\n2 4\n3 3", "4 1\n0 2 1 3\n1 3\n2 4\n3 3", "4 2\n1 2 1 3\n1 3\n3 4\n3 3", "4 2\n1 1 1 3\n1 3\n3 4\n3 3", "4 2\n1 1 1 1\n1 3\n3 4\n3 5", "4 3\n1 2 1 5\n1 3\n2 4\n3 3"], "outputs": ["2\n", "2\n3\n", "1\n2\n1\n", "3\n", "2\n2\n", ... | coding | 338 |
Solve the programming task below in a Python markdown code block.
# Task
The string is called `prime` if it cannot be constructed by concatenating some (more than one) equal strings together.
For example, "abac" is prime, but "xyxy" is not("xyxy"="xy"+"xy").
Given a string determine if it is prime or not.
# Inpu... | {"functional": "_inputs = [['abac'], ['abab'], ['aaaa'], ['x'], ['abc'], ['fdsyffdsyffdsyffdsyffdsyf'], ['utdutdtdutd'], ['abba']]\n_outputs = [[True], [False], [False], [True], [True], [False], [True], [True]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n re... | coding | 146 |
Solve the programming task below in a Python markdown code block.
Complete the method which returns the number which is most frequent in the given input array. If there is a tie for most frequent number, return the largest number among them.
Note: no empty arrays will be given.
## Examples
```
[12, 10, 8, 12, 7, 6,... | {"functional": "_inputs = [[[12, 10, 8, 12, 7, 6, 4, 10, 12]], [[12, 10, 8, 12, 7, 6, 4, 10, 10]], [[12, 10, 8, 12, 7, 6, 4, 10, 12, 10]], [[12, 10, 8, 8, 3, 3, 3, 3, 2, 4, 10, 12, 10]], [[1, 2, 3]], [[1, 1, 2, 3]], [[1, 1, 2, 2, 3]]]\n_outputs = [[12], [10], [12], [3], [3], [1], [2]]\nimport math\ndef _deep_eq(a, b, t... | coding | 216 |
Solve the programming task below in a Python markdown code block.
Write a function that rearranges an integer into its largest possible value.
```python
super_size(123456) # 654321
super_size(105) # 510
super_size(12) # 21
```
``` haskell
superSize 123456 `shouldBe` 654321
superSize 105 `shouldBe` 510
su... | {"functional": "_inputs = [[69], [513], [2017], [414], [608719], [123456789], [700000000001], [666666], [2], [0]]\n_outputs = [[96], [531], [7210], [441], [987610], [987654321], [710000000000], [666666], [2], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n ... | coding | 179 |
Solve the programming task below in a Python markdown code block.
Let's consider one interesting word game. In this game you should transform one word into another through special operations.
Let's say we have word w, let's split this word into two non-empty parts x and y so, that w = xy. A split operation is transfo... | {"inputs": ["ab\nba\n0\n", "hi\nhi\n1\n", "ab\nba\n9\n", "aa\naa\n1\n", "ab\nab\n0\n", "ba\naa\n1\n", "ab\nb`\n2\n", "bb\nab\n2\n"], "outputs": ["0\n", "0\n", "1\n", "1\n", "1\n", "0\n", "0\n", "0\n"]} | coding | 453 |
Solve the programming task below in a Python markdown code block.
Every Turkish citizen has an identity number whose validity can be checked by these set of rules:
- It is an 11 digit number
- First digit can't be zero
- Take the sum of 1st, 3rd, 5th, 7th and 9th digit and multiply it by 7.
Then subtract the sum of 2n... | {"functional": "_inputs = [[6923522112], [692352217312], ['x5810a78432'], [36637640050], [12762438338], ['03868894286'], [10000000146], [19415235426], [16691067984], [72097107542], [57040492705]]\n_outputs = [[False], [False], [False], [True], [False], [False], [True], [True], [False], [True], [False]]\nimport math\nde... | coding | 479 |
Solve the programming task below in a Python markdown code block.
[BasE91](http://base91.sourceforge.net/) is a method for encoding binary as ASCII characters. It is more efficient than Base64 and needs 91 characters to represent the encoded data.
The following ASCII charakters are used:
'ABCDEFGHIJKLMNOPQRSTUVWX... | {"functional": "_inputs = [['fPNKd'], ['>OwJh>Io0Tv!8PE']]\n_outputs = [['test'], ['Hello World!']]\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) != l... | coding | 232 |
Solve the programming task below in a Python markdown code block.
Snuke has a calculator. It has a display and two buttons.
Initially, the display shows an integer x. Snuke wants to change this value into another integer y, by pressing the following two buttons some number of times in arbitrary order:
* Button A: Whe... | {"inputs": ["9 2", "28 0", "28 2", "28 3", "53 3", "53 6", "53 0", "84 0"], "outputs": ["9\n", "29\n", "28\n", "27\n", "52\n", "49\n", "54\n", "85\n"]} | coding | 249 |
Solve the programming task below in a Python markdown code block.
We want an array, but not just any old array, an array with contents!
Write a function that produces an array with the numbers `0` to `N-1` in it.
For example, the following code will result in an array containing the numbers `0` to `4`:
```
arr(5) //... | {"functional": "_inputs = [[4], [0]]\n_outputs = [[[0, 1, 2, 3]], [[]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n ... | coding | 117 |
Solve the programming task below in a Python markdown code block.
On a circle lie $2n$ distinct points, with the following property: however you choose $3$ chords that connect $3$ disjoint pairs of points, no point strictly inside the circle belongs to all $3$ chords. The points are numbered $1, \, 2, \, \dots, \, 2n$ ... | {"inputs": ["4\n4 2\n8 2\n1 6\n1 1\n2 1\n4 0\n10 0\n5 12\n2 20\n9 4\n4 18\n46 18\n1 9\n", "4\n8 2\n8 3\n1 5\n1 1\n2 1\n1 0\n10 1\n19 1\n2 20\n5 7\n16 18\n7 0\n4 13\n", "4\n4 2\n8 2\n1 5\n1 1\n2 1\n0 0\n9 6\n14 6\n2 3\n5 10\n13 18\n4 12\n11 7\n", "4\n4 2\n8 2\n1 5\n1 1\n2 1\n0 0\n9 6\n14 6\n2 3\n5 15\n13 18\n4 12\n11 7\... | coding | 660 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer n. You roll a fair 6-sided dice n times. Determine the total number of distinct sequences of rolls possible such that the following conditions are satisfied:
The greatest common divisor of an... | {"functional": "def check(candidate):\n assert candidate(n = 4) == 184\n assert candidate(n = 2) == 22\n\n\ncheck(Solution().distinctSequences)"} | coding | 188 |
Solve the programming task below in a Python markdown code block.
Alice is teaching Bob maths via a game called N-guesser.
Alice has a positive integer N which Bob needs to guess. She gives him two pieces of information with which to do this:
A positive integer X, which denotes the sum of divisors of N.
Two positive ... | {"inputs": ["2\n4 4 3\n4 1 1\n"], "outputs": ["3\n-1"]} | coding | 377 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array of positive integers arr (not necessarily distinct), return the lexicographically largest permutation that is smaller than arr, that can be made with exactly one swap. If it cannot be done, then return ... | {"functional": "def check(candidate):\n assert candidate(arr = [3,2,1]) == [3,1,2]\n assert candidate(arr = [1,1,5]) == [1,1,5]\n assert candidate(arr = [1,9,4,6,7]) == [1,7,4,6,9]\n\n\ncheck(Solution().prevPermOpt1)"} | coding | 114 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
We distribute some number of candies, to a row of n = num_people people in the following way:
We then give 1 candy to the first person, 2 candies to the second person, and so on until we give n candies to the last per... | {"functional": "def check(candidate):\n assert candidate(candies = 7, num_people = 4) == [1,2,3,1]\n assert candidate(candies = 10, num_people = 3) == [5,2,3]\n\n\ncheck(Solution().distributeCandies)"} | coding | 244 |
Solve the programming task below in a Python markdown code block.
A remote island chain contains n islands, labeled 1 through n. Bidirectional bridges connect the islands to form a simple cycle — a bridge connects islands 1 and 2, islands 2 and 3, and so on, and additionally a bridge connects islands n and 1. The cente... | {"inputs": ["2\n1 0\n0 1\n", "2\n0 1\n0 1\n", "2\n1 0\n1 0\n", "2\n1 0\n1 0\n", "2\n0 1\n0 1\n", "2\n1 0\n0 1\n", "3\n1 0 2\n2 0 1\n", "3\n0 2 1\n1 2 0\n"], "outputs": ["YES\n", "YES\n", "YES\n", "YES", "YES", "YES", "YES\n", "YES\n"]} | coding | 539 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed binary string target of length n. You have another binary string s of length n that is initially set to all zeros. You want to make s equal to target.
In one operation, you can pick an index ... | {"functional": "def check(candidate):\n assert candidate(target = \"10111\") == 3\n assert candidate(target = \"101\") == 3\n assert candidate(target = \"00000\") == 0\n\n\ncheck(Solution().minFlips)"} | coding | 154 |
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 all root-to-leaf paths in any order.
A leaf is a node with no children.
Please complete the following python code precisely:
```python
# Definition for a binary tree node.
# c... | {"functional": "def check(candidate):\n assert candidate(root = tree_node([1,2,3,None,5])) == [\"1->2->5\",\"1->3\"]\n assert candidate(root = tree_node([1])) == [\"1\"]\n\n\ncheck(Solution().binaryTreePaths)"} | coding | 130 |
Solve the programming task below in a Python markdown code block.
### Preface
You are currently working together with a local community to build a school teaching children how to code. First plans have been made and the community wants to decide on the best location for the coding school.
In order to make this decision... | {"functional": "_inputs = [[[[3, 7], [2, 2], [14, 1]], [{'id': 1, 'x': 3, 'y': 4}, {'id': 2, 'x': 8, 'y': 2}]], [[[54, 7], [1, 211], [14, 44], [12, 5], [14, 7]], [{'id': 1, 'x': 44, 'y': 55}, {'id': 2, 'x': 12, 'y': 57}, {'id': 3, 'x': 23, 'y': 66}]], [[[152, 7], [1, 211], [14, 56], [12, 4], [142, 7]], [{'id': 1, 'x': ... | coding | 345 |
Solve the programming task below in a Python markdown code block.
Write a function `getDrinkByProfession`/`get_drink_by_profession()` that receives as input parameter a string, and produces outputs according to the following table:
Input
Output
"Jabroni"
"Patron Tequila"
"School Counselor"
"Anything with Alcoho... | {"functional": "_inputs = [['jabrOni'], ['scHOOl counselor'], ['prOgramMer'], ['bike ganG member'], ['poLiTiCian'], ['rapper'], ['pundit'], ['Pug'], ['jabrOnI'], ['scHOOl COUnselor'], ['prOgramMeR'], ['bike GanG member'], ['poLiTiCiAN'], ['RAPPer'], ['punDIT'], ['pUg']]\n_outputs = [['Patron Tequila'], ['Anything with ... | coding | 236 |
Solve the programming task below in a Python markdown code block.
There are n seats in the train's car and there is exactly one passenger occupying every seat. The seats are numbered from 1 to n from left to right. The trip is long, so each passenger will become hungry at some moment of time and will go to take boiled ... | {"inputs": ["1 1\n1\n", "1 2\n1\n", "1 2\n0\n", "1 3\n1\n", "1 3\n0\n", "5 314\n0 310 18 628 0\n", "5 314\n0 365 18 628 0\n", "5 314\n0 365 18 1117 0\n"], "outputs": ["2 \n", "3 ", "2 ", "4 ", "3 ", "314 628 942 1256 1570 ", "314 942 628 1256 1570 ", "314 942 628 1570 1256 "]} | coding | 627 |
Solve the programming task below in a Python markdown code block.
You are given two integers a and b. Determine if a+b=15 or a\times b=15 or neither holds.
Note that a+b=15 and a\times b=15 do not hold at the same time.
Constraints
* 1 \leq a,b \leq 15
* All values in input are integers.
Input
Input is given from ... | {"inputs": ["8 7", "3 7", "2 1", "3 8", "4 1", "8 5", "3 0", "4 0"], "outputs": ["+\n", "x\n", "x\n", "x\n", "x\n", "x\n", "x\n", "x\n"]} | coding | 171 |
Solve the programming task below in a Python markdown code block.
The member states of the UN are planning to send $2$ people to the moon. They want them to be from different countries. You will be given a list of pairs of astronaut ID's. Each pair is made of astronauts from the same country. Determine how many pair... | {"inputs": ["4 1\n0 2\n", "5 3\n0 1\n2 3\n0 4\n"], "outputs": ["5\n", "6\n"]} | coding | 559 |
Solve the programming task below in a Python markdown code block.
Petya has got an interesting flower. Petya is a busy person, so he sometimes forgets to water it. You are given n days from Petya's live and you have to determine what happened with his flower in the end.
The flower grows as follows:
* If the flower... | {"inputs": ["1\n7\n1 0 1 1 0 0 1 0 0 0\n", "1\n7\n0 0 1 1 0 0 1 0 0 0\n", "1\n7\n0 0 2 1 0 0 1 0 0 0\n", "1\n3\n0 0 2 1 0 0 1 0 0 0\n", "1\n3\n0 0 2 1 0 0 2 0 0 0\n", "1\n7\n0 0 1 1 0 0 1 1 0 0\n", "1\n7\n0 0 2 1 1 0 1 0 0 0\n", "1\n3\n0 0 2 1 1 0 1 0 0 0\n"], "outputs": ["-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n",... | coding | 395 |
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
You are given N red points and M blue points on a 2D plane.
You are required to delete the minimum number of points(the deleted points can be of both colors) so that it's po... | {"inputs": ["1\n4 4\n0 0\n10 10\n0 10\n10 0\n12 11\n2 1\n12 1\n2 11"], "outputs": ["2"]} | coding | 464 |
Solve the programming task below in a Python markdown code block.
Given a square grid of characters in the range ascii[a-z], rearrange elements of each row alphabetically, ascending. Determine if the columns are also in ascending alphabetical order, top to bottom. Return YES if they are or NO if they are not.
Exampl... | {"inputs": ["1\n5\nebacd\nfghij\nolmkn\ntrpqs\nxywuv\n"], "outputs": ["YES\n"]} | coding | 519 |
Solve the programming task below in a Python markdown code block.
Array of integers is unimodal, if:
it is strictly increasing in the beginning; after that it is constant; after that it is strictly decreasing.
The first block (increasing) and the last block (decreasing) may be absent. It is allowed that both of ... | {"inputs": ["1\n7\n", "1\n7\n", "1\n9\n", "2\n1 3\n", "2\n1 2\n", "2\n4 2\n", "2\n2 1\n", "2\n5 1\n"], "outputs": ["YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n"]} | coding | 443 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two non-negative integers num1 and num2.
In one operation, if num1 >= num2, you must subtract num2 from num1, otherwise subtract num1 from num2.
For example, if num1 = 5 and num2 = 4, subtract num2 from... | {"functional": "def check(candidate):\n assert candidate(num1 = 2, num2 = 3) == 3\n assert candidate(num1 = 10, num2 = 10) == 1\n\n\ncheck(Solution().countOperations)"} | coding | 183 |
Solve the programming task below in a Python markdown code block.
Consider the string `"adfa"` and the following rules:
```Pearl
a) each character MUST be changed either to the one before or the one after in alphabet.
b) "a" can only be changed to "b" and "z" to "y".
```
From our string, we get:
```Pearl
"adfa" -> [... | {"functional": "_inputs = [['abba'], ['abaazaba'], ['abccba'], ['adfa'], ['ae'], ['abzy'], ['ababbaba'], ['sq'], ['kxbkwgyydkcbtjcosgikfdyhuuprubpwthgflucpyylbofvqxkkvqthmdnywpaunfihvupbwpruwfybdmgeuocltdaidyyewmbzm']]\n_outputs = [[True], [False], [True], [True], [False], [False], [True], [True], [True]]\nimport math\... | coding | 298 |
Solve the programming task below in a Python markdown code block.
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well.
A tuple $(a, b, c)$ is considered good if it consists of three prime numbers $a$, $b$ and $c$ such that $a < b < c ≤ N$ and $a + b = c$.
Two tuples... | {"inputs": ["2\n3\n6"], "outputs": ["0\n1"]} | coding | 352 |
Solve the programming task below in a Python markdown code block.
You have probably registered on Internet sites many times. And each time you should enter your invented password. Usually the registration form automatically checks the password's crypt resistance. If the user's password isn't complex enough, a message i... | {"inputs": ["0\n", "_\n", "a\n", "D\n", "_\n", "?\n", "?\n", "R\n"], "outputs": ["Too weak\n", "Too weak\n", "Too weak\n", "Too weak\n", "Too weak\n", "Too weak\n", "Too weak\n", "Too weak\n"]} | coding | 283 |
Solve the programming task below in a Python markdown code block.
Implement a class/function, which should parse time expressed as `HH:MM:SS`, or `null/nil/None` otherwise.
Any extra characters, or minutes/seconds higher than 59 make the input invalid, and so should return `null/nil/None`.
Also feel free to reuse/exte... | {"functional": "_inputs = [['00:00:00'], ['01:02:03'], ['01:02:60'], ['01:60:03'], ['99:59:59'], ['0:00:00'], ['00:0:00'], ['00:00:0'], ['00:00:00\\n'], ['\\n00:00:00'], ['100:59:59'], ['09:059:59'], ['09:159:59'], ['09:59:059'], ['09:59:159']]\n_outputs = [[0], [3723], [None], [None], [359999], [None], [None], [None],... | coding | 91 |
Solve the programming task below in a Python markdown code block.
### Task
You've just moved into a perfectly straight street with exactly ```n``` identical houses on either side of the road. Naturally, you would like to find out the house number of the people on the other side of the street. The street looks something... | {"functional": "_inputs = [[1, 3], [3, 3], [2, 3], [3, 5], [7, 11], [10, 22], [20, 3400], [9, 26], [20, 10]]\n_outputs = [[6], [4], [5], [8], [16], [35], [6781], [44], [1]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, a... | coding | 367 |
Solve the programming task below in a Python markdown code block.
Your task is to generate the Fibonacci sequence to `n` places, with each alternating value as `"skip"`. For example:
`"1 skip 2 skip 5 skip 13 skip 34"`
Return the result as a string
You can presume that `n` is always a positive integer between (and i... | {"functional": "_inputs = [[1], [5], [7]]\n_outputs = [['1'], ['1 skip 2 skip 5'], ['1 skip 2 skip 5 skip 13']]\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... | coding | 109 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You own a Goal Parser that can interpret a string command. The command consists of an alphabet of "G", "()" and/or "(al)" in some order. The Goal Parser will interpret "G" as the string "G", "()" as the string "o", an... | {"functional": "def check(candidate):\n assert candidate(command = \"G()(al)\") == \"Goal\"\n assert candidate(command = \"G()()()()(al)\") == \"Gooooal\"\n assert candidate(command = \"(al)G(al)()()G\") == \"alGalooG\"\n\n\ncheck(Solution().interpret)"} | coding | 136 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given the array nums, for each nums[i] find out how many numbers in the array are smaller than it. That is, for each nums[i] you have to count the number of valid j's such that j != i and nums[j] < nums[i].
Return the... | {"functional": "def check(candidate):\n assert candidate(nums = [8,1,2,2,3]) == [4,0,1,1,3]\n assert candidate(nums = [6,5,4,8]) == [2,1,0,3]\n assert candidate(nums = [7,7,7,7]) == [0,0,0,0]\n\n\ncheck(Solution().smallerNumbersThanCurrent)"} | coding | 114 |
Solve the programming task below in a Python markdown code block.
During one of the space missions, humans have found an evidence of previous life at one of the planets. They were lucky enough to find a book with birth and death years of each individual that had been living at this planet. What's interesting is that th... | {"inputs": ["1\n1 2\n", "1\n1 2\n", "1\n1 3\n", "1\n0 3\n", "1\n0 1\n", "1\n0 2\n", "1\n0 6\n", "1\n1 6\n"], "outputs": ["1 1\n", "1 1\n", "1 1\n", "0 1\n", "0 1\n", "0 1\n", "0 1\n", "1 1\n"]} | coding | 382 |
Solve the programming task below in a Python markdown code block.
There is a directed graph G with N vertices and M edges. The vertices are numbered 1, 2, \ldots, N, and for each i (1 \leq i \leq M), the i-th directed edge goes from Vertex x_i to y_i. G does not contain directed cycles.
Find the length of the longest ... | {"inputs": ["6 3\n2 6\n4 5\n5 6", "6 3\n2 6\n4 6\n5 6", "6 3\n4 3\n3 5\n5 6", "7 3\n2 3\n4 5\n5 6", "7 3\n2 3\n1 5\n5 6", "6 3\n2 6\n4 5\n4 6", "7 1\n2 3\n4 5\n5 6", "6 3\n2 6\n4 6\n5 2"], "outputs": ["2\n", "1\n", "3\n", "2\n", "2\n", "1\n", "1\n", "2\n"]} | coding | 328 |
Solve the programming task below in a Python markdown code block.
The postal code in Atcoder Kingdom is A+B+1 characters long, its (A+1)-th character is a hyphen -, and the other characters are digits from 0 through 9.
You are given a string S. Determine whether it follows the postal code format in Atcoder Kingdom.
--... | {"inputs": ["0 0\n5", "0 2\n31", "0 0\n31", "0 0\n48", "0 0\n32", "1 0\n32", "1 0\n48", "0 2\n55"], "outputs": ["No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n"]} | coding | 203 |
Solve the programming task below in a Python markdown code block.
After learning about polynomial hashing, Heidi decided to learn about shift-xor hashing. In particular, she came across this interesting problem.
Given a bitstring $y \in \{0,1\}^n$ find out the number of different $k$ ($0 \leq k < n$) such that there e... | {"inputs": ["1\n0\n", "1\n1\n", "1\n0\n", "1\n1\n", "2\n00\n", "2\n10\n", "2\n01\n", "2\n11\n"], "outputs": ["1\n", "0\n", "1", "0", "2\n", "0\n", "0\n", "1\n"]} | coding | 431 |
Solve the programming task below in a Python markdown code block.
Genos needs your help. He was asked to solve the following programming problem by Saitama:
The length of some string s is denoted |s|. The Hamming distance between two strings s and t of equal length is defined as $\sum_{i = 1}^{|s|}|s_{i} - t_{i}|$, wh... | {"inputs": ["0\n0\n", "1\n0\n", "0\n1\n", "1\n1\n", "1\n0\n", "0\n1\n", "0\n0\n", "1\n1\n"], "outputs": ["0\n", "1\n", "1\n", "0\n", "1\n", "1\n", "0\n", "0\n"]} | coding | 523 |
Solve the programming task below in a Python markdown code block.
Given a string, remove characters until the string is made up of any two alternating characters. When you choose a character to remove, all instances of that character must be removed. Determine the longest string possible that contains just two altern... | {"inputs": ["10\nbeabeefeab\n"], "outputs": ["5\n"]} | coding | 517 |
Solve the programming task below in a Python markdown code block.
Jon Snow now has to fight with White Walkers. He has n rangers, each of which has his own strength. Also Jon Snow has his favourite number x. Each ranger can fight with a white walker only if the strength of the white walker equals his strength. He howev... | {"inputs": ["1 1 1\n1\n", "1 1 1\n1\n", "1 2 1\n1\n", "2 3 5\n1 2\n", "2 1 5\n1 2\n", "2 1 5\n1 2\n", "2 3 5\n1 2\n", "2 1 5\n1 1\n"], "outputs": ["0 0", "0 0\n", "1 1\n", "7 1", "4 2", "4 2\n", "7 1\n", "4 1\n"]} | coding | 608 |
Solve the programming task below in a Python markdown code block.
Little chef has just been introduced to the world of numbers! While experimenting with addition and multiplication operations, the little chef came up with the following problem:
Given an array A of non-negative integers, how many pairs of indices i and... | {"inputs": ["2\n3\n3 4 5\n4\n1 1 1 1", "2\n3\n3 8 5\n4\n1 1 1 1", "2\n3\n1 4 5\n4\n1 1 1 1", "2\n3\n1 3 0\n4\n1 1 2 1", "2\n3\n2 5 2\n4\n1 0 1 1", "2\n3\n1 1 3\n4\n0 2 6 1", "2\n3\n6 4 5\n4\n1 1 1 1", "2\n3\n3 8 5\n4\n1 1 0 1"], "outputs": ["3\n0", "3\n0\n", "1\n0\n", "0\n0\n", "2\n0\n", "0\n1\n", "3\n0\n", "3\n0\n"]} | coding | 322 |
Solve the programming task below in a Python markdown code block.
You are given a positive integer X. Your task is to tell whether there exist two positive integers a and b (a > 0, b > 0) such that
2\cdot a + 2\cdot b + a\cdot b = X
If there exist positive integers a and b satisfying the above condition print YES, ot... | {"inputs": ["4\n2\n5\n6\n12\n"], "outputs": ["NO\nYES\nNO\nYES\n"]} | coding | 402 |
Solve the programming task below in a Python markdown code block.
Problem Statement
Mr. Takatsuki, who is planning to participate in the Aizu training camp, is enthusiastic about studying and has been studying English recently. She tries to learn as many English words as possible by playing the following games on her ... | {"inputs": ["6\nUZI@ 4\nLINER 3\nKGNE 1\nBLL 2\nAS 1\nCHEL 10\nBSKA\nILIC\nNRZI\nUELE\n21", "6\nUZIA 2\nLINER 12\nLGNE 9\nALL 2\nSA 1\nCIEL 9\nBSLA\nCJLI\nIRZN\nUELE\n21", "6\nUZI@ 4\nLINER 12\nLGOE 9\nALL 2\nAS 0\nCIEL 5\nBSLA\nCILI\nINZR\nUELE\n21", "6\nAIZU 4\nLINER 6\nLGNE 3\nLLA 2\nAS 1\nCIEL 10\nBSLA\nCILI\nIRZN\... | coding | 724 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
A confusing number is a number that when rotated 180 degrees becomes a different number with each digit valid.
We can rotate digits of a number by 180 degrees to form new digits.
When 0, 1, 6, 8, and 9 are rotated 18... | {"functional": "def check(candidate):\n assert candidate(6) == True\n assert candidate(89) == True\n assert candidate(11) == False\n assert candidate(25) == False\n\n\ncheck(Solution().confusingNumber)"} | coding | 216 |
Solve the programming task below in a Python markdown code block.
Alice is a very brilliant student. He considers '4' and '7' as Magic numbers. The numbers containing only magic numbers are also magical. Given a magic number N ,he wants to know what could be the next magical number greater than the given number.
-----... | {"inputs": ["2\n4\n47\n\n"], "outputs": ["7\n74"]} | coding | 159 |
Solve the programming task below in a Python markdown code block.
-----
ARRAY AND DISTINCT ELEMENTS
-----
Chef is multitalented but he mistakenly took part in 2 contest which will take place
at the same time. So while chef is busy at one cooking contest, he wants you to
take part in coding contest. Chef wants u to sol... | {"inputs": ["1\n10 6\n8 8 3 5 3 8 5 7 7 7"], "outputs": ["37"]} | coding | 192 |
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.
Maximize t... | {"inputs": ["1\n99999\n", "7\n3 1 4 1 5 9 2\n", "10\n0 1 2 3 4 5 6 7 8 9\n"], "outputs": ["1\n", "4\n", "3\n"]} | coding | 239 |
Solve the programming task below in a Python markdown code block.
Write a function that solves an algebraic expression given as a string.
* The expression can include only sums and products.
* The numbers in the expression are in standard notation (NOT scientific).
* In contrast, the function should return a strin... | {"functional": "_inputs = [['5*4+6'], ['5+4*6'], ['3*8+6*5'], ['5*8+6*3*2'], ['5.4*4.0+6.2+8.0'], ['0.5*1.2*56+9.6*5*81+1'], ['1'], ['1.333333333*1.23456789+0.003*0.002']]\n_outputs = [['2.60000e+01'], ['2.90000e+01'], ['5.40000e+01'], ['7.60000e+01'], ['3.58000e+01'], ['3.92260e+03'], ['1.00000e+00'], ['1.64610e+00']]... | coding | 142 |
Solve the programming task below in a Python markdown code block.
Katsusando loves omelette rice.
Besides, he loves crème brûlée, tenderloin steak and so on, and believes that these foods are all loved by everyone.
To prove that hypothesis, he conducted a survey on M kinds of foods and asked N people whether they like ... | {"inputs": ["1 50\n1 4 3 1", "1 52\n5 9 7 8", "1 50\n1 7 6 3", "1 30\n5 4 2 30", "1 30\n6 4 2 30", "1 30\n3 2 3 30", "1 30\n6 6 2 30", "1 30\n5 4 10 6"], "outputs": ["3\n", "3\n", "3\n", "3\n", "3\n", "3\n", "3\n", "3\n"]} | coding | 363 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
An ugly number is a positive integer whose prime factors are limited to 2, 3, and 5.
Given an integer n, return true if n is an ugly number.
Please complete the following python code precisely:
```python
class Solut... | {"functional": "def check(candidate):\n assert candidate(n = 6) == True\n assert candidate(n = 1) == True\n assert candidate(n = 14) == False\n\n\ncheck(Solution().isUgly)"} | coding | 85 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer n, return true if it is possible to represent n as the sum of distinct powers of three. Otherwise, return false.
An integer y is a power of three if there exists an integer x such that y == 3x.
Plea... | {"functional": "def check(candidate):\n assert candidate(n = 12) == True\n assert candidate(n = 91) == True\n assert candidate(n = 21) == False\n\n\ncheck(Solution().checkPowersOfThree)"} | coding | 100 |
Solve the programming task below in a Python markdown code block.
Chef is very fond of horses. He enjoys watching them race. As expected, he has a stable full of horses. He, along with his friends, goes to his stable during the weekends to watch a few of these horses race. Chef wants his friends to enjoy the race and s... | {"inputs": ["1\n5\n4 9 1 32 13"], "outputs": ["3"]} | coding | 343 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a m x n matrix mat and an integer k, return a matrix answer where each answer[i][j] is the sum of all elements mat[r][c] for:
i - k <= r <= i + k,
j - k <= c <= j + k, and
(r, c) is a valid position in the matr... | {"functional": "def check(candidate):\n assert candidate(mat = [[1,2,3],[4,5,6],[7,8,9]], k = 1) == [[12,21,16],[27,45,33],[24,39,28]]\n assert candidate(mat = [[1,2,3],[4,5,6],[7,8,9]], k = 2) == [[45,45,45],[45,45,45],[45,45,45]]\n\n\ncheck(Solution().matrixBlockSum)"} | coding | 126 |
Solve the programming task below in a Python markdown code block.
Here, we want to solve path planning for a mobile robot cleaning a rectangular room floor with furniture.
Consider the room floor paved with square tiles whose size fits the cleaning robot (1 × 1). There are 'clean tiles' and 'dirty tiles', and the robo... | {"inputs": ["7 5\n.......\n.o...*.\n.......\n.*...*.\n.......\n15 13\n.......x.......\n...o...x....*..\n.......x.......\n.......x.......\n.......x.......\n.-.............\nxxxxx.....xxxxx\n...............\n.......x.......\n.......x.......\n.......x.......\n..*....x....*..\n.......x.......\n10 10\n..........\n..o.......... | coding | 609 |
Solve the programming task below in a Python markdown code block.
An autumn sports festival is held. There are four events: foot race, ball-carrying, obstacle race, and relay. There are n teams participating, and we would like to commend the team with the shortest total time in this 4th event as the "winner", the next ... | {"inputs": ["8\n34001 3 20 3 5 6 1 2 25\n20941 3 5 2 42 7 19 0 42\n67641 4 13 3 12 6 46 1 34\n92201 3 28 2 47 6 37 2 58\n10001 3 50 2 42 7 12 4 54\n63812 4 11 3 11 6 98 2 22\n54092 3 33 2 4 9 18 2 19\n4559 3 44 2 58 6 19 0 46\n4\n1 3 23 1 20 1 34 4 21\n2 5 16 2 12 3 41 2 29\n3 5 24 1 24 2 2 3 35\n4 4 49 2 22 0 41 4 2\n... | coding | 735 |
Solve the programming task below in a Python markdown code block.
There are N squares numbered 1 to N from left to right. Each square has a character written on it, and Square i has a letter s_i. Besides, there is initially one golem on each square.
Snuke cast Q spells to move the golems.
The i-th spell consisted of ... | {"inputs": ["3 4\nACB\nA L\nB L\nB R\nA R", "3 3\nACB\nB L\nB L\nA R\n@ S", "3 3\nBCA\nB L\nB L\nA R\n@ S", "3 4\nCBB\nA L\nC L\nB R\nB R", "3 4\nACB\nA L\nB L\nB R\n@ R", "3 3\nACB\nA L\nB L\nB R\n@ R", "3 3\nACB\nA L\nB L\nA R\n@ R", "3 3\nACB\nA L\nB L\nA R\n@ S"], "outputs": ["2\n", "3\n", "1\n", "0\n", "2\n", "2\n... | coding | 396 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given the head of a singly linked list, return true if it is a palindrome or false otherwise.
Please complete the following python code precisely:
```python
# Definition for singly-linked list.
# class ListNode:
# ... | {"functional": "def check(candidate):\n assert candidate(head = list_node([1,2,2,1])) == True\n assert candidate(head = list_node([1,2])) == False\n\n\ncheck(Solution().isPalindrome)"} | coding | 109 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer array nums, you need to find one continuous subarray such that if you only sort this subarray in non-decreasing order, then the whole array will be sorted in non-decreasing order.
Return the shortest ... | {"functional": "def check(candidate):\n assert candidate(nums = [2,6,4,8,10,9,15]) == 5\n assert candidate(nums = [1,2,3,4]) == 0\n assert candidate(nums = [1]) == 0\n\n\ncheck(Solution().findUnsortedSubarray)"} | coding | 104 |
Solve the programming task below in a Python markdown code block.
You are given a pyramid of the following form with an infinite number of rows:
1
2\ 3
4\ 5\ 6
7\ 8\ 9\ 10
...........
From a cell, you can move to either the bottom-left cell or the bottom-right cell directly in contact with the current one (For examp... | {"inputs": ["3\n2 7\n1 5\n5 3"], "outputs": ["1\n2\n0"]} | coding | 515 |
Solve the programming task below in a Python markdown code block.
Today Vasya visited a widely known site and learned that the continuation of his favourite game Codecraft II will appear after exactly k months. He looked at the calendar and learned that at the moment is the month number s. Vasya immediately got interes... | {"inputs": ["May\n4\n", "May\n7\n", "May\n5\n", "July\n4\n", "May\n44\n", "July\n2\n", "June\n1\n", "May\n48\n"], "outputs": ["September\n", "December\n", "October\n", "November\n", "January\n", "September\n", "July\n", "May\n"]} | coding | 270 |
Solve the programming task below in a Python markdown code block.
The time has finally come, MKnez and Baltic are to host The Game of the Century. For that purpose, they built a village to lodge its participants.
The village has the shape of an equilateral triangle delimited by three roads of length $n$. It is cut int... | {"inputs": ["3\n3\n001\n001\n010\n1\n0\n0\n0\n3\n111\n011\n100\n"], "outputs": ["2\n0\n3\n"]} | coding | 723 |
Solve the programming task below in a Python markdown code block.
A large banner with word CODEFORCES was ordered for the 1000-th onsite round of Codeforces^{ω} that takes place on the Miami beach. Unfortunately, the company that made the banner mixed up two orders and delivered somebody else's banner that contains som... | {"inputs": ["C\n", "C\n", "D\n", "B\n", "ABACABA\n", "ABACABA\n", "AABCABA\n", "CODEFORCE\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]} | coding | 427 |
Solve the programming task below in a Python markdown code block.
In this Kata, you will sort elements in an array by decreasing frequency of elements. If two elements have the same frequency, sort them by increasing value.
More examples in test cases.
Good luck!
Please also try [Simple time difference](https://w... | {"functional": "_inputs = [[[2, 3, 5, 3, 7, 9, 5, 3, 7]], [[1, 2, 3, 0, 5, 0, 1, 6, 8, 8, 6, 9, 1]], [[5, 9, 6, 9, 6, 5, 9, 9, 4, 4]], [[4, 4, 2, 5, 1, 1, 3, 3, 2, 8]], [[4, 9, 5, 0, 7, 3, 8, 4, 9, 0]]]\n_outputs = [[[3, 3, 3, 5, 5, 7, 7, 2, 9]], [[1, 1, 1, 0, 0, 6, 6, 8, 8, 2, 3, 5, 9]], [[9, 9, 9, 9, 4, 4, 5, 5, 6, 6... | coding | 115 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
A binary string is monotone increasing if it consists of some number of 0's (possibly none), followed by some number of 1's (also possibly none).
You are given a binary string s. You can flip s[i] changing it from 0 t... | {"functional": "def check(candidate):\n assert candidate(s = \"00110\") == 1\n assert candidate(s = \"010110\") == 2\n assert candidate(s = \"00011000\") == 2\n\n\ncheck(Solution().minFlipsMonoIncr)"} | coding | 128 |
Solve the programming task below in a Python markdown code block.
The pizza store wants to know how long each order will take. They know:
- Prepping a pizza takes 3 mins
- Cook a pizza takes 10 mins
- Every salad takes 3 mins to make
- Every appetizer takes 5 mins to make
- There are 2 pizza ovens
- 5 pizzas can fit i... | {"functional": "_inputs = [[2, 0, 0], [3, 1, 2], [0, 3, 2], [13, 0, 0], [6, 2, 4], [6, 1, 3], [5, 3, 4]]\n_outputs = [[13], [14.5], [19], [39.5], [26], [19], [29]]\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=to... | coding | 187 |
Solve the programming task below in a Python markdown code block.
You are given a table consisting of n rows and m columns. Each cell of the table contains a number, 0 or 1. In one move we can choose some row of the table and cyclically shift its values either one cell to the left, or one cell to the right.
To cyclica... | {"inputs": ["1 1\n0\n", "1 1\n1\n", "3 1\n0\n0\n0\n", "3 1\n1\n1\n0\n", "3 1\n0\n0\n1\n", "3 1\n1\n0\n0\n", "2 3\n111\n000\n", "5 1\n0\n0\n0\n0\n0\n"], "outputs": ["-1\n", "0\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n"]} | coding | 508 |
Solve the programming task below in a Python markdown code block.
Write a program which reads two integers x and y, and prints them in ascending order.
Constraints
* 0 ≤ x, y ≤ 10000
* the number of datasets ≤ 3000
Input
The input consists of multiple datasets. Each dataset consists of two integers x and y separate... | {"inputs": ["3 1\n2 2\n5 3\n0 0", "3 1\n2 2\n9 3\n0 0", "3 1\n0 2\n9 3\n0 0", "3 0\n0 2\n9 3\n0 0", "3 2\n2 2\n5 6\n0 0", "3 1\n2 3\n9 3\n0 0", "3 0\n0 2\n9 5\n0 0", "3 2\n2 3\n5 6\n0 0"], "outputs": ["1 3\n2 2\n3 5\n", "1 3\n2 2\n3 9\n", "1 3\n0 2\n3 9\n", "0 3\n0 2\n3 9\n", "2 3\n2 2\n5 6\n", "1 3\n2 3\n3 9\n", "0 3\... | coding | 169 |
Solve the programming task below in a Python markdown code block.
Petya once wrote a sad love song and shared it to Vasya. The song is a string consisting of lowercase English letters. Vasya made up $q$ questions about this song. Each question is about a subsegment of the song starting from the $l$-th letter to the $r$... | {"inputs": ["7 3\nabacaba\n1 3\n2 5\n1 7\n", "7 3\nabacaba\n2 3\n2 5\n1 7\n", "7 3\nabacaba\n2 6\n2 5\n1 7\n", "7 3\nabacaba\n2 6\n2 6\n1 7\n", "7 3\nabacaba\n2 3\n4 5\n1 7\n", "7 1\nabacaba\n2 6\n2 5\n1 7\n", "7 2\nabacaba\n2 6\n2 6\n1 7\n", "7 3\nabacaba\n2 3\n4 5\n2 7\n"], "outputs": ["4\n7\n11\n", "3\n7\n11\n", "9\... | coding | 613 |
Solve the programming task below in a Python markdown code block.
Consider an array of numeric strings where each string is a positive number with anywhere from $\mbox{I}$ to $10^{6}$ digits. Sort the array's elements in non-decreasing, or ascending order of their integer values and return the sorted array.
Example
... | {"inputs": ["6\n31415926535897932384626433832795\n1\n3\n10\n3\n5\n", "8\n1\n2\n100\n12303479849857341718340192371\n3084193741082937\n3084193741082938\n111\n200\n"], "outputs": ["1\n3\n3\n5\n10\n31415926535897932384626433832795\n", "1\n2\n100\n111\n200\n3084193741082937\n3084193741082938\n12303479849857341718340192371\n... | coding | 693 |
Solve the programming task below in a Python markdown code block.
Chris the Rabbit has been interested in arrays ever since he was a child. At the moment he is researching arrays with the length of n, containing only integers from 1 to n. He is not good at math, that's why some simple things drive him crazy. For exampl... | {"inputs": ["1\n", "5\n", "8\n", "4\n", "7\n", "2\n", "3\n", "82\n"], "outputs": ["1\n", "247\n", "12862\n", "66\n", "3425\n", "4\n", "17\n", "105516606\n"]} | coding | 273 |
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 playing a card game called Blackjack. He starts with a deck of $N$ cards (numbered $1$ through $N$), where for each valid $i$, the $i$-th car... | {"inputs": ["3\n3 4 5\n1 2 3\n3 3 4\n1 2 3\n2 20 30\n40 10"], "outputs": ["1\n0\n-1"]} | coding | 636 |
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian.
Once upon a time chef decided to learn encodings. And, obviously, he started with the easiest one (well, actually the easiest after Caesar cypher) – substitution cypher.
But very soon Chef got ... | {"inputs": ["3\nqwrtyuipasdfgjkzxcvbnmheol\ndummy!\nbfgjklmopqrstuwxzhvnicdyea\nabcd b efgd hbi!\nqwrtyuipasdfgjkzxcvbnmheol\nDummy!", "3\nqwrtyuipasdfgjkzxcvbnmheol\ndummy!\nbfgjklmopqrstuwxzhvnicdyea\nabcd b efgd hbi!\nqwrtyuipasdfgjkzxcvbnmheol\nDummy!"], "outputs": ["hello!\nhave a nice day!\nHello!", "hello!\nhave... | coding | 472 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a positive integer n, find the sum of all integers in the range [1, n] inclusive that are divisible by 3, 5, or 7.
Return an integer denoting the sum of all numbers in the given range satisfying the constraint.
... | {"functional": "def check(candidate):\n assert candidate(n = 7) == 21\n assert candidate(n = 10) == 40\n assert candidate(n = 9) == 30\n\n\ncheck(Solution().sumOfMultiples)"} | coding | 103 |
Solve the programming task below in a Python markdown code block.
Gargi is thinking of a solution to a problem. Meanwhile, her friend asks her to solve another problem. Since Gargi is busy in her own problem, she seeks your help to solve the new problem.
You are given a string S containing characters a-z (lower case l... | {"inputs": ["1\nabba"], "outputs": ["2"]} | coding | 416 |
Solve the programming task below in a Python markdown code block.
You are given a sequence of integers a_{1},a_{2},a_{3}.....a_{n}. You are free to replace any integer with any other positive integer. How many integers must be replaced to make the resulting sequence strictly increasing?
Input Format
The first line ... | {"inputs": ["3\n4 10 20\n", "5\n1 2 2 3 4 \n", "6\n1 7 10 2 20 22\n"], "outputs": ["0\n", "3\n", "1\n"]} | coding | 340 |
Solve the programming task below in a Python markdown code block.
For a non-negative integer N, define S(N) as the sum of the odd digits of N
plus twice the sum of the even digits of N.
For example, S(5)=5, S(456)=2*4+5+2*6=25, and S(314159)=3+1+2*4+1+5+9=27.
Define D(N) as the last digit of S(N).
So D(5)=5, D(456)=5, ... | {"inputs": ["3\n2 8\n28 102\n1092 314159", "3\n2 8\n35 102\n1092 314159", "3\n2 8\n61 102\n1092 314159", "3\n0 9\n49 155\n4563 223113", "3\n2 8\n28 102\n1358 314159", "3\n2 8\n35 102\n1092 182073", "3\n2 8\n61 102\n1092 544927", "3\n0 9\n49 218\n2145 473966"], "outputs": ["35\n326\n1408814\n", "35\n302\n1408814\n", "35... | coding | 297 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.