problem stringlengths 14 4.09k | solution stringlengths 1 802k | task_type stringclasses 3
values | problem_tokens int64 5 895 |
|---|---|---|---|
Solve the programming task below in a Python markdown code block.
You are given an integer x of n digits a_1, a_2, …, a_n, which make up its decimal notation in order from left to right.
Also, you are given a positive integer k < n.
Let's call integer b_1, b_2, …, b_m beautiful if b_i = b_{i+k} for each i, such that ... | {"inputs": ["2 1\n12\n", "2 1\n31\n", "2 1\n33\n", "2 1\n99\n", "3 1\n123\n", "3 1\n898\n", "3 2\n798\n", "3 2\n192\n"], "outputs": ["2\n22\n", "2\n33\n", "2\n33\n", "2\n99\n", "3\n222\n", "3\n999\n", "3\n808\n", "3\n202\n"]} | coding | 299 |
Solve the programming task below in a Python markdown code block.
It's been a tough week at work and you are stuggling to get out of bed in the morning.
While waiting at the bus stop you realise that if you could time your arrival to the nearest minute you could get valuable extra minutes in bed.
There is a bus that ... | {"functional": "_inputs = [['10:00'], ['10:45'], ['15:05'], ['06:10'], ['05:10'], ['04:50'], ['05:55'], ['23:57'], ['00:00'], ['23:55']]\n_outputs = [[10], [10], [5], [0], [45], [65], [0], [358], [355], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n retur... | coding | 291 |
Solve the programming task below in a Python markdown code block.
Given an array a_1, a_2, ..., a_{n} of n integers, find the largest number in the array that is not a perfect square.
A number x is said to be a perfect square if there exists an integer y such that x = y^2.
-----Input-----
The first line contains a ... | {"inputs": ["1\n2\n", "1\n2\n", "1\n-1\n", "1\n-1\n", "1\n-2\n", "1\n-4\n", "1\n-6\n", "1\n-8\n"], "outputs": ["2\n", "2\n", "-1\n", "-1\n", "-2\n", "-4\n", "-6\n", "-8\n"]} | coding | 270 |
Solve the programming task below in a Python markdown code block.
In this Kata, we are going to determine if the count of each of the characters in a string can be equal if we remove a single character from that string.
For example:
```
solve('abba') = false -- if we remove any character, the count of each character w... | {"functional": "_inputs = [['aaaa'], ['abba'], ['abbba'], ['aabbcc'], ['aaaabb'], ['aabbccddd'], ['aabcde'], ['abcde'], ['aaabcde'], ['abbccc']]\n_outputs = [[True], [False], [True], [False], [False], [True], [True], [True], [False], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or i... | coding | 176 |
Solve the programming task below in a Python markdown code block.
Two people are playing game of Misère Nim. The basic rules for this game are as follows:
The game starts with $n$ piles of stones indexed from $o$ to $n-1$. Each pile $i$ (where $0\leq i<n$) has $s_i$ stones.
The players move in alternating turns. Durin... | {"inputs": ["2 \n2 \n1 1\n3 \n2 1 3\n"], "outputs": ["First\nSecond\n"]} | coding | 623 |
Solve the programming task below in a Python markdown code block.
problem
JOI, who has been suffering from his winter vacation homework every time, decided to do his homework systematically this time. Homework is a national language and math drill, with a national language drill on page A and a math drill on page B.
... | {"inputs": ["20\n2\n6\n3\n1", "20\n4\n0\n6\n1", "20\n8\n9\n7\n1", "20\n4\n6\n3\n1", "20\n4\n6\n6\n1", "20\n1\n4\n6\n6", "20\n4\n0\n6\n2", "20\n1\n4\n6\n2"], "outputs": ["14\n", "19\n", "11\n", "14\n", "14\n", "19\n", "19\n", "18\n"]} | coding | 386 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays.
The overall run time complexity should be O(log (m+n)).
Please complete the following python code pre... | {"functional": "def check(candidate):\n assert candidate(nums1 = [1,3], nums2 = [2]) == 2.00000\n assert candidate(nums1 = [1,2], nums2 = [3,4]) == 2.50000\n\n\ncheck(Solution().findMedianSortedArrays)"} | coding | 95 |
Solve the programming task below in a Python markdown code block.
Bob has a rectangular chocolate bar of the size W × H. He introduced a cartesian coordinate system so that the point (0, 0) corresponds to the lower-left corner of the bar, and the point (W, H) corresponds to the upper-right corner. Bob decided to split ... | {"inputs": ["100 100 1\n0 14 100 14\n", "2 7 2\n0 1 2 1\n0 3 2 3\n", "2 8 2\n0 1 2 1\n0 3 2 3\n", "2 2 2\n1 0 1 2\n1 1 2 1\n", "2 5 2\n0 1 2 1\n0 3 2 3\n", "2 9 2\n0 1 2 1\n0 3 2 3\n", "2 6 2\n0 1 2 1\n0 3 2 3\n", "2 4 2\n0 1 2 1\n0 3 2 3\n"], "outputs": ["1400 8600 \n", "2 4 8\n", "2 4 10\n", "1 1 2\n", "2 4 4\n", "2 ... | coding | 523 |
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"]} | coding | 318 |
Solve the programming task below in a Python markdown code block.
Problem Statement:
Tom is collecting money for his birthday party, he is having 'a' coins today and his father gives him 'k' coins each day.
Since his birthday is on 'nth' day, he wants to know the amount of money he will have on his birthday.
Tom is... | {"inputs": ["100\n84 87 78\n16 94 36\n87 93 50\n22 63 28\n91 60 64\n27 41 27\n73 37 12\n69 68 30\n83 31 63\n24 68 36\n30 3 23\n59 70 68\n94 57 12\n43 30 74\n22 20 85\n38 99 25\n16 71 14\n27 92 81\n57 74 63\n71 97 82\n6 26 85\n28 37 6\n47 30 14\n58 25 96\n83 46 15\n68 35 65\n44 51 88\n9 77 79\n89 85 4\n52 55 100\n33 61 ... | coding | 271 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 2D integer array rectangles where rectangles[i] = [li, hi] indicates that ith rectangle has a length of li and a height of hi. You are also given a 2D integer array points where points[j] = [xj, yj] is... | {"functional": "def check(candidate):\n assert candidate(rectangles = [[1,2],[2,3],[2,5]], points = [[2,1],[1,4]]) == [2,1]\n assert candidate(rectangles = [[1,1],[2,2],[3,3]], points = [[1,3],[1,1]]) == [1,3]\n\n\ncheck(Solution().countRectangles)"} | coding | 228 |
Solve the programming task below in a Python markdown code block.
Takahashi, Aoki and Snuke love cookies. They have A, B and C cookies, respectively. Now, they will exchange those cookies by repeating the action below:
* Each person simultaneously divides his cookies in half and gives one half to each of the other two... | {"inputs": ["0 0 0", "4 0 13", "3 0 13", "6 0 13", "6 0 24", "1 25 5", "1 25 0", "2 25 0"], "outputs": ["-1\n", "0\n", "0\n", "0\n", "1\n", "0\n", "0\n", "0\n"]} | coding | 223 |
Solve the programming task below in a Python markdown code block.
Alice is a kindergarten teacher. She wants to give some candies to the children in her class. All the children sit in a line and each of them has a rating score according to his or her performance in the class. Alice wants to give at least 1 candy to e... | {"inputs": ["3\n1\n2\n2\n", "8\n2\n4\n3\n5\n2\n6\n4\n5\n", "10\n2\n4\n2\n6\n1\n7\n8\n9\n2\n1\n"], "outputs": ["4\n", "12\n", "19\n"]} | coding | 500 |
Solve the programming task below in a Python markdown code block.
You are given a string S of length 2N consisting of lowercase English letters.
There are 2^{2N} ways to color each character in S red or blue. Among these ways, how many satisfy the following condition?
* The string obtained by reading the characters p... | {"inputs": ["4\ncacaabba", "4\nacbaacab", "4\nhgfedcba", "4\nabbaacac", "4\nhgfbdcea", "4\nacbaacac", "4\nhgfbccea", "4\ncacaabca"], "outputs": ["0\n", "4\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | coding | 228 |
Solve the programming task below in a Python markdown code block.
You are given three integers $n$, $l$, and $r$. You need to construct an array $a_1,a_2,\dots,a_n$ ($l\le a_i\le r$) such that $\gcd(i,a_i)$ are all distinct or report there's no solution.
Here $\gcd(x, y)$ denotes the greatest common divisor (GCD) of i... | {"inputs": ["1\n100000 1 99999\n", "1\n100000 50021 100000\n", "4\n5 1 5\n9 1000 2000\n10 30 35\n1 1000000000 1000000000\n"], "outputs": ["NO\n", "NO\n", "YES\n1 2 3 4 5\nYES\n1000 1000 1002 1000 1000 1002 1001 1000 1008\nNO\nYES\n1000000000\n"]} | coding | 494 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given two integers a and b, return the sum of the two integers without using the operators + and -.
Please complete the following python code precisely:
```python
class Solution:
def getSum(self, a: int, b: int)... | {"functional": "def check(candidate):\n assert candidate(a = 1, b = 2) == 3\n assert candidate(a = 2, b = 3) == 5\n\n\ncheck(Solution().getSum)"} | coding | 73 |
Solve the programming task below in a Python markdown code block.
Snuke loves flags.
Snuke is placing N flags on a line.
The i-th flag can be placed at either coordinate x_i or coordinate y_i.
Snuke thinks that the flags look nicer when the smallest distance between two of them, d, is larger. Find the maximum possib... | {"inputs": ["3\n1 3\n2 5\n2 9", "3\n2 3\n2 5\n2 9", "3\n1 3\n2 5\n1 9", "3\n3 3\n2 5\n2 16", "3\n4 0\n5 0\n1 21", "3\n2 1\n8 0\n1 45", "3\n2 3\n2 5\n2 16", "3\n3 3\n2 5\n1 16"], "outputs": ["4\n", "3\n", "4", "2\n", "5\n", "7\n", "3\n", "2\n"]} | coding | 379 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You have a chat log of n messages. You are given two string arrays messages and senders where messages[i] is a message sent by senders[i].
A message is list of words that are separated by a single space with no leadin... | {"functional": "def check(candidate):\n assert candidate(messages = [\"Hello userTwooo\",\"Hi userThree\",\"Wonderful day Alice\",\"Nice day userThree\"], senders = [\"Alice\",\"userTwo\",\"userThree\",\"Alice\"]) == \"Alice\"\n assert candidate(messages = [\"How is leetcode for everyone\",\"Leetcode is useful fo... | coding | 195 |
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 with n nodes. Each node is assigned a unique value from 1 to n. You are also given an array queries of size m.
You have to perform m independent queries on the tree where in the... | {"functional": "def check(candidate):\n assert candidate(root = tree_node([1,3,4,2,None,6,5,None,None,None,None,None,7]), queries = [4]) == [2]\n assert candidate(root = tree_node([5,8,9,2,1,3,7,4,6]), queries = [3,2,4,8]) == [3,2,3,2]\n\n\ncheck(Solution().treeQueries)"} | coding | 265 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
A certain bug's home is on the x-axis at position x. Help them get there from position 0.
The bug jumps according to the following rules:
It can jump exactly a positions forward (to the right).
It can jump exactly b ... | {"functional": "def check(candidate):\n assert candidate(forbidden = [14,4,18,1,15], a = 3, b = 15, x = 9) == 3\n assert candidate(forbidden = [8,3,16,6,12,20], a = 15, b = 13, x = 11) == -1\n assert candidate(forbidden = [1,6,2,14,5,17,4], a = 16, b = 9, x = 7) == 2\n\n\ncheck(Solution().minimumJumps)"} | coding | 221 |
Solve the programming task below in a Python markdown code block.
Suppose there is a circle. There are $N$ petrol pumps on that circle. Petrol pumps are numbered $\mbox{0}$ to $(N-1)$ (both inclusive). You have two pieces of information corresponding to each of the petrol pump: (1) the amount of petrol that particular ... | {"inputs": ["3\n1 5\n10 3\n3 4\n"], "outputs": ["1\n"]} | coding | 318 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You and a gang of thieves are planning on robbing a bank. You are given a 0-indexed integer array security, where security[i] is the number of guards on duty on the ith day. The days are numbered starting from 0. You ... | {"functional": "def check(candidate):\n assert candidate(security = [5,3,3,3,5,6,2], time = 2) == [2,3]\n assert candidate(security = [1,1,1,1,1], time = 0) == [0,1,2,3,4]\n assert candidate(security = [1,2,3,4,5,6], time = 2) == []\n\n\ncheck(Solution().goodDaysToRobBank)"} | coding | 267 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an array of people, people, which are the attributes of some people in a queue (not necessarily in order). Each people[i] = [hi, ki] represents the ith person of height hi with exactly ki other people in... | {"functional": "def check(candidate):\n assert candidate(people = [[7,0],[4,4],[7,1],[5,0],[6,1],[5,2]]) == [[5,0],[7,0],[5,2],[6,1],[4,4],[7,1]]\n assert candidate(people = [[6,0],[5,0],[4,0],[3,2],[2,2],[1,4]]) == [[4,0],[5,0],[2,2],[3,2],[1,4],[6,0]]\n\n\ncheck(Solution().reconstructQueue)"} | coding | 175 |
Solve the programming task below in a Python markdown code block.
Chef's dog *binary* hears frequencies starting from 67 Hertz to 45000 Hertz (both inclusive).
If Chef's commands have a frequency of X Hertz, find whether *binary* can hear them or not.
------ Input Format ------
- The first line of input will conta... | {"inputs": ["5\n42\n67\n402\n45000\n45005\n"], "outputs": ["NO\nYES\nYES\nYES\nNO\n"]} | coding | 478 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a binary tree root, a node X in the tree is named good if in the path from root to X there are no nodes with a value greater than X.
Return the number of good nodes in the binary tree.
Please complete the foll... | {"functional": "def check(candidate):\n assert candidate(root = tree_node([3,1,4,3,None,1,5])) == 4\n assert candidate(root = tree_node([3,3,None,4,2])) == 3\n assert candidate(root = tree_node([1])) == 1\n\n\ncheck(Solution().goodNodes)"} | coding | 145 |
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)"} | coding | 281 |
Solve the programming task below in a Python markdown code block.
You are given a long decimal number $a$ consisting of $n$ digits from $1$ to $9$. You also have a function $f$ that maps every digit from $1$ to $9$ to some (possibly the same) digit from $1$ to $9$.
You can perform the following operation no more than ... | {"inputs": ["1\n5\n1 2 3 4 5 6 7 8 9\n", "1\n9\n2 3 4 5 6 7 8 9 1\n", "1\n2\n9 7 6 2 2 6 2 4 4\n", "1\n3\n2 8 4 5 4 1 7 2 3\n", "1\n2\n1 4 4 8 8 8 7 3 2\n", "1\n3\n4 9 9 6 8 4 5 5 5\n", "1\n6\n4 8 2 6 8 8 8 8 3\n", "1\n3\n8 7 8 7 8 5 8 2 2\n"], "outputs": ["5\n", "9\n", "7\n", "4\n", "4\n", "9\n", "8\n", "8\n"]} | coding | 434 |
Solve the programming task below in a Python markdown code block.
Reca company makes monitors, the most popular of their models is AB999 with the screen size a × b centimeters. Because of some production peculiarities a screen parameters are integer numbers. Recently the screen sides ratio x: y became popular with user... | {"inputs": ["1 1 2 1\n", "1 0 1 2\n", "1 0 2 2\n", "1 1 1 2\n", "620 600 4 3\n", "620 600 4 4\n", "800 600 4 3\n", "1920 1415 16 9\n"], "outputs": ["0 0", "0 0\n", "0 0\n", "0 0", "620 465\n", "600 600\n", "800 600", "1920 1080\n"]} | coding | 270 |
Solve the programming task below in a Python markdown code block.
Polycarp is mad about coding, that is why he writes Sveta encoded messages. He calls the median letter in a word the letter which is in the middle of the word. If the word's length is even, the median letter is the left of the two middle letters. In the ... | {"inputs": ["1\nw\n", "1\nw\n", "1\nv\n", "1\nu\n", "1\nt\n", "1\ns\n", "2\nno\n", "2\ncb\n"], "outputs": ["w\n", "w\n", "v\n", "u\n", "t\n", "s\n", "no\n", "cb\n"]} | coding | 527 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given the head of a linked list. Delete the middle node, and return the head of the modified linked list.
The middle node of a linked list of size n is the ⌊n / 2⌋th node from the start using 0-based indexing,... | {"functional": "def check(candidate):\n assert is_same_list(candidate(head = list_node([1,3,4,7,1,2,6])), list_node([1,3,4,1,2,6]))\n assert is_same_list(candidate(head = list_node([1,2,3,4])), list_node([1,2,4]))\n assert is_same_list(candidate(head = list_node([2,1])), list_node([2]))\n\n\ncheck(Solution().d... | coding | 205 |
Solve the programming task below in a Python markdown code block.
Let's define a split of $n$ as a nonincreasing sequence of positive integers, the sum of which is $n$.
For example, the following sequences are splits of $8$: $[4, 4]$, $[3, 3, 2]$, $[2, 2, 1, 1, 1, 1]$, $[5, 2, 1]$.
The following sequences aren't spl... | {"inputs": ["7\n", "8\n", "9\n", "1\n", "2\n", "3\n", "1\n", "3\n"], "outputs": ["4\n", "5\n", "5\n", "1\n", "2\n", "2\n", "1\n", "2\n"]} | coding | 459 |
Solve the programming task below in a Python markdown code block.
Chef has a binary string S of length N. Chef can perform the following operation on S:
Insert any character (0 or 1) at any position in S.
Find the minimum number of operations Chef needs to perform so that no two consecutive characters are same in S.
... | {"inputs": ["3\n2\n11\n4\n0101\n5\n00100\n"], "outputs": ["1\n0\n2\n"]} | coding | 339 |
Solve the programming task below in a Python markdown code block.
Not long ago Billy came across such a problem, where there were given three natural numbers A, B and C from the range [1, N], and it was asked to check whether the equation AB = C is correct. Recently Billy studied the concept of a digital root of a numb... | {"inputs": ["8\n", "6\n", "1\n", "7\n", "3\n", "9\n", "0\n", "2\n"], "outputs": ["40\n", "14\n", "0\n", "25\n", "0\n", "58\n", "0\n", "0\n"]} | coding | 360 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a non-negative integer num, Return its encoding string.
The encoding is done by converting the integer to a string using a secret function that you should deduce from the following table:
Please complete the ... | {"functional": "def check(candidate):\n assert candidate(num = 23) == \"1000\"\n assert candidate(num = 107) == \"101100\"\n\n\ncheck(Solution().encode)"} | coding | 83 |
Solve the programming task below in a Python markdown code block.
In the current semester, you have taken X RTP courses, Y Audit courses and Z Non-RTP courses.
The credit distribution for the courses are:
4 credits for clearing each RTP course.
2 credits for clearing each Audit course.
No credits for clearing a Non-R... | {"inputs": ["4\n6 6 5\n8 7 2\n9 3 8\n9 2 4\n"], "outputs": ["36\n46\n42\n40\n"]} | coding | 746 |
Solve the programming task below in a Python markdown code block.
Ridhiman challenged Ashish to find the maximum valued subsequence of an array $a$ of size $n$ consisting of positive integers.
The value of a non-empty subsequence of $k$ elements of $a$ is defined as $\sum 2^i$ over all integers $i \ge 0$ such that at... | {"inputs": ["1\n1\n", "1\n1\n", "2\n3 4\n", "2\n3 4\n", "2\n4 4\n", "2\n4 7\n", "2\n0 7\n", "3\n2 1 3\n"], "outputs": ["1", "1\n", "7", "7\n", "4\n", "7\n", "7\n", "3"]} | coding | 601 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a binary array nums, return the maximum number of consecutive 1's in the array.
Please complete the following python code precisely:
```python
class Solution:
def findMaxConsecutiveOnes(self, nums: List[in... | {"functional": "def check(candidate):\n assert candidate(nums = [1,1,0,1,1,1]) == 3\n assert candidate(nums = [1,0,1,1,0,1]) == 2\n\n\ncheck(Solution().findMaxConsecutiveOnes)"} | coding | 71 |
Solve the programming task below in a Python markdown code block.
Vasya has his favourite number $n$. He wants to split it to some non-zero digits. It means, that he wants to choose some digits $d_1, d_2, \ldots, d_k$, such that $1 \leq d_i \leq 9$ for all $i$ and $d_1 + d_2 + \ldots + d_k = n$.
Vasya likes beauty in ... | {"inputs": ["1\n", "4\n", "2\n", "3\n", "5\n", "6\n", "7\n", "8\n"], "outputs": ["1\n1 ", "4\n1 1 1 1 ", "2\n1 1 ", "3\n1 1 1 ", "5\n1 1 1 1 1 ", "6\n1 1 1 1 1 1 ", "7\n1 1 1 1 1 1 1 ", "8\n1 1 1 1 1 1 1 1 "]} | coding | 535 |
Solve the programming task below in a Python markdown code block.
Every year the professor selects the top two students from his class and takes them on a fun filled field trip, this year Ali and Zafar were selected.
The professor took them to a place where there was a never-ending queue of solid metal cubes. The profe... | {"inputs": ["4\n3 3 8 8", "4\n2 8 7 3"], "outputs": ["3", "4"]} | coding | 489 |
Solve the programming task below in a Python markdown code block.
[Chopsticks (singular: chopstick) are short, frequently tapered sticks used in pairs of equal length, which are used as the traditional eating utensils of China, Japan, Korea and Vietnam. Originated in ancient China, they can also be found in some areas ... | {"inputs": ["5 2\n1\n3\n3\n9\n4", "5 2\n2\n3\n3\n9\n4", "5 2\n6\n0\n3\n9\n6", "5 0\n6\n0\n3\n5\n4", "5 2\n3\n3\n3\n9\n4", "5 2\n6\n3\n3\n9\n4", "5 2\n6\n3\n3\n9\n6", "5 2\n0\n3\n3\n9\n4"], "outputs": ["2", "2\n", "1\n", "0\n", "2\n", "2\n", "2\n", "1\n"]} | coding | 513 |
Solve the programming task below in a Python markdown code block.
Given a random string consisting of numbers, letters, symbols, you need to sum up the numbers in the string.
Note:
- Consecutive integers should be treated as a single number. eg, `2015` should be treated as a single number `2015`, NOT four numbers
- ... | {"functional": "_inputs = [['In 2015, I want to know how much does iPhone 6+ cost?'], ['1+1=2'], ['e=mc^2'], ['aHR0cDovL3d3dy5jb2Rld2Fycy5jb20va2F0YS9uZXcvamF2YXNjcmlwdA=='], ['a30561ff4fb19170aa598b1431b52edad1fcc3e0'], ['x1KT CmZ__\\rYouOY8Uqu-ETtz'], ['x1KT-8&*@\"CmZ__\\rYouO __Y8Uq\\\\u-ETtz'], [''], ['Hello Wor... | coding | 222 |
Solve the programming task below in a Python markdown code block.
There are N Snukes lining up in a row. You are given a string S of length N. The i-th Snuke from the front has two red balls if the i-th character in S is `0`; one red ball and one blue ball if the i-th character in S is `1`; two blue balls if the i-th c... | {"inputs": ["1", "0", "2", "0", "1", "2", "10", "11"], "outputs": ["2\n", "1\n", "1\n", "1\n", "2\n", "1\n", "4\n", "6\n"]} | coding | 364 |
Solve the programming task below in a Python markdown code block.
In this problem is used an extremely simplified version of HTML table markup. Please use the statement as a formal document and read it carefully.
A string is a bHTML table, if it satisfies the grammar:
TABLE ::= <table>ROWS</table... | {"inputs": ["<table><tr><td></td></tr></table>\n", "<\nt\na\nble><tr><td></td>\n</\ntr>\n</\nt\nab\nle>\n", "<table><tr><td><table><tr><td></td></tr></table></td></tr></table>\n", "<table><tr><td></td></tr></table>\n", "<table><tr><td><table><tr><td><table><tr><td></td></tr></table><... | coding | 706 |
Solve the programming task below in a Python markdown code block.
You are given two sorted arrays that contain only integers. Your task is to find a way to merge them into a single one, sorted in **ascending order**. Complete the function `mergeArrays(arr1, arr2)`, where `arr1` and `arr2` are the original sorted arrays... | {"functional": "_inputs = [[[1, 2, 3, 4], [5, 6, 7, 8]], [[10, 8, 6, 4, 2], [9, 7, 5, 3, 1]], [[-20, 35, 36, 37, 39, 40], [-10, -5, 0, 6, 7, 8, 9, 10, 25, 38, 50, 62]], [[5, 6, 7, 8, 9, 10], [20, 18, 15, 14, 13, 12, 11, 4, 3, 2]], [[45, 30, 20, 15, 12, 5], [9, 10, 18, 25, 35, 50]], [[-8, -3, -2, 4, 5, 6, 7, 15, 42, 90,... | coding | 198 |
Solve the programming task below in a Python markdown code block.
# Task
Given an initial string `s`, switch case of the minimal possible number of letters to make the whole string written in the upper case or in the lower case.
# Input/Output
`[input]` string `s`
String of odd length consisting of English letters.... | {"functional": "_inputs = [['asdERvT'], ['oyTYbWQ'], ['bbiIRvbcW'], ['rWTmvcoRWEWQQWR']]\n_outputs = [['asdervt'], ['OYTYBWQ'], ['bbiirvbcw'], ['RWTMVCORWEWQQWR']]\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=to... | coding | 150 |
Solve the programming task below in a Python markdown code block.
Third day at your new cryptoanalyst job and you come across your toughest assignment yet. Your job is to implement a simple keyword cipher. A keyword cipher is a type of monoalphabetic substitution where two parameters are provided as such (string, keywo... | {"functional": "_inputs = [['Welcome home', 'secret'], ['hello', 'wednesday'], ['HELLO', 'wednesday'], ['HeLlO', 'wednesday'], ['WELCOME HOME', 'gridlocked'], ['alpha bravo charlie', 'delta'], ['Home Base', 'seven'], ['basecamp', 'covert'], ['one two three', 'rails'], ['Test', 'unbuntu']]\n_outputs = [['wticljt dljt'],... | coding | 243 |
Solve the programming task below in a Python markdown code block.
Complete the function `scramble(str1, str2)` that returns `true` if a portion of ```str1``` characters can be rearranged to match ```str2```, otherwise returns ```false```.
**Notes:**
* Only lower case letters will be used (a-z). No punctuation or digi... | {"functional": "_inputs = [['rkqodlw', 'world'], ['cedewaraaossoqqyt', 'codewars'], ['katas', 'steak'], ['scriptjavx', 'javascript'], ['scriptingjava', 'javascript'], ['scriptsjava', 'javascripts'], ['javscripts', 'javascript'], ['aabbcamaomsccdd', 'commas'], ['commas', 'commas'], ['sammoc', 'commas']]\n_outputs = [[Tr... | coding | 170 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an array nums of positive integers. In one operation, you can choose any number from nums and reduce it to exactly half the number. (Note that you may choose this reduced number in future operations.)
Re... | {"functional": "def check(candidate):\n assert candidate(nums = [5,19,8,1]) == 3\n assert candidate(nums = [3,8,20]) == 3\n\n\ncheck(Solution().halveArray)"} | coding | 109 |
Solve the programming task below in a Python markdown code block.
Codehorses has just hosted the second Codehorses Cup. This year, the same as the previous one, organizers are giving T-shirts for the winners.
The valid sizes of T-shirts are either "M" or from $0$ to $3$ "X" followed by "S" or "L". For example, sizes "... | {"inputs": ["1\nM\nM\n", "1\nS\nM\n", "1\nL\nM\n", "1\nL\nS\n", "1\nM\nM\n", "1\nL\nS\n", "1\nL\nM\n", "1\nS\nM\n"], "outputs": ["0\n", "1\n", "1\n", "1\n", "0\n", "1\n", "1\n", "1\n"]} | coding | 598 |
Solve the programming task below in a Python markdown code block.
Chef has an 8 \times 8 chessboard. He placed a knight on the square (X_{1}, Y_{1}). Note that, the square at the intersection of the i^{th} row and j^{th} column is denoted by (i, j).
Chef wants to determine whether the knight can end up at the square ... | {"inputs": ["3\n1 1 1 1\n8 8 7 6\n8 8 8 6\n"], "outputs": ["YES\nNO\nYES"]} | coding | 580 |
Solve the programming task below in a Python markdown code block.
'Jeopardy!' is an intellectual game where players answer questions and earn points. Company Q conducts a simplified 'Jeopardy!' tournament among the best IT companies. By a lucky coincidence, the old rivals made it to the finals: company R1 and company R... | {"inputs": ["1 1\n1\n1\n", "1 1\n1\n1\n", "1 1\n2\n1\n", "2 1\n1 2\n1\n", "2 1\n1 2\n2\n", "2 1\n1 2\n2\n", "2 1\n1 2\n1\n", "2 1\n1 0\n1\n"], "outputs": ["1\n", " 1", "2\n", "4\n", "3\n", " 3", "... | coding | 593 |
Solve the programming task below in a Python markdown code block.
Implement `String#ipv4_address?`, which should return true if given object is an IPv4 address - four numbers (0-255) separated by dots.
It should only accept addresses in canonical representation, so no leading `0`s, spaces etc.
Also feel free to reuse/... | {"functional": "_inputs = [[''], ['127.0.0.1'], ['0.0.0.0'], ['255.255.255.255'], ['10.20.30.40'], ['10.256.30.40'], ['10.20.030.40'], ['127.0.1'], ['127.0.0.0.1'], ['..255.255'], ['127.0.0.1\\n'], ['\\n127.0.0.1'], [' 127.0.0.1'], ['127.0.0.1 '], [' 127.0.0.1 '], ['127.0.0.1.'], ['.127.0.0.1'], ['127..0.1']]\n_outputs... | coding | 89 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a positive integer n, there exists a 0-indexed array called powers, composed of the minimum number of powers of 2 that sum to n. The array is sorted in non-decreasing order, and there is only one way to form the... | {"functional": "def check(candidate):\n assert candidate(n = 15, queries = [[0,1],[2,2],[0,3]]) == [2,4,64]\n assert candidate(n = 2, queries = [[0,0]]) == [2]\n\n\ncheck(Solution().productQueries)"} | coding | 214 |
Solve the programming task below in a Python markdown code block.
Scientists working internationally use metric units almost exclusively. Unless that is, they wish to crash multimillion dollars worth of equipment on Mars.
Your task is to write a simple function that takes a number of meters, and outputs it using metri... | {"functional": "_inputs = [[1], [999], [123456], [12300000], [9000000000.0], [9000000000000.0], [9000000000000000.0], [9e+18], [9e+21], [9e+24]]\n_outputs = [['1m'], ['999m'], ['123.456km'], ['12.3Mm'], ['9Gm'], ['9Tm'], ['9Pm'], ['9Em'], ['9Zm'], ['9Ym']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(... | coding | 243 |
Solve the programming task below in a Python markdown code block.
We have 3 equations with 3 unknowns x, y, and z and we are to solve for these unknowns.
Equations 4x -3y +z = -10, 2x +y +3z = 0, and -x +2y -5z = 17 will be passed in as an array of [[4, -3, 1, -10], [2, 1, 3, 0], [-1, 2, -5, 17]] and the result should ... | {"functional": "_inputs = [[[[4, -3, 1, -10], [2, 1, 3, 0], [-1, 2, -5, 17]]], [[[2, 1, 3, 10], [-3, -2, 7, 5], [3, 3, -4, 7]]], [[[3, 2, 0, 7], [-4, 0, 3, -6], [0, -2, -6, -10]]], [[[4, 2, -5, -21], [2, -2, 1, 7], [4, 3, -1, -1]]]]\n_outputs = [[[1, 4, -2]], [[-1, 6, 2]], [[3, -1, 2]], [[1, 0, 5]]]\nimport math\ndef _... | coding | 215 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two positive integers low and high.
An integer x consisting of 2 * n digits is symmetric if the sum of the first n digits of x is equal to the sum of the last n digits of x. Numbers with an odd number of... | {"functional": "def check(candidate):\n assert candidate(low = 1, high = 100) == 9\n assert candidate(low = 1200, high = 1230) == 4\n\n\ncheck(Solution().countSymmetricIntegers)"} | coding | 124 |
Solve the programming task below in a Python markdown code block.
Chef hosts a party for his birthday. There are N people at the party. All these N people decide to play Jenga.
There are X Jenga tiles available. In one round, all the players pick 1 tile each and place it in the tower.
The game is *valid* if:
All the... | {"inputs": ["3\n3 3\n4 2\n2 4\n"], "outputs": ["YES\nNO\nYES\n"]} | coding | 389 |
Solve the programming task below in a Python markdown code block.
Berland has a long and glorious history. To increase awareness about it among younger citizens, King of Berland decided to compose an anthem.
Though there are lots and lots of victories in history of Berland, there is the one that stand out the most. Ki... | {"inputs": ["a\nb\n", "a\nb\n", "a\nc\n", "ddddd\nd\n", "ww?ww\nw\n", "?????\nn\n", "ww?ww\nw\n", "?????\nn\n"], "outputs": ["0\n", "0", "0\n", "5\n", "5\n", "5\n", "5", "5"]} | coding | 426 |
Solve the programming task below in a Python markdown code block.
# Task
Changu and Mangu are great buddies. Once they found an infinite paper which had 1,2,3,4,5,6,7,8,......... till infinity, written on it.
Both of them did not like the sequence and started deleting some numbers in the following way.
```
First th... | {"functional": "_inputs = [[1], [5], [8], [9], [13], [15], [134], [289]]\n_outputs = [[True], [False], [False], [False], [True], [False], [False], [True]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n i... | coding | 329 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer array nums and an integer k, return the number of subarrays of nums where the greatest common divisor of the subarray's elements is k.
A subarray is a contiguous non-empty sequence of elements within ... | {"functional": "def check(candidate):\n assert candidate(nums = [9,3,1,2,6,3], k = 3) == 4\n assert candidate(nums = [4], k = 7) == 0\n\n\ncheck(Solution().subarrayGCD)"} | coding | 120 |
Solve the programming task below in a Python markdown code block.
Your goal in this kata is to implement a difference function, which subtracts one list from another and returns the result.
It should remove all values from list `a`, which are present in list `b`.
```python
array_diff([1,2],[1]) == [2]
```
If a value... | {"functional": "_inputs = [[[1, 2], [1]], [[1, 2, 2], [1]], [[1, 2, 2], [2]], [[1, 2, 2], []], [[], [1, 2]]]\n_outputs = [[[2]], [[2, 2]], [[1]], [[1, 2, 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=t... | coding | 163 |
Solve the programming task below in a Python markdown code block.
A **bouncy number** is a positive integer whose digits neither increase nor decrease. For example, `1235` is an increasing number, `5321` is a decreasing number, and `2351` is a bouncy number. By definition, all numbers under `100` are non-bouncy, and `1... | {"functional": "_inputs = [[0], [99], [101], [120], [122], [221], [2379], [29340], [234689], [98874], [92722983], [129347924210]]\n_outputs = [[False], [False], [True], [True], [False], [False], [False], [True], [False], [False], [True], [True]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) o... | coding | 238 |
Solve the programming task below in a Python markdown code block.
You are given a sequence of n integers S and a sequence of different q integers T. Write a program which outputs C, the number of integers in T which are also in the set S.
Notes
Constraints
* Elements in S is sorted in ascending order
* n ≤ 100000
* ... | {"inputs": ["3\n2 2 3\n1\n5", "3\n1 2 3\n1\n4", "3\n1 2 4\n1\n4", "3\n2 2 4\n1\n4", "3\n2 2 5\n1\n4", "3\n0 2 5\n1\n4", "3\n1 2 5\n1\n4", "3\n1 4 5\n1\n4"], "outputs": ["0\n", "0\n", "1\n", "1\n", "0\n", "0\n", "0\n", "1\n"]} | coding | 232 |
Solve the programming task below in a Python markdown code block.
Danny, the local Math Maniac, is fascinated by circles, Omkar's most recent creation. Help him solve this circle problem!
You are given $n$ nonnegative integers $a_1, a_2, \dots, a_n$ arranged in a circle, where $n$ must be odd (ie. $n-1$ is divisible b... | {"inputs": ["1\n4\n", "1\n6\n", "1\n0\n", "1\n7\n", "1\n2\n", "1\n4\n", "3\n0 1 0\n", "3\n0 1 0\n"], "outputs": ["4\n", "6\n", "0\n", "7\n", "2\n", "4\n", "1\n", "1\n"]} | coding | 449 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a string num, which represents a large integer. You are also given a 0-indexed integer array change of length 10 that maps each digit 0-9 to another digit. More formally, digit d maps to digit change[d].... | {"functional": "def check(candidate):\n assert candidate(num = \"132\", change = [9,8,5,0,3,6,4,2,6,8]) == \"832\"\n assert candidate(num = \"021\", change = [9,4,3,5,7,2,1,9,0,6]) == \"934\"\n assert candidate(num = \"5\", change = [1,4,7,5,3,2,5,6,9,4]) == \"5\"\n\n\ncheck(Solution().maximumNumber)"} | coding | 183 |
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"]} | coding | 562 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
A perfectly straight street is represented by a number line. The street has building(s) on it and is represented by a 2D integer array buildings, where buildings[i] = [starti, endi, heighti]. This means that there is ... | {"functional": "def check(candidate):\n assert candidate(buildings = [[1,4,2],[3,9,4]]) == [[1,3,2],[3,4,3],[4,9,4]]\n assert candidate(buildings = [[1,3,2],[2,5,3],[2,8,3]]) == [[1,3,2],[3,8,3]]\n assert candidate(buildings = [[1,2,1],[5,6,1]]) == [[1,2,1],[5,6,1]]\n\n\ncheck(Solution().averageHeightOfBuildin... | coding | 430 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
There is a computer that can run an unlimited number of tasks at the same time. You are given a 2D integer array tasks where tasks[i] = [starti, endi, durationi] indicates that the ith task should run for a total of d... | {"functional": "def check(candidate):\n assert candidate(tasks = [[2,3,1],[4,5,1],[1,5,2]]) == 2\n assert candidate(tasks = [[1,3,2],[2,5,3],[5,6,2]]) == 4\n\n\ncheck(Solution().findMinimumTime)"} | coding | 166 |
Solve the programming task below in a Python markdown code block.
You have initially a string of N characters, denoted by A1,A2...AN. You have to print the size of the largest subsequence of string A such that all the characters in that subsequence are distinct ie. no two characters in that subsequence should be same.
... | {"inputs": ["2\nabc\naba", "2\nabd\naba", "2\nabc\naaa", "2\ncca\naaa", "2\nccb\naab", "2\nccb\ncba", "2\nbbb\nbaa", "2\nbbb\naaa"], "outputs": ["3\n2", "3\n2\n", "3\n1\n", "2\n1\n", "2\n2\n", "2\n3\n", "1\n2\n", "1\n1\n"]} | coding | 268 |
Solve the programming task below in a Python markdown code block.
Reyaan has given you the following problem to solve:
You are given an integer K in base B, represented by an array A of length N such that
0 ≤ A_{i} < B for every 1 ≤ i ≤ N
\sum_{i=1}^N A_{i} \cdot B^{N-i} = K
Note that N ≤ B in this problem.
Find the... | {"inputs": ["4\n4 4\n3 1 0 2\n4 5\n1 2 3 4\n2 2\n1 1\n1 3\n2\n"], "outputs": ["0\n500\n1\n9\n"]} | coding | 668 |
Solve the programming task below in a Python markdown code block.
If Give an integer N . Write a program to obtain the sum of the first and last digits of this number.
-----Input-----
The first line contains an integer T, the total number of test cases. Then follow T lines, each line contains an integer N.
-----Out... | {"inputs": ["3\n1234\n124894\n242323"], "outputs": ["5\n5\n5"]} | coding | 153 |
Solve the programming task below in a Python markdown code block.
A class of students wrote a multiple-choice test.
There are $n$ students in the class. The test had $m$ questions, each of them had $5$ possible answers (A, B, C, D or E). There is exactly one correct answer for each question. The correct answer for que... | {"inputs": ["1 1\nD\n965\n", "1 1\nD\n965\n", "1 1\nD\n1881\n", "2 1\nB\nA\n317\n", "2 1\nB\nA\n317\n", "2 1\nB\nA\n361\n", "2 1\nB\nA\n374\n", "2 1\nC\nA\n361\n"], "outputs": ["965", "965", "1881\n", "317", "317", "361\n", "374\n", "361\n"]} | coding | 463 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a personal information string s, representing either an email address or a phone number. Return the masked personal information using the below rules.
Email address:
An email address is:
A name consisti... | {"functional": "def check(candidate):\n assert candidate(s = \"LeetCode@LeetCode.com\") == \"l*****e@leetcode.com\"\n assert candidate(s = \"AB@qq.com\") == \"a*****b@qq.com\"\n assert candidate(s = \"1(234)567-890\") == \"***-***-7890\"\n\n\ncheck(Solution().maskPII)"} | coding | 360 |
Solve the programming task below in a Python markdown code block.
Dr .: Peter, do you know "Yes, I have a number"?
Peter: I used to do it on TV the other day. You remember something by the number of characters in each word contained in a sentence. "Yes, I have a number", so it means "the number 3.14" and is a keyword ... | {"inputs": ["Yes I have a number\nHow I wish I could calculate an unused bolor for space\nThank you\nEND OF INPUT", "Yes I have a rebmun\nHow I wish I could calculate an unused bolor for space\nThank you\nEND OF INPUT", "Yes I have a rebmun\nHow J wish I could calculate an unused bolor for space\nThank you\nEND OF INPU... | coding | 543 |
Solve the programming task below in a Python markdown code block.
# Description
Given a number `n`, you should find a set of numbers for which the sum equals `n`. This set must consist exclusively of values that are a power of `2` (eg: `2^0 => 1, 2^1 => 2, 2^2 => 4, ...`).
The function `powers` takes a single paramet... | {"functional": "_inputs = [[1], [2], [4], [32], [128], [512], [6], [14], [688], [8197], [1966], [9007199254740991]]\n_outputs = [[[1]], [[2]], [[4]], [[32]], [[128]], [[512]], [[2, 4]], [[2, 4, 8]], [[16, 32, 128, 512]], [[1, 4, 8192]], [[2, 4, 8, 32, 128, 256, 512, 1024]], [[1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024... | coding | 294 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Two strings are considered close if you can attain one from the other using the following operations:
Operation 1: Swap any two existing characters.
For example, abcde -> aecdb
Operation 2: Transform every occur... | {"functional": "def check(candidate):\n assert candidate(word1 = \"abc\", word2 = \"bca\") == True\n assert candidate(word1 = \"a\", word2 = \"aa\") == False\n assert candidate(word1 = \"cabbba\", word2 = \"abbccc\") == True\n\n\ncheck(Solution().closeStrings)"} | coding | 185 |
Solve the programming task below in a Python markdown code block.
Create a function that will return true if all numbers in the sequence follow the same counting pattern. If the sequence of numbers does not follow the same pattern, the function should return false.
Sequences will be presented in an array of varied len... | {"functional": "_inputs = [[[1, 2, 3, 4, 5, 8, 7, 8, 9]], [[2, 8, 6, 7, 4, 3, 1, 5, 9]], [[1, 2, 3, 4, 5, 6, 7, 8, 9]], [[0, 1, 2, 3, 4, 5, 6, 7, 8]], [[1, 3, 5, 7, 9, 11, 13, 15]], [[1, 3, 5, 7, 8, 12, 14, 16]], [[0, 1, 1, 2, 3, 5, 8, 13, 21, 34]], [[0, 2, 4, 6, 8]], [[2, 4, 6, 8, 10]], [[2, 4, 6, 8, 10, 12, 14, 16, 1... | coding | 118 |
Solve the programming task below in a Python markdown code block.
## Description
You've been working with a lot of different file types recently as your interests have broadened.
But what file types are you using the most? With this question in mind we look at the following problem.
Given a `List/Array` of Filenames... | {"functional": "_inputs = [[['direful.pr', 'festive.html', 'historical.wav', 'holistic.mp3', 'impossible.jar', 'gentle.cpp', 'gleaming.xml', 'inconclusive.js', 'erect.jar', 'befitting.mp3', 'brief.wp', 'beautiful.jar', 'energetic.pt', 'careful.wp', 'defective.cpp', 'icky.wav', 'gorgeous.txt', 'good.pt', 'fat.pt', 'bore... | coding | 391 |
Solve the programming task below in a Python markdown code block.
Given an integer N, find a permutation P = P_{1}, P_{2}, \ldots, P_{N} of length N that satisfies the following two conditions:
P_{i} \neq i (1 ≤ i ≤ N);
Consider the set which contains P_{i} \% i for all 1 ≤ i ≤ N. This set should have the minimum numbe... | {"inputs": ["2\n2\n3\n"], "outputs": ["2 1\n2 3 1"]} | coding | 562 |
Solve the programming task below in a Python markdown code block.
In a long narrow forest stretching east-west, there are N beasts. Below, we will call the point that is p meters from the west end Point p. The i-th beast from the west (1 ≤ i ≤ N) is at Point x_i, and can be sold for s_i yen (the currency of Japan) if c... | {"inputs": ["5\n10 2\n40 5\n60 3\n70 5\n90 1", "5\n10 2\n40 8\n60 3\n70 5\n90 1", "5\n10 2\n40 5\n60 3\n70 4\n90 1", "5\n28 17\n40 50\n60 35\n70 40\n90 3", "5\n2 20\n40 50\n60 13\n70 40\n89 10", "5\n2 20\n40 50\n60 13\n70 40\n71 10", "5\n18 17\n40 44\n60 35\n70 40\n90 3", "5\n10 20\n40 50\n60 35\n70 40\n90 10"], "outpu... | coding | 428 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a sentence that consists of some words separated by a single space, and a searchWord, check if searchWord is a prefix of any word in sentence.
Return the index of the word in sentence (1-indexed) where searchWor... | {"functional": "def check(candidate):\n assert candidate(sentence = \"i love eating burger\", searchWord = \"burg\") == 4\n assert candidate(sentence = \"this problem is an easy problem\", searchWord = \"pro\") == 2\n assert candidate(sentence = \"i am tired\", searchWord = \"you\") == -1\n\n\ncheck(Solution()... | coding | 156 |
Solve the programming task below in a Python markdown code block.
Suppose you have a string S which has length N and is indexed from 0 to N−1. String R is the reverse of the string S. The string S is funny if the condition |Si−Si−1|=|Ri−Ri−1| is true for every i from 1 to N−1.
(Note: Given a string str, stri denotes t... | {"inputs": ["2\nacxz\nbcxz", "2\nivvkxq\nivvkx", "10\njkotzxzxrxtzytlruwrxytyzsuzytwyzxuzytryzuzysxvsmupouysywywqlhg\neklrywzvpxtvoptlrskmskszvwzsuzxrtvyzwruqvyxusqwupnurqmtltnltsmuyxqoksyurpwqpv\nefhpuvqvnuwpvwysvnunostvpqvxtxsvqwqvsxtxvqpvtsonunvsywvpwunvqvupxzy\notytmpszumnryqvxpvnvxyvpvprumnvsqwqwtsqyqksqvnuqpxszwz... | coding | 188 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
We define a harmonious array as an array where the difference between its maximum value and its minimum value is exactly 1.
Given an integer array nums, return the length of its longest harmonious subsequence among al... | {"functional": "def check(candidate):\n assert candidate(nums = [1,3,2,2,5,2,3,7]) == 5\n assert candidate(nums = [1,2,3,4]) == 2\n assert candidate(nums = [1,1,1,1]) == 0\n\n\ncheck(Solution().findLHS)"} | coding | 97 |
Solve the programming task below in a Python markdown code block.
Takahashi has A cookies, and Aoki has B cookies.
Takahashi will do the following action K times:
- If Takahashi has one or more cookies, eat one of his cookies.
- Otherwise, if Aoki has one or more cookies, eat one of Aoki's cookies.
- If they both ha... | {"inputs": ["2 3 1", "2 3 2", "2 3 0", "2 6 0", "4 6 0", "8 6 0", "0 6 0", "0 9 0"], "outputs": ["1 3\n", "0 3\n", "2 3\n", "2 6\n", "4 6\n", "8 6\n", "0 6\n", "0 9\n"]} | coding | 302 |
Solve the programming task below in a Python markdown code block.
For the multiset of positive integers $s=\{s_1,s_2,\dots,s_k\}$, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of $s$ as follow: $\gcd(s)$ is the maximum positive integer $x$, such that all integers in $s$ are divisible on $x$.... | {"inputs": ["2\n1 1\n", "2\n4 6\n", "2\n3 3\n", "2\n3 3\n", "2\n4 6\n", "2\n3 5\n", "2\n1 2\n", "2\n1 1\n"], "outputs": ["1\n", "12\n", "3\n", "3\n", "12\n", "15\n", "2\n", "1\n"]} | coding | 565 |
Solve the programming task below in a Python markdown code block.
Lately, a national version of a bingo game has become very popular in Berland. There are n players playing the game, each player has a card with numbers. The numbers on each card are distinct, but distinct cards can have equal numbers. The card of the i-... | {"inputs": ["1\n1 1\n", "1\n1 1\n", "1\n1 2\n", "2\n1 1\n1 1\n", "2\n1 2\n1 3\n", "2\n1 2\n1 3\n", "2\n1 4\n1 3\n", "2\n1 2\n1 1\n"], "outputs": ["YES\n", "YES\n", "YES\n", "NO\nNO\n", "YES\nYES\n", "YES\nYES\n", "YES\nYES\n", "YES\nYES\n"]} | coding | 474 |
Solve the programming task below in a Python markdown code block.
# Story
Due to lack of maintenance the minute-hand has fallen off Town Hall clock face.
And because the local council has lost most of our tax money to a Nigerian email scam there are no funds to fix the clock properly.
Instead, they are asking for v... | {"functional": "_inputs = [[0], [360], [90], [180], [270], [30], [40], [45], [50], [60]]\n_outputs = [['12:00'], ['12:00'], ['03:00'], ['06:00'], ['09:00'], ['01:00'], ['01:20'], ['01:30'], ['01:40'], ['02:00']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n r... | coding | 248 |
Solve the programming task below in a Python markdown code block.
From Wikipedia : "The n-back task is a continuous performance task that is commonly used as an assessment in cognitive neuroscience to measure a part of working memory and working memory capacity. [...] The subject is presented with a sequence of stimuli... | {"functional": "_inputs = [[1, [1, 1, 1, 1, 1]], [2, [1, 1, 1, 1, 1]], [1, [1, 2, 1, 2, 1]], [2, [1, 2, 1, 2, 1]], [9, [1, 2, 3, 4, 5, 6, 7, 8, 9, 1]], [1, []], [1, [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1... | coding | 264 |
Solve the programming task below in a Python markdown code block.
The National Championships are starting soon. There are 4 race categories, numbered from 1 to 4, that Chef is interested in. Chef is participating in exactly 2 of these categories.
Chef has an arch-rival who is, unfortunately, the only person participa... | {"inputs": ["3\n4 3 1 2\n4 2 1 2\n2 1 1 2"], "outputs": ["2\n1\n0"]} | coding | 566 |
Solve the programming task below in a Python markdown code block.
Write a function called `LCS` that accepts two sequences and returns the longest subsequence common to the passed in sequences.
### Subsequence
A subsequence is different from a substring. The terms of a subsequence need not be consecutive terms of the ... | {"functional": "_inputs = [['a', 'b'], ['a', 'a'], ['abc', 'ac'], ['abcdef', 'abc'], ['abcdef', 'acf'], ['anothertest', 'notatest'], ['132535365', '123456789'], ['finaltest', 'zzzfinallyzzz']]\n_outputs = [[''], ['a'], ['ac'], ['abc'], ['acf'], ['nottest'], ['12356'], ['final']]\nimport math\ndef _deep_eq(a, b, tol=1e-... | coding | 424 |
Solve the programming task below in a Python markdown code block.
Sereja has an n × m rectangular table a, each cell of the table contains a zero or a number one. Sereja wants his table to meet the following requirement: each connected component of the same values forms a rectangle with sides parallel to the sides of t... | {"inputs": ["1 1 1\n1\n", "1 1 1\n1\n", "0 1 1\n1\n", "1 1 1\n0\n", "2 2 1\n1 1\n1 0\n", "2 2 1\n1 1\n1 0\n", "2 2 1\n1 0\n1 0\n", "8 1 4\n0\n0\n0\n1\n0\n1\n1\n0\n"], "outputs": ["0\n", "0", "0\n", "0\n", "1\n", "1", "0\n", "0\n"]} | coding | 481 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a string s, return true if s is a good string, or false otherwise.
A string s is good if all the characters that appear in s have the same number of occurrences (i.e., the same frequency).
Please complete the ... | {"functional": "def check(candidate):\n assert candidate(s = \"abacbc\") == True\n assert candidate(s = \"aaabb\") == False\n\n\ncheck(Solution().areOccurrencesEqual)"} | coding | 93 |
Solve the programming task below in a Python markdown code block.
There are N slimes lining up in a row. Initially, the i-th slime from the left has a size of a_i.
Taro is trying to combine all the slimes into a larger slime. He will perform the following operation repeatedly until there is only one slime:
* Choose t... | {"inputs": ["4\n10 5 30 46", "4\n10 3 30 46", "4\n19 3 30 46", "4\n19 3 35 46", "4\n19 3 35 65", "4\n19 3 21 65", "4\n15 3 21 65", "4\n15 3 20 65"], "outputs": ["151\n", "145\n", "172\n", "182\n", "201\n", "173\n", "161\n", "159\n"]} | coding | 342 |
Solve the programming task below in a Python markdown code block.
There is a country with n citizens. The i-th of them initially has a_{i} money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioni... | {"inputs": ["4\n1 2 3 4\n2\n2 3\n2 2\n", "4\n1 2 3 4\n2\n2 3\n2 1\n", "4\n1 2 3 8\n2\n2 3\n2 1\n", "4\n2 4 3 8\n2\n2 3\n2 1\n", "4\n1 2 3 4\n2\n2 3\n2 4\n", "4\n1 2 3 0\n2\n2 3\n2 1\n", "4\n0 2 5 4\n2\n2 3\n2 1\n", "4\n1 2 4 0\n2\n2 3\n2 1\n"], "outputs": ["3 3 3 4\n", "3 3 3 4\n", "3 3 3 8\n", "3 4 3 8\n", "4 4 4 4\n"... | coding | 553 |
Solve the programming task below in a Python markdown code block.
Little Egor is a huge movie fan. He likes watching different kinds of movies: from drama movies to comedy movies, from teen movies to horror movies. He is planning to visit cinema this weekend, but he's not sure which movie he should watch.
There are n m... | {"inputs": ["2\n2\n1 2\n2 1\n4\n2 1 4 1\n2 4 1 4"], "outputs": ["1\n2"]} | coding | 409 |
Solve the programming task below in a Python markdown code block.
What adds up
===========
Given three arrays of integers your task is to create an algorithm that finds the numbers in the first two arrays whose sum is equal to any number in the third. The return value should be an array containing the values from the ... | {"functional": "_inputs = [[[], [1, 2, 3], [5, 2, 3]], [[1, 3, 4], [], [4, 6, 5]], [[1, 2, 3], [4, 5, 6], []]]\n_outputs = [[[]], [[]], [[]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(... | coding | 466 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed integer array nums containing n distinct positive integers. A permutation of nums is called special if:
For all indexes 0 <= i < n - 1, either nums[i] % nums[i+1] == 0 or nums[i+1] % nums[i]... | {"functional": "def check(candidate):\n assert candidate(nums = [2,3,6]) == 2\n assert candidate(nums = [1,4,3]) == 2\n\n\ncheck(Solution().specialPerm)"} | coding | 155 |
Solve the programming task below in a Python markdown code block.
Given an array of numbers, return the difference between the largest and smallest values.
For example:
`[23, 3, 19, 21, 16]` should return `20` (i.e., `23 - 3`).
`[1, 434, 555, 34, 112]` should return `554` (i.e., `555 - 1`).
The array will contain ... | {"functional": "_inputs = [[[1, 1]], [[-1, -1]], [[1, -1]], [[21, 34, 54, 43, 26, 12]], [[-1, -41, -77, -100]]]\n_outputs = [[0], [0], [2], [42], [99]]\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 i... | coding | 164 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a string s, return the length of the longest substring that contains at most two distinct characters.
Please complete the following python code precisely:
```python
class Solution:
def lengthOfLongestSubst... | {"functional": "def check(candidate):\n assert candidate(s = \"eceba\") == 3\n assert candidate(s = \"ccaabbb\") == 5\n\n\ncheck(Solution().lengthOfLongestSubstringTwoDistinct)"} | coding | 72 |
Solve the programming task below in a Python markdown code block.
You are given a text consisting of $n$ space-separated words. There is exactly one space character between any pair of adjacent words. There are no spaces before the first word and no spaces after the last word. The length of text is the number of letter... | {"inputs": ["1\nu\n", "1\nu\n", "1\nt\n", "1\ns\n", "7\na a b a a a b\n", "2\nxnnlpp jpymdh\n", "7\na a b a a a b\n", "2\nxnnlpp jpymdh\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "9\n", "13\n", "9\n", "13\n"]} | coding | 666 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.