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.
Consider an N \times M binary matrix A, i.e. a grid consisting of N rows numbered 1 to N from top to bottom and M columns numbered 1 to M from left to right, whose cells take the value 0 or 1. Let (i, j) denote the cell on the i-th row and j-th column.
... | {"inputs": ["2\n3 3\n4 5"], "outputs": ["5\n10"]} | coding | 439 |
Solve the programming task below in a Python markdown code block.
A new agent called Killjoy invented a virus COVID-2069 that infects accounts on Codeforces. Each account has a rating, described by an integer (it can possibly be negative or very large).
Killjoy's account is already infected and has a rating equal to $... | {"inputs": ["1\n2 2\n0 5\n", "1\n2 2\n0 5\n", "1\n2 2\n0 8\n", "1\n2 2\n0 0\n", "1\n2 2\n1 8\n", "1\n2 4\n0 0\n", "1\n2 1\n0 0\n", "1\n2 2\n-1 0\n"], "outputs": ["2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n"]} | coding | 632 |
Solve the programming task below in a Python markdown code block.
How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
-----Constraints-----
- 1≤M≤23
- M is an integer.
-----Input-----
Input is given from Standard Input in the following format:
M
-----Output-----
If we have x... | {"inputs": ["9", "8", "0", "4", "1", "2", "3", "5"], "outputs": ["39\n", "40\n", "48\n", "44\n", "47\n", "46\n", "45\n", "43\n"]} | coding | 137 |
Solve the programming task below in a Python markdown code block.
Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well.
Chef has a *tasty ingredient* ― an integer $K$. He defines a *tasty matrix* $A$ with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ throug... | {"inputs": ["2\n2 2 5\n2 3 7"], "outputs": ["14\n5"]} | coding | 654 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
A subarray of a 0-indexed integer array is a contiguous non-empty sequence of elements within an array.
The alternating subarray sum of a subarray that ranges from index i to j (inclusive, 0 <= i <= j < nums.length) i... | {"functional": "def check(candidate):\n assert candidate(nums = [3,-1,1,2]) == 5\n assert candidate(nums = [2,2,2,2,2]) == 2\n assert candidate(nums = [1]) == 1\n\n\ncheck(Solution().maximumAlternatingSubarraySum)"} | coding | 150 |
Solve the programming task below in a Python markdown code block.
Create a __moreZeros__ function which will __receive a string__ for input, and __return an array__ (or null terminated string in C) containing only the characters from that string whose __binary representation of its ASCII value__ consists of _more zeros... | {"functional": "_inputs = [['abcde'], ['thequickbrownfoxjumpsoverthelazydog'], ['THEQUICKBROWNFOXJUMPSOVERTHELAZYDOG'], ['abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_'], ['DIGEST'], ['abcdabcd'], ['Forgiveness is the fragrance that the violet sheds on the heal that has crushed it']]\n_outputs = [[['a... | coding | 157 |
Solve the programming task below in a Python markdown code block.
Consider a sequence of n numbers using integers from 0 to 9 k1, k2, ..., kn. Read the positive integers n and s,
k1 + 2 x k2 + 3 x k3 + ... + n x kn = s
Create a program that outputs how many rows of n numbers such as. However, the same number does not... | {"inputs": ["2 9\n3 1", "2 0\n2 1", "2 1\n2 1", "2 3\n2 2", "3 7\n0 1", "6 9\n3 1", "2 0\n6 1", "6 9\n6 1"], "outputs": ["4\n0\n", "0\n1\n", "1\n1\n", "1\n2\n", "6\n0\n", "0\n0\n", "0\n0\n", "0\n0\n"]} | coding | 202 |
Solve the programming task below in a Python markdown code block.
Chef considers an array *good* if it has no subarray of size less than N such that the [GCD] of all the elements of the subarray is equal to 1.
Chef has an array A of size N with him. He wants to convert it into a *good* array by applying a specific op... | {"inputs": ["3\n3\n3 2 6\n4\n3 2 4 8\n4\n6 15 9 18\n "], "outputs": ["1\n2 3\n-1\n0\n"]} | coding | 661 |
Solve the programming task below in a Python markdown code block.
You are given array consisting of n integers. Your task is to find the maximum length of an increasing subarray of the given array.
A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this su... | {"inputs": ["1\n1\n", "1\n1\n", "2\n2 1\n", "2\n1 2\n", "2\n1 2\n", "2\n2 1\n", "2\n1 4\n", "2\n2 2\n"], "outputs": ["1\n", "1\n", "1\n", "2\n", "2\n", "1\n", "2\n", "1\n"]} | coding | 217 |
Solve the programming task below in a Python markdown code block.
A lot of people associate Logo programming language with turtle graphics. In this case the turtle moves along the straight line and accepts commands "T" ("turn around") and "F" ("move 1 unit forward").
You are given a list of commands that will be given... | {"inputs": ["F\n1\n", "FT\n1\n", "TTFFF\n49\n", "FFFTFFF\n3\n", "FFFTFFF\n2\n", "FFFFTFTF\n1\n", "FTTTFTFF\n8\n", "FFFFTFTF\n0\n"], "outputs": ["0\n", "2\n", "4\n", "7\n", "6\n", "5\n", "8\n", "4\n"]} | coding | 323 |
Solve the programming task below in a Python markdown code block.
You are given a valid XML document, and you have to print the maximum level of nesting in it. Take the depth of the root as $\mbox{0}$.
Input Format
The first line contains $N$, the number of lines in the XML document.
The next $N$ lines follow conta... | {"inputs": ["6\n<feed xml:lang='en'>\n <title>HackerRank</title>\n <subtitle lang='en'>Programming challenges</subtitle>\n <link rel='alternate' type='text/html' href='http://hackerrank.com/'/>\n <updated>2013-12-25T12:00:00</updated>\n</feed>\n"], "outputs": ["1\n"]} | coding | 250 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
A city's skyline is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return the skyline formed by these bu... | {"functional": "def check(candidate):\n assert candidate(buildings = [[2,9,10],[3,7,15],[5,12,12],[15,20,10],[19,24,8]]) == [[2,10],[3,15],[7,12],[12,0],[15,10],[20,8],[24,0]]\n assert candidate(buildings = [[0,2,3],[2,5,3]]) == [[0,3],[5,0]]\n\n\ncheck(Solution().getSkyline)"} | coding | 366 |
Solve the programming task below in a Python markdown code block.
Polycarp wants to buy exactly $n$ shovels. The shop sells packages with shovels. The store has $k$ types of packages: the package of the $i$-th type consists of exactly $i$ shovels ($1 \le i \le k$). The store has an infinite number of packages of each t... | {"inputs": ["1\n8 2\n", "1\n8 2\n", "1\n91 5\n", "1\n49 3\n", "1\n91 5\n", "1\n49 3\n", "1\n14 2\n", "1\n49 6\n"], "outputs": ["4\n", "4\n", "91\n", "49\n", "91\n", "49\n", "7\n", "49\n"]} | coding | 521 |
Solve the programming task below in a Python markdown code block.
There is a pond with a rectangular shape.
The pond is divided into a grid with H rows and W columns of squares.
We will denote the square at the i-th row from the top and j-th column from the left by (i,\ j).
Some of the squares in the pond contains a lo... | {"inputs": ["2 2\nST\n..\n", "2 2\nS.\nT.\n", "2 2\nS.\n.T\n", "2 2\nSo\noT\n", "2 3\nS.o\n.o.\no.T", "3 3\nS.o\n.o.\noT.", "2 3\nS.o\n.o.\no.S", "2 3\nS.p\n.o.\no.S"], "outputs": ["-1\n", "-1\n", "0\n", "2\n", "0\n", "1\n", "0\n", "0\n"]} | coding | 407 |
Solve the programming task below in a Python markdown code block.
-----
CHEF N TIMINGS
-----
One day chef was working with some random numbers. Then he found something
interesting. He observed that no 240, 567, 9999 and 122 and called these numbers
nice as the digits in numbers are in increasing order. Also he called ... | {"inputs": ["1\n132"], "outputs": ["129"]} | coding | 244 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
There is an integer array nums sorted in ascending order (with distinct values).
Prior to being passed to your function, nums is possibly rotated at an unknown pivot index k (1 <= k < nums.length) such that the result... | {"functional": "def check(candidate):\n assert candidate(nums = [4,5,6,7,0,1,2], target = 0) == 4\n assert candidate(nums = [4,5,6,7,0,1,2], target = 3) == -1\n assert candidate(nums = [1], target = 0) == -1\n\n\ncheck(Solution().search)"} | coding | 222 |
Solve the programming task below in a Python markdown code block.
Long long ago, there was a thief. Looking for treasures, he was running about all over the world. One day, he heard a rumor that there were islands that had large amount of treasures, so he decided to head for there.
Finally he found n islands that had ... | {"inputs": ["3\n2 3\n3 6\n1 2\n3\n2 3\n3 5\n2 2\n0", "3\n2 3\n3 6\n2 2\n3\n3 3\n3 6\n2 2\n0", "3\n2 1\n3 6\n1 2\n3\n2 3\n3 5\n0 2\n0", "3\n4 5\n3 8\n1 2\n0\n7 3\n3 5\n2 1\n0", "3\n2 3\n3 6\n1 2\n3\n0 3\n3 5\n1 2\n0", "3\n2 3\n3 6\n1 2\n3\n3 3\n3 5\n2 2\n0", "3\n2 3\n3 6\n1 2\n3\n3 3\n3 6\n2 2\n0", "3\n2 3\n3 8\n2 2\n3\... | coding | 377 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a phone number as a string number. number consists of digits, spaces ' ', and/or dashes '-'.
You would like to reformat the phone number in a certain manner. Firstly, remove all spaces and dashes. Then, ... | {"functional": "def check(candidate):\n assert candidate(number = \"1-23-45 6\") == \"123-456\"\n assert candidate(number = \"123 4-567\") == \"123-45-67\"\n assert candidate(number = \"123 4-5678\") == \"123-456-78\"\n assert candidate(number = \"12\") == \"12\"\n assert candidate(number = \"--17-5 229 ... | coding | 202 |
Solve the programming task below in a Python markdown code block.
As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a subsequence. Help Heidi assess wheth... | {"inputs": ["hiedi\n", "ihied\n", "diehi\n", "deiih\n", "iheid\n", "eihdi\n", "ehdii\n", "edhii\n"], "outputs": ["NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO"]} | coding | 192 |
Solve the programming task below in a Python markdown code block.
Yaroslav has an array, consisting of (2·n - 1) integers. In a single operation Yaroslav can change the sign of exactly n elements in the array. In other words, in one operation Yaroslav can select exactly n array elements, and multiply each of them by -1... | {"inputs": ["2\n-1 -1 1\n", "2\n-1 -1 1\n", "2\n-1 -1 0\n", "2\n50 50 50\n", "2\n50 50 63\n", "2\n-1 -1 -1\n", "2\n50 98 63\n", "2\n50 50 50\n"], "outputs": ["3\n", "3\n", "2\n", "150\n", "163\n", "1\n", "211\n", "150\n"]} | coding | 291 |
Solve the programming task below in a Python markdown code block.
You are given an array of positive integers. While there are at least two equal elements, we will perform the following operation. We choose the smallest value $x$ that occurs in the array $2$ or more times. Take the first two occurrences of $x$ in this ... | {"inputs": ["5\n1 1 3 1 1\n", "5\n1 1 5 1 1\n", "5\n1 1 3 1 1\n", "5\n1 1 30 34 11\n", "7\n3 4 1 2 2 1 1\n", "7\n1 4 1 2 2 1 1\n", "7\n1 4 1 2 1 1 1\n", "7\n1 4 1 3 1 1 1\n"], "outputs": ["2\n3 4 \n", "2\n5 4 ", "2\n3 4 ", "4\n2 30 34 11 ", "4\n3 8 2 1 \n", "2\n8 4 ", "3\n8 2 1 ", "3\n3 8 1 "]} | coding | 592 |
Solve the programming task below in a Python markdown code block.
Alas, finding one's true love is not easy. Masha has been unsuccessful in that yet. Her friend Dasha told Masha about a way to determine the phone number of one's Prince Charming through arithmancy.
The phone number is divined like that. First one need... | {"inputs": ["3\n", "2\n", "0\n", "1\n", "4\n", "55\n", "15\n", "09\n"], "outputs": ["9\n", "9\n", "9\n", "9\n", "9\n", "14\n", "15\n", "15\n"]} | coding | 554 |
Solve the programming task below in a Python markdown code block.
###Instructions
A time period starting from ```'hh:mm'``` lasting until ```'hh:mm'``` is stored in an array:
```
['08:14', '11:34']
```
A set of different time periods is then stored in a 2D Array like so, each in its own sub-array:
```
[['08:14','11:34... | {"functional": "_inputs = [[[['08:14', '11:34'], ['08:16', '08:18'], ['13:48', '01:14'], ['09:30', '10:32'], ['04:23', '05:11'], ['11:48', '13:48'], ['01:12', '01:14'], ['01:13', '08:15']]], [[['00:00', '00:05'], ['16:37', '18:19'], ['12:07', '12:12'], ['00:30', '02:49'], ['12:12', '12:14'], ['12:14', '15:00'], ['15:00... | coding | 556 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Special binary strings are binary strings with the following two properties:
The number of 0's is equal to the number of 1's.
Every prefix of the binary string has at least as many 1's as 0's.
You are given a specia... | {"functional": "def check(candidate):\n assert candidate(s = \"11011000\") == \"11100100\"\n assert candidate(s = \"10\") == \"10\"\n\n\ncheck(Solution().makeLargestSpecial)"} | coding | 169 |
Solve the programming task below in a Python markdown code block.
n participants of the competition were split into m teams in some manner so that each team has at least one participant. After the competition each pair of participants from the same team became friends.
Your task is to write a program that will find th... | {"inputs": ["5 1\n", "3 2\n", "6 3\n", "5 3\n", "1 1\n", "2 1\n", "2 2\n", "1 1\n"], "outputs": ["10 10\n", "1 1\n", "3 6\n", "2 3\n", "0 0\n", "1 1\n", "0 0\n", "0 0\n"]} | coding | 322 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer n denoting the number of cities in a country. The cities are numbered from 0 to n - 1.
You are also given a 2D integer array roads where roads[i] = [ai, bi] denotes that there exists a bidirec... | {"functional": "def check(candidate):\n assert candidate(n = 5, roads = [[0,1],[1,2],[2,3],[0,2],[1,3],[2,4]]) == 43\n assert candidate(n = 5, roads = [[0,3],[2,4],[1,3]]) == 20\n\n\ncheck(Solution().maximumImportance)"} | coding | 180 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer num, return three consecutive integers (as a sorted array) that sum to num. If num cannot be expressed as the sum of three consecutive integers, return an empty array.
Please complete the following ... | {"functional": "def check(candidate):\n assert candidate(num = 33) == [10,11,12]\n assert candidate(num = 4) == []\n\n\ncheck(Solution().sumOfThree)"} | coding | 87 |
Solve the programming task below in a Python markdown code block.
Find the sum of weights of edges of the Minimum Spanning Tree for a given weighted undirected graph G = (V, E).
Constraints
* 1 ≤ |V| ≤ 10,000
* 0 ≤ |E| ≤ 100,000
* 0 ≤ wi ≤ 10,000
* The graph is connected
* There are no parallel edges
* There are no s... | {"inputs": ["4 6\n0 1 2\n1 2 1\n2 3 1\n3 0 1\n0 2 1\n1 3 5", "4 6\n0 1 2\n1 2 1\n0 3 0\n3 0 1\n0 2 1\n1 3 5", "4 6\n0 1 2\n1 2 1\n2 3 1\n3 0 1\n0 2 1\n1 1 5", "4 6\n0 1 2\n1 2 1\n0 3 1\n3 0 1\n0 2 1\n1 3 5", "4 6\n0 1 2\n1 2 1\n2 0 1\n3 0 1\n0 2 1\n1 1 5", "4 6\n0 1 2\n1 2 1\n2 0 1\n3 0 1\n0 2 3\n1 3 5", "4 6\n0 1 2\n1... | coding | 348 |
Solve the programming task below in a Python markdown code block.
Takahashi is standing on a two-dimensional plane, facing north. Find the minimum positive integer K such that Takahashi will be at the starting position again after he does the following action K times:
* Go one meter in the direction he is facing. Then... | {"inputs": ["2", "4", "3", "5", "8", "6", "1", "33"], "outputs": ["180\n", "90\n", "120\n", "72\n", "45\n", "60\n", "360", "120\n"]} | coding | 155 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
A decimal number can be converted to its Hexspeak representation by first converting it to an uppercase hexadecimal string, then replacing all occurrences of the digit '0' with the letter 'O', and the digit '1' with t... | {"functional": "def check(candidate):\n assert candidate(num = \"257\") == \"IOI\"\n assert candidate(num = \"3\") == \"ERROR\"\n\n\ncheck(Solution().toHexspeak)"} | coding | 170 |
Solve the programming task below in a Python markdown code block.
Diameter of a Tree
Given a tree T with non-negative weight, find the diameter of the tree.
The diameter of a tree is the maximum distance between two nodes in a tree.
Constraints
* 1 ≤ n ≤ 100,000
* 0 ≤ wi ≤ 1,000
Input
n
s1 t1 w1
s2 t2 w2
:
sn... | {"inputs": ["4\n0 1 1\n1 3 2\n2 3 4", "4\n0 1 1\n1 2 1\n1 3 3", "4\n0 1 2\n1 3 2\n2 3 4", "4\n0 1 1\n1 3 1\n2 3 4", "4\n0 1 1\n1 3 0\n2 3 4", "4\n0 1 1\n1 3 1\n2 3 0", "4\n0 1 0\n2 2 2\n2 3 4", "4\n0 1 2\n1 3 1\n2 3 0"], "outputs": ["7\n", "4\n", "8\n", "6\n", "5\n", "2\n", "0\n", "3\n"]} | coding | 252 |
Solve the programming task below in a Python markdown code block.
*CodeChef recently revamped its [practice page] to make it easier for users to identify the next problems they should solve by introducing some new features:*
*Recent Contest Problems - contains only problems from the last 2 contests*
*Separate Un-Attem... | {"inputs": ["10 4", "10 10", "500 1", "1000 990"], "outputs": ["6", "0", "499", "10"]} | coding | 566 |
Solve the programming task below in a Python markdown code block.
Chef and his competitor Kefa own two restaurants located at a straight road. The position of Chef's restaurant is $X_1$, the position of Kefa's restaurant is $X_2$.
Chef and Kefa found out at the same time that a bottle with a secret recipe is located on... | {"inputs": ["3\n1 3 2 1 2\n1 5 2 1 2\n1 5 3 2 2"], "outputs": ["Kefa\nChef\nDraw"]} | coding | 462 |
Solve the programming task below in a Python markdown code block.
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well.
It is well-known that if you become rich, you will have a lot of trouble. Coach Khaled is one of the richest men in the world. He has $N$ jewels (nu... | {"inputs": ["1\n4 4\n1 2 4 3\n1 3\n3 4\n1 2\n2 3"], "outputs": ["4"]} | coding | 725 |
Solve the programming task below in a Python markdown code block.
Iahub got lost in a very big desert. The desert can be represented as a n × n square matrix, where each cell is a zone of the desert. The cell (i, j) represents the cell at row i and column j (1 ≤ i, j ≤ n). Iahub can go from one cell (i, j) only down or... | {"inputs": ["2 1\n1 2\n", "2 1\n2 2\n", "2 1\n2 2\n", "2 1\n2 2\n", "2 1\n1 2\n", "12 1\n7 4\n", "12 1\n7 4\n", "12 1\n12 4\n"], "outputs": ["2\n", "-1\n", "-1\n", "-1\n", "2\n", "22\n", "22\n", "22\n"]} | coding | 507 |
Solve the programming task below in a Python markdown code block.
Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the serve... | {"inputs": ["2\n1 5 5\n2 6 4\n", "2\n1 5 5\n2 8 4\n", "2\n1 5 5\n2 8 6\n", "2\n1 5 5\n2 6 6\n", "2\n1 5 5\n2 1 6\n", "2\n1 5 3\n2 1 6\n", "2\n1 5 5\n2 8 8\n", "2\n1 5 3\n2 1 7\n"], "outputs": ["LIVE\nLIVE\n", "LIVE\nLIVE\n", "LIVE\nLIVE\n", "LIVE\nLIVE\n", "LIVE\nDEAD\n", "LIVE\nDEAD\n", "LIVE\nLIVE\n", "LIVE\nDEAD\n"]... | coding | 703 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array of digits digits, return the largest multiple of three that can be formed by concatenating some of the given digits in any order. If there is no answer return an empty string.
Since the answer may not f... | {"functional": "def check(candidate):\n assert candidate(digits = [8,1,9]) == \"981\"\n assert candidate(digits = [8,6,7,1,0]) == \"8760\"\n assert candidate(digits = [1]) == \"\"\n assert candidate(digits = [0,0,0,0,0,0]) == \"0\"\n\n\ncheck(Solution().largestMultipleOfThree)"} | coding | 120 |
Solve the programming task below in a Python markdown code block.
A number is called 2050-number if it is $2050$, $20500$, ..., ($2050 \cdot 10^k$ for integer $k \ge 0$).
Given a number $n$, you are asked to represent $n$ as the sum of some (not necessarily distinct) 2050-numbers. Compute the minimum number of 2050-nu... | {"inputs": ["1\n1\n", "1\n1\n", "1\n62\n", "1\n57\n", "1\n68\n", "1\n12\n", "1\n10\n", "1\n22\n"], "outputs": ["-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n"]} | coding | 347 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given the root of a full binary tree with the following properties:
Leaf nodes have either the value 0 or 1, where 0 represents False and 1 represents True.
Non-leaf nodes have either the value 2 or 3, where ... | {"functional": "def check(candidate):\n assert candidate(root = tree_node([2,1,3,None,None,0,1])) == True\n assert candidate(root = tree_node([0])) == False\n\n\ncheck(Solution().evaluateTree)"} | coding | 263 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a string s of lower and upper case English letters.
A good string is a string which doesn't have two adjacent characters s[i] and s[i + 1] where:
0 <= i <= s.length - 2
s[i] is a lower-case letter and s[i + 1] ... | {"functional": "def check(candidate):\n assert candidate(s = \"leEeetcode\") == \"leetcode\"\n assert candidate(s = \"abBAcC\") == \"\"\n assert candidate(s = \"s\") == \"s\"\n\n\ncheck(Solution().makeGood)"} | coding | 183 |
Solve the programming task below in a Python markdown code block.
You are given two integers $n$ and $m$. Calculate the number of pairs of arrays $(a, b)$ such that:
the length of both arrays is equal to $m$; each element of each array is an integer between $1$ and $n$ (inclusive); $a_i \le b_i$ for any index $i$ ... | {"inputs": ["2 2\n", "1 1\n", "1 2\n", "1 2\n", "1 1\n", "7 7\n", "2 3\n", "9 1\n"], "outputs": ["5\n", "1\n", "1\n", "1\n", "1\n", "38760\n", "7\n", "45\n"]} | coding | 375 |
Solve the programming task below in a Python markdown code block.
There are two types of burgers in your restaurant — hamburgers and chicken burgers! To assemble a hamburger you need two buns and a beef patty. To assemble a chicken burger you need two buns and a chicken cutlet.
You have $b$ buns, $p$ beef patties and... | {"inputs": ["1\n0 4 4\n3 0\n", "1\n0 0 4\n3 0\n", "1\n0 0 4\n2 0\n", "1\n0 0 3\n2 0\n", "1\n1 0 3\n2 0\n", "1\n1 0 1\n2 0\n", "1\n1 0 1\n3 0\n", "1\n1 0 1\n4 0\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | coding | 435 |
Solve the programming task below in a Python markdown code block.
MoEngage goes shopping with Chef. There are N ingredients placed on a line, numbered 1 to N from left to right.
At any point in time, MoEngage can choose the ingredient numbered x and do one of the following operations:
If the chosen ingredient is not t... | {"inputs": ["3\n1\n3\n4\n4\n2 1 3 2\n4 2 4 3\n7\n3 10 5 2 8 3 9\n8 6 11 5 9 13 7\n"], "outputs": ["0\n5\n32\n"]} | coding | 759 |
Solve the programming task below in a Python markdown code block.
You are given positive integer number n. You should create such strictly increasing sequence of k positive numbers a_1, a_2, ..., a_{k}, that their sum is equal to n and greatest common divisor is maximal.
Greatest common divisor of sequence is maximum ... | {"inputs": ["6 3\n", "8 2\n", "5 3\n", "1 1\n", "1 2\n", "2 1\n", "5 1\n", "6 2\n"], "outputs": ["1 2 3\n", "2 6\n", "-1\n", "1\n", "-1\n", "2\n", "5\n", "2 4\n"]} | coding | 188 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an m x n integer matrix matrix with the following two properties:
Each row is sorted in non-decreasing order.
The first integer of each row is greater than the last integer of the previous row.
Given a... | {"functional": "def check(candidate):\n assert candidate(matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 3) == True\n assert candidate(matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 13) == False\n\n\ncheck(Solution().searchMatrix)"} | coding | 127 |
Solve the programming task below in a Python markdown code block.
The semester is already ending, so Danil made an effort and decided to visit a lesson on harmony analysis to know how does the professor look like, at least. Danil was very bored on this lesson until the teacher gave the group a simple task: find 4 vecto... | {"inputs": ["2\n", "1\n", "3\n", "0\n", "4\n", "2\n", "4\n", "1\n"], "outputs": ["++++\n+*+*\n++**\n+**+\n", "++\n+*\n", "++++++++\n+*+*+*+*\n++**++**\n+**++**+\n++++****\n+*+**+*+\n++****++\n+**+*++*\n", "+\n", "++++++++++++++++\n+*+*+*+*+*+*+*+*\n++**++**++**++**\n+**++**++**++**+\n++++****++++****\n+*+**+*++*+**+*+\... | coding | 721 |
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"]} | coding | 401 |
Solve the programming task below in a Python markdown code block.
Given a string, return the minimal number of parenthesis reversals needed to make balanced parenthesis.
For example:
```Javascript
solve(")(") = 2 Because we need to reverse ")" to "(" and "(" to ")". These are 2 reversals.
solve("(((())") = 1 We need... | {"functional": "_inputs = [[')()('], ['((()'], ['((('], ['())((('], ['())()))))()()(']]\n_outputs = [[2], [1], [-1], [3], [4]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple... | coding | 152 |
Solve the programming task below in a Python markdown code block.
You are given a square grid with $n$ rows and $n$ columns. Each cell contains either $0$ or $1$.
In an operation, you can select a cell of the grid and flip it (from $0 \to 1$ or $1 \to 0$). Find the minimum number of operations you need to obtain a squ... | {"inputs": ["5\n3\n010\n110\n010\n1\n0\n5\n11100\n11011\n01011\n10011\n11000\n5\n01000\n10101\n01010\n00010\n01001\n5\n11001\n00000\n11111\n10110\n01111\n"], "outputs": ["1\n0\n9\n7\n6\n"]} | coding | 536 |
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 rearrange the elements of nums to any order (including the given order).
Let prefix be the array containing the prefix sums of nums after rearranging it. In other ... | {"functional": "def check(candidate):\n assert candidate(nums = [2,-1,0,1,-3,3,-3]) == 6\n assert candidate(nums = [-2,-3,0]) == 0\n\n\ncheck(Solution().maxScore)"} | coding | 141 |
Solve the programming task below in a Python markdown code block.
Chef bought a huge (effectively infinite) planar island and built $N$ restaurants (numbered $1$ through $N$) on it. For each valid $i$, the Cartesian coordinates of restaurant $i$ are $(X_i, Y_i)$.
Now, Chef wants to build $N-1$ straight narrow roads (li... | {"inputs": ["2\n3\n0 0\n0 1\n0 -1\n3\n0 1\n1 0\n-1 0"], "outputs": ["0.5\n0"]} | coding | 678 |
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"]} | coding | 579 |
Solve the programming task below in a Python markdown code block.
It's hard times now. Today Petya needs to score 100 points on Informatics exam. The tasks seem easy to Petya, but he thinks he lacks time to finish them all, so he asks you to help with one..
There is a glob pattern in the statements (a string consistin... | {"inputs": ["a\nab\n1\na\n", "a\na\n1\nab\n", "b\naa\n1\na\n", "c\na\n1\nab\n", "a\na\n1\nab\n", "b\naa\n1\na\n", "c\na\n1\nab\n", "a\nab\n1\na\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]} | coding | 678 |
Solve the programming task below in a Python markdown code block.
You are given a string S of length 3 consisting of a, b and c. Determine if S can be obtained by permuting abc.
-----Constraints-----
- |S|=3
- S consists of a, b and c.
-----Input-----
Input is given from Standard Input in the following format:
S
-... | {"inputs": ["bba", "cab", "abb", "aab", "aac", "bbb", "baa", "caa"], "outputs": ["No\n", "Yes\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n"]} | coding | 125 |
Solve the programming task below in a Python markdown code block.
You are given array $a$ of length $n$. You can choose one segment $[l, r]$ ($1 \le l \le r \le n$) and integer value $k$ (positive, negative or even zero) and change $a_l, a_{l + 1}, \dots, a_r$ by $k$ each (i.e. $a_i := a_i + k$ for each $l \le i \le r$... | {"inputs": ["2 1\n1 2\n", "2 1\n1 2\n", "2 0\n1 2\n", "3 2\n6 2 6\n", "3 2\n6 2 0\n", "3 2\n6 2 6\n", "1 1\n500000\n", "1 1\n500000\n"], "outputs": ["2\n", "2\n", "1\n", "2\n", "2\n", "2\n", "1\n", "1\n"]} | coding | 378 |
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"]} | coding | 499 |
Solve the programming task below in a Python markdown code block.
After his wife's tragic death, Eurydice, Orpheus descended to the realm of death to see her. Reaching its gates was uneasy, but passing through them proved to be even more challenging. Mostly because of Cerberus, the three-headed hound of Hades.
Orpheus... | {"inputs": ["7\nbabba\nabaac\ncodeforces\nzeroorez\nabcdcba\nbbbbbbb\na\n", "7\nabbab\nabaac\ncodeforces\nzeroorez\nabcdcba\nbbbbbbb\na\n", "7\nabbab\nabaac\ncodeforces\nzeroorez\nabadcbc\nbbbbbbb\na\n", "7\nabbab\nabaac\ncodeforces\nzeroorez\nabadcbc\nbbbbabb\na\n", "7\nbbbaa\nabaac\ncodeforces\nyeroorez\nabadcbc\nbba... | coding | 619 |
Solve the programming task below in a Python markdown code block.
As you know America’s Presidential Elections are about to take place and the most popular leader of the Republican party Donald Trump is famous for throwing allegations against anyone he meets.
He goes to a rally and meets n people which he wants to off... | {"inputs": ["3\n1\n4\n2\n10 5\n4\n2 3 1 3"], "outputs": ["4\n45\n0"]} | coding | 434 |
Solve the programming task below in a Python markdown code block.
Xavier is a computer science student.He is given a task by his teacher the task is to
generate a code which accepts an array of n integers.He now has to select an integer from this array but there is a trick in selection of integer from the array.
... | {"inputs": ["6\n3 5 7 1 2 8\n3", "10\n3 5 7 1 2 8 15 20 35 55\n6"], "outputs": ["1 3 5 7", "1 3 5 7 15 35 55"]} | coding | 412 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an n x n grid representing a field of cherries, each cell is one of three possible integers.
0 means the cell is empty, so you can pass through,
1 means the cell contains a cherry that you can pick up a... | {"functional": "def check(candidate):\n assert candidate(grid = [[0,1,-1],[1,0,-1],[1,1,1]]) == 5\n assert candidate(grid = [[1,1,-1],[1,-1,1],[-1,1,1]]) == 0\n\n\ncheck(Solution().cherryPickup)"} | coding | 266 |
Solve the programming task below in a Python markdown code block.
You gave the twins Ai and Zu a program of games using strings. In this game, Ai and Zu each select a substring from the character string, compare them, and the person who chooses the smaller one will get points. The two competed and played the game many ... | {"inputs": ["13\naizualgorithm\n9\ncomp 1 1 4 5\ncomp 2 6 1 5\nset 9 12 b\ncomp 9 9 6 10\ncomp 5 8 1 3\nset 1 10 z\nset 11 6 x\ncomp 8 10 1 5\ncomp 1 5 2 5", "13\naozualgirithm\n9\ncomp 1 1 4 5\ncomp 2 6 1 5\nset 9 12 b\ncomp 9 9 6 10\ncomp 5 8 1 3\nset 1 10 z\nset 11 6 x\ncomp 8 10 1 5\ncomp 1 5 2 5", "13\naizualgorit... | coding | 554 |
Solve the programming task below in a Python markdown code block.
There are N items, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), Item i has a weight of w_i and a value of v_i.
Taro has decided to choose some of the N items and carry them home in a knapsack. The capacity of the knapsack is W, which means th... | {"inputs": ["2 1\n3 6\n0 97\n8 96", "2 31\n2 4\n1 28\n1 5", "2 1\n1 6\n0 50\n4 96", "3 8\n3 30\n4 35\n5 60", "3 8\n3 30\n4 35\n5 78", "3 8\n3 30\n0 35\n5 78", "2 8\n3 30\n4 50\n5 60", "3 10\n3 30\n0 6\n5 78"], "outputs": ["97\n", "32\n", "56\n", "90\n", "108\n", "143\n", "80\n", "114\n"]} | coding | 346 |
Solve the programming task below in a Python markdown code block.
F: Tea Party
Yun decided to hold a tea party at the company.
The shop sells $ N $ sets of bread, each containing $ A_1, A_2, A_3, \ dots, A_N $.
Yun decided to make a sandwich by combining two breads into a pair.
Yun-san is very careful, so I want to... | {"inputs": ["5\n4 3 5 6 7", "5\n2 3 3 6 7", "5\n6 2 5 0 3", "5\n9 2 2 0 6", "5\n0 0 7 6 0", "5\n0 0 7 1 0", "5\n0 9 2 0 2", "5\n0 0 7 0 0"], "outputs": ["11\n", "9\n", "8\n", "5\n", "3\n", "4\n", "2\n", "0\n"]} | coding | 359 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
The product difference between two pairs (a, b) and (c, d) is defined as (a * b) - (c * d).
For example, the product difference between (5, 6) and (2, 7) is (5 * 6) - (2 * 7) = 16.
Given an integer array nums, choos... | {"functional": "def check(candidate):\n assert candidate(nums = [5,6,2,7,4]) == 34\n assert candidate(nums = [4,2,5,9,7,4,8]) == 64\n\n\ncheck(Solution().maxProductDifference)"} | coding | 170 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a string s and an array of strings words, determine whether s is a prefix string of words.
A string s is a prefix string of words if s can be made by concatenating the first k strings in words for some positive ... | {"functional": "def check(candidate):\n assert candidate(s = \"iloveleetcode\", words = [\"i\",\"love\",\"leetcode\",\"apples\"]) == True\n assert candidate(s = \"iloveleetcode\", words = [\"apples\",\"i\",\"love\",\"leetcode\"]) == False\n\n\ncheck(Solution().isPrefixString)"} | coding | 122 |
Solve the programming task below in a Python markdown code block.
Igor is in 11th grade. Tomorrow he will have to write an informatics test by the strictest teacher in the school, Pavel Denisovich.
Igor knows how the test will be conducted: first of all, the teacher will give each student two positive integers $a$ and... | {"inputs": ["1\n99999 1000000\n", "1\n999999 1000000\n", "5\n1 3\n5 8\n2 5\n3 19\n56678 164422\n", "3\n186850 373693\n1 4\n313129 626299\n", "6\n1 4\n1 4\n4 5\n631059 999974\n1 2\n1 2\n", "4\n2 3\n183887 367789\n3 4\n316073 632198\n", "5\n2 3\n39710 210498\n394744 789486\n1 5\n2 4\n", "6\n1 4\n11286 22574\n488702 97740... | coding | 462 |
Solve the programming task below in a Python markdown code block.
Your friend Rick is trying to send you a message, but he is concerned that it would get intercepted by his partner. He came up with a solution:
1) Add digits in random places within the message.
2) Split the resulting message in two. He wrote down ever... | {"functional": "_inputs = [['', ''], ['hlo', 'el'], ['h3lo', 'el4']]\n_outputs = [[''], ['hello'], ['hello']]\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 | 207 |
Solve the programming task below in a Python markdown code block.
You are given two arrays $a$ and $b$, both of length $n$.
You can perform the following operation any number of times (possibly zero): select an index $i$ ($1 \leq i \leq n$) and swap $a_i$ and $b_i$.
Let's define the cost of the array $a$ as $\sum_{i=... | {"inputs": ["3\n1\n3\n6\n4\n3 6 6 6\n2 7 4 1\n4\n6 7 2 4\n2 5 3 5\n", "4\n33\n2 1 3 6 5 9 5 7 6 7 2 9 9 9 8 1 3 6 10 7 9 3 8 5 4 7 6 6 1 3 3 4 4\n9 9 6 9 10 8 2 6 4 7 10 6 10 1 8 8 1 4 10 7 5 2 5 6 1 5 8 8 3 10 1 10 3\n21\n5 9 8 5 8 10 10 7 3 8 7 3 5 7 7 10 3 7 8 2 7\n7 7 6 7 7 2 7 7 4 7 6 10 8 8 4 7 7 5 7 4 3\n40\n3 5... | coding | 665 |
Solve the programming task below in a Python markdown code block.
Chef is in need of money, so he decided to play a game with Ramsay. In this game, there are $N$ rows of coins (numbered $1$ through $N$). For each valid $i$, the $i$-th row contains $C_i$ coins with values $A_{i, 1}, A_{i, 2}, \ldots, A_{i, C_i}$.
Chef a... | {"inputs": ["1\n2\n4 5 2 3 4\n2 1 6"], "outputs": ["8"]} | coding | 589 |
Solve the programming task below in a Python markdown code block.
Given an array (or list) of scores, return the array of _ranks_ for each value in the array. The largest value has rank 1, the second largest value has rank 2, and so on. Ties should be handled by assigning the same rank to all tied values. For example:... | {"functional": "_inputs = [[[]], [[2]], [[2, 2]], [[1, 2, 3]], [[-5, -10, 3, 1]], [[-1, 3, 3, 3, 5, 5]], [[1, 10, 4]], [[5, 2, 3, 5, 5, 4, 9, 8, 0]]]\n_outputs = [[[]], [[1]], [[1, 1]], [[3, 2, 1]], [[3, 4, 1, 2]], [[6, 3, 3, 3, 1, 1]], [[3, 1, 2]], [[3, 8, 7, 3, 3, 6, 1, 2, 9]]]\nimport math\ndef _deep_eq(a, b, tol=1e... | coding | 184 |
Solve the programming task below in a Python markdown code block.
Pak Chanek plans to build a garage. He wants the garage to consist of a square and a right triangle that are arranged like the following illustration.
Define $a$ and $b$ as the lengths of two of the sides in the right triangle as shown in the illustrati... | {"inputs": ["3\n", "6\n", "5\n", "8\n", "4\n", "2\n", "1\n", "10\n"], "outputs": ["7\n", "11\n", "9\n", "13\n", "8\n", "5\n", "3\n", "16\n"]} | coding | 243 |
Solve the programming task below in a Python markdown code block.
Given a word w, rearrange the letters of w to construct another word s in such a way that s is lexicographic-ally greater than w. In case of multiple possible answers, find the lexicographic-ally smallest one.
Input Format
The first line of input conta... | {"inputs": ["5\nab\nbb\nhefg\ndhck\ndkhc"], "outputs": ["ba\nno answer\nhegf\ndhkc\nhcdk"]} | coding | 339 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a binary string s, return true if the longest contiguous segment of 1's is strictly longer than the longest contiguous segment of 0's in s, or return false otherwise.
For example, in s = "110100010" the longest... | {"functional": "def check(candidate):\n assert candidate(s = \"1101\") == True\n assert candidate(s = \"111000\") == False\n assert candidate(s = \"110100010\") == False\n\n\ncheck(Solution().checkZeroOnes)"} | coding | 169 |
Solve the programming task below in a Python markdown code block.
There's a chip in the point $(0, 0)$ of the coordinate plane. In one operation, you can move the chip from some point $(x_1, y_1)$ to some point $(x_2, y_2)$ if the Euclidean distance between these two points is an integer (i.e. $\sqrt{(x_1-x_2)^2+(y_1-y... | {"inputs": ["3\n8 6\n0 0\n9 15\n"], "outputs": ["1\n0\n2\n"]} | coding | 467 |
Solve the programming task below in a Python markdown code block.
By 2312 there were n Large Hadron Colliders in the inhabited part of the universe. Each of them corresponded to a single natural number from 1 to n. However, scientists did not know what activating several colliders simultaneously could cause, so the col... | {"inputs": ["100 1\n+ 51\n", "100 1\n+ 94\n", "100 1\n+ 68\n", "4 2\n+ 2\n+ 4\n", "100000 1\n+ 7528\n", "100000 1\n+ 8355\n", "100001 1\n+ 7528\n", "100000 1\n+ 2505\n"], "outputs": ["Success\n", "Success\n", "Success\n", "Success\nConflict with 2\n", "Success\n", "Success\n", "Success\n", "Success\n"]} | coding | 743 |
Solve the programming task below in a Python markdown code block.
A lot of goods have an International Article Number (formerly known as "European Article Number") abbreviated "EAN". EAN is a 13-digits barcode consisting of 12-digits data followed by a single-digit checksum (EAN-8 is not considered in this kata).
Th... | {"functional": "_inputs = [['9783815820865'], ['9783815820864'], ['9783827317100']]\n_outputs = [[True], [False], [True]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n... | coding | 525 |
Solve the programming task below in a Python markdown code block.
Given is a string S consisting of L and R.
Let N be the length of S. There are N squares arranged from left to right, and the i-th character of S from the left is written on the i-th square from the left.
The character written on the leftmost square is a... | {"inputs": ["RL\n", "RRLRL", "RRLRL\n", "RRLLRLRLLRLL", "RRLLLLRLRLRL", "RRLRLLRLLLRL", "RRLRLLRLLRLL", "RRLLLLRRLRLL"], "outputs": ["1 1\n", "0 1 2 1 1", "0 1 2 1 1\n", "0 2 2 0 1 1 2 1 0 2 1 0\n", "0 3 3 0 0 0 1 1 1 1 1 1\n", "0 1 2 2 1 0 2 2 0 0 1 1\n", "0 1 2 2 1 0 2 1 0 2 1 0\n", "0 3 3 0 0 0 0 1 2 2 1 0\n"]} | coding | 388 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
A password is considered strong if the below conditions are all met:
It has at least 6 characters and at most 20 characters.
It contains at least one lowercase letter, at least one uppercase letter, and at least one ... | {"functional": "def check(candidate):\n assert candidate(password = \"a\") == 5\n assert candidate(password = \"aA1\") == 3\n assert candidate(password = \"1337C0d3\") == 0\n\n\ncheck(Solution().strongPasswordChecker)"} | coding | 185 |
Solve the programming task below in a Python markdown code block.
Let us play a game of cards. As you all know there are 52 cards in a regular deck, but our deck is somewhat different. Our deck consists of N cards. Each card simply contains a unique number from 1 to N. Initially all the cards are kept on the table, fac... | {"inputs": ["3 4\n1 2 3", "5 12\n4 -2 3 -1 5"], "outputs": ["0", "2\n2 3"]} | coding | 601 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed integer array nums. A subarray s of length m is called alternating if:
m is greater than 1.
s1 = s0 + 1.
The 0-indexed subarray s looks like [s0, s1, s0, s1,...,s(m-1) % 2]. In other words, ... | {"functional": "def check(candidate):\n assert candidate(nums = [2,3,4,3,4]) == 4\n assert candidate(nums = [4,5,6]) == 2\n\n\ncheck(Solution().alternatingSubarray)"} | coding | 222 |
Solve the programming task below in a Python markdown code block.
Akash loves going to school, but not on weekends.
A week consists of 7 days (Monday to Sunday). Akash takes a leave every Saturday.
If a month consists of N days and the first-day of the month is Monday, find the number of days Akash would take a lea... | {"inputs": ["4\n5\n6\n8\n22"], "outputs": ["0\n1\n1\n3"]} | coding | 410 |
Solve the programming task below in a Python markdown code block.
For a given polygon g, computes the area of the polygon.
g is represented by a sequence of points p1, p2,..., pn where line segments connecting pi and pi+1 (1 ≤ i ≤ n-1) are sides of g. The line segment connecting pn and p1 is also a side of the polygon... | {"inputs": ["3\n1 0\n2 4\n-1 1", "3\n2 0\n2 2\n-1 1", "3\n3 0\n2 2\n-1 0", "3\n0 0\n2 2\n-1 1", "3\n3 0\n2 2\n-2 -1", "3\n3 0\n2 2\n-2 -2", "3\n3 0\n1 2\n-2 -2", "3\n3 0\n1 2\n-2 -4"], "outputs": ["4.5\n", "3.0\n", "4.0\n", "2.0", "5.5\n", "6.0\n", "7.0\n", "9.0\n"]} | coding | 298 |
Solve the programming task below in a Python markdown code block.
B: Parentheses Number
problem
Define the correct parenthesis string as follows:
* The empty string is the correct parenthesis string
* For the correct parenthesis string S, `(` S `)` is the correct parenthesis string
* For correct parentheses S, T ST ... | {"inputs": ["2\n1 2", "2\n2 1", "2\n2 -2", "2\n2 -4", "2\n2 -3", "2\n2 -6", "2\n2 -5", "2\n2 -7"], "outputs": ["()()\n", "(())", ":(\n", ":(\n", ":(\n", ":(\n", ":(\n", ":(\n"]} | coding | 416 |
Solve the programming task below in a Python markdown code block.
You are given $n$ points with integer coordinates on a coordinate axis $OX$. The coordinate of the $i$-th point is $x_i$. All points' coordinates are distinct and given in strictly increasing order.
For each point $i$, you can do the following operation... | {"inputs": ["1\n1\n29999\n", "5\n2\n1 4\n3\n1 2 3\n4\n1 2 3 7\n1\n1000000\n3\n2 5 6\n"], "outputs": ["YES\n", "YES\nYES\nNO\nYES\nYES\n"]} | coding | 584 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer array nums.
The low score of nums is the minimum absolute difference between any two integers.
The high score of nums is the maximum absolute difference between any two integers.
The score of... | {"functional": "def check(candidate):\n assert candidate(nums = [1,4,3]) == 0\n assert candidate(nums = [1,4,7,8,5]) == 3\n\n\ncheck(Solution().minimizeSum)"} | coding | 111 |
Solve the programming task below in a Python markdown code block.
You are given N integers A_{1}, A_{2}, \ldots, A_{N}.
You can perform the following operation any number of times:
Select any index i such that 1 ≤ i ≤ (N-1);
Subtract 1 from A_{i} and 2 from A_{i+1}.
Find the smallest possible value of |A_{1}| + |A_{... | {"inputs": ["4\n2\n2 4\n3\n1 1 1\n6\n-4 2 -4 2 -4 2\n1\n-100000000\n"], "outputs": ["0\n2\n15\n100000000\n"]} | coding | 684 |
Solve the programming task below in a Python markdown code block.
Let's call the set of positive integers $S$ correct if the following two conditions are met:
$S \subseteq \{1, 2, \dots, n\}$;
if $a \in S$ and $b \in S$, then $|a-b| \neq x$ and $|a-b| \neq y$.
For the given values $n$, $x$, and $y$, you have to find... | {"inputs": ["3 6 8\n", "3 8 5\n", "9 8 3\n", "10 2 5\n", "21 4 6\n", "21 7 9\n", "3 4 14\n", "5 20 3\n"], "outputs": ["3\n", "3\n", "5\n", "5\n", "9\n", "12\n", "3\n", "3\n"]} | coding | 256 |
Solve the programming task below in a Python markdown code block.
# Task
Pero has been into robotics recently, so he decided to make a robot that checks whether a deck of poker cards is complete.
He’s already done a fair share of work - he wrote a programme that recognizes the suits of the cards. For simplicity’s sa... | {"functional": "_inputs = [['P01K02H03H04'], ['H02H10P11H02'], ['P10K10H10T01'], ['P05P01P02P03P13P09P11P07K01P12K03K02K13K12K10K08H03H02H13H12H10H08T01T03T02T13T12T10T08P04K07H02T07H06T11K11T05K05H05H11'], ['P01K02P03P11K09K10P13P10']]\n_outputs = [[[12, 12, 11, 13]], [[-1, -1, -1, -1]], [[12, 12, 12, 12]], [[-1, -1, ... | coding | 570 |
Solve the programming task below in a Python markdown code block.
You are given a positive integer N and an array A of size N. There are N lists L_{1}, L_{2} \ldots L_{N}. Initially, L_{i} = [A_{i}].
You can perform the following operation any number of times as long as there are at least 2 lists:
Select 2 (non-empty... | {"inputs": ["3\n1\n1\n2\n1 2\n3\n1 1 2\n"], "outputs": ["0\n-1\n2\n"]} | coding | 678 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
There is a malfunctioning keyboard where some letter keys do not work. All other keys on the keyboard work properly.
Given a string text of words separated by a single space (no leading or trailing spaces) and a strin... | {"functional": "def check(candidate):\n assert candidate(text = \"hello world\", brokenLetters = \"ad\") == 1\n assert candidate(text = \"leet code\", brokenLetters = \"lt\") == 1\n assert candidate(text = \"leet code\", brokenLetters = \"e\") == 0\n\n\ncheck(Solution().canBeTypedWords)"} | coding | 124 |
Solve the programming task below in a Python markdown code block.
Let $n$ be a fixed integer.
A permutation is a bijection from the set $\{1,2,\ldots,n\}$ to itself.
A cycle of length ${k}$ ($k\geq2$) is a permutation $\mbox{f}$ where different integers exist $i_1,\ldots,i_k$ such that $f(i_1)=i_2,f(i_2)=i_3,...,f(... | {"inputs": ["1\n3 2\n2 2\n"], "outputs": ["6\n"]} | coding | 528 |
Solve the programming task below in a Python markdown code block.
In this Kata, you will be given a number `n` (`n > 0`) and your task will be to return the smallest square number `N` (`N > 0`) such that `n + N` is also a perfect square. If there is no answer, return `-1` (`nil` in Clojure, `Nothing` in Haskell, `None`... | {"functional": "_inputs = [[1], [2], [3], [4], [5], [7], [8], [9], [10], [11], [13], [17], [88901], [290101]]\n_outputs = [[-1], [-1], [1], [-1], [4], [9], [1], [16], [-1], [25], [36], [64], [5428900], [429235524]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n ... | coding | 572 |
Solve the programming task below in a Python markdown code block.
In this Kata, you will be given a number and your task will be to rearrange the number so that it is divisible by `25`, but without leading zeros. Return the minimum number of digit moves that are needed to make this possible. If impossible, return `-1` ... | {"functional": "_inputs = [[50], [25], [52], [57], [75], [100], [521], [1], [5071], [705], [1241367], [50011117], [1002], [50011111112], [2057], [50001111312], [500111117], [64954713879], [71255535569], [72046951686], [68151901446], [3848363615], [75733989998], [87364011400], [2992127830], [98262144757], [81737102196],... | coding | 109 |
Solve the programming task below in a Python markdown code block.
After a successful field test, Heidi is considering deploying a trap along some Corridor, possibly not the first one. She wants to avoid meeting the Daleks inside the Time Vortex, so for abundance of caution she considers placing the traps only along tho... | {"inputs": ["3 3\n1 2 8\n2 3 3\n3 1 7\n", "3 3\n1 2 8\n2 3 3\n3 1 0\n", "3 3\n1 2 8\n2 3 1\n3 1 0\n", "3 3\n1 2 8\n2 3 6\n3 1 4\n", "3 3\n1 2 8\n2 3 3\n3 1 4\n", "10 9\n5 10 606854707\n3 8 737506631\n2 4 429066157\n8 9 947792932\n6 4 56831480\n2 5 541638168\n10 7 20498997\n7 9 250445792\n6 1 9522145\n", "10 10\n4 8 149... | coding | 396 |
Solve the programming task below in a Python markdown code block.
The palindrome is a string that can be read the same way from left to right and from right to left. For example, strings "hanah", "2332" are palindromes, however the string "rahul" is not a palindrome.
We define "Easy String" if it has an even length a... | {"inputs": ["2\n2\n4\n"], "outputs": ["2\n4\n"]} | coding | 308 |
Solve the programming task below in a Python markdown code block.
N players will participate in a tennis tournament. We will call them Player 1, Player 2, \ldots, Player N.
The tournament is round-robin format, and there will be N(N-1)/2 matches in total.
Is it possible to schedule these matches so that all of the foll... | {"inputs": ["3\n2 3\n3 1\n1 1", "3\n2 3\n3 1\n2 1", "3\n3 2\n1 3\n1 2", "3\n3 2\n1 3\n2 2", "3\n3 2\n1 3\n2 1", "3\n3 3\n1 3\n2 2", "3\n3 2\n1 1\n2 2", "3\n3 3\n1 3\n2 1"], "outputs": ["-1\n", "3\n", "3\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n"]} | coding | 455 |
Solve the programming task below in a Python markdown code block.
Jeff's friends know full well that the boy likes to get sequences and arrays for his birthday. Thus, Jeff got sequence p_1, p_2, ..., p_{n} for his birthday.
Jeff hates inversions in sequences. An inversion in sequence a_1, a_2, ..., a_{n} is a pair of ... | {"inputs": ["1\n0\n", "1\n0\n", "1\n1\n", "1\n-1\n", "1\n-2\n", "1\n-3\n", "1\n-4\n", "2\n2 1\n"], "outputs": ["0\n", "0", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | coding | 281 |
Solve the programming task below in a Python markdown code block.
Deoxyribonucleic acid, DNA is the primary information storage molecule in biological systems. It is composed of four nucleic acid bases Guanine ('G'), Cytosine ('C'), Adenine ('A'), and Thymine ('T').
Ribonucleic acid, RNA, is the primary messenger mol... | {"functional": "_inputs = [['TTTT'], ['GCAT'], ['GACCGCCGCC'], ['GATTCCACCGACTTCCCAAGTACCGGAAGCGCGACCAACTCGCACAGC'], ['CACGACATACGGAGCAGCGCACGGTTAGTACAGCTGTCGGTGAACTCCATGACA'], ['AACCCTGTCCACCAGTAACGTAGGCCGACGGGAAAAATAAACGATCTGTCAATG'], ['GAAGCTTATCCGTTCCTGAAGGCTGTGGCATCCTCTAAATCAGACTTGGCTACGCCGTTAGCCGAGGGCTTAGCGTTGAGT... | coding | 227 |
Solve the programming task below in a Python markdown code block.
Consider the array $a$ composed of all the integers in the range $[l, r]$. For example, if $l = 3$ and $r = 7$, then $a = [3, 4, 5, 6, 7]$.
Given $l$, $r$, and $k$, is it possible for $\gcd(a)$ to be greater than $1$ after doing the following operation ... | {"inputs": ["1\n1 1000000000 999999999\n", "9\n1 1 0\n3 5 1\n13 13 0\n4 4 0\n3 7 4\n4 10 3\n2 4 0\n1 7 3\n1 5 3\n"], "outputs": ["YES\n", "NO\nNO\nYES\nYES\nYES\nYES\nNO\nNO\nYES\n"]} | coding | 587 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given four integers length, width, height, and mass, representing the dimensions and mass of a box, respectively, return a string representing the category of the box.
The box is "Bulky" if:
Any of the dimensions ... | {"functional": "def check(candidate):\n assert candidate(length = 1000, width = 35, height = 700, mass = 300) == \"Heavy\"\n assert candidate(length = 200, width = 50, height = 800, mass = 50) == \"Neither\"\n\n\ncheck(Solution().categorizeBox)"} | coding | 263 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.