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.
You are given a positive integer $n$, written without leading zeroes (for example, the number 04 is incorrect).
In one operation you can delete any digit of the given integer so that the result remains a positive integer without leading zeros.
Determi... | {"inputs": ["1\n", "2\n", "3\n", "4\n", "5\n", "6\n", "7\n", "8\n"], "outputs": ["0\n", "-1\n", "-1\n", "0\n", "-1\n", "-1\n", "-1\n", "-1\n"]} | coding | 348 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer array nums. You are initially positioned at the array's first index, and each element in the array represents your maximum jump length at that position.
Return true if you can reach the last i... | {"functional": "def check(candidate):\n assert candidate(nums = [2,3,1,1,4]) == True\n assert candidate(nums = [3,2,1,0,4]) == False\n\n\ncheck(Solution().canJump)"} | coding | 96 |
Solve the programming task below in a Python markdown code block.
Find a cycle in a directed graph G(V, E).
Constraints
* 1 ≤ |V| ≤ 100
* 0 ≤ |E| ≤ 1,000
* si ≠ ti
Input
A directed graph G is given in the following format:
|V| |E|
s0 t0
s1 t1
:
s|E|-1 t|E|-1
|V| is the number of nodes and |E| is the number of e... | {"inputs": ["5 3\n0 1\n0 2\n1 2", "8 3\n0 1\n0 2\n1 2", "8 3\n0 2\n0 2\n1 2", "5 3\n0 2\n0 2\n1 2", "8 2\n0 1\n0 2\n1 2", "8 3\n1 2\n0 2\n1 2", "8 2\n0 1\n0 2\n1 4", "8 2\n0 1\n0 2\n2 4"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | coding | 219 |
Solve the programming task below in a Python markdown code block.
Dilku and Bhopu live in Artland. Dilku loves Bhopu and he writes a message : “iloveyou”
on paper and wishes to send it to Bhopu. As Dilku is busy making an artwork, he asks his friend Raj to send the message to Bhopu. However Raj has a condition that he ... | {"inputs": ["iloveyou", "ulrvysioqjifo", "abcvleouioydef"], "outputs": ["happy", "sad", "happy"]} | coding | 301 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a string date representing a Gregorian calendar date formatted as YYYY-MM-DD, return the day number of the year.
Please complete the following python code precisely:
```python
class Solution:
def dayOfYear... | {"functional": "def check(candidate):\n assert candidate(date = \"2019-01-09\") == 9\n assert candidate(date = \"2019-02-10\") == 41\n\n\ncheck(Solution().dayOfYear)"} | coding | 71 |
Solve the programming task below in a Python markdown code block.
Problem :
Chotu's father is the owner of a Vada Pav shop. One Sunday, his father takes him to the shop. Father tells him that at the end of the day, Chotu has to give him a list consisting of the names of all the customers on that day who bought Vada Pa... | {"inputs": ["74\ngvny\ndk\nvc\nb\nsuvo\nbljl\nh\nnomnb\nzfv\noy\ngqdld\nrgq\nfia\nyhxbj\nyk\ngunj\nnqe\nmopv\nocgq\njwx\no\no\nh\njbsx\nhby\nnq\ndkp\nf\nnu\nnhl\nb\nrki\nefmlq\nlut\nwcem\nzz\niwevs\nwtpr\nvwn\nwwjjw\na\nqjevs\nsumon\nee\nv\nc\nwip\nylr\ny\nfn\nxlgw\njwwcy\nvdh\nx\nh\nurtoq\nlxc\nxc\nltfhu\nslv\nw\nuims... | coding | 398 |
Solve the programming task below in a Python markdown code block.
# Write Number in Expanded Form - Part 2
This is version 2 of my ['Write Number in Exanded Form' Kata](https://www.codewars.com/kata/write-number-in-expanded-form).
You will be given a number and you will need to return it as a string in [Expanded Form... | {"functional": "_inputs = [[1.24], [7.304], [0.04], [1.04], [7.3004], [0.004], [693.230459]]\n_outputs = [['1 + 2/10 + 4/100'], ['7 + 3/10 + 4/1000'], ['4/100'], ['1 + 4/100'], ['7 + 3/10 + 4/10000'], ['4/1000'], ['600 + 90 + 3 + 2/10 + 3/100 + 4/10000 + 5/100000 + 9/1000000']]\nimport math\ndef _deep_eq(a, b, tol=1e-5... | coding | 202 |
Solve the programming task below in a Python markdown code block.
Reduce a string of lowercase characters in range ascii[‘a’..’z’]by doing a series of operations. In each operation, select a pair of adjacent letters that match, and delete them.
Delete as many characters as possible using this method and return the ... | {"inputs": ["aa\n", "baab\n", "aaabccddd\n"], "outputs": ["Empty String\n", "Empty String\n", "abd\n"]} | coding | 333 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array nums of positive integers. Your task is to select some subset of nums, multiply each element by an integer and add all these numbers. The array is said to be good if you can obtain a sum of 1 from the a... | {"functional": "def check(candidate):\n assert candidate(nums = [12,5,7,23]) == True\n assert candidate(nums = [29,6,10]) == True\n assert candidate(nums = [3,6]) == False\n\n\ncheck(Solution().isGoodArray)"} | coding | 127 |
Solve the programming task below in a Python markdown code block.
Vladik often travels by trains. He remembered some of his trips especially well and I would like to tell you about one of these trips:
Vladik is at initial train station, and now n people (including Vladik) want to get on the train. They are already lin... | {"inputs": ["6\n4 4 2 5 2 3\n", "6\n4 4 2 5 2 6\n", "6\n4 4 2 5 2 3\n", "6\n4 4 2 5 2 11\n", "9\n5 1 3 1 5 2 4 2 5\n", "9\n5 1 3 2 5 2 4 2 5\n", "9\n5 1 3 2 5 2 4 3 5\n", "9\n5 1 3 1 5 2 4 2 5\n"], "outputs": ["14\n", "17\n", "14\n", "22\n", "9\n", "8\n", "5\n", "9\n"]} | coding | 558 |
Solve the programming task below in a Python markdown code block.
For an array $[b_1, b_2, \ldots, b_m]$ define its number of inversions as the number of pairs $(i, j)$ of integers such that $1 \le i < j \le m$ and $b_i>b_j$. Let's call array $b$ odd if its number of inversions is odd.
For example, array $[4, 2, 7]$ i... | {"inputs": ["5\n3\n1 2 3\n4\n4 3 2 1\n2\n1 2\n2\n2 1\n6\n4 5 6 1 2 3\n"], "outputs": ["0\n2\n0\n1\n1\n"]} | coding | 645 |
Solve the programming task below in a Python markdown code block.
You are the top spy of AtCoder Kingdom. To prevent the stolen secret from being handed to AlDebaran Kingdom, you have sneaked into the party where the transaction happens.
There are N attendees in the party, and they are given attendee numbers from 1 thr... | {"inputs": ["6\n2 3 6 1 3 1", "6\n5 2 2 2 8 8", "6\n2 5 3 1 3 1", "6\n3 6 3 1 6 1", "6\n2 6 6 1 3 1", "6\n2 5 3 2 3 1", "6\n2 6 3 1 3 1", "6\n2 5 3 2 3 2"], "outputs": ["3\n", "0\n", "2\n", "1\n", "2\n", "0\n", "2\n", "0\n"]} | coding | 383 |
Solve the programming task below in a Python markdown code block.
Vasya decided to go to the grocery store. He found in his wallet $a$ coins of $1$ burle and $b$ coins of $2$ burles. He does not yet know the total cost of all goods, so help him find out $s$ ($s > 0$): the minimum positive integer amount of money he can... | {"inputs": ["1\n69 74\n", "1\n99 101\n", "1\n3947394 7\n", "1\n3534 1834\n", "1\n9999999 0\n", "1\n12345 12345\n", "1\n112311 11332\n", "1\n1223111 133212\n"], "outputs": ["218\n", "302\n", "3947409\n", "7203\n", "10000000\n", "37036\n", "134976\n", "1489536\n"]} | coding | 567 |
Solve the programming task below in a Python markdown code block.
There are three people sitting in a room - Alice, Bob, and Charlie. They need to decide on the temperature to set on the air conditioner. Everyone has a demand each:
Alice wants the temperature to be at least A degrees.
Bob wants the temperature to be a... | {"inputs": ["4\n30 35 25\n30 35 40\n30 35 35\n30 25 35\n"], "outputs": ["Yes\nNo\nYes\nNo\n"]} | coding | 685 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
On a 2D plane, there are n points with integer coordinates points[i] = [xi, yi]. Return the minimum time in seconds to visit all the points in the order given by points.
You can move according to these rules:
In 1 se... | {"functional": "def check(candidate):\n assert candidate(points = [[1,1],[3,4],[-1,0]]) == 7\n assert candidate(points = [[3,2],[-2,2]]) == 5\n\n\ncheck(Solution().minTimeToVisitAllPoints)"} | coding | 192 |
Solve the programming task below in a Python markdown code block.
Gena loves sequences of numbers. Recently, he has discovered a new type of sequences which he called an almost arithmetical progression. A sequence is an almost arithmetical progression, if its elements can be represented as:
* a1 = p, where p is some... | {"inputs": ["1\n63\n", "1\n68\n", "1\n170\n", "1\n331\n", "2\n3 0\n", "2\n2 0\n", "1\n120\n", "1\n116\n"], "outputs": ["1\n", "1\n", "1", "1\n", "2\n", "2\n", "1\n", "1\n"]} | coding | 354 |
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian.
Spring is interesting season of year. Chef is thinking about different things, but last time he thinks about interesting game - "Strange Matrix".
Chef has a matrix that consists of n rows, each... | {"inputs": ["4 4 6\n2 2\n3 2 \n3 2 \n4 3\n4 4\n4 3", "4 4 6\n3 2\n3 2 \n3 2 \n4 3\n4 4\n4 3", "4 4 6\n3 2\n3 2 \n3 2 \n4 3\n4 4\n4 1", "4 4 6\n3 2\n3 3 \n3 2 \n4 3\n4 4\n4 3", "4 6 6\n3 2\n2 3 \n3 2 \n4 3\n4 4\n4 3", "4 6 2\n3 2\n2 3 \n3 2 \n4 3\n4 4\n4 3", "3 6 2\n1 2\n3 0 \n6 2 \n4 3\n1 1\n5 3", "3 4 2\n1 2\n3 0 \n6 ... | coding | 661 |
Solve the programming task below in a Python markdown code block.
Two moving objects A and B are moving accross the same orbit (those can be anything: two planets, two satellites, two spaceships,two flying saucers, or spiderman with batman if you prefer).
If the two objects start to move from the same point and the orb... | {"functional": "_inputs = [[12, 15, 5], [12, -15, 6], [-14, -5, 5], [23, 16, 5], [0, 0, 7], [12, 0, 10], [0, 15, 17], [-24, 0, 10], [0, -18, 14], [32, -14, 14]]\n_outputs = [['60.00'], ['6.67'], ['7.78'], ['52.57'], ['0.00'], ['12.00'], ['15.00'], ['24.00'], ['18.00'], ['9.74']]\nimport math\ndef _deep_eq(a, b, tol=1e-... | coding | 234 |
Solve the programming task below in a Python markdown code block.
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$... | {"inputs": ["1\n6\n"], "outputs": ["Richard\n"]} | coding | 466 |
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"]} | coding | 535 |
Solve the programming task below in a Python markdown code block.
The kingdom of Zion has cities connected by bidirectional roads. There is a unique path between any pair of cities. Morpheus has found out that the machines are planning to destroy the whole kingdom. If two machines can join forces, they will attack. ... | {"inputs": ["5 3\n2 1 8\n1 0 5\n2 4 5\n1 3 4\n2\n4\n0\n"], "outputs": ["10\n"]} | coding | 631 |
Solve the programming task below in a Python markdown code block.
In recreational mathematics, a [Keith number](https://en.wikipedia.org/wiki/Keith_number) or repfigit number (short for repetitive Fibonacci-like digit) is a number in the following integer sequence:
`14, 19, 28, 47, 61, 75, 197, 742, 1104, 1537, 2208, ... | {"functional": "_inputs = [[14], [10], [4], [28], [23], [0], [19], [47], [34], [61], [58], [75], [197], [742], [1104], [1537], [2208], [2697], [7385], [31331], [120284], [1084051], [44121607], [251133297], [96189170155], [11812665388886672], [855191324330802397989], [18354972585225358067718266], [4179620576514742697470... | coding | 465 |
Solve the programming task below in a Python markdown code block.
Chef rented a car for a day.
Usually, the cost of the car is Rs 10 per km. However, since Chef has booked the car for the whole day, he needs to pay for at least 300 kms even if the car runs less than 300 kms.
If the car ran X kms, determine the cost ... | {"inputs": ["5\n800\n3\n299\n301\n300\n"], "outputs": ["8000\n3000\n3000\n3010\n3000\n"]} | coding | 497 |
Solve the programming task below in a Python markdown code block.
Chef is given a sequence of prime numbers $A_1, A_2, \ldots, A_N$. This sequence has exactly $2^N$ subsequences. A subsequence of $A$ is good if it does not contain any two identical numbers; in particular, the empty sequence is good.
Chef has to find th... | {"inputs": ["5 3\n2 2 3 3 5"], "outputs": ["18"]} | coding | 393 |
Solve the programming task below in a Python markdown code block.
The chef is trying to solve some pattern problems, Chef wants your help to code it. Chef has one number K to form a new pattern. Help the chef to code this pattern problem.
-----Input:-----
- First-line will contain $T$, the number of test cases. Then t... | {"inputs": ["4\n1\n2\n3\n4"], "outputs": ["1\n13\n57\n135\n7911\n131517\n1357\n9111315\n17192123\n25272931"]} | coding | 231 |
Solve the programming task below in a Python markdown code block.
There are n cabs in a city numbered from 1 to n. The city has a rule that only one cab can run in the city at a time. Cab picks up the customer and drops him to his destination. Then the cab gets ready to pick next customer. There are m customers in sear... | {"inputs": ["1\n3 2\n1 3\n3 2\n3 5\n2 3 3 4\n5 3 4 1"], "outputs": ["1\n1"]} | coding | 502 |
Solve the programming task below in a Python markdown code block.
Victor tries to write his own text editor, with word correction included. However, the rules of word correction are really strange.
Victor thinks that if a word contains two consecutive vowels, then it's kinda weird and it needs to be replaced. So the w... | {"inputs": ["1\na\n", "1\nb\n", "1\ne\n", "1\ne\n", "1\na\n", "1\nb\n", "1\nf\n", "1\n`\n"], "outputs": ["a\n", "b\n", "e\n", "e\n", "a\n", "b\n", "f\n", "`\n"]} | coding | 316 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a string s of length n containing only four kinds of characters: 'Q', 'W', 'E', and 'R'.
A string is said to be balanced if each of its characters appears n / 4 times where n is the length of the string.... | {"functional": "def check(candidate):\n assert candidate(s = \"QWER\") == 0\n assert candidate(s = \"QQWE\") == 1\n assert candidate(s = \"QQQW\") == 2\n assert candidate(s = \"QQQQ\") == 3\n\n\ncheck(Solution().balancedString)"} | coding | 137 |
Solve the programming task below in a Python markdown code block.
A palindrome is a series of characters that read the same forwards as backwards such as "hannah", "racecar" and "lol".
For this Kata you need to write a function that takes a string of characters and returns the length, as an integer value, of longest a... | {"functional": "_inputs = [['A'], ['Hannah'], ['xyz__a_/b0110//a_zyx'], ['$aaabbbccddd_!jJpqlQx_.///yYabababhii_'], ['']]\n_outputs = [[1], [6], [13], [25], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)... | coding | 160 |
Solve the programming task below in a Python markdown code block.
Yaroslav likes algorithms. We'll describe one of his favorite algorithms.
1. The algorithm receives a string as the input. We denote this input string as a.
2. The algorithm consists of some number of command. Сommand number i looks either as si >>... | {"inputs": ["2\n8\n52\n", "2\n10\n79\n", "2\n10\n71\n", "2\n18\n79\n", "2\n15\n71\n", "2\n27\n79\n", "2\n15\n52\n", "2\n10\n79\n"], "outputs": ["0??<>1\n1??<>2\n2??<>3\n3??<>4\n4??<>5\n5??<>6\n6??<>7\n7??<>8\n8??<>9\n9??>>??0\n??<>1\n?0>>0?\n?1>>1?\n?2>>2?\n?3>>3?\n?4>>4?\n?5>>5?\n?6>>6?\n?7>>7?\n?8>>8?\n?9>>9?\n?>>??\... | coding | 521 |
Solve the programming task below in a Python markdown code block.
# Do names have colors?
*Now they do.*
Make a function that takes in a name (Any string two chars or longer really, but the name is the idea) and use the ascii values of it's substrings to produce the hex value of its color! Here is how it's going to w... | {"functional": "_inputs = [['A'], [''], ['John Doe'], ['CodeWars']]\n_outputs = [[None], [None], ['C70033'], ['182892']]\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 | 415 |
Solve the programming task below in a Python markdown code block.
HackerRank-city is an acyclic connected graph (or tree). Its not an ordinary place, the construction of the whole tree takes place in $N$ steps. The process is described below:
It initially has $\mbox{1}$ node.
At each step, you must create $3$ duplicat... | {"inputs": ["1\n1\n", "2\n2 1\n"], "outputs": ["29\n", "2641\n"]} | coding | 661 |
Solve the programming task below in a Python markdown code block.
You have a long fence which consists of $n$ sections. Unfortunately, it is not painted, so you decided to hire $q$ painters to paint it. $i$-th painter will paint all sections $x$ such that $l_i \le x \le r_i$.
Unfortunately, you are on a tight budget, ... | {"inputs": ["4 3\n1 1\n2 2\n3 4\n", "3 3\n1 3\n1 1\n2 2\n", "6 3\n1 6\n1 3\n4 6\n", "3 3\n1 1\n2 3\n2 3\n", "5 3\n5 5\n1 3\n3 5\n", "3 3\n1 3\n1 2\n2 3\n", "5 3\n1 3\n2 3\n4 5\n", "3 3\n1 3\n2 3\n3 3\n"], "outputs": ["2\n", "3\n", "6\n", "2\n", "3\n", "3\n", "3\n", "3\n"]} | coding | 340 |
Solve the programming task below in a Python markdown code block.
There are N integers, A_1, A_2, ..., A_N, arranged in a row in this order.
You can perform the following operation on this integer sequence any number of times:
Operation: Choose an integer i satisfying 1 \leq i \leq N-1. Multiply both A_i and A_{i+1} by... | {"inputs": ["3\n0 1 1", "2\n-10 9\n", "3\n-1 5 1", "3\n-2 5 1", "3\n-1 1 1", "3\n-2 0 1", "3\n-10 5 0", "3\n-14 5 0"], "outputs": ["2\n", "1\n", "5\n", "6\n", "1\n", "3\n", "15\n", "19\n"]} | coding | 355 |
Solve the programming task below in a Python markdown code block.
n soldiers stand in a circle. For each soldier his height ai is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |ai - aj| is minimal. So each of them will be less noticeable with the o... | {"inputs": ["2\n6 6\n", "2\n3 6\n", "2\n511 5\n", "2\n511 6\n", "2\n605 6\n", "2\n511 32\n", "3\n83 504 68\n", "3\n136 452 68\n"], "outputs": ["1 2\n", "1 2\n", "1 2\n", "1 2\n", "1 2\n", "1 2\n", "3 1\n", "3 1\n"]} | coding | 244 |
Solve the programming task below in a Python markdown code block.
We have a grid with (2^N - 1) rows and (2^M-1) columns. You are asked to write 0 or 1 in each of these squares. Let a_{i,j} be the number written in the square at the i-th row from the top and the j-th column from the left.
For a quadruple of integers (... | {"inputs": ["1 1", "2 2", "2 1", "3 2", "4 1", "3 3", "5 1", "1 3"], "outputs": ["1\n", "111\n101\n111\n", "1\n1\n1\n", "111\n101\n111\n101\n111\n101\n111\n", "1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n", "1111111\n1010101\n1111111\n1011101\n1111111\n1010101\n1111111\n", "1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\... | coding | 448 |
Solve the programming task below in a Python markdown code block.
You are given an array A, consisting of N distinct integers.
Calculate number of pairs (i,j) (1 ≤ i < j ≤ N), such that 2 \cdot (A_{i} \oplus A_{j}) = A_{i} + A_{j}, where \oplus denotes [bitwise XOR].
------ Input Format ------
- The first line con... | {"inputs": ["4\n1 2 3 6\n", "5\n4 3 9 7 1"], "outputs": ["2\n", "1"]} | coding | 567 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
A string s is called good if there are no two different characters in s that have the same frequency.
Given a string s, return the minimum number of characters you need to delete to make s good.
The frequency of a cha... | {"functional": "def check(candidate):\n assert candidate(s = \"aab\") == 0\n assert candidate(s = \"aaabbbcc\") == 2\n assert candidate(s = \"ceabaacb\") == 2\n\n\ncheck(Solution().minDeletions)"} | coding | 139 |
Solve the programming task below in a Python markdown code block.
There is a directed graph with N vertices and M edges.
The i-th edge (1≤i≤M) points from vertex a_i to vertex b_i, and has a weight c_i.
We will play the following single-player game using this graph and a piece.
Initially, the piece is placed at vertex ... | {"inputs": ["2 2\n1 2 2\n2 1 1", "2 2\n1 2 1\n2 1 1", "2 2\n1 2 1\n2 1 1\n", "3 3\n1 2 4\n2 2 3\n1 3 5", "3 3\n1 2 6\n2 3 0\n1 3 5", "3 3\n2 1 6\n2 3 1\n1 3 1", "3 2\n1 2 6\n1 3 0\n1 3 5", "3 3\n2 1 3\n2 3 1\n1 3 2"], "outputs": ["inf\n", "inf", "inf\n", "5\n", "6\n", "1\n", "0\n", "2\n"]} | coding | 517 |
Solve the programming task below in a Python markdown code block.
Little C loves number «3» very much. He loves all things about it.
Now he is playing a game on a chessboard of size n × m. The cell in the x-th row and in the y-th column is called (x,y). Initially, The chessboard is empty. Each time, he places two ches... | {"inputs": ["3 7\n", "4 3\n", "1 4\n", "2 1\n", "1 8\n", "7 2\n", "7 1\n", "2 5\n"], "outputs": ["20\n", "12\n", "2\n", "0\n", "6\n", "12\n", "6\n", "10\n"]} | coding | 311 |
Solve the programming task below in a Python markdown code block.
We have a grid with H rows and W columns. The square at the i-th row and the j-th column will be called Square (i,j).
The integers from 1 through H×W are written throughout the grid, and the integer written in Square (i,j) is A_{i,j}.
You, a magical girl... | {"inputs": ["3 3 1\n1 4 3\n2 5 7\n8 9 6\n1\n4 8", "3 3 1\n1 4 3\n2 5 7\n8 9 6\n1\n4 9", "3 3 3\n1 4 3\n2 5 7\n8 9 6\n1\n4 8", "3 3 2\n1 4 3\n2 5 7\n8 9 6\n1\n4 1", "3 3 1\n1 4 3\n2 5 7\n8 9 6\n1\n8 9", "3 3 2\n1 4 3\n2 5 7\n8 9 6\n1\n4 8", "3 3 2\n1 4 3\n2 5 7\n8 9 6\n1\n4 8\n", "4 2 3\n3 7\n1 4\n5 2\n6 8\n2\n2 1\n2 2"... | coding | 578 |
Solve the programming task below in a Python markdown code block.
Given a string s, write a method (function) that will return true if its a valid single integer or floating number or false if its not.
Valid examples, should return true:
should return false:
Also feel free to reuse/extend the following starter code:
... | {"functional": "_inputs = [['s2324'], ['-234.4'], ['3 4'], ['3-4'], ['3 4 '], ['34.65'], ['-0'], ['0.0'], [''], [' ']]\n_outputs = [[False], [True], [False], [False], [False], [True], [True], [True], [False], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n ... | coding | 75 |
Solve the programming task below in a Python markdown code block.
# Task
You know the slogan `p`, which the agitators have been chanting for quite a while now. Roka has heard this slogan a few times, but he missed almost all of them and grasped only their endings. You know the string `r` that Roka has heard.
You n... | {"functional": "_inputs = [['glorytoukraine', 'ukraineaineaine'], ['glorytoukraine', 'ukraineaineainee'], ['glorytoukraine', 'einene'], ['programming', 'ingmingmming'], ['mcoecqwmjdudc', 'dcoecqwmjdudcdcudc'], ['erjernhxvbqfjsj', 'ernhxvbqfjsjjrnhxvbqfjsjjernhxvbqfjsj'], ['dhgusdlifons', 'lifonsssdlifonsgusdlifonssnsdl... | coding | 307 |
Solve the programming task below in a Python markdown code block.
Complete the solution so that it returns the number of times the search_text is found within the full_text.
```python
search_substr( fullText, searchText, allowOverlap = true )
```
so that overlapping solutions are (not) counted. If the searchText is e... | {"functional": "_inputs = [['aa_bb_cc_dd_bb_e', 'bb'], ['aaabbbcccc', 'bbb'], ['aaacccbbbcccc', 'cc'], ['aaa', 'aa'], ['aaa', 'aa', False], ['aaabbbaaa', 'bb', False], ['a', ''], ['', 'a'], ['', ''], ['', '', False]]\n_outputs = [[2], [1], [5], [2], [1], [1], [0], [0], [0], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-... | coding | 199 |
Solve the programming task below in a Python markdown code block.
Takahashi is going to buy N items one by one.
The price of the i-th item he buys is A_i yen (the currency of Japan).
He has M discount tickets, and he can use any number of them when buying an item.
If Y tickets are used when buying an item priced X yen,... | {"inputs": ["1 1\n1\n", "3 3\n2 3 8", "3 3\n2 3 5", "3 4\n2 3 5", "3 0\n3 8 2", "3 3\n2 13 3", "3 2\n2 13 3", "3 2\n2 13 2"], "outputs": ["0\n", "5\n", "4\n", "3\n", "13\n", "6\n", "8\n", "7\n"]} | coding | 288 |
Solve the programming task below in a Python markdown code block.
The Hedgehog likes to give presents to his friend, but no less he likes to receive them.
Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboar... | {"inputs": ["5 1\n0\n", "1 1\n0\n", "5 2\n0\n", "2 1\n0\n", "3 1\n0\n", "2 2\n0\n", "15 5\n0\n", "20 1\n0\n"], "outputs": ["5\n", "1\n", "2\n", "2\n", "3\n", "1\n", "3\n", "20\n"]} | coding | 400 |
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.
A split at an index i where 0 <= i <= n - 2 is called valid if the product of the first i + 1 elements and the product of the remaining elements are coprime.
... | {"functional": "def check(candidate):\n assert candidate(nums = [4,7,8,15,3,5]) == 2\n assert candidate(nums = [4,7,15,8,3,5]) == -1\n\n\ncheck(Solution().findValidSplit)"} | coding | 255 |
Solve the programming task below in a Python markdown code block.
You are given a length of string and two thumbtacks. On thumbtack goes into the focus point *F₀* with coordinates *x₀* and *y₀*, and the other does into point *F₁* with points *x₁* and *y₁*. The string is then tied at the ends to the thumbtacks and has l... | {"functional": "_inputs = [[{'x': 0, 'y': 0}, {'x': 0, 'y': 0}, 2, {'x': 0, 'y': 0}], [{'x': 0, 'y': 0}, {'x': 0, 'y': 0}, 2, {'x': 1, 'y': 1}]]\n_outputs = [[True], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol,... | coding | 267 |
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Chef is teaching his students about properties of integers. Today he is teaching them about numbers which are squares of some number, e.g. 1, 4, 9, 16, 25 etc. These numbers ... | {"inputs": ["3\n3\n2 2 2\n3\n1 2 2\n3\n2 4 6"], "outputs": ["0\n1\n2"]} | coding | 624 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array of strings names of size n. You will create n folders in your file system such that, at the ith minute, you will create a folder with the name names[i].
Since two files cannot have the same name, if you... | {"functional": "def check(candidate):\n assert candidate(names = [\"pes\",\"fifa\",\"gta\",\"pes(2019)\"]) == [\"pes\",\"fifa\",\"gta\",\"pes(2019)\"]\n assert candidate(names = [\"gta\",\"gta(1)\",\"gta\",\"avalon\"]) == [\"gta\",\"gta(1)\",\"gta(2)\",\"avalon\"]\n assert candidate(names = [\"onepiece\",\"one... | coding | 170 |
Solve the programming task below in a Python markdown code block.
Complete the function that determines the score of a hand in the card game [Blackjack](https://en.wikipedia.org/wiki/Blackjack) (aka 21).
The function receives an array of strings that represent each card in the hand (`"2"`, `"3",` ..., `"10"`, `"J"`, `... | {"functional": "_inputs = [[['2', '3']], [['4', '5', '6']], [['7', '7', '8']], [['9', '2', '10']], [['4', '7', '8']], [['J', '3']], [['J', 'Q']], [['K', 'J', 'Q']], [['A', '3']], [['A', 'J']], [['A', 'A', 'A', 'J']], [['A', '2', 'A', '9', '9']], [['A', 'A']], [['8', 'A', 'A']], [['5', '4', 'A', 'A']], [['A', '2', 'A', ... | coding | 329 |
Solve the programming task below in a Python markdown code block.
Makoto has a big blackboard with a positive integer $n$ written on it. He will perform the following action exactly $k$ times:
Suppose the number currently written on the blackboard is $v$. He will randomly pick one of the divisors of $v$ (possibly $1$ ... | {"inputs": ["6 1\n", "6 2\n", "2 4\n", "1 1\n", "2 4\n", "1 1\n", "2 6\n", "1 0\n"], "outputs": ["3\n", "875000008\n", "562500005\n", "1\n", "562500005\n", "1\n", "140625002\n", "1\n"]} | coding | 507 |
Solve the programming task below in a Python markdown code block.
To become a millionaire, M-kun has decided to make money by trading in the next N days. Currently, he has 1000 yen and no stocks - only one kind of stock is issued in the country where he lives.
He is famous across the country for his ability to foresee... | {"inputs": ["2\n1 2", "2\n2 3", "2\n2 5", "2\n4 5", "2\n2 7", "2\n7 8", "2\n2 6", "2\n3 5"], "outputs": ["2000\n", "1500\n", "2500\n", "1250\n", "3500\n", "1142\n", "3000\n", "1666\n"]} | coding | 398 |
Solve the programming task below in a Python markdown code block.
Read problem statements in [Mandarin], [Bengali], [Russian], and [Vietnamese] as well.
One day, Chef's friend gave him a wrong number $W$ containing $N + 1$ digits and said that the actual number $A$ is the largest possible number that can be obtained f... | {"inputs": ["2\n9876543211\n12345678999"], "outputs": ["19876543211\n102345678999"]} | coding | 427 |
Solve the programming task below in a Python markdown code block.
There are $n$ points on a coordinate axis $OX$. The $i$-th point is located at the integer point $x_i$ and has a speed $v_i$. It is guaranteed that no two points occupy the same coordinate. All $n$ points move with the constant speed, the coordinate of t... | {"inputs": ["2\n2 1\n-3 0\n", "2\n2 1\n-4 0\n", "2\n0 1\n-4 0\n", "2\n0 2\n-4 0\n", "2\n2 1\n-5 0\n", "2\n2 1\n-4 1\n", "2\n0 2\n-7 0\n", "2\n0 1\n-4 1\n"], "outputs": ["0\n", "0\n", "1\n", "2\n", "0\n", "0\n", "2\n", "1\n"]} | coding | 508 |
Solve the programming task below in a Python markdown code block.
# Task
Two arrays are called similar if one can be obtained from another by swapping at most one pair of elements.
Given two arrays, check whether they are similar.
# Example
For `A = [1, 2, 3]` and `B = [1, 2, 3]`, the output should be `true;`
For `... | {"functional": "_inputs = [[[1, 2, 3], [1, 2, 3]], [[1, 2, 3], [2, 1, 3]], [[1, 2, 2], [2, 1, 1]], [[1, 2, 3], [1, 10, 2]], [[2, 3, 1], [1, 3, 2]], [[1, 1, 2], [1, 2, 2]]]\n_outputs = [[True], [True], [False], [False], [True], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstan... | coding | 302 |
Solve the programming task below in a Python markdown code block.
Rose loves to play games. This problem is about a game he recently played. In the game there are N locations, numbered 0 through N-1. Each location has one entrance and one exit. You are given an array aka A with N elements.For each i, A[i] describes the... | {"inputs": ["10\n2\n1 -1\n3\n1 0 -1\n3\n0 1 2\n37\n29 33 28 16 -1 11 10 14 6 31 7 35 34 8 15 17 26 12 13 22 1 20 2 21 -1 5 19 9 18 4 25 32 3 30 23 10 27\n48\n17 43 20 41 42 15 18 35 -1 31 7 33 23 33 -1 -1 0 33 19 12 42 -1 -1 9 9 -1 39 -1 31 46 -1 20 44 41 -1 -1 12 -1 36 -1 -1 6 47 10 2 4 1 29\n6\n3 1 1 2 -1 4\n47\n15 1... | coding | 372 |
Solve the programming task below in a Python markdown code block.
We need a function (for commercial purposes) that may perform integer partitions with some constraints.
The function should select how many elements each partition should have.
The function should discard some "forbidden" values in each partition.
So, cr... | {"functional": "_inputs = [[10, 3, 2], [10, 3, 0], [10, 4, 1], [10, 5, 3], [15, 5, 3], [15, 5, 4], [15, 3, 3]]\n_outputs = [[4], [8], [2], [4], [15], [19], [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)... | coding | 491 |
Solve the programming task below in a Python markdown code block.
Chef Al Gorithm was reading a book about climate and oceans when he encountered the word “glaciological”. He thought it was quite curious, because it has the following interesting property: For every two letters in the word, if the first appears x times ... | {"inputs": ["4\nglaciological 1\nteammate 0\npossessions 3\ndefenselessness 3", "4\nglaciological 1\nteammate 0\npossessions 3\ndefenselessness 0", "4\nglaciological 1\nteammate 0\npossessions 4\ndefenselessness 0", "4\nglaciological 1\nteammate 1\npossessions 4\ndefensdlessness 0", "4\nlacigoloicalg 2\nteammate 0\npos... | coding | 491 |
Solve the programming task below in a Python markdown code block.
This kata is part of the collection [Mary's Puzzle Books](https://www.codewars.com/collections/marys-puzzle-books).
Mary brought home a "spot the differences" book. The book is full of a bunch of problems, and each problem consists of two strings that a... | {"functional": "_inputs = [['abcdefg', 'abcqetg'], ['Hello World!', 'hello world.'], ['FixedGrey', 'FixedGrey'], ['HACKER', 'H4CK3R'], ['This is a really long sentence.', 'That is a_really long sentence,'], ['', ''], ['abcdefghijklmnopqrstuvwxyz', 'zyxwvutsrqponmlkjihgfedcba'], ['YOLO lol', 'ROLO mom'], ['www.youtube.c... | coding | 319 |
Solve the programming task below in a Python markdown code block.
Tonight is brain dinner night and all zombies will gather together to scarf down some delicious brains. The artful Heidi plans to crash the party, incognito, disguised as one of them. Her objective is to get away with at least one brain, so she can analy... | {"inputs": ["1\n", "4\n", "2\n", "3\n", "5\n", "6\n", "7\n", "8\n"], "outputs": ["1\n", "2\n", "1\n", "2\n", "3\n", "3\n", "4\n", "4\n"]} | coding | 574 |
Solve the programming task below in a Python markdown code block.
You are asked to watch your nephew who likes to play with toy blocks in a strange way.
He has $n$ boxes and the $i$-th box has $a_i$ blocks. His game consists of two steps:
he chooses an arbitrary box $i$;
he tries to move all blocks from the $i$-th b... | {"inputs": ["1\n3\n1000 1000 1001\n", "1\n3\n1000 1000 1001\n", "1\n3\n0000 1000 1001\n", "1\n3\n1000 1001 1001\n", "1\n3\n0000 1000 1000\n", "1\n3\n1000 1001 0001\n", "1\n3\n0001 1000 1000\n", "1\n2\n1000000000 1000000000\n"], "outputs": ["1\n", "1\n", "1\n", "0\n", "0\n", "0\n", "1\n", "0\n"]} | coding | 610 |
Solve the programming task below in a Python markdown code block.
Now-a-days, Manish is becoming famous for bank robbery in the country because of his cleverness, he never robs own his own.He has four workers A , B, C, and D , all working under him.All of the four take some amount for that. There are total N banks in ... | {"inputs": ["1\n3\n4 7 2 9\n5 6 4 7\n2 6 4 3"], "outputs": ["10"]} | coding | 400 |
Solve the programming task below in a Python markdown code block.
There are $n$ distinct points on a coordinate line, the coordinate of $i$-th point equals to $x_i$. Choose a subset of the given set of points such that the distance between each pair of points in a subset is an integral power of two. It is necessary to ... | {"inputs": ["1\n1\n", "1\n1\n", "1\n2\n", "1\n4\n", "1\n8\n", "1\n7\n", "1\n0\n", "1\n5\n"], "outputs": ["1\n1 \n", "1\n1\n", "1\n2 \n", "1\n4 \n", "1\n8 \n", "1\n7 \n", "1\n0 \n", "1\n5 \n"]} | coding | 478 |
Solve the programming task below in a Python markdown code block.
Michael is accused of violating the social distancing rules and creating a risk of spreading coronavirus. He is now sent to prison. Luckily, Michael knows exactly what the prison looks like from the inside, especially since it's very simple.
The prison ... | {"inputs": ["2\n2 2\n1 3\n"], "outputs": ["4\n3\n"]} | coding | 358 |
Solve the programming task below in a Python markdown code block.
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well.
Given the rating R of a person, tell which division he belongs to. The rating range for each division are given below:
Division 1: 2000 ≤ Rating.
Division 2: 1600 ≤ Ratin... | {"inputs": ["3\n1500\n4000\n1900"], "outputs": ["3\n1\n2\n"]} | coding | 380 |
Solve the programming task below in a Python markdown code block.
Your goal is to return multiplication table for ```number``` that is always an integer from 1 to 10.
For example, a multiplication table (string) for ```number == 5``` looks like below:
```
1 * 5 = 5
2 * 5 = 10
3 * 5 = 15
4 * 5 = 20
5 * 5 = 25
6 * 5 = ... | {"functional": "_inputs = [[5], [1]]\n_outputs = [['1 * 5 = 5\\n2 * 5 = 10\\n3 * 5 = 15\\n4 * 5 = 20\\n5 * 5 = 25\\n6 * 5 = 30\\n7 * 5 = 35\\n8 * 5 = 40\\n9 * 5 = 45\\n10 * 5 = 50'], ['1 * 1 = 1\\n2 * 1 = 2\\n3 * 1 = 3\\n4 * 1 = 4\\n5 * 1 = 5\\n6 * 1 = 6\\n7 * 1 = 7\\n8 * 1 = 8\\n9 * 1 = 9\\n10 * 1 = 10']]\nimport math... | coding | 192 |
Solve the programming task below in a Python markdown code block.
Given an array of integers, where all elements but one occur twice, find the unique element.
Example
$a=[1,2,3,4,3,2,1]$
The unique element is $\begin{array}{c}4\end{array}$.
Function Description
Complete the lonelyinteger function in the e... | {"inputs": ["1\n1\n", "3\n1 1 2\n", "5\n0 0 1 2 1\n"], "outputs": ["1\n", "2\n", "2\n"]} | coding | 358 |
Solve the programming task below in a Python markdown code block.
I have the `par` value for each hole on a golf course and my stroke `score` on each hole. I have them stored as strings, because I wrote them down on a sheet of paper. Right now, I'm using those strings to calculate my golf score by hand: take the diffe... | {"functional": "_inputs = [['443454444344544443', '353445334534445344'], ['123456123456123456', '123456123456123456']]\n_outputs = [[-1], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance... | coding | 258 |
Solve the programming task below in a Python markdown code block.
Given an alphanumeric string made up of digits and lower case Latin characters only, find the sum of all the digit characters in the string.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. Then ... | {"inputs": ["1\nab1231da\n"], "outputs": ["7"]} | coding | 213 |
Solve the programming task below in a Python markdown code block.
Write a program to obtain length (L) and breadth (B) of a rectangle and check whether its area is greater or perimeter is greater or both are equal.
------ Input Format ------
- First line will contain the length (L) of the rectangle.
- Second line wi... | {"inputs": ["1\n2\n"], "outputs": ["Peri\n6\n"]} | coding | 243 |
Solve the programming task below in a Python markdown code block.
You are given $n$ integers $a_1, a_2, \ldots, a_n$. You choose any subset of the given numbers (possibly, none or all numbers) and negate these numbers (i. e. change $x \to (-x)$). What is the maximum number of different values in the array you can achie... | {"inputs": ["1\n2\n-100 100\n", "1\n4\n100 -100 99 -99\n", "3\n4\n1 1 2 2\n3\n1 2 3\n2\n0 0\n", "4\n3\n100 -100 100\n4\n100 0 0 0\n5\n0 0 0 0 0\n7\n100 3 -2 0 -100 4 5\n", "1\n30\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30\n"], "outputs": ["2\n", "4\n", "4\n3\n1\n", "2\n2\n1\n7\n",... | coding | 354 |
Solve the programming task below in a Python markdown code block.
Chef's playlist contains 3 songs named A, B, and C, each of duration exactly X minutes. Chef generally plays these 3 songs in loop, i.e, A \rightarrow B \rightarrow C \rightarrow A \rightarrow B \rightarrow C \rightarrow A \rightarrow \dots
Chef went on... | {"inputs": ["5\n6 1\n5 1\n11 2\n5 8\n100 9\n"], "outputs": ["2\n1\n1\n0\n3\n"]} | coding | 457 |
Solve the programming task below in a Python markdown code block.
This is a harder version of the problem. In this version $n \le 500\,000$
The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. A... | {"inputs": ["1\n1\n", "1\n1\n", "1\n2\n", "3\n7 6 4\n", "3\n7 3 4\n", "3\n10 6 8\n", "3\n10 6 4\n", "3\n10 3 8\n"], "outputs": ["1 \n", "1 \n", "2\n", "7 6 4\n", "7 3 3\n", "10 6 6 \n", "10 6 4\n", "10 3 3\n"]} | coding | 683 |
Solve the programming task below in a Python markdown code block.
Write a function that takes an array/list of numbers and returns a number such that
Explanation
total([1,2,3,4,5]) => 48
1+2=3--\ 3+5 => 8 \
2+3=5--/ \ == 8+12=>20\
==>5+7=> 12 / \ 20+28 => 48
3+4=7--\ / ... | {"functional": "_inputs = [[[1, 2, 3, 4, 5]], [[1, 2, 3, 4]], [[1, 2, 3]], [[4, 4, 52, 23, 32, 1, -1]], [[4, 4, 5, -1]], [[-1, -1, -1]], [[-1, -1, -10, 42, 92, 1, 23, 6, -3]], [[-1, 1, -1, 1]], [[42]]]\n_outputs = [[48], [20], [8], [1753], [30], [-4], [9248], [0], [42]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n ... | coding | 263 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two positive integers left and right with left <= right. Calculate the product of all integers in the inclusive range [left, right].
Since the product may be very large, you will abbreviate it following ... | {"functional": "def check(candidate):\n assert candidate(left = 1, right = 4) == \"24e0\"\n assert candidate(left = 2, right = 11) == \"399168e2\"\n assert candidate(left = 371, right = 375) == \"7219856259e3\"\n\n\ncheck(Solution().abbreviateProduct)"} | coding | 360 |
Solve the programming task below in a Python markdown code block.
You are given an expression of the form $a{+}b$, where $a$ and $b$ are integers from $0$ to $9$. You have to evaluate it and print the result.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) — the number of test cases.
Eac... | {"inputs": ["1\n5+5\n", "1\n1+1\n", "1\n2+2\n", "1\n5+6\n", "1\n1+4\n", "1\n0+0\n", "1\n2+3\n", "1\n3+1\n"], "outputs": ["10\n", "2\n", "4\n", "11\n", "5\n", "0\n", "5\n", "4\n"]} | coding | 199 |
Solve the programming task below in a Python markdown code block.
Mr. Suzuki has opened a new mobile sales shop for freshly squeezed milk in the Aizu area. It is assumed that all the customers who come to buy that day are already in the store with bottles to take home and will not increase any more. Customers only orde... | {"inputs": ["5\n2\n6\n4\n6\n9\n0", "5\n2\n6\n4\n7\n9\n0", "5\n1\n2\n6\n9\n0\n0", "5\n1\n2\n6\n9\n1\n0", "5\n1\n2\n6\n1\n1\n0", "5\n1\n2\n6\n1\n3\n0", "5\n1\n2\n4\n2\n4\n0", "5\n2\n2\n4\n2\n4\n0"], "outputs": ["38\n", "39\n", "13\n", "17\n", "11\n", "14\n", "18\n", "22\n"]} | coding | 610 |
Solve the programming task below in a Python markdown code block.
You have N rods with you. The i-th rod has a length of A_{i} and a beauty of B_{i}.
You'd like to arrange these rods side-by-side in some order on the number line, starting from 0.
Let x_{i} be the starting position of the i-th rod in an arrangement.... | {"inputs": ["2\n2\n1 2\n4 6\n4\n2 8 9 11\n25 27 100 45"], "outputs": ["8\n2960"]} | coding | 600 |
Solve the programming task below in a Python markdown code block.
Stellar history 2005.11.5. You are about to engage an enemy spacecraft as the captain of the UAZ Advance spacecraft. Fortunately, the enemy spaceship is still unnoticed. In addition, the space coordinates of the enemy are already known, and the "feather ... | {"inputs": ["-19 0 0\n14 0 0\n0 2 1\n0 8 9\n0 0 8", "-19 0 0\n14 0 0\n1 2 1\n0 8 9\n0 0 8", "-2 0 0\n14 0 0\n1 1 1\n0 8 9\n-1 0 4", "-2 0 0\n14 0 0\n1 1 1\n0 8 9\n-2 0 4", "-2 0 1\n14 0 0\n1 1 1\n0 8 9\n-2 0 4", "-2 0 1\n14 0 0\n1 1 1\n0 8 9\n-1 0 4", "-4 0 1\n14 0 0\n1 1 2\n0 5 9\n-1 0 4", "-4 0 2\n14 0 0\n1 1 2\n0 5 ... | coding | 561 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
The beauty of a string is the difference in frequencies between the most frequent and least frequent characters.
For example, the beauty of "abaacc" is 3 - 1 = 2.
Given a string s, return the sum of beauty of all of... | {"functional": "def check(candidate):\n assert candidate(s = \"aabcb\") == 5\n assert candidate(s = \"aabcbaa\") == 17\n\n\ncheck(Solution().beautySum)"} | coding | 103 |
Solve the programming task below in a Python markdown code block.
You are given an integer N. Build an undirected graph with N vertices with indices 1 to N that satisfies the following two conditions:
* The graph is simple and connected.
* There exists an integer S such that, for every vertex, the sum of the indices o... | {"inputs": ["0", "4", "1", "2", "2", "0", "1", "4"], "outputs": ["0\n", "4\n1 2\n1 3\n2 4\n3 4\n", "0\n", "0\n", "0\n", "0\n", "0\n", "4\n1 2\n1 3\n2 4\n3 4\n"]} | coding | 214 |
Solve the programming task below in a Python markdown code block.
Let's arrange a deck of cards. There are totally 36 cards of 4 suits(S, H, C, D) and 9 values (1, 2, ... 9). For example, 'eight of heart' is represented by H8 and 'one of diamonds' is represented by D1.
Your task is to write a program which sorts a giv... | {"inputs": ["2\nS1 G1", "2\nS1 H1", "5\nH4 B9 S4 D2 C3", "5\nH4 C9 S4 D2 C2", "5\nH4 B9 S4 E2 C3", "5\nI4 C9 S4 D2 C2", "5\nH3 B9 S4 E2 C3", "5\nH3 B9 S4 E2 B3"], "outputs": ["S1 G1\nStable\nS1 G1\nStable\n", "S1 H1\nStable\nS1 H1\nStable", "D2 C3 H4 S4 B9\nStable\nD2 C3 S4 H4 B9\nNot stable\n", "D2 C2 H4 S4 C9\nStable... | coding | 533 |
Solve the programming task below in a Python markdown code block.
Paul is at the orchestra. The string section is arranged in an r × c rectangular grid and is filled with violinists with the exception of n violists. Paul really likes violas, so he would like to take a picture including at least k of them. Paul can take... | {"inputs": ["2 2 1 1\n1 2\n", "1 1 1 1\n1 1\n", "1 1 1 1\n1 1\n", "2 2 1 1\n1 2\n", "5 9 2 2\n4 6\n1 5\n", "2 6 2 2\n1 2\n1 5\n", "2 6 2 2\n1 2\n1 5\n", "5 9 2 2\n4 6\n1 5\n"], "outputs": ["4\n", "1\n", "1\n", "4\n", "40\n", "8\n", "8\n", "40\n"]} | coding | 464 |
Solve the programming task below in a Python markdown code block.
There's a chessboard of size $n \times n$. $m$ rooks are placed on it in such a way that:
no two rooks occupy the same cell;
no two rooks attack each other.
A rook attacks all cells that are in its row or column.
Is it possible to move exactly one ro... | {"inputs": ["2\n2 2\n1 2\n2 1\n3 1\n2 2\n", "3\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n", "17\n8 1\n1 1\n8 1\n1 1\n8 1\n1 1\n8 1\n1 1\n8 1\n1 1\n8 1\n1 1\n8 1\n1 1\n8 1\n1 1\n8 1\n1 1\n8 1\n1 1\n8 1\n1 1\n8 1\n1 1\n8 1\n1 1\n8 1\n1 1\n8 1\n1 1\n8 1\n1 1\n8 1\n1 1\n", "17\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1... | coding | 465 |
Solve the programming task below in a Python markdown code block.
Read problem statements in [Vietnamese],
[Bengali], [Mandarin Chinese], and [Russian] as well.
Chef is planning a heist in the reserve bank of Chefland. They are planning to hijack the bank for $D$ days and print the money. The initial rate of printing... | {"inputs": ["3\n2 1 1 1\n3 2 1 1\n5 2 1 2"], "outputs": ["3\n4\n13"]} | coding | 718 |
Solve the programming task below in a Python markdown code block.
Paul hates palindromes. He assumes that string s is tolerable if each its character is one of the first p letters of the English alphabet and s doesn't contain any palindrome contiguous substring of length 2 or more.
Paul has found a tolerable string s ... | {"inputs": ["1 2\na\n", "1 2\nb\n", "1 1\na\n", "1 3\na\n", "1 4\nb\n", "1 4\na\n", "2 2\nab\n", "2 4\ncd\n"], "outputs": ["b\n", "NO\n", "NO\n", "b\n", "c\n", "b\n", "ba\n", "da\n"]} | coding | 319 |
Solve the programming task below in a Python markdown code block.
Your task is to write a program of a simple dictionary which implements the following instructions:
* insert str: insert a string str in to the dictionary
* find str: if the distionary contains str, then print 'yes', otherwise print 'no'
Notes
Templat... | {"inputs": ["5\ninsert A\ninsert U\ninsert C\nfind G\nfind A", "5\ninsert B\ninsert T\ninsert C\nfind G\nfind A", "5\ninsert A\ninsert U\ninsert F\nfind F\nfind B", "5\ninsert A\ninsert U\ninsert D\nfind G\nfind A", "5\ninsert A\ninsert T\ninsert C\nfind G\nfind @", "5\ninsert A\ninsert U\ninsert D\nfind G\nfind B", "5... | coding | 249 |
Solve the programming task below in a Python markdown code block.
There are some animals in a garden. Each of them is a crane with two legs or a turtle with four legs.
Takahashi says: "there are X animals in total in the garden, and they have Y legs in total." Determine whether there is a combination of numbers of cran... | {"inputs": ["2 2", "6 8", "3 2", "3 1", "6 3", "5 1", "3 3", "5 2"], "outputs": ["No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n"]} | coding | 238 |
Solve the programming task below in a Python markdown code block.
When you look at photographs of watches and clocks, you'll find that they almost always show the time 10:10. There are lots of theories and even urban legends about this. For example, when showing 10:10, the hands look like a smile, and so you are more i... | {"inputs": ["2\n2 3\n3 3\n"], "outputs": ["3\n62\n"]} | coding | 445 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a 0-indexed integer array nums, return the smallest index i of nums such that i mod 10 == nums[i], or -1 if such index does not exist.
x mod y denotes the remainder when x is divided by y.
Please complete the ... | {"functional": "def check(candidate):\n assert candidate(nums = [0,1,2]) == 0\n assert candidate(nums = [4,3,2,1]) == 2\n assert candidate(nums = [1,2,3,4,5,6,7,8,9,0]) == -1\n assert candidate(nums = [2,1,3,5,2]) == 1\n\n\ncheck(Solution().smallestEqual)"} | coding | 99 |
Solve the programming task below in a Python markdown code block.
You are given a string S containing only lowercase characters.
You can rearrange the string and you have to print minimum number of characters needed(can be 0) to make it palindrome.
-----Input:-----
- First line contain an interger T denoting number o... | {"inputs": ["3\n1\na\n9\nabbbcbddd\n6\nabcdef"], "outputs": ["0\n2\n5"]} | coding | 253 |
Solve the programming task below in a Python markdown code block.
Memory and his friend Lexa are competing to get higher score in one popular computer game. Memory starts with score a and Lexa starts with score b. In a single turn, both Memory and Lexa get some integer in the range [ - k;k] (i.e. one integer among - k... | {"inputs": ["1 2 2 1\n", "1 1 1 2\n", "4 6 2 1\n", "4 6 2 2\n", "6 4 2 2\n", "5 3 1 1\n", "6 5 4 3\n", "1 8 1 4\n"], "outputs": ["6\n", "31\n", "3\n", "122\n", "435\n", "8\n", "282051\n", "1\n"]} | coding | 525 |
Solve the programming task below in a Python markdown code block.
You have k pieces of laundry, each of which you want to wash, dry and fold. You are at a laundromat that has n_1 washing machines, n_2 drying machines and n_3 folding machines. Each machine can process only one piece of laundry at a time. You can't dry a... | {"inputs": ["1 1 1 1 5 5 5\n", "5 2 4 5 9 9 6\n", "4 5 1 2 4 6 2\n", "1 3 2 2 5 2 8\n", "4 2 1 2 5 2 3\n", "4 2 1 2 5 2 3\n", "4 5 1 2 4 6 2\n", "5 2 4 5 9 9 6\n"], "outputs": ["15\n", "42\n", "30\n", "15\n", "17\n", "17", "30", "42"]} | coding | 539 |
Solve the programming task below in a Python markdown code block.
Chef Avi likes the number K. Given a list of N integers, help him find the sum of all distinct numbers repeating exactly K times. Each of those numbers should be considered only once in the sum, not K times.
------ Input Format ------
- First line wil... | {"inputs": ["3\n4 1\n2 3 4 4\n5 3\n9 9 1 1 9\n2 1\n2 2"], "outputs": ["5\n9\n-1"]} | coding | 327 |
Solve the programming task below in a Python markdown code block.
Snakeland is a well organised city. The houses of the city are organised in an orderly rectangular fashion with dimensions 2 * n, i.e. there are total two rows and n columns. The house in the i-th row and j-th column is also said to be the house at coord... | {"inputs": ["3\n2\n**\n**\n3\n***\n*..\n3\n*..\n.*."], "outputs": ["2\n3\n1"]} | coding | 523 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer array nums and an integer k, return the maximum length of a subarray that sums to k. If there is not one, return 0 instead.
Please complete the following python code precisely:
```python
class Solut... | {"functional": "def check(candidate):\n assert candidate(nums = [1,-1,5,-2,3], k = 3) == 4\n assert candidate(nums = [-2,-1,2,1], k = 1) == 2\n\n\ncheck(Solution().maxSubArrayLen)"} | coding | 88 |
Solve the programming task below in a Python markdown code block.
Ashish has an array a of consisting of 2n positive integers. He wants to compress a into an array b of size n-1. To do this, he first discards exactly 2 (any two) elements from a. He then performs the following operation until there are no elements left ... | {"inputs": ["3\n3\n1 2 3 4 5 6\n2\n5 7 9 6\n5\n1 3 3 4 5 90 100 101 2 3\n", "3\n3\n1 2 3 5 9 6\n2\n5 7 9 6\n5\n1 3 3 2 5 90 000 101 2 3\n", "3\n3\n1 2 3 5 9 6\n2\n5 7 9 6\n5\n1 3 3 2 5 90 000 100 2 3\n", "3\n3\n1 2 3 4 5 6\n2\n5 7 9 6\n5\n1 3 3 2 5 90 100 101 2 3\n", "3\n3\n1 2 3 4 5 6\n2\n5 7 9 6\n5\n1 3 3 2 5 90 000 ... | coding | 663 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
A binary watch has 4 LEDs on the top to represent the hours (0-11), and 6 LEDs on the bottom to represent the minutes (0-59). Each LED represents a zero or one, with the least significant bit on the right.
For exampl... | {"functional": "def check(candidate):\n assert candidate(turnedOn = 1) == [\"0:01\",\"0:02\",\"0:04\",\"0:08\",\"0:16\",\"0:32\",\"1:00\",\"2:00\",\"4:00\",\"8:00\"]\n assert candidate(turnedOn = 9) == []\n\n\ncheck(Solution().readBinaryWatch)"} | coding | 230 |
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 and two integers key and k. A k-distant index is an index i of nums for which there exists at least one index j such that |i - j| <= k and nums[j] == key.
Return a list of ... | {"functional": "def check(candidate):\n assert candidate(nums = [3,4,9,1,3,9,5], key = 9, k = 1) == [1,2,3,4,5,6]\n assert candidate(nums = [2,2,2,2,2], key = 2, k = 2) == [0,1,2,3,4]\n\n\ncheck(Solution().findKDistantIndices)"} | coding | 127 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.