problem_id
int64
0
5k
question
stringlengths
52
8.71k
solutions
stringlengths
79
764k
input_output
stringlengths
0
23.6M
difficulty
stringclasses
3 values
url
stringlengths
36
106
starter_code
stringlengths
0
1.4k
input_ids
listlengths
14
2.05k
attention_mask
listlengths
14
2.05k
4,130
# Valid HK Phone Number ## Overview In Hong Kong, a valid phone number has the format ```xxxx xxxx``` where ```x``` is a decimal digit (0-9). For example: ## Task Define two functions, ```isValidHKPhoneNumber``` and ```hasValidHKPhoneNumber```, that ```return```s whether a given string is a valid HK phone number a...
["import re\n\nHK_PHONE_NUMBER = '\\d{4} \\d{4}'\n\ndef is_valid_HK_phone_number(number):\n return bool(re.match(HK_PHONE_NUMBER+'\\Z',number))\n\ndef has_valid_HK_phone_number(number):\n return bool(re.search(HK_PHONE_NUMBER,number))", "from re import match, search\n\nis_valid_HK_phone_number = lambda n: match('...
{"fn_name": "is_valid_HK_phone_number", "inputs": [["1234 5678"], ["2359 1478"], ["85748475"], ["3857 4756"], ["sklfjsdklfjsf"], [" 1234 5678 "], ["abcd efgh"], ["9684 2396"], ["836g 2986"], ["0000 0000"], ["123456789"], [" 987 634 "], [" 6 "], ["8A65 2986"], ["8368 2aE6"], ["8c65 2i86"]], "outputs": [[tru...
introductory
https://www.codewars.com/kata/56f54d45af5b1fec4b000cce
def is_valid_HK_phone_number(number):
[ 2, 7818, 42217, 14307, 5624, 271, 565, 34807, 271, 641, 19180, 18211, 11, 264, 2697, 4540, 1372, 702, 279, 3561, 54275, 18516, 83976, 73594, 1380, 54275, 87, 73594, 374, 264, 12122, 15723, 320, 15, 12, 24, 568, 220, 1752, 3110, 1447, ...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
2,621
=====Problem Statement===== Mr. Anant Asankhya is the manager at the INFINITE hotel. The hotel has an infinite amount of rooms. One fine day, a finite number of tourists come to stay at the hotel. The tourists consist of: → A Captain. → An unknown group of families consisting of K members per group where K ≠ 1. The C...
["k = int(input())\nroom_number_list = list(map(int,input().split()))\nroom_number_set = set(room_number_list)\nroom_number_list_sum = sum(room_number_list)\nroom_number_set_sum = sum(room_number_set) * k\ndiff = room_number_set_sum - room_number_list_sum\nfor i in room_number_set:\n if diff == ((k-1)*i):\n p...
{"inputs": ["5\n1 2 3 6 5 4 4 2 5 3 6 1 6 5 3 2 4 1 2 5 1 4 3 6 8 4 3 1 5 6 2"], "outputs": ["8"]}
introductory
https://www.hackerrank.com/challenges/py-the-captains-room/problem
# Enter your code here. Read input from STDIN. Print output to STDOUT
[ 46725, 31198, 21756, 64897, 12275, 13, 1527, 517, 1634, 1180, 86223, 374, 279, 6645, 518, 279, 1964, 84770, 9500, 13, 576, 9500, 702, 458, 23809, 3311, 315, 12026, 382, 3966, 6915, 1899, 11, 264, 34226, 1372, 315, 31653, 2525, 311, 4717...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
1,140
Consider the following algorithm order(arr, i) { if length(arr) <= 1 { return arr } l = [] r = [] n = length(arr) - 1 for j in 0, 1, ..., n { if ( (arr[j] modulo power(2,i+1)) < power(2,i) ) { append arr[j] to l }else{ append arr[j] to r } } l = order(l, i + 1) r = order(r, i + 1) c = concatenate(l, r) return c } N...
["for _ in range(int(input())):\n p, idx = map(int, input().split())\n b = bin(idx)[2:]\n b = ('0' * (p - len(b)) + b)[::-1]\n print(int(b, 2))", "# cook your dish here\nt=int(input())\nfor _ in range(t):\n p, idx=list(map(int, input().split()))\n length=2**p \n somma=0\n mult=1\n while length>1:\n length=length>>1 \n...
{"inputs": [["2", "3 3", "3 7"]], "outputs": [["6", "7"]]}
interview
https://www.codechef.com/ZCOPRAC/problems/ZCO20001
[ 37175, 279, 2701, 12111, 198, 1358, 10939, 11, 600, 8, 341, 333, 3084, 10939, 8, 2651, 220, 16, 341, 689, 2890, 198, 532, 75, 284, 3056, 2303, 81, 284, 4167, 77, 284, 3084, 10939, 8, 481, 220, 16, 198, 1958, 502, 304, 220, 15, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1...
2,554
Given a list of strings words representing an English Dictionary, find the longest word in words that can be built one character at a time by other words in words. If there is more than one possible answer, return the longest word with the smallest lexicographical order. If there is no answer, return the empty string...
["class Solution:\n def longestWord(self, words):\n \"\"\"\n :type words: List[str]\n :rtype: str\n \"\"\"\n \n result = \"\";\n wordSet = set(words);\n for word in words:\n if (len(word) > len(result) or len(word) == len(result) and word <...
{"fn_name": "longestWord", "inputs": [[["\"w\"", "\"wo\"", "\"wor\"", "\"worl\"", "\"world\""]]], "outputs": [""]}
introductory
https://leetcode.com/problems/longest-word-in-dictionary/
class Solution: def longestWord(self, words: List[str]) -> str:
[ 22043, 264, 1140, 315, 9069, 4244, 14064, 458, 6364, 10466, 11, 1477, 279, 22032, 3409, 304, 4244, 429, 646, 387, 5798, 825, 3668, 518, 264, 882, 553, 1008, 4244, 304, 4244, 13, 220, 1416, 1052, 374, 803, 1091, 825, 3204, 4226, 11, ...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
587
On a planet called RUIZ LAND, which is ruled by the queen, Erika Ruiz. Each person on that planet has a strength value (strength value >0). That planet has a special rule made by the queen that a boy and a girl will form a couple if their Hate value is a prime number where $Hate$ is given by the formula:- Hate = (boy's...
["n=int(input())\r\na=list(map(int,input().split()))\r\nc=[]\r\nfor i in range(len(a)):\r\n if a[i]==2:\r\n c.append(1)\r\n else:\r\n c.append(a[i]^2)\r\nprint(*c)", "import copy\r\nn=int(input())\r\na=list(map(int,input().split()))\r\nc=[]\r\nfor i in range(len(a)):\r\n if a[i]==2:\r\n c....
{"inputs": [["2", "10 16"]], "outputs": [["8 18"]]}
interview
https://www.codechef.com/INRO2021/problems/COUPLING
[ 1925, 264, 11580, 2598, 431, 2275, 57, 91856, 11, 892, 374, 21286, 553, 279, 27906, 11, 468, 40454, 89883, 13, 8886, 1697, 389, 429, 11580, 702, 264, 8170, 897, 320, 74237, 897, 861, 15, 4292, 4792, 11580, 702, 264, 3281, 5912, 1865, ...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
2,727
# Task Given string `s`, which contains only letters from `a to z` in lowercase. A set of alphabet is given by `abcdefghijklmnopqrstuvwxyz`. 2 sets of alphabets mean 2 or more alphabets. Your task is to find the missing letter(s). You may need to output them by the order a-z. It is possible that there is more ...
["from collections import Counter\nfrom string import ascii_lowercase\n\ndef missing_alphabets(s):\n c = Counter(s)\n m = max(c.values())\n return ''.join(letter * (m - c[letter]) for letter in ascii_lowercase)", "from collections import Counter\nfrom string import ascii_lowercase as alphabet\n\ndef missing_al...
{"fn_name": "missing_alphabets", "inputs": [["abcdefghijklmnopqrstuvwxy"], ["abcdefghijklmnopqrstuvwxyz"], ["aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyy"], ["abbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxy"], ["codewars"]], "outputs": [["z"], [""], ["zz"], ["ayzz"], ["bfghijklmnpqtuvxyz"]]}
introductory
https://www.codewars.com/kata/58a664bb586e986c940001d5
def missing_alphabets(s):
[ 2, 5430, 198, 16246, 914, 1565, 82, 7808, 892, 5610, 1172, 11931, 504, 1565, 64, 311, 1147, 63, 304, 42047, 382, 362, 738, 315, 27790, 374, 2661, 553, 1565, 67512, 18639, 715, 220, 17, 7289, 315, 64595, 370, 1415, 3076, 220, 17, 476...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
54
You are playing a variation of game 2048. Initially you have a multiset $s$ of $n$ integers. Every integer in this multiset is a power of two. You may perform any number (possibly, zero) operations with this multiset. During each operation you choose two equal integers from $s$, remove them from $s$ and insert the n...
["for i in range(int(input())):\n n=int(input())\n s=list(map(int,input().split()))\n a=0\n for i in s:\n if i<2049:a+=i\n if a<2048:print(\"NO\")\n else:print(\"YES\")", "t=int(input())\nfor i in range(t):\n n=int(input())\n a=list(map(int,input().split()))\n a.sort(reverse=True)\n ...
{ "inputs": [ "6\n4\n1024 512 64 512\n1\n2048\n3\n64 512 2\n2\n4096 4\n7\n2048 2 2048 2048 2048 2048 2048\n2\n2048 4096\n" ], "outputs": [ "YES\nYES\nNO\nNO\nYES\nYES\n" ] }
interview
https://codeforces.com/problemset/problem/1221/A
[ 2610, 525, 5619, 264, 22990, 315, 1809, 220, 17, 15, 19, 23, 13, 58556, 498, 614, 264, 2745, 49189, 400, 82, 3, 315, 400, 77, 3, 25780, 13, 7209, 7546, 304, 419, 2745, 49189, 374, 264, 2355, 315, 1378, 13, 4710, 2610, 1231, 2736, ...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
1,321
The chef is trying to solve some series problems, Chef wants your help to code it. Chef has one number N. Help the chef to find N'th number in the series. 0, 1, 5, 14, 30, 55 ….. -----Input:----- - First-line will contain $T$, the number of test cases. Then the test cases follow. - Each test case contains a single li...
["T=int(input())\nfor i in range(T):\n n=int(input())\n if n==1:\n print(\"0\")\n else:\n n=n-2\n l=(n+1)*(2*n+3)*(n+2)/6\n print(int(l))\n", "\n\nfor _ in range(int(input())):\n k=int(input())\n print(int(((k-1)*(k)*(2*k-1))/6))\n", "testcases=int(input())\r\nfor i in range(t...
{"inputs": [["3", "1", "7", "8"]], "outputs": [["0", "91", "140"]]}
interview
https://www.codechef.com/PEND2020/problems/ITGUY04
[ 785, 29706, 374, 4460, 311, 11625, 1045, 4013, 5322, 11, 35975, 6801, 697, 1492, 311, 2038, 432, 13, 35975, 702, 825, 1372, 451, 13, 11479, 279, 29706, 311, 1477, 451, 944, 71, 1372, 304, 279, 4013, 624, 15, 11, 220, 16, 11, 220, ...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
2,332
There are $n$ cities in Berland and some pairs of them are connected by two-way roads. It is guaranteed that you can pass from any city to any other, moving along the roads. Cities are numerated from $1$ to $n$. Two fairs are currently taking place in Berland — they are held in two different cities $a$ and $b$ ($1 \le...
["import sys\ninput = sys.stdin.readline\n\nfrom collections import deque\n\nt=int(input())\nfor testcaess in range(t):\n n,m,a,b=list(map(int,input().split()))\n E=[[] for i in range(n+1)]\n\n for i in range(m):\n x,y=list(map(int,input().split()))\n E[x].append(y)\n E[y].append(x)\n\n ...
{ "inputs": [ "3\n7 7 3 5\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 5\n4 5 2 3\n1 2\n2 3\n3 4\n4 1\n4 2\n4 3 2 1\n1 2\n2 3\n4 1\n" ], "outputs": [ "4\n0\n1\n" ] }
competition
https://codeforces.com/problemset/problem/1276/B
[ 3862, 525, 400, 77, 3, 9720, 304, 8907, 1933, 323, 1045, 13530, 315, 1105, 525, 8433, 553, 1378, 26798, 19241, 13, 1084, 374, 19323, 429, 498, 646, 1494, 504, 894, 3283, 311, 894, 1008, 11, 7218, 3156, 279, 19241, 13, 37273, 525, 78...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
4,227
Your program will receive an array of complex numbers represented as strings. Your task is to write the `complexSum` function which have to return the sum as a string. Complex numbers can be written in the form of `a+bi`, such as `2-3i` where `2` is the real part, `3` is the imaginary part, and `i` is the "imaginary ...
["def complexSum(arr, sub={'1i': 'i', '-1i': '-i', '0i': '0'}):\n s = str(sum(complex(x.replace('i', 'j')) for x in arr)).replace('j', 'i')\n s = s.strip('()')\n s = s.replace('+0i', '')\n return sub.get(s, s) ", "def complexSum(arr):\n a = [complex(i.replace(\"i\", \"j\")) for i in arr]\n s = 0\n ...
{"fn_name": "complexSum", "inputs": [[["2+3i", "3-i"]], [["2-3i", "3+i"]], [["3", "-3+i"]], [[]], [["3+4i"]], [["123+456i"]], [["0"]], [["-i"]], [["1", "1"]], [["-5", "5"]], [["1", "10", "100", "1000"]], [["5+4i", "11+3i"]], [["-2-4i", "-8+6i"]], [["-1-i", "7+10i"]], [["3+4i", "3-4i"]], [["10+i", "10-i", "9"]], [["2+3i...
introductory
https://www.codewars.com/kata/5a981424373c2e479c00017f
def complexSum(arr):
[ 7771, 2025, 686, 5258, 458, 1334, 315, 6351, 5109, 15251, 438, 9069, 13, 4615, 3383, 374, 311, 3270, 279, 220, 1565, 23247, 9190, 63, 729, 892, 614, 311, 470, 279, 2629, 438, 264, 914, 382, 31137, 5109, 646, 387, 5326, 304, 279, 135...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
3,059
You have an award-winning garden and everyday the plants need exactly 40mm of water. You created a great piece of JavaScript to calculate the amount of water your plants will need when you have taken into consideration the amount of rain water that is forecast for the day. Your jealous neighbour hacked your computer an...
["def rain_amount(mm):\n if mm < 40:\n return \"You need to give your plant \" + str(40 - mm) + \"mm of water\"\n else:\n return \"Your plant has had more than enough water for today!\"", "def rain_amount(mm):\n if mm < 40:\n return 'You need to give your plant {}mm of water'.for...
{"fn_name": "rain_amount", "inputs": [[100], [40], [39], [5], [0]], "outputs": [["Your plant has had more than enough water for today!"], ["Your plant has had more than enough water for today!"], ["You need to give your plant 1mm of water"], ["You need to give your plant 35mm of water"], ["You need to give your plant 4...
introductory
https://www.codewars.com/kata/57158fb92ad763bb180004e7
def rain_amount(mm):
[ 2610, 614, 458, 10084, 26777, 13551, 323, 17778, 279, 10779, 1184, 6896, 220, 19, 15, 3821, 315, 3015, 13, 1446, 3465, 264, 2244, 6573, 315, 12914, 311, 11047, 279, 3311, 315, 3015, 697, 10779, 686, 1184, 979, 498, 614, 4429, 1119, 17...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
4,202
The Ulam sequence `U` is defined by `u0 = u`, `u1 = v`, with the general term `uN` for `N > 2` given by the least integer expressible uniquely as the sum of two distinct earlier terms. In other words, the next number is always the smallest, unique sum of any two previous terms. Complete the function that creates an Ul...
["from itertools import combinations\nfrom collections import defaultdict\n\ndef ulam_sequence(u0, u1, n):\n seq = [u0, u1, u0 + u1]\n \n while len(seq) < n:\n candidates = defaultdict(int)\n \n for a, b in combinations(seq, 2):\n candidates[a + b] += 1\n \n for nu...
{"fn_name": "ulam_sequence", "inputs": [[1, 2, 5], [3, 4, 5], [5, 6, 8]], "outputs": [[[1, 2, 3, 4, 6]], [[3, 4, 7, 10, 11]], [[5, 6, 11, 16, 17, 21, 23, 26]]]}
introductory
https://www.codewars.com/kata/5995ff073acba5fa3a00011d
def ulam_sequence(u0, u1, n):
[ 785, 16582, 309, 8500, 1565, 52, 63, 374, 4512, 553, 1565, 84, 15, 284, 575, 7808, 1565, 84, 16, 284, 348, 7808, 448, 279, 4586, 4647, 1565, 84, 45, 63, 369, 1565, 45, 861, 220, 17, 63, 2661, 553, 279, 3245, 7546, 3158, 1238, 41...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
3,668
We define the sequence ```SF``` in the following way in terms of four previous sequences: ```S1```, ```S2```, ```S3``` and ```ST``` We are interested in collecting the terms of SF that are multiple of ten. The first term multiple of ten of this sequence is ```60``` Make the function ```find_mult10_SF()``` that yo...
["def find_mult10_SF(n):\n n = 4*n - 1\n \n return (6 ** n + 3 * 2 ** n) / 4\n", "def find_mult10_SF(n):\n # ST(n) = 6 ** n + 5 ** n - 2 ** n - 1\n # SF(n) = (6 ** n + 3 * (2 ** n)) / 4\n # SF is divisible by 10 if n = 3 mod 4\n #\n # => nth 10 multiple of 10 is ST(n * 4 - 1)\n k = n * 4 - 1\...
{"fn_name": "find_mult10_SF", "inputs": [[1], [2], [3]], "outputs": [[60], [70080], [90700800]]}
introductory
https://www.codewars.com/kata/561d54055e399e2f62000045
def find_mult10_SF(n):
[ 1654, 6979, 279, 8500, 54275, 28667, 73594, 304, 279, 2701, 1616, 304, 3793, 315, 3040, 3681, 23700, 25, 54275, 50, 16, 13874, 7808, 54275, 50, 17, 13874, 7808, 54275, 50, 18, 73594, 323, 54275, 784, 73594, 1022, 1654, 525, 8014, 304, ...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
1,246
Walter White and Jesse Pinkman (a drug addict) both love to play with chemicals. One day they were playing with some chemicals to make an energy drink. Unknowingly they made a highly powerful drink. To test the drink on others also they called some of their friends and gave a drop of it to everyone. Now they all were f...
["# cook your dish here\nl1=int(input())\nfor i in range(l1):\n x=int(input())\n y=list(map(int,input().split()))\n z=list(map(int,input().split()))\n if max(z)!=max(y):\n print('YES')\n else:\n print('NO')", "# cook your dish here\ntry:\n for _ in range(int(input())):\n n = int(i...
{"inputs": [["1", "5", "1 2 3 4 5", "2 7 8 9 9", ""]], "outputs": [["YES"]]}
interview
https://www.codechef.com/CHPTRS01/problems/FUNRUN
[ 54, 37277, 5807, 323, 39171, 26119, 1515, 320, 64, 5506, 38226, 8, 2176, 2948, 311, 1486, 448, 25266, 13, 3776, 1899, 807, 1033, 5619, 448, 1045, 25266, 311, 1281, 458, 4802, 7027, 13, 1230, 32034, 11307, 807, 1865, 264, 7548, 7988, 7...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
1,040
A string with length $L$ is called rich if $L \ge 3$ and there is a character which occurs in this string strictly more than $L/2$ times. You are given a string $S$ and you should answer $Q$ queries on this string. In each query, you are given a substring $S_L, S_{L+1}, \ldots, S_R$. Consider all substrings of this sub...
["t=int(input())\n\nfor _ in range(t):\n n,q=map(int,input().split())\n s=input()\n l=[0]*(n-1)\n for i in range(n-2):\n a,b,c=s[i],s[i+1],s[i+2]\n if len(set([a,b,c]))<3:\n l[i]=l[i-1]+1\n else:\n l[i]=l[i-1]\n \n for i in range(q):\n left,right=map(int,input().split())\n left-=1\n right-=1\n if right-lef...
{"inputs": [["1", "10 2", "helloworld", "1 3", "1 10"]], "outputs": [["NO", "YES"]]}
interview
https://www.codechef.com/problems/RICHSTR
[ 32, 914, 448, 3084, 400, 43, 3, 374, 2598, 9080, 421, 400, 43, 1124, 709, 220, 18, 3, 323, 1052, 374, 264, 3668, 892, 13666, 304, 419, 914, 25470, 803, 1091, 400, 43, 14, 17, 3, 3039, 624, 2610, 525, 2661, 264, 914, 400, 50, 3...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
4,730
We need a function ```prime_bef_aft()``` that gives the largest prime below a certain given value ```n```, ```befPrime or bef_prime``` (depending on the language), and the smallest prime larger than this value, ```aftPrime/aft_prime``` (depending on the language). The result should be output in a list like the f...
["def prime(a):\n if a < 2: return False\n if a == 2 or a == 3: return True \n if a % 2 == 0 or a % 3 == 0: return False\n maxDivisor = a**0.5\n d, i = 5, 2\n while d <= maxDivisor:\n if a % d == 0: return False\n d += i \n i = 6 - i\n \n return True\n\ndef prime_bef_aft(num)...
{"fn_name": "prime_bef_aft", "inputs": [[3], [4], [100], [97], [101], [120], [130]], "outputs": [[[2, 5]], [[3, 5]], [[97, 101]], [[89, 101]], [[97, 103]], [[113, 127]], [[127, 131]]]}
introductory
https://www.codewars.com/kata/560b8d7106ede725dd0000e2
def prime_bef_aft(num):
[ 1654, 1184, 264, 729, 54275, 32338, 880, 823, 4306, 723, 368, 73594, 429, 6696, 279, 7772, 10250, 3685, 264, 3654, 2661, 897, 54275, 77, 13874, 7808, 4710, 73594, 57647, 32306, 476, 56946, 38217, 73594, 320, 80480, 389, 279, 4128, 701, ...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
252
There is a one-dimensional garden on the x-axis. The garden starts at the point 0 and ends at the point n. (i.e The length of the garden is n). There are n + 1 taps located at points [0, 1, ..., n] in the garden. Given an integer n and an integer array ranges of length n + 1 where ranges[i] (0-indexed) means the i-th t...
["class Solution:\n def minTaps(self, n: int, ranges: List[int]) -> int:\n for i,r in enumerate(ranges):\n l = max(0,i-r)\n ranges[l] = max(i+r, ranges[l])\n \n res = lo = hi = 0 \n while hi < n:\n lo, hi = hi, max(ranges[lo:hi+1])\n ...
{"fn_name": "minTaps", "inputs": [[5, [3, 4, 1, 1, 0, 0]]], "outputs": [1]}
interview
https://leetcode.com/problems/minimum-number-of-taps-to-open-to-water-a-garden/
class Solution: def minTaps(self, n: int, ranges: List[int]) -> int:
[ 3862, 374, 264, 825, 32420, 13551, 389, 279, 856, 35321, 13, 576, 13551, 8471, 518, 279, 1459, 220, 15, 323, 10335, 518, 279, 1459, 308, 13, 320, 72, 1734, 576, 3084, 315, 279, 13551, 374, 308, 4292, 3862, 525, 4102, 77, 488, 220, ...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
3,867
Our fruit guy has a bag of fruit (represented as an array of strings) where some fruits are rotten. He wants to replace all the rotten pieces of fruit with fresh ones. For example, given `["apple","rottenBanana","apple"]` the replaced array should be `["apple","banana","apple"]`. Your task is to implement a method that...
["def remove_rotten(bag_of_fruits):\n return [x.replace('rotten', '').lower() for x in bag_of_fruits] if bag_of_fruits else []", "def remove_rotten(fruit_bag):\n # Checking\n if not fruit_bag:\n return []\n # Processing\n temp = []\n for i in fruit_bag:\n i = i.replace(\"rotten\", \"\", ...
{"fn_name": "remove_rotten", "inputs": [[["apple", "banana", "kiwi", "melone", "orange"]], [["rottenApple", "rottenBanana", "rottenApple", "rottenPineapple", "rottenKiwi"]], [[]], [null], [["apple", "rottenBanana", "rottenApple", "pineapple", "kiwi"]]], "outputs": [[["apple", "banana", "kiwi", "melone", "orange"]], [["...
introductory
https://www.codewars.com/kata/557af4c6169ac832300000ba
def remove_rotten(bag_of_fruits):
[ 7981, 13779, 7412, 702, 264, 8968, 315, 13779, 320, 52759, 438, 458, 1334, 315, 9069, 8, 1380, 1045, 25322, 525, 77692, 13, 1260, 6801, 311, 8290, 678, 279, 77692, 9666, 315, 13779, 448, 7722, 6174, 13, 1752, 3110, 11, 2661, 1565, 118...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
1,172
Chef has the string s of length n consisted of digits 4 and 7. The string s is called balanced if there exits such integer x (1 ≤ x ≤ n) that the number of digits 4 in substring s[1; x) is equal to the number of digits 7 in substring s(x; n], where s[1; x) is the substring from the 1st digit to (x-1)th digit of s, and ...
["from math import factorial\ndef Ncr(n,r):\n if r<0:return 0\n return factorial(n)/(factorial(n-r)*factorial(r))\ndef solve(m,n):\n modulo=10**9+7\n if m==n:\n return (Ncr(2*n-1,n-1)+Ncr(2*n-2,n-2))%modulo\n elif m>n:\n return (Ncr(m+n,n)-Ncr(m+n-2,n-1))%modulo\n else:\n return (...
{"inputs": [["2", "47", "4477", "", ""]], "outputs": [["1", "4"]]}
interview
https://www.codechef.com/NOV12/problems/LUCKY9
[ 93903, 702, 279, 914, 274, 315, 3084, 308, 43560, 315, 18509, 220, 19, 323, 220, 22, 624, 785, 914, 274, 374, 2598, 23831, 198, 333, 1052, 42086, 1741, 7546, 856, 320, 16, 37294, 856, 37294, 308, 8, 429, 279, 1372, 315, 18509, 220, ...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
2,580
=====Problem Statement===== You are given a string S. S contains alphanumeric characters only. Your task is to sort the string S in the following manner: All sorted lowercase letters are ahead of uppercase letters. All sorted uppercase letters are ahead of digits. All sorted odd digits are ahead of sorted even digits. ...
["s = input()\ns = sorted(s,key = lambda x:(x.isdigit() and int(x)%2==0, x.isdigit(),x.isupper(),x.islower(),x))\nprint(*(s),sep = '')\n", "#!/usr/bin/env python3\n\ndef __starting_point():\n string = input().strip()\n \n print(*sorted(string, key = lambda x: (-x.islower(), x.isdigit() - x.isupper(), x in '024...
{"inputs": ["Sorting1234"], "outputs": ["ginortS1324"]}
introductory
https://www.hackerrank.com/challenges/ginorts/problem
# Enter your code here. Read input from STDIN. Print output to STDOUT
[ 46725, 31198, 21756, 64897, 2610, 525, 2661, 264, 914, 328, 13, 328, 5610, 98979, 5766, 1172, 13, 4615, 3383, 374, 311, 3378, 279, 914, 328, 304, 279, 2701, 11566, 510, 2403, 10615, 42047, 11931, 525, 8305, 315, 39482, 11931, 624, 2403,...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
4,735
#### Task: Your job here is to write a function (`keepOrder` in JS/CoffeeScript, `keep_order` in Ruby/Crystal/Python, `keeporder` in Julia), which takes a sorted array `ary` and a value `val`, and returns the lowest index where you could insert `val` to maintain the sorted-ness of the array. The input array will alway...
["from bisect import bisect_left as keep_order", "from bisect import bisect_left\n\ndef keep_order(arr, val):\n return bisect_left(arr, val)", "def keep_order(ary, val):\n for i, x in enumerate(ary):\n if x >= val:\n return i\n return len(ary)", "def keep_order(arr, val):\n for i in range(...
{"fn_name": "keep_order", "inputs": [[[1, 2, 3, 4, 7], 5], [[1, 2, 3, 4, 7], 0], [[1, 1, 2, 2, 2], 2], [[1, 2, 3, 4], 5], [[1, 2, 3, 4], -1], [[1, 2, 3, 4], 2], [[1, 2, 3, 4], 0], [[1, 2, 3, 4], 1], [[1, 2, 3, 4], 3], [[], 1], [[], 0], [[1, 1, 1, 1], 2], [[1, 1, 1, 1], 1], [[1, 1, 1, 1], 0], [[1, 3, 5, 6], 0], [[1, 3, ...
introductory
https://www.codewars.com/kata/582aafca2d44a4a4560000e7
def keep_order(ary, val):
[ 820, 5430, 1447, 7771, 2618, 1588, 374, 311, 3270, 264, 729, 28654, 13096, 4431, 63, 304, 12162, 11295, 21180, 5910, 11, 1565, 13096, 7869, 63, 304, 23726, 11295, 81, 13946, 14, 30280, 11, 1565, 13096, 1358, 63, 304, 39294, 701, 892, ...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
4,183
The goal of this Kata is to return the greatest distance of index positions between matching number values in an array or 0 if there are no matching values. Example: In an array with the values [0, 2, 1, 2, 4, 1] the greatest index distance is between the matching '1' values at index 2 and 5. Executing greatestDist...
["def greatest_distance(arr):\n return max(i - arr.index(x) for i,x in enumerate(arr))", "def greatest_distance(arr):\n indexes, d = {}, 0\n for i,n in enumerate(arr):\n if n in indexes: d = max(d, i-indexes[n])\n else: indexes[n] = i\n return d", "def greatest_distance(lst):\n r...
{"fn_name": "greatest_distance", "inputs": [[[9, 7, 1, 2, 3, 7, 0, -1, -2]], [[0, 7, 0, 2, 3, 7, 0, -1, -2]], [[1, 2, 3, 4]]], "outputs": [[4], [6], [0]]}
introductory
https://www.codewars.com/kata/5442e4fc7fc447653a0000d5
def greatest_distance(arr):
[ 785, 5795, 315, 419, 98838, 374, 311, 470, 279, 12196, 6010, 315, 1922, 9892, 1948, 12579, 1372, 2750, 304, 458, 1334, 476, 220, 15, 421, 1052, 525, 902, 12579, 2750, 13, 18611, 13314, 510, 641, 458, 1334, 448, 279, 2750, 508, 15, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1...
2,087
Vasya has n items lying in a line. The items are consecutively numbered by numbers from 1 to n in such a way that the leftmost item has number 1, the rightmost item has number n. Each item has a weight, the i-th item weights w_{i} kilograms. Vasya needs to collect all these items, however he won't do it by himself. He...
["3\n\nimport sys\n\nn, l, r, ql, qr = list(map(int, sys.stdin.readline().strip().split()))\nw = [int(x) for x in sys.stdin.readline().strip().split()]\n\ns = [0]\nfor i in range(0, n):\n s.append(s[-1] + w[i])\n\ndef cost(left):\n right = n - left\n diff = left - right\n bonus = 0\n if diff > 0: # left ...
{ "inputs": [ "3 4 4 19 1\n42 3 99\n", "4 7 2 3 9\n1 2 3 4\n", "2 100 100 10000 10000\n100 100\n", "2 3 4 5 6\n1 2\n", "1 78 94 369 10000\n93\n", "1 94 78 369 10000\n93\n", "5 1 100 1 10000\n1 2 3 4 5\n", "5 100 1 10000 1\n1 2 3 4 5\n", "5 1 100 10000 1\n1 2 3 4 5\n", "5 100 1 ...
competition
https://codeforces.com/problemset/problem/354/A
[ 53, 6405, 64, 702, 308, 3589, 20446, 304, 264, 1555, 13, 576, 3589, 525, 19908, 332, 3132, 48826, 553, 5109, 504, 220, 16, 311, 308, 304, 1741, 264, 1616, 429, 279, 2115, 3562, 1509, 702, 1372, 220, 16, 11, 279, 1290, 3562, 1509, ...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
4,709
Consider a sequence, which is formed by the following rule: next term is taken as the smallest possible non-negative integer, which is not yet in the sequence, so that `no 3` terms of sequence form an arithmetic progression. ## Example `f(0) = 0` -- smallest non-negative `f(1) = 1` -- smallest non-negative, which i...
["sequence=lambda n:int(format(n,'b'),3)", "def sequence(n):\n return int(format(n, 'b'), 3)", "sequence=lambda n:int(bin(n)[2:],3)", "# A005836\ndef sequence(n):\n return n and 3*sequence(n>>1) + (n&1)", "from math import log2\n\ndef sequence(i):\n if i == 0:\n return 0\n e = int(log2(i))\n retur...
{"fn_name": "sequence", "inputs": [[0], [1], [2], [3], [4], [5], [334], [123], [546], [1634], [14514]], "outputs": [[0], [1], [3], [4], [9], [10], [7329], [1084], [19929], [79707], [2305425]]}
introductory
https://www.codewars.com/kata/5e0607115654a900140b3ce3
def sequence(n):
[ 37175, 264, 8500, 11, 892, 374, 14122, 553, 279, 2701, 5912, 25, 1790, 4647, 374, 4429, 438, 279, 24632, 3204, 2477, 60935, 7546, 11, 892, 374, 537, 3602, 304, 279, 8500, 11, 773, 429, 1565, 2152, 220, 18, 63, 3793, 315, 8500, 1352,...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
2,347
A bitstring is a string consisting only of the characters 0 and 1. A bitstring is called $k$-balanced if every substring of size $k$ of this bitstring has an equal amount of 0 and 1 characters ($\frac{k}{2}$ of each). You are given an integer $k$ and a string $s$ which is composed only of characters 0, 1, and ?. You n...
["import sys\ninput = sys.stdin.readline\n\nt = int(input())\nfor _ in range(t):\n n, k = list(map(int, input().split()))\n s = input()\n l = ['']*k\n works = True\n for i in range(n):\n c = s[i]\n if c != '?':\n if l[i%k] == c or l[i%k] == '':\n l[i%k] = c\n ...
{ "inputs": [ "9\n6 4\n100110\n3 2\n1?1\n3 2\n1?0\n4 4\n????\n7 4\n1?0??1?\n10 10\n11??11??11\n4 2\n1??1\n4 4\n?0?0\n6 2\n????00\n" ], "outputs": [ "YES\nYES\nNO\nYES\nYES\nNO\nNO\nYES\nNO\n" ] }
competition
https://codeforces.com/problemset/problem/1404/A
[ 32, 2699, 917, 374, 264, 914, 30606, 1172, 315, 279, 5766, 220, 15, 323, 220, 16, 13, 362, 2699, 917, 374, 2598, 400, 74, 3, 12, 58402, 421, 1449, 38449, 315, 1379, 400, 74, 3, 315, 419, 2699, 917, 702, 458, 6144, 3311, 315, 220...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
2,687
Complete the method so that it formats the words into a single comma separated value. The last word should be separated by the word 'and' instead of a comma. The method takes in an array of strings and returns a single formatted string. Empty string values should be ignored. Empty arrays or null/nil values being passed...
["def format_words(words):\n return ', '.join(word for word in words if word)[::-1].replace(',', 'dna ', 1)[::-1] if words else ''", "def format_words(words):\n # reject falsey words\n if not words: return \"\"\n \n # ignoring empty strings\n words = [word for word in words if word]\n \n number_...
{"fn_name": "format_words", "inputs": [[["one", "two", "three", "four"]], [["one"]], [["one", "", "three"]], [["", "", "three"]], [["one", "two", ""]], [[]], [null], [[""]]], "outputs": [["one, two, three and four"], ["one"], ["one and three"], ["three"], ["one and two"], [""], [""], [""]]}
introductory
https://www.codewars.com/kata/51689e27fe9a00b126000004
def format_words(words):
[ 12548, 279, 1714, 773, 429, 432, 19856, 279, 4244, 1119, 264, 3175, 31683, 18663, 897, 13, 576, 1537, 3409, 1265, 387, 18663, 553, 279, 3409, 364, 437, 6, 4518, 315, 264, 31683, 13, 576, 1714, 4990, 304, 458, 1334, 315, 9069, 323, 4...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
527
Given an Array of length $N$ containing elements $Ai$ ( i = 1 to n ) . You have to handle $Q$ queries on this array . Each Query is of two types k=(1 or 2). Type 1:- $k$ $l$ $r$ in which you have to tell whether the product of numbers in range l to r results in a perfect square or not. if product of numbers in range...
["def update(index, value, bi_tree):\n while index < len(bi_tree):\n bi_tree[index] += value\n index += index & -index\n\n\ndef get_sum(index, bi_tree):\n ans = 0\n while index > 0:\n ans += bi_tree[index]\n index -= index & -index\n\n return ans\n\n\ndef get_range_sum(left, right, bi_tree):\n ans = get_sum(right, ...
{"inputs": [["4", "2 2 3 4", "4", "1 1 2", "1 3 4", "2 3 3", "1 1 4"]], "outputs": [["YES", "NO", "YES"]]}
interview
https://www.codechef.com/STRT2020/problems/RANPRO
[ 22043, 458, 2910, 315, 3084, 220, 400, 45, 3, 220, 8482, 5424, 400, 69667, 3, 320, 600, 284, 220, 16, 311, 308, 873, 659, 1446, 614, 311, 3705, 400, 48, 3, 19556, 389, 419, 1334, 659, 8886, 11361, 374, 315, 1378, 4494, 595, 4539, ...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
2,394
You are given a bracket sequence $s$ of length $n$, where $n$ is even (divisible by two). The string $s$ consists of $\frac{n}{2}$ opening brackets '(' and $\frac{n}{2}$ closing brackets ')'. In one move, you can choose exactly one bracket and move it to the beginning of the string or to the end of the string (i.e. yo...
["for _ in range(int(input())):\n n = int(input())\n s = input()\n st = 0\n fans = 0\n for x in s:\n if x == ')':\n st -= 1\n else:\n st += 1\n if st < 0:\n fans += 1\n st = 0\n print(fans)", "import sys\n# sys.setrecursionlimit(10**6) \...
{ "inputs": [ "4\n2\n)(\n4\n()()\n8\n())()()(\n10\n)))((((())\n" ], "outputs": [ "1\n0\n1\n3\n" ] }
introductory
https://codeforces.com/problemset/problem/1374/C
[ 2610, 525, 2661, 264, 31642, 8500, 400, 82, 3, 315, 3084, 400, 77, 54876, 1380, 400, 77, 3, 374, 1496, 320, 611, 23066, 553, 1378, 568, 576, 914, 400, 82, 3, 17167, 315, 57960, 37018, 91362, 15170, 17, 31716, 8568, 38929, 37880, 323...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
2,081
Nikita likes tasks on order statistics, for example, he can easily find the $k$-th number in increasing order on a segment of an array. But now Nikita wonders how many segments of an array there are such that a given number $x$ is the $k$-th number in increasing order on this segment. In other words, you should find th...
["from math import pi\nfrom cmath import exp\ndef fft(a, lgN, rot=1): # rot=-1 for ifft\n N = 1<<lgN\n assert len(a)==N\n rev = [0]*N\n for i in range(N):\n rev[i] = (rev[i>>1]>>1)+(i&1)*(N>>1)\n A = [a[rev[i]] for i in range(N)]\n h = 1\n while h<N:\n w_m = exp((0+1j) * rot * (pi / h))\n for k in range...
{ "inputs": [ "5 3\n1 2 3 4 5\n", "2 6\n-5 9\n", "6 99\n-1 -1 -1 -1 -1 -1\n", "5 -2\n-1 -1 -4 -5 1\n", "5 -6\n-4 2 -7 -1 -5\n", "10 29\n88 57 -3 -9 16 48 -84 80 -73 -46\n", "1 1000000000\n1\n", "2 -1000000000\n465132 210\n", "10 -8\n7 -1 0 -8 8 -1 -10 -7 4 0\n", "10 9\n-2 6 0 -...
competition
https://codeforces.com/problemset/problem/993/E
[ 45, 1579, 6255, 13151, 9079, 389, 1973, 13142, 11, 369, 3110, 11, 566, 646, 6707, 1477, 279, 400, 74, 3, 12, 339, 1372, 304, 7703, 1973, 389, 264, 10238, 315, 458, 1334, 13, 1988, 1431, 21573, 6255, 39064, 1246, 1657, 20632, 315, 45...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
3,859
```if-not:swift Create a method that takes an array/list as an input, and outputs the index at which the sole odd number is located. This method should work with arrays with negative numbers. If there are no odd numbers in the array, then the method should output `-1`. ``` ```if:swift reate a function `oddOne` that ta...
["def odd_one(arr):\n for i in range(len(arr)):\n if arr[i] % 2 != 0:\n return i\n return -1\n", "def odd_one(arr):\n return next((i for i,v in enumerate(arr) if v&1), -1)", "def odd_one(arr):\n for i in arr:\n if i%2: return arr.index(i)\n return -1", "def odd_one(arr):\n ad = ...
{"fn_name": "odd_one", "inputs": [[[2, 4, 6, 7, 10]], [[2, 16, 98, 10, 13, 78]], [[4, -8, 98, -12, -7, 90, 100]], [[2, 4, 6, 8]]], "outputs": [[3], [4], [4], [-1]]}
introductory
https://www.codewars.com/kata/5983cba828b2f1fd55000114
def odd_one(arr):
[ 73594, 333, 29169, 25, 70642, 198, 4021, 264, 1714, 429, 4990, 458, 1334, 20936, 438, 458, 1946, 11, 323, 16275, 279, 1922, 518, 892, 279, 13309, 10322, 1372, 374, 7407, 382, 1986, 1714, 1265, 975, 448, 18386, 448, 8225, 5109, 13, 141...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
1,468
Ms. E.T. came from planet Hex. She has 8 fingers in each hand which makes her count in hexadecimal way. When she meets you, she tells you that she came from 7E light years from the planet Earth. You see she means that it is 126 light years far away and she is telling you the numbers in hexadecimal. Now, you are in trou...
["# cook your dish here\ntry:\n t=int(input())\n for i in range(t):\n s=input()\n i=int(s,16)\n print(i)\nexcept EOFError as e:\n print(e)", "# cook your dish here\ntry:\n n=int(input())\n for i in range(n):\n a=input()\n \n print(int(a, 16))\nexcept EOFError as ...
{"inputs": [["3", "A", "1A23", "2C2A"]], "outputs": [["10", "6691", "11306"]]}
interview
https://www.codechef.com/JLUG2020/problems/HXTDC
[ 21634, 13, 468, 836, 13, 3697, 504, 11580, 27228, 13, 2932, 702, 220, 23, 19225, 304, 1817, 1424, 892, 3643, 1059, 1760, 304, 69722, 1616, 13, 3197, 1340, 20027, 498, 11, 1340, 10742, 498, 429, 1340, 3697, 504, 220, 22, 36, 3100, 16...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
2,631
=====Problem Statement===== You are given a function f(X) = X^2. You are also given K lists. The ith list consists of N_i elements. You have to pick one element from each list so that the value from the equation below is maximized: S = (f(X_1) + f(X_2) + ... + f(X_k))%M X_i denotes the element picked from the ith list...
["import itertools\n\nk, m = list(map(int,input().split()))\n\nmain_ar = []\nfor i in range(k):\n ar = list(map(int,input().split()))\n main_ar.append(ar[1:])\n\nall_combination = itertools.product(*main_ar)\nresult = 0\nfor single_combination in all_combination: \n result = max(sum([x*x for x in single_comb...
{"inputs": ["3 1000\n2 5 4\n3 7 8 9\n5 5 7 8 9 10"], "outputs": ["206"]}
introductory
https://www.hackerrank.com/challenges/maximize-it/problem
# Enter your code here. Read input from STDIN. Print output to STDOUT
[ 46725, 31198, 21756, 64897, 2610, 525, 2661, 264, 729, 282, 7644, 8, 284, 1599, 61, 17, 13, 1446, 525, 1083, 2661, 730, 11469, 13, 576, 77842, 1140, 17167, 315, 451, 5318, 5424, 382, 2610, 614, 311, 3735, 825, 2392, 504, 1817, 1140, ...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
949
Fizza is a cute girl and she wants to be more beautiful. So she approached a magician to increase her beauty magically. But the magician's glasses accidently got locked inside the locker and he forgot the password. Without glasses he can't help her. The password is hidden in N integers i.e. $a[1], a[2], ..... a[N]$ w...
["def check(l,n):\n m = 0\n for i in range(n-1):\n x = l[i]\n c = 0\n j = i\n while (j+2<n and l[j+2]==x) or (j+1<n and l[j+1] == x):\n if l[j+1] == x:\n j = j+1\n else:\n j+=2\n c+=1\n if m<c:\n m = c\n ...
{"inputs": [["3", "8", "6 3 6 4 5 4 3 6", "9", "5 5 4 5 2 1 3 4 2", "6", "1 2 3 4 5 6"]], "outputs": [["1", "2", "0"]]}
interview
https://www.codechef.com/LOGI2020/problems/FIZZA
[ 37, 13741, 374, 264, 18838, 3743, 323, 1340, 6801, 311, 387, 803, 6233, 624, 4416, 1340, 24706, 264, 89341, 311, 5263, 1059, 13143, 77725, 13, 1988, 279, 89341, 594, 715, 70, 33868, 11423, 398, 2684, 16061, 4766, 279, 34679, 323, 566, ...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
2,321
Roger is a robot. He has an arm that is a series of n segments connected to each other. The endpoints of the i-th segment are initially located at points (i - 1, 0) and (i, 0). The endpoint at (i - 1, 0) is colored red and the endpoint at (i, 0) is colored blue for all segments. Thus, the blue endpoint of the i-th segm...
["from cmath import rect\nimport sys\nimport math\nfrom functools import reduce\n\nclass SegmentTree():\n def __init__(self, L, function = lambda x,y: x+y):\n self.function = function\n N = self.size = len(L)\n M = 1 << N.bit_length()\n self.margin = 2*M - N\n self.L = [None for i ...
{"inputs": ["5 4\n1 1 3\n2 3 90\n2 5 48\n1 4 1\n", "1 1\n2 1 302\n"], "outputs": ["8.0000000000 0.0000000000\n5.0000000000 -3.0000000000\n4.2568551745 -2.6691306064\n4.2568551745 -3.6691306064\n", "0.5299192642 0.8480480962\n"]}
competition
https://codeforces.com/problemset/problem/618/E
[ 78425, 374, 264, 12305, 13, 1260, 702, 458, 6773, 429, 374, 264, 4013, 315, 308, 20632, 8433, 311, 1817, 1008, 13, 576, 36342, 315, 279, 600, 7563, 10238, 525, 15102, 7407, 518, 3501, 320, 72, 481, 220, 16, 11, 220, 15, 8, 323, 32...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
143
In a row of trees, the i-th tree produces fruit with type tree[i]. You start at any tree of your choice, then repeatedly perform the following steps: Add one piece of fruit from this tree to your baskets.  If you cannot, stop. Move to the next tree to the right of the current tree.  If there is no tree to the right, s...
["class Solution:\n def totalFruit(self, tree: List[int]) -> int:\n prior_fruit = tree[0]\n prior_fruit_counter = 0\n fruits_in_basket = [tree[0]]\n fruits_in_basket_counter = 0\n max_fib = -1\n for fruit in tree: \n if prior_fruit == fruit:\n prior...
{"fn_name": "totalFruit", "inputs": [[[1, 2, 1]]], "outputs": [3]}
interview
https://leetcode.com/problems/fruit-into-baskets/
class Solution: def totalFruit(self, tree: List[int]) -> int:
[ 641, 264, 2802, 315, 12408, 11, 279, 600, 7563, 4916, 4102, 8555, 1603, 4102, 35598, 448, 943, 4102, 9344, 989, 26126, 2610, 1191, 518, 894, 4916, 4102, 1055, 697, 5754, 11, 1221, 18822, 2736, 279, 2701, 7354, 1447, 2212, 825, 6573, 3...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
3,444
# Task You're given a substring s of some cyclic string. What's the length of the smallest possible string that can be concatenated to itself many times to obtain this cyclic string? # Example For` s = "cabca"`, the output should be `3` `"cabca"` is a substring of a cycle string "abcabcabcabc..." that can be obta...
["def cyclic_string(s):\n return next((i for i, _ in enumerate(s[1:], 1) if s.startswith(s[i:])), len(s))", "import math\n\ndef cyclic_string(s):\n for l in [i for i,ch in enumerate(s) if ch==s[0]][1:]:\n if (s[:l]*math.ceil(len(s)/l))[:len(s)] == s:\n return l\n return len(s)\n \n", "from itertools...
{"fn_name": "cyclic_string", "inputs": [["cabca"], ["aba"], ["ccccccccccc"], ["abaca"]], "outputs": [[3], [2], [1], [4]]}
introductory
https://www.codewars.com/kata/58899594b832f80348000122
def cyclic_string(s):
[ 2, 5430, 198, 1446, 2299, 2661, 264, 38449, 274, 315, 1045, 76002, 914, 13, 3555, 594, 279, 3084, 315, 279, 24632, 3204, 914, 429, 646, 387, 97534, 311, 5086, 1657, 3039, 311, 6851, 419, 76002, 914, 1939, 2, 13383, 271, 1752, 63, 27...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
4,685
A number is self-descriptive when the n'th digit describes the amount n appears in the number. E.g. 21200: There are two 0's in the number, so the first digit is 2. There is one 1 in the number, so the second digit is 1. There are two 2's in the number, so the third digit is 2. There are no 3's in the number, so t...
["from collections import Counter\n\n\ndef self_descriptive(num):\n s = [int(a) for a in str(num)]\n cnt = Counter(s)\n return all(cnt[i] == b for i, b in enumerate(s))\n", "def self_descriptive(num):\n numList = list(str(num))\n for i, s in enumerate(numList):\n if int(s) != numList.count(str(i))...
{"fn_name": "self_descriptive", "inputs": [[21200], [3211000], [42101000], [21230], [11200], [1210], [51120111], [2020], [11201], [6210001000]], "outputs": [[true], [true], [true], [false], [false], [true], [false], [true], [false], [true]]}
introductory
https://www.codewars.com/kata/56a628758f8d06b59800000f
def self_descriptive(num):
[ 32, 1372, 374, 656, 24506, 40319, 979, 279, 308, 944, 71, 15723, 16555, 279, 3311, 308, 7952, 304, 279, 1372, 382, 36, 1302, 13, 220, 17, 16, 17, 15, 15, 1447, 3862, 525, 1378, 220, 15, 594, 304, 279, 1372, 11, 773, 279, 1156, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1...
2,069
You are given an array $a$ of $n$ integers. You want to make all elements of $a$ equal to zero by doing the following operation exactly three times: Select a segment, for each number in this segment we can add a multiple of $len$ to it, where $len$ is the length of this segment (added integers can be different). It...
["n=int(input())\nL=list(map(int,input().split()))\nif n==1:\n print(1,1)\n print(0)\n print(1,1)\n print(0)\n print(1,1)\n print(-L[0])\nelse:\n print(1,n-1)\n for i in range(n-1):print(L[i]*(n-1),end=' ')\n print()\n print(n,n)\n print(-L[n-1])\n print(1,n)\n for i in range(n-1)...
{"inputs": ["4\n1 3 2 4\n", "1\n34688642\n", "2\n-492673762 -496405053\n", "4\n-432300451 509430974 -600857890 -140418957\n", "16\n-15108237 489260742 681810357 -78861365 -416467743 -896443270 904192296 -932642644 173249302 402207268 -329323498 537696045 -899233426 902347982 -595589754 -480337024\n", "8\n-311553829 469...
competition
https://codeforces.com/problemset/problem/1396/A
[ 2610, 525, 2661, 458, 1334, 400, 64, 3, 315, 400, 77, 3, 25780, 382, 2610, 1366, 311, 1281, 678, 5424, 315, 400, 64, 3, 6144, 311, 7168, 553, 3730, 279, 2701, 5666, 6896, 2326, 3039, 25, 220, 8427, 264, 10238, 11, 369, 1817, 1372,...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
3,652
I have started studying electronics recently, and I came up with a circuit made up of 2 LEDs and 3 buttons. Here 's how it works: 2 buttons (`red` and `blue`) are connected to the LEDs (`red` and `blue` respectively). Buttons pressing pattern will be remembered and represented through the LEDs when the third button is...
["def button_sequences(seqR, seqB):\n pattern, state = '', ''\n toBool = lambda seq : [i == '1' for i in seq]\n for red, blue in zip(toBool(seqR), toBool(seqB)):\n if red and state == 'R' or blue and state == 'B':\n continue\n state = 'R' if red else 'B' if blue else ''\n patter...
{"fn_name": "button_sequences", "inputs": [["10011010", "10110111"], ["01001000", "01011100"], ["00010100", "01011100"], ["10101010", "01010101"], ["11011011", "11111011"]], "outputs": [["RBRB"], ["RB"], ["BRB"], ["RBRBRBRB"], ["RBR"]]}
introductory
https://www.codewars.com/kata/5bec507e1ab6db71110001fc
def button_sequences(seqR, seqB):
[ 40, 614, 3855, 20956, 30491, 5926, 11, 323, 358, 3697, 705, 448, 264, 16224, 1865, 705, 315, 220, 17, 55572, 323, 220, 18, 12424, 382, 8420, 364, 82, 1246, 432, 4278, 25, 220, 17, 12424, 28654, 1151, 63, 323, 1565, 12203, 32881, 525...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
2,230
A new pack of n t-shirts came to a shop. Each of the t-shirts is characterized by three integers p_{i}, a_{i} and b_{i}, where p_{i} is the price of the i-th t-shirt, a_{i} is front color of the i-th t-shirt and b_{i} is back color of the i-th t-shirt. All values p_{i} are distinct, and values a_{i} and b_{i} are integ...
["n = int(input())\n\np = [int(i) for i in input().split()]\na = [int(i) for i in input().split()]\nb = [int(i) for i in input().split()]\n\ns = []\nfor i in range(n):\n s.append([p[i], a[i], b[i]])\n\ns = sorted(s)\n\nm = int(input())\nc = [int(i) for i in input().split()]\n\nidx = [0]*4\n\nans = []\n\nfor i in ran...
{ "inputs": [ "5\n300 200 400 500 911\n1 2 1 2 3\n2 1 3 2 1\n6\n2 3 1 2 1 1\n", "2\n1000000000 1\n1 1\n1 2\n2\n2 1\n", "10\n251034796 163562337 995167403 531046374 341924810 828969071 971837553 183763940 857690534 687685084\n3 2 1 3 2 3 1 3 2 1\n2 3 3 1 2 3 2 3 3 2\n10\n1 3 2 3 2 3 3 1 2 3\n", "20\n41...
competition
https://codeforces.com/problemset/problem/799/B
[ 32, 501, 3769, 315, 308, 259, 48660, 3697, 311, 264, 8061, 13, 8886, 315, 279, 259, 48660, 374, 31871, 553, 2326, 25780, 281, 15159, 72, 2137, 264, 15159, 72, 92, 323, 293, 15159, 72, 2137, 1380, 281, 15159, 72, 92, 374, 279, 3349, ...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
3,695
# Task You are given a string `s`. Let's call its substring a group, if all letters in it are adjacent and the same(such as `"aa","bbb","cccc"`..). Let's call the substiring with 2 or more adjacent group a big group(such as `"aabb","bbccc"`...). Your task is to count the number of `big groups` in the given string. ...
["from re import findall; repeat_adjacent=lambda s: len(findall(r\"((.)\\2+(?!\\2)){2,}\",s))", "import re\nrepeat_adjacent=lambda s:sum(len(set(i[0]))>1 for i in re.findall(r'((([a-z])\\3+){2,})', s))", "from functools import partial\nfrom itertools import groupby\nfrom operator import ne\n\ndef repeat_adjacent(s):\n ...
{"fn_name": "repeat_adjacent", "inputs": [["ccccoodeffffiiighhhhhhhhhhttttttts"], ["soooooldieeeeeer"], ["ccccoooooooooooooooooooooooddee"], ["wwwwaaaarrioooorrrrr"], ["gztxxxxxggggggggggggsssssssbbbbbeeeeeeehhhmmmmmmmitttttttlllllhkppppp"]], "outputs": [[3], [0], [1], [2], [2]]}
introductory
https://www.codewars.com/kata/58b8dccecf49e57a5a00000e
def repeat_adjacent(string):
[ 2, 5430, 198, 1446, 525, 2661, 264, 914, 1565, 82, 28587, 6771, 594, 1618, 1181, 38449, 264, 1874, 11, 421, 678, 11931, 304, 432, 525, 23942, 323, 279, 1852, 1141, 1387, 438, 53305, 5305, 2198, 53151, 2198, 55597, 39917, 496, 568, 677...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
639
For a string $S$ let the unique set of characters that occur in it one or more times be $C$. Consider a permutation of the elements of $C$ as $(c_1, c_2, c_3 ... )$. Let $f(c)$ be the number of times $c$ occurs in $S$. If any such permutation of the elements of $C$ satisfies $f(c_i) = f(c_{i-1}) + f(c_{i-2})$ for all $...
["# cook your dish here\nt=int(input())\nfor _ in range(t):\n st=input()\n s=set(st)\n a=[]\n f1=f2=0\n for i in s:\n a.append(st.count(i))\n a.sort()\n if len(a)>=3:\n for i in range(2,len(a)):\n if a[i]!=a[i-1]+a[i-2]:\n f1=1\n break\n x=a[0]\n a[0]=a[1]\n a[1]=x\n for i in range(2,len(a)):\n if a[i]!...
{"inputs": [["3", "aaaabccc", "aabbcc", "ppppmmnnoooopp"]], "outputs": [["Dynamic", "Not", "Dynamic"]]}
interview
https://www.codechef.com/problems/CLFIBD
[ 2461, 264, 914, 400, 50, 3, 1077, 279, 4911, 738, 315, 5766, 429, 12170, 304, 432, 825, 476, 803, 3039, 387, 400, 34, 12947, 21144, 264, 58441, 315, 279, 5424, 315, 400, 34, 3, 438, 4930, 66, 62, 16, 11, 272, 62, 17, 11, 272, ...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
4,074
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 a minimum of two elements. Input data range guarantees that `max-m...
["def between_extremes(numbers):\n return max(numbers) - min(numbers)", "def between_extremes(ns):\n return max(ns) - min(ns)", "def between_extremes(a):\n return max(a) - min(a)", "# Naive method: 2 iterations\ndef between_extremes(numbers):\n return max(numbers) - min(numbers)\n\n# Faster method: 1 iterat...
{"fn_name": "between_extremes", "inputs": [[[1, 1]], [[-1, -1]], [[1, -1]], [[21, 34, 54, 43, 26, 12]], [[-1, -41, -77, -100]]], "outputs": [[0], [0], [2], [42], [99]]}
introductory
https://www.codewars.com/kata/56d19b2ac05aed1a20000430
def between_extremes(numbers):
[ 22043, 458, 1334, 315, 5109, 11, 470, 279, 6672, 1948, 279, 7772, 323, 24632, 2750, 13, 4710, 2461, 3110, 1447, 63, 58, 17, 18, 11, 220, 18, 11, 220, 16, 24, 11, 220, 17, 16, 11, 220, 16, 21, 60, 63, 1265, 470, 1565, 17, 15, ...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
2,060
Evlampiy has found one more cool application to process photos. However the application has certain limitations. Each photo i has a contrast v_{i}. In order for the processing to be truly of high quality, the application must receive at least k photos with contrasts which differ as little as possible. Evlampiy alread...
["def f(m):\n nonlocal dp, sdp\n l = 0\n for i in range(n):\n while l < n and v[l] < v[i] - m:\n l += 1\n if l - 1 > i - k:\n dp[i] = False\n else:\n dp[i] = (sdp[i - k + 1] != sdp[l - 1])\n sdp[i + 1] = sdp[i] + (1 if dp[i] else 0)\n return dp[n ...
{ "inputs": [ "5 2\n50 110 130 40 120\n", "4 1\n2 3 4 1\n", "1 1\n4\n", "2 2\n7 5\n", "3 2\n34 3 75\n", "5 2\n932 328 886 96 589\n", "10 4\n810 8527 9736 3143 2341 6029 7474 707 2513 2023\n", "20 11\n924129 939902 178964 918687 720767 695035 577430 407131 213304 810868 596349 266075 12...
competition
https://codeforces.com/problemset/problem/883/I
[ 36, 14536, 1121, 16220, 702, 1730, 825, 803, 7010, 3766, 311, 1882, 7249, 13, 4354, 279, 3766, 702, 3654, 9481, 382, 4854, 6548, 600, 702, 264, 12872, 348, 15159, 72, 7810, 758, 1973, 369, 279, 8692, 311, 387, 9428, 315, 1550, 4271, ...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
1,177
Chef has N subordinates. In order to complete a very important order he will choose exactly K of them. He can't choose less than K since it will be not enough to complete the order in time. On the other hand if he chooses more than K subordinates he can't control them during the operation. Help him to find the number o...
["def nCr(n,k):\n if(k>n):return 0\n k=min(k,n-k)\n num,den=1,1\n for i in range(k):\n num*=(n-i)\n den*=(i+1)\n return num/den\n\ndef Main():\n for cases in range(int(input())):\n a,b=[int(x) for x in input().split()]\n print(nCr(a,b))\n\nMain()", "def gets():\n while(1):\n a=input().strip()\n if(a):return a\n\n...
{"inputs": [["3", "2 1", "3 3", "10 5"]], "outputs": [["2", "1", "252"]]}
interview
https://www.codechef.com/COOK06/problems/CHEFTEAM
[ 93903, 702, 451, 1186, 8742, 13, 758, 1973, 311, 4583, 264, 1602, 2989, 1973, 566, 686, 5157, 6896, 730, 315, 1105, 13, 1260, 646, 944, 5157, 2686, 1091, 730, 2474, 432, 686, 387, 537, 3322, 311, 4583, 279, 1973, 304, 882, 13, 1913,...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
246
In English, we have a concept called root, which can be followed by some other words to form another longer word - let's call this word successor. For example, the root an, followed by other, which can form another word another. Now, given a dictionary consisting of many roots and a sentence. You need to replace al...
["class Solution:\n def replaceWords(self, dt, sentence):\n \"\"\"\n :type dict: List[str]\n :type sentence: str\n :rtype: str\n \"\"\"\n trie = {}\n for w in dt:\n t = trie\n for c in w:\n if c not in t: t[c] = {}\n ...
{"fn_name": "replaceWords", "inputs": [[["\"cat\"", "\"bat\"", "\"rat\""], "\"the cattle was rattled by the battery\""]], "outputs": ["\"the cattle was rattled by the battery\""]}
interview
https://leetcode.com/problems/replace-words/
class Solution: def replaceWords(self, dictionary: List[str], sentence: str) -> str:
[ 641, 6364, 11, 582, 614, 264, 7286, 2598, 3704, 11, 892, 646, 387, 8110, 553, 1045, 1008, 4244, 311, 1352, 2441, 5021, 3409, 481, 1077, 594, 1618, 419, 3409, 33565, 13, 1752, 3110, 11, 279, 3704, 458, 11, 8110, 553, 1008, 11, 892, ...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
3,824
Given a certain integer ```n, n > 0```and a number of partitions, ```k, k > 0```; we want to know the partition which has the maximum or minimum product of its terms. The function ```find_spec_partition() ```, will receive three arguments, ```n```, ```k```, and a command: ```'max' or 'min'``` The function should...
["def find_spec_partition(n, k, com):\n x,r = divmod(n,k)\n return {'max': [x+1]*r + [x]*(k-r),\n 'min': [n+1-k] + [1]*(k-1)}[com]", "def find_spec_partition(n, k, com):\n return [n-k+1] + [1] * (k-1) if com == \"min\" else [n//k + 1] * (n%k) + [n//k] * (k - n%k)", "def find_spec_partition(n, k, com...
{"fn_name": "find_spec_partition", "inputs": [[10, 4, "max"], [10, 4, "min"]], "outputs": [[[3, 3, 2, 2]], [[7, 1, 1, 1]]]}
introductory
https://www.codewars.com/kata/57161cb0b436cf0911000819
def find_spec_partition(n, k, com):
[ 22043, 264, 3654, 7546, 220, 54275, 77, 11, 308, 861, 220, 15, 73594, 437, 264, 1372, 315, 46688, 11, 220, 54275, 74, 11, 595, 861, 220, 15, 73594, 26, 582, 1366, 311, 1414, 279, 16658, 892, 702, 279, 7192, 476, 8028, 1985, 315, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1...
1,029
After a long and successful day of preparing food for the banquet, it is time to clean up. There is a list of n jobs to do before the kitchen can be closed for the night. These jobs are indexed from 1 to n. Most of the cooks have already left and only the Chef and his assistant are left to clean up. Thankfully, some o...
["T = int(input())\nfor _ in range(T):\n n,m = map(int,input().split())\n completed = list(map(int,input().split()))\n jobs = []\n for i in range(1,n+1):\n if i not in completed:\n jobs.append(i)\n jobs.sort()\n chef = []\n ass = []\n for i in range(len(jobs)):\n if i%2==0:\n chef.append(str(jobs[i]))\n else:\n ...
{"inputs": [["3", "6 3", "2 4 1", "3 2", "3 2", "8 2", "3 8"]], "outputs": [["3 6", "5", "1", "1 4 6", "2 5 7"]]}
interview
https://www.codechef.com/problems/CLEANUP
[ 6025, 264, 1293, 323, 6849, 1899, 315, 20045, 3607, 369, 279, 86738, 11, 432, 374, 882, 311, 4240, 705, 13, 2619, 374, 264, 1140, 315, 308, 6887, 311, 653, 1573, 279, 9780, 646, 387, 7877, 369, 279, 3729, 13, 4220, 6887, 525, 30581,...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
4,400
# Task **_Given_** *an array of N integers, you have to find* **_how many times_** *you have to* **_add up the smallest numbers_** *in the array until* **_their Sum_** *becomes greater or equal to* **_K_**. ___ # Notes: * **_List size_** is *at least 3*. * **_All numbers_** *will be* **_positive_**. * **_Num...
["def minimum_steps(arr, n):\n arr = sorted(arr)\n s = 0\n for i,v in enumerate(arr): \n s += v\n if s >= n: return i", "from itertools import accumulate\n\ndef minimum_steps(numbers, value):\n return next(i for i, s in enumerate(accumulate(sorted(numbers))) if s >= value)", "def minimum_steps...
{"fn_name": "minimum_steps", "inputs": [[[4, 6, 3], 7], [[10, 9, 9, 8], 17], [[8, 9, 10, 4, 2], 23], [[19, 98, 69, 28, 75, 45, 17, 98, 67], 464], [[4, 6, 3], 2]], "outputs": [[1], [1], [3], [8], [0]]}
introductory
https://www.codewars.com/kata/5a91a7c5fd8c061367000002
def minimum_steps(numbers, value):
[ 2, 5430, 271, 334, 62, 22043, 62, 334, 353, 276, 1334, 315, 451, 25780, 11, 498, 614, 311, 1477, 9, 3070, 62, 5158, 1657, 3039, 62, 334, 353, 9330, 614, 311, 9, 3070, 62, 718, 705, 279, 24632, 5109, 62, 334, 353, 258, 279, 1334,...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
2,763
In mathematics, a [Diophantine equation](https://en.wikipedia.org/wiki/Diophantine_equation) is a polynomial equation, usually with two or more unknowns, such that only the integer solutions are sought or studied. In this kata we want to find all integers `x, y` (`x >= 0, y >= 0`) solutions of a diophantine equation o...
["import math\ndef sol_equa(n):\n res = []\n for i in range(1, int(math.sqrt(n)) + 1):\n if n % i == 0:\n j = n // i\n if (i + j) % 2 == 0 and (j - i) % 4 == 0:\n x = (i + j) // 2\n y = (j - i) // 4\n res.append([x, y])\n \n r...
{"fn_name": "sol_equa", "inputs": [[5], [12], [13], [16], [17], [20], [9001], [9004], [9005], [9008], [90001], [90002], [90004], [90005], [90009], [900001], [900004], [900005], [9000001], [9000004], [90000001], [90000004], [900000012], [9000000041]], "outputs": [[[[3, 1]]], [[[4, 1]]], [[[7, 3]]], [[[4, 0]]], [[[9, 4]]...
introductory
https://www.codewars.com/kata/554f76dca89983cc400000bb
def sol_equa(n):
[ 641, 37596, 11, 264, 508, 21685, 5127, 38357, 23606, 9533, 2428, 1110, 268, 33366, 2659, 25502, 14953, 72, 5127, 38357, 41443, 367, 8, 374, 264, 47311, 23606, 11, 5990, 448, 1378, 476, 803, 9788, 82, 11, 1741, 429, 1172, 279, 7546, 99...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
2,643
=====Function Descriptions===== .symmetric_difference() The .symmetric_difference() operator returns a set with all the elements that are in the set and the iterable but not both. Sometimes, a ^ operator is used in place of the .symmetric_difference() tool, but it only operates on the set of elements in set. The set i...
["e = int(input())\neng = set(map(int,input().split())) \nf = int(input())\nfre = set(map(int,input().split()))\nprint((len(eng ^ fre)))\n", "#!/usr/bin/env python3\n\ndef __starting_point():\n n = int(input().strip())\n english = set(map(int, input().strip().split(' ')))\n m = int(input().strip())\n french...
{"inputs": ["9\n1 2 3 4 5 6 7 8 9\n9\n10 1 2 3 11 21 55 6 8"], "outputs": ["8"]}
introductory
https://www.hackerrank.com/challenges/py-set-symmetric-difference-operation/problem
# Enter your code here. Read input from STDIN. Print output to STDOUT
[ 46725, 5152, 3874, 24685, 64897, 44906, 47525, 2822, 785, 659, 23802, 15903, 47525, 368, 5675, 4675, 264, 738, 448, 678, 279, 5424, 429, 525, 304, 279, 738, 323, 279, 50834, 714, 537, 2176, 624, 31048, 11, 264, 6306, 5675, 374, 1483, ...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
4,712
Lucas numbers are numbers in a sequence defined like this: ``` L(0) = 2 L(1) = 1 L(n) = L(n-1) + L(n-2) ``` Your mission is to complete the function that returns the `n`th term of this sequence. **Note:** It should work for negative numbers as well; how you do this is you flip the equation around, so for negative num...
["def lucasnum(n):\n a = 2\n b = 1\n\n flip = n < 0 and n % 2 != 0\n\n for _ in range(abs(n)):\n a, b = b, a + b\n \n return -a if flip else a", "SEQUENCE = [2, 1]\n\ndef lucasnum(n):\n try:\n return SEQUENCE[abs(n)] * (1, -1)[n < 0 and n % 2]\n except IndexError:\n while l...
{"fn_name": "lucasnum", "inputs": [[-10], [-1]], "outputs": [[123], [-1]]}
introductory
https://www.codewars.com/kata/55a7de09273f6652b200002e
def lucasnum(n):
[ 40645, 300, 5109, 525, 5109, 304, 264, 8500, 4512, 1075, 419, 510, 13874, 3989, 43, 7, 15, 8, 284, 220, 17, 198, 43, 7, 16, 8, 284, 220, 16, 198, 43, 1445, 8, 284, 444, 1445, 12, 16, 8, 488, 444, 1445, 12, 17, 340, 13874, 19...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
3,987
Write a function that takes in a string of one or more words, and returns the same string, but with all five or more letter words reversed (Just like the name of this Kata). Strings passed in will consist of only letters and spaces. Spaces will be included only when more than one word is present. Examples: spinWords( ...
["def spin_words(sentence):\n # Your code goes here\n return \" \".join([x[::-1] if len(x) >= 5 else x for x in sentence.split(\" \")])", "def spin_words(sentence):\n words = [word for word in sentence.split(\" \")]\n words = [word if len(word) < 5 else word[::-1] for word in words]\n return \" \".join(w...
{"fn_name": "spin_words", "inputs": [["Welcome"], ["to"], ["CodeWars"], ["Hey fellow warriors"], ["This sentence is a sentence"]], "outputs": [["emocleW"], ["to"], ["sraWedoC"], ["Hey wollef sroirraw"], ["This ecnetnes is a ecnetnes"]]}
introductory
https://www.codewars.com/kata/5264d2b162488dc400000001
def spin_words(sentence):
[ 7985, 264, 729, 429, 4990, 304, 264, 914, 315, 825, 476, 803, 4244, 11, 323, 4675, 279, 1852, 914, 11, 714, 448, 678, 4236, 476, 803, 6524, 4244, 27437, 320, 9952, 1075, 279, 829, 315, 419, 98838, 568, 41651, 5823, 304, 686, 6685, ...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
2,009
For a vector $\vec{v} = (x, y)$, define $|v| = \sqrt{x^2 + y^2}$. Allen had a bit too much to drink at the bar, which is at the origin. There are $n$ vectors $\vec{v_1}, \vec{v_2}, \cdots, \vec{v_n}$. Allen will make $n$ moves. As Allen's sense of direction is impaired, during the $i$-th move he will either move in th...
["import random\n\nn = int(input())\nv = []\na = []\nfor i in range(n):\n a.append(i)\n\nfor _ in range(0, n):\n x, y = list(map(int, input().split()))\n v.append([x, y, x*x+y*y])\n\nwhile 1>0:\n x = 0\n y = 0\n ans = [0]*n\n random.shuffle(a)\n for i in range(n):\n if (x+v[a[i]][0])**2+(...
{ "inputs": [ "3\n999999 0\n0 999999\n999999 0\n", "1\n-824590 246031\n", "8\n-67761 603277\n640586 -396671\n46147 -122580\n569609 -2112\n400 914208\n131792 309779\n-850150 -486293\n5272 721899\n", "6\n1000000 0\n1000000 0\n-1000000 0\n0 1000000\n0 -1000000\n0 -1000000\n", "8\n-411248 143802\n3003...
competition
https://codeforces.com/problemset/problem/995/C
[ 2461, 264, 4621, 57960, 4083, 90, 85, 92, 284, 320, 87, 11, 379, 15087, 11, 6979, 400, 91, 85, 91, 284, 1124, 26888, 45340, 61, 17, 488, 379, 61, 17, 31716, 382, 79877, 1030, 264, 2699, 2238, 1753, 311, 7027, 518, 279, 3619, 11, ...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
3,984
If you like Taco Bell, you will be familiar with their signature doritos locos taco. They're very good. Why can't everything be a taco? We're going to attempt that here, turning every word we find into the taco bell recipe with each ingredient. We want to input a word as a string, and return a list representing tha...
["import re\n\nTACODICT = {\n 't':'tomato', \n 'l':'lettuce',\n 'c':'cheese',\n 'g':'guacamole',\n 's':'salsa'\n }\n\ndef tacofy(word):\n return ['shell'] + [TACODICT.get(c, 'beef') for c in re.sub('[^aeioutlcgs]+' ,'', word.lower())] + ['shell']"...
{"fn_name": "tacofy", "inputs": [[""], ["a"], ["ogl"], ["alel"], ["MaXwElL"], ["ggg"], ["Alex is Super Cool"], ["ydjkpwqrzto"], ["abtlcgs"]], "outputs": [[["shell", "shell"]], [["shell", "beef", "shell"]], [["shell", "beef", "guacamole", "lettuce", "shell"]], [["shell", "beef", "lettuce", "beef", "lettuce", "shell"]], ...
introductory
https://www.codewars.com/kata/59414b46d040b7b8f7000021
def tacofy(word):
[ 2679, 498, 1075, 78897, 17884, 11, 498, 686, 387, 11285, 448, 862, 11957, 52303, 25593, 1329, 436, 90841, 13, 2379, 2299, 1602, 1661, 4192, 10234, 646, 944, 4297, 387, 264, 90841, 30, 1205, 2299, 2087, 311, 4774, 429, 1588, 11, 13054, ...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
3,639
Ever the learned traveller, Alan Partridge has pretty strong views on London: ``` "Go to London. I guarantee you'll either be mugged or not appreciated. Catch the train to London, stopping at Rejection, Disappointment, Backstabbing Central and Shattered Dreams Parkway." ``` Your job is to check that the provided list ...
["def alan(arr):\n s = {'Rejection', 'Disappointment', 'Backstabbing Central', 'Shattered Dreams Parkway'}\n return \"Smell my cheese you mother!\" if s.issubset(arr) else \"No, seriously, run. You will miss it.\"", "def alan(arr):\n a = ['Rejection', 'Disappointment', 'Backstabbing Central', 'Shattered Dreams...
{"fn_name": "alan", "inputs": [[["Norwich", "Rejection", "Disappointment", "Backstabbing Central", "Shattered Dreams Parkway", "London"]], [["London", "Norwich"]], [["Norwich", "Tooting", "Bank", "Rejection", "Disappointment", "Backstabbing Central", "Exeter", "Shattered Dreams Parkway", "Belgium", "London"]], [["Londo...
introductory
https://www.codewars.com/kata/580a41b6d6df740d6100030c
def alan(arr):
[ 43487, 279, 9498, 85194, 11, 25282, 4270, 36877, 702, 5020, 3746, 6194, 389, 7148, 1447, 13874, 3989, 1, 10850, 311, 7148, 13, 358, 15440, 498, 3278, 2987, 387, 296, 20146, 476, 537, 25808, 624, 57760, 279, 5426, 311, 7148, 11, 22535, ...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
3,386
Hi there! You have to implement the `String get_column_title(int num) // syntax depends on programming language` function that takes an integer number (index of the Excel column) and returns the string represents the title of this column. #Intro In the MS Excel lines are numbered by decimals, columns - by sets of ...
["from string import ascii_uppercase as u\n\ndef get_column_title(n):\n assert isinstance(n, int) and n > 0\n col = []\n while n:\n n, r = divmod(n-1, 26)\n col.append(u[r])\n return ''.join(reversed(col))", "upper = __import__(\"string\").ascii_uppercase.__getitem__\n\ndef get_column_title(nu...
{"fn_name": "get_column_title", "inputs": [[1], [26], [52], [53], [702]], "outputs": [["A"], ["Z"], ["AZ"], ["BA"], ["ZZ"]]}
introductory
https://www.codewars.com/kata/56d082c24f60457198000e77
def get_column_title(num):
[ 13048, 1052, 0, 715, 2610, 614, 311, 4211, 279, 4710, 63, 703, 633, 8744, 6112, 1548, 1629, 8, 442, 19482, 13798, 389, 15473, 4128, 19324, 1688, 429, 4990, 458, 7546, 1372, 320, 1252, 315, 279, 21029, 3250, 8, 323, 4675, 279, 914, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1...
851
Mr. X has come up with a new string compression algorithm. Consider a string of length N which contains up to K distinct characters. The compression algorithm works as follows: Replace each maximal contiguous substring containing only one distinct character (repeated an arbitrary number of times) and replace it by 2 va...
["for _ in range(int(input())):\n\tn,k=map(int,input().split())\n\tprint(((2*n*(k-1))+2)/k)", "for _ in range(int(input())):\r\n\tn,k=map(int,input().split())\r\n\ta=((2*n*(k-1))+2)/k\r\n\tprint(a)", "# cook your dish here\nfor _ in range(int(input())):\n n,k=map(int,input().split())\n print(2+(n-1)*((2)-(2/k)))"...
{"inputs": [["2", "3 1", "3 2", ""]], "outputs": [["2.0", "4.0"]]}
interview
https://www.codechef.com/problems/COMPEXP
[ 12275, 13, 1599, 702, 2525, 705, 448, 264, 501, 914, 25111, 12111, 13, 21144, 264, 914, 315, 3084, 451, 892, 5610, 705, 311, 730, 12460, 5766, 13, 576, 25111, 12111, 4278, 438, 11017, 25, 29558, 1817, 53129, 66503, 38449, 8482, 1172, ...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
4,939
# Background I drink too much coffee. Eventually it will probably kill me. *Or will it..?* Anyway, there's no way to know. *Or is there...?* # The Discovery of the Formula I proudly announce my discovery of a formula for measuring the life-span of coffee drinkers! For * ```h``` is a health number assigned to ...
["def coffee_limits(year, month, day):\n h = int(f'{year:04}{month:02}{day:02}')\n return [limit(h, 0xcafe), limit(h, 0xdecaf)]\n \ndef limit(h, c):\n for i in range(1, 5000):\n h += c\n if 'DEAD' in f'{h:X}':\n return i\n return 0\n\n", "def coffee_limits(year, month, day):\n ...
{"fn_name": "coffee_limits", "inputs": [], "outputs": []}
introductory
https://www.codewars.com/kata/57db78d3b43dfab59c001abe
def coffee_limits(year, month, day):
[ 2, 24800, 271, 40, 7027, 2238, 1753, 10799, 13, 37174, 432, 686, 4658, 5505, 752, 382, 9, 2195, 686, 432, 496, 30, 21518, 48288, 11, 1052, 594, 902, 1616, 311, 1414, 382, 9, 2195, 374, 1052, 1112, 30, 9, 1406, 2, 576, 38093, 315, ...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
141
The i-th person has weight people[i], and each boat can carry a maximum weight of limit. Each boat carries at most 2 people at the same time, provided the sum of the weight of those people is at most limit. Return the minimum number of boats to carry every given person.  (It is guaranteed each person can be carried by ...
["class Solution:\n def numRescueBoats(self, people: List[int], limit: int) -> int:\n \n people.sort()\n lo = 0 \n hi = len(people) - 1\n count = 0\n \n while lo <= hi:\n count += 1\n if people[lo] + people[hi] <= limit:\n lo += 1\...
{"fn_name": "numRescueBoats", "inputs": [[[1, 2], 3]], "outputs": [1]}
interview
https://leetcode.com/problems/boats-to-save-people/
class Solution: def numRescueBoats(self, people: List[int], limit: int) -> int:
[ 785, 600, 7563, 1697, 702, 4680, 1251, 989, 1125, 323, 1817, 15328, 646, 6777, 264, 7192, 4680, 315, 3930, 624, 4854, 15328, 23377, 518, 1429, 220, 17, 1251, 518, 279, 1852, 882, 11, 3897, 279, 2629, 315, 279, 4102, 4765, 315, 1846, ...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
2,409
Given a positive integer num consisting only of digits 6 and 9. Return the maximum number you can get by changing at most one digit (6 becomes 9, and 9 becomes 6).   Example 1: Input: num = 9669 Output: 9969 Explanation: Changing the first digit results in 6669. Changing the second digit results in 9969. Changing the ...
["class Solution:\n def maximum69Number (self, num: int) -> int:\n numString = str(num)\n numLength = len(numString)\n firstIndex = numString.find('6')\n if firstIndex == -1:\n return num\n else:\n return num+3*10**(numLength-firstIndex-1)", "class Solution:\n...
{"fn_name": "maximum69Number", "inputs": [[9669]], "outputs": [9969]}
introductory
https://leetcode.com/problems/maximum-69-number/
class Solution: def maximum69Number (self, num: int) -> int:
[ 22043, 264, 6785, 7546, 1629, 30606, 1172, 315, 18509, 220, 21, 323, 220, 24, 624, 5598, 279, 7192, 1372, 498, 646, 633, 553, 10018, 518, 1429, 825, 15723, 320, 21, 9044, 220, 24, 11, 323, 220, 24, 9044, 220, 21, 4292, 50950, 13314,...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
4,840
This Kata is the first in the [Rubiks Cube collection](https://www.codewars.com/collections/rubiks-party). [This](https://ruwix.com/the-rubiks-cube/notation/) or [this](https://ruwix.com/the-rubiks-cube/notation/advanced/) websites will be very usefull for this kata, if there will be some lack of understanding after t...
["f,g=lambda X:[list(x) for x in zip(*X[::-1])],lambda X:[list(x) for x in zip(*X)][::-1]\n\ndef ROTF(U,L,F,R,B,D):\n U[2],(L[0][2],L[1][2],L[2][2]),(R[0][0],R[1][0],R[2][0]),D[0]=([L[0][2],L[1][2],L[2][2]][::-1],list(D[0]),list(U[2]),[R[0][0],R[1][0],R[2][0]][::-1])\n return (U,L,f(F),R,B,D)\n \ndef ROTS(U,L,...
{"fn_name": "ROTF", "inputs": [], "outputs": []}
introductory
https://www.codewars.com/kata/5b3bec086be5d8893000002e
def ROTF(U,L,F,R,B,D):
[ 1986, 98838, 374, 279, 1156, 304, 279, 508, 65714, 67891, 42592, 4426, 9533, 2428, 1110, 2136, 41067, 365, 1561, 905, 2899, 3107, 7382, 392, 67891, 24031, 3593, 58, 1986, 9533, 2428, 1110, 2672, 86, 941, 905, 51257, 3795, 392, 67891, 17...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
1,313
The Little Elephant from the Zoo of Lviv has an array A that consists of N positive integers. Let A[i] be the i-th number in this array (i = 1, 2, ..., N). Find the minimal number x > 1 such that x is a divisor of all integers from array A. More formally, this x should satisfy the following relations: A[1] mod x = 0,...
["from math import sqrt,gcd\n\nfor _ in range(int(input())):\n n=int(input())\n ar=[int(x) for x in input().split()]\n g=ar[0]\n for i in range(1,n):\n g=gcd(g,ar[i])\n \n f=g\n for i in range(2,int(sqrt(g))+1):\n if g%i==0:\n f=i\n break\n if g!=1:\n p...
{"inputs": [["2", "3", "2 4 8", "3", "4 7 5", "", ""]], "outputs": [["2", "-1"]]}
interview
https://www.codechef.com/problems/LEDIV
[ 785, 14671, 78089, 504, 279, 40860, 315, 62205, 344, 702, 458, 1334, 362, 429, 17167, 315, 451, 6785, 25780, 13, 6771, 362, 989, 60, 387, 279, 600, 7563, 1372, 304, 419, 1334, 320, 72, 284, 220, 16, 11, 220, 17, 11, 60353, 451, 35...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
184
Given a string text, we are allowed to swap two of the characters in the string. Find the length of the longest substring with repeated characters.   Example 1: Input: text = "ababa" Output: 3 Explanation: We can swap the first 'b' with the last 'a', or the last 'b' with the first 'a'. Then, the longest repeated charac...
["class Solution:\n def maxRepOpt1(self, text: str) -> int:\n letters = {}\n for i, char in enumerate(text):\n if char in letters:\n letters[char].append(i)\n else:\n letters[char] = [i]\n \n if len(letters) == 1:\n return len...
{"fn_name": "maxRepOpt1", "inputs": [["\"ababa\""]], "outputs": [3]}
interview
https://leetcode.com/problems/swap-for-longest-repeated-character-substring/
class Solution: def maxRepOpt1(self, text: str) -> int:
[ 22043, 264, 914, 1467, 11, 582, 525, 5420, 311, 14291, 1378, 315, 279, 5766, 304, 279, 914, 13, 7379, 279, 3084, 315, 279, 22032, 38449, 448, 11504, 5766, 624, 50950, 13314, 220, 16, 510, 2505, 25, 1467, 284, 330, 370, 12004, 698, 5...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
139
We are given an array A of N lowercase letter strings, all of the same length. Now, we may choose any set of deletion indices, and for each string, we delete all the characters in those indices. For example, if we have an array A = ["abcdef","uvwxyz"] and deletion indices {0, 2, 3}, then the final array after deletions...
["class Solution:\n def minDeletionSize(self, A: List[str]) -> int:\n def isSorted(arr, i, j):\n return all(arr[k] <= arr[k+1] for k in range(i, j))\n ans = 0\n ranges = [[0, len(A)-1]]\n for col in zip(*A):\n if not ranges:\n break\n if all...
{"fn_name": "minDeletionSize", "inputs": [[["\"ca\"", "\"bb\"", "\"ac\""]]], "outputs": [1]}
interview
https://leetcode.com/problems/delete-columns-to-make-sorted-ii/
class Solution: def minDeletionSize(self, A: List[str]) -> int:
[ 1654, 525, 2661, 458, 1334, 4102, 32, 315, 451, 42047, 6524, 9069, 11, 678, 315, 279, 1852, 3084, 624, 7039, 11, 582, 1231, 5157, 894, 738, 315, 36066, 14937, 11, 323, 369, 1817, 914, 11, 582, 3698, 678, 279, 5766, 304, 1846, 14937,...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
101
Polycarp lives on the coordinate axis $Ox$ and travels from the point $x=a$ to $x=b$. It moves uniformly rectilinearly at a speed of one unit of distance per minute. On the axis $Ox$ at the point $x=c$ the base station of the mobile operator is placed. It is known that the radius of its coverage is $r$. Thus, if Polyc...
["import os\nfrom io import BytesIO\n\n# input = BytesIO(os.read(0, os.fstat(0).st_size)).readline\nfor i in range(int(input())):\n a, b, c, r = list(map(int, input().split()))\n a, b = min(a, b), max(a, b)\n left = max(c - r, a)\n right = min(c + r, b)\n if right >= a and left <= right:\n print(b...
{ "inputs": [ "9\n1 10 7 1\n3 3 3 0\n8 2 10 4\n8 2 10 100\n-10 20 -17 2\n-3 2 2 0\n-3 1 2 0\n2 3 2 3\n-1 3 -2 2\n" ], "outputs": [ "7\n0\n4\n0\n30\n5\n4\n0\n3\n" ] }
interview
https://codeforces.com/problemset/problem/1282/A
[ 14658, 3337, 7876, 6305, 389, 279, 16184, 8024, 400, 46, 87, 3, 323, 34192, 504, 279, 1459, 400, 87, 24239, 3, 311, 400, 87, 22086, 12947, 1084, 10797, 77809, 7608, 70933, 398, 518, 264, 4628, 315, 825, 4982, 315, 6010, 817, 9383, 3...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
2,739
Find the sum of the odd numbers within an array, after cubing the initial integers. The function should return `undefined`/`None`/`nil`/`NULL` if any of the values aren't numbers. ~~~if:java,csharp Note: There are ONLY integers in the JAVA and C# versions of this Kata. ~~~ ~~~if:python Note: Booleans should not be c...
["def cube_odd(arr):\n return sum( n**3 for n in arr if n % 2 ) if all(type(n) == int for n in arr) else None", "def cube_odd(arr):\n if any(type(x) is not int for x in arr):\n return None\n return sum(x ** 3 for x in arr if x % 2 != 0)", "def cube_odd(arr):\n if len(set(map(type,arr))) < 2:\n ...
{"fn_name": "cube_odd", "inputs": [[[1, 2, 3, 4]], [[-3, -2, 2, 3]], [["a", 12, 9, "z", 42]], [[true, false, 2, 4, 1]]], "outputs": [[28], [0], [null], [null]]}
introductory
https://www.codewars.com/kata/580dda86c40fa6c45f00028a
def cube_odd(arr):
[ 9885, 279, 2629, 315, 279, 10322, 5109, 2878, 458, 1334, 11, 1283, 18728, 287, 279, 2856, 25780, 13, 576, 729, 1265, 470, 1565, 9614, 63, 14, 63, 4064, 63, 14, 63, 8385, 63, 14, 63, 4576, 63, 421, 894, 315, 279, 2750, 7629, 944, ...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
3,583
Given an array of ones and zeroes, convert the equivalent binary value to an integer. Eg: `[0, 0, 0, 1]` is treated as `0001` which is the binary representation of `1`. Examples: ``` Testing: [0, 0, 0, 1] ==> 1 Testing: [0, 0, 1, 0] ==> 2 Testing: [0, 1, 0, 1] ==> 5 Testing: [1, 0, 0, 1] ==> 9 Testing: [0, 0, 1, 0] =...
["def binary_array_to_number(arr):\n return int(\"\".join(map(str, arr)), 2)", "def binary_array_to_number(arr):\n return int(''.join(str(a) for a in arr), 2)", "def binary_array_to_number(arr):\n s = 0\n for digit in arr:\n s = s * 2 + digit\n\n return s", "def binary_array_to_number(arr):\n ret...
{"fn_name": "binary_array_to_number", "inputs": [[[0, 0, 0, 1]], [[0, 0, 1, 0]], [[1, 1, 1, 1]], [[0, 1, 1, 0]]], "outputs": [[1], [2], [15], [6]]}
introductory
https://www.codewars.com/kata/578553c3a1b8d5c40300037c
def binary_array_to_number(arr):
[ 22043, 458, 1334, 315, 6174, 323, 97443, 11, 5508, 279, 13578, 7868, 897, 311, 458, 7546, 382, 36, 70, 25, 77644, 15, 11, 220, 15, 11, 220, 15, 11, 220, 16, 60, 63, 374, 11758, 438, 1565, 15, 15, 15, 16, 63, 892, 374, 279, 786...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
878
There is a big staircase with $N$ steps (numbered $1$ through $N$) in ChefLand. Let's denote the height of the top of step $i$ by $h_i$. Chef Ada is currently under the staircase at height $0$ and she wants to reach the top of the staircase (the top of the last step). However, she can only jump from height $h_i$ to the...
["# cook your dish here\n\nimport numpy as np\n \n\ndef minstairs(n,k):\n stairsHeight=[]\n stairs=0\n current = 0\n stairsHeight=list(map(int, input().split()))\n stairsHeight=np.array(stairsHeight)\n curr=0\n for i in range(n):\n if stairsHeight[i]-curr<=k:\n curr=stairsHeight[i]\n else:\n if (stairsHeight[i]-c...
{"inputs": [["1", "4 3", "2 4 8 16"]], "outputs": [["3"]]}
interview
https://www.codechef.com/problems/ADASTAIR
[ 3862, 374, 264, 2409, 61762, 448, 400, 45, 3, 7354, 320, 4082, 291, 400, 16, 3, 1526, 400, 45, 3, 8, 304, 35975, 41957, 13, 6771, 594, 78064, 279, 2608, 315, 279, 1909, 315, 3019, 400, 72, 3, 553, 400, 71, 5318, 12947, 35975, 51...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
602
Chef Loves to listen to remix songs, but currently he had already finished the entire playlist of remix songs. As Chef is smart, so he thought let's make my own remix songs of the original songs. Chef is not having much knowledge of making remix songs, so he came up with the simple technique in which he will pick the w...
["m= 9999999\r\nword=''\r\np= ''\r\ntry:\r\n s=input().split()\r\n for i in s:\r\n if(len(i) <= m):\r\n m = len(i)\r\n word = i\r\n p = word\r\n for i in s:\r\n p+= (' '+i+' '+ word)\r\n \r\n print(p)\r\n\r\n \r\nexcept E...
{"inputs": [["Mai Hu Jiyaan"]], "outputs": [["Hu Mai Hu Hu Hu Jiyaan Hu"]]}
interview
https://www.codechef.com/STRG2020/problems/REMIX
[ 93903, 84023, 311, 8844, 311, 56366, 11674, 11, 714, 5023, 566, 1030, 2669, 8060, 279, 4453, 26791, 315, 56366, 11674, 624, 2121, 35975, 374, 7785, 11, 773, 566, 3381, 1077, 594, 1281, 847, 1828, 56366, 11674, 315, 279, 4024, 11674, 624...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
3,960
Your task in this Kata is to emulate text justify right in monospace font. You will be given a single-lined text and the expected justification width. The longest word will never be greater than this width. Here are the rules: - Use spaces to fill in the gaps on the left side of the words. - Each line should contain ...
["import textwrap\n\ndef align_right(text,width):\n return \"\\n\".join([l.rjust(width, ' ') for l in textwrap.wrap(text, width)])", "def align_right(text, width):\n res = []\n line = []\n \n for word in text.split():\n if len(' '.join(line + [word])) <= width:\n line.append(word)\n ...
{"fn_name": "align_right", "inputs": [["abc def", 10], ["I take up the whole line", 24], ["Two lines, I am", 10]], "outputs": [[" abc def"], ["I take up the whole line"], ["Two lines,\n I am"]]}
introductory
https://www.codewars.com/kata/583601518d3b9b8d3b0000c9
def align_right(text, width):
[ 7771, 3383, 304, 419, 98838, 374, 311, 65485, 1467, 9357, 1290, 304, 1615, 80014, 3301, 13, 1446, 686, 387, 2661, 264, 3175, 88959, 1467, 323, 279, 3601, 41435, 2374, 13, 576, 22032, 3409, 686, 2581, 387, 7046, 1091, 419, 2374, 382, 8...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
1,403
Dhruvil has always been a studious person and will be completing his Engineering soon. He is always kneen about solving problems and is preparing hard for his next interview at Hackerrank. He has practiced lots of problems and now he came across this problem. Given a message containing English letters(A-Z), it is being...
["# cook your dish here\n# cook your dish here\ndef numDec(s):\n if not s:\n return 0\n\n dp = [0 for _ in range(len(s) + 1)]\n\n dp[0] = 1\n dp[1] = 0 if s[0] == '0' else 1\n\n\n for i in range(2, len(dp)):\n\n if s[i-1] != '0':\n dp[i] += dp[i-1]\n\n two_digit = int(s[i-2 : i])\n if two_digit >= 10 an...
{"inputs": [["2", "12", "226"]], "outputs": [["2", "3"]]}
interview
https://www.codechef.com/CEFT2020/problems/INTER
[ 35, 71, 2672, 45252, 702, 2677, 1012, 264, 1673, 1223, 1697, 323, 686, 387, 26568, 806, 16595, 5135, 13, 1260, 374, 2677, 13853, 268, 911, 21828, 5322, 323, 374, 20045, 2588, 369, 806, 1790, 7128, 518, 34982, 615, 1180, 13, 1260, 702,...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
857
Problem description. Dominic Toretto has taken his crew to compete in this years' Race Wars, a crew-on-crew tournament in which each member of one crew competes with a member of the other crew in a quarter mile drag race. Each win counts as one point for the winning crew. Draws and loses are awarded zero points. In the...
["testcases = int(input())\n\nfor i in range(testcases):\n n = int(input())\n my = list(map(int,input().split()))\n opp = list(map(int,input().split()))\n \n my.sort(reverse = True)\n opp.sort(reverse = True)\n \n j = 0\n k = 0\n while(k < n):\n if(my[j] > opp[k]):\n j += 1\n k += 1\n\n print(j)"]
{"inputs": [["1", "3", "5 4 1", "5 4 1"]], "outputs": [["2"]]}
interview
https://www.codechef.com/EXCT2015/problems/RACEWARS
[ 31198, 4008, 624, 71541, 292, 350, 18174, 983, 702, 4429, 806, 13627, 311, 20259, 304, 419, 1635, 6, 23659, 14968, 11, 264, 13627, 10326, 12, 38617, 16129, 304, 892, 1817, 4462, 315, 825, 13627, 4533, 288, 448, 264, 4462, 315, 279, 10...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
2,930
# Summation Write a program that finds the summation of every number from 1 to num. The number will always be a positive integer greater than 0. For example: ```if-not:racket ~~~ summation(2) -> 3 1 + 2 summation(8) -> 36 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 ~~~ ``` ```if:racket ~~~racket (summation 2) ; 3 (+ 1 2) (summat...
["def summation(num):\n return sum(range(num + 1))\n \n", "def summation(num):\n return (1+num) * num / 2", "def summation(num):\n return sum(range(1,num+1))\n \n", "def summation(num):\n return sum(range(num + 1))\n \n", "def summation(num):\n total = 0\n for i in range(0, num+1):\n t...
{"fn_name": "summation", "inputs": [[1], [8], [22], [100], [213]], "outputs": [[1], [36], [253], [5050], [22791]]}
introductory
https://www.codewars.com/kata/55d24f55d7dd296eb9000030
def summation(num):
[ 2, 8116, 76, 367, 271, 7985, 264, 2025, 429, 13719, 279, 34259, 367, 315, 1449, 1372, 504, 220, 16, 311, 1629, 13, 576, 1372, 686, 2677, 387, 264, 6785, 7546, 7046, 1091, 220, 15, 382, 2461, 3110, 510, 73594, 333, 29169, 67359, 5709...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
1,678
Chef has two integer sequences $A_1, A_2, \ldots, A_N$ and $B_1, B_2, \ldots, B_M$. You should choose $N+M-1$ pairs, each in the form $(A_x, B_y)$, such that the sums $A_x + B_y$ are all pairwise distinct. It is guaranteed that under the given constraints, a solution always exists. If there are multiple solutions, you ...
["# cook your dish here\nn,m = map(int, input().split())\narr1 = list(map(int, input().split()))\narr2 = list(map(int, input().split()))\nmax1 = arr1.index(max(arr1))\nmin2 = arr2.index(min(arr2))\narr = []\nfor i in range(m):\n arr.append([max1, i])\nfor i in range(n):\n if i!=max1:\n arr.append([i , min...
{"inputs": [["3 2", "10 1 100", "4 3", ""]], "outputs": [["2 1", "0 0", "1 0", "0 1"]]}
interview
https://www.codechef.com/problems/DPAIRS
[ 93903, 702, 1378, 7546, 23700, 400, 32, 62, 16, 11, 362, 62, 17, 11, 1124, 507, 2412, 11, 362, 1604, 3, 323, 400, 33, 62, 16, 11, 425, 62, 17, 11, 1124, 507, 2412, 11, 425, 1245, 12947, 1446, 1265, 5157, 400, 45, 10, 44, 12, ...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
1,925
Return the root node of a binary search tree that matches the given preorder traversal. (Recall that a binary search tree is a binary tree where for every node, any descendant of node.left has a value < node.val, and any descendant of node.right has a value > node.val.  Also recall that a preorder traversal displays th...
["# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def bstFromPreorder(self, preorder: List[int]) -> TreeNode:\n # time O(n); space O(n)\n ...
interview
https://leetcode.com/problems/construct-binary-search-tree-from-preorder-traversal/
# Definition for a binary tree node. class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right class Solution: def bstFromPreorder(self, preorder: List[int]) -> TreeNode:
[ 5598, 279, 3704, 2436, 315, 264, 7868, 2711, 4916, 429, 9071, 279, 2661, 71850, 56302, 624, 7, 3820, 541, 429, 264, 7868, 2711, 4916, 4102, 285, 264, 7868, 4916, 1380, 369, 1449, 2436, 11, 894, 75851, 315, 2436, 8272, 702, 264, 897, ...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
2,063
The "BerCorp" company has got n employees. These employees can use m approved official languages for the formal correspondence. The languages are numbered with integers from 1 to m. For each employee we have the list of languages, which he knows. This list could be empty, i. e. an employee may know no official language...
["rd = lambda: list(map(int, input().split()))\n\ndef root(x):\n if f[x]!=x: f[x] = root(f[x])\n return f[x]\n\nn, m = rd()\nN = list(range(n))\nf = list(N)\nlang = [0]*n\nfor i in N: lang[i] = set(rd()[1:])\nfor i in N:\n for j in N[:i]:\n rj = root(j)\n if lang[rj].intersection(lang[i]):\n f[rj] = i\n ...
{ "inputs": [ "5 5\n1 2\n2 2 3\n2 3 4\n2 4 5\n1 5\n", "8 7\n0\n3 1 2 3\n1 1\n2 5 4\n2 6 7\n1 3\n2 7 4\n1 1\n", "2 2\n1 2\n0\n", "2 2\n0\n0\n", "5 5\n1 3\n0\n0\n2 4 1\n0\n", "6 2\n0\n0\n2 1 2\n1 1\n1 1\n0\n", "7 3\n3 1 3 2\n3 2 1 3\n2 2 3\n1 1\n2 2 3\n3 3 2 1\n3 2 3 1\n", "8 4\n0\n0\n4 ...
competition
https://codeforces.com/problemset/problem/277/A
[ 785, 330, 38279, 94795, 1, 2813, 702, 2684, 308, 8256, 13, 4220, 8256, 646, 990, 296, 11792, 3946, 15459, 369, 279, 15908, 43718, 13, 576, 15459, 525, 48826, 448, 25780, 504, 220, 16, 311, 296, 13, 1752, 1817, 9364, 582, 614, 279, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1...
4,330
Mrs Jefferson is a great teacher. One of her strategies that helped her to reach astonishing results in the learning process is to have some fun with her students. At school, she wants to make an arrangement of her class to play a certain game with her pupils. For that, she needs to create the arrangement with **the mi...
["def shortest_arrang(n):\n # For odd n, we can always construct n with 2 consecutive integers.\n if n % 2 == 1:\n return [n//2 + 1, n//2]\n\n # For even n, n is the sum of either an odd number or even number of\n # consecutive positive integers. Moreover, this property is exclusive.\n\n for i in ...
{"fn_name": "shortest_arrang", "inputs": [[10], [14], [16], [22], [65]], "outputs": [[[4, 3, 2, 1]], [[5, 4, 3, 2]], [[-1]], [[7, 6, 5, 4]], [[33, 32]]]}
introductory
https://www.codewars.com/kata/59321f29a010d5aa80000066
def shortest_arrang(n):
[ 49229, 33544, 374, 264, 2244, 11079, 13, 3776, 315, 1059, 14830, 429, 8910, 1059, 311, 5545, 48913, 3059, 304, 279, 6832, 1882, 374, 311, 614, 1045, 2464, 448, 1059, 4143, 13, 2411, 2906, 11, 1340, 6801, 311, 1281, 458, 26112, 315, 10...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
603
----- Statement ----- You need to find a string which has exactly K positions in it such that the character at that position comes alphabetically later than the character immediately after it. If there are many such strings, print the one which has the shortest length. If there is still a tie, print the string which c...
["for i in range(int(input())):\n N = int(input())\n s = 'zyxwvutsrqponmlkjihgfedcba'\n r = ''\n while True:\n r = s[-N-1:] + r \n if N < 26:\n break\n N -= 25\n print(r)", "s='abcdefghijklmnopqrstuvwxyz'\nfor u in range(int(input())):\n n=int(input())\n r=''\n while(1):\n r=s[n::-1]+r\n if(n<26):\n break\n n...
{"inputs": [["2", "1", "2"]], "outputs": [["ba", "cba"]]}
interview
https://www.codechef.com/problems/DECSTR
[ 15081, 21756, 11304, 10452, 2610, 1184, 311, 1477, 264, 914, 892, 702, 6896, 730, 9892, 304, 432, 1741, 429, 279, 3668, 518, 429, 2309, 4041, 27790, 2673, 2937, 1091, 279, 3668, 7069, 1283, 432, 13, 1416, 1052, 525, 1657, 1741, 9069, ...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
2,688
# Task let F(N) be the sum square of digits of N. So: `F(1) = 1, F(3) = 9, F(123) = 14` Choose a number A, the sequence {A0, A1, ...} is defined as followed: ``` A0 = A A1 = F(A0) A2 = F(A1) ... ``` if A = 123, we have: ``` 123 → 14(1 x 1 + 2 x 2 + 3 x 3) → 17(1 x 1 + 4 x 4) → 50(1 ...
["from itertools import count\n\n# Couldn't find the pattern of why it's 1 or 8, I'm sad :(\ndef repeat_sequence_len(n):\n memo = {}\n for i in count():\n if n in memo: return i - memo[n]\n memo[n] = i\n n = sum(d*d for d in map(int, str(n)))", "def F(n):\n return sum(int(d)**2 for d in st...
{"fn_name": "repeat_sequence_len", "inputs": [[1], [85], [810], [812], [818], [833]], "outputs": [[1], [8], [8], [8], [1], [1]]}
introductory
https://www.codewars.com/kata/58a3f57ecebc06bfcb00009c
def repeat_sequence_len(n):
[ 2, 5430, 198, 1077, 434, 8204, 8, 387, 279, 2629, 9334, 315, 18509, 315, 451, 13, 2055, 510, 715, 1565, 37, 7, 16, 8, 284, 220, 16, 11, 434, 7, 18, 8, 284, 220, 24, 11, 434, 7, 16, 17, 18, 8, 284, 220, 16, 19, 19324, 22201...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
1,933
Given two strings representing two complex numbers. You need to return a string representing their multiplication. Note i2 = -1 according to the definition. Example 1: Input: "1+1i", "1+1i" Output: "0+2i" Explanation: (1 + i) * (1 + i) = 1 + i2 + 2 * i = 2i, and you need convert it to the form of 0+2i. Example ...
["class Solution:\n def complexNumberMultiply(self, a, b):\n \"\"\"\n :type a: str\n :type b: str\n :rtype: str\n \"\"\"\n a = a.split('+')\n b = b.split('+')\n a[1] = a[1][:-1]\n b[1] = b[1][:-1]\n a = list(map(int, a))\n b = l...
interview
https://leetcode.com/problems/complex-number-multiplication/
class Solution: def complexNumberMultiply(self, a: str, b: str) -> str:
[ 22043, 1378, 9069, 14064, 1378, 6351, 5109, 4192, 2610, 1184, 311, 470, 264, 914, 14064, 862, 46444, 13, 7036, 600, 17, 284, 481, 16, 4092, 311, 279, 7271, 4192, 13314, 220, 16, 1447, 2505, 25, 330, 16, 10, 16, 72, 497, 330, 16, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1...
977
Chef recently graduated Computer Science in university, so he was looking for a job. He applied for several job offers, but he eventually settled for a software engineering job at ShareChat. Chef was very enthusiastic about his new job and the first mission assigned to him was to implement a message encoding feature to...
["# cook your dish here\ntry:\n for _ in range(int(input())):\n n = int(input())\n li = [i for i in input()]\n a = 0\n while a+1<len(li):\n li[a],li[a+1] = li[a+1],li[a]\n a+=2\n li2 = li.copy()\n for i in li2:\n fh = 109\n sh = 110\n li.remove(i)\n if ord(i)>fh:\n li.append(chr(fh-(ord(i)-sh)))\n ...
{"inputs": [["2", "9", "sharechat", "4", "chef"]], "outputs": [["shizxvzsg", "sxuv"]]}
interview
https://www.codechef.com/problems/ENCMSG
[ 93903, 5926, 32009, 17407, 9965, 304, 12103, 11, 773, 566, 572, 3330, 369, 264, 2618, 13, 1260, 9251, 369, 3807, 2618, 6081, 11, 714, 566, 9583, 22378, 369, 264, 3162, 14667, 2618, 518, 11775, 15672, 13, 35975, 572, 1602, 41602, 911, ...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
1,297
Chef has just started Programming, he is in first year of Engineering. Chef is reading about Relational Operators. Relational Operators are operators which check relatioship between two values. Given two numerical values A and B you need to help chef in finding the relationship between them that is, - First one is ...
["# cook your dish here\nfor _ in range(int(input())):\n x, y= map(int, input().split())\n if x<y:\n print('<')\n elif x>y:\n print('>')\n else:\n print('=')", "t=int(input())\nfor i in range(t):\n a,b=list(map(int,input().split()))\n if a>b:\n print(\">\")\n elif b>a:\n...
{"inputs": [["3", "10 20", "20 10", "10 10"]], "outputs": [["<", ">", "="]]}
interview
https://www.codechef.com/problems/CHOPRT
[ 93903, 702, 1101, 3855, 38424, 11, 566, 374, 304, 1156, 1042, 315, 16595, 13, 35975, 374, 5290, 911, 6512, 1663, 64420, 13, 4710, 6740, 1663, 64420, 525, 19624, 892, 1779, 90803, 3530, 2151, 1948, 1378, 2750, 13, 16246, 1378, 34776, 275...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
909
-----Problem Statement----- A classroom has several students, half of whom are boys and half of whom are girls. You need to arrange all of them in a line for the morning assembly such that the following conditions are satisfied: - The students must be in order of non-decreasing height. - Two boys or two girls must not ...
["for u in range(int(input())):\n n=int(input())\n l=list(map(int,input().split()))\n d=list(map(int,input().split()))\n ka=[]\n k=[]\n l.sort()\n d.sort()\n for i in range(n):\n ka.append(d[i])\n ka.append(l[i])\n for i in range(n):\n k.append(l[i])\n k.append(d[i...
{"inputs": [["1", "2", "1 3", "2 4"]], "outputs": [["YES"]]}
interview
https://www.codechef.com/SCAT2020/problems/SC_02
[ 15081, 31198, 21756, 34764, 32, 24017, 702, 3807, 4143, 11, 4279, 315, 8711, 525, 13007, 323, 4279, 315, 8711, 525, 7571, 13, 1446, 1184, 311, 30893, 678, 315, 1105, 304, 264, 1555, 369, 279, 6556, 14614, 1741, 429, 279, 2701, 4682, 5...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
953
Chef has $N$ doggo (dogs) , Lets number them $1$ to $N$. Chef decided to build houses for each, but he soon realizes that keeping so many dogs at one place may be messy. So he decided to divide them into several groups called doggo communities. Let the total no. of groups be $K$ . In a community, paths between pairs ...
["# cook your dish here\nimport sys\ndef get_array(): return list(map(int , sys.stdin.readline().strip().split()))\ndef get_ints(): return list(map(int, sys.stdin.readline().strip().split()))\ndef input(): return sys.stdin.readline().strip()\nimport math\nfrom collections import defaultdict\nfrom itertools import combi...
{"inputs": [["1", "4"]], "outputs": [["2"]]}
interview
https://www.codechef.com/STR2020/problems/DOGGO
[ 93903, 702, 220, 400, 45, 3, 5562, 3346, 320, 80034, 8, 1154, 57066, 1372, 1105, 400, 16, 3, 311, 400, 45, 3, 382, 93903, 6635, 311, 1936, 14967, 369, 1817, 11, 714, 566, 5135, 51594, 429, 10282, 773, 1657, 12590, 518, 825, 1992, ...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
1,386
-----Problem description----- As a holiday gift, Tojo received a probability problem. The problem read as follows Consider an N by M grid. Rows are numbered 1 to N, from top to bottom. Columns are numbered 1 to M, from left to right. You are initially at cell (1, 1) and want to go to cell (N, M). From any cell you can ...
["from math import factorial\n\nfor _ in range(int(input())):\n N,M=[int(a) for a in input().split()]\n print(float(N+M-1))", "for _ in range(int(input())):\n n ,m = map(int,input().split())\n if n==1 or m==1:\n print(max(n,m))\n else:\n print(n+m-1)", "for i in range(int(input())):\n a,b = list(map(int, input().spli...
{"inputs": [["2", "2 2", "1 6"]], "outputs": [["3.000000", "6.000000"]]}
interview
https://www.codechef.com/problems/ANUTHM
[ 15081, 31198, 4008, 34764, 2121, 264, 13257, 8189, 11, 2014, 7305, 3949, 264, 18927, 3491, 13, 576, 3491, 1349, 438, 11017, 198, 37175, 458, 451, 553, 386, 5827, 13, 61706, 525, 48826, 220, 16, 311, 451, 11, 504, 1909, 311, 5622, 13, ...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
2,862
```if:python Note: Python may currently have some performance issues. If you find them, please let me know and provide suggestions to improve the Python version! It's my weakest language... any help is much appreciated :) ``` Artlessly stolen and adapted from Hackerrank. Kara Danvers is new to CodeWars, and eager to...
["def leaderboard_climb(arr, kara):\n scores = sorted(set(arr), reverse=True)\n position = len(scores)\n ranks = []\n \n for checkpoint in kara:\n while position >= 1 and checkpoint >= scores[position - 1]:\n position -= 1\n ranks.append(position + 1) \n \n return ranks"...
{"fn_name": "leaderboard_climb", "inputs": [[[100, 90, 90, 80], [70, 80, 105]], [[982, 490, 339, 180], [180, 250, 721, 2500]], [[1982, 490, 339, 180], [180, 250, 721, 880]], [[1079, 490, 339, 180], [180, 250, 1200, 1980]]], "outputs": [[[4, 3, 1]], [[4, 4, 2, 1]], [[4, 4, 2, 2]], [[4, 4, 1, 1]]]}
introductory
https://www.codewars.com/kata/5b19f34c7664aacf020000ec
def leaderboard_climb(arr, kara):
[ 73594, 333, 25, 12669, 715, 9112, 25, 13027, 1231, 5023, 614, 1045, 5068, 4714, 13, 1416, 498, 1477, 1105, 11, 4486, 1077, 752, 1414, 323, 3410, 18225, 311, 7269, 279, 13027, 2319, 0, 1084, 594, 847, 80763, 4128, 1112, 894, 1492, 374,...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
4,126
# 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 volunteer programmers to write some code that tell the time by only...
["def what_time_is_it(angle):\n hr = int(angle // 30)\n mn = int((angle % 30) * 2)\n if hr == 0:\n hr = 12\n return '{:02d}:{:02d}'.format(hr, mn)", "def what_time_is_it(angle):\n angle %= 360\n h, m = divmod(angle, 30)\n return '{:02}:{:02}'.format(int(h or 12), int(m * 2))", "import time\n...
{"fn_name": "what_time_is_it", "inputs": [[0], [360], [90], [180], [270], [30], [40], [45], [50], [60]], "outputs": [["12:00"], ["12:00"], ["03:00"], ["06:00"], ["09:00"], ["01:00"], ["01:20"], ["01:30"], ["01:40"], ["02:00"]]}
introductory
https://www.codewars.com/kata/59752e1f064d1261cb0000ec
def what_time_is_it(angle):
[ 2, 15106, 271, 33060, 311, 6853, 315, 13404, 279, 9383, 24413, 702, 20866, 1007, 13971, 10926, 8866, 3579, 382, 3036, 1576, 279, 2205, 14833, 702, 5558, 1429, 315, 1039, 3742, 3220, 311, 264, 54333, 2551, 34626, 1052, 525, 902, 10514, 3...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
2,928
# Introduction There is a war and nobody knows - the alphabet war! There are two groups of hostile letters. The tension between left side letters and right side letters was too high and the war began. # Task Write a function that accepts `fight` string consists of only small letters and return who wins the fight. ...
["def alphabet_war(fight):\n d = {'w':4,'p':3,'b':2,'s':1,\n 'm':-4,'q':-3,'d':-2,'z':-1}\n r = sum(d[c] for c in fight if c in d)\n \n return {r==0:\"Let's fight again!\",\n r>0:\"Left side wins!\",\n r<0:\"Right side wins!\"\n }[True]", "def alphabet_war(fight):\n ...
{"fn_name": "alphabet_war", "inputs": [["z"], ["zdqmwpbs"], ["wq"], ["zzzzs"], ["wwwwww"]], "outputs": [["Right side wins!"], ["Let's fight again!"], ["Left side wins!"], ["Right side wins!"], ["Left side wins!"]]}
introductory
https://www.codewars.com/kata/59377c53e66267c8f6000027
def alphabet_war(fight):
[ 2, 28338, 271, 3862, 374, 264, 4116, 323, 18581, 8788, 481, 279, 27790, 4116, 0, 2303, 3862, 525, 1378, 5203, 315, 32515, 11931, 13, 576, 23504, 1948, 2115, 3108, 11931, 323, 1290, 3108, 11931, 572, 2238, 1550, 323, 279, 4116, 6009, 3...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
4,958
Complete the solution so that it returns a formatted string. The return value should equal "Value is VALUE" where value is a 5 digit padded number. Example: ```python solution(5) # should return "Value is 00005" ```
["def solution(value):\n return \"Value is %05d\" % value", "solution='Value is {:05d}'.format\n \n", "def solution(value):\n num = 5 - len(str(value))\n zeros = \"\"\n for i in range(num):\n zeros += \"0\"\n return(\"Value is {}\".format(zeros + str(value)))\n", "def solution(value):\n retu...
{"fn_name": "solution", "inputs": [], "outputs": []}
introductory
https://www.codewars.com/kata/51c89385ee245d7ddf000001
def solution(value):
[ 12548, 279, 6291, 773, 429, 432, 4675, 264, 23126, 914, 13, 576, 470, 897, 1265, 6144, 330, 1130, 374, 26827, 1, 220, 1380, 897, 374, 264, 220, 20, 15723, 43868, 1372, 13, 4710, 13314, 1447, 73594, 12669, 198, 49460, 7, 20, 8, 220, ...
[ 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, 1, 1 ]
1,267
Chef likes problems related to learning new languages. He only knows first N letters of English alphabet. Also he explores all M-letter words formed by the characters he knows. Define cost for a given M-letter word S, cost(S) = P1, S1+P2, S2+...+PM, SM, where Pi, j is i, jth entry of matrix P. Sort all the words by des...
["def dfs(ind,m,n,k):\n if(ind == m):\n return [\"\"]\n else:\n temp = dfs(ind+1,m,n,k)\n ans = []\n if(len(temp)<k):\n for i in temp:\n for j in range(97,97+n):\n ans += [chr(j)+i]\n else:\n for i in temp:\n ans += [\"z\"+i]\n return ans\nn,m,k = list(map(int,input().split()))\np = []\nmr= []\nfor _...
{"inputs": [["2 5 17", "7 9", "13 18", "10 12", "4 18", "3 9"]], "outputs": [["aaaba"]]}
interview
https://www.codechef.com/LTIME40/problems/LTM40EF
[ 93903, 13151, 5322, 5435, 311, 6832, 501, 15459, 13, 1260, 1172, 8788, 1156, 451, 11931, 315, 6364, 27790, 13, 7281, 566, 40324, 678, 386, 79368, 4244, 14122, 553, 279, 5766, 566, 8788, 13, 18614, 2783, 369, 264, 2661, 386, 79368, 3409,...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
3,268
You're given a string containing a sequence of words separated with whitespaces. Let's say it is a sequence of patterns: a name and a corresponding number - like this: ```"red 1 yellow 2 black 3 white 4"``` You want to turn it into a different **string** of objects you plan to work with later on - like this: ```"[{n...
["import re\n\ndef words_to_object(s):\n return \"[\" + re.sub(\"([^ ]+) ([^ ]+)\", r\"{name : '\\1', id : '\\2'},\", s).strip(',') + \"]\"", "def words_to_object(s):\n return '[' + ', '.join(\"{name : '%s', id : '%s'}\" % (n, i) for n, i in zip(s.split()[::2], s.split()[1::2])) + ']'", "def words_to_object(s):\n...
{"fn_name": "words_to_object", "inputs": [["red 1 yellow 2 black 3 white 4"], ["1 red 2 white 3 violet 4 green"], ["1 1 2 2 3 3 4 4"], ["#@&fhds 123F3f 2vn2# 2%y6D @%fd3 @!#4fs W@R^g WE56h%"], [""]], "outputs": [["[{name : 'red', id : '1'}, {name : 'yellow', id : '2'}, {name : 'black', id : '3'}, {name : 'white', id : ...
introductory
https://www.codewars.com/kata/5877786688976801ad000100
def words_to_object(s):
[ 2610, 2299, 2661, 264, 914, 8482, 264, 8500, 315, 4244, 18663, 448, 21874, 27338, 13, 6771, 594, 1977, 432, 374, 264, 8500, 315, 12624, 25, 264, 829, 323, 264, 12159, 1372, 481, 1075, 419, 1447, 73594, 1, 1151, 220, 16, 13753, 220, ...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
4,441
Lot of junior developer can be stuck when they need to change the access permission to a file or a directory in an Unix-like operating systems. To do that they can use the `chmod` command and with some magic trick they can change the permissionof a file or a directory. For more information about the `chmod` command yo...
["def chmod_calculator(perm):\n perms = { \"r\": 4, \"w\": 2, \"x\": 1 }\n value = \"\"\n for permission in [\"user\", \"group\", \"other\"]:\n value += str(sum(perms.get(x, 0) for x in perm.get(permission, \"\")))\n \n return value", "def chmod_calculator(perm): \n return str(sum([wbin(...
{"fn_name": "chmod_calculator", "inputs": [[{"user": "rwx", "group": "r-x", "other": "r-x"}], [{"user": "rwx", "group": "r--", "other": "r--"}], [{"user": "r-x", "group": "r-x", "other": "---"}], [{"group": "rwx"}], [{}]], "outputs": [["755"], ["744"], ["550"], ["070"], ["000"]]}
introductory
https://www.codewars.com/kata/57f4ccf0ab9a91c3d5000054
def chmod_calculator(perm):
[ 54666, 315, 26052, 15754, 646, 387, 15700, 979, 807, 1184, 311, 2297, 279, 2615, 7882, 311, 264, 1034, 476, 264, 6220, 304, 458, 46995, 12681, 10350, 5942, 382, 1249, 653, 429, 807, 646, 990, 279, 1565, 56274, 63, 3210, 323, 448, 1045...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
3,388
Write a function that takes in a binary string and returns the equivalent decoded text (the text is ASCII encoded). Each 8 bits on the binary string represent 1 character on the ASCII table. The input string will always be a valid binary string. Characters can be in the range from "00000000" to "11111111" (inclusive...
["def binary_to_string(binary):\n return \"\".join( [ chr( int(binary[i: i+8], 2) ) for i in range(0, len(binary), 8) ] )", "def binary_to_string(binary):\n return \"\".join(chr(int(binary[i:i+8],2)) for i in range(0,len(binary),8))\n", "def binary_to_string(binary):\n result = \"\"\n \n while binary:\n ...
{"fn_name": "binary_to_string", "inputs": [[""], ["0100100001100101011011000110110001101111"], ["00110001001100000011000100110001"], ["01010011011100000110000101110010011010110111001100100000011001100110110001100101011101110010111000101110001000000110010101101101011011110111010001101001011011110110111001110011001000000...
introductory
https://www.codewars.com/kata/5583d268479559400d000064
def binary_to_string(binary):
[ 7985, 264, 729, 429, 4990, 304, 264, 7868, 914, 323, 4675, 279, 13578, 29213, 1467, 320, 1782, 1467, 374, 39316, 20498, 3593, 4854, 220, 23, 9472, 389, 279, 7868, 914, 4009, 220, 16, 3668, 389, 279, 39316, 1965, 382, 785, 1946, 914, ...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
164
Given a string num representing the digits of a very large integer and an integer k. You are allowed to swap any two adjacent digits of the integer at most k times. Return the minimum integer you can obtain also as a string.   Example 1: Input: num = "4321", k = 4 Output: "1342" Explanation: The steps to obtain the mi...
["class Solution:\n def minInteger(self, num: str, k: int) -> str:\n n=len(num)\n if k<=0:\n return num\n \n if k>n*(n-1)//2:\n return ''.join(sorted(list(num)))\n \n for i in range(10):\n idx = num.find(str(i))\n if idx>=0 and idx...
{"fn_name": "minInteger", "inputs": [["\"4321\"", 4]], "outputs": ["1\"432\""]}
interview
https://leetcode.com/problems/minimum-possible-integer-after-at-most-k-adjacent-swaps-on-digits/
class Solution: def minInteger(self, num: str, k: int) -> str:
[ 22043, 264, 914, 1629, 14064, 279, 18509, 315, 4102, 64, 1602, 3460, 7546, 323, 458, 7546, 595, 624, 2610, 525, 5420, 311, 14291, 894, 1378, 23942, 18509, 315, 279, 7546, 518, 1429, 595, 3039, 624, 5598, 279, 8028, 7546, 498, 646, 685...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
2,030
A group of n cities is connected by a network of roads. There is an undirected road between every pair of cities, so there are $\frac{n \cdot(n - 1)}{2}$ roads in total. It takes exactly y seconds to traverse any single road. A spanning tree is a set of roads containing exactly n - 1 roads such that it's possible to t...
["from collections import defaultdict\nfrom collections import deque\nfrom functools import reduce\nn, x, y = [int(x) for x in input().split()]\nE = defaultdict(set)\nfor i in range(n-1):\n u, v = [int(x) for x in input().split()]\n E[u].add(v)\n E[v].add(u)\n\nif x > y:\n for v in E:\n if len(E[v]) ...
{ "inputs": [ "5 2 3\n1 2\n1 3\n3 4\n5 3\n", "5 3 2\n1 2\n1 3\n3 4\n5 3\n", "50 23129 410924\n18 28\n17 23\n21 15\n18 50\n50 11\n32 3\n44 41\n50 31\n50 34\n5 14\n36 13\n22 40\n20 9\n9 43\n19 47\n48 40\n20 22\n33 45\n35 22\n33 24\n9 6\n13 1\n13 24\n49 20\n1 20\n29 38\n10 35\n25 23\n49 30\n42 8\n20 18\n32 1...
competition
https://codeforces.com/problemset/problem/618/D
[ 32, 1874, 315, 308, 9720, 374, 8433, 553, 264, 3922, 315, 19241, 13, 2619, 374, 458, 2030, 74612, 5636, 1948, 1449, 6716, 315, 9720, 11, 773, 1052, 525, 57960, 37018, 91362, 1124, 50853, 1445, 481, 220, 16, 9139, 90, 17, 31716, 19241,...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
3,619
In this kata, we want to discover a small property of numbers. We say that a number is a **dd** number if it contains d occurences of a digit d, (d is in [1,9]). ## Examples * 664444309 is a **dd** number, as it contains 4 occurences of the number 4 * 30313, 122 are **dd** numbers as they respectively contain 3 occu...
["from collections import Counter\n\n\ndef is_dd(n):\n return any(value==count for value, count in Counter(int(x) for x in str(n)).items())", "from collections import Counter\n\ndef is_dd(n):\n return any(int(k) == v for k, v in Counter(str(n)).items())", "def is_dd(n):\n for i in range(1, 10):\n if str...
{"fn_name": "is_dd", "inputs": [[664444309], [122], [30313], [5023011], [9081231]], "outputs": [[true], [true], [true], [false], [false]]}
introductory
https://www.codewars.com/kata/5a40fc7ce1ce0e34440000a3
def is_dd(n):
[ 641, 419, 61688, 11, 582, 1366, 311, 6997, 264, 2613, 3343, 315, 5109, 13, 715, 1654, 1977, 429, 264, 1372, 374, 264, 3070, 631, 334, 1372, 421, 432, 5610, 294, 2983, 552, 98162, 315, 264, 15723, 294, 11, 320, 67, 374, 304, 508, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1...
4,502
Well met with Fibonacci bigger brother, AKA Tribonacci. As the name may already reveal, it works basically like a Fibonacci, but summing the last 3 (instead of 2) numbers of the sequence to generate the next. And, worse part of it, regrettably I won't get to hear non-native Italian speakers trying to pronounce it :( ...
["def tribonacci(signature, n):\n res = signature[:n]\n for i in range(n - 3): res.append(sum(res[-3:]))\n return res", "def tribonacci(signature,n):\n while len(signature) < n:\n signature.append(sum(signature[-3:]))\n \n return signature[:n]", "def tribonacci(signature, n):\n s = signature.copy(...
{"fn_name": "tribonacci", "inputs": [[[1, 1, 1], 10], [[0, 0, 1], 10], [[0, 1, 1], 10], [[1, 0, 0], 10], [[0, 0, 0], 10], [[1, 2, 3], 10], [[3, 2, 1], 10], [[1, 1, 1], 1], [[300, 200, 100], 0], [[0.5, 0.5, 0.5], 30]], "outputs": [[[1, 1, 1, 3, 5, 9, 17, 31, 57, 105]], [[0, 0, 1, 1, 2, 4, 7, 13, 24, 44]], [[0, 1, 1, 2, ...
introductory
https://www.codewars.com/kata/556deca17c58da83c00002db
def tribonacci(signature,n):
[ 11395, 2270, 448, 79683, 11243, 10641, 11, 362, 26444, 20523, 39345, 382, 2121, 279, 829, 1231, 2669, 16400, 11, 432, 4278, 13221, 1075, 264, 79683, 11, 714, 2629, 5311, 279, 1537, 220, 18, 320, 64837, 315, 220, 17, 8, 5109, 315, 279,...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
2,523
Given a non-empty array of non-negative integers nums, the degree of this array is defined as the maximum frequency of any one of its elements. Your task is to find the smallest possible length of a (contiguous) subarray of nums, that has the same degree as nums. Example 1: Input: [1, 2, 2, 3, 1] Output: 2 Explanatio...
["class Solution:\n def findShortestSubArray(self, nums):\n \n diction = {}\n \n for i in nums:\n if i not in diction:\n diction[i] = 1\n else:\n diction[i] += 1\n \n degree = max(list(diction.values()))\n ...
{"fn_name": "findShortestSubArray", "inputs": [[[1, 2, 2, 3, 1]]], "outputs": [2]}
introductory
https://leetcode.com/problems/degree-of-an-array/
class Solution: def findShortestSubArray(self, nums: List[int]) -> int:
[ 22043, 264, 2477, 39433, 1334, 315, 2477, 60935, 25780, 10307, 11, 279, 8381, 315, 419, 1334, 374, 4512, 438, 279, 7192, 11639, 315, 894, 825, 315, 1181, 5424, 624, 7771, 3383, 374, 311, 1477, 279, 24632, 3204, 3084, 315, 264, 320, 77...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...
1,588
Lucy had recently learned the game, called Natural Numbers. The rules of the game are really simple. There are N players. At the same time, every player says one natural number. Let's call the number said by the i-th player Ai. The person with the smallest unique number (that is, the smallest number that was not said b...
["try:\n t = int(input())\n while t:\n t -= 1\n n = int(input())\n arr = []\n obj = {}\n for i in range(n):\n x,y = input().split()\n y = int(y)\n arr.append([x, y])\n if y in obj: obj[y].append(x)\n else: obj[y] = [x]\n ...
{"inputs": [["2", "5", "Kouta 1", "Yuka 1", "Mayu 3", "Lucy 2", "Nana 5", "2", "Lucy 2", "Nana 2", "", ""]], "outputs": [["Lucy", "Nobody wins."]]}
interview
https://www.codechef.com/problems/NUMBERS
[ 40645, 88, 1030, 5926, 9498, 279, 1809, 11, 2598, 18448, 34713, 624, 785, 5601, 315, 279, 1809, 525, 2167, 4285, 13, 2619, 525, 451, 4217, 13, 2411, 279, 1852, 882, 11, 1449, 2781, 2727, 825, 5810, 1372, 13, 6771, 594, 1618, 279, 13...
[ 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, 1, 1, 1, 1, 1, 1, 1, 1, 1...