task_type
stringclasses
1 value
problem
stringlengths
261
3.34k
answer
stringlengths
35
6.15k
problem_tokens
int64
62
774
answer_tokens
int64
12
2.04k
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. There are n flights that are labeled from 1 to n. You are given an array of flight bookings bookings, where bookings[i] = [firsti, lasti, seatsi] represents a booking for flights firsti through lasti (inclusive) with ...
{"functional": "def check(candidate):\n assert candidate(bookings = [[1,2,10],[2,3,20],[2,5,25]], n = 5) == [10,55,45,25,25]\n assert candidate(bookings = [[1,2,10],[2,2,15]], n = 2) == [10,25]\n\n\ncheck(Solution().corpFlightBookings)"}
142
107
coding
Solve the programming task below in a Python markdown code block. Very simple, given a number, find its opposite. Examples: ``` 1: -1 14: -14 -34: 34 ``` ~~~if:sql You will be given a table: `opposite`, with a column: `number`. Return a table with a column: `res`. ~~~ Also feel free to reuse/extend the following star...
{"functional": "_inputs = [[1], [25.6], [0], [1425.2222], [-3.1458], [-95858588225]]\n_outputs = [[-1], [-25.6], [0], [-1425.2222], [3.1458], [95858588225]]\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 ...
106
237
coding
Solve the programming task below in a Python markdown code block. A plurality of trampolines are arranged in a line at 10 m intervals. Each trampoline has its own maximum horizontal distance within which the jumper can jump safely. Starting from the left-most trampoline, the jumper jumps to another trampoline within th...
{"inputs": ["3\n7\n5\n9", "3\n4\n0\n9", "3\n4\n0\n4", "3\n4\n1\n4", "3\n3\n1\n4", "3\n3\n1\n2", "3\n3\n1\n1", "3\n3\n0\n1"], "outputs": ["no\n", "no\n", "no\n", "no\n", "no\n", "no\n", "no\n", "no\n"]}
319
110
coding
Solve the programming task below in a Python markdown code block. My grandfather always predicted how old people would get, and right before he passed away he revealed his secret! In honor of my grandfather's memory we will write a function using his formula! * Take a list of ages when each of your great-grandparent ...
{"functional": "_inputs = [[65, 60, 75, 55, 60, 63, 64, 45], [32, 54, 76, 65, 34, 63, 64, 45]]\n_outputs = [[86], [79]]\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 ...
275
220
coding
Solve the programming task below in a Python markdown code block. A series or sequence of numbers is usually the product of a function and can either be infinite or finite. In this kata we will only consider finite series and you are required to return a code according to the type of sequence: |Code|Type|Example| |-|...
{"functional": "_inputs = [[[3, 5, 8, 1, 14, 3]], [[3, 5, 8, 9, 14, 23]], [[3, 5, 8, 8, 14, 14]], [[14, 9, 8, 5, 3, 1]], [[14, 14, 8, 8, 5, 3]], [[8, 8, 8, 8, 8, 8]], [[8, 9]], [[8, 8, 8, 8, 8, 9]], [[9, 8]], [[9, 9, 9, 8, 8, 8]], [[3, 5, 8, 1, 14, 2]]]\n_outputs = [[0], [1], [2], [3], [4], [5], [1], [2], [3], [4], [0]...
335
364
coding
Solve the programming task below in a Python markdown code block. You are given an array A = [1, 2, 3, ..., n]: How many sequences ($S_{1}$) can you get after exact k adjacent swaps on A? How many sequences ($S_{2}$) can you get after at most k swaps on A? An adjacent swap can be made between two elements of...
{"inputs": ["3 2\n"], "outputs": ["3 6\n"]}
392
18
coding
Solve the programming task below in a Python markdown code block. There are N Reversi pieces arranged in a row. (A Reversi piece is a disc with a black side and a white side.) The state of each piece is represented by a string S of length N. If S_i=`B`, the i-th piece from the left is showing black; If S_i=`W`, the i-t...
{"inputs": ["BBX", "BXB", "BYB", "CYB", "CYA", "CAY", "CAX", "AYC"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
274
70
coding
Solve the programming task below in a Python markdown code block. Chef likes problems on geometry a lot. Please help him to solve one such problem. Find all possible triangles with integer sides which has the radius of inscribed circle (also known as incircle) equal to R. Two triangles are said to be different if they ...
{"inputs": ["2"], "outputs": ["5\n5 12 13\n6 8 10\n6 25 29\n7 15 20\n9 10 17"]}
367
51
coding
Solve the programming task below in a Python markdown code block. Problem A graph is given in which N vertices, each numbered from 1 to N, are connected by N-1 undirected edges. For each vertex, output the shortest number of steps to start from that vertex and visit all vertices. However, one step is to follow one si...
{"inputs": ["2\n1 2", "6\n1 2\n2 3\n3 4\n3 5\n5 6", "6\n1 2\n2 3\n6 4\n3 5\n5 6", "6\n1 2\n2 3\n6 4\n3 4\n5 6", "6\n1 2\n2 3\n3 4\n3 5\n1 6", "6\n1 2\n1 3\n3 4\n3 5\n3 6", "6\n1 2\n2 3\n3 4\n3 5\n2 6", "6\n1 2\n2 5\n6 4\n3 4\n5 6"], "outputs": ["1\n1", "6\n7\n8\n7\n7\n6\n", "5\n6\n7\n5\n7\n6\n", "5\n6\n7\n7\n5\n6\n", "...
281
277
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 2D integer array logs where each logs[i] = [birthi, deathi] indicates the birth and death years of the ith person. The population of some year x is the number of people alive during that year. The ith ...
{"functional": "def check(candidate):\n assert candidate(logs = [[1993,1999],[2000,2010]]) == 1993\n assert candidate(logs = [[1950,1961],[1960,1971],[1970,1981]]) == 1960\n\n\ncheck(Solution().maximumPopulation)"}
149
97
coding
Solve the programming task below in a Python markdown code block. The Little Elephant loves chess very much. One day the Little Elephant and his friend decided to play chess. They've got the chess pieces but the board is a problem. They've got an 8 × 8 checkered board, each square is painted either black or white. Th...
{"inputs": ["WBWBWBWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB\n", "WBWBWBWB\nWBWBWBWB\nBBWBWWWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWWW\nBWBWBWBW\nBWBWBWBW\n", "BWBWBWBW\nWBWBWBWB\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nWBWBWBWB\nWBWBWBWB\nWBWBWBWB\n", "BWBWBWBW\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB\nBWBWBWBW\nWBWBW...
591
402
coding
Solve the programming task below in a Python markdown code block. You have to build a pyramid. This pyramid should be built from characters from a given string. You have to create the code for these four methods: ```python watch_pyramid_from_the_side(characters): watch_pyramid_from_above(characters): count_visible_...
{"functional": "_inputs = [[None], ['']]\n_outputs = [[None], ['']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n ret...
467
163
coding
Solve the programming task below in a Python markdown code block. You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a good string when the following conditions are all met: * Let L be the length of X. L is divisible by both ...
{"inputs": ["3 2\nacq\nae", "1 2\nacq\nae", "4 1\nabq\nae", "1 1\n`br\n`e", "5 2\naar\nae", "5 1\nacp\nae", "5 3\naar\nae", "7 2\n`ar\n`e"], "outputs": ["6\n", "2\n", "4\n", "1\n", "10\n", "5\n", "15\n", "14\n"]}
373
121
coding
Solve the programming task below in a Python markdown code block. # Task Write a function named `sumEvenNumbers`, taking a sequence of numbers as single parameter. Your function must return the sum of **the even values** of this sequence. Only numbers without decimals like `4` or `4.0` can be even. ## Input * seque...
{"functional": "_inputs = [[[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]], [[]], [[1337, 374, 849, 22.5, 19, 16, 0, 0, 16, 32]], [[-16, -32, 20, 21, 41, 42]], [[15397, 12422, 10495, 22729, 23921, 18326, 27955, 24073, 23690, 15002, 11615, 15682, 24346, 16725, 17252, 20467, 20493, 17807, 13041, 25861, 22471, 22747, 24082, 18979, 2854...
172
975
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a positive integer n which is the number of nodes of a 0-indexed undirected weighted connected graph and a 0-indexed 2D array edges where edges[i] = [ui, vi, wi] indicates that there is an edge between n...
{"functional": "def check(candidate):\n assert candidate(n = 4, edges = [[0,1,4],[0,2,2],[2,3,6]], s = 1, d = 3, k = 2) == 2\n assert candidate(n = 7, edges = [[3,1,9],[3,2,4],[4,0,9],[0,5,6],[3,6,2],[6,0,4],[1,2,4]], s = 4, d = 1, k = 2) == 6\n assert candidate(n = 5, edges = [[0,4,2],[0,1,3],[0,2,1],[2,1,4],...
212
209
coding
Solve the programming task below in a Python markdown code block. You are given an integer N. Find the number of distinct XORs it is possible to make using two positive integers no larger than N. Formally, let S be the set S = \{x\oplus y \mid 1 ≤ x, y ≤ N\} where \oplus denotes the [bitwise XOR] operation. Find |S...
{"inputs": ["3\n1\n3\n7"], "outputs": ["1\n4\n8"]}
369
22
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. The alternating sum of a 0-indexed array is defined as the sum of the elements at even indices minus the sum of the elements at odd indices. For example, the alternating sum of [4,2,5,3] is (4 + 5) - (2 + 3) = 4. Gi...
{"functional": "def check(candidate):\n assert candidate(nums = [4,2,5,3]) == 7\n assert candidate(nums = [5,6,7,8]) == 8\n assert candidate(nums = [6,2,1,2,4,5]) == 10\n\n\ncheck(Solution().maxAlternatingSum)"}
222
80
coding
Solve the programming task below in a Python markdown code block. Three companies decided to order a billboard with pictures of their logos. A billboard is a big square board. A logo of each company is a rectangle of a non-zero area. Advertisers will put up the ad only if it is possible to place all three logos on th...
{"inputs": ["5 1 2 5 5 2\n", "4 4 2 6 4 2\n", "1 3 1 3 3 1\n", "2 4 1 4 1 4\n", "7 2 7 2 7 3\n", "2 1 3 1 2 2\n", "1 2 2 4 3 2\n", "7 4 3 3 4 3\n"], "outputs": ["5\nAAAAA\nBBBBB\nBBBBB\nCCCCC\nCCCCC\n", "6\nBBBBBB\nBBBBBB\nAAAACC\nAAAACC\nAAAACC\nAAAACC\n", "3\nAAA\nBBB\nCCC\n", "4\nAAAA\nAAAA\nBBBB\nCCCC\n", "7\nAAAAA...
535
262
coding
Solve the programming task below in a Python markdown code block. There are N cards on a table, out of which X cards are face-up and the remaining are face-down. In one operation, we can do the following: Select any one card and flip it (i.e. if it was initially face-up, after the operation, it will be face-down and v...
{"inputs": ["4\n5 0\n4 2\n3 3\n10 2\n"], "outputs": ["0\n2\n0\n2\n"]}
402
37
coding
Solve the programming task below in a Python markdown code block. You are given a matrix with $n$ rows (numbered from $1$ to $n$) and $m$ columns (numbered from $1$ to $m$). A number $a_{i, j}$ is written in the cell belonging to the $i$-th row and the $j$-th column, each number is either $0$ or $1$. A chip is initial...
{"inputs": ["1\n6 4\n0 1 1 0\n0 1 1 0\n0 1 1 0\n0 1 1 0\n1 1 1 1\n1 1 1 1\n", "1\n6 4\n0 1 1 0\n0 1 1 0\n0 1 1 0\n0 1 1 0\n1 1 1 1\n1 1 1 1\n", "1\n6 4\n0 1 1 1\n0 1 1 0\n0 1 1 0\n0 1 1 0\n1 1 1 1\n1 1 1 1\n", "1\n6 4\n0 1 1 0\n0 1 1 0\n1 1 1 0\n0 1 1 0\n1 1 1 1\n1 1 0 1\n", "1\n6 4\n0 1 1 0\n1 1 1 0\n1 1 1 0\n0 1 1 0\...
711
486
coding
Solve the programming task below in a Python markdown code block. A group of university students wants to get to the top of a mountain to have a picnic there. For that they decided to use a cableway. A cableway is represented by some cablecars, hanged onto some cable stations by a cable. A cable is scrolled cyclically...
{"inputs": ["1 2 2\n", "1 2 1\n", "2 0 0\n", "2 1 1\n", "0 2 1\n", "5 4 5\n", "2 0 2\n", "2 1 2\n"], "outputs": ["32", "32", "30", "32", "32", "38", "32", "32"]}
625
102
coding
Solve the programming task below in a Python markdown code block. PizzaForces is Petya's favorite pizzeria. PizzaForces makes and sells pizzas of three sizes: small pizzas consist of $6$ slices, medium ones consist of $8$ slices, and large pizzas consist of $10$ slices each. Baking them takes $15$, $20$ and $25$ minute...
{"inputs": ["1\n6\n", "1\n9\n", "1\n66\n", "1\n45\n", "1\n12\n", "1\n213\n", "1\n129\n", "1\n216\n"], "outputs": ["15\n", "25\n", "165\n", "115\n", "30\n", "535\n", "325\n", "540\n"]}
659
108
coding
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 ...
415
183
coding
Solve the programming task below in a Python markdown code block. Professor Vasechkin is studying evolution of worms. Recently he put forward hypotheses that all worms evolve by division. There are n forms of worms. Worms of these forms have lengths a1, a2, ..., an. To prove his theory, professor needs to find 3 differ...
{"inputs": ["3\n2 2 4\n", "3\n2 4 4\n", "3\n2 4 100\n", "3\n2 6 100\n", "5\n1 8 1 4 1\n", "5\n1 8 1 6 1\n", "5\n1 2 3 5 7\n", "5\n1 8 1 5 1\n"], "outputs": ["3 1 2\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "3 1 2", "-1\n"]}
256
145
coding
Solve the programming task below in a Python markdown code block. Jerry is a little mouse. He is trying to survive from the cat Tom. Jerry is carrying a parallelepiped-like piece of cheese of size A × B × C. It is necessary to trail this cheese to the Jerry's house. There are several entrances in the Jerry's house. Eac...
{"inputs": ["7 6 0\n5\n4\n0\n0\n2\n5\n0 0 0", "7 3 0\n5\n4\n0\n0\n2\n5\n0 0 0", "7 3 1\n5\n4\n0\n0\n2\n5\n0 0 0", "10 6 8\n5\n4\n1\n6\n2\n5\n0 0 0", "10 6 8\n5\n4\n0\n0\n2\n5\n0 0 0", "10 6 8\n5\n4\n0\n0\n2\n7\n0 0 0", "10 6 8\n5\n1\n8\n6\n2\n5\n0 0 0", "10 3 8\n5\n4\n0\n6\n2\n5\n0 0 0"], "outputs": ["OK\nNA\nNA\nNA\nO...
294
307
coding
Solve the programming task below in a Python markdown code block. Snuke is interested in strings that satisfy the following conditions: * The length of the string is at least N. * The first N characters equal to the string s. * The last N characters equal to the string t. Find the length of the shortest string that...
{"inputs": ["1\na\n{", "1\n`\nz", "1\n`\n{", "1\n`\n|", "1\n`\n}", "1\n`\n~", "1\n_\n~", "1\n_\n\u007f"], "outputs": ["2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n"]}
176
96
coding
Solve the programming task below in a Python markdown code block. A *Vampire number* is a positive integer `z` with a factorization `x * y = z` such that - `x` and `y` have the same number of digits and - the multiset of digits of `z` is equal to the multiset of digits of `x` and `y`. - Additionally, to avoid triviali...
{"functional": "_inputs = [[10], [100], [155]]\n_outputs = [[105210], [336960], [939658]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): ret...
322
187
coding
Solve the programming task below in a Python markdown code block. Adam is standing at point $(a,b)$ in an infinite 2D grid. He wants to know if he can reach point $(x,y)$ or not. The only operation he can do is to move to point $(a+b,b),(a,a+b),(a-b,b),\text{or}(a,b-a)$ from some point $(a,b)$. It is given that he can ...
{"inputs": ["3\n1 1 2 3\n2 1 2 3\n3 3 1 1\n"], "outputs": ["YES\nYES\nNO\n"]}
325
42
coding
Solve the programming task below in a Python markdown code block. You are given an array $a$ of $n$ ($n \geq 2$) positive integers and an integer $p$. Consider an undirected weighted graph of $n$ vertices numbered from $1$ to $n$ for which the edges between the vertices $i$ and $j$ ($i<j$) are added in the following ma...
{"inputs": ["1\n2 1000000000\n1000000000 1000000000\n", "1\n2 1000000000\n1000000000 1000000000\n", "1\n2 1100000000\n1000000000 1000000000\n", "1\n2 1100000000\n1000000000 1100000000\n", "1\n2 1100000001\n1000000011 1001000000\n", "1\n2 1100000011\n1000000011 1001000000\n", "1\n2 1100100011\n1000000111 1001000000\n", ...
613
422
coding
Solve the programming task below in a Python markdown code block. After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer. At the start of the day they have x ice cream packs. Since the ice cream is free, people start standing in the queue be...
{"inputs": ["1 0\n+ 1\n", "1 0\n- 1\n", "1 3\n- 5\n", "1 0\n- 5\n", "1 0\n+ 5\n", "1 0\n+ 1\n", "1 0\n- 5\n", "1 3\n- 5\n"], "outputs": ["1 0\n", "0 1\n", "3 1\n", "0 1\n", "5 0\n", "1 0\n", "0 1\n", "3 1\n"]}
592
134
coding
Solve the programming task below in a Python markdown code block. Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya loves long lucky numbers v...
{"inputs": ["3 3 2 2\n", "4 4 2 2\n", "8 3 2 1\n", "4 3 2 1\n", "4 4 1 1\n", "2 1 3 1\n", "6 6 1 3\n", "1 4 1 1\n"], "outputs": ["474774", "44747774", "44444447477", "4447477", "44477774", "-1", "-1", "74777"]}
382
149
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given the root of a binary search tree, rearrange the tree in in-order so that the leftmost node in the tree is now the root of the tree, and every node has no left child and only one right child.   Please complete th...
{"functional": "def check(candidate):\n assert is_same_tree(candidate(root = tree_node([5,3,6,2,4,None,8,1,None,None,None,7,9])), tree_node([1,None,2,None,3,None,4,None,5,None,6,None,7,None,8,None,9]))\n assert is_same_tree(candidate(root = tree_node([5,1,7])), tree_node([1,None,5,None,7]))\n\n\ncheck(Solution()....
145
114
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an array start where start = [startX, startY] represents your initial position (startX, startY) in a 2D space. You are also given the array target where target = [targetX, targetY] represents your target...
{"functional": "def check(candidate):\n assert candidate(start = [1,1], target = [4,5], specialRoads = [[1,2,3,3,2],[3,4,4,5,1]]) == 5\n assert candidate(start = [3,2], target = [5,7], specialRoads = [[3,2,3,4,4],[3,3,5,5,5],[3,4,5,6,6]]) == 7\n\n\ncheck(Solution().minimumCost)"}
281
121
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. You are given a tree consisting of n nodes numbered from 1 to n. The weights of edges of the tree can be any binary integer satisfying following Q conditions. Each conditi...
{"inputs": ["3\n3 2\n1 2\n1 3\n1 2 0\n1 3 0\n3 0\n1 2\n2 3\n3 1\n1 2\n2 3\n1 2 1"], "outputs": ["1\n4\n2"]}
670
70
coding
Solve the programming task below in a Python markdown code block. You are given a function $f$ written in some basic language. The function accepts an integer value, which is immediately written into some variable $x$. $x$ is an integer variable and can be assigned values from $0$ to $2^{32}-1$. The function contains t...
{"inputs": ["1\nadd\n", "1\nadd\n", "2\nfor 4\nend\n", "2\nfor 62\nend\n", "2\nfor 15\nend\n", "2\nfor 14\nend\n", "2\nfor 16\nend\n", "2\nfor 24\nend\n"], "outputs": ["1\n", "1\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
640
115
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian. Chef has N simple polygons (non self intersecting polygons) in which no two of them intersect with each other. For any two polygons P_{1}, P_{2}, either P_{1} lies inside P_{2} or vice versa. C...
{"inputs": ["1\n3\n6\n0 4 -1 1 4 1 0 -1 1 -2 -3 -2\n2\n0 -1 1 0 1 0\n2\n3 3 0 1 -3 -3 3 -3", "1\n2\n6\n0 4 -1 1 2 1 0 -1 1 0 -3 0\n3\n-2 -1 0 0 1 0\n2\n6 3 -1 1 -1 -3 3 -3", "1\n2\n5\n-1 4 -1 1 2 2 0 -1 1 0 0 0\n3\n-3 -1 0 -1 1 0\n2\n6 3 0 1 -2 -3 6 -3", "1\n2\n6\n0 4 -1 1 2 1 0 -1 0 0 -3 0\n3\n-2 -1 0 0 1 0\n2\n6 3 -1...
534
569
coding
Solve the programming task below in a Python markdown code block. Gag Segtree has $ N $ of "gags", each with a value of $ V_i $. Segtree decided to publish all the gags in any order. Here, the "joy" you get when you publish the $ i $ th gag to the $ j $ th is expressed as $ V_i --j $. Find the maximum sum of the "j...
{"inputs": ["1\n2", "1\n1", "1\n4", "1\n6", "1\n7", "1\n9", "1\n3", "1\n8"], "outputs": ["1\n", "0\n", "3\n", "5\n", "6\n", "8\n", "2\n", "7\n"]}
282
78
coding
Solve the programming task below in a Python markdown code block. # Description Write a function that accepts the current position of a knight in a chess board, it returns the possible positions that it will end up after 1 move. The resulted should be sorted. ## Example "a1" -> ["b3", "c2"] Also feel free to reuse/...
{"functional": "_inputs = [['a1'], ['f7'], ['c3']]\n_outputs = [[['b3', 'c2']], [['d6', 'd8', 'e5', 'g5', 'h6', 'h8']], [['a2', 'a4', 'b1', 'b5', 'd1', 'd5', 'e2', 'e4']]]\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, ab...
90
227
coding
Solve the programming task below in a Python markdown code block. You have a grid with N rows and M columns. You have two types of tiles — one of dimensions 2 \times 2 and the other of dimensions 1 \times 1. You want to cover the grid using these two types of tiles in such a way that: Each cell of the grid is covered b...
{"inputs": ["4\n1 1\n4 5\n6 8\n3 2\n\n"], "outputs": ["1\n4\n0\n2\n"]}
383
37
coding
Solve the programming task below in a Python markdown code block. Write a simple function that takes polar coordinates (an angle in degrees and a radius) and returns the equivalent cartesian coordinates (rouded to 10 places). ``` For example: coordinates(90,1) => (0.0, 1.0) coordinates(45, 1) => (0.7071067812, 0.707...
{"functional": "_inputs = [[90, 1], [90, 2], [0, 1], [45, 1], [1090, 10000], [-270, 1]]\n_outputs = [[[0.0, 1.0]], [[0.0, 2.0]], [[1.0, 0.0]], [[0.7071067812, 0.7071067812]], [[9848.0775301221, 1736.4817766693]], [[0.0, 1.0]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, flo...
130
297
coding
Solve the programming task below in a Python markdown code block. Polycarp found $n$ segments on the street. A segment with the index $i$ is described by two integers $l_i$ and $r_i$ — coordinates of the beginning and end of the segment, respectively. Polycarp realized that he didn't need all the segments, so he wanted...
{"inputs": ["7\n1\n1 2\n1\n1 2\n1\n1 2\n1\n1 2\n1\n1 2\n1\n1 2\n1\n1 2\n", "7\n1\n1 2\n1\n1 2\n1\n1 2\n1\n1 2\n1\n1 2\n1\n1 2\n1\n1 2\n", "7\n1\n1 2\n1\n1 2\n1\n1 2\n1\n1 2\n1\n1 2\n1\n1 2\n1\n1 1\n", "7\n1\n1 2\n1\n1 2\n1\n1 2\n1\n1 2\n1\n1 2\n1\n1 2\n1\n1 3\n", "7\n1\n1 2\n1\n1 2\n1\n1 2\n1\n2 2\n1\n1 2\n1\n1 2\n1\n1...
563
502
coding
Solve the programming task below in a Python markdown code block. Two foxes Jiro and Saburo are playing a game called 1D Reversi. This game is played on a board, using black and white stones. On the board, stones are placed in a row, and each player places a new stone to either end of the row. Similarly to the original...
{"inputs": ["BWBBW", "WWBBB", "WBBWB", "WBBXB", "BXBBW", "BXBWB", "BXWBB", "WXBBB"], "outputs": ["3\n", "1\n", "3\n", "3\n", "3\n", "4\n", "3\n", "2\n"]}
427
78
coding
Solve the programming task below in a Python markdown code block. There are N bags of biscuits. The i-th bag contains A_i biscuits. Takaki will select some of these bags and eat all of the biscuits inside. Here, it is also possible to select all or none of the bags. He would like to select bags so that the total numb...
{"inputs": ["1 1\n67", "1 1\n42", "1 1\n50", "2 0\n1 1", "2 0\n1 3", "3 1\n1 1 1", "3 0\n1 1 1", "45 1\n6 55 85 55 74 20 90 67 40 70 39 89 91 50 16 24 14 43 24 8 25 9 89 45 41 16 3 11 61 8 167 72 62 67 42 26 36 66 4 87 59 91 4 24 4"], "outputs": ["1\n", "0\n", "0", "2\n", "2", "4\n", "4", "17592186044416\n"]}
388
246
coding
Solve the programming task below in a Python markdown code block. Complete the square sum function so that it squares each number passed into it and then sums the results together. For example, for `[1, 2, 2]` it should return `9` because `1^2 + 2^2 + 2^2 = 9`. ```if:racket In Racket, use a list instead of an array, ...
{"functional": "_inputs = [[[1, 2]], [[0, 3, 4, 5]], [[]], [[-1, -2]], [[-1, 0, 1]]]\n_outputs = [[5], [50], [0], [5], [2]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):...
126
201
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Return the number of permutations of 1 to n so that prime numbers are at prime indices (1-indexed.) (Recall that an integer is prime if and only if it is greater than 1, and cannot be written as a product of two posit...
{"functional": "def check(candidate):\n assert candidate(n = 5) == 12\n assert candidate(n = 100) == 682289015\n\n\ncheck(Solution().numPrimeArrangements)"}
130
57
coding
Solve the programming task below in a Python markdown code block. You are given a string, $\mbox{S}$, consisting of lowercase English letters. A string is beautiful with respect to $\mbox{S}$ if it can be derived from $\mbox{S}$ by removing exactly $2$ characters. Find and print the number of different strings that a...
{"inputs": ["abba\n"], "outputs": ["4\n"]}
308
15
coding
Solve the programming task below in a Python markdown code block. Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya has two strings a and b of...
{"inputs": ["7\n4\n", "7\n7\n", "4\n7\n", "4\n4\n", "4\n46\n", "47\n77\n", "47\n47\n", "47\n44\n"], "outputs": ["1\n", "0\n", "1\n", "0\n", "0\n", "1\n", "0\n", "1\n"]}
342
93
coding
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)"}
263
55
coding
Solve the programming task below in a Python markdown code block. Format any integer provided into a string with "," (commas) in the correct places. **Example:** ``` csharp Kata.NumberFormat(100000); // return "100,000" Kata.NumberFormat(5678545); // return "5,678,545" Kata.NumberFormat(-420902); // return "-420,902" ...
{"functional": "_inputs = [[100000], [5678545], [-420902], [-3], [-1003]]\n_outputs = [['100,000'], ['5,678,545'], ['-420,902'], ['-3'], ['-1,003']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isin...
489
221
coding
Solve the programming task below in a Python markdown code block. Chloe, the same as Vladik, is a competitive programmer. She didn't have any problems to get to the olympiad like Vladik, but she was confused by the task proposed on the olympiad. Let's consider the following algorithm of generating a sequence of intege...
{"inputs": ["3 2\n", "4 8\n", "1 1\n", "3 3\n", "1 1\n", "3 3\n", "2 3\n", "4 5\n"], "outputs": ["2", "4", "1", "1", "1\n", "1\n", "1\n", "1\n"]}
415
82
coding
Solve the programming task below in a Python markdown code block. You are given two strings $S$ and $R$. Each of these strings has length $N$. We want to make $S$ equal to $R$ by performing the following operation some number of times (possibly zero): - Choose two integers $a$ and $b$ such that $1 \le a \le b \le N$. -...
{"inputs": ["1\nadefb\nbdefa"], "outputs": ["4"]}
496
20
coding
Solve the programming task below in a Python markdown code block. Chef has a number N, Cheffina challenges the chef to check the divisibility of all the permutation of N by 5. If any of the permutations is divisible by 5 then print 1 else print 0. -----Input:----- - First-line will contain $T$, the number of test case...
{"inputs": ["2\n19\n385"], "outputs": ["0\n1"]}
176
21
coding
Solve the programming task below in a Python markdown code block. Pak Chanek has $n$ two-dimensional slices of cheese. The $i$-th slice of cheese can be represented as a rectangle of dimensions $a_i \times b_i$. We want to arrange them on the two-dimensional plane such that: Each edge of each cheese is parallel to eit...
{"inputs": ["1\n1\n420 420\n", "3\n4\n4 1\n4 5\n1 1\n2 3\n3\n2 4\n2 6\n2 3\n1\n2 65\n"], "outputs": ["1680\n", "26\n24\n134\n"]}
647
82
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. An array is monotonic if it is either monotone increasing or monotone decreasing. An array nums is monotone increasing if for all i <= j, nums[i] <= nums[j]. An array nums is monotone decreasing if for all i <= j, num...
{"functional": "def check(candidate):\n assert candidate(nums = [1,2,2,3]) == True\n assert candidate(nums = [6,5,4,4]) == True\n assert candidate(nums = [1,3,2]) == False\n\n\ncheck(Solution().isMonotonic)"}
129
70
coding
Solve the programming task below in a Python markdown code block. How to make a cake you'll never eat. Ingredients. * 2 carrots * 0 calories * 100 g chocolate spread * 1 pack of flour * 1 egg Method. 1. Put calories into the mixing bowl. 2. Take carrots from refrigerator. 3. Chop carrots. 4. T...
{"inputs": ["4 1 1 3 4\n", "4 2 1 3 4\n", "4 1 2 3 4\n", "3 452 979 51\n", "3 287 979 395\n", "3 887 104 641\n", "3 452 979 395\n", "4 802 765 992 1\n"], "outputs": ["28\n", "29\n", "30", "2563\n", "3430", "3018", "3595\n", "5312"]}
293
169
coding
Solve the programming task below in a Python markdown code block. You know that 1 kg of pulp can be used to make 1000 pages and 1 notebook consists of 100 pages. Suppose a notebook factory receives N kg of pulp, how many notebooks can be made from that? ------ Input Format ------ - First line will contain T, the n...
{"inputs": ["3\n1\n100\n50\n"], "outputs": ["10\n1000\n500\n"]}
319
33
coding
Solve the programming task below in a Python markdown code block. Team Red and Team Blue competed in a competitive FPS. Their match was streamed around the world. They played a series of $n$ matches. In the end, it turned out Team Red won $r$ times and Team Blue won $b$ times. Team Blue was less skilled than Team Red,...
{"inputs": ["3\n7 4 3\n6 5 1\n19 13 6\n", "6\n3 2 1\n10 6 4\n11 6 5\n10 9 1\n10 8 2\n11 9 2\n"], "outputs": ["RBRBRBR\nRRRBRR\nRRBRRBRRBRRBRRBRRBR\n", "RBR\nRRBRBRBRBR\nRBRBRBRBRBR\nRRRRRBRRRR\nRRRBRRRBRR\nRRRBRRRBRRR\n"]}
579
136
coding
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 number of distinct quadruplets (a, b, c, d) such that: nums[a] + nums[b] + nums[c] == nums[d], and a < b < c < d   Please complete the following python code precisely...
{"functional": "def check(candidate):\n assert candidate(nums = [1,2,3,6]) == 1\n assert candidate(nums = [3,3,6,4,5]) == 0\n assert candidate(nums = [1,1,1,3,5]) == 4\n\n\ncheck(Solution().countQuadruplets)"}
106
80
coding
Solve the programming task below in a Python markdown code block. You have a rectangular chocolate bar consisting of n × m single squares. You want to eat exactly k squares, so you may need to break the chocolate bar. In one move you can break any single rectangular piece of chocolate in two rectangular pieces. You c...
{"inputs": ["4\n2 2 1\n2 2 3\n2 2 2\n2 2 4\n", "4\n2 2 1\n2 2 1\n2 2 2\n2 2 4\n", "4\n2 2 2\n2 2 1\n2 2 2\n2 2 4\n", "4\n2 2 4\n2 2 1\n2 2 2\n2 2 4\n", "4\n2 1 1\n2 2 3\n2 2 2\n2 2 4\n", "4\n2 1 1\n2 2 3\n2 2 2\n4 2 4\n", "4\n2 2 2\n2 2 1\n4 2 2\n2 2 2\n", "4\n2 1 1\n2 3 3\n2 2 2\n4 2 8\n"], "outputs": ["5\n5\n4\n0\n",...
524
310
coding
Solve the programming task below in a Python markdown code block. Problem statement Meatishi can increase or decrease the number of fingers. There are n buns in front of Nikunishi-kun. Meatishi is trying to count the number of steamed buns by breaking his finger. There are only two shapes that Nishikun's fingers can t...
{"inputs": ["1", "2", "4", "9", "3", "7", "5", "6"], "outputs": ["1\n", "2\n", "3\n", "4\n", "2\n", "3\n", "3\n", "3\n"]}
264
62
coding
Solve the programming task below in a Python markdown code block. # Don't give me five! In this kata you get the start number and the end number of a region and should return the count of all numbers except numbers with a 5 in it. The start and the end number are both inclusive! Examples: ``` 1,9 -> 1,2,3,4,6,7,8,9 ...
{"functional": "_inputs = [[1, 9], [4, 17], [1, 90], [-4, 17], [-4, 37], [-14, -1], [-14, -6]]\n_outputs = [[8], [12], [72], [20], [38], [13], [9]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isins...
249
226
coding
Solve the programming task below in a Python markdown code block. There are 100 questions in a paper. Each question carries +3 marks for correct answer, -1 marks for incorrect answer and 0 marks for unattempted question. It is given that Chef received exactly X (0 ≤ X ≤ 100) marks. Determine the minimum number of prob...
{"inputs": ["4\n0\n100\n32\n18\n"], "outputs": ["0\n2\n1\n0\n"]}
318
32
coding
Solve the programming task below in a Python markdown code block. Sometimes it is hard to prepare tests for programming problems. Now Bob is preparing tests to new problem about strings — input data to his problem is one string. Bob has 3 wrong solutions to this problem. The first gives the wrong answer if the input da...
{"inputs": ["ab\ncc\ncd\n", "ab\ncc\ndd\n", "ab\ncc\ndc\n", "ba\ncc\ndd\n", "aa\ncc\ndd\n", "aa\ndc\ndd\n", "aa\ndc\ncd\n", "aa\ndc\nbd\n"], "outputs": ["5\n", "6\n", "5\n", "6\n", "6\n", "5\n", "5\n", "5\n"]}
235
112
coding
Solve the programming task below in a Python markdown code block. Your boss decided to save money by purchasing some cut-rate optical character recognition software for scanning in the text of old novels to your database. At first it seems to capture words okay, but you quickly notice that it throws in a lot of numbers...
{"functional": "_inputs = [[''], ['! !'], ['123456789'], ['(E3at m2e2!!)'], ['Dsa32 cdsc34232 csa!!! 1I 4Am cool!'], ['A1 A1! AAA 3J4K5L@!!!'], ['Adgre2321 A1sad! A2A3A4 fv3fdv3J544K5L@'], ['Ad2dsad3ds21 A 1$$s122ad! A2A3Ae24 f44K5L@222222 '], ['33333Ad2dsad3ds21 A3333 1$$s122a!d! A2!A!3Ae$24 f2##222 '], ['My \"me3...
206
525
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer array nums, return 0 if the sum of the digits of the minimum integer in nums is odd, or 1 otherwise.   Please complete the following python code precisely: ```python class Solution: def sumOfDigit...
{"functional": "def check(candidate):\n assert candidate([34,23,1,24,75,33,54,8]) == 0\n assert candidate([99,77,33,66,55]) == 1\n\n\ncheck(Solution().sumOfDigits)"}
78
73
coding
Solve the programming task below in a Python markdown code block. You are given two positive integers $a$ and $b$. In one move, you can change $a$ in the following way: Choose any positive odd integer $x$ ($x > 0$) and replace $a$ with $a+x$; choose any positive even integer $y$ ($y > 0$) and replace $a$ with $a-y...
{"inputs": ["1\n164 94\n", "1\n224 94\n", "1\n80398 6\n", "1\n76711 6\n", "1\n76711 2\n", "1\n22528 2\n", "1\n22528 1\n", "1\n27854 1\n"], "outputs": ["1\n", "1\n", "1\n", "2\n", "2\n", "1\n", "2\n", "2\n"]}
423
132
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Mandarin], [Vietnamese], and [Russian] as well. Alice and Bob play the classic game of odds and evens. In this game, each of the two players choose a number between 1 and 5 without revealing to their opponent. Both of the pla...
{"inputs": ["2\n1 1\n1 2\n"], "outputs": ["Bob\nAlice\n"]}
346
24
coding
Solve the programming task below in a Python markdown code block. There is an ice cream shop named Ten Ice Cream. At this store, we always have 10 types of ice cream on the shelves. The store manager creates a daily graph showing how well ice cream is selling for reference in product development. For such a store mana...
{"inputs": ["15\n2\n6\n7\n0\n1\n9\n8\n7\n3\n8\n9\n4\n8\n4\n2\n3\n9\n1\n5\n0", "15\n2\n6\n7\n0\n0\n9\n8\n7\n3\n8\n9\n4\n8\n2\n2\n3\n9\n1\n5\n0", "15\n2\n6\n7\n0\n1\n9\n8\n7\n3\n8\n9\n4\n8\n4\n2\n3\n9\n1\n2\n0", "15\n2\n6\n7\n0\n0\n9\n8\n7\n3\n8\n9\n8\n8\n2\n2\n3\n9\n1\n5\n0", "15\n2\n6\n7\n0\n1\n9\n8\n7\n3\n8\n9\n4\n8\n...
366
731
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed array of integers nums of length n. You are initially positioned at nums[0]. Each element nums[i] represents the maximum length of a forward jump from index i. In other words, if you are at n...
{"functional": "def check(candidate):\n assert candidate(nums = [2,3,1,1,4]) == 2\n assert candidate(nums = [2,3,0,1,4]) == 2\n\n\ncheck(Solution().jump)"}
157
58
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. In MATLAB, there is a handy function called reshape which can reshape an m x n matrix into a new one with a different size r x c keeping its original data. You are given an m x n matrix mat and two integers r and c re...
{"functional": "def check(candidate):\n assert candidate(mat = [[1,2],[3,4]], r = 1, c = 4) == [[1,2,3,4]]\n assert candidate(mat = [[1,2],[3,4]], r = 2, c = 4) == [[1,2],[3,4]]\n\n\ncheck(Solution().matrixReshape)"}
179
92
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. In LeetCode Store, there are n items to sell. Each item has a price. However, there are some special offers, and a special offer consists of one or more different kinds of items with a sale price. You are given an int...
{"functional": "def check(candidate):\n assert candidate(price = [2,5], special = [[3,0,5],[1,2,10]], needs = [3,2]) == 14\n assert candidate(price = [2,3,4], special = [[1,1,0,4],[2,2,1,9]], needs = [1,2,1]) == 11\n\n\ncheck(Solution().shoppingOffers)"}
270
102
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer n and an integer array rounds. We have a circular track which consists of n sectors labeled from 1 to n. A marathon will be held on this track, the marathon consists of m rounds. The ith round starts ...
{"functional": "def check(candidate):\n assert candidate(n = 4, rounds = [1,3,1,2]) == [1,2]\n assert candidate(n = 2, rounds = [2,1,2,1,2,1,2,1,2]) == [2]\n assert candidate(n = 7, rounds = [1,3,5,7]) == [1,2,3,4,5,6,7]\n\n\ncheck(Solution().mostVisited)"}
174
115
coding
Solve the programming task below in a Python markdown code block. You are given a string s consisting only of characters 0 and 1. A substring [l, r] of s is a string s_{l}s_{l} + 1s_{l} + 2... s_{r}, and its length equals to r - l + 1. A substring is called balanced if the number of zeroes (0) equals to the number of o...
{"inputs": ["2\n10\n", "2\n01\n", "2\n01\n", "2\n10\n", "3\n111\n", "3\n011\n", "3\n110\n", "3\n001\n"], "outputs": ["2\n", "2\n", "2\n", "2\n", "0\n", "2\n", "2\n", "2\n"]}
284
98
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. A magical string s consists of only '1' and '2' and obeys the following rules: The string s is magical because concatenating the number of contiguous occurrences of characters '1' and '2' generates the string s itsel...
{"functional": "def check(candidate):\n assert candidate(n = 6) == 3\n assert candidate(n = 1) == 1\n\n\ncheck(Solution().magicalString)"}
253
44
coding
Solve the programming task below in a Python markdown code block. ByteLand is a large country with a tree-like road system. It has $N$ cities and $(N-1)$ unidirected roads. The capital of ByteLand is a city, numbered $\mbox{1}$, and all the roads go away from the capital. So people use these roads to reach any city fro...
{"inputs": ["5 2\n1 2 1 2 1\n1 2\n2 3\n3 4\n4 5\n2 4\n2 5\n"], "outputs": ["2\n3\n"]}
691
52
coding
Solve the programming task below in a Python markdown code block. Motu and Patlu are playing with a Magical Ball. Patlu find some interesting pattern in the motion of the ball that ball always bounce back from the ground after travelling a linear distance whose value is some power of $2$. Patlu gave Motu total distance...
{"inputs": ["1\n13"], "outputs": ["2"]}
241
15
coding
Solve the programming task below in a Python markdown code block. John is new to Mathematics and does not know how to calculate GCD of numbers. So he wants you to help him in a few GCD calculations. John has a list A of numbers, indexed 1 to N. He wants to create another list B having N+1 numbers, indexed from 1 to N+1...
{"inputs": ["2\n3\n1 2 3\n3\n5 10 5\n"], "outputs": ["1 2 6 3\n5 10 10 5\n"]}
470
47
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string s and an integer k, a k duplicate removal consists of choosing k adjacent and equal letters from s and removing them, causing the left and the right side of the deleted substring to concatenate ...
{"functional": "def check(candidate):\n assert candidate(s = \"abcd\", k = 2) == \"abcd\"\n assert candidate(s = \"deeedbbcccbdaa\", k = 3) == \"aa\"\n assert candidate(s = \"pbbcggttciiippooaais\", k = 2) == \"ps\"\n\n\ncheck(Solution().removeDuplicates)"}
133
88
coding
Solve the programming task below in a Python markdown code block. Born a misinterpretation of [this kata](https://www.codewars.com/kata/simple-fun-number-334-two-beggars-and-gold/), your task here is pretty simple: given an array of values and an amount of beggars, you are supposed to return an array with the sum of wh...
{"functional": "_inputs = [[[1, 2, 3, 4, 5], 1], [[1, 2, 3, 4, 5], 2], [[1, 2, 3, 4, 5], 3], [[1, 2, 3, 4, 5], 6], [[1, 2, 3, 4, 5], 0]]\n_outputs = [[[15]], [[9, 6]], [[5, 7, 3]], [[1, 2, 3, 4, 5, 0]], [[]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n retu...
325
278
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string s consisting of digits and an integer k. A round can be completed if the length of s is greater than k. In one round, do the following: Divide s into consecutive groups of size k such that the ...
{"functional": "def check(candidate):\n assert candidate(s = \"11111222223\", k = 3) == \"135\"\n assert candidate(s = \"00000000\", k = 3) == \"000\"\n\n\ncheck(Solution().digitSum)"}
218
76
coding
Solve the programming task below in a Python markdown code block. Finally the clowns of Synapse have decided to take their site online. The convener of the clowns has heard from somewhere that knowing URI's is very important for their website, so kindly help him with this task. Uniform Resource Identifiers (or URIs) a...
{"inputs": ["Happy Joy Joy!\nhttp://synapse.daiict.ac.in/\nplain_vanilla\n(**)\n?\nthe 7% solution\n#"], "outputs": ["Happy%20Joy%20Joy%21\nhttp://synapse.daiict.ac.in/\nplain_vanilla\n%28%2a%2a%29\n?\nthe%207%25%20solution"]}
547
99
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Chef is a big fan of soccer! He loves soccer so much, that he even invented soccer for his pet dogs! Here are the rules of the game: There are N dogs numerated from 1 to N s...
{"inputs": ["3\n3 2 2\n1 2 \n3 3 3\n1 1 1\n3 1 1\n3"], "outputs": ["1 0 1\n0 2 0\n0 0 0"]}
716
59
coding
Solve the programming task below in a Python markdown code block. To celebrate today's launch of my Hero's new book: Alan Partridge: Nomad, We have a new series of kata arranged around the great man himself. Given an array of terms, if any of those terms relate to Alan Partridge, return Mine's a Pint! The number of !...
{"functional": "_inputs = [[['Grouse', 'Partridge', 'Pheasant']], [['Pheasant', 'Goose', 'Starling', 'Robin']], [['Grouse', 'Partridge', 'Partridge', 'Partridge', 'Pheasant']], [[]], [['Grouse', 'Partridge', 'Pheasant', 'Goose', 'Starling', 'Robin', 'Thrush', 'Emu', 'PearTree', 'Chat', 'Dan', 'Square', 'Toblerone', 'Ly...
200
347
coding
Solve the programming task below in a Python markdown code block. Failed Filter - Bug Fixing #3 Oh no, Timmy's filter doesn't seem to be working? Your task is to fix the FilterNumber function to remove all the numbers from the string. Also feel free to reuse/extend the following starter code: ```python def filter_numbe...
{"functional": "_inputs = [['test123'], ['a1b2c3'], ['aa1bb2cc3dd'], ['CodeWars'], ['99234']]\n_outputs = [['test'], ['abc'], ['aabbccdd'], ['CodeWars'], ['']]\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...
75
200
coding
Solve the programming task below in a Python markdown code block. Find the second-to-last element of a list. Example: ```python penultimate([1,2,3,4]) # => 3 penultimate(["Python is dynamic"]) # => 'i' (courtesy of [haskell.org](http://www.haskell.org/haskellwiki/99_questions/1_to_10)) ``` Also feel free to...
{"functional": "_inputs = [[[1, 2, 3, 4]], ['hello']]\n_outputs = [[3], ['l']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n...
109
170
coding
Solve the programming task below in a Python markdown code block. The main city magazine offers its readers an opportunity to publish their ads. The format of the ad should be like this: There are space-separated non-empty words of lowercase and uppercase Latin letters. There are hyphen characters '-' in some words, ...
{"inputs": ["1\nj\n", "1\nj\n", "1\ni\n", "1\nh\n", "1\ng\n", "1\nf\n", "10\nb\n", "10\nb\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
403
88
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a binary string s and an integer k, return true if every binary code of length k is a substring of s. Otherwise, return false.   Please complete the following python code precisely: ```python class Solution: ...
{"functional": "def check(candidate):\n assert candidate(s = \"00110110\", k = 2) == True\n assert candidate(s = \"0110\", k = 1) == True\n assert candidate(s = \"0110\", k = 2) == False\n\n\ncheck(Solution().hasAllCodes)"}
82
81
coding
Solve the programming task below in a Python markdown code block. # Welcome to the Codewars Bar! Codewars Bar recommends you drink 1 glass of water per standard drink so you're not hungover tomorrow morning. Your fellow coders have bought you several drinks tonight in the form of a string. Return a string suggesting ...
{"functional": "_inputs = [['1 beer'], ['2 glasses of wine and 1 shot'], ['1 shot, 5 beers, 2 shots, 1 glass of wine, 1 beer']]\n_outputs = [['1 glass of water'], ['3 glasses of water'], ['10 glasses of water']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n r...
219
205
coding
Solve the programming task below in a Python markdown code block. Take an input string and return a string that is made up of the number of occurences of each english letter in the input followed by that letter, sorted alphabetically. The output string shouldn't contain chars missing from input (chars with 0 occurence)...
{"functional": "_inputs = [['The quick brown fox jumps over the lazy dog.'], ['The time you enjoy wasting is not wasted time.'], ['./4592#{}()'], ['This%Sentence\"is$$being^tested.'], ['abccdefgdhijklmno_pqrsTuvwxYz'], [''], ['.'], ['y']]\n_outputs = [['1a1b1c1d3e1f1g2h1i1j1k1l1m1n4o1p1q2r1s2t2u1v1w1x1y1z'], ['2a1d5e1g...
176
391
coding
Solve the programming task below in a Python markdown code block. Write ```python word_pattern(pattern, string) ``` that given a ```pattern``` and a string ```str```, find if ```str``` follows the same sequence as ```pattern```. For example: ```python word_pattern('abab', 'truck car truck car') == True word_pattern('...
{"functional": "_inputs = [['abab', 'apple banana apple banana'], ['abba', 'car truck truck car'], ['abab', 'apple banana banana apple'], ['aaaa', 'cat cat cat cat'], ['aaaa', 'cat cat dog cat'], ['bbbabcb', 'c# c# c# javascript c# python c#'], ['abcdef', 'apple banana cat donkey elephant flower'], ['xyzzyx', 'apple ba...
143
358
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string s and an integer k, return the maximum number of vowel letters in any substring of s with length k. Vowel letters in English are 'a', 'e', 'i', 'o', and 'u'.   Please complete the following python code ...
{"functional": "def check(candidate):\n assert candidate(s = \"abciiidef\", k = 3) == 3\n assert candidate(s = \"aeiou\", k = 2) == 2\n assert candidate(s = \"leetcode\", k = 3) == 2\n assert candidate(s = \"rhythms\", k = 4) == 0\n assert candidate(s = \"tryhard\", k = 4) == 1\n\n\ncheck(Solution().maxV...
100
113
coding
Solve the programming task below in a Python markdown code block. This is the easy version of the problem. The difference between the versions is in the constraints on the array elements. You can make hacks only if all versions of the problem are solved. You are given an array [a_1, a_2, ..., a_n]. Your goal is to f...
{"inputs": ["1\n1\n", "7\n1 2 3 3 3 2 1\n", "7\n1 2 2 3 3 2 1\n", "7\n1 2 1 3 3 2 1\n", "7\n1 2 2 3 3 4 1\n", "7\n1 2 2 3 2 2 1\n", "7\n1 2 2 5 3 2 1\n", "7\n1 2 1 3 3 4 1\n"], "outputs": ["0\n", "3\n", "5\n", "6\n", "7\n", "2\n", "4\n", "6\n"]}
431
170
coding
Solve the programming task below in a Python markdown code block. problem AOR Ika is at the $ S $ th bus stop at time $ 0 $ and wants to go from there to the $ G $ th bus stop. The number of bus stops $ N $ and $ M $ routes (*) connecting different bus stops are given. The bus stops are numbered $ 1, \ dots, and N $, ...
{"inputs": ["2 1 1 2\n1 2 9 011\n2 2 5 500", "2 2 1 2\n1 2 6 001\n1 2 2 893", "2 2 1 2\n1 2 8 111\n1 1 4 526", "2 1 1 2\n1 2 10 001\n1 2 5 58", "2 2 1 2\n1 2 6 101\n1 2 5 893", "2 1 1 2\n1 2 5 101\n1 2 5 500", "2 1 1 2\n1 2 10 001\n1 2 5 28", "2 2 1 2\n1 2 0 001\n2 2 5 500"], "outputs": ["9\n", "2\n", "8\n", "10\n", "5...
372
272
coding
Solve the programming task below in a Python markdown code block. We say that a string contains the word hackerrank if a subsequence of its characters spell the word hackerrank. Remeber that a subsequence maintains the order of characters selected from a sequence. More formally, let $p[0],p[1],\cdots,p[9]$ be the ...
{"inputs": ["2\nhereiamstackerrank\nhackerworld\n", "2\nhhaacckkekraraannk\nrhbaasdndfsdskgbfefdbrsdfhuyatrjtcrtyytktjjt\n"], "outputs": ["YES\nNO\n", "YES\nNO\n"]}
640
70
coding
Solve the programming task below in a Python markdown code block. Write a function that solves an algebraic expression given as a string. * The expression can include only sums and products. * The numbers in the expression are in standard notation (NOT scientific). * In contrast, the function should return a strin...
{"functional": "_inputs = [['5*4+6'], ['5+4*6'], ['3*8+6*5'], ['5*8+6*3*2'], ['5.4*4.0+6.2+8.0'], ['0.5*1.2*56+9.6*5*81+1'], ['1'], ['1.333333333*1.23456789+0.003*0.002']]\n_outputs = [['2.60000e+01'], ['2.90000e+01'], ['5.40000e+01'], ['7.60000e+01'], ['3.58000e+01'], ['3.92260e+03'], ['1.00000e+00'], ['1.64610e+00']]...
142
365
coding
Solve the programming task below in a Python markdown code block. You are given a list of $N$ numbers $a_1,a_2,\ldots,a_n$. For each element at position $\boldsymbol{i}$ ($1\leq i\leq N$), we define $\text{Left}(i)$ and $\textit{Right}(i)$ as: $\text{Left}(i)$ = closest index j such that j < i and $a_j>a_i$. If no su...
{"inputs": ["5\n5 4 3 4 5\n"], "outputs": ["8\n"]}
405
24
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef has A units of solid and B units of liquid. He combines them to create a mixture. What kind of mixture does Chef produce: a solution, a solid, or a liqui...
{"inputs": ["3\n10 5\n0 3\n3 0\n"], "outputs": ["Solution\nLiquid\nSolid\n"]}
363
31
coding
Solve the programming task below in a Python markdown code block. "I have only one rule, never submit partially correct code" -Barney Stinson The religious act which Barney and his friends hold most sacred, XORING the natural numbers in the given range. This time Barney is a bit busy with picking up some girls, so he ...
{"inputs": ["4\n1 4\n2 6\n3 3\n2 3"], "outputs": ["Even\nEven\nOdd\nOdd"]}
335
34
coding
Solve the programming task below in a Python markdown code block. You are given a sequence of integers $A_1,A_2,…,A_N$ and a magical non-zero integer $x$ You have to select a subsegment of sequence A (possibly empty), and replace the elements in that subsegment after dividing them by x. Formally, replace any one subseg...
{"inputs": ["3 2\n1 -2 3"], "outputs": ["0.5"]}
334
22
coding
Solve the programming task below in a Python markdown code block. The only difference between easy and hard versions is the constraints. Vova likes pictures with kittens. The news feed in the social network he uses can be represented as an array of $n$ consecutive pictures (with kittens, of course). Vova likes all the...
{"inputs": ["1 1 1\n7082632\n", "1 1 1\n7082632\n", "1 1 1\n7647119\n", "1 1 1\n99996055\n", "1 1 1\n99996055\n", "1 1 1\n37049130\n", "1 1 1\n50273182\n", "1 1 1\n14314026\n"], "outputs": ["7082632\n", "7082632\n", "7647119\n", "99996055\n", "99996055\n", "37049130\n", "50273182\n", "14314026\n"]}
500
224