task_type stringclasses 1
value | problem stringlengths 261 3.34k | answer stringlengths 35 6.15k | problem_tokens int64 62 774 | answer_tokens int64 12 2.04k |
|---|---|---|---|---|
coding | Solve the programming task below in a Python markdown code block.
## Task
Write a function that accepts two arguments and generates a sequence containing the integers from the first argument to the second inclusive.
## Input
Pair of integers greater than or equal to `0`. The second argument will always be greater t... | {"functional": "_inputs = [[2, 5]]\n_outputs = [[[2, 3, 4, 5]]]\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 return ... | 124 | 168 |
coding | Solve the programming task below in a Python markdown code block.
Three people, A, B and C, are trying to communicate using transceivers.
They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively.
Two people can directly communicate when the distance between them ... | {"inputs": ["4 7 2 3", "4 5 2 3", "4 7 9 3", "4 7 9 3\n", "0 011 5 8", "0 011 5 3", "0 111 5 3", "0 111 1 3"], "outputs": ["Yes\n", "Yes\n", "Yes", "Yes\n", "Yes\n", "No\n", "No\n", "Yes\n"]} | 228 | 118 |
coding | Solve the programming task below in a Python markdown code block.
A bracket sequence is a string containing only characters "(" and ")".
A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original characters of t... | {"inputs": ["1\n)(\n", "1\n()\n", "1\n)(\n", "1\n()\n", "1\n((\n", "1\n))\n", "2\n()\n()\n", "2\n((\n))\n"], "outputs": ["0\n", "1\n", "0\n", "1\n", "0\n", "0\n", "4\n", "1\n"]} | 475 | 96 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
In a garden represented as an infinite 2D grid, there is an apple tree planted at every integer coordinate. The apple tree planted at an integer coordinate (i, j) has |i| + |j| apples growing on it.
You will buy an ax... | {"functional": "def check(candidate):\n assert candidate(neededApples = 1) == 8\n assert candidate(neededApples = 13) == 16\n assert candidate(neededApples = 1000000000) == 5040\n\n\ncheck(Solution().minimumPerimeter)"} | 175 | 79 |
coding | Solve the programming task below in a Python markdown code block.
MKnez wants to construct an array $s_1,s_2, \ldots , s_n$ satisfying the following conditions:
Each element is an integer number different from $0$;
For each pair of adjacent elements their sum is equal to the sum of the whole array.
More formally, $s... | {"inputs": ["2\n2\n3\n", "100\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3... | 676 | 433 |
coding | Solve the programming task below in a Python markdown code block.
Petya and his friend, robot Petya++, like to solve exciting math problems.
One day Petya++ came up with the numbers $n$ and $x$ and wrote the following equality on the board: $$n\ \&\ (n+1)\ \&\ \dots\ \&\ m = x,$$ where $\&$ denotes the bitwise AND ope... | {"inputs": ["1\n0 1\n", "5\n10 8\n10 10\n10 42\n20 16\n1000000000000000000 0\n"], "outputs": ["-1\n", "12\n10\n-1\n24\n1152921504606846976\n"]} | 496 | 102 |
coding | Solve the programming task below in a Python markdown code block.
In Dark Souls, players level up trading souls for stats. 8 stats are upgradable this way: vitality, attunement, endurance, strength, dexterity, resistance, intelligence, and faith. Each level corresponds to adding one point to a stat of the player's choi... | {"functional": "_inputs = [['deprived', [11, 11, 11, 11, 11, 11, 11, 11]], ['pyromancer', [10, 12, 11, 12, 9, 12, 11, 8]], ['pyromancer', [16, 12, 11, 12, 9, 12, 10, 8]], ['pyromancer', [16, 12, 11, 12, 9, 12, 13, 8]], ['pyromancer', [16, 12, 11, 12, 9, 12, 13, 10]]]\n_outputs = [['Starting as a deprived, level 6 will ... | 746 | 427 |
coding | Solve the programming task below in a Python markdown code block.
There are N candles placed on a number line.
The i-th candle from the left is placed on coordinate x_i.
Here, x_1 < x_2 < ... < x_N holds.
Initially, no candles are burning.
Snuke decides to light K of the N candles.
Now, he is at coordinate 0.
He can mo... | {"inputs": ["1 1\n0", "1 1\n0\n", "3 2\n10 18 30", "3 2\n10 20 43", "3 2\n10 22 30", "3 2\n10 11 30", "3 3\n12 20 60", "3 3\n5 26 149"], "outputs": ["0", "0\n", "18\n", "20\n", "22\n", "11\n", "60\n", "149\n"]} | 334 | 143 |
coding | Solve the programming task below in a Python markdown code block.
problem
Given a sequence $ a_i $ of length $ N $. Output all integers $ K (1 \ le K \ le N) $ that satisfy the following conditions.
Condition: Well sorted $ a_1, \ cdots, a_K $ matches $ a_ {N-K + 1}, \ cdots, a_N $.
Example
Input
8
5 2 4 9 4 9... | {"inputs": ["8\n5 2 4 4 4 9 2 5", "8\n6 2 7 4 2 7 2 0", "8\n5 2 4 9 4 9 2 5", "8\n5 2 4 4 4 14 2 0", "8\n5 2 4 4 4 14 2 5", "8\n5 2 4 4 4 11 2 0", "8\n5 2 6 4 4 11 2 0", "8\n6 2 6 4 4 11 2 0"], "outputs": ["1 2 6 7 8\n", "8\n", "1 2 4 6 7 8", "8\n", "1 2 6 7 8\n", "8\n", "8\n", "8\n"]} | 118 | 220 |
coding | Solve the programming task below in a Python markdown code block.
You are given 3 numbers A, B and C.
You want to make all these 3 numbers equal. To do this, you can perform any finite number of operations:
In the i^{th} operation, you must add 2^{(i-1)} to any one of these 3 numbers.
Find whether you can make thes... | {"inputs": ["4\n4 4 3\n1 6 7\n3 4 3\n2 3 4\n"], "outputs": ["YES\nYES\nNO\nYES\n"]} | 566 | 44 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a 1-indexed array of integers numbers that is already sorted in non-decreasing order, find two numbers such that they add up to a specific target number. Let these two numbers be numbers[index1] and numbers[inde... | {"functional": "def check(candidate):\n assert candidate(numbers = [2,7,11,15], target = 9) == [1,2]\n assert candidate(numbers = [2,3,4], target = 6) == [1,3]\n assert candidate(numbers = [-1,0], target = -1) == [1,2]\n\n\ncheck(Solution().twoSum)"} | 177 | 93 |
coding | Solve the programming task below in a Python markdown code block.
Write a program that extracts n different numbers from the numbers 0 to 9 and outputs the number of combinations that add up to s. Each n number is from 0 to 9, and the same number cannot be used in one combination. For example, if n is 3 and s is 6, the... | {"inputs": ["3 5\n3 1\n0 0", "3 0\n5 1\n0 0", "1 0\n5 1\n0 0", "3 6\n3 0\n0 0", "2 5\n1 1\n0 0", "2 0\n1 1\n0 0", "3 2\n0 0\n0 0", "2 2\n0 0\n0 0"], "outputs": ["2\n0\n", "0\n0\n", "1\n0\n", "3\n0\n", "3\n1\n", "0\n1\n", "0\n", "1\n"]} | 253 | 154 |
coding | Solve the programming task below in a Python markdown code block.
Chef is teaching his class of N students at Hogwarts. He groups students with the same height together for an activity. Some of the students end up in a groups with only themselves and are saddened by this.
With the help of his magic wand, Chef can incr... | {"inputs": ["4\n4\n1 2 1 2\n4\n1 2 2 2\n3\n1 1 1\n5\n1 2 3 4 5\n"], "outputs": ["0\n1\n0\n3\n"]} | 519 | 60 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a network of n nodes represented as an n x n adjacency matrix graph, where the ith node is directly connected to the jth node if graph[i][j] == 1.
Some nodes initial are initially infected by malware. Wh... | {"functional": "def check(candidate):\n assert candidate(graph = [[1,1,0],[1,1,0],[0,0,1]], initial = [0,1]) == 0\n assert candidate(graph = [[1,1,0],[1,1,1],[0,1,1]], initial = [0,1]) == 1\n assert candidate(graph = [[1,1,0,0],[1,1,1,0],[0,1,1,1],[0,0,1,1]], initial = [0,1]) == 1\n\n\ncheck(Solution().minMalw... | 231 | 140 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed m x n binary matrix grid.
A 0-indexed m x n difference matrix diff is created with the following procedure:
Let the number of ones in the ith row be onesRowi.
Let the number of ones in the j... | {"functional": "def check(candidate):\n assert candidate(grid = [[0,1,1],[1,0,1],[0,0,1]]) == [[0,0,4],[0,0,4],[-2,-2,2]]\n assert candidate(grid = [[1,1,1],[1,1,1]]) == [[5,5,5],[5,5,5]]\n\n\ncheck(Solution().onesMinusZeros)"} | 172 | 101 |
coding | Solve the programming task below in a Python markdown code block.
Your task is to sort a given string. Each word in the string will contain a single number. This number is the position the word should have in the result.
Note: Numbers can be from 1 to 9. So 1 will be the first word (not 0).
If the input string is emp... | {"functional": "_inputs = [['is2 Thi1s T4est 3a'], ['4of Fo1r pe6ople g3ood th5e the2'], ['d4o dru7nken sh2all w5ith s8ailor wha1t 3we a6'], [''], ['3 6 4 2 8 7 5 1 9']]\n_outputs = [['Thi1s is2 3a T4est'], ['Fo1r the2 g3ood 4of th5e pe6ople'], ['wha1t sh2all 3we d4o w5ith a6 dru7nken s8ailor'], [''], ['1 2 3 4 5 6 7 8... | 197 | 309 |
coding | Solve the programming task below in a Python markdown code block.
You are going to eat X red apples and Y green apples.
You have A red apples of deliciousness p_1,p_2, \dots, p_A, B green apples of deliciousness q_1,q_2, \dots, q_B, and C colorless apples of deliciousness r_1,r_2, \dots, r_C.
Before eating a colorles... | {"inputs": ["1 2 2 2 1\n3 4\n5 1\n3", "1 2 2 4 1\n3 3\n1 1\n3", "1 0 4 4 1\n3 3\n1 1\n3", "1 1 4 4 1\n3 3\n1 1\n3", "1 1 4 4 1\n6 3\n1 1\n3", "1 2 4 8 1\n6 3\n1 1\n3", "2 2 4 8 1\n6 3\n1 1\n3", "1 2 2 2 1\n2 4\n9 1\n3"], "outputs": ["12\n", "7\n", "3\n", "6\n", "9\n", "10\n", "13\n", "16\n"]} | 439 | 210 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
There are n rooms you need to visit, labeled from 0 to n - 1. Each day is labeled, starting from 0. You will go in and visit one room a day.
Initially on day 0, you visit room 0. The order you visit the rooms for the ... | {"functional": "def check(candidate):\n assert candidate(nextVisit = [0,0]) == 2\n assert candidate(nextVisit = [0,0,2]) == 6\n assert candidate(nextVisit = [0,1,2,0]) == 6\n\n\ncheck(Solution().firstDayBeenInAllRooms)"} | 278 | 74 |
coding | Solve the programming task below in a Python markdown code block.
In order to establish dominance amongst his friends, Chef has decided that he will only walk in large steps of length exactly $K$ feet. However, this has presented many problems in Chef’s life because there are certain distances that he cannot traverse. ... | {"inputs": ["1\n5 3\n12 13 18 20 27216"], "outputs": ["10101"]} | 454 | 38 |
coding | Solve the programming task below in a Python markdown code block.
For a given prime $\boldsymbol{p}$, define $\text{ord}_p(k)$ as the multiplicity of $\boldsymbol{p}$ in $\boldsymbol{\mbox{k}}$, i.e. the number of times $\boldsymbol{p}$ appears in the prime factorization of $\boldsymbol{k}$.
For a given $\boldsymbol{p... | {"inputs": ["2\n2 6\n3 6\n"], "outputs": ["2\n2\n"]} | 488 | 24 |
coding | Solve the programming task below in a Python markdown code block.
Problem statement
There is a rational number sequence $ X_0, X_1, X_2, ..., X_N $. Each term is defined as follows.
1. $ X_0 = 0 $
2. $ X_i = X_ {i-1} $ $ op_i $ $ Y_i $ ($ 1 \ leq i \ leq N $). However, $ op_i $ is $ + $, $ − $, $ × $, $ ÷ $ Either.
... | {"inputs": ["4\n0 1\n4 2\n2 4\n3 4", "4\n0 1\n4 2\n2 1\n3 4", "4\n1 2\n4 2\n2 4\n3 4", "4\n1 2\n4 2\n2 4\n3 7", "4\n0 1\n4 3\n2 1\n2 4", "4\n2 2\n4 2\n2 4\n3 7", "4\n2 2\n4 2\n2 7\n3 7", "4\n2 0\n4 2\n2 7\n3 7"], "outputs": ["-16\n", "-4\n", "-12\n", "-21\n", "-5\n", "-35\n", "-56\n", "-49\n"]} | 390 | 197 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed 2D integer array peaks where peaks[i] = [xi, yi] states that mountain i has a peak at coordinates (xi, yi). A mountain can be described as a right-angled isosceles triangle, with its base alo... | {"functional": "def check(candidate):\n assert candidate(peaks = [[2,2],[6,3],[5,4]]) == 2\n assert candidate(peaks = [[1,3],[1,3]]) == 0\n\n\ncheck(Solution().visibleMountains)"} | 167 | 62 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer array nums, return the greatest common divisor of the smallest number and largest number in nums.
The greatest common divisor of two numbers is the largest positive integer that evenly divides both nu... | {"functional": "def check(candidate):\n assert candidate(nums = [2,5,6,9,10]) == 2\n assert candidate(nums = [7,5,6,8,3]) == 1\n assert candidate(nums = [3,3]) == 3\n\n\ncheck(Solution().findGCD)"} | 88 | 75 |
coding | Solve the programming task below in a Python markdown code block.
Takahashi, who is a novice in competitive programming, wants to learn M algorithms.
Initially, his understanding level of each of the M algorithms is 0.
Takahashi is visiting a bookstore, where he finds N books on algorithms.
The i-th book (1\leq i\leq N... | {"inputs": ["1 1 1\n1 0\n", "1 1 100000\n100000 100000\n", "2 3 8\n2 3 3 4\n74 7 7 4\n50 4 3 6", "3 3 8\n62 3 3 4\n74 7 7 2\n50 2 3 6", "3 3 8\n12 3 3 4\n74 7 7 4\n50 4 3 6", "3 3 10\n60 2 2 4\n70 8 7 2\n50 2 3 9", "3 3 10\n60 2 2 4\n68 8 7 2\n50 2 3 9", "3 3 10\n60 2 3 4\n74 7 7 2\n50 2 3 9"], "outputs": ["-1\n", "100... | 183 | 299 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two arrays of integers nums1 and nums2, possibly of different lengths. The values in the arrays are between 1 and 6, inclusive.
In one operation, you can change any integer's value in any of the arrays t... | {"functional": "def check(candidate):\n assert candidate(nums1 = [1,2,3,4,5,6], nums2 = [1,1,2,2,2,2]) == 3\n assert candidate(nums1 = [1,1,1,1,1,1,1], nums2 = [6]) == -1\n assert candidate(nums1 = [6,6], nums2 = [1]) == 3\n\n\ncheck(Solution().minOperations)"} | 163 | 110 |
coding | Solve the programming task below in a Python markdown code block.
In 2300, the Life Science Division of Federal Republic of Space starts a very ambitious project to complete the genome sequencing of all living creatures in the entire universe and develop the genomic database of all space life. Thanks to scientific rese... | {"inputs": ["ABC 3\nABB 0\n2(4(AB)3(XY))10C 2\n1000(1000(1000(1000(1000(1000(NM)))))) 76895\n0 0", "ABC 3\nABC 0\n2(4(AB)3(XY))10C 3\n1000(1000(1000(1000(1000(1000(NM)))))) 999999\n0 0", "ABC 3\nABC 0\n2(4(AB)3(XY))10C 3\n1000(1000(1000(1000(1000(1000(NM)))))) 976314\n0 0", "ABC 3\nBAB 0\n2(4(AB)3(XY))10C 3\n1000(1000(... | 717 | 645 |
coding | Solve the programming task below in a Python markdown code block.
Polygons are the most fundamental objects in geometric processing. Complex figures are often represented and handled as polygons with many short sides. If you are interested in the processing of geometric data, you'd better try some programming exercises... | {"inputs": ["3\n1 1\n3 1\n1 0\n\n7\n0 0\n0 10\n0 32\n9 2\n0 69\n100 26\n100 1\n\n0", "3\n1 1\n3 4\n2 0\n\n7\n0 0\n10 15\n0 20\n9 32\n0 40\n110 1\n100 0\n\n0", "3\n1 1\n3 4\n2 0\n\n7\n0 0\n10 15\n-1 4\n9 32\n0 40\n110 1\n100 0\n\n0", "3\n1 2\n3 4\n2 0\n\n7\n0 0\n10 15\n-1 4\n9 32\n0 40\n110 1\n100 0\n\n0", "3\n1 1\n3 1\... | 531 | 605 |
coding | Solve the programming task below in a Python markdown code block.
There are $n$ players sitting at the card table. Each player has a favorite number. The favorite number of the $j$-th player is $f_j$.
There are $k \cdot n$ cards on the table. Each card contains a single integer: the $i$-th card contains number $c_i$. ... | {"inputs": ["1 1\n1\n2\n1\n", "1 1\n1\n1\n1\n", "1 1\n1\n2\n1\n", "1 1\n1\n1\n1\n", "1 1\n1\n4\n1\n", "1 1\n1\n7\n1\n", "1 1\n1\n7\n2\n", "1 1\n1\n7\n3\n"], "outputs": ["0\n", "1\n", "0\n", "1\n", "0\n", "0\n", "0\n", "0\n"]} | 759 | 134 |
coding | Solve the programming task below in a Python markdown code block.
You will be given a fruit which a farmer has harvested, your job is to see if you should buy or sell.
You will be given 3 pairs of fruit. Your task is to trade your harvested fruit back into your harvested fruit via the intermediate pair, you should ret... | {"functional": "_inputs = [[[['apple', 'orange'], ['orange', 'pear'], ['apple', 'pear']], 'apple'], [[['orange', 'apple'], ['orange', 'pear'], ['pear', 'apple']], 'apple'], [[['apple', 'orange'], ['pear', 'orange'], ['apple', 'pear']], 'apple'], [[['orange', 'apple'], ['pear', 'orange'], ['pear', 'apple']], 'apple'], [... | 286 | 425 |
coding | Solve the programming task below in a Python markdown code block.
You are given a string $s$ consisting only of characters + and -. You perform some process with this string. This process can be described by the following pseudocode: res = 0
for init = 0 to inf
cur = init
ok = true
for i = 1 to |s|
... | {"inputs": ["3\n--+-\n---\n++--+-\n", "3\n-+--\n---\n++--+-\n", "3\n--+-\n---\n+--++-\n", "3\n-+--\n---\n+--++-\n", "3\n--+-\n---\n-+-++-\n", "3\n---+\n---\n++--+-\n", "3\n-+--\n---\n---+++\n", "3\n--+-\n---\n-+--++\n"], "outputs": ["7\n9\n6\n", "9\n9\n6\n", "7\n9\n9\n", "9\n9\n9\n", "7\n9\n7\n", "10\n9\n6\n", "9\n9\n1... | 316 | 203 |
coding | Solve the programming task below in a Python markdown code block.
The Bubble Cup hypothesis stood unsolved for $130$ years. Who ever proves the hypothesis will be regarded as one of the greatest mathematicians of our time! A famous mathematician Jerry Mao managed to reduce the hypothesis to this problem:
Given a numbe... | {"inputs": ["1\n9\n", "1\n9\n", "1\n3\n", "1\n17\n", "1\n29\n", "1\n50\n", "1\n15\n", "1\n21\n"], "outputs": ["9\n", "9\n", "2\n", "25\n", "64\n", "182\n", "20\n", "36\n"]} | 337 | 97 |
coding | Solve the programming task below in a Python markdown code block.
Soma is a fashionable girl. She absolutely loves shiny stones that she can put on as jewellery accessories. She has been collecting stones since her childhood - now she has become really good with identifying which ones are fake and which ones are not. ... | {"inputs": ["4\nabc\nabcdef\naA\nabAZ\naaa\na\nwhat\nnone"], "outputs": ["3\n2\n1\n0"]} | 310 | 36 |
coding | Solve the programming task below in a Python markdown code block.
Find the number of k-divisible numbers on the segment [a, b]. In other words you need to find the number of such integer values x that a ≤ x ≤ b and x is divisible by k.
-----Input-----
The only line contains three space-separated integers k, a and b ... | {"inputs": ["1 1 1\n", "1 0 0\n", "1 0 1\n", "2 0 0\n", "2 0 1\n", "2 1 2\n", "2 2 3\n", "2 0 1\n"], "outputs": ["1\n", "1\n", "2\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | 139 | 102 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given three integers x, y, and bound, return a list of all the powerful integers that have a value less than or equal to bound.
An integer is powerful if it can be represented as xi + yj for some integers i >= 0 and j... | {"functional": "def check(candidate):\n assert candidate(x = 2, y = 3, bound = 10) == [2,3,4,5,7,9,10]\n assert candidate(x = 3, y = 5, bound = 15) == [2,4,6,8,10,14]\n\n\ncheck(Solution().powerfulIntegers)"} | 134 | 94 |
coding | Solve the programming task below in a Python markdown code block.
You're writing an excruciatingly detailed alternate history novel set in a world where [Daniel Gabriel Fahrenheit](https://en.wikipedia.org/wiki/Daniel_Gabriel_Fahrenheit) was never born.
Since Fahrenheit never lived the world kept on using the [Rømer s... | {"functional": "_inputs = [[24], [8], [29]]\n_outputs = [[20.1], [11.7], [22.725]]\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 Fal... | 234 | 182 |
coding | Solve the programming task below in a Python markdown code block.
Alice and Bob are playing a game with n piles of stones. It is guaranteed that n is an even number. The i-th pile has a_i stones.
Alice and Bob will play a game alternating turns with Alice going first.
On a player's turn, they must choose exactly n/2 ... | {"inputs": ["2\n1 1\n", "2\n8 8\n", "4\n2 3 3 3\n", "4\n1 2 2 2\n", "4\n2 1 1 1\n", "4\n1 1 1 4\n", "4\n1 3 3 3\n", "4\n1 2 2 3\n"], "outputs": ["Bob\n", "Bob\n", "Alice\n", "Alice\n", "Bob\n", "Bob\n", "Alice\n", "Alice\n"]} | 344 | 126 |
coding | Solve the programming task below in a Python markdown code block.
When provided with a number between 0-9, return it in words.
Input :: 1
Output :: "One".
If your language supports it, try using a switch statement.
Also feel free to reuse/extend the following starter code:
```python
def switch_it_up(number):
``` | {"functional": "_inputs = [[0], [1], [2], [3], [4], [5], [6], [7], [8], [9]]\n_outputs = [['Zero'], ['One'], ['Two'], ['Three'], ['Four'], ['Five'], ['Six'], ['Seven'], ['Eight'], ['Nine']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, ... | 73 | 210 |
coding | Solve the programming task below in a Python markdown code block.
Ishank lives in a country in which there are N$N$ cities and N−1$N-1$ roads. All the cities are connected via these roads. Each city has been assigned a unique number from 1 to N$N$. The country can be assumed as a tree, with nodes representing the citie... | {"inputs": ["9 5\n1 2 8\n1 3 -9\n2 4 1\n2 5 -6\n3 6 7\n3 7 6\n6 8 3\n6 9 4\n1 2\n2 7\n4 3\n3 2\n8 9"], "outputs": ["10\n5\n0\n-1\n21"]} | 707 | 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 binary tree where each node has a value 0 or 1. Each root-to-leaf path represents a binary number starting with the most significant bit.
For example, if the path is 0 -> 1 -> 1 -> 0 -> 1,... | {"functional": "def check(candidate):\n assert candidate(root = tree_node([1,0,1,0,1,0,1])) == 22\n assert candidate(root = tree_node([0])) == 0\n\n\ncheck(Solution().sumRootToLeaf)"} | 228 | 62 |
coding | Solve the programming task below in a Python markdown code block.
Ayush, Ashish and Vivek are busy preparing a new problem for the next Codeforces round and need help checking if their test cases are valid.
Each test case consists of an integer $n$ and two arrays $a$ and $b$, of size $n$. If after some (possibly zero)... | {"inputs": ["1\n1\n1\n1\n", "1\n1\n1\n1\n", "1\n1\n0\n1\n", "1\n3\n1 2 1\n2 1 2\n", "1\n3\n8 9 8\n9 8 9\n", "1\n3\n4 5 4\n5 4 5\n", "1\n3\n3 7 3\n7 3 7\n", "1\n3\n1 2 1\n1 1 2\n"], "outputs": ["Yes\n", "Yes\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n"]} | 718 | 158 |
coding | Solve the programming task below in a Python markdown code block.
Given an array of integers and a target value, determine the number of pairs of array elements that have a difference equal to the target value.
Example
$k=1$
$arr=[1,2,3,4]$
There are three values that differ by $k=1$: $2-1=2$, $3-2=1$, and $... | {"inputs": ["5 2 \n1 5 3 4 2 \n"], "outputs": ["3\n"]} | 350 | 29 |
coding | Solve the programming task below in a Python markdown code block.
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style.
Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all pow... | {"inputs": ["hg\n", "hg\n", "hh\n", "gh\n", "gi\n", "fi\n", "gj\n", "fj\n"], "outputs": ["0", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | 417 | 71 |
coding | Solve the programming task below in a Python markdown code block.
There is a string s of length 3 or greater.
No two neighboring characters in s are equal.
Takahashi and Aoki will play a game against each other.
The two players alternately performs the following operation, Takahashi going first:
- Remove one of the ch... | {"inputs": ["aba\n", "abc\n", "abab\n", "abac\n", "abca\n", "abcb\n", "abcab\n"], "outputs": ["Second\n", "First\n", "Second\n", "Second\n", "First\n", "Second\n", "First\n"]} | 254 | 67 |
coding | Solve the programming task below in a Python markdown code block.
Given a square table sized NxN (3 ≤ N ≤ 5,000; rows and columns are indexed from 1) with a robot on it. The robot has a mission of moving from cell (1, 1) to cell (N, N) using only the directions "right" or "down". You are requested to find the number of... | {"inputs": ["4 2\n4 3\n5 3\n0 0", "2 2\n4 3\n5 3\n0 0", "2 2\n5 3\n5 3\n0 0", "2 1\n4 3\n5 3\n0 0", "2 1\n4 2\n5 3\n0 0", "2 2\n5 5\n5 2\n0 0", "2 1\n3 2\n5 3\n0 0", "2 2\n5 0\n5 3\n0 0"], "outputs": ["4\n8\n18", "774058230\n8\n18\n", "774058230\n18\n18\n", "2\n8\n18\n", "2\n4\n18\n", "774058230\n18\n6\n", "2\n2\n18\n"... | 318 | 254 |
coding | Solve the programming task below in a Python markdown code block.
Chef wants to conduct a lecture for which he needs to set up an online meeting of exactly X minutes.
The meeting platform supports a meeting of maximum 30 minutes without subscription and a meeting of unlimited duration with subscription.
Determine w... | {"inputs": ["4\n50\n3\n30\n80\n"], "outputs": ["YES\nNO\nNO\nYES\n"]} | 413 | 31 |
coding | Solve the programming task below in a Python markdown code block.
Chef has an array A consisting of N elements. He wants to find number of pairs of non-intersecting segments [a, b] and [c, d] (1 ≤ a ≤ b < c ≤ d ≤ N) such there is no number that occurs in the subarray {Aa, Aa+1, ... , Ab} and {Ac, Ac+1, ... , Ad} simu... | {"inputs": ["2\n3\n1 2 3\n4\n1 2 1 2"], "outputs": ["5\n4"]} | 457 | 32 |
coding | Solve the programming task below in a Python markdown code block.
Write a function that takes a positive integer and returns the next smaller positive integer containing the same digits.
For example:
```python
next_smaller(21) == 12
next_smaller(531) == 513
next_smaller(2071) == 2017
```
Return -1 (for `Haskell`: re... | {"functional": "_inputs = [[21], [907], [531], [1027], [441], [123456798], [513], [351], [315], [153], [135], [100], [2071], [1207], [414], [123456789], [29009], [1234567908], [9999999999], [59884848483559], [1023456789], [51226262651257], [202233445566], [506789]]\n_outputs = [[12], [790], [513], [-1], [414], [1234567... | 341 | 482 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer n. You have an n x n binary grid grid with all values initially 1's except for some indices given in the array mines. The ith element of the array mines is defined as mines[i] = [xi, yi] where... | {"functional": "def check(candidate):\n assert candidate(n = 5, mines = [[4,2]]) == 2\n assert candidate(n = 1, mines = [[0,0]]) == 0\n\n\ncheck(Solution().orderOfLargestPlusSign)"} | 232 | 61 |
coding | Solve the programming task below in a Python markdown code block.
Takahashi and Aoki are playing a stone-taking game. Initially, there are N piles of stones, and the i-th pile contains A_i stones and has an associated integer K_i.
Starting from Takahashi, Takahashi and Aoki take alternate turns to perform the following... | {"inputs": ["1\n1 1\n", "1\n1 2\n", "1\n2 2\n", "1\n2 1\n", "2\n7 2\n3 6", "2\n7 2\n3 3", "2\n5 2\n3 3", "2\n5 2\n3 3\n"], "outputs": ["Takahashi\n", "Aoki\n", "Takahashi\n", "Takahashi\n", "Aoki\n", "Takahashi\n", "Aoki", "Aoki\n"]} | 562 | 126 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
In a string composed of 'L', 'R', and 'X' characters, like "RXXLRXRXL", a move consists of either replacing one occurrence of "XL" with "LX", or replacing one occurrence of "RX" with "XR". Given the starting string st... | {"functional": "def check(candidate):\n assert candidate(start = \"RXXLRXRXL\", end = \"XRLXXRRLX\") == True\n assert candidate(start = \"X\", end = \"L\") == False\n\n\ncheck(Solution().canTransform)"} | 134 | 60 |
coding | Solve the programming task below in a Python markdown code block.
Chef is very fond of horses. He enjoys watching them race. As expected, he has a stable full of horses. He, along with his friends, goes to his stable during the weekends to watch a few of these horses race. Chef wants his friends to enjoy the race and s... | {"inputs": ["1\n5\n7 4 2 29 5", "1\n5\n0 7 0 8 14", "1\n5\n7 9 1 13 0", "1\n5\n7 4 4 29 5", "1\n5\n1 7 0 8 14", "1\n5\n0 9 1 4 14", "1\n5\n7 9 0 13 0", "1\n5\n7 4 4 29 7"], "outputs": ["1\n", "0\n", "1\n", "0\n", "1\n", "1\n", "0\n", "0\n"]} | 356 | 166 |
coding | Solve the programming task below in a Python markdown code block.
Write a function `consonantCount`, `consonant_count` or `ConsonantCount` that takes a string of English-language text and returns the number of consonants in the string.
Consonants are all letters used to write English excluding the vowels `a, e, i, o, ... | {"functional": "_inputs = [[''], ['aaaaa'], ['helLo world'], ['h^$&^#$&^elLo world'], ['0123456789'], ['012345_Cb']]\n_outputs = [[0], [0], [7], [7], [0], [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... | 100 | 214 |
coding | Solve the programming task below in a Python markdown code block.
Math geeks and computer nerds love to anthropomorphize numbers and assign emotions and personalities to them. Thus there is defined the concept of a "happy" number. A happy number is defined as an integer in which the following sequence ends with the num... | {"functional": "_inputs = [[10], [50], [100]]\n_outputs = [[[1, 7, 10]], [[1, 7, 10, 13, 19, 23, 28, 31, 32, 44, 49]], [[1, 7, 10, 13, 19, 23, 28, 31, 32, 44, 49, 68, 70, 79, 82, 86, 91, 94, 97, 100]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math... | 539 | 293 |
coding | Solve the programming task below in a Python markdown code block.
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Ari and Rich are playing a pretty confusing game. Here are the rules of the game:
The game is played with two piles of matches. Initially, the first ... | {"inputs": ["5\n1 1\n2 2\n1 3\n155 47\n6 4"], "outputs": ["Ari\nAri\nAri\nAri\nRich"]} | 537 | 47 |
coding | Solve the programming task below in a Python markdown code block.
Welcome. In this kata, you are asked to square every digit of a number and concatenate them.
For example, if we run 9119 through the function, 811181 will come out, because 9^(2) is 81 and 1^(2) is 1.
**Note:** The function accepts an integer and retur... | {"functional": "_inputs = [[3212], [2112]]\n_outputs = [[9414], [4114]]\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 ... | 113 | 172 |
coding | Solve the programming task below in a Python markdown code block.
3R2 as DJ Mashiro - Happiness Breeze Ice - DJ Mashiro is dead or alive
NEKO#ΦωΦ has just got a new maze game on her PC!
The game's main puzzle is a maze, in the forms of a $2 \times n$ rectangle grid. NEKO's task is to lead a Nekomimi girl from cell $(... | {"inputs": ["4 1\n1 4\n", "4 1\n1 4\n", "2 2\n2 1\n1 2\n", "2 2\n2 1\n1 2\n", "2 4\n2 1\n1 2\n1 2\n1 2\n", "2 4\n2 1\n1 2\n1 2\n1 2\n", "5 5\n2 3\n1 4\n2 4\n2 3\n1 4\n", "6 5\n2 3\n1 4\n2 4\n2 3\n1 4\n"], "outputs": ["Yes\n", "Yes\n", "Yes\nNo\n", "Yes\nNo\n", "Yes\nNo\nYes\nNo\n", "Yes\nNo\nYes\nNo\n", "Yes\nNo\nNo\nN... | 707 | 214 |
coding | Solve the programming task below in a Python markdown code block.
Bharat was given a problem to solve, by his brother, Lord Ram. The problem was like, given integers, $N$ and $K$, Bharat has to find the number (possibilities) of non-increasing arrays of length $K$, where each element of the array is between $1$ and $N$... | {"inputs": ["2 5"], "outputs": ["6"]} | 403 | 14 |
coding | Solve the programming task below in a Python markdown code block.
The code provided is supposed replace all the dots `.` in the specified String `str` with dashes `-`
But it's not working properly.
# Task
Fix the bug so we can all go home early.
# Notes
String `str` will never be null.
Also feel free to reuse/exte... | {"functional": "_inputs = [[''], ['no dots'], ['one.two.three'], ['........']]\n_outputs = [[''], ['no dots'], ['one-two-three'], ['--------']]\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 isinstanc... | 90 | 179 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given head which is a reference node to a singly-linked list. The value of each node in the linked list is either 0 or 1. The linked list holds the binary representation of a number.
Return the decimal value of the nu... | {"functional": "def check(candidate):\n assert candidate(head = list_node([1,0,1])) == 5\n assert candidate(head = list_node([0])) == 0\n assert candidate(head = list_node([1])) == 1\n assert candidate(head = list_node([1,0,0,1,0,0,1,1,1,0,0,0,0,0,0])) == 18880\n assert candidate(head = list_node([0,0]))... | 155 | 128 |
coding | Solve the programming task below in a Python markdown code block.
Vova again tries to play some computer card game.
The rules of deck creation in this game are simple. Vova is given an existing deck of n cards and a magic number k. The order of the cards in the deck is fixed. Each card has a number written on it; numb... | {"inputs": ["1 1\n1\n", "1 2\n1\n", "1 3\n1\n", "1 4\n1\n", "1 5\n3\n", "1 6\n4\n", "1 7\n2\n", "1 8\n3\n"], "outputs": ["1\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | 469 | 102 |
coding | Solve the programming task below in a Python markdown code block.
A very easy task for you!
You have to create a method, that corrects a given date string.
There was a problem in addition, so many of the date strings are broken.
Date-Format is european. That means "DD.MM.YYYY".
Some examples:
"30.02.2016" -> "01.03... | {"functional": "_inputs = [[None], [''], ['01112016'], ['01,11,2016'], ['0a.1c.2016'], ['03.12.2016'], ['30.02.2016'], ['40.06.2015'], ['11.13.2014'], ['33.13.2014'], ['99.11.2010']]\n_outputs = [[None], [''], [None], [None], [None], ['03.12.2016'], ['01.03.2016'], ['10.07.2015'], ['11.01.2015'], ['02.02.2015'], ['07.0... | 260 | 345 |
coding | Solve the programming task below in a Python markdown code block.
# ASC Week 1 Challenge 5 (Medium #2)
Create a function that takes a 2D array as an input, and outputs another array that contains the average values for the numbers in the nested arrays at the corresponding indexes.
Note: the function should also work... | {"functional": "_inputs = [[[[1, 2, 3, 4], [5, 6, 7, 8]]], [[[2, 3, 9, 10, 7], [12, 6, 89, 45, 3], [9, 12, 56, 10, 34], [67, 23, 1, 88, 34]]], [[[2, 5, 4, 3, 19], [2, 5, 6, 7, 10]]], [[[1.2, 8.521, 0.4, 3.14, 1.9], [2, 4.5, 3.75, 0.987, 1.0]]], [[[2, 5, -4, 3, -19], [-2, -5, 6, 7, 10]]], [[[-2, -18, -45, -10], [0, -45,... | 488 | 531 |
coding | Solve the programming task below in a Python markdown code block.
Move the first letter of each word to the end of it, then add "ay" to the end of the word. Leave punctuation marks untouched.
## Examples
```python
pig_it('Pig latin is cool') # igPay atinlay siay oolcay
pig_it('Hello world !') # elloHay orldway !
... | {"functional": "_inputs = [['Pig latin is cool'], ['This is my string']]\n_outputs = [['igPay atinlay siay oolcay'], ['hisTay siay ymay tringsay']]\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... | 202 | 187 |
coding | Solve the programming task below in a Python markdown code block.
You are given an array $a$ of length $2n$. Consider a partition of array $a$ into two subsequences $p$ and $q$ of length $n$ each (each element of array $a$ should be in exactly one subsequence: either in $p$ or in $q$).
Let's sort $p$ in non-decreasing... | {"inputs": ["1\n1 4\n", "1\n2 5\n", "1\n2 5\n", "1\n3 5\n", "1\n1 6\n", "1\n4 5\n", "1\n1 9\n", "1\n1 7\n"], "outputs": ["6", "6", "6\n", "4\n", "10\n", "2\n", "16\n", "12\n"]} | 753 | 103 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.
Ple... | {"functional": "def check(candidate):\n assert candidate(nums = [8,2,4,7], limit = 4) == 2 \n assert candidate(nums = [10,1,2,4,7,2], limit = 5) == 4 \n assert candidate(nums = [4,2,2,2,4,4,2,2], limit = 0) == 3\n\n\ncheck(Solution().longestSubarray)"} | 95 | 105 |
coding | Solve the programming task below in a Python markdown code block.
You are given two positive integers N and K. How many multisets of rational numbers satisfy all of the following conditions?
- The multiset has exactly N elements and the sum of them is equal to K.
- Each element of the multiset is one of 1, \frac{1}{2... | {"inputs": ["4 2\n", "1 1\n", "2 1\n", "2 2\n", "3 1\n", "6 4\n", "88 11\n", "97 24\n"], "outputs": ["2\n", "1\n", "1\n", "1\n", "1\n", "2\n", "843932061\n", "120274922\n"]} | 301 | 106 |
coding | Solve the programming task below in a Python markdown code block.
The Collatz Conjecture states that for any natural number n, if n is even, divide it by 2. If n is odd, multiply it by 3 and add 1. If you repeat the process continuously for n, n will eventually reach 1.
For example, if n = 20, the resulting sequence w... | {"functional": "_inputs = [[100], [10], [500], [73567465519280238573], [1000000000], [1000000000000000]]\n_outputs = [[26], [7], [111], [362], [101], [276]]\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 ... | 184 | 241 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian.
Chef loves to prepare delicious dishes. This time, Chef has decided to prepare a special dish for you, and needs to gather several apples to do so.
Chef has N apple trees in his home garden. E... | {"inputs": ["2\n3\n3 3 3\n4\n1 2 3 3", "2\n3\n3 3 3\n4\n1 4 3 3", "2\n3\n3 5 3\n4\n1 2 3 3", "2\n3\n3 9 3\n4\n1 2 3 4", "2\n3\n3 5 4\n4\n1 2 3 3", "2\n3\n6 9 3\n4\n1 2 3 4", "2\n3\n2 3 3\n4\n1 1 6 6", "2\n3\n3 3 3\n4\n1 1 3 3"], "outputs": ["1\n3", "1\n3\n", "2\n3\n", "2\n4\n", "3\n3\n", "3\n4\n", "2\n2\n", "1\n2\n"]} | 654 | 221 |
coding | Solve the programming task below in a Python markdown code block.
Polycarp knows that if the sum of the digits of a number is divisible by $3$, then the number itself is divisible by $3$. He assumes that the numbers, the sum of the digits of which is divisible by $4$, are also somewhat interesting. Thus, he considers a... | {"inputs": ["1\n", "2\n", "8\n", "9\n", "7\n", "4\n", "3\n", "6\n"], "outputs": ["4\n", "4\n", "8\n", "13\n", "8\n", "4\n", "4\n", "8\n"]} | 254 | 71 |
coding | Solve the programming task below in a Python markdown code block.
I need to save some money to buy a gift. I think I can do something like that:
First week (W0) I save nothing on Sunday, 1 on Monday, 2 on Tuesday... 6 on Saturday,
second week (W1) 2 on Monday... 7 on Saturday and so on according to the table below whe... | {"functional": "_inputs = [[5], [6], [8], [15], [100], [365], [730], [999], [2000], [4000], [5000]]\n_outputs = [[105], [168], [360], [2040], [515100], [24513765], [195308580], [499999500], [4006002000], [32024004000], [62537505000]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance... | 469 | 298 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer array nums sorted in non-decreasing order and an integer target, return true if target is a majority element, or false otherwise.
A majority element in an array nums is an element that appears more th... | {"functional": "def check(candidate):\n assert candidate(nums = [2,4,5,5,5,5,5,6,6], target = 5) == True\n assert candidate(nums = [10,100,101,101], target = 101) == False\n\n\ncheck(Solution().isMajorityElement)"} | 107 | 84 |
coding | Solve the programming task below in a Python markdown code block.
Create a function that will return ```true``` if the input is in the following date time format ```01-09-2016 01:20``` and ```false``` if it is not.
This Kata has been inspired by the Regular Expressions chapter from the book Eloquent JavaScript.
Also f... | {"functional": "_inputs = [['01-09-2016 01:20'], ['01-09-2016 01;20'], ['01_09_2016 01:20'], ['14-10-1066 12:00'], ['Tenth of January'], ['20 Sep 1988'], ['19-12-2050 13:34'], ['Tue Sep 06 2016 01:46:38 GMT+0100'], ['01-09-2016 00:00'], ['01-09-2016 2:00']]\n_outputs = [[True], [False], [False], [True], [False], [False... | 98 | 346 |
coding | Solve the programming task below in a Python markdown code block.
Recently a serious bug has been found in the FOS code. The head of the F company wants to find the culprit and punish him. For that, he set up an organizational meeting, the issue is: who's bugged the code? Each of the n coders on the meeting said: 'I kn... | {"inputs": ["3 2\n2 3\n3 1\n2 1\n", "3 0\n2 3\n3 1\n2 1\n", "3 0\n2 1\n3 1\n2 1\n", "4 2\n3 4\n4 3\n4 2\n3 1\n", "4 4\n3 4\n4 3\n1 2\n2 1\n", "4 1\n3 2\n4 1\n4 2\n1 2\n", "4 4\n3 4\n3 4\n1 2\n1 2\n", "4 4\n2 3\n4 3\n2 1\n2 3\n"], "outputs": ["3\n", "3\n", "3\n", "6\n", "4\n", "6\n", "4\n", "3\n"]} | 426 | 202 |
coding | Solve the programming task below in a Python markdown code block.
Little penguin Polo adores strings. But most of all he adores strings of length n.
One day he wanted to find a string that meets the following conditions:
1. The string consists of n lowercase English letters (that is, the string's length equals n), ... | {"inputs": ["3 3\n", "1 1\n", "1 2\n", "2 2\n", "7 7\n", "9 4\n", "4 4\n", "1 4\n"], "outputs": ["abc\n", "a\n", "-1\n", "ab\n", "abcdefg\n", "abababacd\n", "abcd\n", "-1\n"]} | 370 | 90 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a string s and a string array dictionary, return the longest string in the dictionary that can be formed by deleting some of the given string characters. If there is more than one possible result, return the lon... | {"functional": "def check(candidate):\n assert candidate(s = \"abpcplea\", dictionary = [\"ale\",\"apple\",\"monkey\",\"plea\"]) == \"apple\"\n assert candidate(s = \"abpcplea\", dictionary = [\"a\",\"b\",\"c\"]) == \"a\"\n\n\ncheck(Solution().findLongestWord)"} | 117 | 78 |
coding | Solve the programming task below in a Python markdown code block.
# Task
The number is considered to be `unlucky` if it does not have digits `4` and `7` and is divisible by `13`. Please count all unlucky numbers not greater than `n`.
# Example
For `n = 20`, the result should be `2` (numbers `0 and 13`).
For `n =... | {"functional": "_inputs = [[20], [100], [1000], [1000000]]\n_outputs = [[2], [7], [40], [20182]]\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(... | 197 | 191 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
On a campus represented on the X-Y plane, there are n workers and m bikes, with n <= m.
You are given an array workers of length n where workers[i] = [xi, yi] is the position of the ith worker. You are also given an a... | {"functional": "def check(candidate):\n assert candidate(workers = [[0,0],[2,1]], bikes = [[1,2],[3,3]]) == [1,0]\n assert candidate(workers = [[0,0],[1,1],[2,0]], bikes = [[1,0],[2,2],[2,1]]) == [0,2,1]\n\n\ncheck(Solution().assignBikes)"} | 314 | 96 |
coding | Solve the programming task below in a Python markdown code block.
Harsh was recently gifted a book consisting of N pages. Each page contains exactly M words printed on it. As he was bored, he decided to count the number of words in the book.
Help Harsh find the total number of words in the book.
------ Input Format ... | {"inputs": ["4\n1 1\n4 2\n2 4\n95 42\n"], "outputs": ["1\n8\n8\n3990\n"]} | 394 | 41 |
coding | Solve the programming task below in a Python markdown code block.
By 2312 there were n Large Hadron Colliders in the inhabited part of the universe. Each of them corresponded to a single natural number from 1 to n. However, scientists did not know what activating several colliders simultaneously could cause, so the col... | {"inputs": ["100 1\n+ 51\n", "100 1\n+ 94\n", "100 1\n+ 68\n", "4 2\n+ 2\n+ 4\n", "100000 1\n+ 7528\n", "100000 1\n+ 8355\n", "100001 1\n+ 7528\n", "100000 1\n+ 2505\n"], "outputs": ["Success\n", "Success\n", "Success\n", "Success\nConflict with 2\n", "Success\n", "Success\n", "Success\n", "Success\n"]} | 743 | 168 |
coding | Solve the programming task below in a Python markdown code block.
You are given a forest with N vertices and M edges. The vertices are numbered 0 through N-1. The edges are given in the format (x_i,y_i), which means that Vertex x_i and y_i are connected by an edge.
Each vertex i has a value a_i. You want to add edges ... | {"inputs": ["1 0\n7", "1 0\n5", "5 0\n3 0 4 1 5", "1 0\n3 0 4 1 2", "2 0\n4 0 1 1 1", "2 0\n7 1 4 1 2", "2 0\n9 1 0 0 2", "2 0\n6 0 0 2 2"], "outputs": ["0\n", "0", "Impossible\n", "0\n", "4\n", "8\n", "10\n", "6\n"]} | 374 | 142 |
coding | Solve the programming task below in a Python markdown code block.
A plot of land can be described by $M x N$ dots such that horizontal and vertical distance between any two dots is 10m.
Mr. Wolf would like to build a house in the land such that all four sides of the house are equal. Help Mr. Wolf to find the total numb... | {"inputs": ["4\n2 4\n3 4\n4 4\n1000 500"], "outputs": ["3\n10\n20\n624937395"]} | 298 | 49 |
coding | Solve the programming task below in a Python markdown code block.
You are given an integer N. Let A be an N \times N grid such that A_{i, j} = i + N\cdot(j-1) for 1 ≤ i, j ≤ N. For example, if N = 4 the grid looks like:
You start at the top left corner of the grid, i.e, cell (1, 1). You would like to reach the bottom-... | {"inputs": ["4\n1 0\n2 0\n2 1\n3 1\n"], "outputs": ["No\nYes\nYes\nYes\n"]} | 592 | 36 |
coding | Solve the programming task below in a Python markdown code block.
Takahashi is meeting up with Aoki.
They have planned to meet at a place that is D meters away from Takahashi's house in T minutes from now.
Takahashi will leave his house now and go straight to the place at a speed of S meters per minute.
Will he arrive ... | {"inputs": ["1 1 1\n", "3 0 001", "27 0 101", "27 0 001", "50 0 001", "1001 0 2", "11000 1 1", "11000 1 2"], "outputs": ["Yes\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n"]} | 247 | 117 |
coding | Solve the programming task below in a Python markdown code block.
A tutorial for this problem is now available on our blog. Click here to read it.
You are asked to calculate factorials of some small positive integers.
------ Input ------
An integer t, 1≤t≤100, denoting the number of testcases, followed by t lines... | {"inputs": ["4\n1\n2\n5\n3", "4\n2\n2\n5\n3", "4\n2\n2\n5\n6", "4\n2\n2\n8\n6", "4\n2\n2\n2\n6", "4\n1\n2\n2\n6", "4\n1\n2\n2\n9", "4\n2\n2\n2\n9"], "outputs": ["1\n2\n120\n6", "2\n2\n120\n6\n", "2\n2\n120\n720\n", "2\n2\n40320\n720\n", "2\n2\n2\n720\n", "1\n2\n2\n720\n", "1\n2\n2\n362880\n", "2\n2\n2\n362880\n"]} | 145 | 201 |
coding | Solve the programming task below in a Python markdown code block.
We will call a string obtained by arranging the characters contained in a string a in some order, an anagram of a.
For example, greenbin is an anagram of beginner. As seen here, when the same character occurs multiple times, that character must be used t... | {"inputs": ["2\noneplustwo\nnioemodsix", "2\nonepltsuwo\nnioemodsix", "2\nowustlpeno\nnioemodsix", "2\nowustlpeno\nnxoemodsii", "2\nowustlpeno\nnxofmodsii", "2\nowustlpeno\nnxofiodsim", "2\nonepltsuwo\nnxofiodsim", "2\nonepltsuwo\nnyofiodsim"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | 350 | 150 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
The value of an alphanumeric string can be defined as:
The numeric representation of the string in base 10, if it comprises of digits only.
The length of the string, otherwise.
Given an array strs of alphanumeric st... | {"functional": "def check(candidate):\n assert candidate(strs = [\"alic3\",\"bob\",\"3\",\"4\",\"00000\"]) == 5\n assert candidate(strs = [\"1\",\"01\",\"001\",\"0001\"]) == 1\n\n\ncheck(Solution().maximumValue)"} | 104 | 74 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
A company has n employees with a unique ID for each employee from 0 to n - 1. The head of the company is the one with headID.
Each employee has one direct manager given in the manager array where manager[i] is the dir... | {"functional": "def check(candidate):\n assert candidate(n = 1, headID = 0, manager = [-1], informTime = [0]) == 0\n assert candidate(n = 6, headID = 2, manager = [2,2,-1,2,2,2], informTime = [0,0,1,0,0,0]) == 1\n\n\ncheck(Solution().numOfMinutes)"} | 248 | 98 |
coding | Solve the programming task below in a Python markdown code block.
The Rebel fleet is on the run. It consists of m ships currently gathered around a single planet. Just a few seconds ago, the vastly more powerful Empire fleet has appeared in the same solar system, and the Rebels will need to escape into hyperspace. In o... | {"inputs": ["4\n(99+98)/97\n(26+4)/10\n(12+33)/15\n(5+1)/7\n", "4\n(99+98)/97\n(16+4)/10\n(12+33)/15\n(5+1)/7\n", "4\n(97+98)/99\n(26+4)/10\n(12+33)/15\n(5+1)/7\n", "4\n(99+98)/97\n(27+4)/10\n(12+33)/15\n(5+1)/7\n", "4\n(99+98)/97\n(27+4)/10\n(13+33)/15\n(5+1)/7\n", "4\n(99+98)/97\n(20+4)/17\n(13+33)/15\n(5+1)/7\n", "4... | 420 | 399 |
coding | Solve the programming task below in a Python markdown code block.
Given a string made up of letters a, b, and/or c, switch the position of letters a and b (change a to b and vice versa). Leave any incidence of c untouched.
Example:
'acb' --> 'bca'
'aabacbaa' --> 'bbabcabb'
Also feel free to reuse/extend the following... | {"functional": "_inputs = [['abc'], ['aaabcccbaaa'], ['ccccc'], ['abababababababab'], ['aaaaa']]\n_outputs = [['bac'], ['bbbacccabbb'], ['ccccc'], ['babababababababa'], ['bbbbb']]\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... | 96 | 205 |
coding | Solve the programming task below in a Python markdown code block.
Complete the function that takes an array of words.
You must concatenate the `n`th letter from each word to construct a new word which should be returned as a string, where `n` is the position of the word in the list.
For example:
```
["yoda", "best",... | {"functional": "_inputs = [[['yoda', 'best', 'has']], [[]], [['X-ray']], [['No', 'No']], [['Chad', 'Morocco', 'India', 'Algeria', 'Botswana', 'Bahamas', 'Ecuador', 'Micronesia']]]\n_outputs = [['yes'], [''], ['X'], ['No'], ['Codewars']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinsta... | 154 | 222 |
coding | Solve the programming task below in a Python markdown code block.
You are given an integer $n$. A set, $\mbox{S}$, of triples $(x_i,y_i,z_i)$ is beautiful if and only if:
$0\leq x_i,y_i,z_i$
$x_i+y_i+z_i=n,\forall i:1\leq i\leq|S|$
Let $\mbox{X}$ be the set of different $x_i$'s in $\mbox{S}$, $\mathbf{Y}$ be the set o... | {"inputs": ["3\n"], "outputs": ["3\n0 1 2\n2 0 1\n1 2 0\n"]} | 600 | 32 |
coding | Solve the programming task below in a Python markdown code block.
# Grasshopper - Function syntax debugging
A student was working on a function and made some syntax mistakes while coding. Help them find their mistakes and fix them.
Also feel free to reuse/extend the following starter code:
```python
def main(verb, nou... | {"functional": "_inputs = [['take ', 'item'], ['use ', 'sword']]\n_outputs = [['take item'], ['use sword']]\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... | 69 | 167 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an array nums consisting of positive integers.
You can perform the following operation on the array any number of times:
Choose any two adjacent elements and replace them with their sum.
For example,... | {"functional": "def check(candidate):\n assert candidate(nums = [4,3,2,1,2,3,1]) == 2\n assert candidate(nums = [1,2,3,4]) == 3\n\n\ncheck(Solution().minimumOperations)"} | 132 | 61 |
coding | Solve the programming task below in a Python markdown code block.
**Steps**
1. Square the numbers that are greater than zero.
2. Multiply by 3 every third number.
3. Multiply by -1 every fifth number.
4. Return the sum of the sequence.
**Example**
`{ -2, -1, 0, 1, 2 }` returns `-6`
```
1. { -2, -1, 0, 1 * 1, 2 * 2 ... | {"functional": "_inputs = [[[0, 2, 1, -6, -3, 3]], [[0]], [[1, 1, 1, 1, 1]], [[1, 1, -9, 9, 16, -15, -45, -73, 26]], [[1, -1, 10, -9, 16, 15, 45, -73, -26]], [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], [[-5, -5, -5, -5, -5, -5, -5]]]\n_outputs = [[31], [0], [5], [1665], [2584], [0], [-45]]\nimport math\ndef _deep_eq(a, ... | 204 | 338 |
coding | Solve the programming task below in a Python markdown code block.
Bizon the Champion is called the Champion for a reason.
Bizon the Champion has recently got a present — a new glass cupboard with n shelves and he decided to put all his presents there. All the presents can be divided into two types: medals and cups. B... | {"inputs": ["1 1 1\n1 1 1\n4\n", "1 1 3\n2 3 4\n2\n", "1 0 0\n1 0 0\n1\n", "0 0 0\n0 0 0\n1\n", "1 1 1\n0 0 0\n1\n", "0 0 0\n1 1 1\n1\n", "5 5 5\n0 0 0\n2\n", "1 2 3\n2 4 6\n3\n"], "outputs": ["YES\n", "YES\n", "NO\n", "YES\n", "YES\n", "YES\n", "NO\n", "NO\n"]} | 403 | 166 |
coding | Solve the programming task below in a Python markdown code block.
Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like.
... | {"inputs": ["1\n5\n", "1\n1\n", "1\n2\n", "1\n3\n", "1\n6\n", "1\n4\n", "1\n8\n", "2\n2 1\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | 594 | 88 |
coding | Solve the programming task below in a Python markdown code block.
Takaki Tono is a Computer Programmer in Tokyo. His boss at work shows him an online puzzle, which if solved would earn the solver a full expense paid trip to Los Angeles, California. Takaki really wants to solve this, as the love of his life, Akari, live... | {"inputs": ["5\n1 2 7 4 5\n1 2\n2 3\n2 4\n2 5\n7\nC 1 5\nF 1 5\nC 2 4\nC 1 2\nF 1 3\nF 3 4\nF 2 4"], "outputs": ["1\n4\n2\n1\n6\n5\n2"]} | 722 | 94 |
coding | Solve the programming task below in a Python markdown code block.
Your task is to calculate logical value of boolean array. Test arrays are one-dimensional and their size is in the range 1-50.
Links referring to logical operations: [AND](https://en.wikipedia.org/wiki/Logical_conjunction), [OR](https://en.wikipedia.org... | {"functional": "_inputs = [[[True, True, True, False], 'AND'], [[True, True, True, False], 'OR'], [[True, True, True, False], 'XOR'], [[True, True, False, False], 'AND'], [[True, True, False, False], 'OR'], [[True, True, False, False], 'XOR'], [[True, False, False, False], 'AND'], [[True, False, False, False], 'OR'], [... | 265 | 411 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You want to schedule a list of jobs in d days. Jobs are dependent (i.e To work on the ith job, you have to finish all the jobs j where 0 <= j < i).
You have to finish at least one task every day. The difficulty of a j... | {"functional": "def check(candidate):\n assert candidate(jobDifficulty = [6,5,4,3,2,1], d = 2) == 7\n assert candidate(jobDifficulty = [9,9,9], d = 4) == -1\n assert candidate(jobDifficulty = [1,1,1], d = 3) == 3\n assert candidate(jobDifficulty = [7,1,7,1,7,1], d = 3) == 15\n assert candidate(jobDifficu... | 187 | 166 |
coding | Solve the programming task below in a Python markdown code block.
You are given two set of points. The first set is determined by the equation A1x + B1y + C1 = 0, and the second one is determined by the equation A2x + B2y + C2 = 0.
Write the program which finds the number of points in the intersection of two given set... | {"inputs": ["2 2 1\n1 2 0\n", "1 0 0\n0 1 0\n", "1 1 0\n2 2 1\n", "1 1 2\n0 1 0\n", "0 0 0\n0 0 1\n", "0 1 0\n1 0 1\n", "1 0 1\n0 0 1\n", "4 6 1\n2 3 1\n"], "outputs": ["1", "1", "0", "1", "0", "1", "0", "0"]} | 202 | 142 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.