description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
Thor is getting used to the Earth. As a gift Loki gave him a smartphone. There are n applications on this phone. Thor is fascinated by this phone. He has only one minor issue: he can't count the number of unread notifications generated by those applications (maybe Loki put a curse on it so he can't).
q events are abou... | import sys
n, m = list(map(int, input().split()))
k = 0
pos = 0
L = []
L1 = []
d = {i: [0, -1] for i in range(1, n + 1)}
for i in range(m):
a, b = list(map(int, sys.stdin.readline()[:-1].split()))
if a == 1:
d[b][0] += 1
k += 1
L.append(b)
elif a == 2:
k -= d[b][0]
d... | IMPORT ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ... |
By the age of three Smart Beaver mastered all arithmetic operations and got this summer homework from the amazed teacher:
You are given a sequence of integers a_1, a_2, ..., a_{n}. Your task is to perform on it m consecutive operations of the following type: For given numbers x_{i} and v_{i} assign value v_{i} to ele... | mod = 10**9
FibArray = [1, 1]
def fibonacci(n):
if n <= len(FibArray):
return FibArray[n - 1]
else:
temp_fib = fibonacci(n - 1) + fibonacci(n - 2)
FibArray.append(temp_fib)
return temp_fib
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
for _ in ran... | ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN V... |
By the age of three Smart Beaver mastered all arithmetic operations and got this summer homework from the amazed teacher:
You are given a sequence of integers a_1, a_2, ..., a_{n}. Your task is to perform on it m consecutive operations of the following type: For given numbers x_{i} and v_{i} assign value v_{i} to ele... | n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
for i in range(m):
t, l, r = list(map(int, input().split()))
if t == 1:
a[l - 1] = r
else:
s = 0
fiba = fibb = 1
for i in range(l - 1, r):
s += fiba * a[i]
fiba, fibb = fibb, fi... | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR VAR N... |
By the age of three Smart Beaver mastered all arithmetic operations and got this summer homework from the amazed teacher:
You are given a sequence of integers a_1, a_2, ..., a_{n}. Your task is to perform on it m consecutive operations of the following type: For given numbers x_{i} and v_{i} assign value v_{i} to ele... | import sys
f = [-1] * 200000
def fib(n):
if f[n] == -1:
k = n // 2
while k > 0 and f[k] == -1:
k = k / 2
for i in range(k, n):
f[i + 1] = f[i] + f[i - 1]
return f[n]
def solve(numbers, t, l, r, d):
if t == 1:
numbers[l - 1] = r
elif t == 2:
... | IMPORT ASSIGN VAR BIN_OP LIST NUMBER NUMBER FUNC_DEF IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR VAR FUNC_DEF IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUM... |
By the age of three Smart Beaver mastered all arithmetic operations and got this summer homework from the amazed teacher:
You are given a sequence of integers a_1, a_2, ..., a_{n}. Your task is to perform on it m consecutive operations of the following type: For given numbers x_{i} and v_{i} assign value v_{i} to ele... | n, m = map(int, input().split())
a = list(map(int, input().split()))
f = [1] * n
for i in range(2, n):
f[i] = f[i - 1] + f[i - 2]
for i in range(m):
t, l, r = map(int, input().split())
if t == 1:
a[l - 1] = r
else:
sum_lr = 0
for x in range(r - l + 1):
sum_lr += f[x] ... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR ... |
By the age of three Smart Beaver mastered all arithmetic operations and got this summer homework from the amazed teacher:
You are given a sequence of integers a_1, a_2, ..., a_{n}. Your task is to perform on it m consecutive operations of the following type: For given numbers x_{i} and v_{i} assign value v_{i} to ele... | n, m = map(int, input().split())
a = list(map(int, input().split()))
f = [1, 1]
for i in range(2, n + 1):
f.append(f[i - 1] + f[i - 2])
f[i] %= 10**9
for q in range(m):
z, l, r = map(int, input().split())
if z == 1:
a[l - 1] = r
else:
s = 0
for j in range(l - 1, r):
... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VA... |
By the age of three Smart Beaver mastered all arithmetic operations and got this summer homework from the amazed teacher:
You are given a sequence of integers a_1, a_2, ..., a_{n}. Your task is to perform on it m consecutive operations of the following type: For given numbers x_{i} and v_{i} assign value v_{i} to ele... | n, m = map(int, input().split())
d = [int(x) for x in input().split()]
f = [1, 1]
for i in range(n):
f.append((f[-1] + f[-2]) % 1000000000)
for i in range(m):
s = [int(x) for x in input().split()]
if s[0] == 1:
x = s[1] - 1
v = s[2]
d[x] = v
elif s[0] == 2:
r = s[2] - 1
... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VA... |
They declared Sonam as bewafa. Although she is not, believe me! She asked a number of queries to people regrading their position in a test. Now its your duty to remove her bewafa tag by answering simple queries. All the students who give test can score from 1 to 10^18. Lower the marks, better the rank. Now instead of d... | def construct(groups: list):
sum_ = 0
data = []
for group in groups:
data.append((sum_ + 1, group[0], group[1]))
sum_ += group[1] - group[0] + 1
return data
def search(tgt: int, data: list):
l = 0
r = len(data)
while l < r:
mid = l + (r - l) // 2
if data[mid... | FUNC_DEF VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER RETURN VAR FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR NUMB... |
They declared Sonam as bewafa. Although she is not, believe me! She asked a number of queries to people regrading their position in a test. Now its your duty to remove her bewafa tag by answering simple queries. All the students who give test can score from 1 to 10^18. Lower the marks, better the rank. Now instead of d... | class Solution:
def getTestMarks(self, n, q, r, l, rank, storeAnswer):
score = []
for i in range(1, n + 1):
score.append((l[i], r[i]))
score.sort()
cnt = []
for i in range(n):
curr = score[i][1] - score[i][0] + 1
if i == 0:
... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NU... |
They declared Sonam as bewafa. Although she is not, believe me! She asked a number of queries to people regrading their position in a test. Now its your duty to remove her bewafa tag by answering simple queries. All the students who give test can score from 1 to 10^18. Lower the marks, better the rank. Now instead of d... | class Solution:
def fun(self, arr, num):
i = 0
j = len(arr) - 1
mid = (i + j) // 2
while i <= j:
mid = (i + j) // 2
if arr[mid] > num:
j = mid - 1
elif arr[mid] < num:
i = mid + 1
else:
r... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR RETURN VAR FUNC_DEF ASSIGN VAR LIST EXPR FUNC_C... |
Find all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be a unique set of numbers.
Note:
All numbers will be positive integers.
The solution set must not contain duplicate combinations.
Example 1:
Input: k =... | class Solution:
def combinationSum3(self, k, n):
if n > 45:
return []
res = []
def rev(start, s, count, one):
if count == k and s == n:
res.append(one[:])
return
if count == k or s == n:
return
... | CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN LIST ASSIGN VAR LIST FUNC_DEF IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN IF VAR VAR VAR VAR RETURN FOR VAR FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR VAR VAR RETURN EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER BIN_OP VAR LIST VAR EXPR FUNC_CALL VAR NUMB... |
Find all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be a unique set of numbers.
Note:
All numbers will be positive integers.
The solution set must not contain duplicate combinations.
Example 1:
Input: k =... | class Solution:
def combinationSum3(self, k, n):
res = []
self.dfs(range(1, 10), k, n, 0, [], res)
return res
def dfs(self, nums, k, n, index, path, res):
if k == 0 and n == 0:
res.append(path)
return
for i in range(index, len(nums)):
... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER VAR VAR NUMBER LIST VAR RETURN VAR FUNC_DEF IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR LIST V... |
Find all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be a unique set of numbers.
Note:
All numbers will be positive integers.
The solution set must not contain duplicate combinations.
Example 1:
Input: k =... | class Solution:
def combinationSum3(self, k, n):
to_return = []
self.backtrack(to_return, [], k, n, 1)
return to_return
def backtrack(self, to_return, temp, k, n, start):
total = sum(temp)
if total > n:
return
if len(temp) == k and total == n:
... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR LIST VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN IF FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER EXP... |
Find all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be a unique set of numbers.
Note:
All numbers will be positive integers.
The solution set must not contain duplicate combinations.
Example 1:
Input: k =... | class Solution:
def combinationSum3(self, k, n):
res = []
self.dfs(res, [], 0, 0, 1, k, n)
return res
def dfs(self, res, cur, d, s, b, k, n):
if d == k and s == n:
res.append(cur)
return
for i in range(b, 10):
self.dfs(res, cur + [i],... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR LIST NUMBER NUMBER NUMBER VAR VAR RETURN VAR FUNC_DEF IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR LIST VAR BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR |
Find all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be a unique set of numbers.
Note:
All numbers will be positive integers.
The solution set must not contain duplicate combinations.
Example 1:
Input: k =... | class Solution:
result = []
def combinationSum3Util(self, candidates, current_subset, k, target, start):
if target == 0 and k == 0:
Solution.result.append(current_subset)
elif target != 0 and k != 0:
for i in range(start, len(candidates)):
current_candida... | CLASS_DEF ASSIGN VAR LIST FUNC_DEF IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP V... |
Find all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be a unique set of numbers.
Note:
All numbers will be positive integers.
The solution set must not contain duplicate combinations.
Example 1:
Input: k =... | class Solution:
def combinationSum3(self, k, n):
res, com = [], []
self.combination(n, res, com, 1, k)
return res
def combination(self, target, res, com, begin, k):
for i in range(begin, target + 1 if target < 9 else 10):
com.append(i)
if i == target and... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR LIST LIST EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR RETURN VAR FUNC_DEF FOR VAR FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR F... |
Find all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be a unique set of numbers.
Note:
All numbers will be positive integers.
The solution set must not contain duplicate combinations.
Example 1:
Input: k =... | class Solution:
def combinationSum3(self, k, n):
res = []
temp = []
idx = 1
self.backtracking(res, temp, n, k, idx)
return res
def backtracking(self, res, temp, n, k, idx):
if len(temp) == k and n == 0:
res.append(temp[:])
return
... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR RETURN VAR FUNC_DEF IF FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR F... |
Given a string s, remove all its adjacent duplicate characters recursively.
Note: For some test cases, the resultant string would be an empty string. In that case, the function should return the empty string only.
Example 1:
Input:
S = "geeksforgeek"
Output: "gksforgk"
Explanation:
g(ee)ksforg(ee)k -> gksforgk
Exampl... | class Solution:
def rremove(self, S):
def rem(s):
l = [s[0]]
i = 1
n = len(s)
while i < n:
if s[i] != s[i - 1]:
l += [s[i]]
else:
p = s[i]
j = i + 1
... | CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR LIST VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR LIST VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR WHILE VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR LIST VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR... |
Given a string s, remove all its adjacent duplicate characters recursively.
Note: For some test cases, the resultant string would be an empty string. In that case, the function should return the empty string only.
Example 1:
Input:
S = "geeksforgeek"
Output: "gksforgk"
Explanation:
g(ee)ksforg(ee)k -> gksforgk
Exampl... | class Solution:
def rremove(self, s):
sm = len(s)
is_con = True
while is_con:
is_con = False
buf = []
i = 0
while i < sm:
j = i + 1
while j < sm and s[j] == s[i]:
j += 1
if j ... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR F... |
Given a string s, remove all its adjacent duplicate characters recursively.
Note: For some test cases, the resultant string would be an empty string. In that case, the function should return the empty string only.
Example 1:
Input:
S = "geeksforgeek"
Output: "gksforgk"
Explanation:
g(ee)ksforg(ee)k -> gksforgk
Exampl... | class Solution:
def rremove(self, S):
ans = ""
if len(S) <= 1:
return S
for i in range(0, len(S)):
if i == 0:
if S[i] != S[i + 1]:
ans = ans + S[i]
elif i == len(S) - 1:
if S[i] != S[i - 1]:
... | CLASS_DEF FUNC_DEF ASSIGN VAR STRING IF FUNC_CALL VAR VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR VAR BIN... |
Given a string s, remove all its adjacent duplicate characters recursively.
Note: For some test cases, the resultant string would be an empty string. In that case, the function should return the empty string only.
Example 1:
Input:
S = "geeksforgeek"
Output: "gksforgk"
Explanation:
g(ee)ksforg(ee)k -> gksforgk
Exampl... | class Solution:
def rremove(self, s):
def remove(s, old):
if s == "":
return s
elif s == old:
return s
old = s
arr = list(s)
prev = 0
for i in range(1, len(s)):
if arr[i] == arr[i - 1]:
... | CLASS_DEF FUNC_DEF FUNC_DEF IF VAR STRING RETURN VAR IF VAR VAR RETURN VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER STRING IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER STRING... |
Given a string s, remove all its adjacent duplicate characters recursively.
Note: For some test cases, the resultant string would be an empty string. In that case, the function should return the empty string only.
Example 1:
Input:
S = "geeksforgeek"
Output: "gksforgk"
Explanation:
g(ee)ksforg(ee)k -> gksforgk
Exampl... | class Solution:
def rremove(self, S):
new = []
i = 0
n = len(S)
while i < len(S):
temp = 0
while i < n - 1 and S[i] == S[i + 1]:
temp = 1
i += 1
if temp == 0:
new.append(S[i])
i += 1
... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR VAR RET... |
Given a string s, remove all its adjacent duplicate characters recursively.
Note: For some test cases, the resultant string would be an empty string. In that case, the function should return the empty string only.
Example 1:
Input:
S = "geeksforgeek"
Output: "gksforgk"
Explanation:
g(ee)ksforg(ee)k -> gksforgk
Exampl... | class Solution:
def rremove(self, S):
if not S:
return S
global_dups = 0
final_string = ""
i = 0
while i < len(S):
duplicates = 0
j = i + 1
while j < len(S) and S[j] == S[i]:
duplicates = 1
globa... | CLASS_DEF FUNC_DEF IF VAR RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER RETURN VAR ... |
Given a string s, remove all its adjacent duplicate characters recursively.
Note: For some test cases, the resultant string would be an empty string. In that case, the function should return the empty string only.
Example 1:
Input:
S = "geeksforgeek"
Output: "gksforgk"
Explanation:
g(ee)ksforg(ee)k -> gksforgk
Exampl... | class Solution:
def rremove(self, s):
n = len(s)
word = []
i = 0
while i < len(s):
flag = 0
while i < n - 1 and s[i] == s[i + 1]:
i += 1
flag = 1
if not flag:
word.append(s[i])
i += 1
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR FUNC_CALL STRI... |
Given a string s, remove all its adjacent duplicate characters recursively.
Note: For some test cases, the resultant string would be an empty string. In that case, the function should return the empty string only.
Example 1:
Input:
S = "geeksforgeek"
Output: "gksforgk"
Explanation:
g(ee)ksforg(ee)k -> gksforgk
Exampl... | class Solution:
def rremove(self, S):
if len(S) < 2:
return S
i = 0
j = 1
is_duplicate = False
modified = False
non_duplicates = []
while j < len(S):
if S[j] == S[i]:
j += 1
is_duplicate = True
... | CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR AS... |
Given a string s, remove all its adjacent duplicate characters recursively.
Note: For some test cases, the resultant string would be an empty string. In that case, the function should return the empty string only.
Example 1:
Input:
S = "geeksforgeek"
Output: "gksforgk"
Explanation:
g(ee)ksforg(ee)k -> gksforgk
Exampl... | class Solution:
def rremove(self, s):
s1 = ""
while len(s1) != len(s):
s1 = s
s = self.fun(s)
return s
def fun(self, s):
ans = ""
n = len(s)
i = 0
while i < n:
if i < n - 1 and s[i] == s[i + 1]:
while i... | CLASS_DEF FUNC_DEF ASSIGN VAR STRING WHILE FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR VAR VAR BIN... |
Given a string s, remove all its adjacent duplicate characters recursively.
Note: For some test cases, the resultant string would be an empty string. In that case, the function should return the empty string only.
Example 1:
Input:
S = "geeksforgeek"
Output: "gksforgk"
Explanation:
g(ee)ksforg(ee)k -> gksforgk
Exampl... | class Solution:
def rremove(self, S):
def rems(S):
i = 0
ans = []
while i < len(S):
if i < len(S) - 1:
if S[i] == S[i + 1]:
while i < len(S) - 1 and S[i] == S[i + 1]:
i = i + 1
... | CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR FUNC_CALL VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASS... |
Given a string s, remove all its adjacent duplicate characters recursively.
Note: For some test cases, the resultant string would be an empty string. In that case, the function should return the empty string only.
Example 1:
Input:
S = "geeksforgeek"
Output: "gksforgk"
Explanation:
g(ee)ksforg(ee)k -> gksforgk
Exampl... | class Solution:
def rremove(self, S):
l = len(S)
a = []
d = False
for i in range(len(S)):
if i == 0:
if S[i] != S[i + 1]:
a.append(S[i])
elif i < len(S) - 1:
if S[i] != S[i + 1] and S[i] != S[i - 1]:
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR... |
Given a string s, remove all its adjacent duplicate characters recursively.
Note: For some test cases, the resultant string would be an empty string. In that case, the function should return the empty string only.
Example 1:
Input:
S = "geeksforgeek"
Output: "gksforgk"
Explanation:
g(ee)ksforg(ee)k -> gksforgk
Exampl... | class Solution:
def rremove(self, S):
new = [i for i in S]
st = []
i = 0
while i < len(S):
if st and st[-1] == S[i]:
while i < len(S) and S[i] == st[-1]:
i += 1
st.pop()
if i < len(S):
st.app... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR RETURN FUNC_CALL STRING VAR RETURN FUNC... |
Given a string s, remove all its adjacent duplicate characters recursively.
Note: For some test cases, the resultant string would be an empty string. In that case, the function should return the empty string only.
Example 1:
Input:
S = "geeksforgeek"
Output: "gksforgk"
Explanation:
g(ee)ksforg(ee)k -> gksforgk
Exampl... | class Solution:
def rremove(self, S):
def remove(s):
if s == "":
return ""
if len(s) == 1:
return s
if s[0] == s[1]:
new_s = ""
else:
new_s = s[0]
i = 1
while i < len(s) ... | CLASS_DEF FUNC_DEF FUNC_DEF IF VAR STRING RETURN STRING IF FUNC_CALL VAR VAR NUMBER RETURN VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR NUMBER IF VAR NUMBER ... |
Given a string s, remove all its adjacent duplicate characters recursively.
Note: For some test cases, the resultant string would be an empty string. In that case, the function should return the empty string only.
Example 1:
Input:
S = "geeksforgeek"
Output: "gksforgk"
Explanation:
g(ee)ksforg(ee)k -> gksforgk
Exampl... | class Solution:
def rremove(self, s):
a = ""
b = ""
if len(s) < 2:
return s
for i in range(len(s) - 1):
if s[i] == s[i + 1]:
a = s[i]
elif s[i] == a:
a = ""
else:
b += s[i]
if s[-... | CLASS_DEF FUNC_DEF ASSIGN VAR STRING ASSIGN VAR STRING IF FUNC_CALL VAR VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR VAR ASSIGN VAR STRING VAR VAR VAR IF VAR NUMBER VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RET... |
Given a string s, remove all its adjacent duplicate characters recursively.
Note: For some test cases, the resultant string would be an empty string. In that case, the function should return the empty string only.
Example 1:
Input:
S = "geeksforgeek"
Output: "gksforgk"
Explanation:
g(ee)ksforg(ee)k -> gksforgk
Exampl... | class Solution:
def rremove(self, S):
s_list = list(S)
ns = self._remove(s_list)
return "".join(ns)
def _remove(self, s_lst):
ns = []
prv = None
lprv = None
for c in s_lst:
if c != prv:
ns.append(c)
elif lprv != c:... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR RETURN FUNC_CALL STRING VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NONE ASSIGN VAR NONE FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN VAR RE... |
Given a string s, remove all its adjacent duplicate characters recursively.
Note: For some test cases, the resultant string would be an empty string. In that case, the function should return the empty string only.
Example 1:
Input:
S = "geeksforgeek"
Output: "gksforgk"
Explanation:
g(ee)ksforg(ee)k -> gksforgk
Exampl... | class Solution:
def rremove(self, s):
res = ""
i = 0
while i < len(s):
if i + 1 < len(s) and s[i] == s[i + 1]:
i += 1
while i < len(s) and s[i] == s[i - 1]:
i += 1
else:
res += s[i]
i... | CLASS_DEF FUNC_DEF ASSIGN VAR STRING ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR VAR VAR NUMBER RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR |
Given a string s, remove all its adjacent duplicate characters recursively.
Note: For some test cases, the resultant string would be an empty string. In that case, the function should return the empty string only.
Example 1:
Input:
S = "geeksforgeek"
Output: "gksforgk"
Explanation:
g(ee)ksforg(ee)k -> gksforgk
Exampl... | class Solution:
def rremove(self, S):
if len(S) == 0:
return ""
length = len(S)
dupl_nums = 1
store = []
i = 0
while i < length - 1:
if S[i] == S[i + 1]:
start_dupl = i
dupl_nums = 2
k = i + 2
... | CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER ... |
Given a string s, remove all its adjacent duplicate characters recursively.
Note: For some test cases, the resultant string would be an empty string. In that case, the function should return the empty string only.
Example 1:
Input:
S = "geeksforgeek"
Output: "gksforgk"
Explanation:
g(ee)ksforg(ee)k -> gksforgk
Exampl... | class Solution:
def rremove(self, S):
ans = ""
duplicate = True
while duplicate:
i = 0
duplicate = False
while i < len(S):
count = 1
while i < len(S) - 1 and S[i] == S[i + 1]:
count += 1
... | CLASS_DEF FUNC_DEF ASSIGN VAR STRING ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR VAR VAR VAR NUMBER IF VAR ASSIGN VAR VAR AS... |
Given a string s, remove all its adjacent duplicate characters recursively.
Note: For some test cases, the resultant string would be an empty string. In that case, the function should return the empty string only.
Example 1:
Input:
S = "geeksforgeek"
Output: "gksforgk"
Explanation:
g(ee)ksforg(ee)k -> gksforgk
Exampl... | class Solution:
def remove(self, S):
ans = ""
n = len(S)
i = 0
while i < n:
if i < n - 1 and S[i] == S[i + 1]:
while i < n - 1 and S[i] == S[i + 1]:
i += 1
else:
ans += S[i]
i += 1
return... | CLASS_DEF FUNC_DEF ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR STRING WHILE FUNC_CALL VAR VAR FUNC_CALL VAR... |
Given a string s, remove all its adjacent duplicate characters recursively.
Note: For some test cases, the resultant string would be an empty string. In that case, the function should return the empty string only.
Example 1:
Input:
S = "geeksforgeek"
Output: "gksforgk"
Explanation:
g(ee)ksforg(ee)k -> gksforgk
Exampl... | class Solution:
def rremove(self, S):
newS = ""
if len(S) == 0:
return ""
if len(S) == 1:
return S
c = "%"
S += "&"
for i in range(len(S) - 1):
if S[i] == S[i + 1]:
c = S[i]
newS += "#"
e... | CLASS_DEF FUNC_DEF ASSIGN VAR STRING IF FUNC_CALL VAR VAR NUMBER RETURN STRING IF FUNC_CALL VAR VAR NUMBER RETURN VAR ASSIGN VAR STRING VAR STRING FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR STRING IF VAR VAR VAR VAR STRING ASSIGN VAR STRING VAR VAR VAR ... |
Given a string s, remove all its adjacent duplicate characters recursively.
Note: For some test cases, the resultant string would be an empty string. In that case, the function should return the empty string only.
Example 1:
Input:
S = "geeksforgeek"
Output: "gksforgk"
Explanation:
g(ee)ksforg(ee)k -> gksforgk
Exampl... | class Solution:
def rremove(self, S):
q = [S]
newS = ""
while len(q):
root = q.pop(0)
flg = True
newS = ""
i = 0
while i < len(root):
j = i + 1
fl = True
while j < len(root) and root[... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST VAR ASSIGN VAR STRING WHILE FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIG... |
Given a N x N matrix such that each of its cells contains some coins. Count the number of ways to collect exactly K coins while moving from top left corner of the matrix to the bottom right. From a cell (i, j), you can only move to (i+1, j) or (i, j+1).
Example 1:
Input:
K = 12, N = 3
arr[] = [[1, 2, 3],
[4, ... | class Solution:
def numberOfPath(self, N, K, arr):
def func(ind1, ind2, k, arr, dp, n):
if ind1 >= n or ind2 >= n:
return 0
if k < 0:
return 0
if ind1 == n - 1 and ind2 == n - 1:
if k == arr[ind1][ind2]:
... | CLASS_DEF FUNC_DEF FUNC_DEF IF VAR VAR VAR VAR RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER IF VAR VAR VAR VAR NUMBER RETURN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR ASSIGN... |
Given a N x N matrix such that each of its cells contains some coins. Count the number of ways to collect exactly K coins while moving from top left corner of the matrix to the bottom right. From a cell (i, j), you can only move to (i+1, j) or (i, j+1).
Example 1:
Input:
K = 12, N = 3
arr[] = [[1, 2, 3],
[4, ... | class Solution:
def numberOfPath(self, N, K, arr):
dp = {}
def fun(i, j, su):
if i >= N or j >= N:
return 0
if i == N - 1 and j == N - 1:
if su == arr[i][j]:
return 1
else:
return 0
... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT FUNC_DEF IF VAR VAR VAR VAR RETURN NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR VAR VAR VAR RETURN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VA... |
Given a N x N matrix such that each of its cells contains some coins. Count the number of ways to collect exactly K coins while moving from top left corner of the matrix to the bottom right. From a cell (i, j), you can only move to (i+1, j) or (i, j+1).
Example 1:
Input:
K = 12, N = 3
arr[] = [[1, 2, 3],
[4, ... | import sys
sys.setrecursionlimit(10**6)
class Solution:
dp = [[([-1] * 101) for i in range(101)] for i in range(101)]
a = [([0] * 101) for i in range(101)]
def go(self, n, m, k):
if k < 0:
return 0
if m < 0 or n < 0:
return 0
if n == 0 and m == 0:
... | IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER CLASS_DEF ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VA... |
Given a N x N matrix such that each of its cells contains some coins. Count the number of ways to collect exactly K coins while moving from top left corner of the matrix to the bottom right. From a cell (i, j), you can only move to (i+1, j) or (i, j+1).
Example 1:
Input:
K = 12, N = 3
arr[] = [[1, 2, 3],
[4, ... | def pathCountDPRecDP(mat, m, n, k, dp):
if m < 0 or n < 0 or k < 0:
return 0
elif m == 0 and n == 0:
return k == mat[m][n]
if dp[m][n][k] != -1:
return dp[m][n][k]
dp[m][n][k] = pathCountDPRecDP(mat, m - 1, n, k - mat[m][n], dp) + pathCountDPRecDP(
mat, m, n - 1, k - mat[... | FUNC_DEF IF VAR NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN VAR VAR VAR VAR IF VAR VAR VAR VAR NUMBER RETURN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR VAR ... |
Given a N x N matrix such that each of its cells contains some coins. Count the number of ways to collect exactly K coins while moving from top left corner of the matrix to the bottom right. From a cell (i, j), you can only move to (i+1, j) or (i, j+1).
Example 1:
Input:
K = 12, N = 3
arr[] = [[1, 2, 3],
[4, ... | class Solution:
def numberOfPath(self, N, K, arr):
paths = {}
for y in range(N - 1, -1, -1):
for x in range(N - 1, -1, -1):
coord = x, y
coins = arr[x][y]
if x < N - 1:
x_paths = paths.get((x + 1, y), {})
... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR DICT ASSIGN VAR DICT IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_C... |
Given a N x N matrix such that each of its cells contains some coins. Count the number of ways to collect exactly K coins while moving from top left corner of the matrix to the bottom right. From a cell (i, j), you can only move to (i+1, j) or (i, j+1).
Example 1:
Input:
K = 12, N = 3
arr[] = [[1, 2, 3],
[4, ... | class Solution:
def numberOfPath(self, N, K, A):
def _solve(r, c, left):
if r >= N or c >= N:
return 0
cell = A[r][c]
if cell > left:
return 0
if r == c == N - 1:
return 1 if left == cell else 0
v =... | CLASS_DEF FUNC_DEF FUNC_DEF IF VAR VAR VAR VAR RETURN NUMBER ASSIGN VAR VAR VAR VAR IF VAR VAR RETURN NUMBER IF VAR VAR BIN_OP VAR NUMBER RETURN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NUMBER RETURN VAR ASSIGN VAR VAR VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR... |
Given a N x N matrix such that each of its cells contains some coins. Count the number of ways to collect exactly K coins while moving from top left corner of the matrix to the bottom right. From a cell (i, j), you can only move to (i+1, j) or (i, j+1).
Example 1:
Input:
K = 12, N = 3
arr[] = [[1, 2, 3],
[4, ... | class Solution:
def pathCountDPRecDP(self, mat, m, n, k, dp):
if m < 0 or n < 0 or k < 0:
return 0
elif m == 0 and n == 0:
return 1 if k == mat[m][n] else 0
if dp[m][n][k] != -1:
return dp[m][n][k]
dp[m][n][k] = self.pathCountDPRecDP(
... | CLASS_DEF FUNC_DEF IF VAR NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN VAR VAR VAR VAR NUMBER NUMBER IF VAR VAR VAR VAR NUMBER RETURN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER BIN... |
Given a N x N matrix such that each of its cells contains some coins. Count the number of ways to collect exactly K coins while moving from top left corner of the matrix to the bottom right. From a cell (i, j), you can only move to (i+1, j) or (i, j+1).
Example 1:
Input:
K = 12, N = 3
arr[] = [[1, 2, 3],
[4, ... | def helper(i, j, s, arr, n, m, dp):
if not i and not j:
return 1 if s == arr[i][j] else 0
if i < 0 or j < 0 or s < 1:
return 0
if dp[i][j][s] != -1:
return dp[i][j][s]
up = helper(i - 1, j, s - arr[i][j], arr, n, m, dp)
dn = helper(i, j - 1, s - arr[i][j], arr, n, m, dp)
... | FUNC_DEF IF VAR VAR RETURN VAR VAR VAR VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR VAR VAR VAR NUMBER RETURN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR VAR VAR ... |
Given a N x N matrix such that each of its cells contains some coins. Count the number of ways to collect exactly K coins while moving from top left corner of the matrix to the bottom right. From a cell (i, j), you can only move to (i+1, j) or (i, j+1).
Example 1:
Input:
K = 12, N = 3
arr[] = [[1, 2, 3],
[4, ... | class Solution:
def solve(self, mat, m, n, k, dp):
if m < 0 or n < 0 or k < 0:
return 0
elif m == 0 and n == 0:
if k == mat[m][n]:
return 1
return 0
if (m, n, k) in dp:
return dp[m, n, k]
dp[m, n, k] = self.solve(mat, m... | CLASS_DEF FUNC_DEF IF VAR NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER IF VAR VAR VAR VAR RETURN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ... |
Given a N x N matrix such that each of its cells contains some coins. Count the number of ways to collect exactly K coins while moving from top left corner of the matrix to the bottom right. From a cell (i, j), you can only move to (i+1, j) or (i, j+1).
Example 1:
Input:
K = 12, N = 3
arr[] = [[1, 2, 3],
[4, ... | class Solution:
def numberOfPath(self, N, K, arr):
dp = [[[(-1) for _ in range(K + 1)] for _ in range(N)] for _ in range(N)]
return self.solve(arr, dp, N, K, 0, 0, 0)
def solve(self, arr, dp, N, K, x, y, k):
if x >= N or y >= N or x < 0 or y < 0 or k + arr[x][y] > K:
return... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR VAR VAR VAR NUMBER NUMBER NUMBER FUNC_DEF IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER BIN_OP VAR VAR VAR VAR VAR RETURN NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP ... |
Given a N x N matrix such that each of its cells contains some coins. Count the number of ways to collect exactly K coins while moving from top left corner of the matrix to the bottom right. From a cell (i, j), you can only move to (i+1, j) or (i, j+1).
Example 1:
Input:
K = 12, N = 3
arr[] = [[1, 2, 3],
[4, ... | class Solution:
def numberOfPath(self, N, K, arr):
return self.paths(0, 0, K, arr, N, {})
def paths(self, cr, cc, K, arr, N, memo):
if cr >= N or cc >= N:
return 0
if cr == N - 1 and cc == N - 1:
if K - arr[cr][cc] != 0:
return 0
if cr ==... | CLASS_DEF FUNC_DEF RETURN FUNC_CALL VAR NUMBER NUMBER VAR VAR VAR DICT FUNC_DEF IF VAR VAR VAR VAR RETURN NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER RETURN NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP B... |
Given a N x N matrix such that each of its cells contains some coins. Count the number of ways to collect exactly K coins while moving from top left corner of the matrix to the bottom right. From a cell (i, j), you can only move to (i+1, j) or (i, j+1).
Example 1:
Input:
K = 12, N = 3
arr[] = [[1, 2, 3],
[4, ... | class Solution:
def numberOfPath(self, N, K, M):
return dfs(0, 0, M, N, K - M[0][0], {})
def dfs(r, c, M, N, K, memo):
if (r, c, K) in memo:
return memo[r, c, K]
if K < 0:
return 0
if (r, c) == (N - 1, N - 1):
if K == 0:
return 1
return 0
ans = ... | CLASS_DEF FUNC_DEF RETURN FUNC_CALL VAR NUMBER NUMBER VAR VAR BIN_OP VAR VAR NUMBER NUMBER DICT FUNC_DEF IF VAR VAR VAR VAR RETURN VAR VAR VAR VAR IF VAR NUMBER RETURN NUMBER IF VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR VAR LIST BIN_OP VAR NUMBER VAR... |
Given a N x N matrix such that each of its cells contains some coins. Count the number of ways to collect exactly K coins while moving from top left corner of the matrix to the bottom right. From a cell (i, j), you can only move to (i+1, j) or (i, j+1).
Example 1:
Input:
K = 12, N = 3
arr[] = [[1, 2, 3],
[4, ... | class Solution:
def numberOfPath(self, N, K, arr):
if not arr:
return
if N == 1 and K > arr[0][0]:
return 0
dp = [
[[(-1) for col in range(K + 1)] for col in range(N + 1)]
for row in range(N + 1)
]
def pathCountDPRecDP(arr, m,... | CLASS_DEF FUNC_DEF IF VAR RETURN IF VAR NUMBER VAR VAR NUMBER NUMBER RETURN NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_DEF IF VAR NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR RETURN N... |
Given a N x N matrix such that each of its cells contains some coins. Count the number of ways to collect exactly K coins while moving from top left corner of the matrix to the bottom right. From a cell (i, j), you can only move to (i+1, j) or (i, j+1).
Example 1:
Input:
K = 12, N = 3
arr[] = [[1, 2, 3],
[4, ... | class Solution:
def numberOfPath(self, N, K, arr):
m = len(arr)
n = len(arr[0])
def check(i, j, K):
if i < 0 or j < 0 or K < 1:
return 0
if i == 0 and j == 0:
if K == arr[i][j]:
return 1
else:
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF IF VAR NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER IF VAR VAR VAR VAR NUMBER RETURN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VA... |
Given a N x N matrix such that each of its cells contains some coins. Count the number of ways to collect exactly K coins while moving from top left corner of the matrix to the bottom right. From a cell (i, j), you can only move to (i+1, j) or (i, j+1).
Example 1:
Input:
K = 12, N = 3
arr[] = [[1, 2, 3],
[4, ... | class Solution:
def numberOfPath(self, n, k, l):
dp = [[{} for _ in range(n)] for _ in range(n)]
dp[-1][-1][l[-1][-1]] = 1
for i in range(n - 2, -1, -1):
for t in dp[i + 1][-1]:
x = t + l[i][-1]
if x <= k:
if x in dp[i][-1]:
... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER IF VAR VAR IF VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR BIN_OP ... |
Given a N x N matrix such that each of its cells contains some coins. Count the number of ways to collect exactly K coins while moving from top left corner of the matrix to the bottom right. From a cell (i, j), you can only move to (i+1, j) or (i, j+1).
Example 1:
Input:
K = 12, N = 3
arr[] = [[1, 2, 3],
[4, ... | def f(A, N, summ, x, y, dp):
if x >= N or y >= N or summ < 0:
return 0
if x == N - 1 and y == N - 1 and summ - A[x][y] == 0:
return 1
if dp[x][y][summ] != -1:
return dp[x][y][summ]
ans = f(A, N, summ - A[x][y], x + 1, y, dp) + f(A, N, summ - A[x][y], x, y + 1, dp)
dp[x][y][su... | FUNC_DEF IF VAR VAR VAR VAR VAR NUMBER RETURN NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR NUMBER RETURN NUMBER IF VAR VAR VAR VAR NUMBER RETURN VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR V... |
Given a N x N matrix such that each of its cells contains some coins. Count the number of ways to collect exactly K coins while moving from top left corner of the matrix to the bottom right. From a cell (i, j), you can only move to (i+1, j) or (i, j+1).
Example 1:
Input:
K = 12, N = 3
arr[] = [[1, 2, 3],
[4, ... | class Solution:
def numberOfPath(self, N, K, arr):
def solve(i, j, n, k, arr, dp):
if i >= n or j >= n or k < 0:
return 0
if i == n - 1 and j == n - 1:
if k == arr[i][j]:
return 1
return 0
if (i, j, k) ... | CLASS_DEF FUNC_DEF FUNC_DEF IF VAR VAR VAR VAR VAR NUMBER RETURN NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER IF VAR VAR VAR VAR RETURN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR FUNC_CALL V... |
Given a N x N matrix such that each of its cells contains some coins. Count the number of ways to collect exactly K coins while moving from top left corner of the matrix to the bottom right. From a cell (i, j), you can only move to (i+1, j) or (i, j+1).
Example 1:
Input:
K = 12, N = 3
arr[] = [[1, 2, 3],
[4, ... | class Solution:
def recur(self, m, n, k, a):
global dp
if m < 0 or n < 0 or k < 0:
return 0
if m == 0 and n == 0:
return k == a[0][0]
if dp[m][n][k]:
return dp[m][n][k]
dp[m][n][k] = self.recur(m - 1, n, k - a[m][n], a) + self.recur(
... | CLASS_DEF FUNC_DEF IF VAR NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN VAR VAR NUMBER NUMBER IF VAR VAR VAR VAR RETURN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR VAR... |
Given a N x N matrix such that each of its cells contains some coins. Count the number of ways to collect exactly K coins while moving from top left corner of the matrix to the bottom right. From a cell (i, j), you can only move to (i+1, j) or (i, j+1).
Example 1:
Input:
K = 12, N = 3
arr[] = [[1, 2, 3],
[4, ... | class Solution:
def memo(self, m, n, cost, grid, dp):
if m == 0 and n == 0:
return 1 if cost - grid[m][n] == 0 else 0
if m < 0 or n < 0 or cost < 0:
return 0
if dp[m][n][cost] != -1:
return dp[m][n][cost]
dp[m][n][cost] = self.memo(m - 1, n, cost ... | CLASS_DEF FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN BIN_OP VAR VAR VAR VAR NUMBER NUMBER NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR VAR VAR VAR NUMBER RETURN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR ... |
Given a N x N matrix such that each of its cells contains some coins. Count the number of ways to collect exactly K coins while moving from top left corner of the matrix to the bottom right. From a cell (i, j), you can only move to (i+1, j) or (i, j+1).
Example 1:
Input:
K = 12, N = 3
arr[] = [[1, 2, 3],
[4, ... | class Solution:
def util(self, a, i, j, n, m, k):
global dp
if i >= n or j >= m or k < 0:
return 0
if i == n - 1 and j == m - 1:
if k - a[i][j] == 0:
return 1
return 0
if dp[i][j][k] != -1:
return dp[i][j][k]
dp... | CLASS_DEF FUNC_DEF IF VAR VAR VAR VAR VAR NUMBER RETURN NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER RETURN NUMBER RETURN NUMBER IF VAR VAR VAR VAR NUMBER RETURN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR VAR VAR VAR... |
Given a N x N matrix such that each of its cells contains some coins. Count the number of ways to collect exactly K coins while moving from top left corner of the matrix to the bottom right. From a cell (i, j), you can only move to (i+1, j) or (i, j+1).
Example 1:
Input:
K = 12, N = 3
arr[] = [[1, 2, 3],
[4, ... | class Solution:
def numberOfPath(self, N, K, arr):
def dfs(arr, i, j, k):
if i < 0 or j < 0 or k < 0:
return 0
if i == 0 and j == 0:
return k == arr[i][j]
if dp[i][j][k] != -1:
return dp[i][j][k]
dp[i][j][k] = ... | CLASS_DEF FUNC_DEF FUNC_DEF IF VAR NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN VAR VAR VAR VAR IF VAR VAR VAR VAR NUMBER RETURN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR V... |
Given a N x N matrix such that each of its cells contains some coins. Count the number of ways to collect exactly K coins while moving from top left corner of the matrix to the bottom right. From a cell (i, j), you can only move to (i+1, j) or (i, j+1).
Example 1:
Input:
K = 12, N = 3
arr[] = [[1, 2, 3],
[4, ... | class Solution:
def numberOfPath(self, n, k, a):
v = [([False] * n) for i in range(n)]
d = [([] * n) for i in range(n)]
dp = {}
for i in range(n):
for j in range(n):
d[i].append(dp.copy())
d[n - 1][n - 1][a[n - 1][n - 1]] = 1
def solve(i,... | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST VAR VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMB... |
Given a N x N matrix such that each of its cells contains some coins. Count the number of ways to collect exactly K coins while moving from top left corner of the matrix to the bottom right. From a cell (i, j), you can only move to (i+1, j) or (i, j+1).
Example 1:
Input:
K = 12, N = 3
arr[] = [[1, 2, 3],
[4, ... | class Solution:
def numberOfPath(self, N, K, arr):
memo = [[([-1] * (K + 1)) for j in range(N)] for i in range(N)]
return self.dfs(0, 0, N, arr, K, memo)
def dfs(self, i, j, N, arr, k, memo):
if i < 0 or i > N - 1 or j < 0 or j > N - 1:
return 0
if memo[i][j][k] != ... | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR NUMBER NUMBER VAR VAR VAR VAR FUNC_DEF IF VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER RETURN NUMBER IF VAR VAR VAR VAR NUMBER RETURN VAR VAR VAR VAR IF BIN_OP VAR VAR... |
Given a N x N matrix such that each of its cells contains some coins. Count the number of ways to collect exactly K coins while moving from top left corner of the matrix to the bottom right. From a cell (i, j), you can only move to (i+1, j) or (i, j+1).
Example 1:
Input:
K = 12, N = 3
arr[] = [[1, 2, 3],
[4, ... | class Solution:
def numberOfPath(self, N, K, arr):
dp = [[([-1] * (K + 1)) for _ in range(N)] for __ in range(N)]
def recur(i, j, k, dp):
if i >= N or j >= N or k < 0:
return 0
if i == N - 1 and j == N - 1:
if k == arr[i][j]:
... | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR VAR VAR VAR NUMBER RETURN NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER IF VAR VAR VAR VAR NUMBER RETURN VAR VAR VAR VAR ASSIGN VAR VA... |
Given a N x N matrix such that each of its cells contains some coins. Count the number of ways to collect exactly K coins while moving from top left corner of the matrix to the bottom right. From a cell (i, j), you can only move to (i+1, j) or (i, j+1).
Example 1:
Input:
K = 12, N = 3
arr[] = [[1, 2, 3],
[4, ... | class Solution:
def numberOfPath(self, N, K, arr):
d = {}
def calPathSum(i, j, s):
if (i, j, s) in d:
return d[i, j, s]
if i < 0 or i >= N or j < 0 or j >= N:
d[i, j, s] = 0
return 0
if i == N - 1 and j == N - 1:
... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT FUNC_DEF IF VAR VAR VAR VAR RETURN VAR VAR VAR VAR IF VAR NUMBER VAR VAR VAR NUMBER VAR VAR ASSIGN VAR VAR VAR VAR NUMBER RETURN NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR VAR NUMBE... |
Given a N x N matrix such that each of its cells contains some coins. Count the number of ways to collect exactly K coins while moving from top left corner of the matrix to the bottom right. From a cell (i, j), you can only move to (i+1, j) or (i, j+1).
Example 1:
Input:
K = 12, N = 3
arr[] = [[1, 2, 3],
[4, ... | class Solution:
def numberOfPath(self, N, K, arr):
t = [
[[(-1) for _ in range(100 + 1)] for j in range(N + 1)] for k in range(N + 1)
]
def solve(r, c, rem):
if r < 0 or c < 0 or r >= N or c >= N or rem < 0:
return 0
if r == N - 1 and c =... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_DEF IF VAR NUMBER VAR NUMBER VAR VAR VAR VAR VAR NUMBER RETURN NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR VA... |
Given a N x N matrix such that each of its cells contains some coins. Count the number of ways to collect exactly K coins while moving from top left corner of the matrix to the bottom right. From a cell (i, j), you can only move to (i+1, j) or (i, j+1).
Example 1:
Input:
K = 12, N = 3
arr[] = [[1, 2, 3],
[4, ... | class Solution:
def find(self, i, j, K, arr, N, dp):
if i == N or j == N:
return 0
if i == N - 1 and j == N - 1 and K - arr[i][j] == 0:
return 1
if K <= 0:
return 0
if dp[i][j][K] != -1:
return dp[i][j][K]
dp[i][j][K] = self.fi... | CLASS_DEF FUNC_DEF IF VAR VAR VAR VAR RETURN NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR VAR VAR VAR NUMBER RETURN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR... |
Given a N x N matrix such that each of its cells contains some coins. Count the number of ways to collect exactly K coins while moving from top left corner of the matrix to the bottom right. From a cell (i, j), you can only move to (i+1, j) or (i, j+1).
Example 1:
Input:
K = 12, N = 3
arr[] = [[1, 2, 3],
[4, ... | class Solution:
def f(self, cr, cc, n, k, arr, dp):
if cr == n - 1 and cc == n - 1:
if k == 0:
return 1
return 0
if k < 0:
return 0
state = cr, cc, k
if state in dp:
return dp[state]
if cc + 1 < n:
a... | CLASS_DEF FUNC_DEF IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR VAR IF VAR VAR RETURN VAR VAR IF BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUM... |
Given a N x N matrix such that each of its cells contains some coins. Count the number of ways to collect exactly K coins while moving from top left corner of the matrix to the bottom right. From a cell (i, j), you can only move to (i+1, j) or (i, j+1).
Example 1:
Input:
K = 12, N = 3
arr[] = [[1, 2, 3],
[4, ... | class Solution:
def numberOfPath(self, N, K, arr):
memo = {}
def helper(i, j, k):
if i >= N or j >= N or k < 0:
return 0
if i == N - 1 and j == N - 1:
return 1 if k == arr[i][j] else 0
if (i, j, k) in memo:
return ... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT FUNC_DEF IF VAR VAR VAR VAR VAR NUMBER RETURN NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER RETURN VAR VAR VAR VAR NUMBER NUMBER IF VAR VAR VAR VAR RETURN VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR ... |
One tradition of welcoming the New Year is launching fireworks into the sky. Usually a launched firework flies vertically upward for some period of time, then explodes, splitting into several parts flying in different directions. Sometimes those parts also explode after some period of time, splitting into even more par... | from sys import stdin, stdout
def ri():
return map(int, input().split())
w = 15
adding = [(0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1), (1, 0), (1, 1)]
def fill(x, y, dir, depth):
for i in range(t[depth]):
x += adding[dir][0]
y += adding[dir][1]
v[x][y] = 1
def dfs(x, y, ... | FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER FUNC_DEF IF V... |
One tradition of welcoming the New Year is launching fireworks into the sky. Usually a launched firework flies vertically upward for some period of time, then explodes, splitting into several parts flying in different directions. Sometimes those parts also explode after some period of time, splitting into even more par... | import time
coord = set()
flows = int(input())
start = time.time()
t = list(map(int, input().split()))
directions = {
(0): (0, 1),
(1): (1, 1),
(2): (1, 0),
(3): (1, -1),
(4): (0, -1),
(5): (-1, -1),
(6): (-1, 0),
(7): (-1, 1),
}
was = [
[[[(0) for j in range(300)] for i in range(30... | IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER N... |
One tradition of welcoming the New Year is launching fireworks into the sky. Usually a launched firework flies vertically upward for some period of time, then explodes, splitting into several parts flying in different directions. Sometimes those parts also explode after some period of time, splitting into even more par... | dr = [[0, 1], [1, 1], [1, 0], [1, -1], [0, -1], [-1, -1], [-1, 0], [-1, 1]]
n = int(input())
t = [int(i) for i in input().split()]
visited = set()
N = 150 * 2 + 10
covers = [([0] * N) for i in range(N)]
def dfs(d, pos, path):
mem = d, pos, path
if mem in visited:
return set()
else:
visited... | ASSIGN VAR LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER... |
One tradition of welcoming the New Year is launching fireworks into the sky. Usually a launched firework flies vertically upward for some period of time, then explodes, splitting into several parts flying in different directions. Sometimes those parts also explode after some period of time, splitting into even more par... | import sys
plane = set()
crackers = {((0, -1), (0, 1))}
n = int(input())
a = [int(x) for x in input().split()]
crack_dict = {
(1, 0): ((1, -1), (1, 1)),
(1, 1): ((1, 0), (0, 1)),
(0, 1): ((1, 1), (-1, 1)),
(-1, 1): ((0, 1), (-1, 0)),
(-1, 0): ((-1, 1), (-1, -1)),
(-1, -1): ((-1, 0), (0, -1)),
... | IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMB... |
One tradition of welcoming the New Year is launching fireworks into the sky. Usually a launched firework flies vertically upward for some period of time, then explodes, splitting into several parts flying in different directions. Sometimes those parts also explode after some period of time, splitting into even more par... | k = int(input()) & 1
p = []
s = range(1, 6)
for q in map(int, input().split()[::-1]):
if k:
p += [(x, -y) for x, y in p]
p = [(x - q, y) for x, y in p]
p += [(-x, 0) for x in s[:q]]
else:
p += [(y, -x) for x, y in p]
p = [(x - q, y + q) for x, y in p]
p += [(-x, x... | ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_O... |
One tradition of welcoming the New Year is launching fireworks into the sky. Usually a launched firework flies vertically upward for some period of time, then explodes, splitting into several parts flying in different directions. Sometimes those parts also explode after some period of time, splitting into even more par... | from sys import *
T = int(stdin.readline())
t = [int(s) for s in stdin.readline().split(" ")]
a = []
for i in range(T - 1, -1, -1):
if i % 2 == 0:
a += [(e[0], -e[1]) for e in a]
a = [(e[0] - t[i], e[1]) for e in a]
a += [(-x - 1, 0) for x in range(t[i])]
a = list(set(a))
if i %... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER NUMBER ... |
Given an array of scores that are non-negative integers. Player 1 picks one of the numbers from either end of the array followed by the player 2 and then player 1 and so on. Each time a player picks a number, that number will not be available for the next player. This continues until all the scores have been chosen. Th... | class Solution:
def PredictTheWinner(self, nums):
if not nums:
return True
n = len(nums)
if n & 1 == 0:
return True
dp = [0] * n
for i in range(n - 1, -1, -1):
for j in range(i, n):
if i == j:
dp[i] = nu... | CLASS_DEF FUNC_DEF IF VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER RETURN NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR BIN_O... |
Given an array of scores that are non-negative integers. Player 1 picks one of the numbers from either end of the array followed by the player 2 and then player 1 and so on. Each time a player picks a number, that number will not be available for the next player. This continues until all the scores have been chosen. Th... | class Solution:
def PredictTheWinner(self, nums):
l = len(nums)
memo = [([None] * l) for _ in range(l)]
def predict(start, end, memo):
if start == end:
return nums[start]
if memo[start][end]:
return memo[start][end]
one = ... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NONE VAR VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR RETURN VAR VAR IF VAR VAR VAR RETURN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VA... |
Given an array of scores that are non-negative integers. Player 1 picks one of the numbers from either end of the array followed by the player 2 and then player 1 and so on. Each time a player picks a number, that number will not be available for the next player. This continues until all the scores have been chosen. Th... | class Solution:
def PredictTheWinner(self, nums):
memo = [[(0) for _ in range(len(nums))] for _ in range(len(nums))]
self.count = 0
def winner(left, right, player):
self.count += 1
if left == right:
return player * nums[left]
if memo[left... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FUNC_DEF VAR NUMBER IF VAR VAR RETURN BIN_OP VAR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR FUNC_CALL VAR... |
Given an array of scores that are non-negative integers. Player 1 picks one of the numbers from either end of the array followed by the player 2 and then player 1 and so on. Each time a player picks a number, that number will not be available for the next player. This continues until all the scores have been chosen. Th... | class Solution:
p1dict = {}
p2dict = {}
def play1(self, nums):
if str(nums) in self.p1dict:
return self.p1dict[str(nums)]
if len(nums) == 1:
return nums[0]
ret = max(self.play2(nums[1:]) + nums[0], self.play2(nums[:-1]) + nums[-1])
self.p1dict[str(num... | CLASS_DEF ASSIGN VAR DICT ASSIGN VAR DICT FUNC_DEF IF FUNC_CALL VAR VAR VAR RETURN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF IF FU... |
Given an array of scores that are non-negative integers. Player 1 picks one of the numbers from either end of the array followed by the player 2 and then player 1 and so on. Each time a player picks a number, that number will not be available for the next player. This continues until all the scores have been chosen. Th... | class Solution:
def PredictTheWinner(self, nums):
N = len(nums)
dp = [([0] * N) for _ in range(N)]
pre_sum = [nums[0]] * (N + 1)
pre_sum[-1] = 0
for i in range(1, N):
pre_sum[i] = pre_sum[i - 1] + nums[i]
for i in range(N):
dp[i][i] = nums[i]
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR F... |
Given an array of scores that are non-negative integers. Player 1 picks one of the numbers from either end of the array followed by the player 2 and then player 1 and so on. Each time a player picks a number, that number will not be available for the next player. This continues until all the scores have been chosen. Th... | class Solution:
def PredictTheWinner(self, nums):
cache = {}
def whose_turn(i, j):
return (len(nums) - (j - i + 1)) % 2 == 0
def traverse(i, j):
if (i, j) in cache:
return cache[i, j]
p1_turn = whose_turn(i, j)
if i == j:
... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT FUNC_DEF RETURN BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER NUMBER FUNC_DEF IF VAR VAR VAR RETURN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR RETURN VAR VAR VAR NUMBER NUMBER VAR VAR IF BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ... |
Given an array of scores that are non-negative integers. Player 1 picks one of the numbers from either end of the array followed by the player 2 and then player 1 and so on. Each time a player picks a number, that number will not be available for the next player. This continues until all the scores have been chosen. Th... | class Solution:
def PredictTheWinner(self, nums):
def helper(nums, start, end, mem):
if start == end:
return nums[start]
if (start, end) not in mem:
mem[start, end] = max(
nums[start] - helper(nums, start + 1, end, mem),
... | CLASS_DEF FUNC_DEF FUNC_DEF IF VAR VAR RETURN VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR RETURN VAR VAR VAR RETURN FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER DICT NUMBER |
Given an array of scores that are non-negative integers. Player 1 picks one of the numbers from either end of the array followed by the player 2 and then player 1 and so on. Each time a player picks a number, that number will not be available for the next player. This continues until all the scores have been chosen. Th... | class Solution:
def PredictTheWinner(self, nums):
_cache = {}
return Solution.Moves(self, nums, 0, len(nums) - 1, 1, _cache) >= 0
def Moves(self, nums, ini, fin, pl, _cache={}):
memo = str((ini, fin, pl))
if memo in list(_cache.keys()):
return _cache[memo]
i... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT RETURN FUNC_CALL VAR VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER FUNC_DEF DICT ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR FUNC_CALL VAR FUNC_CALL VAR RETURN VAR VAR IF VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR VAR RETURN VAR VAR ASSIGN VAR VAR VAR VAR RETURN VAR V... |
Given an array of scores that are non-negative integers. Player 1 picks one of the numbers from either end of the array followed by the player 2 and then player 1 and so on. Each time a player picks a number, that number will not be available for the next player. This continues until all the scores have been chosen. Th... | class Solution:
def PredictTheWinner(self, nums):
n = len(nums)
if n == 0:
return False
dp = [([0] * n) for i in range(n)]
for i in range(n):
dp[i][i] = nums[i]
for period in range(1, n):
for i in range(n - period):
j = i +... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP... |
Given an array of scores that are non-negative integers. Player 1 picks one of the numbers from either end of the array followed by the player 2 and then player 1 and so on. Each time a player picks a number, that number will not be available for the next player. This continues until all the scores have been chosen. Th... | class Solution:
def PredictTheWinner(self, nums):
total = sum(nums)
dic = {}
def score(i, j, t):
if i > j:
return 0
if (i, j) in dic:
return dic[i, j]
ret = max(
t - score(i + 1, j, t - nums[i]), t - score(... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR VAR RETURN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR VAR RETURN V... |
Given an array of scores that are non-negative integers. Player 1 picks one of the numbers from either end of the array followed by the player 2 and then player 1 and so on. Each time a player picks a number, that number will not be available for the next player. This continues until all the scores have been chosen. Th... | class Solution:
def PredictTheWinner(self, nums):
dic = {}
def solve(nums):
if len(nums) <= 1:
return sum(nums)
tnums = tuple(nums)
if tnums in dic:
return dic[tnums]
dic[tnums] = max(nums[0] - solve(nums[1:]), nums[-1... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR NUMBER RETURN VAR VAR RETURN FUNC_CALL VAR VAR NUMBER |
Given 2n balls of k distinct colors. You will be given an integer array balls of size k where balls[i] is the number of balls of color i.
All the balls will be shuffled uniformly at random, then we will distribute the first n balls to the first box and the remaining n balls to the other box (Please read the explanatio... | class Solution:
def getProbability(self, balls: List[int]) -> float:
total = sum(balls)
k = len(balls)
def theSame(added):
res = 0
for i in range(k):
if added[i] == 0:
res -= 1
elif balls[i] == added[i]:
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER RETURN VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER W... |
Given 2n balls of k distinct colors. You will be given an integer array balls of size k where balls[i] is the number of balls of color i.
All the balls will be shuffled uniformly at random, then we will distribute the first n balls to the first box and the remaining n balls to the other box (Please read the explanatio... | class Solution:
def getProbability(self, balls: List[int]) -> float:
self.total = 0
self.valid = 0
t = sum(balls) >> 1
n = len(balls)
def check(s):
return sum([(x != 0) for x in s]) == sum(
[(balls[i] - s[i] != 0) for i in range(n)]
)... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ... |
Given 2n balls of k distinct colors. You will be given an integer array balls of size k where balls[i] is the number of balls of color i.
All the balls will be shuffled uniformly at random, then we will distribute the first n balls to the first box and the remaining n balls to the other box (Please read the explanatio... | class Solution(object):
def __init__(self):
self.fact = [1, 1, 2, 6, 24, 120, 720]
self.total = 0.0
self.match = 0.0
def dfs(self, balls, i=0, n=0, c=0, w=1.0):
if i == len(balls):
self.total += w * (n == 0)
self.match += w * (n == 0) * (c == 0)
... | CLASS_DEF VAR FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF NUMBER NUMBER NUMBER NUMBER IF VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER RETURN FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR NU... |
Given 2n balls of k distinct colors. You will be given an integer array balls of size k where balls[i] is the number of balls of color i.
All the balls will be shuffled uniformly at random, then we will distribute the first n balls to the first box and the remaining n balls to the other box (Please read the explanatio... | class Solution:
def getProbability(self, balls: List[int]) -> float:
def factorial(k):
if k <= 1:
return 1
return factorial(k - 1) * k
def calc(balls):
bs = [b for b in balls if b > 0]
ans = factorial(sum(bs))
for b in bs... | CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_DEF ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR VAR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_DEF IF VAR ... |
Given 2n balls of k distinct colors. You will be given an integer array balls of size k where balls[i] is the number of balls of color i.
All the balls will be shuffled uniformly at random, then we will distribute the first n balls to the first box and the remaining n balls to the other box (Please read the explanatio... | class Solution:
def getProbability(self, balls: List[int]) -> float:
firstHalf, secondHalf = [(0) for _ in range(len(balls))], [
(0) for _ in range(len(balls))
]
self.good, self.all = 0, 0
mem_factorial = {}
def factorial(v):
if v not in mem_factoria... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR DICT FUNC_DEF IF VAR VAR ASSIGN VAR VAR VAR NUMBER BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER RETURN VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR V... |
Given 2n balls of k distinct colors. You will be given an integer array balls of size k where balls[i] is the number of balls of color i.
All the balls will be shuffled uniformly at random, then we will distribute the first n balls to the first box and the remaining n balls to the other box (Please read the explanatio... | class Solution:
def getProbability(self, balls: List[int]) -> float:
def calc(d):
n = len(d)
s = sum(d.values())
result = math.factorial(s)
for k, v in list(d.items()):
result /= math.factorial(v)
return result
t, e = 0, ... | CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR VAR NUMBER NUMBER FUNC_DEF IF VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR A... |
Given 2n balls of k distinct colors. You will be given an integer array balls of size k where balls[i] is the number of balls of color i.
All the balls will be shuffled uniformly at random, then we will distribute the first n balls to the first box and the remaining n balls to the other box (Please read the explanatio... | class Solution:
def getProbability(self, balls: List[int]) -> float:
N = len(balls)
sm = sum(balls)
half = sm // 2
@lru_cache(None)
def rec2(cur, na, nb):
if na > half or nb > half:
return 0
if cur == N:
return int(na ... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FUNC_DEF IF VAR VAR VAR VAR RETURN NUMBER IF VAR VAR RETURN FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP... |
Given 2n balls of k distinct colors. You will be given an integer array balls of size k where balls[i] is the number of balls of color i.
All the balls will be shuffled uniformly at random, then we will distribute the first n balls to the first box and the remaining n balls to the other box (Please read the explanatio... | class Solution:
def getProbability(self, balls: List[int]) -> float:
balls_flattened = []
for i, count in enumerate(balls):
balls_flattened.extend([i] * count)
def has_same_distinct_color(perm):
n = len(perm)
return len(set(perm[: n // 2])) == len(set(pe... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP LIST VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER FUNC_DEF IF VAR V... |
Given 2n balls of k distinct colors. You will be given an integer array balls of size k where balls[i] is the number of balls of color i.
All the balls will be shuffled uniformly at random, then we will distribute the first n balls to the first box and the remaining n balls to the other box (Please read the explanatio... | class Solution:
def getProbability(self, balls: List[int]) -> float:
total = 0
valid = 0
@lru_cache(None)
def getFactor(i):
ans = 1
for i in range(2, i + 1):
ans *= i
return ans
def getComb(nums):
a = getFacto... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR RETURN VAR FUNC_CALL VAR NONE FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN BIN_OP VAR VAR... |
Given 2n balls of k distinct colors. You will be given an integer array balls of size k where balls[i] is the number of balls of color i.
All the balls will be shuffled uniformly at random, then we will distribute the first n balls to the first box and the remaining n balls to the other box (Please read the explanatio... | class Solution:
def getProbability(self, balls: List[int]) -> float:
@lru_cache(None)
def select(n, r):
if r > n:
return 0
if r == 0:
return 1
if r == 1:
return n
return select(n - 1, r) + select(n - 1,... | CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN VAR RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR NONE FUNC_DEF IF VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR BIN_OP NUMB... |
Given 2n balls of k distinct colors. You will be given an integer array balls of size k where balls[i] is the number of balls of color i.
All the balls will be shuffled uniformly at random, then we will distribute the first n balls to the first box and the remaining n balls to the other box (Please read the explanatio... | class Solution:
def getProbability(self, balls: List[int]) -> float:
n = sum(balls)
k = len(balls)
total = 0
valid = 0
fact = [1] * 50
for i in range(1, 50):
fact[i] = fact[i - 1] * i
def dfs(d, b1, b2, c1, c2, p1, p2):
nonlocal total... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR FUNC_DEF IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER RETURN IF VAR VAR ASSI... |
Given 2n balls of k distinct colors. You will be given an integer array balls of size k where balls[i] is the number of balls of color i.
All the balls will be shuffled uniformly at random, then we will distribute the first n balls to the first box and the remaining n balls to the other box (Please read the explanatio... | class Solution:
def getProbability(self, balls: List[int]) -> float:
total = sum(balls)
def factorial(n):
if n == 0:
return 1
if n < 3:
return n
return n * factorial(n - 1)
self.match = 0
self.total = 0
d... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN VAR RETURN BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF IF VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER FOR ... |
Given 2n balls of k distinct colors. You will be given an integer array balls of size k where balls[i] is the number of balls of color i.
All the balls will be shuffled uniformly at random, then we will distribute the first n balls to the first box and the remaining n balls to the other box (Please read the explanatio... | class Solution:
def getProbability(self, balls: List[int]) -> float:
firsthalf, secondhalf = [0] * len(balls), [0] * len(balls)
self.good, self.all = 0, 0
@lru_cache(None)
def fac(n):
if n == 0:
return 1
return n * fac(n - 1)
def per... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER RETURN BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR NONE FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR RETURN B... |
Given 2n balls of k distinct colors. You will be given an integer array balls of size k where balls[i] is the number of balls of color i.
All the balls will be shuffled uniformly at random, then we will distribute the first n balls to the first box and the remaining n balls to the other box (Please read the explanatio... | class Solution:
def getProbability(self, balls: List[int]) -> float:
k, n = len(balls), sum(balls)
total = 2 * math.comb(n, n // 2)
def shuffle(color, box1, box2):
if color == k:
if sum(box1) == sum(box2) and box1.count(0) == box2.count(0):
a... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_DEF IF VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR LIST VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL V... |
Given 2n balls of k distinct colors. You will be given an integer array balls of size k where balls[i] is the number of balls of color i.
All the balls will be shuffled uniformly at random, then we will distribute the first n balls to the first box and the remaining n balls to the other box (Please read the explanatio... | class Solution:
def getProbability(self, balls: List[int]) -> float:
@lru_cache(None)
def C(n, m):
return math.factorial(n) / math.factorial(m) / math.factorial(n - m)
def choose(i, k, d1, d2, cnt):
if k == 0 and i <= n:
return cnt, cnt if d1 == d2 ... | CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR NONE FUNC_DEF IF VAR NUMBER VAR VAR RETURN VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR VAR RETURN NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL... |
Given 2n balls of k distinct colors. You will be given an integer array balls of size k where balls[i] is the number of balls of color i.
All the balls will be shuffled uniformly at random, then we will distribute the first n balls to the first box and the remaining n balls to the other box (Please read the explanatio... | class Solution:
def getProbability(self, balls: List[int]) -> float:
self.n = len(balls)
self.mem = {(0): 1}
self.mem2 = {}
self.balls = balls
rv = self.dfs(0, [], [])
return rv / self.multinomial(balls)
def dfs(self, idx, lefts, rights):
if idx >= self.... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR DICT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER LIST LIST RETURN BIN_OP VAR FUNC_CALL VAR VAR VAR FUNC_DEF IF VAR VAR IF VAR VAR RETURN NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN NUMBER IF FUNC_CALL VAR VAR FU... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.