description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
Given a binary tree and an integer X. Your task is to complete the function countSubtreesWithSumX() that returns the count of the number of subtress having total node’s data sum equal to the value X.
Example: For the tree given below:
5
/ \
-10 3
/ \ /... | def util(root, x):
if root == None:
return [0, 0]
l = util(root.left, x)
r = util(root.right, x)
if l[0] + r[0] + root.data == x:
return [x, l[1] + r[1] + 1]
else:
return [l[0] + r[0] + root.data, l[1] + r[1]]
def countSubtreesWithSumX(root, x):
ans = util(root, x)
... | FUNC_DEF IF VAR NONE RETURN LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR VAR RETURN LIST VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER RETURN LIST BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER FUNC_DEF ASSIGN VAR ... |
Given a binary tree and an integer X. Your task is to complete the function countSubtreesWithSumX() that returns the count of the number of subtress having total node’s data sum equal to the value X.
Example: For the tree given below:
5
/ \
-10 3
/ \ /... | def calc(curr, d):
if curr == None:
return 0
sl = calc(curr.left, d)
sr = calc(curr.right, d)
d[curr] = sl + sr + curr.data
return d[curr]
def countSubtreesWithSumX(root, x):
d = {}
calc(root, d)
c = 0
va = d.values()
for v in va:
if v == x:
c += 1
... | FUNC_DEF IF VAR NONE RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR DICT EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR VAR NUMBER RETURN VAR |
Given a binary tree and an integer X. Your task is to complete the function countSubtreesWithSumX() that returns the count of the number of subtress having total node’s data sum equal to the value X.
Example: For the tree given below:
5
/ \
-10 3
/ \ /... | def countSubtreesWithSumX(root, x):
count = 0
def helper(root):
nonlocal count
if root:
x1 = helper(root.left)
x2 = helper(root.right)
if x1 + x2 + root.data == x:
count += 1
return x1 + x2 + root.data
return 0
helper(... | FUNC_DEF ASSIGN VAR NUMBER FUNC_DEF IF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER RETURN BIN_OP BIN_OP VAR VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR |
Given a binary tree and an integer X. Your task is to complete the function countSubtreesWithSumX() that returns the count of the number of subtress having total node’s data sum equal to the value X.
Example: For the tree given below:
5
/ \
-10 3
/ \ /... | class Node:
def __init__(self, val):
self.data = val
self.left = None
self.right = None
def countSubtreesWithSumX(root, x):
stack = [root]
parent = {}
parent[root] = Node(0)
vis = set()
while stack:
top = stack[-1]
if top.left and top.left not in vis:
... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NONE ASSIGN VAR NONE FUNC_DEF ASSIGN VAR LIST VAR ASSIGN VAR DICT ASSIGN VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VA... |
Given a binary tree and an integer X. Your task is to complete the function countSubtreesWithSumX() that returns the count of the number of subtress having total node’s data sum equal to the value X.
Example: For the tree given below:
5
/ \
-10 3
/ \ /... | def modify(root, x, count):
sum = lsum = rsum = 0
if root.left:
lsum = modify(root.left, x, count)
if root.right:
rsum = modify(root.right, x, count)
sum = lsum + rsum + root.data
if sum == x:
count[0] += 1
return sum
def countSubtreesWithSumX(root, x):
res = [0]
... | FUNC_DEF ASSIGN VAR VAR VAR NUMBER IF VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR VAR NUMBER NUMBER RETURN VAR FUNC_DEF ASSIGN VAR LIST NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR NUMBER |
You are given an array arr[] of N integers including 0. The task is to find the smallest positive number missing from the array.
Example 1:
Input:
N = 5
arr[] = {1,2,3,4,5}
Output: 6
Explanation: Smallest positive missing
number is 6.
Example 2:
Input:
N = 5
arr[] = {0,-10,1,3,-20}
Output: 2
Explanation: Smallest posi... | class Solution:
def missingNumber(self, arr, n) -> int:
j = 0
for i in range(n):
if arr[i] <= 0:
arr[i], arr[j] = arr[j], arr[i]
j += 1
arr = arr[j:]
n = n - j
for i in range(n):
if abs(arr[i]) <= n and arr[abs(arr[i]) ... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NU... |
You are given an array arr[] of N integers including 0. The task is to find the smallest positive number missing from the array.
Example 1:
Input:
N = 5
arr[] = {1,2,3,4,5}
Output: 6
Explanation: Smallest positive missing
number is 6.
Example 2:
Input:
N = 5
arr[] = {0,-10,1,3,-20}
Output: 2
Explanation: Smallest posi... | class Solution:
def missingNumber(self, arr, n):
arr.sort()
ans = 1
for i in range(n):
if ans == arr[i]:
ans += 1
elif arr[i] > ans:
break
return ans | CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR VAR VAR RETURN VAR |
You are given an array arr[] of N integers including 0. The task is to find the smallest positive number missing from the array.
Example 1:
Input:
N = 5
arr[] = {1,2,3,4,5}
Output: 6
Explanation: Smallest positive missing
number is 6.
Example 2:
Input:
N = 5
arr[] = {0,-10,1,3,-20}
Output: 2
Explanation: Smallest posi... | class Solution:
def missingNumber(self, arr, n):
n = len(arr)
j = 0
for i in range(n):
if arr[i] <= 0:
arr[i], arr[j] = arr[j], arr[i]
j += 1
positive_nums = arr[j:]
for num in positive_nums:
index = abs(num) - 1
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR FOR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR F... |
You are given an array arr[] of N integers including 0. The task is to find the smallest positive number missing from the array.
Example 1:
Input:
N = 5
arr[] = {1,2,3,4,5}
Output: 6
Explanation: Smallest positive missing
number is 6.
Example 2:
Input:
N = 5
arr[] = {0,-10,1,3,-20}
Output: 2
Explanation: Smallest posi... | class Solution:
def missingNumber(self, arr, n):
arr.sort()
s = 1
for i in range(0, len(arr)):
if s == arr[i]:
s += 1
return s | CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER RETURN VAR |
You are given an array arr[] of N integers including 0. The task is to find the smallest positive number missing from the array.
Example 1:
Input:
N = 5
arr[] = {1,2,3,4,5}
Output: 6
Explanation: Smallest positive missing
number is 6.
Example 2:
Input:
N = 5
arr[] = {0,-10,1,3,-20}
Output: 2
Explanation: Smallest posi... | class Solution:
def missingNumber(self, arr, n):
i = 0
j = 1
while True:
while i < n and arr[i] > 0:
i += 1
j = max(i + 1, j)
while j < n and arr[j] <= 0:
j += 1
if i < n and j < n:
arr[i], arr[j... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER WHILE VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR WHILE VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC... |
You are given an array arr[] of N integers including 0. The task is to find the smallest positive number missing from the array.
Example 1:
Input:
N = 5
arr[] = {1,2,3,4,5}
Output: 6
Explanation: Smallest positive missing
number is 6.
Example 2:
Input:
N = 5
arr[] = {0,-10,1,3,-20}
Output: 2
Explanation: Smallest posi... | class Solution:
def swap(self, start, end, A, val):
A[end] = val
A[start] = 0
def missingNumber(self, A, N):
result = A[N - 1] + 1
A.sort()
for i in range(N):
if A[i] == i + 1:
continue
elif A[i] <= 0 or A[i] >= N:
... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER FUNC_DEF ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR... |
You are given an array arr[] of N integers including 0. The task is to find the smallest positive number missing from the array.
Example 1:
Input:
N = 5
arr[] = {1,2,3,4,5}
Output: 6
Explanation: Smallest positive missing
number is 6.
Example 2:
Input:
N = 5
arr[] = {0,-10,1,3,-20}
Output: 2
Explanation: Smallest posi... | class Solution:
def missingNumber(self, arr, n):
for i in range(n):
if arr[i] < 0:
arr[i] = 0
for i in range(n):
val = abs(arr[i])
if 1 <= val <= n:
if arr[val - 1] > 0:
arr[val - 1] *= -1
elif a... | CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF NUMBER VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER FOR ... |
You are given an array arr[] of N integers including 0. The task is to find the smallest positive number missing from the array.
Example 1:
Input:
N = 5
arr[] = {1,2,3,4,5}
Output: 6
Explanation: Smallest positive missing
number is 6.
Example 2:
Input:
N = 5
arr[] = {0,-10,1,3,-20}
Output: 2
Explanation: Smallest posi... | class Solution:
def missingNumber(self, arr, n):
ptr = 0
for i in range(n):
if arr[i] == 1:
ptr = 1
break
if ptr == 0:
return 1
for i in range(n):
if arr[i] <= 0 or arr[i] > n:
arr[i] = 1
for... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR RETURN ... |
You are given an array arr[] of N integers including 0. The task is to find the smallest positive number missing from the array.
Example 1:
Input:
N = 5
arr[] = {1,2,3,4,5}
Output: 6
Explanation: Smallest positive missing
number is 6.
Example 2:
Input:
N = 5
arr[] = {0,-10,1,3,-20}
Output: 2
Explanation: Smallest posi... | class Solution:
def missingNumber(self, arr, n):
positives = [x for x in arr if x > 0]
n = len(positives)
for i in range(n):
if abs(positives[i]) - 1 < n and positives[abs(positives[i]) - 1] > 0:
positives[abs(positives[i]) - 1] = -positives[abs(positives[i]) - 1... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VA... |
You are given an array arr[] of N integers including 0. The task is to find the smallest positive number missing from the array.
Example 1:
Input:
N = 5
arr[] = {1,2,3,4,5}
Output: 6
Explanation: Smallest positive missing
number is 6.
Example 2:
Input:
N = 5
arr[] = {0,-10,1,3,-20}
Output: 2
Explanation: Smallest posi... | class Solution:
def missingNumber(self, arr, n):
arr.sort()
a = 1
for i in arr:
if i > 0 and i > a:
return a
elif i == a:
a += 1
return a | CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR VAR RETURN VAR IF VAR VAR VAR NUMBER RETURN VAR |
You are given an array arr[] of N integers including 0. The task is to find the smallest positive number missing from the array.
Example 1:
Input:
N = 5
arr[] = {1,2,3,4,5}
Output: 6
Explanation: Smallest positive missing
number is 6.
Example 2:
Input:
N = 5
arr[] = {0,-10,1,3,-20}
Output: 2
Explanation: Smallest posi... | class Solution:
def missingNumber(self, arr, n):
arr.sort()
c = 0
for i in range(0, n):
if arr[i] < 0:
continue
elif c + 1 == arr[i]:
c = c + 1
continue
else:
return c + 1 | CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER |
You are given an array arr[] of N integers including 0. The task is to find the smallest positive number missing from the array.
Example 1:
Input:
N = 5
arr[] = {1,2,3,4,5}
Output: 6
Explanation: Smallest positive missing
number is 6.
Example 2:
Input:
N = 5
arr[] = {0,-10,1,3,-20}
Output: 2
Explanation: Smallest posi... | class Solution:
def missingNumber(self, arr, n):
distinct = set(arr)
i = 1
idx = 0
while True:
if i not in distinct:
return i
i += 1
idx += 1
if idx == n:
break
return i | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF VAR VAR RETURN VAR VAR NUMBER VAR NUMBER IF VAR VAR RETURN VAR |
You are given an array arr[] of N integers including 0. The task is to find the smallest positive number missing from the array.
Example 1:
Input:
N = 5
arr[] = {1,2,3,4,5}
Output: 6
Explanation: Smallest positive missing
number is 6.
Example 2:
Input:
N = 5
arr[] = {0,-10,1,3,-20}
Output: 2
Explanation: Smallest posi... | class Solution:
def missingNumber(self, arr, n):
arr = [x for x in sorted(set(arr)) if x > 0]
n = len(arr)
for i in range(n):
if i + 1 != arr[i]:
return i + 1
return n + 1 | CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR VAR RETURN BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER |
You are given an array arr[] of N integers including 0. The task is to find the smallest positive number missing from the array.
Example 1:
Input:
N = 5
arr[] = {1,2,3,4,5}
Output: 6
Explanation: Smallest positive missing
number is 6.
Example 2:
Input:
N = 5
arr[] = {0,-10,1,3,-20}
Output: 2
Explanation: Smallest posi... | class Solution:
def missingNumber(self, arr, n):
index = 0
count = 0
for index in range(n):
correct_index = arr[index] - 1
while (
correct_index >= 0
and correct_index < n
and arr[index] != arr[correct_index]
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER WHILE VAR NUMBER VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER RETURN BIN_OP... |
You are given an array arr[] of N integers including 0. The task is to find the smallest positive number missing from the array.
Example 1:
Input:
N = 5
arr[] = {1,2,3,4,5}
Output: 6
Explanation: Smallest positive missing
number is 6.
Example 2:
Input:
N = 5
arr[] = {0,-10,1,3,-20}
Output: 2
Explanation: Smallest posi... | class Solution:
def missingNumber(self, arr, n):
freq = [0] * (10**6 + 1)
for num in arr:
if num > 0:
freq[num] += 1
for i in range(1, len(freq)):
if freq[i] == 0:
return i
return -1 | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR VAR IF VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER RETURN VAR RETURN NUMBER |
You are given an array arr[] of N integers including 0. The task is to find the smallest positive number missing from the array.
Example 1:
Input:
N = 5
arr[] = {1,2,3,4,5}
Output: 6
Explanation: Smallest positive missing
number is 6.
Example 2:
Input:
N = 5
arr[] = {0,-10,1,3,-20}
Output: 2
Explanation: Smallest posi... | class Solution:
def missingNumber(self, arr, n):
s = {}
for i in range(1, max(arr) + 1):
s[i] = 0
for i in arr:
if i > 0:
s[i] += 1
for i in s:
if s[i] == 0:
return i
return max(arr) + 1 | CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER RETURN VAR RETURN BIN_OP FUNC_CALL VAR VAR NUMBER |
You are given an array arr[] of N integers including 0. The task is to find the smallest positive number missing from the array.
Example 1:
Input:
N = 5
arr[] = {1,2,3,4,5}
Output: 6
Explanation: Smallest positive missing
number is 6.
Example 2:
Input:
N = 5
arr[] = {0,-10,1,3,-20}
Output: 2
Explanation: Smallest posi... | class Solution:
def missingNumber(self, arr, n):
arr = set(arr)
i = 1
for i in range(1, max(arr)):
if i not in arr:
return i
return max(arr) + 1 | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR RETURN VAR RETURN BIN_OP FUNC_CALL VAR VAR NUMBER |
You are given an array arr[] of N integers including 0. The task is to find the smallest positive number missing from the array.
Example 1:
Input:
N = 5
arr[] = {1,2,3,4,5}
Output: 6
Explanation: Smallest positive missing
number is 6.
Example 2:
Input:
N = 5
arr[] = {0,-10,1,3,-20}
Output: 2
Explanation: Smallest posi... | class Solution:
def missingNumber(self, arr, n):
s = set()
for i in range(n):
if arr[i] >= 0:
s.add(arr[i])
continue
arr.clear()
for ele in s:
arr.append(ele)
arr.sort()
if len(arr) == 0:
return 1
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR NUMBER VA... |
You are given an array arr[] of N integers including 0. The task is to find the smallest positive number missing from the array.
Example 1:
Input:
N = 5
arr[] = {1,2,3,4,5}
Output: 6
Explanation: Smallest positive missing
number is 6.
Example 2:
Input:
N = 5
arr[] = {0,-10,1,3,-20}
Output: 2
Explanation: Smallest posi... | class Solution:
def missingNumber(self, arr, n):
arr.sort()
m = 0
for i in arr:
if i < 0:
continue
if i > m + 1:
return m + 1
else:
m = i
return arr[-1] + 1 | CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER IF VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER ASSIGN VAR VAR RETURN BIN_OP VAR NUMBER NUMBER |
You are given an array arr[] of N integers including 0. The task is to find the smallest positive number missing from the array.
Example 1:
Input:
N = 5
arr[] = {1,2,3,4,5}
Output: 6
Explanation: Smallest positive missing
number is 6.
Example 2:
Input:
N = 5
arr[] = {0,-10,1,3,-20}
Output: 2
Explanation: Smallest posi... | class Solution:
def missingNumber(self, arr, n):
dic = {}
for elem in arr:
dic[elem] = True
for i in range(1, n + 2):
if dic.get(i, False) == False:
return i | CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER NUMBER RETURN VAR |
You are given an array arr[] of N integers including 0. The task is to find the smallest positive number missing from the array.
Example 1:
Input:
N = 5
arr[] = {1,2,3,4,5}
Output: 6
Explanation: Smallest positive missing
number is 6.
Example 2:
Input:
N = 5
arr[] = {0,-10,1,3,-20}
Output: 2
Explanation: Smallest posi... | class Solution:
def missingNumber(self, arr, n):
for i in range(len(arr)):
if 1 > arr[i] or arr[i] > n:
arr[i] = 0
for i in range(len(arr)):
if arr[i] > 0:
arr[(arr[i] - 1) % n] += n
for i in range(len(arr)):
arr[i] //= n
... | CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF NUMBER VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR NUMBER RETURN BIN_OP VAR NUMBER RETURN BIN_OP V... |
You are given an array arr[] of N integers including 0. The task is to find the smallest positive number missing from the array.
Example 1:
Input:
N = 5
arr[] = {1,2,3,4,5}
Output: 6
Explanation: Smallest positive missing
number is 6.
Example 2:
Input:
N = 5
arr[] = {0,-10,1,3,-20}
Output: 2
Explanation: Smallest posi... | class Solution:
def missingNumber(self, arr, n):
arr = set(arr)
arr = list(arr)
arr.sort()
if 1 in arr:
ind0 = arr.index(1)
arr[:] = arr[ind0:]
for i in range(n - ind0):
if arr[i] != i + 1:
return i + 1
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR IF NUMBER VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER RETURN NUMBER |
You are given an array arr[] of N integers including 0. The task is to find the smallest positive number missing from the array.
Example 1:
Input:
N = 5
arr[] = {1,2,3,4,5}
Output: 6
Explanation: Smallest positive missing
number is 6.
Example 2:
Input:
N = 5
arr[] = {0,-10,1,3,-20}
Output: 2
Explanation: Smallest posi... | class Solution:
def missingNumber(self, arr, n):
arr.sort()
if 0 in arr:
arr = set(arr)
arr = list(arr)
count = 1
ind = arr.index(0)
for i in range(ind + 1, n):
if arr[i] != count:
return count
... | CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR IF NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR RETURN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF NUMBER VAR RETURN ... |
You are given an array arr[] of N integers including 0. The task is to find the smallest positive number missing from the array.
Example 1:
Input:
N = 5
arr[] = {1,2,3,4,5}
Output: 6
Explanation: Smallest positive missing
number is 6.
Example 2:
Input:
N = 5
arr[] = {0,-10,1,3,-20}
Output: 2
Explanation: Smallest posi... | class Solution:
def missingNumber(self, arr, n):
k = 0
c = 0
m = []
p = 0
arr.sort()
for y in range(len(arr)):
if arr[y] > 0:
m.append(arr[y])
else:
p += 1
m = set(m)
m = list(m)
m.sort()... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUN... |
You are given an array arr[] of N integers including 0. The task is to find the smallest positive number missing from the array.
Example 1:
Input:
N = 5
arr[] = {1,2,3,4,5}
Output: 6
Explanation: Smallest positive missing
number is 6.
Example 2:
Input:
N = 5
arr[] = {0,-10,1,3,-20}
Output: 2
Explanation: Smallest posi... | class Solution:
def missingNumber(self, arr, n):
d = {}
for i in arr:
if i > 0:
if i not in d:
d[i] = 1
else:
d[i] += 1
for i in range(1, n + 1):
if i not in d:
return i
r... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR IF VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR RETURN VAR RETURN BIN_OP VAR NUMBER |
You are given an array arr[] of N integers including 0. The task is to find the smallest positive number missing from the array.
Example 1:
Input:
N = 5
arr[] = {1,2,3,4,5}
Output: 6
Explanation: Smallest positive missing
number is 6.
Example 2:
Input:
N = 5
arr[] = {0,-10,1,3,-20}
Output: 2
Explanation: Smallest posi... | class Solution:
def missingNumber(self, arr, n):
shift = self.segregate(arr, n)
return self.findMissingPositive(arr[shift:], n - shift)
def segregate(self, arr, n):
j = 0
for i in range(n):
if arr[i] <= 0:
arr[i], arr[j] = arr[j], arr[i]
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR BIN_OP VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF FOR VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR VAR BIN_OP FUN... |
You are given an array arr[] of N integers including 0. The task is to find the smallest positive number missing from the array.
Example 1:
Input:
N = 5
arr[] = {1,2,3,4,5}
Output: 6
Explanation: Smallest positive missing
number is 6.
Example 2:
Input:
N = 5
arr[] = {0,-10,1,3,-20}
Output: 2
Explanation: Smallest posi... | class Solution:
def missingNumber(self, arr, n):
dic = {}
for i in range(1, 10**5 + 1):
dic[i] = 1
for i in arr:
dic[i] = 0
for i in dic.keys():
if dic[i] == 1:
return i | CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR IF VAR VAR NUMBER RETURN VAR |
You are given an array arr[] of N integers including 0. The task is to find the smallest positive number missing from the array.
Example 1:
Input:
N = 5
arr[] = {1,2,3,4,5}
Output: 6
Explanation: Smallest positive missing
number is 6.
Example 2:
Input:
N = 5
arr[] = {0,-10,1,3,-20}
Output: 2
Explanation: Smallest posi... | class Solution:
def missingNumber(self, arr, n):
numSet = set(arr)
num = 1
for i in range(len(arr) + 1):
if num in numSet:
num += 1
return num | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR NUMBER RETURN VAR |
You are given an array arr[] of N integers including 0. The task is to find the smallest positive number missing from the array.
Example 1:
Input:
N = 5
arr[] = {1,2,3,4,5}
Output: 6
Explanation: Smallest positive missing
number is 6.
Example 2:
Input:
N = 5
arr[] = {0,-10,1,3,-20}
Output: 2
Explanation: Smallest posi... | class Solution:
def missingNumber(self, arr, n):
present = [(False) for _ in range(n + 1)]
for i in range(n):
if 0 < arr[i] <= n:
present[arr[i]] = True
for i in range(1, n + 1):
if not present[i]:
return i
return n + 1 | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF NUMBER VAR VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR RETURN VAR RETURN BIN_OP VAR NUMBER |
You are given an array arr[] of N integers including 0. The task is to find the smallest positive number missing from the array.
Example 1:
Input:
N = 5
arr[] = {1,2,3,4,5}
Output: 6
Explanation: Smallest positive missing
number is 6.
Example 2:
Input:
N = 5
arr[] = {0,-10,1,3,-20}
Output: 2
Explanation: Smallest posi... | class Solution:
def missingNumber(self, arr, n):
res = 0
i = 0
while i < n:
if arr[i] > 0:
arr[i], arr[res] = arr[res], arr[i]
res += 1
i += 1
for i in range(res):
if abs(arr[i]) - 1 >= res:
continue... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR IF VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN... |
You are given an array arr[] of N integers including 0. The task is to find the smallest positive number missing from the array.
Example 1:
Input:
N = 5
arr[] = {1,2,3,4,5}
Output: 6
Explanation: Smallest positive missing
number is 6.
Example 2:
Input:
N = 5
arr[] = {0,-10,1,3,-20}
Output: 2
Explanation: Smallest posi... | class Solution:
def missingNumber(self, arr, n):
c = 1
a = sorted(arr)
for i in a:
if i > c:
return c
elif i == c:
c += 1
return c | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR IF VAR VAR RETURN VAR IF VAR VAR VAR NUMBER RETURN VAR |
You are given an array arr[] of N integers including 0. The task is to find the smallest positive number missing from the array.
Example 1:
Input:
N = 5
arr[] = {1,2,3,4,5}
Output: 6
Explanation: Smallest positive missing
number is 6.
Example 2:
Input:
N = 5
arr[] = {0,-10,1,3,-20}
Output: 2
Explanation: Smallest posi... | class Solution:
def missingNumber(self, nums, n):
for i in range(n):
while nums[i] > 0 and nums[i] <= n and nums[nums[i] - 1] != nums[i]:
nums[nums[i] - 1], nums[i] = nums[i], nums[nums[i] - 1]
for i in range(n):
if nums[i] != i + 1:
return i ... | CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR NUMBER VAR VAR VAR VAR BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER |
You are given an array arr[] of N integers including 0. The task is to find the smallest positive number missing from the array.
Example 1:
Input:
N = 5
arr[] = {1,2,3,4,5}
Output: 6
Explanation: Smallest positive missing
number is 6.
Example 2:
Input:
N = 5
arr[] = {0,-10,1,3,-20}
Output: 2
Explanation: Smallest posi... | class Solution:
def missingNumber(self, arr, n):
arr = list(set(arr))
arr.sort()
s = 0
ind = 0
k = 1
for i in range(0, len(arr)):
if arr[i] >= 0:
s = arr[i]
ind = i
break
if s == 0:
k = 0... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR... |
You are given an array arr[] of N integers including 0. The task is to find the smallest positive number missing from the array.
Example 1:
Input:
N = 5
arr[] = {1,2,3,4,5}
Output: 6
Explanation: Smallest positive missing
number is 6.
Example 2:
Input:
N = 5
arr[] = {0,-10,1,3,-20}
Output: 2
Explanation: Smallest posi... | class Solution:
def missingNumber(self, arr, n):
for i in range(0, n):
while arr[i] > 0 and arr[i] <= n and arr[i] != arr[arr[i] - 1]:
temp = arr[i]
arr[i], arr[temp - 1] = arr[temp - 1], arr[i]
for i in range(0, n):
if arr[i] != i + 1:
... | CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER VAR WHILE VAR VAR NUMBER VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER |
You are given an array arr[] of N integers including 0. The task is to find the smallest positive number missing from the array.
Example 1:
Input:
N = 5
arr[] = {1,2,3,4,5}
Output: 6
Explanation: Smallest positive missing
number is 6.
Example 2:
Input:
N = 5
arr[] = {0,-10,1,3,-20}
Output: 2
Explanation: Smallest posi... | class Solution:
def missingNumber(self, arr, n):
for i in range(n):
if arr[i] % 10000000 > 0 and arr[i] % 10000000 <= n:
if arr[arr[i] % 10000000 - 1] < 0:
arr[arr[i] % 10000000 - 1] = 0
arr[arr[i] % 10000000 - 1] += 10000000
res = n +... | CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER VAR IF VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF V... |
You are given an array arr[] of N integers including 0. The task is to find the smallest positive number missing from the array.
Example 1:
Input:
N = 5
arr[] = {1,2,3,4,5}
Output: 6
Explanation: Smallest positive missing
number is 6.
Example 2:
Input:
N = 5
arr[] = {0,-10,1,3,-20}
Output: 2
Explanation: Smallest posi... | class Solution:
def missingNumber(self, arr, n):
missing_num = None
lst = [(0) for x in range(0, n + 2)]
for i in arr:
if i > 0:
try:
lst[i] = i
except:
pass
missing_num = lst[1:].index(0) + 1
... | CLASS_DEF FUNC_DEF ASSIGN VAR NONE ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER RETURN VAR |
You are given an array arr[] of N integers including 0. The task is to find the smallest positive number missing from the array.
Example 1:
Input:
N = 5
arr[] = {1,2,3,4,5}
Output: 6
Explanation: Smallest positive missing
number is 6.
Example 2:
Input:
N = 5
arr[] = {0,-10,1,3,-20}
Output: 2
Explanation: Smallest posi... | class Solution:
def missingNumber(self, arr, n):
arr = set(arr)
arr = sorted(list(arr))
c = 0
for i in range(n):
if arr[i] <= 0:
continue
elif c + 1 == arr[i]:
c = c + 1
continue
else:
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER |
You are given an array arr[] of N integers including 0. The task is to find the smallest positive number missing from the array.
Example 1:
Input:
N = 5
arr[] = {1,2,3,4,5}
Output: 6
Explanation: Smallest positive missing
number is 6.
Example 2:
Input:
N = 5
arr[] = {0,-10,1,3,-20}
Output: 2
Explanation: Smallest posi... | class Solution:
def missingNumber(self, arr, n):
a = []
for i in range(n + 1):
a.append("x")
for i in range(n):
if arr[i] >= 0 and arr[i] <= n:
a[arr[i]] = arr[i]
for i in range(1, n + 1):
if a[i] == "x":
return i
... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR STRING RETURN VAR RETURN BIN_OP VAR NUMBER NUMBER |
You are given an array arr[] of N integers including 0. The task is to find the smallest positive number missing from the array.
Example 1:
Input:
N = 5
arr[] = {1,2,3,4,5}
Output: 6
Explanation: Smallest positive missing
number is 6.
Example 2:
Input:
N = 5
arr[] = {0,-10,1,3,-20}
Output: 2
Explanation: Smallest posi... | class Solution:
def missingNumber(self, arr, n):
m = max(arr)
if m < 1:
return 1
if len(arr) == 1:
return 2 if arr[0] == 1 else 1
l = [0] * m
for i in range(n):
if arr[i] > 0:
if l[arr[i] - 1] != 1:
l[ar... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR F... |
You are given an array arr[] of N integers including 0. The task is to find the smallest positive number missing from the array.
Example 1:
Input:
N = 5
arr[] = {1,2,3,4,5}
Output: 6
Explanation: Smallest positive missing
number is 6.
Example 2:
Input:
N = 5
arr[] = {0,-10,1,3,-20}
Output: 2
Explanation: Smallest posi... | class Solution:
def missingNumber(self, arr, n):
li = list(set(arr))
li.sort()
j = 1
for i in range(n):
if li[i] >= 1:
if li[i] > j:
return j
j = j + 1
if max(li) < 0:
return 1
else:
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR VAR VAR RETURN VAR ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER RETURN BIN_OP FUNC_CALL VAR VAR NUMBER |
You are given an array arr[] of N integers including 0. The task is to find the smallest positive number missing from the array.
Example 1:
Input:
N = 5
arr[] = {1,2,3,4,5}
Output: 6
Explanation: Smallest positive missing
number is 6.
Example 2:
Input:
N = 5
arr[] = {0,-10,1,3,-20}
Output: 2
Explanation: Smallest posi... | class Solution:
def missingNumber(self, arr, n):
j = n - 1
for i in range(n):
if arr[i] < 1 or arr[i] > n:
while j >= 0 and (arr[j] < 1 or arr[j] > n):
j -= 1
if j <= i:
break
arr[i], arr[j] = arr[j]... | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR WHILE VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR IF VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN... |
Given a string of digits, the task is to check if it is a ‘sum-string’. A string S is called a sum-string if a rightmost substring can be written as a sum of two substrings before it and the same is recursively true for substrings before it.
Example 1:
Input:
12243660
Output:
1
Explanation:
"12243660" is a sum strin... | class Solution:
def isSumString(ob, S):
def rec(first, second, rest):
if len(rest) == 0:
return True
total = str(first + second)
l = len(total)
if total == rest[:l]:
return rec(second, int(total), rest[l:])
for i in r... | CLASS_DEF FUNC_DEF FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR ... |
Given a string of digits, the task is to check if it is a ‘sum-string’. A string S is called a sum-string if a rightmost substring can be written as a sum of two substrings before it and the same is recursively true for substrings before it.
Example 1:
Input:
12243660
Output:
1
Explanation:
"12243660" is a sum strin... | class Solution:
def isSumString(self, s: str) -> int:
n = len(s)
for i in range(1, n):
for j in range(i + 1, n):
x = int(s[:i])
y = int(s[i:j])
k = j
while k < n:
z = x + y
sz = str(z... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR FUNC_CALL V... |
Given a string of digits, the task is to check if it is a ‘sum-string’. A string S is called a sum-string if a rightmost substring can be written as a sum of two substrings before it and the same is recursively true for substrings before it.
Example 1:
Input:
12243660
Output:
1
Explanation:
"12243660" is a sum strin... | class Solution:
def first(ob, S):
possib = []
for i in range(1, len(S) - 2):
s1 = S[0:i]
for j in range(i + 1, len(S) - 1):
s2 = S[i:j]
s3 = str(int(s1) + int(s2))
if s3 == S[j : j + len(s3)]:
possib.append(... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR FUNC_CALL... |
Given a string of digits, the task is to check if it is a ‘sum-string’. A string S is called a sum-string if a rightmost substring can be written as a sum of two substrings before it and the same is recursively true for substrings before it.
Example 1:
Input:
12243660
Output:
1
Explanation:
"12243660" is a sum strin... | class Solution:
def isSumString(ob, S):
def dfs(S, s1, s2, s3, i):
if i == len(S):
if s3 != "" and int(s1) + int(s2) != int(s3):
return False
return True
if int(s3 + S[i]) > int(s1) + int(s2):
return False
... | CLASS_DEF FUNC_DEF FUNC_DEF IF VAR FUNC_CALL VAR VAR IF VAR STRING BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN NUMBER RETURN NUMBER IF FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN NUMBER IF FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL ... |
Given a string of digits, the task is to check if it is a ‘sum-string’. A string S is called a sum-string if a rightmost substring can be written as a sum of two substrings before it and the same is recursively true for substrings before it.
Example 1:
Input:
12243660
Output:
1
Explanation:
"12243660" is a sum strin... | class Solution:
def isSumString(self, S):
n = len(S)
for l in range(1, n):
sub_arr = int(S[n - l :])
if self.is_sum_string_sub(S, n - l, sub_arr, None) == 1:
return 1
return 0
def is_sum_string_sub(self, S, limit, sub_arr, sub_1):
sub_2 =... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR BIN_OP VAR VAR VAR NONE NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR NUMBER IF VAR NONE ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR ... |
Given a string of digits, the task is to check if it is a ‘sum-string’. A string S is called a sum-string if a rightmost substring can be written as a sum of two substrings before it and the same is recursively true for substrings before it.
Example 1:
Input:
12243660
Output:
1
Explanation:
"12243660" is a sum strin... | class Solution:
def solve(self, i, S, P, lst=[]):
if i >= len(S) and P > 2:
return True
if i >= len(S) and P <= 2:
return False
for j in range(i, len(S)):
if P < 2:
lst.append(S[i : j + 1])
if self.solve(j + 1, S, P + 1, ls... | CLASS_DEF FUNC_DEF LIST IF VAR FUNC_CALL VAR VAR VAR NUMBER RETURN NUMBER IF VAR FUNC_CALL VAR VAR VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR RETURN NUMBER EXPR FUNC_CALL VAR... |
Given a string of digits, the task is to check if it is a ‘sum-string’. A string S is called a sum-string if a rightmost substring can be written as a sum of two substrings before it and the same is recursively true for substrings before it.
Example 1:
Input:
12243660
Output:
1
Explanation:
"12243660" is a sum strin... | class Solution:
def isSumString(ob, S):
def getsum(s1, s2):
if s1 == "" and s2 == "":
return ""
if s1 == "":
return s2
if s2 == "":
return s1
first = int(s1)
second = int(s2)
return str(... | CLASS_DEF FUNC_DEF FUNC_DEF IF VAR STRING VAR STRING RETURN STRING IF VAR STRING RETURN VAR IF VAR STRING RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR BIN_OP VAR VAR FUNC_DEF ASSIGN VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR... |
Given a string of digits, the task is to check if it is a ‘sum-string’. A string S is called a sum-string if a rightmost substring can be written as a sum of two substrings before it and the same is recursively true for substrings before it.
Example 1:
Input:
12243660
Output:
1
Explanation:
"12243660" is a sum strin... | class Solution:
def isSumString(ob, S, idx=0, val1=None, val2=None, cnt=0):
if idx == len(S):
return 1 if cnt > 2 else 0
if val1 == None:
tmp = ""
for i in range(idx, len(S) // 3 + 1):
tmp += S[i]
if ob.isSumString(S, i + 1, tmp, v... | CLASS_DEF FUNC_DEF NUMBER NONE NONE NUMBER IF VAR FUNC_CALL VAR VAR RETURN VAR NUMBER NUMBER NUMBER IF VAR NONE ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR VAR IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER RETURN NUMBER RETURN NUMBER IF VAR NONE A... |
Given a string of digits, the task is to check if it is a ‘sum-string’. A string S is called a sum-string if a rightmost substring can be written as a sum of two substrings before it and the same is recursively true for substrings before it.
Example 1:
Input:
12243660
Output:
1
Explanation:
"12243660" is a sum strin... | class Solution:
def __init__(self):
self.flag = False
self.ans = False
def checkSum(self, prev, num, numprev, lenn, n):
while prev < lenn:
wenge = str(num + numprev)
t = len(wenge)
if prev + t > lenn:
return "Length over", False
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR RETURN STRING NUMBER IF VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR RETURN STRI... |
Given a string of digits, the task is to check if it is a ‘sum-string’. A string S is called a sum-string if a rightmost substring can be written as a sum of two substrings before it and the same is recursively true for substrings before it.
Example 1:
Input:
12243660
Output:
1
Explanation:
"12243660" is a sum strin... | class Solution:
def isSumString(ob, S):
def rec(s, beg, l1, l2):
s1 = s[beg : beg + l1]
s2 = s[beg + l1 : beg + l1 + l2]
s3 = str(int(s1) + int(s2))
l3 = len(s3)
if beg + l1 + l2 + l3 > len(s):
return False
elif s3 == ... | CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR RETURN NUMBER IF VAR VAR BIN_OP BIN_OP VAR VAR ... |
Given a string of digits, the task is to check if it is a ‘sum-string’. A string S is called a sum-string if a rightmost substring can be written as a sum of two substrings before it and the same is recursively true for substrings before it.
Example 1:
Input:
12243660
Output:
1
Explanation:
"12243660" is a sum strin... | class Solution:
def isSumString(ob, s):
len_s = len(s)
def rec(s1, s2, en2):
s3 = str(s1 + s2)
len_s3 = len(s3)
if len_s3 > len_s - en2 - 1:
return 0
elif len_s3 == len_s - en2 - 1 and s[en2 + 1 :] == s3:
return 1
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN NUMBER IF VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR RETURN NUMBER RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR FOR VAR FU... |
Given a string of digits, the task is to check if it is a ‘sum-string’. A string S is called a sum-string if a rightmost substring can be written as a sum of two substrings before it and the same is recursively true for substrings before it.
Example 1:
Input:
12243660
Output:
1
Explanation:
"12243660" is a sum strin... | class Solution:
def solve(ob, s, idx, a, b, found):
if idx == len(s):
if found == True:
return 1
return 0
t = ""
for i in range(idx, len(s)):
t += s[i]
if a == -1:
if ob.solve(s, i + 1, int(t), b, found):
... | CLASS_DEF FUNC_DEF IF VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR RETURN NUMBER IF VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL ... |
Given a string of digits, the task is to check if it is a ‘sum-string’. A string S is called a sum-string if a rightmost substring can be written as a sum of two substrings before it and the same is recursively true for substrings before it.
Example 1:
Input:
12243660
Output:
1
Explanation:
"12243660" is a sum strin... | class Solution:
def getSequenceLength(self, x0, x1, pos, S):
if pos == len(S):
return 0
x2 = str(x0 + x1)
if pos + len(x2) > len(S):
return -1
if S[pos : pos + len(x2)] != x2:
return -1
else:
seq_len = self.getSequenceLength(x1... | CLASS_DEF FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR IF BIN_OP VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN NUMBER IF VAR VAR BIN_OP VAR FUNC_CALL VAR VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER RETURN NU... |
Given a string S that contains only digits (0-9) and an integer target, return all possible strings to insert the binary operator ' + ', ' - ', or ' * ' between the digits of S so that the resultant expression evaluates to the target value.
Note:
Operands in the returned expressions should not contain leading zeros. F... | class Solution:
def addOperators(self, S, target):
res = []
def helper(ind, tmp, curr_sum, prev):
if ind == len(S):
if curr_sum == target:
res.append("".join(tmp))
return
for i in range(ind, len(S)):
curr_s... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FUNC_DEF IF VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR RETURN FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER LIST VAR VAR VAR EXPR FUNC_CALL VAR BIN... |
Given a string S that contains only digits (0-9) and an integer target, return all possible strings to insert the binary operator ' + ', ' - ', or ' * ' between the digits of S so that the resultant expression evaluates to the target value.
Note:
Operands in the returned expressions should not contain leading zeros. F... | class Solution:
def addOperators(self, num: "str", target: "int") -> "List[str]":
def backtracking(idx=0, path="", value=0, prev=None):
if idx == len(num) and value == target:
rtn.append(path)
return
for i in range(idx + 1, len(num) + 1):
... | CLASS_DEF FUNC_DEF STRING STRING FUNC_DEF NUMBER STRING NUMBER NONE IF VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR NONE EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR BI... |
Given a string S that contains only digits (0-9) and an integer target, return all possible strings to insert the binary operator ' + ', ' - ', or ' * ' between the digits of S so that the resultant expression evaluates to the target value.
Note:
Operands in the returned expressions should not contain leading zeros. F... | class Solution:
def addOperators(self, S, target):
def dfs(l, r, expr, cur, last, res):
if l == r:
if cur == target:
res.append(expr)
return
for i in range(l + 1, r + 1):
if i == l + 1 or i > l + 1 and S[l] != "0":... | CLASS_DEF FUNC_DEF FUNC_DEF IF VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR STRING ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR NONE EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CA... |
Given a string S that contains only digits (0-9) and an integer target, return all possible strings to insert the binary operator ' + ', ' - ', or ' * ' between the digits of S so that the resultant expression evaluates to the target value.
Note:
Operands in the returned expressions should not contain leading zeros. F... | class Solution:
def addOperators(self, num, target):
def backtrack(path, prev_operand, curr_operand, value, index):
if index == len(num):
if value == target and curr_operand == 0:
res.append("".join(path[1:]))
return
curr_operand ... | CLASS_DEF FUNC_DEF FUNC_DEF IF VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER RETURN ASSIGN VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_C... |
Given a string S that contains only digits (0-9) and an integer target, return all possible strings to insert the binary operator ' + ', ' - ', or ' * ' between the digits of S so that the resultant expression evaluates to the target value.
Note:
Operands in the returned expressions should not contain leading zeros. F... | def getExprUtil(res, curExp, _input, target, pos, curVal, last):
if pos == len(_input):
if curVal == target:
res.append(curExp)
return
for i in range(pos, len(_input)):
if i != pos and _input[pos] == "0":
break
part = _input[pos : i + 1].strip()
cu... | FUNC_DEF IF VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CAL... |
Given a string S that contains only digits (0-9) and an integer target, return all possible strings to insert the binary operator ' + ', ' - ', or ' * ' between the digits of S so that the resultant expression evaluates to the target value.
Note:
Operands in the returned expressions should not contain leading zeros. F... | class Solution:
def generate(self, num, target, curr, res, build, prevNumber, currSum, n):
if curr == len(num):
if currSum == target:
res.append(build)
return
for length in range(1, n - curr + 1):
number = num[curr : curr + length]
if ... | CLASS_DEF FUNC_DEF IF VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR IF VAR NUMBER STRING FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR STRI... |
Given a string S that contains only digits (0-9) and an integer target, return all possible strings to insert the binary operator ' + ', ' - ', or ' * ' between the digits of S so that the resultant expression evaluates to the target value.
Note:
Operands in the returned expressions should not contain leading zeros. F... | class Solution:
def solve(self, i, S, target, ans, lst=[]):
if i >= len(S):
a = lst
i = 0
stack = []
while i < len(a) - 1:
if a[i + 1] == "*":
mul = 1
while i < len(a) - 1 and a[i + 1] == "*":
... | CLASS_DEF FUNC_DEF LIST IF VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF V... |
Given a string S that contains only digits (0-9) and an integer target, return all possible strings to insert the binary operator ' + ', ' - ', or ' * ' between the digits of S so that the resultant expression evaluates to the target value.
Note:
Operands in the returned expressions should not contain leading zeros. F... | class Solution:
def solve(self, ind, S, target, evalu, ans, res, mul):
if ind == len(S):
if evalu == target:
res.append(ans)
return
for i in range(ind, len(S)):
if ind != i and S[ind] == "0":
break
cur = int(S[ind : i +... | CLASS_DEF FUNC_DEF IF VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL... |
Given a string S that contains only digits (0-9) and an integer target, return all possible strings to insert the binary operator ' + ', ' - ', or ' * ' between the digits of S so that the resultant expression evaluates to the target value.
Note:
Operands in the returned expressions should not contain leading zeros. F... | class Solution:
def addOperators(self, S, target):
results = []
def dfs(index, expression, value, prev_operand, target):
if index == len(S):
if value == target:
results.append(expression)
return
operand = 0
for... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FUNC_DEF IF VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC... |
Given a string S that contains only digits (0-9) and an integer target, return all possible strings to insert the binary operator ' + ', ' - ', or ' * ' between the digits of S so that the resultant expression evaluates to the target value.
Note:
Operands in the returned expressions should not contain leading zeros. F... | class Solution:
def addops(self, target, value, S, index, seq, lastnum, lastop):
if index == len(S):
if value == target:
self.res.append(seq)
return
maxend = len(S)
if S[index] == "0":
maxend = index + 1
for end in range(index + 1,... | CLASS_DEF FUNC_DEF IF VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP VAR ... |
Given a string S that contains only digits (0-9) and an integer target, return all possible strings to insert the binary operator ' + ', ' - ', or ' * ' between the digits of S so that the resultant expression evaluates to the target value.
Note:
Operands in the returned expressions should not contain leading zeros. F... | class Solution:
def addOperators(self, S, target):
def dfs(S: str, tmp: str, curr: int, prev: int) -> None:
nonlocal target
if not S:
if curr == target:
ans.append(tmp)
return
for i in range(len(S)):
pr... | CLASS_DEF FUNC_DEF FUNC_DEF VAR VAR VAR VAR IF VAR IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER STRING EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR STRING VAR BIN_OP VAR FUNC_CALL VAR VAR FUNC_... |
Given a string S of length N containing only numeric characters, find the number of Nice Pairs.
A Nice Pair is a pair of indices - (i, j) such that 1 ≤ i < j ≤ N and j - i = |S_{j} - S_{i}|.
------ Input Format ------
- First line will contain T, number of testcases. Then the testcases follow.
- The first line of e... | for i in range(int(input())):
k1 = int(input())
str1 = input()
c1 = 0
for k in range(k1):
for j in range(k + 1, min(k + 11, k1)):
if abs(k - j) == abs(int(str1[k]) - int(str1[j])):
c1 += 1
print(c1) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL V... |
Given a string S of length N containing only numeric characters, find the number of Nice Pairs.
A Nice Pair is a pair of indices - (i, j) such that 1 ≤ i < j ≤ N and j - i = |S_{j} - S_{i}|.
------ Input Format ------
- First line will contain T, number of testcases. Then the testcases follow.
- The first line of e... | t = int(input())
for i in range(t):
n = int(input())
s = list(map(int, list(input())))
c = 0
for j in range(n):
for k in range(j + 1, min(j + 10, n)):
if k - j == abs(s[j] - s[k]):
c += 1
print(c) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF BIN_OP VAR VAR FUNC_CA... |
Given a string S of length N containing only numeric characters, find the number of Nice Pairs.
A Nice Pair is a pair of indices - (i, j) such that 1 ≤ i < j ≤ N and j - i = |S_{j} - S_{i}|.
------ Input Format ------
- First line will contain T, number of testcases. Then the testcases follow.
- The first line of e... | for t in range(int(input())):
n = int(input())
s = input()
res = 0
if n < 10:
for i in range(n - 1):
for j in range(i + 1, n):
if j - i == abs(int(s[i]) - int(s[j])):
res += 1
print(res)
continue
for i in range(n - 9):
f... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF BIN_OP VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUM... |
Given a string S of length N containing only numeric characters, find the number of Nice Pairs.
A Nice Pair is a pair of indices - (i, j) such that 1 ≤ i < j ≤ N and j - i = |S_{j} - S_{i}|.
------ Input Format ------
- First line will contain T, number of testcases. Then the testcases follow.
- The first line of e... | T = int(input())
for a in range(T):
N = int(input())
s = input()[:N]
c = 0
for i in range(len(s)):
for j in range(i + 1, min(N, i + 9 + 1)):
if j - i > 9:
continue
if j - i == abs(int(s[j]) - int(s[i])):
c = c + 1
print(c) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER IF BIN_OP VAR ... |
Given a string S of length N containing only numeric characters, find the number of Nice Pairs.
A Nice Pair is a pair of indices - (i, j) such that 1 ≤ i < j ≤ N and j - i = |S_{j} - S_{i}|.
------ Input Format ------
- First line will contain T, number of testcases. Then the testcases follow.
- The first line of e... | t = int(input())
for k in range(t):
n = int(input())
s = str(input())
count = 0
for i in range(1, n + 1):
for j in range(i + 1, min(n, i + 9) + 1):
if int(j) > int(i) and int(j) - int(i) == abs(
int(s[j - 1]) - int(s[i - 1])
):
count += 1
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR F... |
Given a string S of length N containing only numeric characters, find the number of Nice Pairs.
A Nice Pair is a pair of indices - (i, j) such that 1 ≤ i < j ≤ N and j - i = |S_{j} - S_{i}|.
------ Input Format ------
- First line will contain T, number of testcases. Then the testcases follow.
- The first line of e... | t = int(input())
while t:
n = int(input())
s = input()
string = []
for i in s:
string.append(int(i))
count = 0
for i in range(n - 1):
for j in range(i + 1, n):
if j - i > 9:
break
diff = abs(string[i] - string[j])
if diff == j -... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC... |
Given a string S of length N containing only numeric characters, find the number of Nice Pairs.
A Nice Pair is a pair of indices - (i, j) such that 1 ≤ i < j ≤ N and j - i = |S_{j} - S_{i}|.
------ Input Format ------
- First line will contain T, number of testcases. Then the testcases follow.
- The first line of e... | t = int(input())
for i in range(t):
a = int(input())
b = input()
c = 0
for i in range(1, a + 1):
for k in range(i + 1, min(10 + i, a + 1)):
if k - i == abs(int(b[k - 1]) - int(b[i - 1])):
c += 1
print(c) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR BIN_... |
Given a string S of length N containing only numeric characters, find the number of Nice Pairs.
A Nice Pair is a pair of indices - (i, j) such that 1 ≤ i < j ≤ N and j - i = |S_{j} - S_{i}|.
------ Input Format ------
- First line will contain T, number of testcases. Then the testcases follow.
- The first line of e... | for _ in range(int(input())):
n = int(input())
s = str(input())
c = 0
for i in range(n):
j = i + 1
while j <= min(i + 9, n - 1):
if j - i == abs(int(s[j]) - int(s[i])):
c += 1
j += 1
print(c) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VA... |
Given a string S of length N containing only numeric characters, find the number of Nice Pairs.
A Nice Pair is a pair of indices - (i, j) such that 1 ≤ i < j ≤ N and j - i = |S_{j} - S_{i}|.
------ Input Format ------
- First line will contain T, number of testcases. Then the testcases follow.
- The first line of e... | for i in range(int(input())):
n = int(input())
arr = [int(x) for x in input()]
cnt = 0
for j in range(n - 1):
for k in range(j + 1, min(j + 10, n)):
if abs(arr[k] - arr[j]) == k - j:
cnt += 1
print(cnt) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF FUNC_CALL VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR... |
Given a string S of length N containing only numeric characters, find the number of Nice Pairs.
A Nice Pair is a pair of indices - (i, j) such that 1 ≤ i < j ≤ N and j - i = |S_{j} - S_{i}|.
------ Input Format ------
- First line will contain T, number of testcases. Then the testcases follow.
- The first line of e... | t = int(input())
def solve(s):
s = list(map(int, list(s)))
c, n = 0, len(s)
for i in range(n):
for j in range(i + 1, min(i + 10, n)):
if abs(s[i] - s[j]) == j - i:
c += 1
return c
for _ in range(t):
n = int(input())
x = input()
print(solve(x)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF FUNC_CALL VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER RET... |
Given a string S of length N containing only numeric characters, find the number of Nice Pairs.
A Nice Pair is a pair of indices - (i, j) such that 1 ≤ i < j ≤ N and j - i = |S_{j} - S_{i}|.
------ Input Format ------
- First line will contain T, number of testcases. Then the testcases follow.
- The first line of e... | def NPAIRS(inputline1: int, inputline2: str) -> int:
size = inputline1
numbers = list(inputline2)
numbers = [int(i) for i in numbers]
numbers = numbers + ["dead"]
maincount = 0
for i in range(size):
temp = 0
while temp < 9:
temp += 1
if numbers[i + temp] =... | FUNC_DEF VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR LIST STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER IF VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR VAR ... |
Given a string S of length N containing only numeric characters, find the number of Nice Pairs.
A Nice Pair is a pair of indices - (i, j) such that 1 ≤ i < j ≤ N and j - i = |S_{j} - S_{i}|.
------ Input Format ------
- First line will contain T, number of testcases. Then the testcases follow.
- The first line of e... | t = int(input())
for m in range(t):
x = int(input())
l = input()
count = 0
for i in range(x):
for j in range(i + 1, min(x, i + 11)):
p = abs(int(l[i]) - int(l[j]))
if j - i == p:
count = count + 1
print(count) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR... |
Given a string S of length N containing only numeric characters, find the number of Nice Pairs.
A Nice Pair is a pair of indices - (i, j) such that 1 ≤ i < j ≤ N and j - i = |S_{j} - S_{i}|.
------ Input Format ------
- First line will contain T, number of testcases. Then the testcases follow.
- The first line of e... | def solve(arr):
ans = 0
for i in range(len(arr)):
for j in range(1, min(10, len(arr) - i)):
if abs(int(arr[i]) - int(arr[i + j])) == j:
ans += 1
return ans
for _ in range(int(input())):
a = input()
print(solve(input())) | FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CAL... |
Given a string S of length N containing only numeric characters, find the number of Nice Pairs.
A Nice Pair is a pair of indices - (i, j) such that 1 ≤ i < j ≤ N and j - i = |S_{j} - S_{i}|.
------ Input Format ------
- First line will contain T, number of testcases. Then the testcases follow.
- The first line of e... | t = int(input())
for _ in range(t):
n = int(input())
s = input()
count = 0
for i in range(n - 1):
num1 = int(s[i])
for j in range(i + 1, min(n, i + 10)):
num2 = int(s[j])
if abs(num1 - num2) == j - i:
count += 1
print(count) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR... |
Given a string S of length N containing only numeric characters, find the number of Nice Pairs.
A Nice Pair is a pair of indices - (i, j) such that 1 ≤ i < j ≤ N and j - i = |S_{j} - S_{i}|.
------ Input Format ------
- First line will contain T, number of testcases. Then the testcases follow.
- The first line of e... | def fun(ls):
neg_mod = []
pos_mod = []
for i, val in enumerate(ls, start=1):
neg_mod.append(val + i)
pos_mod.append(val - i)
neg_value_with_index = {}
pos_value_with_index = {}
for index, val in enumerate(zip(neg_mod, pos_mod), start=1):
neg_mod_val = val[0]
pos_m... | FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR NONE EXPR FUNC_CALL VA... |
Given a string S of length N containing only numeric characters, find the number of Nice Pairs.
A Nice Pair is a pair of indices - (i, j) such that 1 ≤ i < j ≤ N and j - i = |S_{j} - S_{i}|.
------ Input Format ------
- First line will contain T, number of testcases. Then the testcases follow.
- The first line of e... | t = int(input())
for _ in range(t):
n = int(input())
s = input()
c = 0
for i in range(n):
p = int(s[i])
for j in range(i + 1, min(n - 1, i + 9) + 1):
p1 = int(s[j])
if abs(p1 - p) == j + 1 - (i + 1):
c = c + 1
print(c) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR... |
Given a string S of length N containing only numeric characters, find the number of Nice Pairs.
A Nice Pair is a pair of indices - (i, j) such that 1 ≤ i < j ≤ N and j - i = |S_{j} - S_{i}|.
------ Input Format ------
- First line will contain T, number of testcases. Then the testcases follow.
- The first line of e... | for _ in range(int(input())):
ans = 0
n = int(input())
s = input()
for i in range(n - 1):
for j in range(i + 1, i + 10):
if j < n:
if abs(int(s[i]) - int(s[j])) == j - i:
ans += 1
print(ans) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR IF FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR ... |
Given a string S of length N containing only numeric characters, find the number of Nice Pairs.
A Nice Pair is a pair of indices - (i, j) such that 1 ≤ i < j ≤ N and j - i = |S_{j} - S_{i}|.
------ Input Format ------
- First line will contain T, number of testcases. Then the testcases follow.
- The first line of e... | for _ in range(int(input())):
n = int(input())
s = input()
c = 0
for i in range(1, len(s) + 1):
for j in range(i + 1, min(9 + i, n) + 1):
if (
j - i == abs(int(s[j - 1]) - int(s[i - 1]))
and int(s[j - 1]) - int(s[i - 1]) != 0
):
... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP NUMBER VAR VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR BIN_O... |
Given a string S of length N containing only numeric characters, find the number of Nice Pairs.
A Nice Pair is a pair of indices - (i, j) such that 1 ≤ i < j ≤ N and j - i = |S_{j} - S_{i}|.
------ Input Format ------
- First line will contain T, number of testcases. Then the testcases follow.
- The first line of e... | for _ in range(int(input())):
n = int(input())
l = list(input().strip())
l = list(map(int, l))
ans = 0
for i in range(n):
for k in range(1, 10):
j = i + k
if j >= n:
continue
if abs(l[i] - l[j]) == k:
ans += 1
print(ans) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR IF FUNC_CALL VAR B... |
Given an integer array of N elements. You need to find the maximum sum of two elements such that sum is closest to zero.
Example 1:
Input:
N = 3
arr[] = {-8 -66 -60}
Output: -68
Explanation: Sum of two elements closest to
zero is -68 using numbers -60 and -8.
Example 2:
Input:
N = 6
arr[] = {-21 -67 -37 -18 4 -65}
Ou... | class Solution:
def closestToZero(self, arr, n):
arr.sort()
i = 0
j = n - 1
ans = arr[0] + arr[1]
while i < j:
t = arr[i] + arr[j]
if abs(t) < abs(ans):
ans = t
if abs(t) == abs(ans) and t >= 0:
ans = t
... | CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER VAR... |
Given an integer array of N elements. You need to find the maximum sum of two elements such that sum is closest to zero.
Example 1:
Input:
N = 3
arr[] = {-8 -66 -60}
Output: -68
Explanation: Sum of two elements closest to
zero is -68 using numbers -60 and -8.
Example 2:
Input:
N = 6
arr[] = {-21 -67 -37 -18 4 -65}
Ou... | class Solution:
def closestToZero(self, arr, n):
arr.sort()
tar = 0
ans = float("inf")
l = 0
r = len(arr) - 1
while l < r:
sum = arr[l] + arr[r]
if sum == 0:
ans = 0
break
elif sum < 0:
... | CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR ... |
Given an integer array of N elements. You need to find the maximum sum of two elements such that sum is closest to zero.
Example 1:
Input:
N = 3
arr[] = {-8 -66 -60}
Output: -68
Explanation: Sum of two elements closest to
zero is -68 using numbers -60 and -8.
Example 2:
Input:
N = 6
arr[] = {-21 -67 -37 -18 4 -65}
Ou... | class Solution:
def closestToZero(self, arr, n):
srt = sorted(arr)
left = 0
right = len(arr) - 1
closest = srt[left] + srt[right]
while left < right:
s = srt[left] + srt[right]
if abs(s) == abs(closest) and s > closest:
closest = s
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR IF VAR NUMBER... |
Given an integer array of N elements. You need to find the maximum sum of two elements such that sum is closest to zero.
Example 1:
Input:
N = 3
arr[] = {-8 -66 -60}
Output: -68
Explanation: Sum of two elements closest to
zero is -68 using numbers -60 and -8.
Example 2:
Input:
N = 6
arr[] = {-21 -67 -37 -18 4 -65}
Ou... | class Solution:
def closestToZero(self, arr, n):
arr.sort()
i, j = 0, n - 1
k = -(10**9)
while j > i:
if arr[j] + arr[i] == 0:
return 0
if abs(arr[j] + arr[i]) <= abs(k):
if abs(k) == abs(arr[j] + arr[i]):
k... | CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER WHILE VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER RETURN NUMBER IF FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_... |
Given an integer array of N elements. You need to find the maximum sum of two elements such that sum is closest to zero.
Example 1:
Input:
N = 3
arr[] = {-8 -66 -60}
Output: -68
Explanation: Sum of two elements closest to
zero is -68 using numbers -60 and -8.
Example 2:
Input:
N = 6
arr[] = {-21 -67 -37 -18 4 -65}
Ou... | class Solution:
def closestToZero(self, arr, n):
arr.sort()
i = 0
j = 0
result = float("-inf")
diff = float("inf")
while i + j + 1 < n:
summa = arr[i] + arr[-j - 1]
abs_summa = abs(summa)
if abs_summa < diff:
diff =... | CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING WHILE BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR FUN... |
Given an integer array of N elements. You need to find the maximum sum of two elements such that sum is closest to zero.
Example 1:
Input:
N = 3
arr[] = {-8 -66 -60}
Output: -68
Explanation: Sum of two elements closest to
zero is -68 using numbers -60 and -8.
Example 2:
Input:
N = 6
arr[] = {-21 -67 -37 -18 4 -65}
Ou... | class Solution:
def closestToZero(self, arr, n):
arr.sort()
if arr[0] >= 0:
return arr[0] + arr[1]
elif arr[n - 1] < 0:
return arr[n - 1] + arr[n - 2]
else:
start = 0
end = n
mid = start + (end - start) // 2
ans... | CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR IF VAR NUMBER NUMBER RETURN BIN_OP VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER RETURN BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER A... |
Given an integer array of N elements. You need to find the maximum sum of two elements such that sum is closest to zero.
Example 1:
Input:
N = 3
arr[] = {-8 -66 -60}
Output: -68
Explanation: Sum of two elements closest to
zero is -68 using numbers -60 and -8.
Example 2:
Input:
N = 6
arr[] = {-21 -67 -37 -18 4 -65}
Ou... | import sys
class Solution:
def closestToZero(self, arr, n):
arr.sort()
i, j = 0, len(arr) - 1
sum = arr[i] + arr[j]
diff = abs(sum)
while i < j:
if arr[i] + arr[j] == 0:
return 0
if abs(arr[i] + arr[j]) < abs(diff):
d... | IMPORT CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER RETURN NUMBER IF FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIG... |
Given an integer array of N elements. You need to find the maximum sum of two elements such that sum is closest to zero.
Example 1:
Input:
N = 3
arr[] = {-8 -66 -60}
Output: -68
Explanation: Sum of two elements closest to
zero is -68 using numbers -60 and -8.
Example 2:
Input:
N = 6
arr[] = {-21 -67 -37 -18 4 -65}
Ou... | class Solution:
def closestToZero(self, arr, n):
arr.sort()
i, j = 0, n - 1
max_sum = -99999999999
while i < j:
cur_sum = arr[i] + arr[j]
if cur_sum < 0:
if abs(cur_sum) < abs(max_sum):
max_sum = cur_sum
i +... | CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR NUMBER RETURN NUMBER RETURN VAR |
Given an integer array of N elements. You need to find the maximum sum of two elements such that sum is closest to zero.
Example 1:
Input:
N = 3
arr[] = {-8 -66 -60}
Output: -68
Explanation: Sum of two elements closest to
zero is -68 using numbers -60 and -8.
Example 2:
Input:
N = 6
arr[] = {-21 -67 -37 -18 4 -65}
Ou... | class Solution:
def closestToZero(self, arr, n):
arr = sorted(arr)
i = 0
j = n - 1
prev_sum = 1000000009
while i < j:
if abs(arr[i] + arr[j]) < prev_sum:
prev_sum = abs(arr[i] + arr[j])
ans = arr[i] + arr[j]
elif abs(ar... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VA... |
Given an integer array of N elements. You need to find the maximum sum of two elements such that sum is closest to zero.
Example 1:
Input:
N = 3
arr[] = {-8 -66 -60}
Output: -68
Explanation: Sum of two elements closest to
zero is -68 using numbers -60 and -8.
Example 2:
Input:
N = 6
arr[] = {-21 -67 -37 -18 4 -65}
Ou... | class Solution:
def closestToZero(self, arr, n):
if n == 2:
return sum(arr)
arr.sort()
i = 0
j = n - 1
mini = 10**9
maxi = -(10**9)
while i < j and j < n:
sumi = arr[i] + arr[j]
if sumi < 0:
maxi = max(maxi,... | CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER WHILE VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NUMBER ASSI... |
Given an integer array of N elements. You need to find the maximum sum of two elements such that sum is closest to zero.
Example 1:
Input:
N = 3
arr[] = {-8 -66 -60}
Output: -68
Explanation: Sum of two elements closest to
zero is -68 using numbers -60 and -8.
Example 2:
Input:
N = 6
arr[] = {-21 -67 -37 -18 4 -65}
Ou... | class Solution:
def closestToZero(self, arr, n):
arr.sort()
maxi = 1e19
l = 0
h = len(arr) - 1
while l < h:
s = arr[l] + arr[h]
if abs(0 - s) < abs(0 - maxi):
maxi = s
elif abs(0 - s) == abs(0 - maxi):
maxi ... | CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF FUNC_CALL VAR BIN_OP NUMBER VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR VAR IF FUNC_CALL VAR BIN_OP NUMBER VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.