task_type stringclasses 1
value | problem stringlengths 261 3.34k | answer stringlengths 35 6.15k | problem_tokens int64 62 774 | answer_tokens int64 12 2.04k |
|---|---|---|---|---|
coding | Solve the programming task below in a Python markdown code block.
Mr. Krabs loves money. He enters a bank and sees that there are n rooms arranged in a row. The only rooms with doors are the two rooms on either corner. Initially, all the rooms are locked (including the corner ones). To enter a room, it must be unlocked... | {"inputs": ["7\n1 2 3 4 5 6 1\n3"], "outputs": ["12"]} | 504 | 29 |
coding | Solve the programming task below in a Python markdown code block.
I'm sure you're familiar with factorials – that is, the product of an integer and all the integers below it.
For example, `5! = 120`, as `5 * 4 * 3 * 2 * 1 = 120`
Your challenge is to create a function that takes any number and returns the number that... | {"functional": "_inputs = [[120], [3628800], [150]]\n_outputs = [['5!'], ['10!'], ['None']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): r... | 204 | 180 |
coding | Solve the programming task below in a Python markdown code block.
There are n pictures delivered for the new exhibition. The i-th painting has beauty a_{i}. We know that a visitor becomes happy every time he passes from a painting to a more beautiful one.
We are allowed to arranged pictures in any order. What is the m... | {"inputs": ["1\n995\n", "1\n995\n", "1\n1000\n", "1\n1000\n", "2\n179 5\n", "2\n251 75\n", "2\n251 42\n", "2\n251 30\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "1\n", "1\n", "1\n", "1\n"]} | 362 | 115 |
coding | Solve the programming task below in a Python markdown code block.
Karan likes the number 4 very much.
Impressed by the power of this number, Karan has begun to look for occurrences of four anywhere. He has a list of T integers, for each of them he wants to calculate the number of occurrences of the digit 4 in the deci... | {"inputs": ["5\n447474\n228\n6664\n40\n81\n"], "outputs": ["4\n0\n1\n1\n0\n"]} | 273 | 44 |
coding | Solve the programming task below in a Python markdown code block.
Alice and Bob are playing One Card Poker.
One Card Poker is a two-player game using playing cards.
Each card in this game shows an integer between 1 and 13, inclusive.
The strength of a card is determined by the number written on it, as follows:
We... | {"inputs": ["8 7", "2 1", "0 0", "8 3", "3 1", "7 3", "4 1", "7 1"], "outputs": ["Alice\n", "Bob\n", "Draw\n", "Alice\n", "Bob\n", "Alice\n", "Bob\n", "Bob\n"]} | 344 | 78 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array of integers arr, return true if and only if it is a valid mountain array.
Recall that arr is a mountain array if and only if:
arr.length >= 3
There exists some i with 0 < i < arr.length - 1 such that:
... | {"functional": "def check(candidate):\n assert candidate(arr = [2,1]) == False\n assert candidate(arr = [3,5,5]) == False\n assert candidate(arr = [0,3,2,1]) == True\n\n\ncheck(Solution().validMountainArray)"} | 151 | 65 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
There is a class with m students and n exams. You are given a 0-indexed m x n integer matrix score, where each row represents one student and score[i][j] denotes the score the ith student got in the jth exam. The matr... | {"functional": "def check(candidate):\n assert candidate(score = [[10,6,9,1],[7,5,11,2],[4,8,3,15]], k = 2) == [[7,5,11,2],[10,6,9,1],[4,8,3,15]]\n assert candidate(score = [[3,4],[5,6]], k = 0) == [[5,6],[3,4]]\n\n\ncheck(Solution().sortTheStudents)"} | 164 | 120 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
We define str = [s, n] as the string str which consists of the string s concatenated n times.
For example, str == ["abc", 3] =="abcabcabc".
We define that string s1 can be obtained from string s2 if we can remove so... | {"functional": "def check(candidate):\n assert candidate(s1 = \"acb\", n1 = 4, s2 = \"ab\", n2 = 2) == 2\n assert candidate(s1 = \"acb\", n1 = 1, s2 = \"acb\", n2 = 1) == 1\n\n\ncheck(Solution().getMaxRepetitions)"} | 234 | 84 |
coding | Solve the programming task below in a Python markdown code block.
Let's dive into the interesting topic of regular expressions! You are given some input, and you are required to check whether they are valid mobile numbers.
A valid mobile number is a ten digit number starting with a $7,8$ or $9$.
Concept
A valid ... | {"inputs": ["2\n9587456281\n1252478965\n"], "outputs": ["YES\nNO\n"]} | 269 | 38 |
coding | Solve the programming task below in a Python markdown code block.
Write
```python
remove(text, what)
```
that takes in a string ```str```(```text``` in Python) and an object/hash/dict/Dictionary ```what``` and returns a string with the chars removed in ```what```.
For example:
```python
remove('this is a string',{'t':1... | {"functional": "_inputs = [['this is a string', {'t': 1, 'i': 2}], ['hello world', {'x': 5, 'i': 2}], ['apples and bananas', {'a': 50, 'n': 1}], ['a', {'a': 1, 'n': 1}], ['codewars', {'c': 5, 'o': 1, 'd': 1, 'e': 1, 'w': 1, 'z': 1, 'a': 1, 'r': 1, 's': 1}]]\n_outputs = [['hs s a string'], ['hello world'], ['pples d bnn... | 222 | 296 |
coding | Solve the programming task below in a Python markdown code block.
"Everybody! Doremy's Perfect Math Class is about to start! Come and do your best if you want to have as much IQ as me!" In today's math class, Doremy is teaching everyone subtraction. Now she gives you a quiz to prove that you are paying attention in cla... | {"inputs": ["2\n2\n1 2\n3\n5 10 25\n"], "outputs": ["2\n5\n"]} | 610 | 32 |
coding | Solve the programming task below in a Python markdown code block.
Read problem statements in [Mandarin], [Bengali], [Russian], and [Vietnamese] as well.
Chef is a software developer, so he has to switch between different languages sometimes. Each programming language has some features, which are represented by integer... | {"inputs": ["3\n1 2 2 1 3 4\n3 4 2 1 4 3\n1 2 1 3 2 4"], "outputs": ["1\n2\n0"]} | 494 | 52 |
coding | Solve the programming task below in a Python markdown code block.
At Aizu Shingakujuku, students are divided into classes by conducting a proficiency test when they enter the cram school. The test consists of three subjects: Mathematics, English, and Japanese, and students are divided into A, B, and C classes. The leve... | {"inputs": ["4\n110 16 20\n98 86 19\n80 8 39\n65 79 65\n2\n99 81 9\n66 72 90\n0", "4\n010 163 20\n98 86 5\n80 34 33\n65 79 65\n2\n49 81 20\n97 1 4\n0", "4\n110 11 20\n98 86 19\n80 10 39\n65 0 65\n2\n99 81 9\n66 102 90\n0", "4\n100 64 20\n51 86 18\n80 39 36\n65 79 65\n2\n99 81 6\n76 72 90\n0", "4\n100 70 20\n98 86 55\n8... | 465 | 608 |
coding | Solve the programming task below in a Python markdown code block.
Consider the number triangle below, in which each number is equal to the number above plus the number to the left. If there is no number above, assume it's a `0`.
The triangle has `5` rows and the sum of the last row is `sum([1,4,9,14,14]) = 42`.
You w... | {"functional": "_inputs = [[4], [5], [6], [7], [8], [20]]\n_outputs = [[14], [42], [132], [429], [1430], [6564120420]]\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 ... | 227 | 203 |
coding | Solve the programming task below in a Python markdown code block.
Iahub likes trees very much. Recently he discovered an interesting tree named propagating tree. The tree consists of n nodes numbered from 1 to n, each node i having an initial value a_{i}. The root of the tree is node 1.
This tree has a special propert... | {"inputs": ["5 5\n1 2 1 1 2\n1 2\n1 3\n2 4\n2 5\n1 2 3\n1 1 2\n2 1\n2 2\n2 4\n", "5 5\n1 2 1 1 2\n1 2\n1 3\n2 4\n2 5\n1 2 3\n1 1 2\n2 1\n2 2\n2 4\n", "10 10\n137 197 856 768 825 894 86 174 2 326\n7 8\n4 7\n8 9\n7 10\n1 2\n2 4\n3 6\n3 5\n2 3\n1 9 624\n2 1\n2 4\n1 6 505\n1 8 467\n1 3 643\n2 1\n1 8 631\n2 1\n1 7 244\n", "... | 694 | 1,127 |
coding | Solve the programming task below in a Python markdown code block.
Let $\mathsf{AND}$ denote the bitwise AND operation , and $\mathsf{OR}$ denote the bitwise OR operation .
You are given an array $a$ of length $n$ and a non-negative integer $k$. You can perform at most $k$ operations on the array of the following type:... | {"inputs": ["4\n3 2\n2 1 1\n7 0\n4 6 6 28 6 6 12\n1 30\n0\n4 4\n3 1 3 1\n"], "outputs": ["2\n4\n2147483646\n1073741825\n"]} | 646 | 87 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are a hiker preparing for an upcoming hike. You are given heights, a 2D array of size rows x columns, where heights[row][col] represents the height of cell (row, col). You are situated in the top-left cell, (0, 0)... | {"functional": "def check(candidate):\n assert candidate(heights = [[1,2,2],[3,8,2],[5,3,5]]) == 2\n assert candidate(heights = [[1,2,3],[3,8,4],[5,3,5]]) == 1\n assert candidate(heights = [[1,2,1,1,1],[1,2,1,2,1],[1,2,1,2,1],[1,2,1,2,1],[1,1,1,2,1]]) == 0\n\n\ncheck(Solution().minimumEffortPath)"} | 200 | 140 |
coding | Solve the programming task below in a Python markdown code block.
A string is made of only lowercase latin letters (a,b,c,d,.....,z). Can you find the length of the lexicographically smallest string such that it has exactly ${K}$ sub-strings, each of which are palindromes?
Input Format
The first line of input contai... | {"inputs": ["2\n10\n17\n"], "outputs": ["4\n7\n"]} | 242 | 22 |
coding | Solve the programming task below in a Python markdown code block.
There are $n$ benches in the Berland Central park. It is known that $a_i$ people are currently sitting on the $i$-th bench. Another $m$ people are coming to the park and each of them is going to have a seat on some bench out of $n$ available.
Let $k$ be... | {"inputs": ["1\n10\n5\n", "1\n10\n2\n", "1\n10\n5\n", "2\n1\n5\n1\n", "2\n1\n5\n1\n", "2\n2\n5\n1\n", "2\n1\n10\n1\n", "2\n1\n10\n1\n"], "outputs": ["15 15\n", "12 12\n", "15 15\n", "5 6\n", "5 6\n", "5 7\n", "10 11\n", "10 11\n"]} | 494 | 143 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef is an intern at Zoozle. He has a co-intern named Ajar who's good at maths. Chef wants to impress Ajar with his zoozliness, so he decided to play the following game with ... | {"inputs": ["5\n5"], "outputs": ["187500002"]} | 566 | 22 |
coding | Solve the programming task below in a Python markdown code block.
You are given a multiset $S$ initially consisting of $n$ distinct non-negative integers. A multiset is a set, that can contain some elements multiple times.
You will perform the following operation $k$ times:
Add the element $\lceil\frac{a+b}{2}\rceil$... | {"inputs": ["1\n1 0\n0\n", "1\n1 0\n0\n", "1\n1 0\n1\n", "1\n1 1\n4\n", "1\n1 0\n2\n", "1\n1 1\n1\n", "1\n1 2\n4\n", "1\n1 0\n4\n"], "outputs": ["1\n", "1\n", "1\n", "2\n", "1\n", "1\n", "2\n", "1\n"]} | 700 | 118 |
coding | Solve the programming task below in a Python markdown code block.
Little Walter likes playing with his toy scales. He has $N$ types of weights. The $i^{\mbox{th}}$ weight type has weight $a_i$. There are infinitely many weights of each type.
Recently, Walter defined a function, $F(X)$, denoting the number of different... | {"inputs": ["3\n1 2 3\n1 6\n"], "outputs": ["22\n"]} | 567 | 25 |
coding | Solve the programming task below in a Python markdown code block.
Jeff's got n cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got?
Jeff must mak... | {"inputs": ["1\n5\n", "1\n0\n", "1\n0\n", "1\n5\n", "2\n0 0\n", "2\n0 5\n", "2\n0 5\n", "2\n0 0\n"], "outputs": ["-1\n", "0\n", "0\n", "-1\n", "0\n", "0\n", "0\n", "0\n"]} | 336 | 95 |
coding | Solve the programming task below in a Python markdown code block.
You are given three integers A, B and C.
Determine if there exists an equilateral triangle whose sides have lengths A, B and C.
Constraints
* All values in input are integers.
* 1 \leq A,B,C \leq 100
Input
Input is given from Standard Input in the f... | {"inputs": ["2 4 2", "0 0 0", "3 4 2", "2 6 2", "3 4 1", "2 7 2", "3 0 1", "1 7 2"], "outputs": ["No\n", "Yes\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n"]} | 141 | 94 |
coding | 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 an integer sequence $A$ with length $N$.
Find the number of (unordered) pairs of elements such that the average of these two elements is also present in the se... | {"inputs": ["3\n2\n2 2\n3\n2 1 3\n6\n4 2 5 1 3 5"], "outputs": ["1\n1\n7"]} | 486 | 44 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a string s, return the length of the longest repeating substrings. If no repeating substring exists, return 0.
Please complete the following python code precisely:
```python
class Solution:
def longestRepe... | {"functional": "def check(candidate):\n assert candidate(\"abcd\") == 0\n assert candidate(\"abbaba\") == 2\n assert candidate(\"aabcaabdaab\") == 3\n assert candidate(\"aaaaa\") == 4\n\n\ncheck(Solution().longestRepeatingSubstring)"} | 74 | 68 |
coding | Solve the programming task below in a Python markdown code block.
An array $a$ is good if for all pairs of adjacent elements, $a_i$ and $a_{i+1}$ ($1\le i \lt n$) are of different parity. Note that an array of size $1$ is trivially good.
You are given an array of size $n$.
In one operation you can select any pair of ... | {"inputs": ["1\n1\n9\n", "1\n10\n4 4 4 4 4 4 4 4 4 5\n", "3\n5\n1 7 11 2 13\n4\n1 2 3 4\n6\n1 1 1 2 2 3\n", "2\n10\n1 1 1 1 1 5 5 5 5 5\n11\n9 9 9 9 9 10 9 9 9 9 9\n", "1\n20\n1 2 3 4 4 5 5 6 6 7 7 9 9 9 9 10 10 124 241 241\n", "30\n1\n1\n1\n2\n2\n1 1\n2\n1 2\n2\n2 1\n2\n2 2\n3\n1 1 1\n3\n1 1 2\n3\n1 2 1\n3\n1 2 2\n3\n... | 472 | 541 |
coding | Solve the programming task below in a Python markdown code block.
Nian is a monster which lives deep in the oceans. Once a year, it shows up on the land, devouring livestock and even people. In order to keep the monster away, people fill their villages with red colour, light, and cracking noise, all of which frighten t... | {"inputs": ["2 2\n15 18\n0 4\n", "2 2\n20 18\n2 14\n", "2 2\n20 18\n0 14\n", "2 2\n15 18\n0 14\n", "2 2\n20 18\n2 14\n", "5 3\n0 0 1 0 3\n0 0 1\n", "5 3\n-1 0 1 0 3\n0 0 1\n", "5 3\n-1 0 1 2 3\n-1 0 1\n"], "outputs": ["60\n", "252\n", "252\n", "210\n", "252\n", "1\n", "1\n", "2\n"]} | 439 | 200 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a binary string s consisting only of zeroes and ones.
A substring of s is considered balanced if all zeroes are before ones and the number of zeroes is equal to the number of ones inside the substring. N... | {"functional": "def check(candidate):\n assert candidate(s = \"01000111\") == 6\n assert candidate(s = \"00111\") == 4\n assert candidate(s = \"111\") == 0\n\n\ncheck(Solution().findTheLongestBalancedSubstring)"} | 129 | 73 |
coding | Solve the programming task below in a Python markdown code block.
Write a program that, given a word, computes the scrabble score for that word.
## Letter Values
You'll need these:
```
Letter Value
A, E, I, O, U, L, N, R, S, T 1
D, G 2
B, C, M, P ... | {"functional": "_inputs = [[''], ['a'], ['street'], ['STREET'], [' a'], ['st re et'], ['f'], ['quirky'], ['MULTIBILLIONAIRE'], ['alacrity']]\n_outputs = [[0], [1], [6], [6], [1], [6], [4], [22], [20], [13]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return... | 430 | 223 |
coding | Solve the programming task below in a Python markdown code block.
Henry and Derek are waiting on a room, eager to join the Snackdown 2016 Qualifier Round. They decide to pass the time by playing a game.
In this game's setup, they write N positive integers on a blackboard. Then the players take turns, starting with He... | {"inputs": ["2\n2\n3 4\n3\n1 3 5"], "outputs": ["Henry\nDerek"]} | 682 | 29 |
coding | Solve the programming task below in a Python markdown code block.
A permutation p of size n is the sequence p_1, p_2, ..., p_{n}, consisting of n distinct integers, each of them is from 1 to n (1 ≤ p_{i} ≤ n).
A lucky permutation is such permutation p, that any integer i (1 ≤ i ≤ n) meets this condition p_{p}_{i} = n ... | {"inputs": ["1\n", "2\n", "4\n", "5\n", "3\n", "6\n", "7\n", "8\n"], "outputs": ["1 \n", "-1\n", "2 4 1 3 \n", "2 5 3 1 4 \n", "-1\n", "-1\n", "-1\n", "2 8 4 6 3 5 1 7 \n"]} | 259 | 102 |
coding | Solve the programming task below in a Python markdown code block.
A city has been infected by a contagious virus.
In a survey, it was found that A out of the N people living in the city are currently infected.
It has been observed that the only way for a person to get infected is if he comes in contact with an already... | {"inputs": ["3\n2 1\n3 2\n3 1"], "outputs": ["1\n1\n1"]} | 456 | 28 |
coding | Solve the programming task below in a Python markdown code block.
You are a person who is always fond of eating candies. Your friend gave you a candy of length N, to eat during the break period of your school.
You start eating this candy from one of the ends. But as it is not your candy, your friend told you to eat ex... | {"inputs": ["3\n3 1\n3 2\n0 3\n"], "outputs": ["3\n-1\n0\n"]} | 436 | 31 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian.
Time flies fast, Chef’s sons are getting older, stronger and higher. Chef has got two sons and they don’t go well with each other. Their relations are getting worse day by day. Concerned Chef h... | {"inputs": ["4 4\n0 1 1 \n1 2 2\n2 3 3\n3 0 4"], "outputs": ["1 2"]} | 704 | 41 |
coding | Solve the programming task below in a Python markdown code block.
Alice and Bob play a game. There is a paper strip which is divided into n + 1 cells numbered from left to right starting from 0. There is a chip placed in the n-th cell (the last one).
Players take turns, Alice is first. Each player during his or her tu... | {"inputs": ["1\n9 3\n", "1\n8 2\n", "1\n3 7\n", "1\n2 7\n", "1\n0 4\n", "1\n25 6\n", "1\n24 6\n", "1\n25 6\n"], "outputs": ["Alice\n", "Alice\n", "Bob\n", "Alice\n", "Bob\n", "Alice\n", "Bob\n", "Alice\n"]} | 344 | 105 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given two integer arrays nums1 and nums2, return the maximum length of a subarray that appears in both arrays.
Please complete the following python code precisely:
```python
class Solution:
def findLength(self, ... | {"functional": "def check(candidate):\n assert candidate(nums1 = [1,2,3,2,1], nums2 = [3,2,1,4,7]) == 3\n assert candidate(nums1 = [0,0,0,0,0], nums2 = [0,0,0,0,0]) == 5\n\n\ncheck(Solution().findLength)"} | 79 | 89 |
coding | Solve the programming task below in a Python markdown code block.
You are given a set S of strings consisting of `0` and `1`, and an integer K.
Find the longest string that is a subsequence of K or more different strings in S. If there are multiple strings that satisfy this condition, find the lexicographically smalle... | {"inputs": ["2 5\n0\n11\n1111", "3 0\n1\n3\n1111\n01000110", "3 2\n1\n2\n1011\n01001110", "3 2\n1\n2\n1011\n01000110", "3 2\n1\n2\n1111\n01000110", "3 2\n1\n3\n1111\n01000110", "3 0\n1\n3\n1111\n00000110", "3 2\n1\n2\n1111\n01001110"], "outputs": ["", "000\n", "00\n", "00\n", "00\n", "00\n", "000\n", "00\n"]} | 531 | 221 |
coding | 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\n0 1\n0 1\n", "2\n1 0\n1 0\n", "2\n1 0\n0 1\n", "3\n0 1 2\n0 1 2\n", "3\n0 1 2\n1 0 2\n", "3\n0 2 1\n2 0 1\n", "3\n0 2 1\n1 2 0\n", "3\n2 0 1\n1 0 2\n"], "outputs": ["YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES"]} | 508 | 146 |
coding | Solve the programming task below in a Python markdown code block.
Princess Artapoelc greeted her guests by either kissing on the cheek (K) or hugging (H). From the first guest
she kisses, she has a
compulsion to necessarily kiss every alternate guest from that first kissed guest. That is if the guests are G_{1},
G_... | {"inputs": ["3\n1\n2\n3"], "outputs": ["2\n4\n6"]} | 337 | 22 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array of integers nums, return the number of good pairs.
A pair (i, j) is called good if nums[i] == nums[j] and i < j.
Please complete the following python code precisely:
```python
class Solution:
def ... | {"functional": "def check(candidate):\n assert candidate(nums = [1,2,3,1,1,3]) == 4\n assert candidate(nums = [1,1,1,1]) == 6\n assert candidate(nums = [1,2,3]) == 0\n\n\ncheck(Solution().numIdenticalPairs)"} | 87 | 77 |
coding | Solve the programming task below in a Python markdown code block.
You are given a sequence of positive integers of length N, a = (a_1, a_2, ..., a_N).
Your objective is to remove some of the elements in a so that a will be a good sequence.
Here, an sequence b is a good sequence when the following condition holds true:
... | {"inputs": ["4\n3 3 3 3\n", "5\n2 4 1 4 2\n", "1\n1000000000\n", "6\n1 2 2 3 3 3\n", "8\n2 7 1 8 2 8 1 8\n"], "outputs": ["1\n", "2\n", "1\n", "0\n", "5\n"]} | 331 | 103 |
coding | Solve the programming task below in a Python markdown code block.
You want to arrange n integers a_1, a_2, ..., a_{n} in some order in a row. Let's define the value of an arrangement as the sum of differences between all pairs of adjacent integers.
More formally, let's denote some arrangement as a sequence of integers... | {"inputs": ["2\n0 0\n", "2\n0 0\n", "2\n0 1\n", "2\n0 2\n", "2\n0 4\n", "2\n0 3\n", "2\n0 -1\n", "2\n-1 -1\n"], "outputs": ["0 0 \n", "0 0\n", "1 0\n", "2 0\n", "4 0\n", "3 0\n", "0 -1\n", "-1 -1\n"]} | 499 | 120 |
coding | Solve the programming task below in a Python markdown code block.
Implement `String#ipv4_address?`, which should return true if given object is an IPv4 address - four numbers (0-255) separated by dots.
It should only accept addresses in canonical representation, so no leading `0`s, spaces etc.
Also feel free to reuse/... | {"functional": "_inputs = [[''], ['127.0.0.1'], ['0.0.0.0'], ['255.255.255.255'], ['10.20.30.40'], ['10.256.30.40'], ['10.20.030.40'], ['127.0.1'], ['127.0.0.0.1'], ['..255.255'], ['127.0.0.1\\n'], ['\\n127.0.0.1'], [' 127.0.0.1'], ['127.0.0.1 '], [' 127.0.0.1 '], ['127.0.0.1.'], ['.127.0.0.1'], ['127..0.1']]\n_outputs... | 89 | 411 |
coding | Solve the programming task below in a Python markdown code block.
You have an $n \times n$ chessboard and $k$ rooks. Rows of this chessboard are numbered by integers from $1$ to $n$ from top to bottom and columns of this chessboard are numbered by integers from $1$ to $n$ from left to right. The cell $(x, y)$ is the ce... | {"inputs": ["5\n3 2\n3 3\n1 1\n5 2\n40 33\n"], "outputs": ["R..\n...\n..R\n-1\nR\nR....\n.....\n..R..\n.....\n.....\n-1\n"]} | 658 | 67 |
coding | 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... | 109 | 182 |
coding | Solve the programming task below in a Python markdown code block.
Takahashi has two positive integers A and B.
It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
Constraints
* 2 ≤ N ≤ 10^5
* N is an integer.
Input
Inpu... | {"inputs": ["3", "5", "7", "4", "9", "8", "2", "6"], "outputs": ["3\n", "5\n", "7\n", "4\n", "9\n", "8\n", "2\n", "6\n"]} | 152 | 62 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given the array nums consisting of n positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of n * (n + ... | {"functional": "def check(candidate):\n assert candidate(nums = [1,2,3,4], n = 4, left = 1, right = 5) == 13 \n assert candidate(nums = [1,2,3,4], n = 4, left = 3, right = 4) == 6\n assert candidate(nums = [1,2,3,4], n = 4, left = 1, right = 10) == 50\n\n\ncheck(Solution().rangeSum)"} | 158 | 122 |
coding | Solve the programming task below in a Python markdown code block.
In this Kata, you will be given two integers `n` and `k` and your task is to remove `k-digits` from `n` and return the lowest number possible, without changing the order of the digits in `n`. Return the result as a string.
Let's take an example of `solv... | {"functional": "_inputs = [[123056, 1], [123056, 2], [123056, 3], [123056, 4], [1284569, 1], [1284569, 2], [1284569, 3], [1284569, 4]]\n_outputs = [['12056'], ['1056'], ['056'], ['05'], ['124569'], ['12456'], ['1245'], ['124']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, fl... | 242 | 288 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer n representing the number of nodes in a perfect binary tree consisting of nodes numbered from 1 to n. The root of the tree is node 1 and each node i in the tree has two children where the left... | {"functional": "def check(candidate):\n assert candidate(n = 7, cost = [1,5,2,2,3,3,1]) == 6\n assert candidate(n = 3, cost = [5,3,3]) == 0\n\n\ncheck(Solution().minIncrements)"} | 240 | 70 |
coding | Solve the programming task below in a Python markdown code block.
You are given an integer N.
Construct any permutation A of N integers such that the value LCM(1 + A_{1} , 2 + A_{2}, \ldots, N + A_{N}) is minimised.
Note:
LCM denotes the [least common multiple] of the integers.
A permutation of N integers contains ... | {"inputs": ["1\n2\n"], "outputs": ["2 1 \n"]} | 286 | 19 |
coding | Solve the programming task below in a Python markdown code block.
Snuke has decided to use a robot to clean his room.
There are N pieces of trash on a number line. The i-th piece from the left is at position x_i. We would like to put all of them in a trash bin at position 0.
For the positions of the pieces of trash, ... | {"inputs": ["2 100\n1 13", "2 100\n1 25", "2 101\n1 25", "2 101\n1 42", "2 101\n1 10", "2 100\n0 13", "2 001\n1 25", "2 101\n0 10"], "outputs": ["370\n", "430\n", "433\n", "518\n", "358\n", "365\n", "133\n", "353\n"]} | 656 | 150 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed integer array nums of length n.
The sum score of nums at an index i where 0 <= i < n is the maximum of:
The sum of the first i + 1 elements of nums.
The sum of the last n - i elements of num... | {"functional": "def check(candidate):\n assert candidate(nums = [4,3,-2,5]) == 10\n assert candidate(nums = [-3,-5]) == -3\n\n\ncheck(Solution().maximumSumScore)"} | 121 | 53 |
coding | Solve the programming task below in a Python markdown code block.
Your job is to change the given string `s` using a non-negative integer `n`.
Each bit in `n` will specify whether or not to swap the case for each alphabetic character in `s`: if the bit is `1`, swap the case; if its `0`, leave it as is. When you finish... | {"functional": "_inputs = [['Hello world!', 11], ['the quick broWn fox leapt over the fence', 9], ['eVerybody likes ice cReam', 85], ['gOOd MOrniNg', 7864], ['how are you today?', 12345], ['the lord of the rings', 0], ['', 11345]]\n_outputs = [['heLLO wORLd!'], ['The QUicK BrowN foX LeaPT ovER thE FenCE'], ['EVErYbODy ... | 337 | 306 |
coding | Solve the programming task below in a Python markdown code block.
In some other world, today is Christmas.
Mr. Takaha decides to make a multi-dimensional burger in his party. A level-L burger (L is an integer greater than or equal to 0) is the following thing:
- A level-0 burger is a patty.
- A level-L burger (L \geq... | {"inputs": ["2 1", "4 7", "0 1", "1 0", "8 7", "1 2", "2 5", "4 1"], "outputs": ["0\n", "3\n", "1\n", "0\n", "0\n", "1\n", "3\n", "0\n"]} | 347 | 78 |
coding | Solve the programming task below in a Python markdown code block.
You are given an array A of length N. Your task is to divide it into several contiguous subarrays. Here, all subarrays obtained must be sorted in either non-decreasing or non-increasing order. At least how many subarrays do you need to divide A into?
Co... | {"inputs": ["6\n1 2 3 2 0 1", "6\n1 2 3 2 0 0", "6\n0 2 3 2 0 0", "6\n0 2 3 1 0 0", "6\n1 2 3 2 2 1", "6\n0 2 3 1 -1 0", "6\n0 2 3 0 -1 0", "6\n0 2 3 -1 -1 0"], "outputs": ["3\n", "2\n", "2\n", "2\n", "2", "3\n", "3\n", "2\n"]} | 238 | 157 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
There are n servers numbered from 0 to n - 1 connected by undirected server-to-server connections forming a network where connections[i] = [ai, bi] represents a connection between servers ai and bi. Any server can rea... | {"functional": "def check(candidate):\n assert candidate(n = 4, connections = [[0,1],[1,2],[2,0],[1,3]]) == [[1,3]]\n assert candidate(n = 2, connections = [[0,1]]) == [[0,1]]\n\n\ncheck(Solution().criticalConnections)"} | 144 | 77 |
coding | Solve the programming task below in a Python markdown code block.
Awruk is taking part in elections in his school. It is the final round. He has only one opponent — Elodreip. The are $n$ students in the school. Each student has exactly $k$ votes and is obligated to use all of them. So Awruk knows that if a person gives... | {"inputs": ["1\n1\n", "1\n1\n", "1\n2\n", "1\n100\n", "2\n1 1\n", "2\n1 4\n", "2\n1 1\n", "1\n100\n"], "outputs": ["3", "3\n", "5\n", "201", "3", "6", "3\n", "201\n"]} | 579 | 96 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given two strings word1 and word2, return the minimum number of operations required to convert word1 to word2.
You have the following three operations permitted on a word:
Insert a character
Delete a character
Replac... | {"functional": "def check(candidate):\n assert candidate(word1 = \"horse\", word2 = \"ros\") == 3\n assert candidate(word1 = \"intention\", word2 = \"execution\") == 5\n\n\ncheck(Solution().minDistance)"} | 100 | 58 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer array arr. You can choose a set of integers and remove all the occurrences of these integers in the array.
Return the minimum size of the set so that at least half of the integers of the array... | {"functional": "def check(candidate):\n assert candidate(arr = [3,3,3,3,5,5,5,2,2,7]) == 2\n assert candidate(arr = [7,7,7,7,7,7]) == 1\n\n\ncheck(Solution().minSetSize)"} | 97 | 72 |
coding | Solve the programming task below in a Python markdown code block.
You have an array $a$ of size $n$ consisting only of zeroes and ones. You can do the following operation:
choose two indices $1 \le i , j \le n$, $i \ne j$,
add $a_{i}$ to $a_{j}$,
remove $a_{i}$ from $a$.
Note that elements of $a$ can become bigger ... | {"inputs": ["4\n8\n0 0 1 1 1 1 1 1\n5\n1 0 0 1 1\n2\n1 0\n11\n1 1 0 0 1 0 0 1 1 1 0\n"], "outputs": ["0\n1\n1\n3\n"]} | 535 | 81 |
coding | Solve the programming task below in a Python markdown code block.
Constraints
* 1 ≤ |V| ≤ 100
* 0 ≤ |E| ≤ 9900
* -2 × 107 ≤ di ≤ 2 × 107
* There are no parallel edges
* There are no self-loops
Input
An edge-weighted graph G (V, E).
|V| |E|
s0 t0 d0
s1 t1 d1
:
s|E|-1 t|E|-1 d|E|-1
|V| is the number of vertices an... | {"inputs": ["4 6\n0 1 1\n0 2 5\n1 2 3\n1 3 4\n2 3 1\n3 2 7", "4 6\n0 1 1\n0 2 5\n1 2 3\n0 3 4\n2 3 1\n3 2 7", "4 6\n0 1 1\n0 2 5\n1 2 3\n0 3 4\n2 3 1\n0 2 7", "4 6\n0 1 1\n0 2 5\n1 2 3\n0 2 4\n2 3 1\n0 2 7", "4 6\n0 1 1\n0 2 0\n1 2 2\n0 3 4\n2 3 1\n3 2 7", "4 6\n0 1 1\n0 2 5\n1 2 3\n0 3 3\n2 3 1\n3 2 7", "4 6\n0 1 1\n0... | 555 | 586 |
coding | Solve the programming task below in a Python markdown code block.
You will receive 3 points for solving this problem.
Manao is designing the genetic code for a new type of algae to efficiently produce fuel. Specifically, Manao is focusing on a stretch of DNA that encodes one protein. The stretch of DNA is represented ... | {"inputs": ["A\n", "G\n", "T\n", "C\n", "C\n", "G\n", "A\n", "T\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | 434 | 70 |
coding | Solve the programming task below in a Python markdown code block.
There are two lists of different length. The first one consists of keys, the second one consists of values. Write a function ```createDict(keys, values)``` that returns a dictionary created from keys and values. If there are not enough values, the rest o... | {"functional": "_inputs = [[[], []], [[], [1]], [['a'], []], [['a', 'b', 'c'], [1, 2, 3]], [['a', 'b', 'c', 'd', 'e'], [1, 2]], [['a', 'b'], [1, 2, 3, 4]]]\n_outputs = [[{}], [{}], [{'a': None}], [{'a': 1, 'b': 2, 'c': 3}], [{'a': 1, 'b': 2, 'c': None, 'd': None, 'e': None}], [{'a': 1, 'b': 2}]]\nimport math\ndef _deep... | 236 | 288 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed integer array nums. You can apply the following operation any number of times:
Pick any element from nums and put it at the end of nums.
The prefix sum array of nums is an array prefix of t... | {"functional": "def check(candidate):\n assert candidate(nums = [2,3,-5,4]) == 0\n assert candidate(nums = [3,-5,-2,6]) == 1\n\n\ncheck(Solution().makePrefSumNonNegative)"} | 169 | 58 |
coding | Solve the programming task below in a Python markdown code block.
# Task
Your task is to find the similarity of given sorted arrays `a` and `b`, which is defined as follows:
you take the number of elements which are present in both arrays and divide it by the number of elements which are present in at least one ar... | {"functional": "_inputs = [[[1, 2, 3], [1, 2, 3]], [[1, 2, 3], [4, 5, 6]], [[1, 2, 4, 6, 7], [2, 3, 4, 7]], [[1, 2, 6, 8, 9], [0, 1, 4, 5, 6, 8, 9]], [[0, 1, 3, 4, 5, 6, 9, 14, 15, 16, 17, 18, 19], [1, 4, 10, 12, 13, 14, 15, 16]]]\n_outputs = [[1], [0], [0.5], [0.5], [0.3125]]\nimport math\ndef _deep_eq(a, b, tol=1e-5)... | 397 | 346 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a string s, determine if it is valid.
A string s is valid if, starting with an empty string t = "", you can transform t into s after performing the following operation any number of times:
Insert string "abc" i... | {"functional": "def check(candidate):\n assert candidate(s = \"aabcbc\") == True\n assert candidate(s = \"abcabcababcc\") == True\n assert candidate(s = \"abccba\") == False\n\n\ncheck(Solution().isValid)"} | 148 | 58 |
coding | Solve the programming task below in a Python markdown code block.
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef has 3 boxes of sizes A, B, and C respectively. He puts the boxes in bags of size D (A ≤ B ≤ C ≤ D). Find the minimum number of bags Chef needs so that he... | {"inputs": ["3\n2 3 5 10\n1 2 3 5\n3 3 4 4\n"], "outputs": ["1\n2\n3\n"]} | 405 | 43 |
coding | Solve the programming task below in a Python markdown code block.
Jenny is 9 years old. She is the youngest detective in North America. Jenny is a 3rd grader student, so when a new mission comes up, she gets a code to decipher in a form of a sticker (with numbers) in her math notebook and a comment (a sentence) in her ... | {"functional": "_inputs = [[[0, 3, 5], 'I love you'], [[7, 10, 1], 'see you later'], [[29, 31, 8], 'The quick brown fox jumps over the lazy dog'], [[12, 4, 6], 'Good Morning'], [[1, 16, 21], 'A purple pig and a green donkey flew a kite in the middle of the night'], [[35, 8, 20], 'A song can make or ruin your day if you... | 304 | 526 |
coding | Solve the programming task below in a Python markdown code block.
Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game a... | {"inputs": ["2\n1 2\n1 2\n", "2\n0 2\n1 2\n", "2\n1 2\n1 2\n", "2\n46 6\n6 46\n", "2\n46 6\n6 46\n", "2\n46 6\n12 46\n", "2\n75 6\n12 46\n", "2\n75 6\n12 34\n"], "outputs": ["0\n", "0\n", "0\n", "2\n", "2\n", "1\n", "0\n", "0\n"]} | 537 | 147 |
coding | Solve the programming task below in a Python markdown code block.
International Women's Day is coming soon! Polycarp is preparing for the holiday.
There are $n$ candy boxes in the shop for sale. The $i$-th box contains $d_i$ candies.
Polycarp wants to prepare the maximum number of gifts for $k$ girls. Each gift will ... | {"inputs": ["1 2\n21\n", "1 2\n41\n", "0 2\n41\n", "0 2\n10\n", "1 2\n24\n", "1 2\n60\n", "0 2\n24\n", "0 2\n60\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | 596 | 110 |
coding | Solve the programming task below in a Python markdown code block.
We have a grid with A horizontal rows and B vertical columns, with the squares painted white. On this grid, we will repeatedly apply the following operation:
* Assume that the grid currently has a horizontal rows and b vertical columns. Choose "vertical... | {"inputs": ["2 0 3 4", "1 0 2 2", "2 0 3 0", "1 0 2 3", "2 0 3 1", "2 0 3 2", "1 0 2 1", "2 0 6 2"], "outputs": ["130\n", "3\n", "0\n", "7\n", "2\n", "10\n", "1\n", "94\n"]} | 346 | 114 |
coding | Solve the programming task below in a Python markdown code block.
Misha and Vasya participated in a Codeforces contest. Unfortunately, each of them solved only one problem, though successfully submitted it at the first attempt. Misha solved the problem that costs a points and Vasya solved the problem that costs b point... | {"inputs": ["250 250 0 0\n", "250 250 0 0\n", "146 250 0 0\n", "146 175 0 0\n", "229 175 0 0\n", "250 3500 0 0\n", "250 3500 0 0\n", "250 4386 0 0\n"], "outputs": ["Tie\n", "Tie", "Vasya\n", "Vasya\n", "Misha\n", "Vasya\n", "Vasya", "Vasya\n"]} | 401 | 164 |
coding | Solve the programming task below in a Python markdown code block.
Given two positive integers a and b, we define f(a, b) = \text{lcm}(a, b) - \gcd(a, b), where \text{lcm} denotes the [lowest common multiple] and \gcd denotes the [greatest common divisor].
Chef has a positive integer N. He wonders, what is the maximum ... | {"inputs": ["3\n3\n4\n6\n"], "outputs": ["1\n2\n4\n"]} | 517 | 24 |
coding | 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)"} | 114 | 92 |
coding | Solve the programming task below in a Python markdown code block.
Reforms continue entering Berland. For example, during yesterday sitting the Berland Parliament approved as much as n laws (each law has been assigned a unique number from 1 to n). Today all these laws were put on the table of the President of Berland, G... | {"inputs": ["2 1\n1 1\n", "2 1\n1 1\n", "2 1\n2 1\n", "2 1\n2 2\n", "4 1\n1 2 2 2\n", "4 1\n1 2 2 2\n", "4 1\n1 1 2 2\n", "4 1\n1 2 2 4\n"], "outputs": ["1 2\n", "1 2\n", "1 2\n", "1 2\n", "2 3\n", "2 3\n", "3 4\n", "2 4\n"]} | 634 | 150 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well.
Chef went to the store in order to buy one can of coke. In the store, they offer $N$ cans of coke (numbered $1$ through $N$). For each valid $i$, th... | {"inputs": ["2\n3 2 5 4 6\n1 6\n2 8\n8 10\n3 5 10 20 30\n21 20\n22 22\n23 23"], "outputs": ["8\n-1"]} | 738 | 69 |
coding | Solve the programming task below in a Python markdown code block.
Imagine that there is a group of three friends: A, B and С. A owes B 20 rubles and B owes C 20 rubles. The total sum of the debts is 40 rubles. You can see that the debts are not organized in a very optimal manner. Let's rearrange them like that: assume ... | {"inputs": ["3 0\n", "1 0\n", "3 0\n", "4 3\n1 2 1\n2 3 1\n3 1 1\n", "4 3\n1 4 1\n2 3 1\n4 2 2\n", "4 3\n1 4 1\n2 3 1\n4 2 2\n", "4 2\n1 2 1\n2 3 1\n3 1 1\n", "4 2\n1 2 1\n2 3 1\n3 1 2\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "2\n", "2\n", "1\n", "1\n"]} | 573 | 176 |
coding | Solve the programming task below in a Python markdown code block.
You are given an array $a$ consisting of $n$ integers. Let's denote monotonic renumeration of array $a$ as an array $b$ consisting of $n$ integers such that all of the following conditions are met:
$b_1 = 0$; for every pair of indices $i$ and $j$ suc... | {"inputs": ["2\n100 1\n", "2\n000 1\n", "2\n000 2\n", "2\n010 2\n", "2\n011 2\n", "2\n100 1\n", "4\n1 3 3 7\n", "4\n1 3 1 7\n"], "outputs": ["2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "4\n", "2\n"]} | 461 | 122 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer n, which indicates that there are n courses labeled from 1 to n. You are also given an array relations where relations[i] = [prevCoursei, nextCoursei], representing a prerequisite relationship... | {"functional": "def check(candidate):\n assert candidate(n = 3, relations = [[1,3],[2,3]]) == 2\n assert candidate(n = 3, relations = [[1,2],[2,3],[3,1]]) == -1\n\n\ncheck(Solution().minimumSemesters)"} | 184 | 70 |
coding | 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"]} | 756 | 66 |
coding | Solve the programming task below in a Python markdown code block.
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
There is a grid of size 10^{5} \times 10^{5}, covered completely in railway tracks. Tom is riding in a train, currently in cell (a, b), and Jerry is tied up i... | {"inputs": ["3\n1 1 2 2 2\n1 1 2 3 4\n1 1 1 0 3"], "outputs": ["YES\nNO\nYES"]} | 548 | 46 |
coding | Solve the programming task below in a Python markdown code block.
problem
Given the squares of $ R * C $. Each square is either an empty square or a square with a hole. The given square meets the following conditions.
* The cells with holes are connected. (You can move a square with a hole in the cross direction to a... | {"inputs": ["3 5\n.....\n.#.#.\n.###.\n.#.#.\n.....", "3 1\n.....\n.#.#.\n.###.\n.#.#.\n.....", "2 5\n.....\n.#.#.\n.###.\n.#.#.\n.....", "4 2\n.....\n.#.#/\n.###.\n.#.#.\n.....", "0 1\n.....\n.#.#.\n.###.\n.#.#.\n.....", "4 1\n.....\n.#.#.\n.###.\n.#.#.\n.....", "0 1\n.....\n.#.#.\n.##\".\n.#.#.\n.....", "2 1\n.....\n... | 230 | 215 |
coding | Solve the programming task below in a Python markdown code block.
At the annual meeting of Board of Directors of Acme Inc. If everyone attending shakes hands exactly one time with every other attendee, how many handshakes are there?
Example
$n=3$
There are $3$ attendees, ${p1}$, $p2$ and $p3$. ${p1}$ shakes han... | {"inputs": ["2\n1\n2\n"], "outputs": ["0\n1\n"]} | 280 | 20 |
coding | Solve the programming task below in a Python markdown code block.
You are given a permutation $p_1, p_2, \ldots, p_n$ of length $n$. You have to choose two integers $l,r$ ($1 \le l \le r \le n$) and reverse the subsegment $[l,r]$ of the permutation. The permutation will become $p_1,p_2, \dots, p_{l-1},p_r,p_{r-1}, \dot... | {"inputs": ["4\n1\n1\n3\n2 1 3\n4\n1 4 2 3\n5\n1 2 3 4 5\n"], "outputs": ["1 \n1 2 3 \n1 2 4 3 \n1 2 3 4 5 \n"]} | 658 | 76 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a zero-based permutation nums (0-indexed), build an array ans of the same length where ans[i] = nums[nums[i]] for each 0 <= i < nums.length and return it.
A zero-based permutation nums is an array of distinct in... | {"functional": "def check(candidate):\n assert candidate(nums = [0,2,1,5,3,4]) == [0,1,2,4,5,3]\n assert candidate(nums = [5,0,1,2,3,4]) == [4,5,0,1,2,3]\n\n\ncheck(Solution().buildArray)"} | 114 | 85 |
coding | Solve the programming task below in a Python markdown code block.
A hero is on his way to the castle to complete his mission. However, he's been told that the castle is surrounded with a couple of powerful dragons! each dragon takes 2 bullets to be defeated, our hero has no idea how many bullets he should carry.. Assum... | {"functional": "_inputs = [[10, 5], [7, 4], [4, 5], [100, 40], [1500, 751], [0, 1]]\n_outputs = [[True], [False], [False], [True], [False], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isin... | 125 | 210 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array arr of 4 digits, find the latest 24-hour time that can be made using each digit exactly once.
24-hour times are formatted as "HH:MM", where HH is between 00 and 23, and MM is between 00 and 59. The earl... | {"functional": "def check(candidate):\n assert candidate(arr = [1,2,3,4]) == \"23:41\"\n assert candidate(arr = [5,5,5,5]) == \"\"\n assert candidate(arr = [0,0,0,0]) == \"00:00\"\n assert candidate(arr = [0,0,1,0]) == \"10:00\"\n\n\ncheck(Solution().largestTimeFromDigits)"} | 168 | 109 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array of integers preorder, which represents the preorder traversal of a BST (i.e., binary search tree), construct the tree and return its root.
It is guaranteed that there is always possible to find a binary... | {"functional": "def check(candidate):\n assert is_same_tree(candidate(preorder = [8,5,1,7,10,12]), tree_node([8,5,10,1,7,None,12]))\n\n\ncheck(Solution().bstFromPreorder)"} | 227 | 65 |
coding | Solve the programming task below in a Python markdown code block.
Burenka and Tonya are playing an old Buryat game with a chip on a board of $n \times m$ cells.
At the beginning of the game, the chip is located in the lower left corner of the board. In one move, the player can move the chip to the right or up by any o... | {"inputs": ["6\n1 1\n1 4\n5 6\n2 2\n6 3\n999999999 1000000000\n"], "outputs": ["Tonya\nBurenka\nBurenka\nTonya\nBurenka\nBurenka\n"]} | 549 | 75 |
coding | Solve the programming task below in a Python markdown code block.
Emily and Mia are friends. Emily got Mia’s essay paper, but since she is a prankster, she decided to meddle with the words present in the paper. She changes all the words in the paper into palindromes. To do this, she follows two rules:
- In one operati... | {"inputs": ["4\nabc\nabcba\nabcd\ncba"], "outputs": ["2\n0\n4\n2"]} | 340 | 28 |
coding | Solve the programming task below in a Python markdown code block.
Hanuman has been a great admirer of Ram. However, there is one thing that Hanuman finds really difficult when talking to Ram. Hanuman can only understand sentences in reverse order but Ram,though an incarnation of God,is somehow unable to speak in revers... | {"inputs": ["9\nI have always been fond of you, Hanuman\nSpacelessSentence\nHello how are ou?\n.\na . gg\nt t his is a random sentence\nabcdef\nreverse me please\ntestcase 1"], "outputs": ["Hanuman you, of fond been always have I \nSpacelessSentence \nou? are how Hello \n. \ngg . a \nsentence random a is his t t \nabcd... | 216 | 108 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an n x n binary matrix grid. You are allowed to change at most one 0 to be 1.
Return the size of the largest island in grid after applying this operation.
An island is a 4-directionally connected group o... | {"functional": "def check(candidate):\n assert candidate(grid = [[1,0],[0,1]]) == 3\n assert candidate(grid = [[1,1],[1,0]]) == 4\n assert candidate(grid = [[1,1],[1,1]]) == 4\n\n\ncheck(Solution().largestIsland)"} | 105 | 75 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a string expression representing an expression of fraction addition and subtraction, return the calculation result in string format.
The final result should be an irreducible fraction. If your final result is an... | {"functional": "def check(candidate):\n assert candidate(expression = \"-1/2+1/2\") == \"0/1\"\n assert candidate(expression = \"-1/2+1/2+1/3\") == \"1/3\"\n assert candidate(expression = \"1/3-1/2\") == \"-1/6\"\n\n\ncheck(Solution().fractionAddition)"} | 118 | 90 |
coding | Solve the programming task below in a Python markdown code block.
Today is Chef's birthday. His mom decided to surprise him with a truly fantastic gift: his favourite binary string B. But, unfortunately, all the stocks of binary string B have been sold out, and only a binary string A (A ≠ B) is available in the market.... | {"inputs": ["2\n101\n010\n1111\n1010", "2\n101\n011\n1111\n1010", "2\n001\n111\n1111\n1010", "2\n111\n110\n1111\n1010", "2\n110\n110\n1111\n1010", "2\n110\n110\n1011\n1010", "2\n010\n110\n0011\n1010", "2\n000\n110\n0011\n1010"], "outputs": ["Lucky Chef\n2\nUnlucky Chef", "Lucky Chef\n1\nUnlucky Chef\n", "Lucky Chef\n2\... | 693 | 278 |
coding | Solve the programming task below in a Python markdown code block.
You are given a string S consisting of lowercase English letters.
Another string T is initially empty.
Determine whether it is possible to obtain S = T by performing the following operation an arbitrary number of times:
- Append one of the following at ... | {"inputs": ["dreamerer\n", "erasedream\n", "dreameraser\n"], "outputs": ["NO\n", "YES\n", "YES\n"]} | 171 | 35 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed array nums and a non-negative integer k.
In one operation, you can do the following:
Choose an index i that hasn't been chosen before from the range [0, nums.length - 1].
Replace nums[i] wit... | {"functional": "def check(candidate):\n assert candidate(nums = [4,6,1,2], k = 2) == 3\n assert candidate(nums = [1,1,1,1], k = 10) == 4\n\n\ncheck(Solution().maximumBeauty)"} | 206 | 66 |
coding | Solve the programming task below in a Python markdown code block.
This year $p$ footballers and $q$ cricketers have been invited to participate in IPL (Indian Programming League) as guests. You have to accommodate them in $r$ rooms such that-
- No room may remain empty.
- A room may contain either only footballers or o... | {"inputs": ["4\n2 1 4\n2 4 4\n2 5 4\n2 8 4"], "outputs": ["0\n3\n10\n609"]} | 479 | 45 |
coding | Solve the programming task below in a Python markdown code block.
$\textit{ABC}$ is a right triangle, $90^{\circ}$ at $\mbox{B}$.
Therefore, $\angle ABC=90°$.
Point $\mbox{M}$ is the midpoint of hypotenuse $\mbox{AC}$.
You are given the lengths $\boldsymbol{AB}$ and $\mbox{BC}$.
Your task is to find $\measuredangl... | {"inputs": ["10\n10\n"], "outputs": ["45\u00b0\n"]} | 334 | 24 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given the root of a binary tree, return the sum of values of nodes with an even-valued grandparent. If there are no nodes with an even-valued grandparent, return 0.
A grandparent of a node is the parent of its parent ... | {"functional": "def check(candidate):\n assert candidate(root = tree_node([6,7,8,2,7,1,3,9,None,1,4,None,None,None,5])) == 18\n\n\ncheck(Solution().sumEvenGrandparent)"} | 157 | 60 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.