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,629 | You have been speeding on a motorway and a police car had to stop you. The policeman is a funny guy that likes to play games. Before issuing penalty charge notice he gives you a choice to change your penalty.
Your penalty charge is a combination of numbers like: speed of your car, speed limit in the area, speed of th... | ["def penalty(lst):\n lst, maxLen = list(map(str, lst)), max(map(len, lst))\n return ''.join(sorted(lst, key=lambda s: s.ljust(maxLen, s[-1])))", "#return str of the smallest value of the combined numbers in a_list\ndef penalty(a_list):\n return ''.join(sorted(a_list, key = lambda n: n + n[:1]))", "penalty=lambd... | {"fn_name": "penalty", "inputs": [[["45", "30", "50", "1"]], [["100", "10", "1"]], [["32", "3"]], [["70", "46", "4", "19"]], [["71", "82", "42", "34", "90"]], [["31", "97", "6", "78"]], [["72", "7", "7", "78", "79", "709", "94"]]], "outputs": [["1304550"], ["100101"], ["323"], ["1944670"], ["3442718290"], ["3167897"], ... | introductory | https://www.codewars.com/kata/5a05a4d206d5b61ba70000f9 |
def penalty(a_list):
| [
2610,
614,
1012,
57575,
389,
264,
8872,
3117,
323,
264,
4282,
1803,
1030,
311,
2936,
498,
13,
576,
78580,
374,
264,
15173,
7412,
429,
13151,
311,
1486,
3868,
13,
13235,
42121,
16346,
6757,
5293,
566,
6696,
498,
264,
5754,
311,
2297,
6... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,778 | A faro shuffle of a deck of playing cards is a shuffle in which the deck is split exactly in half and then the cards in the two halves are perfectly interwoven, such that the original bottom card is still on the bottom and the original top card is still on top.
For example, faro shuffling the list
```python
['ace', 't... | ["def faro_cycles(n):\n x, cnt = 2, 1\n while x != 1 and n > 3:\n cnt += 1\n x = x*2 % (n-1)\n return cnt", "def faro_cycles(deck_size):\n arr, count = list(range(deck_size)), 0\n original_arr = arr\n while True:\n arr = arr[0:deck_size:2] + arr[1:deck_size:2]\n count += 1\... | {"fn_name": "faro_cycles", "inputs": [[2], [52], [542], [1250], [1954]], "outputs": [[1], [8], [540], [156], [30]]} | introductory | https://www.codewars.com/kata/57bc802c615f0ba1e3000029 |
def faro_cycles(deck_size):
| [
32,
3041,
78,
25947,
315,
264,
9530,
315,
5619,
7411,
374,
264,
25947,
304,
892,
279,
9530,
374,
6718,
6896,
304,
4279,
323,
1221,
279,
7411,
304,
279,
1378,
74112,
525,
13942,
946,
86,
16253,
11,
1741,
429,
279,
4024,
5622,
3701,
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... |
105 | — Hey folks, how do you like this problem?
— That'll do it.
BThero is a powerful magician. He has got $n$ piles of candies, the $i$-th pile initially contains $a_i$ candies. BThero can cast a copy-paste spell as follows: He chooses two piles $(i, j)$ such that $1 \le i, j \le n$ and $i \ne j$. All candies from pi... | ["import math\nt = int(input())\nfor test in range(t):\n n,k = map(int,input().split())\n A = list(map(int,input().split()))\n A.sort()\n ans = 0\n for i in range(1,n):\n if(A[i]>k):\n ans = 0\n break\n rem = k-A[i]\n ans+=rem//A[0]\n print(ans)", "t = int(in... | {
"inputs": [
"3\n2 2\n1 1\n3 5\n1 2 3\n3 7\n3 2 2\n"
],
"outputs": [
"1\n5\n4\n"
]
} | interview | https://codeforces.com/problemset/problem/1417/A | [
2293,
27553,
15327,
11,
1246,
653,
498,
1075,
419,
3491,
1939,
2293,
2938,
3278,
653,
432,
13,
4710,
33,
1001,
2328,
374,
264,
7988,
89341,
13,
1260,
702,
2684,
400,
77,
3,
58772,
315,
97397,
11,
279,
400,
72,
3,
12,
339,
26306,
1... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,314 | For an array $b$ of length $m$ we define the function $f$ as $ f(b) = \begin{cases} b[1] & \quad \text{if } m = 1 \\ f(b[1] \oplus b[2],b[2] \oplus b[3],\dots,b[m-1] \oplus b[m]) & \quad \text{otherwise,} \end{cases} $
where $\oplus$ is bitwise exclusive OR.
For example, $f(1,2,4,8)=f(1\oplus2,2\oplus4,4\oplus8)=f(... | ["n = int(input())\n*a, = map(int, input().split())\ndp = [[0 for i in range(n + 1)] for j in range(n + 1)]\nfor i in range(n):\n dp[0][i] = a[i]\nfor i in range(1, n):\n for j in range(n - i + 1):\n dp[i][j] = dp[i - 1][j] ^ dp[i - 1][j + 1]\nfor i in range(1, n):\n for j in range(n - i):\n dp[i... | {
"inputs": [
"3\n8 4 1\n2\n2 3\n1 2\n",
"6\n1 2 4 8 16 32\n4\n1 6\n2 5\n3 4\n1 2\n"
],
"outputs": [
"5\n12\n",
"60\n30\n12\n3\n"
]
} | competition | https://codeforces.com/problemset/problem/983/B | [
2461,
458,
1334,
400,
65,
3,
315,
3084,
400,
76,
3,
582,
6979,
279,
729,
400,
69,
3,
438,
220,
400,
282,
1883,
8,
284,
1124,
7265,
90,
23910,
92,
293,
58,
16,
60,
609,
1124,
31610,
1124,
1318,
90,
333,
335,
296,
284,
220,
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... | |
4,538 | You are going to be given a string. Your job is to return that string in a certain order that I will explain below:
Let's say you start with this: `012345`
The first thing you do is reverse it:`543210`
Then you will take the string from the 1st position and reverse it again:`501234`
Then you will take the string ... | ["def reverse_fun(n):\n for i in range(len(n)):\n n = n[:i] + n[i:][::-1]\n return n", "def reverse_fun(n):\n l = len(n)\n return ''.join(b+a for a,b in zip(list(n[:l//2])+[''], n[l//2:][::-1]))", "def reverse_fun(n):\n n = n[::-1]\n for i in range(1, len(n)):\n n = n[:i] + n[i:][::-1]\n... | {"fn_name": "reverse_fun", "inputs": [["012"], ["012345"], ["0123456789"], ["Hello"]], "outputs": [["201"], ["504132"], ["9081726354"], ["oHlel"]]} | introductory | https://www.codewars.com/kata/566efcfbf521a3cfd2000056 |
def reverse_fun(n):
| [
2610,
525,
2087,
311,
387,
2661,
264,
914,
13,
4615,
2618,
374,
311,
470,
429,
914,
304,
264,
3654,
1973,
429,
358,
686,
10339,
3685,
1447,
10061,
594,
1977,
498,
1191,
448,
419,
25,
1565,
15,
16,
17,
18,
19,
20,
19324,
785,
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... |
978 | Chuck Norris just created a universe. He has already started the space-time continuum. Now he needs to fill the universe with matter and antimatter for the avatar cycle to start.
He created $N$ distinct pairs of elementary matter and their corresponding antimatter particles. Annihilations happen only when a matter part... | ["for i in range(int(input())):\n n=int(input())\n if(n<=2 or n>1000000007):\n print(\"0\")\n else:\n prod=1\n for i in range(2,n):\n prod*=i\n if(prod>1000000007):\n prod=prod%1000000007\n print(((prod)*(n*prod-2))%1000000007)\n", "import math\nfor i in range(int(input())):\n n=int(input())\n if(n<=2 or n>1... | {"inputs": [["1", "3", "Sample output :", "8"]], "outputs": [[]]} | interview | https://www.codechef.com/PROC2020/problems/VC711 | [
93526,
70765,
1101,
3465,
264,
15494,
13,
1260,
702,
2669,
3855,
279,
3550,
7246,
85801,
13,
4695,
566,
3880,
311,
5155,
279,
15494,
448,
4925,
323,
78212,
1650,
369,
279,
20701,
10775,
311,
1191,
624,
1519,
3465,
400,
45,
3,
12460,
1... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,435 | Similarly to the [previous kata](https://www.codewars.com/kata/string-subpattern-recognition-i/), you will need to return a boolean value if the base string can be expressed as the repetition of one subpattern.
This time there are two small changes:
* if a subpattern has been used, it will be repeated at least twice,... | ["from collections import Counter\nfrom functools import reduce\nfrom math import gcd\n\ndef has_subpattern(string):\n return reduce(gcd, Counter(string).values()) != 1", "from collections import Counter\nfrom functools import reduce\nfrom math import gcd\n\ndef has_subpattern(s):\n return reduce(gcd, Counter(s).... | {"fn_name": "has_subpattern", "inputs": [["a"], ["aaaa"], ["abcd"], ["babababababababa"], ["ababababa"], ["123a123a123a"], ["123A123a123a"], ["12aa13a21233"], ["12aa13a21233A"], ["abcdabcaccd"]], "outputs": [[false], [true], [false], [true], [false], [true], [false], [true], [false], [false]]} | introductory | https://www.codewars.com/kata/5a4a391ad8e145cdee0000c4 |
def has_subpattern(string):
| [
67691,
311,
279,
508,
19702,
61688,
9533,
2428,
1110,
2136,
41067,
365,
1561,
905,
14109,
459,
54544,
17967,
14339,
59172,
30656,
17600,
14,
701,
498,
686,
1184,
311,
470,
264,
2710,
897,
421,
279,
2331,
914,
646,
387,
13302,
438,
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... |
3,475 | Implement a function/class, which should return an integer if the input string is in one of the formats specified below, or `null/nil/None` otherwise.
Format:
* Optional `-` or `+`
* Base prefix `0b` (binary), `0x` (hexadecimal), `0o` (octal), or in case of no prefix decimal.
* Digits depending on base
Any extra char... | ["import re\n\ndef to_integer(s):\n if re.match(\"\\A[+-]?(\\d+|0b[01]+|0o[0-7]+|0x[0-9a-fA-F]+)\\Z\", s):\n return int(s, 10 if s[1:].isdigit() else 0)", "from re import compile, match\n\nREGEX = compile(r'[+-]?(0(?P<base>[bxo]))?[\\d\\w]+\\Z')\n\n\ndef to_integer(strng):\n try:\n return int(strng,... | {"fn_name": "to_integer", "inputs": [["123"], ["0x123"], ["0o123"], ["0123"], ["123 "], [" 123"], ["0b1010"], ["+123"], ["-123"], ["0B1010"], ["0b12"], ["-0x123"], ["-0o123"], ["-0123"], ["123\n"], ["\n123"], ["-0b1010"], ["0xDEADbeef"], ["0X123"], ["0O123"], ["0o18"]], "outputs": [[123], [291], [83], [123], [null], [n... | introductory | https://www.codewars.com/kata/5682e1082cc7862db5000039 |
def to_integer(string):
| [
62980,
264,
729,
25514,
11,
892,
1265,
470,
458,
7546,
421,
279,
1946,
914,
374,
304,
825,
315,
279,
19856,
5189,
3685,
11,
476,
1565,
2921,
14,
8385,
14,
4064,
63,
5937,
382,
4061,
510,
9,
12256,
93797,
63,
476,
1565,
10,
3989,
9... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1... |
4,621 | ---
# Story
The Pied Piper has been enlisted to play his magical tune and coax all the rats out of town.
But some of the rats are deaf and are going the wrong way!
# Kata Task
How many deaf rats are there?
# Legend
* ```P``` = The Pied Piper
* ```O~``` = Rat going left
* ```~O``` = Rat going right
# Example
* ... | ["def count_deaf_rats(town):\n return town.replace(' ', '')[::2].count('O')", "import re\ndef count_deaf_rats(town):\n return re.findall(r\"O~|~O\",town.split(\"P\")[0]).count(\"O~\") + re.findall(r\"O~|~O\",town.split(\"P\")[1]).count(\"~O\")", "import re\n\ndef count_deaf_rats(town):\n town = re.sub(\"(~O|O~... | {"fn_name": "count_deaf_rats", "inputs": [["~O~O~O~O P"], ["P O~ O~ ~O O~"], ["~O~O~O~OP~O~OO~"], ["O~~OO~~OO~~OO~P~OO~~OO~~OO~~O"], ["~OP"], ["PO~"], ["O~P"], ["P~O"], [" P"], ["P "], [" P "], ["P"]], "outputs": [[0], [1], [2], [8], [0], [0], [1], [1], [0], [0], [0], [0]]} | introductory | https://www.codewars.com/kata/598106cb34e205e074000031 |
def count_deaf_rats(town):
| [
44364,
2,
15106,
271,
785,
83330,
69807,
702,
1012,
68476,
311,
1486,
806,
23702,
25240,
323,
90866,
678,
279,
31410,
700,
315,
6290,
382,
3983,
1045,
315,
279,
31410,
525,
46742,
323,
525,
2087,
279,
4969,
1616,
2219,
2,
98838,
5430,
... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,237 | You are given a permutation $p_1, p_2, \ldots, p_n$.
In one move you can swap two adjacent values.
You want to perform a minimum number of moves, such that in the end there will exist a subsegment $1,2,\ldots, k$, in other words in the end there should be an integer $i$, $1 \leq i \leq n-k+1$ such that $p_i = 1, p_{i... | ["import sys\nreader = (s.rstrip() for s in sys.stdin)\ninput = reader.__next__\n\nclass Binary_Indexed_Tree():\n def __init__(self, n):\n self.n = n\n self.data = [0]*(n+1)\n\n def add(self, i, x):\n while i <= self.n:\n self.data[i] += x\n i += i & -i\n\n def get(se... | {
"inputs": [
"5\n5 4 3 2 1\n",
"3\n1 2 3\n",
"1\n1\n",
"10\n5 1 6 2 8 3 4 10 9 7\n",
"100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 ... | competition | https://codeforces.com/problemset/problem/1268/C | [
2610,
525,
2661,
264,
58441,
400,
79,
62,
16,
11,
281,
62,
17,
11,
1124,
507,
2412,
11,
281,
1089,
3,
382,
641,
825,
3271,
498,
646,
14291,
1378,
23942,
2750,
382,
2610,
1366,
311,
2736,
264,
8028,
1372,
315,
10797,
11,
1741,
429,... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,884 | # RegExp Fun #1 - When I miss few days of gym
## Disclaimer
The background story of this Kata is 100% fiction. Any resemblance to real people or real events is **nothing more than a coincidence** and should be regarded as such.
## Background Story
You are a person who loves to go to the gym everyday with the squad... | ["import re\n\ndef gym_slang(phrase):\n phrase = re.sub(r'([pP])robably', r'\\1rolly', phrase)\n phrase = re.sub(r'([iI]) am', r\"\\1'm\", phrase)\n phrase = re.sub(r'([iI])nstagram', r'\\1nsta', phrase)\n phrase = re.sub(r'([dD])o not', r\"\\1on't\", phrase)\n phrase = re.sub(r'([gG])oing to', r'\\1onna... | {"fn_name": "gym_slang", "inputs": [["When I miss few days of gym"], ["Squad probably think I am fake"], ["Whole squad probably bigger than me now"], ["No selfie to post on Instagram either"], ["Gym crush probably found someone else"], ["What if I die fat"], ["What if I do not fit in my clothes now"], ["Going to feel l... | introductory | https://www.codewars.com/kata/5720a81309e1f9b232001c5b |
def gym_slang(phrase):
| [
2,
28487,
16071,
671,
16,
481,
3197,
358,
3116,
2421,
2849,
315,
18813,
271,
565,
66829,
271,
785,
4004,
3364,
315,
419,
98838,
374,
220,
16,
15,
15,
4,
16989,
13,
220,
5765,
68900,
311,
1931,
1251,
476,
1931,
4357,
374,
3070,
41212... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1... |
732 | Alice and Bob are walking on an infinite straight street. Initially, both are at the position $X=0$ and they start walking in the direction of increasing $X$. After $N$ seconds, they stop. Let's denote Alice's speed and Bob's speed during the $i$-th of these seconds by $A_i$ and $B_i$ respectively.
Sometimes, Alice and... | ["# cook your dish here\nfor tc in range(int(input())):\n \n n = int(input())\n \n li1 = list(map(int,input().split(' ')))\n li2 = list(map(int,input().split(' ')))\n walk = 0\n sum1 = 0 \n sum2 = 0\n for i in range(n):\n if li1[i] == li2[i] and sum1 == sum2:\n walk += li1[i]\n sum1 += li1[i]\n sum2 += li2[i]\n pr... | {"inputs": [["3", "4", "1 3 3 4", "1 2 4 4", "2", "2 3", "3 2", "2", "3 3", "3 3"]], "outputs": [["5", "0", "6"]]} | interview | https://www.codechef.com/problems/WWALK | [
61686,
323,
14261,
525,
11435,
389,
458,
23809,
7678,
8592,
13,
58556,
11,
2176,
525,
518,
279,
2309,
400,
55,
28,
15,
3,
323,
807,
1191,
11435,
304,
279,
5106,
315,
7703,
400,
55,
12947,
4636,
400,
45,
3,
6486,
11,
807,
2936,
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... | |
5 | The sequence of $m$ integers is called the permutation if it contains all integers from $1$ to $m$ exactly once. The number $m$ is called the length of the permutation.
Dreamoon has two permutations $p_1$ and $p_2$ of non-zero lengths $l_1$ and $l_2$.
Now Dreamoon concatenates these two permutations into another sequ... | ["def possible(a):\n ans = set()\n s = set()\n lmax = 0\n for i in range(len(a)):\n lmax = max(lmax, a[i])\n s.add(a[i])\n if lmax == i + 1 and len(s) == i + 1:\n ans.add(i + 1)\n return ans\n\n\nt = int(input())\nfor case_num in range(t):\n n = int(input())\n a = li... | {
"inputs": [
"6\n5\n1 4 3 2 1\n6\n2 4 1 3 2 1\n4\n2 1 1 3\n4\n1 3 3 1\n12\n2 1 3 4 5 6 7 8 9 1 10 2\n3\n1 1 1\n"
],
"outputs": [
"2\n1 4\n4 1\n1\n4 2\n0\n0\n1\n2 10\n0\n"
]
} | interview | https://codeforces.com/problemset/problem/1330/B | [
785,
8500,
315,
400,
76,
3,
25780,
374,
2598,
279,
58441,
421,
432,
5610,
678,
25780,
504,
400,
16,
3,
311,
400,
76,
3,
6896,
3055,
13,
576,
1372,
400,
76,
3,
374,
2598,
279,
3084,
315,
279,
58441,
382,
64354,
9009,
702,
1378,
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,621 | Write a function that counts how many different ways you can make change for an amount of money, given an array of coin denominations. For example, there are 3 ways to give change for 4 if you have coins with denomination 1 and 2:
```
1+1+1+1, 1+1+2, 2+2.
```
The order of coins does not matter:
```
1+1+2 == 2+1+1
```
... | ["def count_change(money, coins):\n if money<0:\n return 0\n if money == 0:\n return 1\n if money>0 and not coins:\n return 0\n return count_change(money-coins[-1],coins) + count_change(money,coins[:-1])", "\n\ndef count_change(money, coins):\n\n ways = [1] + [0] * (money + 1)\n\n ... | {"fn_name": "count_change", "inputs": [[4, [1, 2]], [10, [5, 2, 3]], [11, [5, 7]], [98, [3, 14, 8]], [199, [3, 5, 9, 15]], [300, [5, 10, 20, 50, 100, 200, 500]], [301, [5, 10, 20, 50, 100, 200, 500]], [419, [2, 5, 10, 20, 50]]], "outputs": [[3], [4], [0], [19], [760], [1022], [0], [18515]]} | interview | https://www.codewars.com/kata/541af676b589989aed0009e7 |
def count_change(money, coins):
| [
7985,
264,
729,
429,
14579,
1246,
1657,
2155,
5510,
498,
646,
1281,
2297,
369,
458,
3311,
315,
3220,
11,
2661,
458,
1334,
315,
16254,
61165,
804,
13,
1752,
3110,
11,
1052,
525,
220,
18,
5510,
311,
2968,
2297,
369,
220,
19,
421,
498,... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,504 | Your task is to create a new implementation of `modpow` so that it computes `(x^y)%n` for large `y`. The problem with the current implementation is that the output of `Math.pow` is so large on our inputs that it won't fit in a 64-bit float.
You're also going to need to be efficient, because we'll be testing some prett... | ["def power_mod(b, e, m):\n res, b = 1, b % m\n while e > 0:\n if e & 1: res = res * b % m\n e >>= 1\n b = b * b % m\n return res", "def power_mod(base, exponent, modulus):\n if base is 0: return 0\n if exponent is 0: return 0\n base = base % modulus\n result = 1\n while (exponent > 0):\n ... | {"fn_name": "power_mod", "inputs": [[11, 10, 300], [11, 100000, 49], [5, 100000000, 19], [2, 3, 5], [4, 12, 3], [200, 3000, 10], [8132, 21302, 5], [9, 193125, 37], [13, 81230123, 22], [29, 1013293125, 492], [31, 902938423012, 1023]], "outputs": [[1], [32], [5], [3], [1], [0], [4], [26], [19], [161], [961]]} | introductory | https://www.codewars.com/kata/52fe629e48970ad2bd0007e6 |
def power_mod(b, e, m):
| [
7771,
3383,
374,
311,
1855,
264,
501,
8129,
315,
1565,
2593,
21743,
63,
773,
429,
432,
57203,
48651,
87,
61,
88,
23891,
77,
63,
369,
3460,
1565,
88,
28587,
576,
3491,
448,
279,
1482,
8129,
374,
429,
279,
2550,
315,
1565,
8815,
25290... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1... |
442 | Given an n x n binary grid, in one step you can choose two adjacent rows of the grid and swap them.
A grid is said to be valid if all the cells above the main diagonal are zeros.
Return the minimum number of steps needed to make the grid valid, or -1 if the grid cannot be valid.
The main diagonal of a grid is the diago... | ["class Solution:\n def minSwaps(self, grid: List[List[int]]) -> int:\n start=1\n swap=0\n n=len(grid)\n zeros_ingrid=n-1\n while zeros_ingrid>0:\n swapped_grid=False\n for i in range(len(grid)):\n if sum(grid[i][start:])==0:\n ... | {"fn_name": "minSwaps", "inputs": [[[[0, 0, 1], [1, 1, 0], [1, 0, 0], [], []]]], "outputs": [3]} | interview | https://leetcode.com/problems/minimum-swaps-to-arrange-a-binary-grid/ |
class Solution:
def minSwaps(self, grid: List[List[int]]) -> int:
| [
22043,
458,
308,
4102,
87,
308,
4102,
25891,
5827,
11,
304,
825,
3019,
498,
646,
5157,
1378,
23942,
6978,
315,
279,
5827,
323,
14291,
1105,
624,
32,
5827,
374,
1053,
311,
387,
2697,
421,
678,
279,
7761,
3403,
279,
1887,
37236,
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... |
861 | Recall the definition of the Fibonacci numbers:
f1 := 1
f2 := 2
fn := fn-1 + fn-2 (n>=3)
Given two numbers a and b, calculate how many Fibonacci numbers are in the range [a,b].
-----Input-----
The input contains several test cases. Each test case consists of two non-negative integer numbers a and b. Input is te... | ["#!/usr/bin/env python\n\nF = [1,1]\ndef fibo():\n for i in range(500):\n F.append(F[-2] + F[-1])\n\ndef main():\n fibo()\n #print len(str(F[-1]))\n #print len(str(10**100))\n while True:\n try:\n A, B = list(map(int, input().strip().split()[:2]))\n if A == 0 and B == 0: break\n print(len([x for x in F if x >=... | {"inputs": [["10 100", "1234567890 9876543210", "0 0"]], "outputs": [["5", "4"]]} | interview | https://www.codechef.com/PRFT2012/problems/PD32 | [
3820,
541,
279,
7271,
315,
279,
79683,
5109,
24391,
69,
16,
1669,
220,
16,
271,
69,
17,
1669,
220,
17,
271,
8822,
1669,
5168,
12,
16,
488,
5168,
12,
17,
320,
77,
9922,
18,
692,
22043,
1378,
5109,
264,
323,
293,
11,
11047,
1246,
... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1... | |
1,383 | Due to COVID19 all employees of chemical factory are quarantined in home. So, company is organized by automated robots. There are $N$ Containers in company, which are labelled with $1$ to $N$ numbers. There are Total $N$ robots in Company, which are labelled $1$ to $N$.
Each Robot adds $1$ litter Chemical in container... | ["T = int(input())\r\nfor _ in range(T):\r\n N, K1, K2 = list(map(int, input().split()))\r\n P1, P2, P3, P4 = list(map(int, input().split()))\r\n ans = 0\r\n arr = [0] * (1005)\r\n\r\n length = len(arr)\r\n for i in range(1,N+1):\r\n\r\n j = 0\r\n while j < length:\r\n arr[j] ... | {"inputs": [["1", "4 1 4", "2 2 2 2"]], "outputs": [["8"]]} | interview | https://www.codechef.com/QFUN2020/problems/CHEMFACT | [
33060,
311,
19966,
16,
24,
678,
8256,
315,
11483,
8633,
525,
36865,
517,
1589,
304,
2114,
13,
2055,
11,
2813,
374,
16645,
553,
27498,
28707,
13,
2619,
525,
400,
45,
3,
98293,
304,
2813,
11,
892,
525,
60236,
448,
400,
16,
3,
311,
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... | |
3,447 | Write a function name `nextPerfectSquare` that returns the first perfect square that is greater than its integer argument. A `perfect square` is a integer that is equal to some integer squared. For example 16 is a perfect square because `16=4*4`.
```
example
n next perfect sqare
6 9
36 49
0 1
-5 0
```
... | ["def next_perfect_square(n):\n return n>=0 and (int(n**0.5)+1)**2", "next_perfect_square=lambda n:(n>=0and int(n**.5)+1)**2", "def next_perfect_square(n):\n return n >= 0 and (int(n**.5)+1)**2", "import math\ndef next_perfect_square(n):\n return math.ceil((n + 1) ** 0.5) ** 2 if n > -1 else 0\n", "from bisect... | {"fn_name": "next_perfect_square", "inputs": [[6], [36], [0], [-5]], "outputs": [[9], [49], [1], [0]]} | introductory | https://www.codewars.com/kata/599f403119afacf9f1000051 |
def next_perfect_square(n):
| [
7985,
264,
729,
829,
1565,
3600,
51041,
33271,
63,
429,
4675,
279,
1156,
4727,
9334,
429,
374,
7046,
1091,
1181,
7546,
5693,
13,
362,
1565,
63085,
9334,
63,
374,
264,
7546,
429,
374,
6144,
311,
1045,
7546,
52263,
13,
1752,
3110,
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,186 | # Task
Your task is to find the similarity of given sorted arrays `a` and `b`, which is defined as follows:
you take the number of elements which are present in both arrays and divide it by the number of elements which are present in at least one array.
It also can be written as a formula `similarity(A, B) = #(A... | ["def similarity(a, b):\n try:\n return len(set(a) & set(b)) / len(set(a) | set(b))\n except:\n return 0", "def similarity(*args):\n a,b = map(set, args)\n return len(a&b) / len(a|b)", "def similarity(a, b):\n c = a + b\n lst1 = []\n lst2 = []\n for i in set(c):\n if c.count... | {"fn_name": "similarity", "inputs": [[[1, 2, 3], [1, 2, 3]], [[1, 2, 3], [4, 5, 6]], [[1, 2, 4, 6, 7], [2, 3, 4, 7]], [[1, 2, 6, 8, 9], [0, 1, 4, 5, 6, 8, 9]], [[0, 1, 3, 4, 5, 6, 9, 14, 15, 16, 17, 18, 19], [1, 4, 10, 12, 13, 14, 15, 16]]], "outputs": [[1], [0], [0.5], [0.5], [0.3125]]} | introductory | https://www.codewars.com/kata/58a6841442fd72aeb4000080 |
def similarity(a, b):
| [
2,
5430,
198,
4615,
3383,
374,
311,
1477,
279,
37623,
315,
2661,
10615,
18386,
1565,
64,
63,
323,
1565,
65,
7808,
892,
374,
4512,
438,
11017,
25,
31906,
498,
1896,
279,
1372,
315,
5424,
892,
525,
3042,
304,
2176,
18386,
323,
21749,
... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1... |
1,194 | Toby has found a game to entertain himself.The game is like this:
You are in a coordinate system initially at (0,0) and you are given a sequence of steps which lead to your destination.The steps are given in the form of directions: ’U’ ,’D’ , ’L’ and ‘R’ for up, down, left and right respectively.If you are at position... | ["from collections import Counter\ntry:\n for _ in range(int(input())):\n n=int(input())\n s=input()\n d1=dict(Counter(s))\n \n u,d,r,l=0,0,0,0\n if 'U' in d1:\n u=d1['U']\n else:\n u=0\n if 'D' in d1:\n d=d1['D']\n else:\n d=0\n if 'R' in d1:\n r=d1['R']\n else:\n r=0\n if 'L' in d1:\n l=d1['... | {"inputs": [["3", "7", "ULUDLLU", "4", "RUUR", "4", "LRLR"]], "outputs": [["2", "0", "4"]]} | interview | https://www.codechef.com/CSEP2020/problems/TOBY | [
51,
27015,
702,
1730,
264,
1809,
311,
45176,
5561,
11568,
1809,
374,
1075,
419,
1447,
2610,
525,
304,
264,
16184,
1849,
15102,
518,
320,
15,
11,
15,
8,
323,
498,
525,
2661,
264,
8500,
315,
7354,
892,
2990,
311,
697,
9106,
11568,
735... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1... | |
301 | We write the integers of A and B (in the order they are given) on two separate horizontal lines.
Now, we may draw connecting lines: a straight line connecting two numbers A[i] and B[j] such that:
A[i] == B[j];
The line we draw does not intersect any other connecting (non-horizontal) line.
Note that a connecting lines... | ["class Solution:\n def maxUncrossedLines(self, A, B):\n # Optimization\n #commons = set(A).intersection(set(B)) # or commons = set(A) & set(B)\n #A = [x for x in A if x in commons]\n #B = [x for x in B if x in commons]\n\n N1, N2 = len(A), len(B)\n dp = [[0 for _ in range(N... | {"fn_name": "maxUncrossedLines", "inputs": [[[1, 4, 2], [1, 2, 4]]], "outputs": [2]} | interview | https://leetcode.com/problems/uncrossed-lines/ |
class Solution:
def maxUncrossedLines(self, A: List[int], B: List[int]) -> int:
| [
1654,
3270,
279,
25780,
315,
362,
323,
425,
4102,
5900,
279,
1973,
807,
525,
2661,
8,
389,
1378,
8651,
16202,
5128,
624,
7039,
11,
582,
1231,
4038,
20913,
5128,
25,
264,
7678,
1555,
20913,
1378,
5109,
362,
989,
60,
323,
425,
3809,
6... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,687 | # Task
Your task is to find the smallest number which is evenly divided by all numbers between `m` and `n` (both inclusive).
# Example
For `m = 1, n = 2`, the output should be `2`.
For `m = 2, n = 3`, the output should be `6`.
For `m = 3, n = 2`, the output should be `6` too.
For `m = 1, n = 10`, the outpu... | ["from fractions import gcd\nfrom functools import reduce\n\ndef mn_lcm(m, n):\n return reduce(lambda x, y: (x * y) / gcd(x, y), list(range(min(m, n), max(m, n) + 1)))\n\n", "from fractions import gcd\nfrom functools import reduce\ndef mn_lcm(m, n):\n return reduce(lambda x, y: (x * y) / gcd(x, y), range(min(m, n... | {"fn_name": "mn_lcm", "inputs": [[1, 2], [1, 5], [5, 1], [1, 10], [2, 3], [3, 5], [10, 20], [1, 25], [24, 25]], "outputs": [[2], [60], [60], [2520], [6], [60], [232792560], [26771144400], [600]]} | introductory | https://www.codewars.com/kata/58bcdc65f6d3b11fce000045 |
def mn_lcm(m, n):
| [
2,
5430,
198,
4615,
3383,
374,
311,
1477,
279,
24632,
1372,
892,
374,
41047,
17779,
553,
678,
5109,
1948,
1565,
76,
63,
323,
1565,
77,
63,
320,
21028,
28308,
3593,
2,
13383,
271,
1752,
1565,
76,
284,
220,
16,
11,
308,
284,
220,
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,626 | Consider the following array:
```
[1, 12, 123, 1234, 12345, 123456, 1234567, 12345678, 123456789, 12345678910, 1234567891011...]
```
If we join these blocks of numbers, we come up with an infinite sequence which starts with `112123123412345123456...`. The list is infinite.
You will be given an number (`n`) and your ... | ["def solve(n):\n def length(n):\n s = 0\n for i in range(20):\n o = 10 ** i - 1\n if o > n: break\n s += (n - o) * (n - o + 1) // 2\n return s\n\n def binary_search(k):\n n = 0\n for p in range(63, -1, -1):\n if length(n + 2 ** p) < k... | {"fn_name": "solve", "inputs": [[1], [2], [3], [100], [2100], [31000], [55], [123456], [123456789], [999999999999999999], [1000000000000000000], [999999999999999993]], "outputs": [[1], [1], [2], [1], [2], [2], [1], [6], [3], [4], [1], [7]]} | interview | https://www.codewars.com/kata/5e1ab1b9fe268c0033680e5f |
def solve(n):
| [
37175,
279,
2701,
1334,
1447,
13874,
3989,
58,
16,
11,
220,
16,
17,
11,
220,
16,
17,
18,
11,
220,
16,
17,
18,
19,
11,
220,
16,
17,
18,
19,
20,
11,
220,
16,
17,
18,
19,
20,
21,
11,
220,
16,
17,
18,
19,
20,
21,
22,
11,
2... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1... |
1,735 | Ever heard about Dijkstra's shallowest path algorithm? Me neither. But I can imagine what it would be.
You're hiking in the wilderness of Northern Canada and you must cross a large river. You have a map of one of the safer places to cross the river showing the depths of the water on a rectangular grid. When crossing t... | ["from heapq import *\n\nMOVES = tuple( (dx,dy) for dx in range(-1,2) for dy in range(-1,2) if dx or dy)\n\n\ndef shallowest_path(river):\n\n lX,lY = len(river), len(river[0])\n pathDct = {}\n cost = [ [(float('inf'),float('inf'))]*lY for _ in range(lX) ]\n for x in range(lX): cost[x][0] = (river[x][0]... | {"fn_name": "shallowest_path", "inputs": [], "outputs": []} | interview | https://www.codewars.com/kata/585cec2471677ee42c000296 |
def shallowest_path(river):
| [
43487,
6617,
911,
422,
87177,
594,
25600,
477,
1815,
12111,
30,
2157,
13866,
13,
1988,
358,
646,
12793,
1128,
432,
1035,
387,
382,
2610,
2299,
37364,
304,
279,
48262,
315,
16926,
6864,
323,
498,
1969,
5312,
264,
3460,
14796,
13,
1446,
... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,035 | This is the easy version of the problem. The only difference between easy and hard versions is the constraint of $m$. You can make hacks only if both versions are solved.
Chiori loves dolls and now she is going to decorate her bedroom![Image]
As a doll collector, Chiori has got $n$ dolls. The $i$-th doll has a non-n... | ["MOD = 998244353\nBOUND = 19\n \nn, m = list(map(int, input().split()))\nl = list(map(int,input().split()))\n \nbasis = []\nfor p in range(m-1,-1,-1):\n p2 = pow(2,p)\n nex = -1\n for i in range(n):\n if l[i] >= p2:\n nex = l[i]\n break\n if nex != -1:\n basis.append(nex... | {
"inputs": [
"4 4\n3 5 8 14\n",
"6 7\n11 45 14 9 19 81\n",
"1 0\n0\n",
"30 35\n11712212162 13887261936 9226451478 5810578422 4558800999 2160186631 25345435752 20420262166 16723017889 4041013095 17986671533 30276157972 27290831854 10571984774 24307466845 32173907391 15769943440 28953863917 1549581104 ... | competition | https://codeforces.com/problemset/problem/1336/E1 | [
1986,
374,
279,
4135,
2319,
315,
279,
3491,
13,
576,
1172,
6672,
1948,
4135,
323,
2588,
10795,
374,
279,
21568,
315,
400,
76,
12947,
1446,
646,
1281,
59784,
1172,
421,
2176,
10795,
525,
27956,
382,
1143,
2462,
72,
15803,
63781,
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,
1... | |
4,159 | *** Nova polynomial multiply***
This kata is from a series on polynomial handling. ( [#1](http://www.codewars.com/kata/nova-polynomial-1-add-1) [#2](http://www.codewars.com/kata/570eb07e127ad107270005fe) [#3](http://www.codewars.com/kata/5714041e8807940ff3001140 ) [#4](http://www.codewars.com/kata/571a2e2df24bdf... | ["def poly_multiply(p1, p2):\n if not p1 or not p2: return []\n n = len(p1) + len(p2) - 1\n p = [0]*n\n for i,a in enumerate(p1):\n for j,b in enumerate(p2):\n p[i + j] += a*b\n return p", "from numpy import polymul\n\ndef poly_multiply(p1, p2):\n res = list(polymul(p1, p2))\n return res if any(res) ... | {"fn_name": "poly_multiply", "inputs": [[[], []], [[1, 2, 3, 4, 5, 6], []], [[], [1, 2, 3, 4, 5, 6]]], "outputs": [[[]], [[]], [[]]]} | introductory | https://www.codewars.com/kata/570eb07e127ad107270005fe |
def poly_multiply(p1, p2):
| [
12210,
34641,
47311,
30270,
12210,
4710,
1986,
61688,
374,
504,
264,
4013,
389,
47311,
11589,
13,
320,
83703,
16,
9533,
1254,
1110,
2136,
41067,
365,
1561,
905,
14109,
459,
9612,
12660,
53996,
25358,
12,
16,
18570,
12,
16,
8,
256,
83703... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1... |
1,532 | As you know America’s Presidential Elections are about to take place and the most popular leader of the Republican party Donald Trump is famous for throwing allegations against anyone he meets.
He goes to a rally and meets n people which he wants to offend. For each person i he can choose an integer between 1 to max[i... | ["for t in range(int(input())):\n n = int(input())\n a = sorted(map(int,input().split()))\n ans = 1\n for i in range(n):\n ans *= (a[i]-i)\n ans %= (10**9+7)\n if (ans == 0):\n break\n print(ans) ", "t = eval(input())\n\nfor i in range(t):\n n=eval(input())\n a = list(map(int, input().split()))\n a.sort()\n \n cnt... | {"inputs": [["3", "1", "4", "2", "10 5", "4", "2 3 1 3"]], "outputs": [["4", "45", "0"]]} | interview | https://www.codechef.com/CDGF2016/problems/CDGLF01 | [
2121,
498,
1414,
5159,
748,
41755,
57501,
525,
911,
311,
1896,
1992,
323,
279,
1429,
5411,
7653,
315,
279,
9356,
4614,
9453,
3339,
374,
11245,
369,
21244,
18367,
2348,
5489,
566,
20027,
382,
1519,
5780,
311,
264,
19217,
323,
20027,
308,... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1... | |
718 | The chef is trying to decode some pattern problems, Chef wants your help to code it. Chef has one number K to form a new pattern. Help the chef to code this pattern problem.
-----Input:-----
- First-line will contain $T$, the number of test cases. Then the test cases follow.
- Each test case contains a single line of... | ["import sys\ninput = lambda: sys.stdin.readline().rstrip(\"\\r\\n\")\ninp = lambda: list(map(int,sys.stdin.readline().rstrip(\"\\r\\n\").split()))\n#_______________________________________________________________________________\u00a0\u00a0\u00a0\u00a0_______________________\n# from math import *\n# from bisect import... | {"inputs": [["4", "1", "2", "3", "4"]], "outputs": [["0", "0", "1 1", "0", "1 1", "2 3 5", "0", "1 1", "2 3 5", "8 13 21 34"]]} | interview | https://www.codechef.com/PSTR2020/problems/ITGUY57 | [
785,
29706,
374,
4460,
311,
16895,
1045,
5383,
5322,
11,
35975,
6801,
697,
1492,
311,
2038,
432,
13,
35975,
702,
825,
1372,
730,
311,
1352,
264,
501,
5383,
13,
11479,
279,
29706,
311,
2038,
419,
5383,
3491,
382,
15081,
2505,
25,
34764... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1... | |
1,623 | ## Story
Before we dive into the exercise, I would like to show you why these numbers are so important in computer programming today.
It all goes back to the time of 19th century. Where computers we know today were non-existing. The first ever **computer program** was for the Analytical Engine to compute **Bernoulli ... | ["from fractions import Fraction as frac\ndef ber():\n res, m = [], 0\n while True:\n res.append(frac(1, m+1))\n for j in range(m, 0, -1):\n res[j-1] = j*(res[j-1] - res[j])\n yield res[0]\n m += 1\ndef bernoulli_number(n): \n if n == 1: return Fraction(-1, 2)\n if n %... | {"fn_name": "bernoulli_number", "inputs": [[0], [3], [1337]], "outputs": [[1], [0], [0]]} | interview | https://www.codewars.com/kata/567ffb369f7f92e53800005b |
def bernoulli_number(n):
| [
565,
15106,
271,
10227,
582,
29863,
1119,
279,
10158,
11,
358,
1035,
1075,
311,
1473,
498,
3170,
1493,
5109,
525,
773,
2989,
304,
6366,
15473,
3351,
382,
2132,
678,
5780,
1182,
311,
279,
882,
315,
220,
16,
24,
339,
9294,
13,
10967,
... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1... |
998 | You are given an N × N grid initially filled by zeros. Let the rows and columns of the grid be numbered from 1 to N, inclusive. There are two types of operations can be applied to the grid:
- RowAdd R X: all numbers in the row R should be increased by X.
- ColAdd C X: all numbers in the column C should be increased by... | ["n,q=map(int,input().split())\ndr={}\ndc={}\nfor i in range(1,n+1):\n dr[i]=0\n dc[i]=0\nmer=0\nmec=0\nfor i in range(q):\n s,j,k=input().split()\n j=int(j)\n k=int(k)\n if s==\"RowAdd\":\n dr[j]+=k\n if dr[j]>mer:\n mer=dr[j]\n else:\n dc[j]+=k\n if mec<dc[j]:\n mec=dc[j]\n# m=max(list(dr.values()))+max(list(... | {"inputs": [["2 4", "RowAdd 1 3", "ColAdd 2 1", "ColAdd 1 4", "RowAdd 2 1"]], "outputs": [["7"]]} | interview | https://www.codechef.com/problems/ROWCOLOP | [
2610,
525,
2661,
458,
451,
24768,
451,
5827,
15102,
10199,
553,
17516,
13,
6771,
279,
6978,
323,
8147,
315,
279,
5827,
387,
48826,
504,
220,
16,
311,
451,
11,
28308,
13,
2619,
525,
1378,
4494,
315,
7525,
646,
387,
9251,
311,
279,
58... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1... | |
1,499 | Given $N *M$ matrix containing elements either $1$ or $0$ and string S of length $N+M-1$ containing characters $0$ or $1$. Your task is to make all the paths from top left corner to the bottom right corner of the matrix same as the given string .You can perform two types of operations any time .Path means you can on... | ["from sys import stdin,stdout\nimport math,bisect\nfrom collections import Counter,deque,defaultdict\nL=lambda:list(map(int, stdin.readline().strip().split()))\nM=lambda:list(map(int, stdin.readline().strip().split()))\nI=lambda:int(stdin.readline().strip())\nS=lambda:stdin.readline().strip()\nC=lambda:stdin.readline(... | {"inputs": [["2", "3 3", "1 0 1", "0 1 1", "1 1 0", "10111", "10 5", "3 3", "0 0 1", "0 1 1", "0 1 1", "00011", "2 9"]], "outputs": [["5", "4"]]} | interview | https://www.codechef.com/LOGI2020/problems/MATMIN1 | [
22043,
400,
45,
353,
44,
3,
6172,
8482,
5424,
2987,
400,
16,
3,
476,
400,
15,
3,
323,
914,
328,
315,
3084,
400,
45,
10,
44,
12,
16,
3,
8482,
5766,
400,
15,
3,
476,
400,
16,
12947,
4615,
3383,
374,
311,
1281,
678,
279,
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,
1... | |
1,508 | The chef is trying to decode some pattern problems, Chef wants your help to code it. Chef has one number K to form a new pattern. Help the chef to code this pattern problem.
-----Input:-----
- First-line will contain $T$, the number of test cases. Then the test cases follow.
- Each test case contains a single line of... | ["# cook your dish here\nfor _ in range(int(input())):\n n=int(input())\n if n==1:\n print(\"0\")\n else:\n s=[]\n for i in range(n):\n s.append(str(i))\n print(''.join(s))\n p=1\n for i in range(n-1):\n s.pop(n-1)\n s=[str(p)]+s\n ... | {"inputs": [["4", "1", "2", "3", "4"]], "outputs": [["0", "01", "10", "012", "101", "210", "0123", "1012", "2101", "3210"]]} | interview | https://www.codechef.com/PEND2020/problems/ITGUY59 | [
785,
29706,
374,
4460,
311,
16895,
1045,
5383,
5322,
11,
35975,
6801,
697,
1492,
311,
2038,
432,
13,
35975,
702,
825,
1372,
730,
311,
1352,
264,
501,
5383,
13,
11479,
279,
29706,
311,
2038,
419,
5383,
3491,
382,
15081,
2505,
25,
34764... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,377 | This is an easy version of the problem. In this version, all numbers in the given array are distinct and the constraints on $n$ are less than in the hard version of the problem.
You are given an array $a$ of $n$ integers (there are no equals elements in the array). You can perform the following operations on array ele... | ["import sys\ninput = sys.stdin.readline\nimport bisect\n\nt=int(input())\nfor tests in range(t):\n n=int(input())\n A=list(map(int,input().split()))\n\n compression_dict={a: ind for ind, a in enumerate(sorted(set(A)))}\n A=[compression_dict[a] for a in A]\n\n Q=[0]*n\n \n for i in range(n):\n ... | {
"inputs": [
"4\n5\n4 7 2 3 9\n5\n3 5 8 1 7\n5\n1 4 5 7 12\n4\n0 2 1 3\n"
],
"outputs": [
"2\n2\n0\n2\n"
]
} | introductory | https://codeforces.com/problemset/problem/1367/F1 | [
1986,
374,
458,
4135,
2319,
315,
279,
3491,
13,
758,
419,
2319,
11,
678,
5109,
304,
279,
2661,
1334,
525,
12460,
323,
279,
16982,
389,
400,
77,
3,
525,
2686,
1091,
304,
279,
2588,
2319,
315,
279,
3491,
382,
2610,
525,
2661,
458,
1... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1... | |
279 | The set [1,2,3,...,n] contains a total of n! unique permutations.
By listing and labeling all of the permutations in order, we get the following sequence for n = 3:
"123"
"132"
"213"
"231"
"312"
"321"
Given n and k, return the kth permutation sequence.
Note:
Give... | ["class Solution:\n def getPermutation(self, n, k):\n \"\"\"\n :type n: int\n :type k: int\n :rtype: str\n \"\"\"\n nums = list(\"123456789\")\n k -= 1\n factor = 1\n for i in range(1, n):\n factor *= i\n res = []\n ... | {"fn_name": "getPermutation", "inputs": [[3, 3]], "outputs": ["213"]} | interview | https://leetcode.com/problems/permutation-sequence/ |
class Solution:
def getPermutation(self, n: int, k: int) -> str:
| [
785,
738,
508,
16,
11,
17,
11,
18,
28675,
11,
77,
60,
5610,
264,
2790,
315,
308,
0,
4911,
71949,
382,
1359,
14838,
323,
54302,
678,
315,
279,
71949,
304,
1973,
11,
582,
633,
279,
2701,
8500,
369,
308,
284,
220,
18,
24391,
981,
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... |
277 | There is a room with n bulbs, numbered from 1 to n, arranged in a row from left to right. Initially, all the bulbs are turned off.
At moment k (for k from 0 to n - 1), we turn on the light[k] bulb. A bulb change color to blue only if it is on and all the previous bulbs (to the left) are turned on too.
Return the number... | ["class Solution:\n def numTimesAllBlue(self, light: List[int]) -> int:\n right = 0\n ans = 0\n for i in range(len(light)):\n if (light[i] > right):\n right = light[i]\n \n if (i + 1 == right):\n ans += 1\n \n r... | {"fn_name": "numTimesAllBlue", "inputs": [[[2, 1, 3, 5, 4]]], "outputs": [3]} | interview | https://leetcode.com/problems/bulb-switcher-iii/ |
class Solution:
def numTimesAllBlue(self, light: List[int]) -> int:
| [
3862,
374,
264,
3054,
448,
308,
53220,
11,
48826,
504,
220,
16,
311,
308,
11,
27802,
304,
264,
2802,
504,
2115,
311,
1290,
13,
58556,
11,
678,
279,
53220,
525,
6519,
1007,
624,
1655,
4445,
595,
320,
1958,
595,
504,
220,
15,
311,
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,445 | [Haikus](https://en.wikipedia.org/wiki/Haiku_in_English) are short poems in a three-line format, with 17 syllables arranged in a 5–7–5 pattern. Your task is to check if the supplied text is a haiku or not.
### About syllables
[Syllables](https://en.wikipedia.org/wiki/Syllable) are the phonological building blocks of... | ["import re\n\nPATTERN = re.compile(r'[aeyuio]+[^aeyuio ]*((?=e\\b)e)?', flags=re.I)\n\n\ndef is_haiku(text):\n return [5,7,5] == [check(s) for s in text.split(\"\\n\")]\n \ndef check(s):\n return sum(1 for _ in PATTERN.finditer(s))\n", "import re\n\ndef is_haiku(text):\n def count_syllables(line):\n ... | {"fn_name": "is_haiku", "inputs": [["An old silent pond...\nA frog jumps into the pond,\nsplash! Silence again."], ["An old silent pond...\nA frog jumps into the pond, splash!\nSilence again."], ["An old silent pond...\nA frog jumps into the pond,\nsplash!\nSilence again."], ["An old silent pond... A frog jumps into th... | introductory | https://www.codewars.com/kata/5c765a4f29e50e391e1414d4 |
def is_haiku(text):
| [
58,
32942,
1579,
355,
9533,
2428,
1110,
268,
33366,
2659,
25502,
23354,
64,
38242,
1243,
2089,
968,
1672,
8,
525,
2805,
44219,
304,
264,
2326,
8447,
3561,
11,
448,
220,
16,
22,
47604,
4788,
27802,
304,
264,
220,
20,
4142,
22,
4142,
... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,977 | # Messi goals function
[Messi](https://en.wikipedia.org/wiki/Lionel_Messi) is a soccer player with goals in three leagues:
- LaLiga
- Copa del Rey
- Champions
Complete the function to return his total number of goals in all three leagues.
Note: the input will always be valid.
For example:
```
5, 10, 2 --> 17
`... | ["def goals(*a):\n return sum(a)", "def goals(*args):\n return sum(args)", "def goals(laLiga, copaDelRey, championsLeague):\n return laLiga+copaDelRey+championsLeague", "def goals(laLiga, copaDelRey, championsLeague):\n \n resultado = laLiga + copaDelRey + championsLeague\n \n return resultado\n ... | {"fn_name": "goals", "inputs": [], "outputs": []} | introductory | https://www.codewars.com/kata/55f73be6e12baaa5900000d4 |
def goals(laLiga, copaDelRey, championsLeague):
| [
2,
70005,
8845,
729,
271,
39379,
433,
72,
9533,
2428,
1110,
268,
33366,
2659,
25502,
7434,
290,
301,
1245,
433,
72,
8,
374,
264,
22174,
2781,
448,
8845,
304,
2326,
38359,
25,
4710,
12,
4929,
43,
16551,
198,
12,
84531,
1594,
48212,
1... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1... |
65 | You and your friend are playing the game Mortal Kombat XI. You are trying to pass a challenge tower. There are $n$ bosses in this tower, numbered from $1$ to $n$. The type of the $i$-th boss is $a_i$. If the $i$-th boss is easy then its type is $a_i = 0$, otherwise this boss is hard and its type is $a_i = 1$.
During o... | ["import math\nfrom collections import deque\nfrom sys import stdin, stdout\nfrom string import ascii_letters\nimport sys\nletters = ascii_letters\ninput = stdin.readline\n#print = stdout.write\n\nfor _ in range(int(input())):\n n = int(input())\n arr = list(map(int, input().split()))\n ans = [999999999] * n\n... | {
"inputs": [
"6\n8\n1 0 1 1 0 1 1 1\n5\n1 1 1 1 0\n7\n1 1 1 1 0 0 1\n6\n1 1 1 1 1 1\n1\n1\n1\n0\n"
],
"outputs": [
"2\n2\n2\n2\n1\n0\n"
]
} | interview | https://codeforces.com/problemset/problem/1418/C | [
2610,
323,
697,
4238,
525,
5619,
279,
1809,
22031,
278,
730,
77628,
53243,
13,
1446,
525,
4460,
311,
1494,
264,
8645,
21271,
13,
2619,
525,
400,
77,
3,
41747,
304,
419,
21271,
11,
48826,
504,
400,
16,
3,
311,
400,
77,
12947,
576,
... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1... | |
49 | Let's call some positive integer classy if its decimal representation contains no more than $3$ non-zero digits. For example, numbers $4$, $200000$, $10203$ are classy and numbers $4231$, $102306$, $7277420000$ are not.
You are given a segment $[L; R]$. Count the number of classy integers $x$ such that $L \le x \le R$... | ["\nimport sys\n#sys.stdin=open(\"data.txt\")\ninput=sys.stdin.readline\n\n# this math tutorial is boring\n\nclassy=set()\n\nfor i in range(19):\n for j in range(i):\n for k in range(j):\n for a in range(10): # a=0 for good measure\n for b in range(10):\n for c... | {
"inputs": [
"4\n1 1000\n1024 1024\n65536 65536\n999999 1000001\n"
],
"outputs": [
"1000\n1\n0\n2\n"
]
} | interview | https://codeforces.com/problemset/problem/1036/C | [
10061,
594,
1618,
1045,
6785,
7546,
70258,
421,
1181,
12122,
13042,
5610,
902,
803,
1091,
400,
18,
3,
2477,
36929,
18509,
13,
1752,
3110,
11,
5109,
400,
19,
54876,
400,
17,
15,
15,
15,
15,
15,
54876,
400,
16,
15,
17,
15,
18,
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,863 | # Task
John is playing a RPG game. The initial attack value of the player is `x`. The player will face a crowd of monsters. Each monster has different defense value.
If the monster's defense value is less than or equal to the player's attack value, the player can easily defeat the monster, and the player's attack val... | ["from functools import reduce\nfrom fractions import gcd\n\ndef final_attack_value(x, monster_list):\n return reduce(lambda a, b: a + (b if b <= a else gcd(a, b)), monster_list, x)", "from fractions import gcd\ndef final_attack_value(x,monster_list):\n for i in monster_list:\n x += gcd(i,x) if i > x else ... | {"fn_name": "final_attack_value", "inputs": [[50, [50, 105, 200]], [20, [30, 20, 15, 40, 100]]], "outputs": [[110], [205]]} | introductory | https://www.codewars.com/kata/5951b409aea9beff3f0000c6 |
def final_attack_value(x,monster_list):
| [
2,
5430,
271,
13079,
374,
5619,
264,
33502,
1809,
13,
576,
2856,
3359,
897,
315,
279,
2781,
374,
1565,
87,
28587,
576,
2781,
686,
3579,
264,
13428,
315,
25787,
13,
8886,
17651,
702,
2155,
9055,
897,
382,
2679,
279,
17651,
594,
9055,
... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,506 | In your class, you have started lessons about geometric progression.
Since you are also a programmer, you have decided to write a function that will print first `n` elements of the sequence with the given constant `r` and first element `a`.
Result should be separated by comma and space.
### Example
```python
geometr... | ["def geometric_sequence_elements(a, r, n):\n return ', '.join(str(a * r ** i) for i in range(n))\n", "def geometric_sequence_elements(a, r, n):\n l = []\n for _ in range(n):\n l.append(str(a))\n a *= r\n return \", \".join(l)\n", "def geometric_sequence_elements(a, r, n):\n return \", \".j... | {"fn_name": "geometric_sequence_elements", "inputs": [[2, 3, 5], [2, 2, 10], [1, -2, 10]], "outputs": [["2, 6, 18, 54, 162"], ["2, 4, 8, 16, 32, 64, 128, 256, 512, 1024"], ["1, -2, 4, -8, 16, -32, 64, -128, 256, -512"]]} | introductory | https://www.codewars.com/kata/55caef80d691f65cb6000040 |
def geometric_sequence_elements(a, r, n):
| [
641,
697,
536,
11,
498,
614,
3855,
18366,
911,
52484,
32724,
624,
12549,
498,
525,
1083,
264,
47788,
11,
498,
614,
6635,
311,
3270,
264,
729,
429,
686,
1173,
1156,
1565,
77,
63,
5424,
315,
279,
8500,
448,
279,
2661,
6783,
1565,
81,
... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,785 | #Task:
Write a function `get_member_since` which accepts a username from someone at Codewars and returns an string containing the month and year separated by a space that they joined CodeWars.
###If you want/don't want your username to be in the tests, ask me in the discourse area. There can't be too many though becau... | ["from urllib.request import urlopen\nfrom bs4 import BeautifulSoup as bs\ndef get_member_since(username):\n html = urlopen(f'https://www.codewars.com/users/{username}')\n soup = bs(html.read(), \"html.parser\")\n tags = soup.find_all(\"div\", {\"class\": \"stat\"})\n member_tag = [x.text for x in tags if '... | {"fn_name": "get_member_since", "inputs": [], "outputs": []} | introductory | https://www.codewars.com/kata/58ab2ed1acbab2eacc00010e |
def get_member_since(username):
| [
2,
6262,
510,
7985,
264,
729,
1565,
455,
19388,
56262,
63,
892,
26344,
264,
5934,
504,
4325,
518,
33677,
365,
1561,
323,
4675,
458,
914,
8482,
279,
2254,
323,
1042,
18663,
553,
264,
3550,
429,
807,
10859,
6119,
98970,
382,
14374,
2679... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1... |
1,661 | # RoboScript #3 - Implement the RS2 Specification
## Disclaimer
The story presented in this Kata Series is purely fictional; any resemblance to actual programming languages, products, organisations or people should be treated as purely coincidental.
## About this Kata Series
This Kata Series is based on a fictional... | ["from collections import deque\nimport re\n\nTOKENIZER = re.compile(r'(R+|F+|L+|\\)|\\()(\\d*)')\n\ndef parseCode(code):\n cmds = [[]]\n for cmd,n in TOKENIZER.findall(code):\n s,r = cmd[0], int(n or '1') + len(cmd)-1\n if cmd == '(': cmds.append([])\n elif cmd == ')': lst = cmds.pop() ; c... | {"fn_name": "execute", "inputs": [["LF5(RF3)(RF3R)F7"], ["(L(F5(RF3))(((R(F3R)F7))))"], ["F4L(F4RF4RF4LF4L)2F4RF4RF4"], ["F4L((F4R)2(F4L)2)2(F4R)2F4"], ["F2LF3L(F2)2LF5L(F3)2LF7L((F2)2)2L(F3)3L(F5)2"], ["F2LF3L(F2)2LF5L(F3)2LF7L(F4)2L((F3)1)3L(F5)2"], ["(F5RF5R(F3R)2)3"], ["((F5R)2(F3R)2)3"], ["((F3LF3R)2FRF6L)2"], ["(... | interview | https://www.codewars.com/kata/58738d518ec3b4bf95000192 |
def execute(code):
| [
2,
4892,
78,
5910,
671,
18,
481,
31075,
279,
23229,
17,
51277,
271,
565,
66829,
271,
785,
3364,
10449,
304,
419,
98838,
11131,
374,
31127,
43582,
26,
894,
68900,
311,
5042,
15473,
15459,
11,
3871,
11,
28433,
476,
1251,
1265,
387,
1175... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,225 | For strings s and t, we will say that s and t are prefix-free when neither is a prefix of the other.
Let L be a positive integer. A set of strings S is a good string set when the following conditions hold true:
- Each string in S has a length between 1 and L (inclusive) and consists of the characters 0 and 1.
- Any t... | ["import sys\ninput=sys.stdin.readline\nsys.setrecursionlimit(10**9)\nfrom collections import deque\n\nclass Node:\n def __init__(self,depth):\n self.depth=depth\n self.left=None\n self.right=None\n\ndef insert(node,s):\n n=node\n for i in range(len(s)):\n t=s[i]\n if t=='0':... | {"inputs": ["2 2\n00\n01\n", "2 2\n00\n11\n", "3 3\n0\n10\n110\n", "2 1\n0\n1\n", "1 2\n11\n", "2 3\n101\n11\n"], "outputs": ["Alice\n", "Bob\n", "Alice\n", "Bob\n", "Alice\n", "Bob\n"]} | competition | https://atcoder.jp/contests/arc087/tasks/arc087_c | [
2461,
9069,
274,
323,
259,
11,
582,
686,
1977,
429,
274,
323,
259,
525,
9252,
12577,
979,
13866,
374,
264,
9252,
315,
279,
1008,
624,
10061,
444,
387,
264,
6785,
7546,
13,
362,
738,
315,
9069,
328,
374,
264,
1661,
914,
738,
979,
2... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,630 | # Task
Smartphones software security has become a growing concern related to mobile telephony. It is particularly important as it relates to the security of available personal information.
For this reason, Ahmed decided to encrypt phone numbers of contacts in such a way that nobody can decrypt them. At first he tri... | ["def decrypt(s):\n return next((str(b // 11) for b in (int(str(a) + s) for a in range(1, 11)) if b % 11 == 0), 'impossible')", "def decrypt(s):\n for i in range(1,11):\n n = int(str(i)+s)\n if n//11*11==n : return str(n//11)\n return 'impossible'", "def decrypt(s):\n x, l = int(s), 10**len(s)\n ... | {"fn_name": "decrypt", "inputs": [["353"], ["444"], ["123456"], ["147"], ["4334"]], "outputs": [["123"], ["404"], ["738496"], ["377"], ["impossible"]]} | introductory | https://www.codewars.com/kata/58a3cb34623e8c119d0000d5 |
def decrypt(s):
| [
2,
5430,
198,
15770,
16729,
3162,
4763,
702,
3635,
264,
7826,
4643,
5435,
311,
6371,
7963,
29648,
13,
1084,
374,
7945,
2989,
438,
432,
35616,
311,
279,
4763,
315,
2500,
4345,
1995,
624,
715,
1752,
419,
2874,
11,
40669,
6635,
311,
2962... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,165 | Giant chess is quite common in Geraldion. We will not delve into the rules of the game, we'll just say that the game takes place on an h × w field, and it is painted in two colors, but not like in chess. Almost all cells of the field are white and only some of them are black. Currently Gerald is finishing a game of gia... | ["def init_factorials(N, mod):\n f = 1\n fac = [1] * N\n for i in range(1, N):\n f *= i\n f %= mod\n fac[i] = f\n return fac\n\ndef init_inv(N, mod, fac):\n b = bin(mod-2)[2:][-1::-1]\n ret = 1\n tmp = fac[N]\n if b[0] == '1':\n ret = fac[N]\n for bi in b[1:]:\n ... | {
"inputs": [
"3 4 2\n2 2\n2 3\n",
"100 100 3\n15 16\n16 15\n99 88\n",
"1000 1000 4\n50 50\n51 50\n50 51\n51 51\n",
"100000 100000 4\n50001 50001\n50000 50000\n50000 50001\n50001 50000\n",
"2 2 2\n2 1\n1 2\n",
"100 10 30\n40 4\n15 3\n75 3\n88 10\n32 1\n16 5\n81 8\n45 2\n72 8\n11 6\n86 4\n50 2\... | competition | https://codeforces.com/problemset/problem/559/C | [
38,
5372,
32719,
374,
5008,
4185,
304,
54257,
290,
13,
1205,
686,
537,
81745,
1119,
279,
5601,
315,
279,
1809,
11,
582,
3278,
1101,
1977,
429,
279,
1809,
4990,
1992,
389,
458,
305,
24768,
289,
2070,
11,
323,
432,
374,
23983,
304,
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,420 | Given two strings s and t , write a function to determine if t is an anagram of s.
Example 1:
Input: s = "anagram", t = "nagaram"
Output: true
Example 2:
Input: s = "rat", t = "car"
Output: false
Note:
You may assume the string contains only lowercase alphabets.
Follow up:
What if the inputs contain unicode c... | ["class Solution:\n def isAnagram(self, s, t):\n \"\"\"\n :type s: str\n :type t: str\n :rtype: bool\n \"\"\"\n # dic = {}\n # for item in s:\n # if item not in dic:\n # dic[item] = 1\n # else:\n # dic[it... | {"fn_name": "isAnagram", "inputs": [["\"anagram\"", "\"nagaram\""]], "outputs": [true]} | introductory | https://leetcode.com/problems/valid-anagram/ |
class Solution:
def isAnagram(self, s: str, t: str) -> bool:
| [
22043,
1378,
9069,
274,
323,
259,
4102,
11,
3270,
264,
729,
311,
8253,
421,
259,
374,
458,
458,
5745,
315,
274,
382,
13314,
220,
16,
24391,
2505,
25,
274,
284,
330,
276,
5745,
497,
259,
284,
330,
77,
351,
637,
698,
5097,
25,
830,
... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,869 | Define a function that removes duplicates from an array of numbers and returns it as a result.
The order of the sequence has to stay the same. | ["def distinct(seq):\n return sorted(set(seq), key = seq.index)", "def distinct(seq):\n result = []\n seen = set()\n for a in seq:\n if a not in seen:\n result.append(a)\n seen.add(a)\n return result", "# Using Set:\n# Time complexity | O(N)\ndef distinct(seq):\n result = ... | {"fn_name": "distinct", "inputs": [[[1]], [[1, 2]], [[1, 1, 2]], [[1, 1, 1, 2, 3, 4, 5]], [[1, 2, 2, 3, 3, 4, 4, 5, 6, 7, 7, 7]]], "outputs": [[[1]], [[1, 2]], [[1, 2]], [[1, 2, 3, 4, 5]], [[1, 2, 3, 4, 5, 6, 7]]]} | introductory | https://www.codewars.com/kata/57a5b0dfcf1fa526bb000118 |
def distinct(seq):
| [
35338,
264,
729,
429,
28160,
42328,
504,
458,
1334,
315,
5109,
323,
4675,
432,
438,
264,
1102,
382,
785,
1973,
315,
279,
8500,
702,
311,
4717,
279,
1852,
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
] |
669 | Nadaca is a country with N$N$ cities. These cities are numbered 1$1$ through N$N$ and connected by M$M$ bidirectional roads. Each city can be reached from every other city using these roads.
Initially, Ryan is in city 1$1$. At each of the following K$K$ seconds, he may move from his current city to an adjacent city (a ... | ["T = int(input())\nfor _ in range(T):\n N, M, K = [int(x) for x in input().split()]\n UV = [[int(x) for x in input().split()] for _ in range(M)]\n Q = int(input())\n AB = [[int(x) for x in input().split()] for _ in range(Q)]\n \n X = [[i] for i in range(N)]\n for u, v in UV:\n X[u - 1] += [v - 1]... | {"inputs": [["3", "4 3 3", "1 2", "1 3", "1 4", "0", "4 3 3", "1 2", "1 3", "1 4", "1", "2 2", "4 3 3", "1 2", "1 3", "1 4", "1", "2 1"]], "outputs": [["28", "4", "6"]]} | interview | https://www.codechef.com/problems/WNDR | [
45,
329,
17106,
374,
264,
3146,
448,
451,
3,
45,
3,
9720,
13,
4220,
9720,
525,
48826,
220,
16,
3,
16,
3,
1526,
451,
3,
45,
3,
323,
8433,
553,
386,
3,
44,
3,
14103,
44670,
19241,
13,
8886,
3283,
646,
387,
8643,
504,
1449,
1008,... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,831 | Tired of those repetitive javascript challenges? Here's a unique hackish one that should keep you busy for a while ;)
There's a mystery function which is already available for you to use. It's a simple function called `mystery`. It accepts a string as a parameter and outputs a string. The exercise depends on guessing ... | ["def solved(s):\n if len(s)&1:\n s = s[:len(s)//2]+s[len(s)//2+1:]\n return ''.join(sorted(s))", "def solved(string):\n b = str((len(string)-1)/2)\n b = int(b[:-2])\n if len(string)%2==1:\n c = string[:b] + string[b+1:]\n return ''.join(sorted(c))\n return ''.join(sorted(string))... | {"fn_name": "solved", "inputs": [], "outputs": []} | introductory | https://www.codewars.com/kata/531963f82dde6fc8c800048a |
def solved(string):
| [
51,
2690,
315,
1846,
58077,
35710,
11513,
30,
5692,
594,
264,
4911,
17086,
812,
825,
429,
1265,
2506,
498,
13028,
369,
264,
1393,
81142,
3862,
594,
264,
22531,
729,
892,
374,
2669,
2500,
369,
498,
311,
990,
13,
1084,
594,
264,
4285,
... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1... |
1,524 | Zombies zombies everywhere!!
In a parallel world of zombies, there are N zombies. There are infinite number of unused cars, each of same model only differentiated by the their colors. The cars are of K colors.
A zombie parent can give birth to any number of zombie-children (possibly zero), i.e. each zombie will have ... | ["ways=x=0\nval=10**9\nremi=((10**9)+7)\nt=int(input())\nfor i in range(t):\n n,k=list(map(int,input().split()))\n if t<=100 and n>=1 and k<=val:\n x=(k-1)**(n-1)\n ways=k*x\n ways=ways%remi\n print(ways)\n x=ways=0\n else:\n break", "test = int(input())\nfor i in range (1,test+1):\n a = input().split(\" \")\n n ... | {"inputs": [["2", "2 2", "3 3"]], "outputs": [["2", "12"]]} | interview | https://www.codechef.com/APRIL16/problems/BIPIN3 | [
57,
35694,
47073,
16852,
2928,
715,
641,
264,
15279,
1879,
315,
47073,
11,
1052,
525,
451,
47073,
13,
2619,
525,
23809,
1372,
315,
20006,
9331,
11,
1817,
315,
1852,
1614,
1172,
88042,
553,
279,
862,
7987,
13,
576,
9331,
525,
315,
730,... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,138 | Consider a game, wherein the player has to guess a target word. All the player knows is the length of the target word.
To help them in their goal, the game will accept guesses, and return the number of letters that are in the correct position.
Write a method that, given the correct word and the player's guess, return... | ["def count_correct_characters(c, g):\n if len(c) != len(g): raise Exception('Error')\n return sum(1 for i,j in zip(c,g) if i==j)", "def count_correct_characters(s, t):\n assert len(s) == len(t)\n return sum(a == b for a, b in zip(s, t))", "def count_correct_characters(correct, guess):\n if len(correct) ... | {"fn_name": "count_correct_characters", "inputs": [["dog", "car"], ["dog", "god"], ["dog", "cog"], ["dog", "cod"], ["dog", "bog"], ["dog", "dog"], ["abcde", "abcde"], ["same", "same"], ["z", "z"]], "outputs": [[0], [1], [2], [1], [2], [3], [5], [4], [1]]} | introductory | https://www.codewars.com/kata/5912ded3f9f87fd271000120 |
def count_correct_characters(correct, guess):
| [
37175,
264,
1809,
11,
41318,
279,
2781,
702,
311,
7942,
264,
2169,
3409,
13,
2009,
279,
2781,
8788,
374,
279,
3084,
315,
279,
2169,
3409,
382,
1249,
1492,
1105,
304,
862,
5795,
11,
279,
1809,
686,
4193,
60537,
11,
323,
470,
279,
137... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1... |
1,658 | The aim is to calculate `exponential(x)` (written `exp(x)` in most math libraries) as an irreducible fraction, the numerator of this fraction having a given number of digits.
We call this function `expand`, it takes two parameters, `x` of which we want to evaluate the exponential, `digits` which is the required number... | ["from fractions import Fraction\n\ndef expand(x, digit):\n step = 0\n fact = 1\n expo = Fraction(1)\n n = 10 ** len(str(x).split('.')[-1])\n x = Fraction(int(x * n), n)\n while expo.numerator < 10 ** (digit - 1):\n step += 1\n fact *= step\n expo += x ** step / fact\n return [... | {"fn_name": "expand", "inputs": [[1, 2], [1, 5], [1, 6], [10, 3], [10, 4], [10, 40], [10, 39], [10, 38], [1.5, 10], [1.6, 10], [1.7, 10], [1.7, 12], [1.7, 15], [1.8, 20], [2.0, 20], [1.95, 60]], "outputs": [[[65, 24]], [[109601, 40320]], [[109601, 40320]], [[683, 3]], [[1933, 3]], [[123934329054285820429389726875580721... | interview | https://www.codewars.com/kata/54f5f22a00ecc4184c000034 |
def expand(x, digit):
| [
785,
9213,
374,
311,
11047,
1565,
327,
59825,
2075,
46186,
320,
25569,
1565,
4580,
2075,
46186,
304,
1429,
6888,
20186,
8,
438,
458,
24870,
78285,
19419,
11,
279,
63533,
315,
419,
19419,
3432,
264,
2661,
1372,
315,
18509,
382,
1654,
161... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,601 | Your task is to construct a building which will be a pile of n cubes.
The cube at the bottom will have a volume of n^3, the cube above
will have volume of (n-1)^3 and so on until the top which will have a volume of 1^3.
You are given the total volume m of the building.
Being given m can you find the number n of cube... | ["def find_nb(m):\n n = 1\n volume = 0\n while volume < m:\n volume += n**3\n if volume == m:\n return n\n n += 1\n return -1", "def find_nb(m):\n n=s=0\n while True:\n n+=1\n s+=n\n k=s*s\n if k== m:\n return n\n elif k>m:\n r... | {"fn_name": "find_nb", "inputs": [[4183059834009], [24723578342962], [135440716410000], [40539911473216], [26825883955641], [41364076483082], [9541025211025], [112668204662785], [79172108332642], [1788719004901], [131443152397956], [1801879360282], [18262169777476], [11988186060816], [826691919076], [36099801072722], [... | introductory | https://www.codewars.com/kata/5592e3bd57b64d00f3000047 |
def find_nb(m):
| [
7771,
3383,
374,
311,
9245,
264,
4752,
892,
686,
387,
264,
26306,
315,
308,
54104,
624,
785,
23739,
518,
279,
5622,
686,
614,
264,
8123,
315,
308,
61,
18,
11,
279,
23739,
3403,
715,
14387,
614,
220,
8123,
315,
320,
77,
12,
16,
297... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,263 | For every string, after every occurrence of `'and'` and `'but'`, insert the substring `'apparently'` directly after the occurrence.
If input does not contain 'and' or 'but', return the original string. If a blank string, return `''`.
If substring `'apparently'` is already directly after an `'and'` and/or `'but'`, do ... | ["import re\n\ndef apparently(string):\n return re.sub(r'(?<=\\b(and|but)\\b(?! apparently\\b))', ' apparently', string)", "import re\napparently=lambda Q:re.sub(r'(?<=\\band|\\bbut)\\b(?! apparently\\b)',' apparently',Q)", "import re\nfrom functools import partial\n\napparently = partial(re.sub, r'(?<=\\b(and|but)\... | {"fn_name": "apparently", "inputs": [["A fast-food resteraunt down the street was grumbling my tummy but I could not go."], ["apparently"], ["and"], ["but"], ["but apparently"], ["and apparently"], ["but but but and and and"], [""], ["but and apparently apparently apparently apparently"], ["and apparentlybutactuallynot... | introductory | https://www.codewars.com/kata/5b049d57de4c7f6a6c0001d7 |
def apparently(string):
| [
2461,
1449,
914,
11,
1283,
1449,
31559,
315,
72911,
437,
6,
63,
323,
72911,
8088,
6,
7808,
5656,
279,
38449,
72911,
676,
30127,
6,
63,
5961,
1283,
279,
31559,
382,
2679,
1946,
1558,
537,
6644,
364,
437,
6,
476,
364,
8088,
516,
470,
... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,148 | # Story
John found a path to a treasure, and while searching for its precise location he wrote a list of directions using symbols `"^"`, `"v"`, `"<"`, `">"` which mean `north`, `east`, `west`, and `east` accordingly. On his way John had to try many different paths, sometimes walking in circles, and even missing the tr... | ["def simplify(p):\n new_p=[(0,0)]\n new_str=''\n x=0\n y=0\n for i in p:\n if i == '<':\n x-=1\n elif i == '>':\n x+=1\n elif i == '^':\n y+=1\n elif i == 'v':\n y-=1\n if (x,y) not in new_p:\n new_p.append((x,y))\... | {"fn_name": "simplify", "inputs": [["<>>"], [""], ["v>^<"], [">>>>"], ["^>>>>v"], ["<^^>v<^^^"], ["<^>>v<"], ["<^<<^^>>vv<<<>^^^v^"], ["v<<<<<^^^^^v>v>v>v>v>>"], [">^>^>^>^>^>^>v>v>v>v>v>v>v>v<"], ["^^^>>>>>>^^^<<<vvv<<<vvv"], ["^^^>>>>>>^^^<<<vvv<<<vv"], [">vv<<<^^^^>>>>>vvvvvv<<<<<<^^^^^^^^>>>>vv"], [">vv<<<^^^^>>>>>... | introductory | https://www.codewars.com/kata/56bcafba66a2ab39e6001226 |
def simplify(path):
| [
2,
15106,
271,
13079,
1730,
264,
1815,
311,
264,
31626,
11,
323,
1393,
15039,
369,
1181,
23560,
3728,
566,
6139,
264,
1140,
315,
17961,
1667,
17738,
53305,
61,
1,
7808,
53305,
85,
1,
7808,
1565,
22476,
1,
7808,
1565,
755,
39917,
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... |
2,361 | You are given an array $a$ of length $n$ consisting of zeros. You perform $n$ actions with this array: during the $i$-th action, the following sequence of operations appears: Choose the maximum by length subarray (continuous subsegment) consisting only of zeros, among all such segments choose the leftmost one; Let th... | ["from collections import defaultdict as dd\nfrom collections import deque\nimport bisect\nimport heapq\n\ndef ri():\n return int(input())\n\ndef rl():\n return list(map(int, input().split()))\n\n\ndef solve():\n n = ri()\n output = [0] * (n)\n\n Q = [(-n, 0 ,n - 1)]\n for i in range(1, n + 1):\n ... | {"inputs": ["6\n1\n2\n3\n4\n5\n6\n"], "outputs": ["1 \n1 2 \n2 1 3 \n3 1 2 4 \n2 4 1 3 5 \n3 4 1 5 2 6 \n"]} | introductory | https://codeforces.com/problemset/problem/1353/D | [
2610,
525,
2661,
458,
1334,
400,
64,
3,
315,
3084,
400,
77,
3,
30606,
315,
17516,
13,
1446,
2736,
400,
77,
3,
6168,
448,
419,
1334,
25,
2337,
279,
400,
72,
3,
12,
339,
1917,
11,
279,
2701,
8500,
315,
7525,
7952,
25,
220,
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... | |
2,344 | You are given a graph with $3 \cdot n$ vertices and $m$ edges. You are to find a matching of $n$ edges, or an independent set of $n$ vertices.
A set of edges is called a matching if no two edges share an endpoint.
A set of vertices is called an independent set if no two vertices are connected with an edge.
-----Inp... | ["import sys\ninput = sys.stdin.readline\n\nT = int(input())\nfor _ in range(T):\n N, M = list(map(int, input().split()))\n X = [[] for i in range(3*N)]\n for i in range(M):\n x, y = list(map(int, input().split()))\n x, y = min(x,y), max(x,y)\n X[x-1].append((y-1, i+1))\n \n MAT = []... | {
"inputs": [
"4\n1 2\n1 3\n1 2\n1 2\n1 3\n1 2\n2 5\n1 2\n3 1\n1 4\n5 1\n1 6\n2 15\n1 2\n1 3\n1 4\n1 5\n1 6\n2 3\n2 4\n2 5\n2 6\n3 4\n3 5\n3 6\n4 5\n4 6\n5 6\n"
],
"outputs": [
"Matching\n1 \nMatching\n1 \nIndSet\n3 4 \nMatching\n1 10 \n"
]
} | competition | https://codeforces.com/problemset/problem/1198/C | [
2610,
525,
2661,
264,
4771,
448,
400,
18,
1124,
50853,
308,
3,
17228,
323,
400,
76,
3,
12822,
13,
1446,
525,
311,
1477,
264,
12579,
315,
400,
77,
3,
12822,
11,
476,
458,
9489,
738,
315,
400,
77,
3,
17228,
382,
32,
738,
315,
1282... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1... | |
1,526 | Alice and Bob created $N$ and $M$ recipes, respectively ($N, M \ge 1$), and submitted them to Chef for evaluation. Each recipe is represented by a string containing only lowercase English letters. Let's denote Alice's recipes by $A_1, A_2, \ldots, A_N$ and Bob's recipes by $B_1, B_2, \ldots, B_M$.
Accidentally, Chef mi... | ["# v = [\"a\",\"e\",\"i\",\"o\",\"u\"]\n# for _ in range(int(input())):\n# n = int(input())\n# a,b = [],[]\n# for i in range(n):\n# s = input()\n# isa = True\n# for j in range(1,len(s) - 1):\n# if(s[j] in v):\n# if(s[j - 1] not in v and s[j + 1] not in v):\n# ... | {"inputs": [["2", "4", "aba", "abc", "bab", "aac", "3", "aba", "baab", "abc"]], "outputs": [["1.1250000", "0.0277778"]]} | interview | https://www.codechef.com/problems/WEIRDO | [
61686,
323,
14261,
3465,
400,
45,
3,
323,
400,
44,
3,
18627,
11,
15576,
1711,
45,
11,
386,
1124,
709,
220,
16,
3,
701,
323,
14634,
1105,
311,
35975,
369,
16460,
13,
8886,
11116,
374,
15251,
553,
264,
914,
8482,
1172,
42047,
6364,
... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,586 | # Background
My TV remote control has arrow buttons and an `OK` button.
I can use these to move a "cursor" on a logical screen keyboard to type "words"...
The screen "keyboard" layout looks like this
#tvkb {
width : 300px;
border: 5px solid gray; border-collapse: collapse;
}
#tvkb td {
color : or... | ["KEYBOARD = \"abcde123fghij456klmno789pqrst.@0uvwxyz_/\"\nMAP = {c: (i//8, i%8) for i,c in enumerate(KEYBOARD)}\n\ndef manhattan(*pts): return sum( abs(z2-z1) for z1,z2 in zip(*pts))\n\ndef tv_remote(word):\n return len(word) + sum( manhattan(MAP[was], MAP[curr]) for was,curr in zip('a'+word, word))", "def get... | {"fn_name": "tv_remote", "inputs": [["codewars"], ["does"], ["your"], ["solution"], ["work"], ["for"], ["these"], ["words"], ["mississippi"]], "outputs": [[36], [16], [23], [33], [20], [12], [27], [25], [35]]} | introductory | https://www.codewars.com/kata/5a5032f4fd56cb958e00007a |
def tv_remote(word):
| [
2,
24800,
271,
5050,
5883,
8699,
2524,
702,
17921,
12424,
323,
458,
1565,
3925,
63,
3137,
382,
40,
646,
990,
1493,
311,
3271,
264,
330,
17437,
1,
389,
264,
19819,
4171,
13625,
311,
943,
330,
5761,
1,
2146,
785,
4171,
330,
41713,
1,
... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,792 | # Task
You know the slogan `p`, which the agitators have been chanting for quite a while now. Roka has heard this slogan a few times, but he missed almost all of them and grasped only their endings. You know the string `r` that Roka has heard.
You need to determine what is the `minimal number` of times agitators r... | ["import re\ndef slogans(p,r):\n reg=re.compile(\"|\".join([p[i:] for i in range(len(p))]))\n return len(re.findall(reg,r))", "from re import findall\n\ndef slogans(p, r):\n return len(findall('|'.join(p[i:] for i in range(len(p))), r))", "def slogans(slogan,heard):\n li = []\n while heard:\n temp = l... | {"fn_name": "slogans", "inputs": [["glorytoukraine", "ukraineaineaine"], ["glorytoukraine", "ukraineaineainee"], ["glorytoukraine", "einene"], ["programming", "ingmingmming"], ["mcoecqwmjdudc", "dcoecqwmjdudcdcudc"], ["erjernhxvbqfjsj", "ernhxvbqfjsjjrnhxvbqfjsjjernhxvbqfjsj"], ["dhgusdlifons", "lifonsssdlifonsgusdlifo... | introductory | https://www.codewars.com/kata/58bf79fdc8bd4432d6000029 |
def slogans(p,r):
| [
2,
5430,
198,
1446,
1414,
279,
51537,
1565,
79,
7808,
892,
279,
933,
275,
2973,
614,
1012,
76574,
369,
5008,
264,
1393,
1431,
13,
431,
30766,
702,
6617,
419,
51537,
264,
2421,
3039,
11,
714,
566,
13628,
4558,
678,
315,
1105,
323,
48... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,909 | In recreational mathematics, a [Keith number](https://en.wikipedia.org/wiki/Keith_number) or repfigit number (short for repetitive Fibonacci-like digit) is a number in the following integer sequence:
`14, 19, 28, 47, 61, 75, 197, 742, 1104, 1537, 2208, 2580, 3684, 4788, 7385, 7647, 7909, ...` (sequence A007629 in the ... | ["def is_keith_number(n):\n numList = [int(i) for i in str(n)] # int array\n if len(numList) > 1: # min 2 digits\n itr = 0\n while numList[0] <= n:\n # replace array entries by its sum:\n numList[itr % len(numList)] = sum(numList)\n itr += 1\n if n in nu... | {"fn_name": "is_keith_number", "inputs": [[14], [10], [4], [28], [23], [0], [19], [47], [34], [61], [58], [75], [197], [742], [1104], [1537], [2208], [2697], [7385], [31331], [120284], [1084051], [44121607], [251133297], [96189170155], [11812665388886672], [855191324330802397989], [18354972585225358067718266], [4179620... | introductory | https://www.codewars.com/kata/590e4940defcf1751c000009 |
def is_keith_number(n):
| [
641,
36000,
37596,
11,
264,
508,
90328,
1372,
9533,
2428,
1110,
268,
33366,
2659,
25502,
14,
90328,
5500,
8,
476,
2064,
904,
275,
1372,
320,
8676,
369,
58077,
79683,
12681,
15723,
8,
374,
264,
1372,
304,
279,
2701,
7546,
8500,
1447,
6... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,737 | ```if:python,php
In this kata you will have to write a function that takes `litres` and `price_per_litre` as arguments. Purchases of 2 or more litres get a discount of 5 cents per litre, purchases of 4 or more litres get a discount of 10 cents per litre, and so on every two litres, up to a maximum discount of 25 cents ... | ["def fuel_price(litres, price_per_liter):\n discount = int(min(litres, 10)/2) * 5 / 100\n return round((price_per_liter - discount) * litres, 2)", "fuel_price = lambda l,p: round(l*(p-min(0.05*(l//2), 0.25)), 2)", "from bisect import bisect\n\n\ndef fuel_price(litres, price_per_liter):\n discount = (0, 5, 10,... | {"fn_name": "fuel_price", "inputs": [[10, 21.5], [40, 10], [15, 5.83]], "outputs": [[212.5], [390], [83.7]]} | introductory | https://www.codewars.com/kata/57b58827d2a31c57720012e8 |
def fuel_price(litres, price_per_liter):
| [
73594,
333,
25,
12669,
11,
1208,
198,
641,
419,
61688,
498,
686,
614,
311,
3270,
264,
729,
429,
4990,
1565,
31635,
416,
63,
323,
1565,
6555,
5678,
907,
48734,
63,
438,
5977,
13,
52692,
2264,
315,
220,
17,
476,
803,
87916,
633,
264,
... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,386 | # Right in the Center
_This is inspired by one of Nick Parlante's exercises on the [CodingBat](https://codingbat.com/java) online code practice tool._
Given a sequence of characters, does `"abc"` appear in the CENTER of the sequence?
The sequence of characters could contain more than one `"abc"`.
To define CENTER, ... | ["def is_in_middle(s):\n while len(s)>4:\n s = s[1:-1]\n return 'abc' in s", "def is_in_middle(seq):\n mid, rem = divmod(len(seq), 2)\n start = mid-1\n end = start+3\n \n if not rem: \n start -= 1\n \n return 'abc' in seq[start:end]\n", "def is_in_middle(s):\n return is_in_mi... | {"fn_name": "is_in_middle", "inputs": [["abc"], ["abcabcabc"], ["AAabcBBB"], ["AAAabcBB"], ["AAAAabcBB"], ["AAabcabcBB"], ["abcabcabcabc"], ["AabcBBB"], [""], ["ABC"], ["abcZ"], ["Yabc"]], "outputs": [[true], [true], [true], [true], [false], [false], [false], [false], [false], [false], [true], [true]]} | introductory | https://www.codewars.com/kata/5f5da7a415fbdc0001ae3c69 |
def is_in_middle(s):
| [
2,
10083,
304,
279,
5832,
271,
62,
1986,
374,
14606,
553,
825,
315,
14991,
94887,
4942,
594,
22932,
389,
279,
508,
77513,
58400,
9533,
2428,
1110,
48367,
13718,
905,
47200,
8,
2860,
2038,
6588,
5392,
34773,
22043,
264,
8500,
315,
5766,
... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,665 | Your job at E-Corp is both boring and difficult. It isn't made any easier by the fact that everyone constantly wants to have a meeting with you, and that the meeting rooms are always taken!
In this kata, you will be given an array. Each value represents a meeting room. Your job? Find the **first** empty one and return... | ["def meeting(rooms):\n try:\n return rooms.index('O')\n except ValueError:\n return 'None available!'\n", "def meeting(rooms):\n return rooms.index(\"O\") if \"O\" in rooms else \"None available!\"", "def meeting(rooms):\n return next((i for i, r in enumerate(rooms) if r == 'O'), 'None availa... | {"fn_name": "meeting", "inputs": [[["X", "O", "X"]], [["O", "X", "X", "X", "X"]], [["X", "X", "O", "X", "X"]], [["X"]]], "outputs": [[1], [0], [2], ["None available!"]]} | introductory | https://www.codewars.com/kata/57f604a21bd4fe771b00009c |
def meeting(rooms):
| [
7771,
2618,
518,
468,
7658,
30115,
374,
2176,
27759,
323,
5000,
13,
1084,
4436,
944,
1865,
894,
8661,
553,
279,
2097,
429,
5019,
14971,
6801,
311,
614,
264,
6438,
448,
498,
11,
323,
429,
279,
6438,
12026,
525,
2677,
4429,
2219,
641,
... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,827 | When provided with a number between 0-9, return it in words.
Input :: 1
Output :: "One".
If your language supports it, try using a switch statement. | ["def switch_it_up(n):\n return ['Zero','One','Two','Three','Four','Five','Six','Seven','Eight','Nine'][n]", "def switch_it_up(number):\n number_converter={0:\"Zero\",1:\"One\",2:\"Two\",3:\"Three\",4:\"Four\",5:\"Five\",6:\"Six\",7:\"Seven\",8:\"Eight\",9:\"Nine\"}\n return number_converter[number]", "def swi... | {"fn_name": "switch_it_up", "inputs": [[0], [1], [2], [3], [4], [5], [6], [7], [8], [9]], "outputs": [["Zero"], ["One"], ["Two"], ["Three"], ["Four"], ["Five"], ["Six"], ["Seven"], ["Eight"], ["Nine"]]} | introductory | https://www.codewars.com/kata/5808dcb8f0ed42ae34000031 |
def switch_it_up(number):
| [
4498,
3897,
448,
264,
1372,
1948,
220,
15,
12,
24,
11,
470,
432,
304,
4244,
382,
2505,
3504,
220,
16,
271,
5097,
3504,
330,
3966,
11436,
2679,
697,
4128,
11554,
432,
11,
1430,
1667,
264,
3398,
5114,
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
] |
2,260 | There are $n$ football teams in the world.
The Main Football Organization (MFO) wants to host at most $m$ games. MFO wants the $i$-th game to be played between the teams $a_i$ and $b_i$ in one of the $k$ stadiums.
Let $s_{ij}$ be the numbers of games the $i$-th team played in the $j$-th stadium. MFO does not want a... | ["import random\nimport math\n\ndef set_color(game, color):\n color_count[game[0]][game[2]] -= 1\n color_count[game[1]][game[2]] -= 1\n game[2] = color\n color_count[game[0]][game[2]] += 1\n color_count[game[1]][game[2]] += 1\n\ndef fix(node):\n minimum = math.inf\n maximum = 0\n\n for i in rang... | {
"inputs": [
"7 11 3\n4 7 8 10 10 9 3\n6 2\n6 1\n7 6\n4 3\n4 6\n3 1\n5 3\n7 5\n7 3\n4 2\n1 4\n",
"100 0 1\n629 909 904 632 485 339 719 758 724 769 180 866 743 470 103 114 871 523 19 826 224 381 445 978 978 814 729 622 75 899 94 484 108 719 29 897 671 311 421 965 616 381 394 866 681 990 826 65 443 3 495 997 7... | competition | https://codeforces.com/problemset/problem/1240/F | [
3862,
525,
400,
77,
3,
8964,
7263,
304,
279,
1879,
13,
4710,
785,
4697,
20761,
20395,
320,
44,
3788,
8,
6801,
311,
3468,
518,
1429,
400,
76,
3,
3868,
13,
386,
3788,
6801,
279,
400,
72,
3,
12,
339,
1809,
311,
387,
6342,
1948,
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... | |
3,027 | Given a board of `NxN`, distributed with tiles labeled `0` to `N² - 1`(inclusive):
A solved grid will have the tiles in order of label, left to right, top to bottom.
Return `true` if the board state is currently solved, and `false` if the board state is unsolved.
Input will always be a square 2d array.
For example... | ["def is_solved(board):\n curr = 0;\n for r in board:\n for c in r:\n if c != curr:\n return False;\n curr+=1;\n return True;", "def is_solved(board):\n board = sum(board, [])\n return board == sorted(board)", "def is_solved(board):\n return all( v==w for x,... | {"fn_name": "is_solved", "inputs": [[[[1, 0], [3, 2]]], [[[1, 0, 4], [3, 2, 7], [8, 5, 6]]], [[[6, 7, 8], [0, 1, 2], [3, 4, 5]]]], "outputs": [[false], [false], [false]]} | introductory | https://www.codewars.com/kata/5e28b3ff0acfbb001f348ccc |
def is_solved(board):
| [
22043,
264,
4479,
315,
1565,
91431,
45,
7808,
4237,
448,
20493,
29829,
1565,
15,
63,
311,
1565,
45,
29456,
481,
220,
16,
81556,
98361,
7731,
32,
27956,
5827,
686,
614,
279,
20493,
304,
1973,
315,
2383,
11,
2115,
311,
1290,
11,
1909,
... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1... |
555 | Sherlock Holmes has decided to start a new academy to some of the young lads. He has conducted several tests and finally selected N equally brilliant
students.Now he don't know whether to train all the N students or not. Now since Holmes was in a confusion, Watson came up with an idea. He wanted to
test the obedience... | ["t = eval(input())\n\nfor i in range(t):\n n = eval(input())\n a = list(map(int, input().split()))\n cnt = 2\n cnt1 = 2\n ll = len(a)\n if ll < 3:\n cnt1 = ll\n else:\n for j in range(2,ll):\n if a[j-1] + a[j-2] == a[j]:\n cnt += 1\n cnt1 = max(cnt1, cnt)\n else:\n cnt1 = max(cnt1, cnt)\n cnt = 2\n p... | {"inputs": [["2", "5", "2 3 5 1 2", "3", "1 2 3"]], "outputs": [["3", "3"]]} | interview | https://www.codechef.com/LOCAPR16/problems/ACDEMY | [
67259,
1023,
39301,
702,
6635,
311,
1191,
264,
501,
43345,
311,
1045,
315,
279,
3908,
326,
7664,
13,
1260,
702,
13075,
3807,
7032,
323,
5499,
4091,
451,
18308,
19752,
271,
37218,
13244,
566,
1513,
944,
1414,
3425,
311,
5426,
678,
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,058 | There is a popular apps named “Exbook” like “Facebook”. To sign up in this app , You have to make a strong password with more than 3 digits and less than 10 digits . But I am a pro hacker and so I make a Exbook hacking site . You need to login in this site to hack exbook account and then you will get a portal. You can ... | ["# cook your dish here\nt=int(input())\nfor i in range(0,t):\n p=input()\n l=list(p)\n for j in range(0,len(l)):\n l[j]=int(l[j])\n l[j]=l[j]-2\n for j in range(0,len(l)):\n l[j]=str(l[j])\n q=''.join(l)\n print(q)", "t=int(input())\nfor i in range(t):\n n=input()\n l=len(n... | {"inputs": [["2", "3527", "47269"]], "outputs": [["1305", "25047"]]} | interview | https://www.codechef.com/ABCC2020/problems/PASSHACK | [
3862,
374,
264,
5411,
10500,
6941,
1036,
840,
2190,
854,
1075,
1036,
20489,
11204,
2014,
1841,
705,
304,
419,
906,
1154,
1446,
614,
311,
1281,
264,
3746,
3552,
448,
803,
1091,
220,
18,
18509,
323,
2686,
1091,
220,
16,
15,
18509,
659,
... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1... | |
1,081 | A spy needs your help to encrypt a 5 letter message.
To encrypt the message the following steps are need to be done:
1)Each letter of the message will be converted to it's equivalent number (i.e A=0, B=1,..Z=25)
2)98, 57, 31, 45, 46 are the 5 numbers in the key.
3)Add the equivalent number of the first letter of the ... | ["# cook your dish here\nimport string \nfrom collections import OrderedDict\nfrom itertools import zip_longest\ndic = OrderedDict(zip(string.ascii_uppercase, range(0, 26)))\nkeys = [98, 57, 31, 45, 46]\nt = int(input()) # number of test cases\ns1 = []\nfor i in range(t):\n s = input()\n for i in s:\n if i in dic.... | {"inputs": [["2", "HELLO", "HELL"]], "outputs": [["BJQEI", "BJQE"]]} | interview | https://www.codechef.com/STRG2020/problems/ENCYP | [
32,
21236,
3880,
697,
1492,
311,
29625,
264,
220,
20,
6524,
1943,
13,
715,
1249,
29625,
279,
1943,
279,
2701,
7354,
525,
1184,
311,
387,
2814,
510,
16,
8,
4854,
6524,
315,
279,
1943,
686,
387,
16099,
311,
432,
594,
13578,
1372,
320,... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1... | |
1,815 | We have a string S of lowercase letters, and an integer array shifts.
Call the shift of a letter, the next letter in the alphabet, (wrapping around so that 'z' becomes 'a').
For example, shift('a') = 'b', shift('t') = 'u', and shift('z') = 'a'.
Now for each shifts[i] = x, we want to shift the first i+1 letters of S, x... | ["class Solution:\n def shiftingLetters(self, S: str, shifts: List[int]) -> str:\n # cumulative sum from back\n shifts[-1] = shifts[-1] % 26\n \n if len(shifts) >= 2:\n for i in range(len(shifts) - 2, -1, -1):\n shifts[i] += shifts[i + 1]\n shifts[... | interview | https://leetcode.com/problems/shifting-letters/ |
class Solution:
def shiftingLetters(self, S: str, shifts: List[int]) -> str:
| [
1654,
614,
264,
914,
328,
315,
42047,
11931,
11,
323,
458,
7546,
1334,
28635,
624,
7220,
279,
6407,
315,
264,
6524,
11,
279,
1790,
6524,
304,
279,
27790,
11,
320,
18718,
3629,
2163,
773,
429,
364,
89,
6,
9044,
364,
64,
1823,
50950,
... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,631 | There are two lists of different length. The first one consists of keys, the second one consists of values. Write a function ```createDict(keys, values)``` that returns a dictionary created from keys and values. If there are not enough values, the rest of keys should have a ```None``` value. If there not enough keys, j... | ["def createDict(keys, values):\n while len(keys) > len(values):\n values.append(None)\n \n dictionary = dict(list(zip(keys, values))) \n return dictionary\n", "def createDict(keys, values):\n return dict(zip(keys, values + [None]*(len(keys) - len(values))))", "def createDict(keys, values):\n r... | {"fn_name": "createDict", "inputs": [[[], []], [[], [1]], [["a"], []], [["a", "b", "c"], [1, 2, 3]], [["a", "b", "c", "d", "e"], [1, 2]], [["a", "b"], [1, 2, 3, 4]]], "outputs": [[{}], [{}], [{"a": null}], [{"a": 1, "b": 2, "c": 3}], [{"a": 1, "b": 2, "c": null, "d": null, "e": null}], [{"a": 1, "b": 2}]]} | introductory | https://www.codewars.com/kata/5533c2a50c4fea6832000101 |
def createDict(keys, values):
| [
3862,
525,
1378,
11469,
315,
2155,
3084,
13,
576,
1156,
825,
17167,
315,
6894,
11,
279,
2086,
825,
17167,
315,
2750,
13,
9645,
264,
729,
54275,
3182,
13448,
36131,
11,
2750,
8,
73594,
429,
4675,
264,
10997,
3465,
504,
6894,
323,
2750,... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1... |
1,296 | In Byteland there are N cities, numbered 1 through N. Some pairs of cities are connected by bi-directional roads in such a way that starting from any one city you can visit all other cities either directly or indirectly.
Chef is currently at city A and wants to visit all other cities in Byteland. Chef can only move ac... | ["import sys\nsys.setrecursionlimit(10**8)\n\nMOD = 10**9+7\n\nfac = [0]*(10**5+1)\ndef pre() :\n fac[0] = 1\n for i in range(1,10**5+1) :\n fac[i] = fac[i-1]*i\n fac[i] = fac[i]%MOD\n\ndef dfs(gp , vertex , visited , deg , ans) :\n visited[vertex] = 1\n stack = []\n stack.append(vertex)\n while len(stack)>0 :\n ver... | {"inputs": [["2", "3", "1 2", "1 3", "1", "5", "1 2", "1 3", "2 4", "2 5", "1"]], "outputs": [["2", "4"]]} | interview | https://www.codechef.com/LOCAPR16/problems/BLTOUR | [
641,
3216,
83,
18123,
1052,
525,
451,
9720,
11,
48826,
220,
16,
1526,
451,
13,
4329,
13530,
315,
9720,
525,
8433,
553,
6032,
33049,
278,
19241,
304,
1741,
264,
1616,
429,
5916,
504,
894,
825,
3283,
498,
646,
3947,
678,
1008,
9720,
2... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1... | |
1,039 | “I am not in danger, Skyler. I am the danger. A guy opens his door and gets shot, and you think that of me? No! I am the one who knocks!”
Skyler fears Walter and ponders escaping to Colorado. Walter wants to clean his lab as soon as possible and then go back home to his wife.
In order clean his lab, he has to achieve ... | ["t=int(input())\nfor i in range(t):\n ans=0\n x,y=list(map(int,input().split()))\n if y>x:\n if (y-x)%4==0:ans=3\n elif (y-x)%2==0: ans=2\n else: ans=1\n if y<x:\n if (y-x)%2==0:ans=1\n else: ans=2\n print(ans)\n", "# cook your dish here\nfor _ in range(int(input())):\n x,y = map(int,input().split())\n if x == y:... | {"inputs": [["3", "0 5", "4 -5", "0 10000001"]], "outputs": [["1", "2", "1"]]} | interview | https://www.codechef.com/problems/EOOPR | [
10168,
1079,
537,
304,
7978,
11,
14722,
1536,
13,
358,
1079,
279,
7978,
13,
362,
7412,
15885,
806,
6006,
323,
5221,
6552,
11,
323,
498,
1744,
429,
315,
752,
30,
2308,
0,
358,
1079,
279,
825,
879,
84669,
17839,
198,
45948,
1536,
2320... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,924 | Professor Oak has just begun learning Python and he wants to program his new Pokedex prototype with it.
For a starting point, he wants to instantiate each scanned Pokemon as an object that is stored at Pokedex's memory. He needs your help!
Your task is to:
1) Create a ```PokeScan``` class that takes in 3 arguments: ... | ["class PokeScan:\n def __init__(self, name, level, pkmntype):\n self.name = name\n self.level = level\n self.pkmntype = pkmntype\n\n def info(self):\n level_info = \"weak\" if self.level <= 20 else \"fair\" if self.level <= 50 else \"strong\"\n pkmntypes_info = {\"water\": \"we... | {"fn_name": "__init__", "inputs": [], "outputs": []} | introductory | https://www.codewars.com/kata/57520361f2dac757360018ce |
def __init__(self, name, level, pkmntype):
| [
47020,
18283,
702,
1101,
21376,
6832,
13027,
323,
566,
6801,
311,
2025,
806,
501,
393,
86331,
24052,
448,
432,
382,
2461,
264,
5916,
1459,
11,
566,
6801,
311,
40902,
1817,
47448,
27731,
438,
458,
1633,
429,
374,
9768,
518,
393,
86331,
... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,669 | Consider the following series:
`1, 2, 4, 8, 16, 22, 26, 38, 62, 74, 102, 104, 108, 116, 122`
It is generated as follows:
* For single digit integers, add the number to itself to get the next element.
* For other integers, multiply all the non-zero digits and add the result to the original number to get the next elem... | ["from operator import mul\nfrom functools import reduce\n\ndef genSequence(n):\n yield n\n while True:\n n += reduce(mul, [int(d) for d in str(n) if d != '0']) if n > 9 else n\n yield n\n\ndef extract(seq, v):\n return sorted(seq).index(v)\n\ndef convergence(n):\n gen1, genN = genSequence(1),... | {"fn_name": "convergence", "inputs": [[3], [5], [10], [15], [500], [5000]], "outputs": [[5], [6], [5], [2], [29], [283]]} | introductory | https://www.codewars.com/kata/59971e64bfccc70748000068 |
def convergence(n):
| [
37175,
279,
2701,
4013,
1447,
63,
16,
11,
220,
17,
11,
220,
19,
11,
220,
23,
11,
220,
16,
21,
11,
220,
17,
17,
11,
220,
17,
21,
11,
220,
18,
23,
11,
220,
21,
17,
11,
220,
22,
19,
11,
220,
16,
15,
17,
11,
220,
16,
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,499 | In a deck of cards, each card has an integer written on it.
Return true if and only if you can choose X >= 2 such that it is possible to split the entire deck into 1 or more groups of cards, where:
Each group has exactly X cards.
All the cards in each group have the same integer.
Example 1:
Input: deck = [1,2,3,4,4... | ["class Solution:\n def hasGroupsSizeX(self, deck: List[int]) -> bool:\n def findGCD(a,b):\n if b ==0:\n return a\n return findGCD(b, a%b)\n \n hash_cards = {}\n for card in deck:\n if card in hash_cards:\n hash_cards[card... | {"fn_name": "hasGroupsSizeX", "inputs": [[[1, 2, 3, 4, 4, 3, 2, 1]]], "outputs": [true]} | introductory | https://leetcode.com/problems/x-of-a-kind-in-a-deck-of-cards/ |
class Solution:
def hasGroupsSizeX(self, deck: List[int]) -> bool:
| [
641,
264,
9530,
315,
7411,
11,
1817,
3701,
702,
458,
7546,
5326,
389,
432,
624,
5598,
830,
421,
323,
1172,
421,
498,
646,
5157,
4102,
55,
2604,
220,
17,
1741,
429,
4102,
275,
374,
3204,
311,
6718,
279,
4453,
9530,
4102,
18122,
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... |
528 | Recently in JEC ants have become huge, the Principal is on a journey to snipe them !!
Principal has limited $N$ practice Bullets to practice so that he can be sure to kill ants.
- The Practice ground has max length $L$.
- There is a Limit X such that if the bullet is fired beyond this, it will destroy and it wont be of... | ["# cook your dish here\n\nfrom sys import stdin,stdout\nfrom collections import deque,defaultdict\nfrom math import ceil,floor,inf,sqrt,factorial,gcd,log\nfrom copy import deepcopy\nii1=lambda:int(stdin.readline().strip())\nis1=lambda:stdin.readline().strip()\niia=lambda:list(map(int,stdin.readline().strip().split()))... | {"inputs": [["2", "1 10", "2 10"]], "outputs": [["10", "4"]]} | interview | https://www.codechef.com/COPT2020/problems/ANTHUNT | [
45137,
304,
619,
7498,
60395,
614,
3635,
6765,
11,
279,
36309,
374,
389,
264,
11618,
311,
4131,
3444,
1105,
753,
4894,
31771,
702,
7199,
400,
45,
3,
6588,
13497,
9942,
311,
6588,
773,
429,
566,
646,
387,
2704,
311,
5505,
60395,
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... | |
752 | Many internet protocols these days include the option of associating a
media type with the content being sent.
The type is usually inferred from the file extension.
You are to write a program that facilitates the lookup of media types for
a number of files.
You will be given a table of media type associations that asso... | ["# cook your dish here\nn,m=list(map(int,input().split()))\na={}\nfor i in range(n):\n x,y=input().split()\n a[x]=y\nfor i in range(m):\n c=input().strip()\n if '.' not in c:\n print(\"unknown\")\n else:\n h=c.split('.')[-1]\n if h in a:\n print(a[h])\n else:\n print('unknown')\n \n \n", "# cook your dish her... | {"inputs": [["5 6", "html text/html", "htm text/html", "png image/png", "svg image/svg+xml", "txt text/plain", "index.html", "this.file.has.lots.of.dots.txt", "nodotsatall", "virus.exe", "dont.let.the.png.fool.you", "case.matters.TXT"]], "outputs": [["text/html", "text/plain", "unknown", "unknown", "unknown", "unknown"... | interview | https://www.codechef.com/problems/MIME2 | [
8441,
7602,
31785,
1493,
2849,
2924,
279,
2999,
315,
4097,
1095,
264,
198,
7399,
943,
448,
279,
2213,
1660,
3208,
624,
785,
943,
374,
5990,
67595,
504,
279,
1034,
8894,
624,
2610,
525,
311,
3270,
264,
2025,
429,
72533,
279,
18615,
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,219 | You have found $M$ different types of jewels in a mine and each type of jewel is present in an infinite number.
There are $N$ different boxes located at position $(1 ,2 ,3 ,...N)$.
Each box can collect jewels up to a certain number ( box at position $i$ have $i$ different partitions and each partition can collect at mo... | ["t = int(input())\nwhile t != 0:\n M = 1000000007\n n, m = list(map(int, input().split())) \n ans = 1\n tt = n//2\n tt = tt * (tt + 1)\n \n ans = pow(m, tt, M)\n \n print(ans)\n t -= 1\n \n \n", "# cook your dish here\nt = int(input())\nfor _ in range(t):\n nm = list(map(int,inpu... | {"inputs": [["2", "1 10", "5 2"]], "outputs": [["1", "64"]]} | interview | https://www.codechef.com/INRO2021/problems/JEWELMIN | [
2610,
614,
1730,
400,
44,
3,
2155,
4494,
315,
85031,
304,
264,
10485,
323,
1817,
943,
315,
65841,
374,
3042,
304,
458,
23809,
1372,
624,
3862,
525,
400,
45,
3,
2155,
14697,
7407,
518,
2309,
4930,
16,
1154,
17,
1154,
18,
1154,
1112,
... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,382 | ## Task
In this kata you'll be given a string of English digits "collapsed" together, like this:
`zeronineoneoneeighttwoseventhreesixfourtwofive`
Your task is to split the string back to digits:
`zero nine one one eight two seven three six four two five`
## Examples
```
three -> three
eightsix -> eight six
fivefour... | ["import re\n\ndef uncollapse(digits):\n return ' '.join(re.findall('zero|one|two|three|four|five|six|seven|eight|nine', digits))", "import re\n\ndef uncollapse(digits):\n return ' '.join(m.group() for m in re.finditer(r'zero|one|two|three|four|five|six|seven|eight|nine', digits))", "uncollapse=lambda s:__import_... | {"fn_name": "uncollapse", "inputs": [["three"], ["eightsix"], ["fivefourseven"], ["ninethreesixthree"], ["foursixeighttwofive"], ["fivethreefivesixthreenineonesevenoneeight"], ["threesevensevensixninenineninefiveeighttwofiveeightsixthreeeight"], ["zeroonetwothreefourfivesixseveneightnine"]], "outputs": [["three"], ["ei... | introductory | https://www.codewars.com/kata/5a626fc7fd56cb63c300008c |
def uncollapse(digits):
| [
565,
5430,
198,
641,
419,
61688,
498,
3278,
387,
2661,
264,
914,
315,
6364,
18509,
330,
42028,
1,
3786,
11,
1075,
419,
1447,
63,
7070,
263,
482,
603,
603,
67532,
15560,
960,
44607,
7858,
941,
34024,
15560,
1055,
533,
19324,
7771,
3383... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,410 | .task {
background: #fff;
color: #333;
padding: 25px;
box-sizing: border-box;
font-family: Comfortaa, sans-serif !important;
position: relative;
}
.task code, .task_code {
display: inline-block;
padding: 0;
border-radius: 2px;
margin: 0;
position: relative;
top: 6px;
background: bisque;
bord... | ["from math import floor, log\ndef count_sixes(n):\n return floor((n - n % 2) * log(2, 10))", "count_sixes=lambda n:len(str(1<<n-n%2))-1", "from math import log10, floor, log\n\ndef count_sixes(n):\n k = floor(log10(3) + (n - 1)*log10(2))\n return k - (k*log(10) > (n - (n & 1))*log(2))\n\n# x[n] = 2/3 + d if n is ... | {"fn_name": "count_sixes", "inputs": [[10]], "outputs": [[3]]} | introductory | https://www.codewars.com/kata/582110dc2fd420bf7f00117b |
def count_sixes(n):
| [
15034,
341,
220,
4004,
25,
671,
14092,
280,
220,
1894,
25,
671,
18,
18,
18,
280,
220,
5300,
25,
220,
17,
20,
1767,
280,
220,
3745,
60351,
25,
3886,
12625,
280,
220,
3301,
17190,
25,
43742,
5305,
11,
15510,
27566,
753,
15333,
280,
... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1... |
333 | Given an array of integers arr, you are initially positioned at the first index of the array.
In one step you can jump from index i to index:
i + 1 where: i + 1 < arr.length.
i - 1 where: i - 1 >= 0.
j where: arr[i] == arr[j] and i != j.
Return the minimum number of steps to reach the last index of the array.
Notice ... | ["from collections import deque\n\nclass Solution:\n def minJumps(self, arr: list) -> int:\n if len(arr) == 1:\n return 0\n graph = {}\n for i, n in enumerate(arr):\n if n in graph:\n graph[n].append(i)\n else:\n graph[n] = [i]\n ... | {"fn_name": "minJumps", "inputs": [[[100, -23, -23, 404, 100, 23, 23, 23, 3, 404]]], "outputs": [3]} | interview | https://leetcode.com/problems/jump-game-iv/ |
class Solution:
def minJumps(self, arr: List[int]) -> int:
| [
22043,
458,
1334,
315,
4102,
396,
67592,
2890,
11,
498,
525,
15102,
34228,
518,
279,
1156,
1922,
315,
279,
1334,
624,
641,
825,
3019,
498,
646,
7784,
504,
1922,
600,
311,
1922,
1447,
72,
488,
220,
16,
1380,
25,
4102,
72,
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... |
182 | Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.
The above elevation map is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 units of rain water (blue section) are being trapped. Thanks Marcos for cont... | ["class Solution:\n def trap(self, height):\n \"\"\"\n :type height: List[int]\n :rtype: int\n \"\"\"\n if not height:\n return 0\n result = 0\n left = 0\n right = len(height) - 1\n while left < right:\n if height[left] ... | {"fn_name": "trap", "inputs": [[[0, 1, 0, 2, 1, 0, 1, 3, 2, 1, 2, 1]]], "outputs": [6]} | interview | https://leetcode.com/problems/trapping-rain-water/ |
class Solution:
def trap(self, height: List[int]) -> int:
| [
22043,
308,
2477,
60935,
25780,
14064,
458,
26163,
2415,
1380,
279,
2374,
315,
1817,
3619,
374,
220,
16,
11,
12564,
1246,
1753,
3015,
432,
374,
2952,
311,
22862,
1283,
83253,
4192,
785,
3403,
26163,
2415,
374,
15251,
553,
1334,
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... |
3,590 | Given two arrays of strings, return the number of times each string of the second array appears in the first array.
#### Example
```python
array1 = ['abc', 'abc', 'xyz', 'cde', 'uvw']
array2 = ['abc', 'cde', 'uap']
```
How many times do the elements in `array2` appear in `array1`?
* `'abc'` appears twice in the fi... | ["def solve(a,b):\n return [a.count(e) for e in b]", "from collections import Counter\n\ndef solve(a,b):\n c = Counter(a)\n return [c[s] for s in b]", "def solve(a,b):\n return [a.count(x) for x in b]", "def solve(a,b):\n return list(map(a.count, b))", "def solve(haystack, needles):\n return [haystack... | {"fn_name": "solve", "inputs": [[["abc", "abc", "xyz", "abcd", "cde"], ["abc", "cde", "uap"]], [["abc", "xyz", "abc", "xyz", "cde"], ["abc", "cde", "xyz"]], [["quick", "brown", "fox", "is", "quick"], ["quick", "abc", "fox"]]], "outputs": [[[2, 1, 0]], [[2, 1, 2]], [[2, 0, 1]]]} | introductory | https://www.codewars.com/kata/59ca8e8e1a68b7de740001f4 |
def solve(a,b):
| [
22043,
1378,
18386,
315,
9069,
11,
470,
279,
1372,
315,
3039,
1817,
914,
315,
279,
2086,
1334,
7952,
304,
279,
1156,
1334,
382,
820,
13383,
271,
73594,
12669,
198,
1653,
16,
284,
2509,
13683,
516,
364,
13683,
516,
364,
28854,
516,
364... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,783 | ## Debug celsius converter
Your friend is traveling abroad to the United States so he wrote a program to convert fahrenheit to celsius. Unfortunately his code has some bugs.
Find the errors in the code to get the celsius converter working properly.
To convert fahrenheit to celsius:
```
celsius = (fahrenheit - 32) * ... | ["def weather_info (temp):\n c = convertToCelsius(temp)\n if (c <= 0):\n return (str(c) + \" is freezing temperature\")\n else:\n return (str(c) + \" is above freezing temperature\")\n \ndef convertToCelsius (temperature):\n celsius = (temperature - 32) * (5.0/9.0)\n return celsius", "#I nee... | {"fn_name": "weather_info ", "inputs": [], "outputs": []} | introductory | https://www.codewars.com/kata/55cb854deb36f11f130000e1 |
def weather_info (temp):
| [
565,
11091,
272,
40247,
27058,
271,
7771,
4238,
374,
20971,
22131,
311,
279,
3639,
4180,
773,
566,
6139,
264,
2025,
311,
5508,
282,
47910,
311,
272,
40247,
13,
18656,
806,
2038,
702,
1045,
22551,
382,
9885,
279,
5975,
304,
279,
2038,
... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,137 | ## A square of squares
You like building blocks. You especially like building blocks that are squares. And what you even like more, is to arrange them into a square of square building blocks!
However, sometimes, you can't arrange them into a square. Instead, you end up with an ordinary rectangle! Those blasted things!... | ["import math\ndef is_square(n):\n return n > -1 and math.sqrt(n) % 1 == 0;", "import math\n\ndef is_square(n): \n\n if n < 0:\n return False\n\n sqrt = math.sqrt(n)\n \n return sqrt.is_integer()", "def is_square(n): \n return n >= 0 and (n**0.5) % 1 == 0", "import math\ndef is_square(n):... | {"fn_name": "is_square", "inputs": [[-1], [25], [26]], "outputs": [[false], [true], [false]]} | introductory | https://www.codewars.com/kata/54c27a33fb7da0db0100040e |
def is_square(n):
| [
565,
362,
9334,
315,
31340,
198,
2610,
1075,
4752,
10010,
13,
1446,
5310,
1075,
4752,
10010,
429,
525,
31340,
13,
1597,
1128,
498,
1496,
1075,
803,
11,
374,
311,
30893,
1105,
1119,
264,
9334,
315,
9334,
4752,
10010,
2219,
11209,
11,
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... |
3,606 | In this kata, your task is to identify the pattern underlying a sequence of numbers. For example, if the sequence is [1, 2, 3, 4, 5], then the pattern is [1], since each number in the sequence is equal to the number preceding it, plus 1. See the test cases for more examples.
A few more rules :
pattern may contain neg... | ["from itertools import cycle\n\ndef find_pattern(s):\n diffs = [y - x for x, y in zip(s, s[1:])] \n for i in range(1, len(diffs) + 1):\n if len(diffs) % i == 0 and all(a == b for a, b in zip(diffs, cycle(diffs[:i]))): return diffs[:i]", "def find_pattern(seq):\n start, end = [], []\n for i in ran... | {"fn_name": "find_pattern", "inputs": [[[1, 2, 3, 4, 5]], [[1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1]], [[1, 5, 2, 3, 1, 5, 2, 3, 1]], [[1, 5, 4, 8, 7, 11, 10, 14, 13]], [[0, 1]], [[4, 5, 6, 8, 3, 4, 5, 6, 8, 3, 4, 5, 6, 8, 3, 4]], [[4, 5, 3, -2, -1, 0, -2, -7, -6]], [[4, 5, 6, 5, 3, 2, 3, 4, 5, 6, 5, 3, 2, 3,... | introductory | https://www.codewars.com/kata/596185fe9c3097a345000a18 |
def find_pattern(seq):
| [
641,
419,
61688,
11,
697,
3383,
374,
311,
10542,
279,
5383,
16533,
264,
8500,
315,
5109,
13,
1752,
3110,
11,
421,
279,
8500,
374,
508,
16,
11,
220,
17,
11,
220,
18,
11,
220,
19,
11,
220,
20,
1125,
1221,
279,
5383,
374,
508,
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... |
4,371 | Given a long number, return all the possible sum of two digits of it.
For example, `12345`: all possible sum of two digits from that number are:
[ 1 + 2, 1 + 3, 1 + 4, 1 + 5, 2 + 3, 2 + 4, 2 + 5, 3 + 4, 3 + 5, 4 + 5 ]
Therefore the result must be:
[ 3, 4, 5, 6, 5, 6, 7, 7, 8, 9 ] | ["from itertools import combinations\n\ndef digits(num):\n return list(map(sum, combinations(map(int,str(num)),2)))", "# Solution 1\ndef digits(num):\n return [int(a)+int(b) for i,a in enumerate(str(num)) for b in str(num)[(i+1):]]\n \n \n# Solution 2\ndef digits(num):\n from itertools import combination... | {"fn_name": "digits", "inputs": [[156], [81596], [3852], [3264128], [999999]], "outputs": [[[6, 7, 11]], [[9, 13, 17, 14, 6, 10, 7, 14, 11, 15]], [[11, 8, 5, 13, 10, 7]], [[5, 9, 7, 4, 5, 11, 8, 6, 3, 4, 10, 10, 7, 8, 14, 5, 6, 12, 3, 9, 10]], [[18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18]]]} | introductory | https://www.codewars.com/kata/5b4e474305f04bea11000148 |
def digits(num):
| [
22043,
264,
1293,
1372,
11,
470,
678,
279,
3204,
2629,
315,
1378,
18509,
315,
432,
382,
2461,
3110,
11,
1565,
16,
17,
18,
19,
20,
44622,
678,
3204,
2629,
315,
1378,
18509,
504,
429,
1372,
525,
1447,
262,
508,
220,
16,
488,
220,
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... |
675 | A permutation $p_1,p_2...p_N$ of $\{1, 2, ..., N\}$ is beautiful if $p_i \& p_{i+1}$ is greater than 0 for every $1 \leq i < N$ . You are given an integer $N$, and your task is toconstruct a beautiful permutation of length $N$ or determine that it's impossible.
Note that $a \& b$ denotes the bitwise AND of $a$ and $b$.... | ["import math\ndef ispoweroftwo(y):\n return math.ceil(math.log(y,2))==math.floor(math.log(y,2))\nt=int(input())\nfor i in range(t):\n n=int(input())\n \n a=[]\n if(ispoweroftwo(n) and n!=1):\n print(-1,end=\" \")\n if(n==1):\n print(1)\n \n if(n>=3 and not(ispoweroftwo(n))):\n a.append(2)\n a.append(3)\n a.append... | {"inputs": [["3", "4", "3", "5"]], "outputs": [["-1", "1 3 2", "2 3 1 5 4"]]} | interview | https://www.codechef.com/problems/POSAND | [
32,
58441,
400,
79,
62,
16,
7237,
62,
17,
1112,
79,
1604,
3,
315,
57960,
90,
16,
11,
220,
17,
11,
60353,
451,
59,
31716,
374,
6233,
421,
400,
79,
5318,
1124,
5,
281,
15159,
72,
10,
16,
31716,
374,
7046,
1091,
220,
15,
369,
144... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,375 | Consider the following numbers (where `n!` is `factorial(n)`):
```
u1 = (1 / 1!) * (1!)
u2 = (1 / 2!) * (1! + 2!)
u3 = (1 / 3!) * (1! + 2! + 3!)
...
un = (1 / n!) * (1! + 2! + 3! + ... + n!)
```
Which will win: `1 / n!` or `(1! + 2! + 3! + ... + n!)`?
Are these numbers going to `0` because of `1/n!` or to infinity du... | ["def going(n): \n s = 1.0\n for i in range(2, n + 1):\n s = s/i + 1\n return int(s * 1e6) / 1e6", "def going(n):\n factor = 1.0\n acc = 1.0\n for i in range(n, 1, -1):\n factor *= 1.0 / i\n acc += factor\n return int(acc * 1e6) / 1e6", "def going(n):\n a = 1.\n for i in... | {"fn_name": "going", "inputs": [[5], [6], [7], [8], [20], [30], [50], [113], [200], [523], [1011], [10110]], "outputs": [[1.275], [1.2125], [1.173214], [1.146651], [1.052786], [1.034525], [1.020416], [1.008929], [1.005025], [1.001915], [1.00099], [1.000098]]} | introductory | https://www.codewars.com/kata/55a29405bc7d2efaff00007c |
def going(n):
| [
37175,
279,
2701,
5109,
320,
2870,
1565,
77,
0,
63,
374,
1565,
37591,
530,
1445,
46186,
982,
13874,
3989,
84,
16,
284,
320,
16,
608,
220,
16,
16315,
353,
320,
16,
27584,
84,
17,
284,
320,
16,
608,
220,
17,
16315,
353,
320,
16,
0... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1... |
1,137 | Vishal Wants to buy 2 gifts for his best friend whose name is Annabelle(her age is 20), So they both went for shopping in a store. But Annabelle gave, Vishal a condition that she will accept this gifts only when the total price of the gifts is the same as her age times 100.
The store contains, a list of items whose pri... | ["test = int(input())\nANS = list()\nfor i in range(test):\n n = int(input())\n items = sorted(list(map(int, input().split())))\n c = 1\n for j in range(len(items)):\n if items[j] < 2000:\n t = 2000 - items[j]\n if t in items[j+1:]:\n ANS.append(\"Accepted\")\n c = 2\n break\n else:\n pass\n else:\n... | {"inputs": [["1", "5", "10 2 1000 50 1000"]], "outputs": [["Accepted"]]} | interview | https://www.codechef.com/ARYS2020/problems/BDYGFT | [
53,
812,
278,
77478,
311,
3695,
220,
17,
20609,
369,
806,
1850,
4238,
6693,
829,
374,
9305,
54167,
7,
1923,
4231,
374,
220,
17,
15,
701,
2055,
807,
2176,
3937,
369,
11919,
304,
264,
3553,
13,
1988,
9305,
54167,
6551,
11,
87152,
278,... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1... | |
749 | The Government of Siruseri is no different from any other when it comes to being "capital-centric" in its policies. Recently the government decided to set up a nationwide fiber-optic network to take Siruseri into the digital age. And as usual, this decision was implemented in a capital centric manner --- from each city... | ["n=int(input())\r\nl=[]\r\nfor i in range(n):\r\n\tl.append([int(x) for x in input().split()])\r\nd=[10**9]*(n)\r\nq=set([int(x) for x in range(1,n)])\r\nd[1]=0\r\n#print(q)\r\ndef extract():\r\n\tmini=10**9\r\n\to=0\r\n\tfor i in range(1,len(d)):\r\n\t\tif d[i]<mini and i in q:\r\n\t\t\tmini=d[i]\r\n\t\t\to=i\r\n\tq.... | {"inputs": [["4", "0 7 8 10", "7 0 4 5", "8 4 0 6", "10 5 6 0"]], "outputs": [["9"]]} | interview | https://www.codechef.com/IARCSJUD/problems/HISPDNET | [
785,
10212,
315,
16759,
872,
72,
374,
902,
2155,
504,
894,
1008,
979,
432,
4041,
311,
1660,
330,
65063,
64424,
1,
304,
1181,
10186,
13,
40996,
279,
3033,
6635,
311,
738,
705,
264,
27954,
23788,
56112,
292,
3922,
311,
1896,
16759,
872,... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1... | |
437 | An encoded string S is given. To find and write the decoded string to a tape, the encoded string is read one character at a time and the following steps are taken:
If the character read is a letter, that letter is written onto the tape.
If the character read is a digit (say d), the entire current tape is repeatedly w... | ["class Solution:\n def decodeAtIndex(self, S: str, K: int) -> str:\n size = 0\n # Find size = length of decoded string\n for c in S:\n if c.isdigit():\n size *= int(c)\n else:\n size += 1\n for c in reversed(S):\n K %= size\n... | {"fn_name": "decodeAtIndex", "inputs": [["\"leet2code3\"", 10]], "outputs": ["t"]} | interview | https://leetcode.com/problems/decoded-string-at-index/ |
class Solution:
def decodeAtIndex(self, S: str, K: int) -> str:
| [
2082,
20498,
914,
328,
374,
2661,
13,
4102,
2014,
1477,
323,
3270,
279,
29213,
914,
311,
264,
16971,
11,
279,
20498,
914,
374,
1349,
825,
3668,
518,
264,
882,
4102,
437,
279,
2701,
7354,
525,
4429,
1447,
2679,
279,
3668,
1349,
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... |
491 | Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz", so s will look like this: "...zabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcd....".
Now we have another string p. Your job is to find out how many unique non-empty substrings of p are present in s. In particular, your... | ["class Solution:\n def findSubstringInWraproundString(self, p):\n \"\"\"\n :type p: str\n :rtype: int\n \"\"\"\n pc = None\n sl = 0\n ll = {}\n \n for c in p:\n if pc and (ord(pc) + 1 == ord(c) or (pc == 'z' and c == 'a')):\n ... | {"fn_name": "findSubstringInWraproundString", "inputs": [["\"a\""]], "outputs": [2]} | interview | https://leetcode.com/problems/unique-substrings-in-wraparound-string/ |
class Solution:
def findSubstringInWraproundString(self, p: str) -> int:
| [
37175,
279,
914,
274,
311,
387,
279,
23809,
15061,
19454,
914,
315,
330,
67512,
497,
773,
274,
686,
1401,
1075,
419,
25,
38713,
89,
67512,
67512,
68644,
1934,
11436,
7039,
582,
614,
2441,
914,
281,
13,
4615,
2618,
374,
311,
1477,
700,... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,189 | T is playing a game with his friend, HL.
There are $n$ piles of stones, the $i$-th pile initially has $a_i$ stones.
T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen... | ["t = int(input())\n\nfor _ in range(t):\n n = int(input())\n a = list(map(int,input().split()))\n sumA = sum(a)\n TWins = False\n for elem in a:\n if elem > sumA // 2:\n TWins = True\n break\n if TWins or sumA % 2 != 0:\n print(\"T\")\n else:\n print(\"HL... | {
"inputs": [
"2\n1\n2\n2\n1 1\n",
"1\n4\n2 3 1 2\n",
"2\n2\n1 4\n3\n3 1 3\n",
"3\n2\n4 3\n4\n2 2 2 3\n3\n1 4 1\n",
"4\n5\n1 3 1 3 4\n1\n4\n1\n5\n2\n3 3\n",
"1\n3\n2 1 1\n",
"1\n4\n3 1 1 1\n",
"1\n7\n10 3 1 1 1 1 1\n"
],
"outputs": [
"T\nHL\n",
"HL\n",
"T\nT\n",
"T\... | competition | https://codeforces.com/problemset/problem/1396/B | [
51,
374,
5619,
264,
1809,
448,
806,
4238,
11,
52487,
382,
3862,
525,
400,
77,
3,
58772,
315,
26210,
11,
279,
400,
72,
3,
12,
339,
26306,
15102,
702,
400,
64,
5318,
3,
26210,
13,
4710,
51,
323,
52487,
686,
1896,
72362,
10577,
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... | |
4,802 | # Task
Follow the instructions in each failing test case to write logic that calculates the total price when ringing items up at a cash register.
# Purpose
Practice writing maintainable and extendable code.
# Intent
This kata is meant to emulate the real world where requirements change over time. This kata does not ... | ["import re\nclass Checkout(object):\n def __init__(self, d={}):\n self.pricing,self.total,self.fruits,self.free = d,0,{},{}\n \n def scan(self, n, qty=1):\n item = get_price(n)\n for i in range(qty):\n if not self.free.get(n, 0) : self.total += item ; self.fruits[n] = self.frui... | {"fn_name": "__init__", "inputs": [], "outputs": []} | introductory | https://www.codewars.com/kata/57c8d7f8484cf9c1550000ff |
def __init__(self, d={}):
| [
2,
5430,
198,
12480,
279,
11221,
304,
1817,
21394,
1273,
1142,
311,
3270,
12218,
429,
47417,
279,
2790,
3349,
979,
67043,
3589,
705,
518,
264,
8350,
4161,
382,
2,
29045,
198,
88492,
4378,
10306,
480,
323,
13036,
480,
2038,
13,
4710,
2... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1... |
1,672 | per nextum in unam tum XI conscribementis fac sic
vestibulo perlegementum da varo.
morde varo.
seqis cumula varum.
cis
per nextum in unam tum XI conscribementis fac sic
seqis decumulamenta da varo.
varum privamentum fodementum da aresulto.
varum tum III elevamentum tum V multiplicament... | ["f={}\n\nf[-40] = '-319993.68'\nf[-41] = '-344598.60'\nf[-42] = '-370433.52'\nf[-43] = '-397528.44'\nf[-44] = '-425913.37'\nf[-45] = '-455618.29'\nf[-46] = '-486673.22'\nf[-47] = '-519108.14'\nf[-48] = '-552953.07'\nf[-49] = '-588238.00'\nf[-50] = '-624992.93'\nf[-29] = '-121939.61'\nf[-30] = '-134994.52'\nf[-31] = '-... | {
"inputs": [
"0\n1\n-2\n-3\n-4\n-5\n-6\n-7\n-8\n-9\n10\n"
],
"outputs": [
""
]
} | interview | https://codeforces.com/problemset/problem/1331/G | [
712,
1790,
372,
304,
650,
309,
15394,
53243,
1585,
740,
65,
1114,
285,
3463,
52647,
271,
262,
90934,
8763,
817,
1937,
1114,
372,
2994,
762,
78,
382,
262,
4313,
450,
762,
78,
382,
262,
12981,
285,
12177,
5607,
762,
372,
382,
78055,
1... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.