description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
Given a sequence of matrices, find the most efficient way to multiply these matrices together. The efficient way is the one that involves the least number of multiplications.
The dimensions of the matrices are given in an array arr[] of size N (such that N = number of matrices + 1) where the i^{th} matrix has the dime... | class Solution:
def matrixMultiplication(self, N, arr):
memo = [[(-1) for i in range(N)] for j in range(N)]
def MCM(start, end):
if start + 1 >= end:
return 0
if memo[start][end] != -1:
return memo[start][end]
ans = float("inf")
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF IF BIN_OP VAR NUMBER VAR RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR V... |
Given a sequence of matrices, find the most efficient way to multiply these matrices together. The efficient way is the one that involves the least number of multiplications.
The dimensions of the matrices are given in an array arr[] of size N (such that N = number of matrices + 1) where the i^{th} matrix has the dime... | class Solution:
def matrixMultiplication(self, N, arr):
dp = [[float("inf") for j in range(N)] for i in range(N)]
for i in range(1, N):
dp[i][i] = 0
for L in range(1, N):
for i in range(1, N - L + 1):
j = i + L - 1
for k in range(i, j)... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIG... |
Given a sequence of matrices, find the most efficient way to multiply these matrices together. The efficient way is the one that involves the least number of multiplications.
The dimensions of the matrices are given in an array arr[] of size N (such that N = number of matrices + 1) where the i^{th} matrix has the dime... | class Solution:
def matrixMultiplication(self, N, arr):
dp = [([0] * N) for _ in range(N)]
for l in range(2, N):
for i in range(1, N - l + 1):
j = i + l - 1
dp[i][j] = float("inf")
for k in range(i, j):
temp = dp[i][k] ... | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN... |
Given a sequence of matrices, find the most efficient way to multiply these matrices together. The efficient way is the one that involves the least number of multiplications.
The dimensions of the matrices are given in an array arr[] of size N (such that N = number of matrices + 1) where the i^{th} matrix has the dime... | class Solution:
def matrixMultiplication(self, N, arr):
dp = [[(0) for i in range(N)] for j in range(N)]
for idx in range(N - 1, 0, -1):
for last in range(idx + 1, N):
maxi = float("inf")
for i in range(idx, last):
temp = (
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VA... |
Given a sequence of matrices, find the most efficient way to multiply these matrices together. The efficient way is the one that involves the least number of multiplications.
The dimensions of the matrices are given in an array arr[] of size N (such that N = number of matrices + 1) where the i^{th} matrix has the dime... | class Solution:
def matrixMultiplication(self, N, arr):
maxi = 10**10
dp = [([-1] * N) for _ in range(N)]
def find(i, j):
if j == i:
return 0
if dp[i][j] != -1:
return dp[i][j]
ans = maxi
for k in range(i, j):
... | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP BIN... |
Given a sequence of matrices, find the most efficient way to multiply these matrices together. The efficient way is the one that involves the least number of multiplications.
The dimensions of the matrices are given in an array arr[] of size N (such that N = number of matrices + 1) where the i^{th} matrix has the dime... | class Solution:
def solve(self, arr, i, j, N, dp):
if i == j:
return 0
if dp[i][j] != -1:
return dp[i][j]
dp[i][j] = float("inf")
for k in range(i, j):
dp[i][j] = min(
dp[i][j],
self.solve(arr, i, k, N, dp)
... | CLASS_DEF FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP... |
Given a sequence of matrices, find the most efficient way to multiply these matrices together. The efficient way is the one that involves the least number of multiplications.
The dimensions of the matrices are given in an array arr[] of size N (such that N = number of matrices + 1) where the i^{th} matrix has the dime... | class Solution:
def matrixMultiplication(self, N, arr):
def solve(arr, i, j, dp):
if i == j:
return 0
if dp[i][j] != -1:
return dp[i][j]
min1 = float("inf")
for k in range(i, j):
temp = (
so... | CLASS_DEF FUNC_DEF FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR VAR IF VAR VAR AS... |
Given a sequence of matrices, find the most efficient way to multiply these matrices together. The efficient way is the one that involves the least number of multiplications.
The dimensions of the matrices are given in an array arr[] of size N (such that N = number of matrices + 1) where the i^{th} matrix has the dime... | class Solution:
def matrixMultiplication(self, N, arr):
d = {}
def fun(i, j):
if j - i <= 1:
return 0
if (i, j) in d:
return d[i, j]
steps = 1e22
for k in range(i + 1, j):
res = arr[i] * arr[j] * arr[k]... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT FUNC_DEF IF BIN_OP VAR VAR NUMBER RETURN NUMBER IF VAR VAR VAR RETURN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR A... |
Given a sequence of matrices, find the most efficient way to multiply these matrices together. The efficient way is the one that involves the least number of multiplications.
The dimensions of the matrices are given in an array arr[] of size N (such that N = number of matrices + 1) where the i^{th} matrix has the dime... | class Solution:
def matrixMultiplication(self, N, arr):
dp = [[(-1) for i in range(501)] for j in range(501)]
def solve(arr, i, j):
if i >= j:
return 0
if dp[i][j] != -1:
return dp[i][j]
ans = 10**9
for k in range(i, j... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN V... |
Given a sequence of matrices, find the most efficient way to multiply these matrices together. The efficient way is the one that involves the least number of multiplications.
The dimensions of the matrices are given in an array arr[] of size N (such that N = number of matrices + 1) where the i^{th} matrix has the dime... | class Solution:
def matrixMultiplication(self, N, arr):
dp = [[(-1) for _ in range(N + 1)] for _ in range(N + 1)]
def helper(i, j):
if i == j:
return 0
if dp[i][j] != -1:
return dp[i][j]
min_val = float("inf")
for k in... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR V... |
Given a sequence of matrices, find the most efficient way to multiply these matrices together. The efficient way is the one that involves the least number of multiplications.
The dimensions of the matrices are given in an array arr[] of size N (such that N = number of matrices + 1) where the i^{th} matrix has the dime... | class Solution:
def matrixMultiplication(self, n, m):
dp = [([-1] * (n + 1)) for i in range(n + 1)]
def dfs(m, i, j):
if dp[i][j] != -1:
return dp[i][j]
if i + 1 == j:
return 0
mx = float("inf")
for k in range(i + 1, j... | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_DEF IF VAR VAR VAR NUMBER RETURN VAR VAR VAR IF BIN_OP VAR NUMBER VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR F... |
Given a sequence of matrices, find the most efficient way to multiply these matrices together. The efficient way is the one that involves the least number of multiplications.
The dimensions of the matrices are given in an array arr[] of size N (such that N = number of matrices + 1) where the i^{th} matrix has the dime... | class Solution:
def matrixMultiplication(self, N, arr):
if N <= 2:
return 0
mTable = [[(0) for _ in range(N)] for i in range(N)]
def dfs(start, end):
if mTable[start][end]:
return mTable[start][end]
if start > end:
mTable[... | CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR VAR RETURN VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP ... |
Given a string S of lowercase english alphabetic characters and a substring range starting from q1 and ending at q2, the task is to find out the count of palindromic substrings in the given substring range.
Example 1:
Input:
N = 7
S = "xyaabax"
q1 = 3
q2 = 5
Output: 4
Explanation: The substring in the given range
is ... | def countPalinInRange(n, s, q1, q2):
if q2 < q1:
q1, q2 = q2, q1
num = q2 - q1 + 1
dp = [[(0) for i in range(num)] for j in range(num)]
s = s[q1 : q2 + 1]
c = 0
for gap in range(num):
for i in range(num - gap):
j = i + gap
if i == j:
dp[i][... | FUNC_DEF IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR VAR N... |
Given a string S of lowercase english alphabetic characters and a substring range starting from q1 and ending at q2, the task is to find out the count of palindromic substrings in the given substring range.
Example 1:
Input:
N = 7
S = "xyaabax"
q1 = 3
q2 = 5
Output: 4
Explanation: The substring in the given range
is ... | def countPalinInRange(n, s, q1, q2):
r1 = min(q1, q2)
r2 = max(q1, q2)
SS = s[r1 : r2 + 1]
cnt = 0
for i in range(len(SS)):
for j in range(i + 1, len(SS) + 1):
ss1 = SS[i:j]
ss2 = ss1[::-1]
if ss1 == ss2:
cnt += 1
return cnt | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR NUMBER IF VAR VAR VAR NUMBER RETURN VAR |
Given a string S of lowercase english alphabetic characters and a substring range starting from q1 and ending at q2, the task is to find out the count of palindromic substrings in the given substring range.
Example 1:
Input:
N = 7
S = "xyaabax"
q1 = 3
q2 = 5
Output: 4
Explanation: The substring in the given range
is ... | def palindrome(st):
if len(st) == 1:
return 1
j = len(st) - 1
i = 0
while i < j:
if st[i] != st[j]:
return 0
i += 1
j -= 1
return 1
def countPalinInRange(n, s, q1, q2):
s = list(s)
if q1 < q2:
s1 = s[q1 : q2 + 1]
else:
s1 = s[... | FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR RETURN NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER AS... |
Given a string S of lowercase english alphabetic characters and a substring range starting from q1 and ending at q2, the task is to find out the count of palindromic substrings in the given substring range.
Example 1:
Input:
N = 7
S = "xyaabax"
q1 = 3
q2 = 5
Output: 4
Explanation: The substring in the given range
is ... | def is_palin(s, i, j):
if i >= j:
return 1
if dp[i][j] != -1:
return dp[i][j]
if s[i] != s[j]:
dp[i][j] = 0
return dp[i][j]
dp[i][j] = is_palin(s, i + 1, j - 1)
return dp[i][j]
def solve(s, n):
c = 0
global dp
dp = [[(-1) for i in range(n)] for j in rang... | FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ... |
Given a string S of lowercase english alphabetic characters and a substring range starting from q1 and ending at q2, the task is to find out the count of palindromic substrings in the given substring range.
Example 1:
Input:
N = 7
S = "xyaabax"
q1 = 3
q2 = 5
Output: 4
Explanation: The substring in the given range
is ... | def countPalinInRange(n, s, q1, q2):
res = 0
if q1 > q2:
temp = q1
q1 = q2
q2 = temp
for i in range(q1, q2 + 1):
l = r = i
while l >= q1 and r <= q2 and s[l] == s[r]:
res += 1
l -= 1
r += 1
l = i
r = i + 1
wh... | FUNC_DEF ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR WHILE VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER... |
Given a string S of lowercase english alphabetic characters and a substring range starting from q1 and ending at q2, the task is to find out the count of palindromic substrings in the given substring range.
Example 1:
Input:
N = 7
S = "xyaabax"
q1 = 3
q2 = 5
Output: 4
Explanation: The substring in the given range
is ... | def countPalinInRange(n, s, q1, q2):
l = 0
h = 0
if q1 < q2:
l = q1
h = q2
else:
l = q2
h = q1
string = s[l : h + 1]
dp = [[(False) for j in range(len(string))] for i in range(len(string))]
count = 0
for i in range(len(string)):
for j in range(i, l... | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL V... |
Given a string S of lowercase english alphabetic characters and a substring range starting from q1 and ending at q2, the task is to find out the count of palindromic substrings in the given substring range.
Example 1:
Input:
N = 7
S = "xyaabax"
q1 = 3
q2 = 5
Output: 4
Explanation: The substring in the given range
is ... | def countPalinInRange(n, s, q1, q2):
Min = min(q1, q2)
Max = max(q1, q2)
S = s[Min : Max + 1]
count = 0
length = Max - Min + 1
for i in range(1, length + 1):
window = i
slides = length - window + 1
for j in range(slides):
res = S[j:window]
if res =... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR... |
Given a string S of lowercase english alphabetic characters and a substring range starting from q1 and ending at q2, the task is to find out the count of palindromic substrings in the given substring range.
Example 1:
Input:
N = 7
S = "xyaabax"
q1 = 3
q2 = 5
Output: 4
Explanation: The substring in the given range
is ... | def countPalinInRange(n, s, q1, q2):
x = min(q1, q2)
y = max(q1, q2)
s = s[x : y + 1]
n = len(s)
n = len(s)
p = [([False] * n) for i in range(n)]
d = {}
r = 0
for i in range(n):
p[i][i] = True
for i in range(n - 1):
if s[i] == s[i + 1]:
p[i][i + 1] = T... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR ... |
Given a string S of lowercase english alphabetic characters and a substring range starting from q1 and ending at q2, the task is to find out the count of palindromic substrings in the given substring range.
Example 1:
Input:
N = 7
S = "xyaabax"
q1 = 3
q2 = 5
Output: 4
Explanation: The substring in the given range
is ... | def countPalinInRange(n, s, q1, q2):
if q1 < q2:
s = s[q1 : q2 + 1]
else:
s = s[q2 : q1 + 1]
count = 0
for i in range(len(s)):
l = r = i
while l >= 0 and r < len(s) and s[l] == s[r]:
count += 1
l -= 1
r += 1
l = i
r = i ... | FUNC_DEF IF VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR WHILE VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER ... |
Given a string S of lowercase english alphabetic characters and a substring range starting from q1 and ending at q2, the task is to find out the count of palindromic substrings in the given substring range.
Example 1:
Input:
N = 7
S = "xyaabax"
q1 = 3
q2 = 5
Output: 4
Explanation: The substring in the given range
is ... | def countPalinInRange(n, s, q1, q2):
if q1 > q2:
return countPalinInRange(n, s, q2, q1)
return countSubstrings(s[q1 : q2 + 1])
def countSubstrings(s):
maxlen = 1
count = 0
for i in range(len(s)):
h = i
l = i
while l >= 0 and h < len(s) and s[l] == s[h]:
... | FUNC_DEF IF VAR VAR RETURN FUNC_CALL VAR VAR VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VA... |
Given a string S of lowercase english alphabetic characters and a substring range starting from q1 and ending at q2, the task is to find out the count of palindromic substrings in the given substring range.
Example 1:
Input:
N = 7
S = "xyaabax"
q1 = 3
q2 = 5
Output: 4
Explanation: The substring in the given range
is ... | def solve(dp, s, i, j):
if i > j:
return True
if dp[i][j] != -1:
return dp[i][j]
if s[i] != s[j]:
dp[i][j] = False
return dp[i][j]
if s[i] == s[j]:
dp[i][j] = solve(dp, s, i + 1, j - 1)
return dp[i][j]
def countPalinInRange(n, s, q1, q2):
if q1 > q2:
... | FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER RETURN VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN VAR VAR VAR FUNC_DEF IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN... |
Given a string S of lowercase english alphabetic characters and a substring range starting from q1 and ending at q2, the task is to find out the count of palindromic substrings in the given substring range.
Example 1:
Input:
N = 7
S = "xyaabax"
q1 = 3
q2 = 5
Output: 4
Explanation: The substring in the given range
is ... | from itertools import combinations
def countPalinInRange(n, s, q1, q2):
l = min(q1, q2)
r = max(q1, q2)
a = s[l : r + 1]
ans = 0
x = [i for i in range(len(a) + 1)]
for i, j in combinations(x, 2):
temp = a[i:j]
if temp == temp[::-1]:
ans += 1
return ans | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR VAR NUMBER VAR NUMBER RETURN VAR |
Given a string S of lowercase english alphabetic characters and a substring range starting from q1 and ending at q2, the task is to find out the count of palindromic substrings in the given substring range.
Example 1:
Input:
N = 7
S = "xyaabax"
q1 = 3
q2 = 5
Output: 4
Explanation: The substring in the given range
is ... | def countPalinInRange(n, s, q1, q2):
S = s[min(q1, q2) : max(q1, q2) + 1]
N = len(S)
count = 0
dp = [[(False) for i in range(N + 1)] for j in range(N + 1)]
for gap in range(N):
i, j = 0, gap
while j < N:
if gap == 0:
dp[i][j] = True
count +... | FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR WHILE VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR NU... |
Given a string S of lowercase english alphabetic characters and a substring range starting from q1 and ending at q2, the task is to find out the count of palindromic substrings in the given substring range.
Example 1:
Input:
N = 7
S = "xyaabax"
q1 = 3
q2 = 5
Output: 4
Explanation: The substring in the given range
is ... | def countPalinInRange(n, s, q1, q2):
res = []
a = max(q1, q2)
b = min(q1, q2)
S = s[b : a + 1]
for i in range(len(S)):
l, r = i, i
while l >= 0 and r < len(S) and S[l] == S[r]:
res.append(S[l : r + 1])
l -= 1
r += 1
l, r = i, i + 1
... | FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR WHILE VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN ... |
Given a string S of lowercase english alphabetic characters and a substring range starting from q1 and ending at q2, the task is to find out the count of palindromic substrings in the given substring range.
Example 1:
Input:
N = 7
S = "xyaabax"
q1 = 3
q2 = 5
Output: 4
Explanation: The substring in the given range
is ... | def countPalinInRange(n, s, q1, q2):
count = 0
if q1 > q2:
temp = q2
q2 = q1
q1 = temp
for i in range(q1, q2 + 1):
d = ""
for j in range(i, q2 + 1):
d = d + s[j]
if d == d[::-1]:
count = count + 1
return count | FUNC_DEF ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR |
Given a string S of lowercase english alphabetic characters and a substring range starting from q1 and ending at q2, the task is to find out the count of palindromic substrings in the given substring range.
Example 1:
Input:
N = 7
S = "xyaabax"
q1 = 3
q2 = 5
Output: 4
Explanation: The substring in the given range
is ... | def countPalinInRange(n, A, q1, q2):
res = 0
if q1 > q2:
q1, q2 = q2, q1
for i in range(q1, q2 + 1):
j = i - 1
k = i + 1
res += 1
while j >= q1 and k <= q2:
if A[j] == A[k]:
res += 1
else:
break
j -= ... | FUNC_DEF ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR AS... |
Given a string S of lowercase english alphabetic characters and a substring range starting from q1 and ending at q2, the task is to find out the count of palindromic substrings in the given substring range.
Example 1:
Input:
N = 7
S = "xyaabax"
q1 = 3
q2 = 5
Output: 4
Explanation: The substring in the given range
is ... | def countPalinInRange(n, s, q1, q2):
if q1 < q2:
s = s[q1 : q2 + 1]
elif q1 > q2:
s = s[q2 : q1 + 1]
else:
return 1
l = abs(q2 - q1) + 1
k = 1
c = 0
while k <= l:
for i in range(l):
if i + k <= l:
if s[i : i + k] == s[i : i + k][::-... | FUNC_DEF IF VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR IF VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR ... |
Given a string S of lowercase english alphabetic characters and a substring range starting from q1 and ending at q2, the task is to find out the count of palindromic substrings in the given substring range.
Example 1:
Input:
N = 7
S = "xyaabax"
q1 = 3
q2 = 5
Output: 4
Explanation: The substring in the given range
is ... | def countPalinInRange(n, s, q1, q2):
s = s[min(q1, q2) : max(q1, q2) + 1]
c = 0
for i in range(len(s)):
for j in range(i + 1, len(s) + 1):
x = s[i:j]
if x == x[::-1]:
c += 1
return c | FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR VAR NUMBER VAR NUMBER RETURN VAR |
Given a string S of lowercase english alphabetic characters and a substring range starting from q1 and ending at q2, the task is to find out the count of palindromic substrings in the given substring range.
Example 1:
Input:
N = 7
S = "xyaabax"
q1 = 3
q2 = 5
Output: 4
Explanation: The substring in the given range
is ... | def countPalinInRange(n, s, q1, q2):
S = s[q1 : q2 + 1]
if q1 > q2:
S = s[q2 : q1 + 1]
count = 0
ans = set([])
n = len(S)
for i in range(n):
left = i - 1
right = i + 1
while left >= 0 and right < n and S[left] == S[right]:
count += 1
stmax ... | FUNC_DEF ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR LIST ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VA... |
Given a string S of lowercase english alphabetic characters and a substring range starting from q1 and ending at q2, the task is to find out the count of palindromic substrings in the given substring range.
Example 1:
Input:
N = 7
S = "xyaabax"
q1 = 3
q2 = 5
Output: 4
Explanation: The substring in the given range
is ... | def countPalinInRange(n, s, q1, q2):
if q1 > q2:
q1, q2 = q2, q1
s1 = s[q1 : q2 + 1]
counter = 0
if len(s1) == 1:
return counter + 1
for i in range(len(s1)):
for j in range(i + 1, len(s1) + 1):
temp = s1[i:j]
if temp == temp[::-1]:
coun... | FUNC_DEF IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR VAR NUMBER VAR NUMBER RETUR... |
Given a string S of lowercase english alphabetic characters and a substring range starting from q1 and ending at q2, the task is to find out the count of palindromic substrings in the given substring range.
Example 1:
Input:
N = 7
S = "xyaabax"
q1 = 3
q2 = 5
Output: 4
Explanation: The substring in the given range
is ... | def countPalinInRange(n, s, q1, q2):
if q1 > q2:
q1, q2 = q2, q1
s1 = s[q1 : q2 + 1]
n1 = len(s1)
count = 0
for i in range(n1):
for j in range(i + 1, n1 + 1):
if s1[i:j] == s1[i:j][::-1]:
count += 1
return count | FUNC_DEF IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR |
Given a string S of lowercase english alphabetic characters and a substring range starting from q1 and ending at q2, the task is to find out the count of palindromic substrings in the given substring range.
Example 1:
Input:
N = 7
S = "xyaabax"
q1 = 3
q2 = 5
Output: 4
Explanation: The substring in the given range
is ... | def countPalinInRange(n, s, q1, q2):
c = 0
if q2 > q1:
a = s[q1 : q2 + 1]
else:
a = s[q2 : q1 + 1]
m = len(a)
for i in range(m):
l, r = i, i
while l >= 0 and r < m and a[l] == a[r]:
c += 1
l -= 1
r += 1
l, r = i, i + 1
... | FUNC_DEF ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR WHILE VAR NUMBER VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VA... |
Given a string S of lowercase english alphabetic characters and a substring range starting from q1 and ending at q2, the task is to find out the count of palindromic substrings in the given substring range.
Example 1:
Input:
N = 7
S = "xyaabax"
q1 = 3
q2 = 5
Output: 4
Explanation: The substring in the given range
is ... | def countPalinInRange(n, s, q1, q2):
s = s[min(q1, q2) : max(q1, q2) + 1]
c = 0
for i in range(len(s)):
for j in range(i + 1, len(s) + 1):
x = s[i:j]
if x == x[::-1]:
c += 1
return c
t = int(input())
for tc in range(t):
n = int(input())
s = input... | FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VA... |
Given a string S of lowercase english alphabetic characters and a substring range starting from q1 and ending at q2, the task is to find out the count of palindromic substrings in the given substring range.
Example 1:
Input:
N = 7
S = "xyaabax"
q1 = 3
q2 = 5
Output: 4
Explanation: The substring in the given range
is ... | def check(x, y, q1, q2):
ans = 0
while x >= q1 and y <= q2 and s[x] == s[y]:
x -= 1
y += 1
ans += 1
return ans
def countPalinInRange(n, s, q1, q2):
ans = 0
if q1 > q2:
q2, q1 = q1, q2
for i in range(q1, q2 + 1):
ans += check(i, i, q1, q2) + check(i, i + ... | FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR RETURN VAR |
Given a string S of lowercase english alphabetic characters and a substring range starting from q1 and ending at q2, the task is to find out the count of palindromic substrings in the given substring range.
Example 1:
Input:
N = 7
S = "xyaabax"
q1 = 3
q2 = 5
Output: 4
Explanation: The substring in the given range
is ... | def countPalinInRange(n, s, q1, q2):
if q1 > q2:
q1, q2 = q2, q1
s = s[q1 : q2 + 1]
n = len(s)
is_palin = [[(0) for i in range(n)] for i in range(n)]
dp = [[(0) for i in range(n)] for i in range(n)]
for g in range(n):
i = 0
j = g
while j < n:
if g == 0... | FUNC_DEF IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR IF VAR NUMBER ... |
You are given a set of strings S. Each string consists of lowercase Latin letters.
For each string in this set, you want to calculate the minimum number of seconds required to type this string. To type a string, you have to start with an empty string and transform it into the string you want to type using the followin... | import sys
input = sys.stdin.readline
n = int(input())
T = [input().split() for i in range(n)]
k = int(input())
S = list(map(int, input().split()))
SETS = set(S)
E = [[] for i in range(n + 1)]
P = [-1] * (n + 1)
for i in range(n):
p, s = T[i]
p = int(p)
E[p].append((s, i + 1))
P[i + 1] = p
for i in ran... | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_... |
Given an array arr[] of N integers. Find the contiguous sub-array(containing at least one number) which has the minimum sum and return its sum.
Example 1:
Input:
arr[] = {3,-4, 2,-3,-1, 7,-5}
Output: -6
Explanation: sub-array which has smallest
sum among all the sub-array is {-4,2,-3,-1} = -6
Example 2:
Input:
arr[] ... | class Solution:
def smallestSumSubarray(self, A, N):
A = [(-1 * x) for x in A]
cs = 0
mx = 0
l = []
p = 0
for x in A:
if x < 0:
p += 1
if x + cs > 0:
cs += x
l.append(cs)
else:
... | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP NUMBER VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR VAR RETURN BIN_OP NUMBER FUNC_CALL VAR VAR IF VAR NUM... |
Given an array arr[] of N integers. Find the contiguous sub-array(containing at least one number) which has the minimum sum and return its sum.
Example 1:
Input:
arr[] = {3,-4, 2,-3,-1, 7,-5}
Output: -6
Explanation: sub-array which has smallest
sum among all the sub-array is {-4,2,-3,-1} = -6
Example 2:
Input:
arr[] ... | class Solution:
def smallestSumSubarray(self, a, n):
ans = 1000000000
sm = 0
j = 0
for i in range(n):
el = a[i]
sm += el
ans = min(ans, sm, el)
if sm > 0:
while sm > 0 and j < i:
sm -= a[j]
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER WHILE VAR NUMBER VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMB... |
Given an array arr[] of N integers. Find the contiguous sub-array(containing at least one number) which has the minimum sum and return its sum.
Example 1:
Input:
arr[] = {3,-4, 2,-3,-1, 7,-5}
Output: -6
Explanation: sub-array which has smallest
sum among all the sub-array is {-4,2,-3,-1} = -6
Example 2:
Input:
arr[] ... | class Solution:
def smallestSumSubarray(self, A, N):
minsum = float("inf")
total = 0
for i in range(N):
total += A[i]
minsum = min(total, minsum)
if total > 0:
total = 0
return minsum | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER RETURN VAR |
Given an array arr[] of N integers. Find the contiguous sub-array(containing at least one number) which has the minimum sum and return its sum.
Example 1:
Input:
arr[] = {3,-4, 2,-3,-1, 7,-5}
Output: -6
Explanation: sub-array which has smallest
sum among all the sub-array is {-4,2,-3,-1} = -6
Example 2:
Input:
arr[] ... | class Solution:
def smallestSumSubarray(self, A, N):
mini = A[0]
s = 0
for i in range(N):
s = s + A[i]
mini = min(s, mini)
if s >= 0:
s = 0
return mini | CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER RETURN VAR |
Given an array arr[] of N integers. Find the contiguous sub-array(containing at least one number) which has the minimum sum and return its sum.
Example 1:
Input:
arr[] = {3,-4, 2,-3,-1, 7,-5}
Output: -6
Explanation: sub-array which has smallest
sum among all the sub-array is {-4,2,-3,-1} = -6
Example 2:
Input:
arr[] ... | class Solution:
def smallestSumSubarray(self, A, N):
s = 0
p = 999999
for i in A:
s += i
if s < p:
p = s
if s > 0:
s = 0
return p | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER RETURN VAR |
Given an array arr[] of N integers. Find the contiguous sub-array(containing at least one number) which has the minimum sum and return its sum.
Example 1:
Input:
arr[] = {3,-4, 2,-3,-1, 7,-5}
Output: -6
Explanation: sub-array which has smallest
sum among all the sub-array is {-4,2,-3,-1} = -6
Example 2:
Input:
arr[] ... | class Solution:
def smallestSumSubarray(self, A, N):
sum = 0
minsum = min(A)
for i in range(0, N):
sum = sum + A[i]
if sum < minsum:
minsum = sum
if sum > 0:
sum = 0
return minsum | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER RETURN VAR |
Given an array arr[] of N integers. Find the contiguous sub-array(containing at least one number) which has the minimum sum and return its sum.
Example 1:
Input:
arr[] = {3,-4, 2,-3,-1, 7,-5}
Output: -6
Explanation: sub-array which has smallest
sum among all the sub-array is {-4,2,-3,-1} = -6
Example 2:
Input:
arr[] ... | class Solution:
def smallestSumSubarray(self, A, N):
prefix_sum = [A[i] for i in range(N)]
for i in range(1, N):
prefix_sum[i] = A[i] + prefix_sum[i - 1]
ans = prefix_sum[0]
maxi = max(prefix_sum[0], 0)
for i in range(1, N):
ans = min(ans, prefix_sum[... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ... |
Given an array arr[] of N integers. Find the contiguous sub-array(containing at least one number) which has the minimum sum and return its sum.
Example 1:
Input:
arr[] = {3,-4, 2,-3,-1, 7,-5}
Output: -6
Explanation: sub-array which has smallest
sum among all the sub-array is {-4,2,-3,-1} = -6
Example 2:
Input:
arr[] ... | class Solution:
def smallestSumSubarray(self, A, N):
a = A[0]
b = A[0]
for i in range(1, N):
b = min(A[i], b + A[i])
a = min(a, b)
return a | CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR |
Given an array arr[] of N integers. Find the contiguous sub-array(containing at least one number) which has the minimum sum and return its sum.
Example 1:
Input:
arr[] = {3,-4, 2,-3,-1, 7,-5}
Output: -6
Explanation: sub-array which has smallest
sum among all the sub-array is {-4,2,-3,-1} = -6
Example 2:
Input:
arr[] ... | class Solution:
def smallestSumSubarray(self, A, N):
mini = 999
su = 0
for i in A:
su += i
mini = min(su, mini)
if su > 0:
su = 0
if len(A) == 1:
return A[0]
return mini | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN VAR NUMBER RETURN VAR |
Given an array arr[] of N integers. Find the contiguous sub-array(containing at least one number) which has the minimum sum and return its sum.
Example 1:
Input:
arr[] = {3,-4, 2,-3,-1, 7,-5}
Output: -6
Explanation: sub-array which has smallest
sum among all the sub-array is {-4,2,-3,-1} = -6
Example 2:
Input:
arr[] ... | class Solution:
def smallestSumSubarray(self, A, N):
sm = mn = 0
least_positive = 10**9
for i in A:
sm += i
if sm >= 0:
sm = 0
else:
mn = min(mn, sm)
if i >= 0 and i < least_positive:
least_posit... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR VAR RETURN VAR NUMBER VAR VAR |
Given an array arr[] of N integers. Find the contiguous sub-array(containing at least one number) which has the minimum sum and return its sum.
Example 1:
Input:
arr[] = {3,-4, 2,-3,-1, 7,-5}
Output: -6
Explanation: sub-array which has smallest
sum among all the sub-array is {-4,2,-3,-1} = -6
Example 2:
Input:
arr[] ... | class Solution:
def smallestSumSubarray(self, a, n):
s = 0
m = -999999
ans = 9999999
for i in range(n):
ans = min(a[i], ans)
s += a[i]
ans = min(s, ans)
if m < s:
m = s
else:
ans = min(s - m,... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR RETURN VAR |
Given an array arr[] of N integers. Find the contiguous sub-array(containing at least one number) which has the minimum sum and return its sum.
Example 1:
Input:
arr[] = {3,-4, 2,-3,-1, 7,-5}
Output: -6
Explanation: sub-array which has smallest
sum among all the sub-array is {-4,2,-3,-1} = -6
Example 2:
Input:
arr[] ... | class Solution:
def smallestSumSubarray(self, A, N):
if N > 0:
S = math.inf
S_aux = S
idx = 0
while idx < N:
if S > 0:
if A[idx] < S:
S = A[idx]
S_aux = S
... | CLASS_DEF FUNC_DEF IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR IF BIN_OP VAR VAR VAR NUMBER... |
Given an array arr[] of N integers. Find the contiguous sub-array(containing at least one number) which has the minimum sum and return its sum.
Example 1:
Input:
arr[] = {3,-4, 2,-3,-1, 7,-5}
Output: -6
Explanation: sub-array which has smallest
sum among all the sub-array is {-4,2,-3,-1} = -6
Example 2:
Input:
arr[] ... | class Solution:
def smallestSumSubarray(self, arr, N):
count = 0
ans = 9999
for i in arr:
count += i
count = min(count, i)
ans = min(ans, count)
return ans | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR |
Given an array arr[] of N integers. Find the contiguous sub-array(containing at least one number) which has the minimum sum and return its sum.
Example 1:
Input:
arr[] = {3,-4, 2,-3,-1, 7,-5}
Output: -6
Explanation: sub-array which has smallest
sum among all the sub-array is {-4,2,-3,-1} = -6
Example 2:
Input:
arr[] ... | class Solution:
def smallestSumSubarray(self, A, N):
prefixSumList = [0] * N
prevSum = 0
index = 0
while index < N:
curElement = A[index]
if curElement + prevSum <= curElement:
prefixSumList[index] = curElement + prevSum
else:
... | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER RETURN FUNC_CALL VAR VAR |
Given an array arr[] of N integers. Find the contiguous sub-array(containing at least one number) which has the minimum sum and return its sum.
Example 1:
Input:
arr[] = {3,-4, 2,-3,-1, 7,-5}
Output: -6
Explanation: sub-array which has smallest
sum among all the sub-array is {-4,2,-3,-1} = -6
Example 2:
Input:
arr[] ... | import sys
class Solution:
def smallestSumSubarray(self, A, N):
mina = sys.maxsize
temp = 0
for i in A:
temp = temp + i
if temp < mina:
mina = temp
if temp > 0:
temp = 0
return mina | IMPORT CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER RETURN VAR |
Given an array arr[] of N integers. Find the contiguous sub-array(containing at least one number) which has the minimum sum and return its sum.
Example 1:
Input:
arr[] = {3,-4, 2,-3,-1, 7,-5}
Output: -6
Explanation: sub-array which has smallest
sum among all the sub-array is {-4,2,-3,-1} = -6
Example 2:
Input:
arr[] ... | class Solution:
def smallestSumSubarray(self, a, n):
minsum = float("inf")
cmin = 0
for i in a:
cmin = min(i, cmin + i)
minsum = min(minsum, cmin)
return minsum | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR |
Given an array arr[] of N integers. Find the contiguous sub-array(containing at least one number) which has the minimum sum and return its sum.
Example 1:
Input:
arr[] = {3,-4, 2,-3,-1, 7,-5}
Output: -6
Explanation: sub-array which has smallest
sum among all the sub-array is {-4,2,-3,-1} = -6
Example 2:
Input:
arr[] ... | class Solution:
def smallestSumSubarray(self, arr, n):
sumval = 0
minval = float("inf")
for num in arr:
sumval += num
minval = min(minval, sumval)
if sumval > 0:
sumval = 0
return minval | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER RETURN VAR |
Given an array arr[] of N integers. Find the contiguous sub-array(containing at least one number) which has the minimum sum and return its sum.
Example 1:
Input:
arr[] = {3,-4, 2,-3,-1, 7,-5}
Output: -6
Explanation: sub-array which has smallest
sum among all the sub-array is {-4,2,-3,-1} = -6
Example 2:
Input:
arr[] ... | class Solution:
def smallestSumSubarray(self, A, N):
dp = [0] * (N + 1)
sol = float("inf")
for i, x in enumerate(A):
dp[i] = t = x + min(dp[i - 1], 0)
if t < sol:
sol = t
return sol | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR RETURN VAR |
Given an array arr[] of N integers. Find the contiguous sub-array(containing at least one number) which has the minimum sum and return its sum.
Example 1:
Input:
arr[] = {3,-4, 2,-3,-1, 7,-5}
Output: -6
Explanation: sub-array which has smallest
sum among all the sub-array is {-4,2,-3,-1} = -6
Example 2:
Input:
arr[] ... | class Solution:
def smallestSumSubarray(self, arr, n):
maxsize = int(1000000000.0 + 7)
min_ending_here = maxsize
min_so_far = maxsize
for i in range(n):
if min_ending_here > 0:
min_ending_here = arr[i]
else:
min_ending_here += ... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR |
Given an array arr[] of N integers. Find the contiguous sub-array(containing at least one number) which has the minimum sum and return its sum.
Example 1:
Input:
arr[] = {3,-4, 2,-3,-1, 7,-5}
Output: -6
Explanation: sub-array which has smallest
sum among all the sub-array is {-4,2,-3,-1} = -6
Example 2:
Input:
arr[] ... | class Solution:
def smallestSumSubarray(self, arr, n):
curr_sum = 0
min_sum = 999
for i in range(len(arr)):
curr_sum += arr[i]
if curr_sum <= min_sum:
min_sum = curr_sum
if curr_sum > 0:
curr_sum = 0
if len(arr) == ... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN VAR NUMBER RETURN VAR |
Given an array arr[] of N integers. Find the contiguous sub-array(containing at least one number) which has the minimum sum and return its sum.
Example 1:
Input:
arr[] = {3,-4, 2,-3,-1, 7,-5}
Output: -6
Explanation: sub-array which has smallest
sum among all the sub-array is {-4,2,-3,-1} = -6
Example 2:
Input:
arr[] ... | class Solution:
def smallestSumSubarray(self, A, N):
if len(A) == 0:
return 0
ans = float("inf")
min_sum = 0
for i in range(len(A)):
min_sum = min(A[i], A[i] + min_sum)
ans = min(ans, min_sum)
return ans | CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR |
Given an array arr[] of N integers. Find the contiguous sub-array(containing at least one number) which has the minimum sum and return its sum.
Example 1:
Input:
arr[] = {3,-4, 2,-3,-1, 7,-5}
Output: -6
Explanation: sub-array which has smallest
sum among all the sub-array is {-4,2,-3,-1} = -6
Example 2:
Input:
arr[] ... | class Solution:
def smallestSumSubarray(self, A, N):
for i in range(N):
A[i] = -1 * A[i]
meh = 0
largest = -999999
for i in A:
meh = meh + i
if i > meh:
meh = i
if meh > largest:
largest = meh
re... | CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR RETURN BIN_OP NUMBER VAR |
Given an array arr[] of N integers. Find the contiguous sub-array(containing at least one number) which has the minimum sum and return its sum.
Example 1:
Input:
arr[] = {3,-4, 2,-3,-1, 7,-5}
Output: -6
Explanation: sub-array which has smallest
sum among all the sub-array is {-4,2,-3,-1} = -6
Example 2:
Input:
arr[] ... | class Solution:
def smallestSumSubarray(self, A, N):
Sum = A[0]
arr_sum = Sum
Arr = [A[0]]
for i in range(1, N):
ele = A[i]
new_s = arr_sum + ele
if new_s < 0 and new_s < ele:
Arr.append(ele)
arr_sum += ele
... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR LIST VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN V... |
Given an array arr[] of N integers. Find the contiguous sub-array(containing at least one number) which has the minimum sum and return its sum.
Example 1:
Input:
arr[] = {3,-4, 2,-3,-1, 7,-5}
Output: -6
Explanation: sub-array which has smallest
sum among all the sub-array is {-4,2,-3,-1} = -6
Example 2:
Input:
arr[] ... | class Solution:
def smallestSumSubarray(self, A, N):
n = len(A)
mini = float("inf")
csum = 0
for i in range(n):
csum += A[i]
if csum < mini:
mini = csum
if csum > 0:
csum = 0
return mini | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER RETURN VAR |
Given an array arr[] of N integers. Find the contiguous sub-array(containing at least one number) which has the minimum sum and return its sum.
Example 1:
Input:
arr[] = {3,-4, 2,-3,-1, 7,-5}
Output: -6
Explanation: sub-array which has smallest
sum among all the sub-array is {-4,2,-3,-1} = -6
Example 2:
Input:
arr[] ... | class Solution:
def smallestSumSubarray(self, arr, n):
ans = float("inf")
curr = 0
for val in arr:
ans = min(ans, val)
if curr + val > 0:
curr = 0
else:
curr += val
ans = min(ans, curr)
return ans | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR |
Given an array arr[] of N integers. Find the contiguous sub-array(containing at least one number) which has the minimum sum and return its sum.
Example 1:
Input:
arr[] = {3,-4, 2,-3,-1, 7,-5}
Output: -6
Explanation: sub-array which has smallest
sum among all the sub-array is {-4,2,-3,-1} = -6
Example 2:
Input:
arr[] ... | class Solution:
def smallestSumSubarray(self, A, N):
ans = min(A)
i, j = 0, 0
sum1 = 0
while j < len(A):
sum1 += A[j]
if sum1 < 0:
while A[i] >= 0:
sum1 -= A[i]
i += 1
ans = min(ans, sum1... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER WHILE VAR VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR |
Given an array arr[] of N integers. Find the contiguous sub-array(containing at least one number) which has the minimum sum and return its sum.
Example 1:
Input:
arr[] = {3,-4, 2,-3,-1, 7,-5}
Output: -6
Explanation: sub-array which has smallest
sum among all the sub-array is {-4,2,-3,-1} = -6
Example 2:
Input:
arr[] ... | class Solution:
def smallestSumSubarray(self, a, n):
m1, m2 = 10**9, 10**9
for i in range(n):
m1 = min(m1 + a[i], a[i])
m2 = min(m1, m2)
return m2 | CLASS_DEF FUNC_DEF ASSIGN VAR VAR BIN_OP NUMBER NUMBER BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR |
Given an array arr[] of N integers. Find the contiguous sub-array(containing at least one number) which has the minimum sum and return its sum.
Example 1:
Input:
arr[] = {3,-4, 2,-3,-1, 7,-5}
Output: -6
Explanation: sub-array which has smallest
sum among all the sub-array is {-4,2,-3,-1} = -6
Example 2:
Input:
arr[] ... | class Solution:
def smallestSumSubarray(self, A, N):
sumi = 0
mini = A[0]
for i in range(N):
if sumi > 0:
sumi = A[i]
else:
sumi += A[i]
mini = min(mini, sumi)
return mini | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR |
Given an array arr[] of N integers. Find the contiguous sub-array(containing at least one number) which has the minimum sum and return its sum.
Example 1:
Input:
arr[] = {3,-4, 2,-3,-1, 7,-5}
Output: -6
Explanation: sub-array which has smallest
sum among all the sub-array is {-4,2,-3,-1} = -6
Example 2:
Input:
arr[] ... | class Solution:
def smallestSumSubarray(self, A, N):
mini = float("inf")
cur = A[0]
for i in A[1:]:
if i > 0:
mini = min(mini, cur)
if i < mini:
mini = i
cur = i
else:
cur... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER FOR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER VAR VAR RETURN FUNC_CALL VAR VAR VAR |
Given an array arr[] of N integers. Find the contiguous sub-array(containing at least one number) which has the minimum sum and return its sum.
Example 1:
Input:
arr[] = {3,-4, 2,-3,-1, 7,-5}
Output: -6
Explanation: sub-array which has smallest
sum among all the sub-array is {-4,2,-3,-1} = -6
Example 2:
Input:
arr[] ... | class Solution:
def smallestSumSubarray(self, A, N):
arr = A
n = N
dp = [None] * (n + 1)
sol = float("inf")
dp[n] = float("inf")
for i, x in enumerate(arr):
dp[i] = min(x, x + dp[i - 1])
sol = min(sol, dp[i])
return sol | CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NONE BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR STRING FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR |
Given an array arr[] of N integers. Find the contiguous sub-array(containing at least one number) which has the minimum sum and return its sum.
Example 1:
Input:
arr[] = {3,-4, 2,-3,-1, 7,-5}
Output: -6
Explanation: sub-array which has smallest
sum among all the sub-array is {-4,2,-3,-1} = -6
Example 2:
Input:
arr[] ... | class Solution:
def smallestSumSubarray(self, arr, N):
cur = arr[0]
msum = arr[0]
for i in range(1, N):
if msum > 0:
cur = arr[i]
else:
cur = min(cur + arr[i], arr[i])
msum = min(msum, cur)
return msum | CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR |
Given an array arr[] of N integers. Find the contiguous sub-array(containing at least one number) which has the minimum sum and return its sum.
Example 1:
Input:
arr[] = {3,-4, 2,-3,-1, 7,-5}
Output: -6
Explanation: sub-array which has smallest
sum among all the sub-array is {-4,2,-3,-1} = -6
Example 2:
Input:
arr[] ... | class Solution:
def smallestSumSubarray(self, A, N):
start = 0
end = 0
min_summ = 999999
summ = 0
while end < N and start <= end:
summ += A[end]
min_summ = min(min_summ, summ)
if summ > 0:
start = end + 1
su... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER RETURN VAR |
Given an array arr[] of N integers. Find the contiguous sub-array(containing at least one number) which has the minimum sum and return its sum.
Example 1:
Input:
arr[] = {3,-4, 2,-3,-1, 7,-5}
Output: -6
Explanation: sub-array which has smallest
sum among all the sub-array is {-4,2,-3,-1} = -6
Example 2:
Input:
arr[] ... | class Solution:
def smallestSumSubarray(self, A, N):
if max(A) < 0:
return sum(A)
if min(A) >= 0:
if min(A) == 0:
return 0
else:
return min(A)
mini = float("inf")
curr = 0
for i in A:
curr += i
... | CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER RETURN FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER RETURN VAR |
Given an array arr[] of N integers. Find the contiguous sub-array(containing at least one number) which has the minimum sum and return its sum.
Example 1:
Input:
arr[] = {3,-4, 2,-3,-1, 7,-5}
Output: -6
Explanation: sub-array which has smallest
sum among all the sub-array is {-4,2,-3,-1} = -6
Example 2:
Input:
arr[] ... | class Solution:
def smallestSumSubarray(self, arr, n):
min_sum = arr[0]
sum1 = arr[0]
for i in range(1, n):
sum1 += arr[i]
min_sum = min(min_sum, arr[i], sum1)
if arr[i] < sum1:
sum1 = arr[i]
return min_sum | CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR RETURN VAR |
Given an array arr[] of N integers. Find the contiguous sub-array(containing at least one number) which has the minimum sum and return its sum.
Example 1:
Input:
arr[] = {3,-4, 2,-3,-1, 7,-5}
Output: -6
Explanation: sub-array which has smallest
sum among all the sub-array is {-4,2,-3,-1} = -6
Example 2:
Input:
arr[] ... | class Solution:
def smallestSumSubarray(self, arr, n):
prev_max, prev_min, glob_min = arr[0], arr[0], arr[0]
for i in range(1, n):
curr_max = max(prev_max + arr[i], prev_min + arr[i], arr[i])
curr_min = min(prev_max + arr[i], prev_min + arr[i], arr[i])
glob_min =... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR |
You are given an array $a_1, a_2, \dots , a_n$ consisting of integers from $0$ to $9$. A subarray $a_l, a_{l+1}, a_{l+2}, \dots , a_{r-1}, a_r$ is good if the sum of elements of this subarray is equal to the length of this subarray ($\sum\limits_{i=l}^{r} a_i = r - l + 1$).
For example, if $a = [1, 2, 0]$, then there ... | for _ in range(int(input())):
n = int(input())
a = input()
d = {(0): 1}
ss = 0
for i in range(n):
ss += int(a[i])
k = ss - (i + 1)
if k not in d:
d[k] = 1
else:
d[k] += 1
ss = 0
for i in d:
ss += d[i] * (d[i] - 1) // 2
print... | 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 DICT NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER ... |
You are given an array $a_1, a_2, \dots , a_n$ consisting of integers from $0$ to $9$. A subarray $a_l, a_{l+1}, a_{l+2}, \dots , a_{r-1}, a_r$ is good if the sum of elements of this subarray is equal to the length of this subarray ($\sum\limits_{i=l}^{r} a_i = r - l + 1$).
For example, if $a = [1, 2, 0]$, then there ... | for time in range(int(input())):
array = []
n = int(input())
num = input()
for i in range(len(num)):
array.append(int(num[i]))
d = {}
ans = 0
diff = 0
for i in range(n):
if diff in d:
d[diff] += 1
else:
d[diff] = 1
diff += array[i] ... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER ASSIG... |
You are given an array $a_1, a_2, \dots , a_n$ consisting of integers from $0$ to $9$. A subarray $a_l, a_{l+1}, a_{l+2}, \dots , a_{r-1}, a_r$ is good if the sum of elements of this subarray is equal to the length of this subarray ($\sum\limits_{i=l}^{r} a_i = r - l + 1$).
For example, if $a = [1, 2, 0]$, then there ... | q = int(input())
for _ in range(q):
n = int(input())
s = list(input())
s = list(map(int, s))
l = [(s[i] - 1) for i in range(n)]
pref = [0] * (n + 1)
for i in range(1, n + 1):
pref[i] = pref[i - 1] + l[i - 1]
d = {}
for elt in pref:
try:
d[elt] += 1
exc... | 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 FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBE... |
You are given an array $a_1, a_2, \dots , a_n$ consisting of integers from $0$ to $9$. A subarray $a_l, a_{l+1}, a_{l+2}, \dots , a_{r-1}, a_r$ is good if the sum of elements of this subarray is equal to the length of this subarray ($\sum\limits_{i=l}^{r} a_i = r - l + 1$).
For example, if $a = [1, 2, 0]$, then there ... | for _ in range(int(input())):
n = int(input())
arr = list(map(int, input()))
d = {(0): 1}
sm = 0
ans = 0
for i in range(n):
x = arr[i] - 1
sm += x
ans += d.get(sm, 0)
d[sm] = d.get(sm, 0) + 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 VAR VAR FUNC_CALL VAR ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR V... |
You are given an array $a_1, a_2, \dots , a_n$ consisting of integers from $0$ to $9$. A subarray $a_l, a_{l+1}, a_{l+2}, \dots , a_{r-1}, a_r$ is good if the sum of elements of this subarray is equal to the length of this subarray ($\sum\limits_{i=l}^{r} a_i = r - l + 1$).
For example, if $a = [1, 2, 0]$, then there ... | ncases = int(input())
for tcase in range(ncases):
n = int(input())
nums = list(map(int, [i for i in input()]))
sums = {}
sums[0] = 1
current = 0
for i in nums:
current += i - 1
try:
sums[current] += 1
except KeyError:
sums[current] = 1
total = ... | 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 VAR VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER... |
You are given an array $a_1, a_2, \dots , a_n$ consisting of integers from $0$ to $9$. A subarray $a_l, a_{l+1}, a_{l+2}, \dots , a_{r-1}, a_r$ is good if the sum of elements of this subarray is equal to the length of this subarray ($\sum\limits_{i=l}^{r} a_i = r - l + 1$).
For example, if $a = [1, 2, 0]$, then there ... | def main():
t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, list(input())))
ar_sum = [0] * (n + 1)
for i in range(n):
ar_sum[i + 1] = a[i] + ar_sum[i]
m = {}
ans = 0
for i in range(1, n + 1):
m[ar_sum[i - 1] -... | FUNC_DEF 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 BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR ASSIGN VAR... |
You are given an array $a_1, a_2, \dots , a_n$ consisting of integers from $0$ to $9$. A subarray $a_l, a_{l+1}, a_{l+2}, \dots , a_{r-1}, a_r$ is good if the sum of elements of this subarray is equal to the length of this subarray ($\sum\limits_{i=l}^{r} a_i = r - l + 1$).
For example, if $a = [1, 2, 0]$, then there ... | (T,) = list(map(int, input().split()))
for t in range(T):
(N,) = list(map(int, input().split()))
X = [0] * (N + 1)
for i, c in enumerate(input().strip()):
X[i + 1] = X[i] + int(c)
d = dict()
for i in range(N + 1):
x = X[i] - i
if x not in d:
d[x] = 0
d[x] ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR FUNC_CALL VAR VAR ... |
You are given an array $a_1, a_2, \dots , a_n$ consisting of integers from $0$ to $9$. A subarray $a_l, a_{l+1}, a_{l+2}, \dots , a_{r-1}, a_r$ is good if the sum of elements of this subarray is equal to the length of this subarray ($\sum\limits_{i=l}^{r} a_i = r - l + 1$).
For example, if $a = [1, 2, 0]$, then there ... | for _ in range(int(input())):
n = int(input())
s = input()
arr = [(int(i) - 1) for i in s]
dic = {}
summ = 0
ans = 0
for i in range(n):
summ += arr[i]
if summ == 0:
ans += 1
if summ in dic:
ans += dic[summ]
try:
dic[summ] +=... | 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 BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR NUMBER AS... |
You are given an array $a_1, a_2, \dots , a_n$ consisting of integers from $0$ to $9$. A subarray $a_l, a_{l+1}, a_{l+2}, \dots , a_{r-1}, a_r$ is good if the sum of elements of this subarray is equal to the length of this subarray ($\sum\limits_{i=l}^{r} a_i = r - l + 1$).
For example, if $a = [1, 2, 0]$, then there ... | import sys
def main():
T = int(sys.stdin.readline())
while T:
T -= 1
N = int(sys.stdin.readline())
Arr = [int(i) for i in sys.stdin.readline().rstrip()]
agg = [0] * N
agg[0] = Arr[0]
for i in range(1, N):
agg[i] = agg[i - 1] + Arr[i]
nxt_zero... | IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ... |
You are given an array $a_1, a_2, \dots , a_n$ consisting of integers from $0$ to $9$. A subarray $a_l, a_{l+1}, a_{l+2}, \dots , a_{r-1}, a_r$ is good if the sum of elements of this subarray is equal to the length of this subarray ($\sum\limits_{i=l}^{r} a_i = r - l + 1$).
For example, if $a = [1, 2, 0]$, then there ... | for s in [*open(0)][2::2]:
d = {(0): 1}
r = t = 0
for x in s[:-1]:
t += int(x) - 1
x = d.get(t, 0)
r += x
d[t] = x + 1
print(r) | FOR VAR LIST FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR |
You are given an array $a_1, a_2, \dots , a_n$ consisting of integers from $0$ to $9$. A subarray $a_l, a_{l+1}, a_{l+2}, \dots , a_{r-1}, a_r$ is good if the sum of elements of this subarray is equal to the length of this subarray ($\sum\limits_{i=l}^{r} a_i = r - l + 1$).
For example, if $a = [1, 2, 0]$, then there ... | def main():
t = int(input())
for i in range(t):
n = int(input())
s = input()
sums = dict()
sums[0] = 1
ans = 0
now = 0
for i in range(n):
a = int(s[i]) - 1
now += a
if now in sums:
ans += sums[now]
... | FUNC_DEF 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 FUNC_CALL VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR VAR IF VAR VAR VAR ... |
You are given an array $a_1, a_2, \dots , a_n$ consisting of integers from $0$ to $9$. A subarray $a_l, a_{l+1}, a_{l+2}, \dots , a_{r-1}, a_r$ is good if the sum of elements of this subarray is equal to the length of this subarray ($\sum\limits_{i=l}^{r} a_i = r - l + 1$).
For example, if $a = [1, 2, 0]$, then there ... | t = int(input())
for tt in range(t):
n = int(input())
s = input().strip()
d = {}
d[0] = 1
pre = [0] * n
ans = 0
for i in range(n):
pre[i] = int(s[i])
if i > 0:
pre[i] += pre[i - 1]
xx = pre[i] - (i + 1)
if xx in d:
ans += d[xx]
... | 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 FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR VAR VAR... |
You are given an array $a_1, a_2, \dots , a_n$ consisting of integers from $0$ to $9$. A subarray $a_l, a_{l+1}, a_{l+2}, \dots , a_{r-1}, a_r$ is good if the sum of elements of this subarray is equal to the length of this subarray ($\sum\limits_{i=l}^{r} a_i = r - l + 1$).
For example, if $a = [1, 2, 0]$, then there ... | def good(arr):
d = {(0): 1}
s = 0
ans = 0
for i in range(0, len(arr)):
s += arr[i]
x = s - i - 1
d[x] = d.get(x, 0) + 1
ans += d[x] - 1
return ans
for i in range(int(input())):
a = input()
lst = [int(i) for i in input()]
print(good(lst)) | FUNC_DEF ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR BIN_OP VAR VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIG... |
You are given an array $a_1, a_2, \dots , a_n$ consisting of integers from $0$ to $9$. A subarray $a_l, a_{l+1}, a_{l+2}, \dots , a_{r-1}, a_r$ is good if the sum of elements of this subarray is equal to the length of this subarray ($\sum\limits_{i=l}^{r} a_i = r - l + 1$).
For example, if $a = [1, 2, 0]$, then there ... | def solve(string):
val = string
prefix = [0]
for i in range(n):
prefix.append(prefix[-1] + int(val[i]))
one_sub = [i for i in range(n + 1)]
after = [(prefix[i] - one_sub[i]) for i in range(n + 1)]
hash_map = {}
res = 0
for i in after[::-1]:
hash_map[i] = hash_map.get(i, 0... | FUNC_DEF ASSIGN VAR VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR NUMBER ASSIGN VAR VAR... |
You are given an array $a_1, a_2, \dots , a_n$ consisting of integers from $0$ to $9$. A subarray $a_l, a_{l+1}, a_{l+2}, \dots , a_{r-1}, a_r$ is good if the sum of elements of this subarray is equal to the length of this subarray ($\sum\limits_{i=l}^{r} a_i = r - l + 1$).
For example, if $a = [1, 2, 0]$, then there ... | import sys
input = sys.stdin.readline
T = int(input())
for testcase in range(T):
n = int(input())
s = list(input())
a = []
for i in range(n):
a.append(int(s[i]) - 1)
d = dict()
res = 0
val = 0
d[0] = 1
for e in a:
val += e
if val in d:
res += d[va... | IMPORT ASSIGN VAR VAR 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 LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMB... |
You are given an array $a_1, a_2, \dots , a_n$ consisting of integers from $0$ to $9$. A subarray $a_l, a_{l+1}, a_{l+2}, \dots , a_{r-1}, a_r$ is good if the sum of elements of this subarray is equal to the length of this subarray ($\sum\limits_{i=l}^{r} a_i = r - l + 1$).
For example, if $a = [1, 2, 0]$, then there ... | for t in range(int(input())):
n = int(input())
a = list(map(int, input()))
pref = [(0) for i in range(n + 1)]
pref[0] = 0
for i in range(1, n + 1):
pref[i] = pref[i - 1] + a[i - 1] - 1
pref = sorted(pref) + [9 * 10**5 + 1]
cnt = 1
total = 0
for i in range(1, n + 2):
i... | 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 VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMB... |
You are given an array $a_1, a_2, \dots , a_n$ consisting of integers from $0$ to $9$. A subarray $a_l, a_{l+1}, a_{l+2}, \dots , a_{r-1}, a_r$ is good if the sum of elements of this subarray is equal to the length of this subarray ($\sum\limits_{i=l}^{r} a_i = r - l + 1$).
For example, if $a = [1, 2, 0]$, then there ... | for _ in range(int(input())):
n = int(input())
a = input().strip()
currsum = 0
d = {(0): 1}
ans = 0
for i in a:
currsum += int(i) - 1
if currsum in d:
ans += d[currsum]
d[currsum] += 1
else:
d[currsum] = 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 FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
You are given an array $a_1, a_2, \dots , a_n$ consisting of integers from $0$ to $9$. A subarray $a_l, a_{l+1}, a_{l+2}, \dots , a_{r-1}, a_r$ is good if the sum of elements of this subarray is equal to the length of this subarray ($\sum\limits_{i=l}^{r} a_i = r - l + 1$).
For example, if $a = [1, 2, 0]$, then there ... | def comb(n, r):
return n * (n - 1) // 2
a = int(input())
for i in range(0, a):
b = int(input())
s = input()
arr = []
for i in s:
arr.append(int(i))
summ = [0]
for i in range(0, len(arr)):
summ.append(summ[len(summ) - 1] + arr[i])
fsumm = []
for i in range(0, len(sum... | FUNC_DEF RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER 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 LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CAL... |
You are given an array $a_1, a_2, \dots , a_n$ consisting of integers from $0$ to $9$. A subarray $a_l, a_{l+1}, a_{l+2}, \dots , a_{r-1}, a_r$ is good if the sum of elements of this subarray is equal to the length of this subarray ($\sum\limits_{i=l}^{r} a_i = r - l + 1$).
For example, if $a = [1, 2, 0]$, then there ... | t = int(input())
for q in range(t):
n = int(input())
arr = [int(i) for i in input()]
dict = {(1): 1}
count = 0
sum = 0
i = 0
for item in arr:
sum += item
temp = sum - i
if temp in dict:
count += dict[temp]
dict[temp] += 1
else:
... | 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 VAR FUNC_CALL VAR ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR VAR VAR VAR VAR NUMBER A... |
You are given an array $a_1, a_2, \dots , a_n$ consisting of integers from $0$ to $9$. A subarray $a_l, a_{l+1}, a_{l+2}, \dots , a_{r-1}, a_r$ is good if the sum of elements of this subarray is equal to the length of this subarray ($\sum\limits_{i=l}^{r} a_i = r - l + 1$).
For example, if $a = [1, 2, 0]$, then there ... | for _ in range(int(input())):
n = int(input())
s = input()
ll = {}
sol = 0
b = 1
for i in s:
i = int(i)
if b in ll:
ll[b] += 1
else:
ll[b] = 1
b = b + i - 1
if b in ll:
sol += ll[b]
print(sol) | 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 DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR VAR EX... |
You are given an array $a_1, a_2, \dots , a_n$ consisting of integers from $0$ to $9$. A subarray $a_l, a_{l+1}, a_{l+2}, \dots , a_{r-1}, a_r$ is good if the sum of elements of this subarray is equal to the length of this subarray ($\sum\limits_{i=l}^{r} a_i = r - l + 1$).
For example, if $a = [1, 2, 0]$, then there ... | for t in range(int(input())):
n = int(input())
a = list(input())
a = list(map(int, a))
for i in range(1, n):
a[i] = a[i] + a[i - 1]
a.insert(0, 0)
for i in range(n + 1):
a[i] = a[i] - i
d = {}
for el in a:
d[el] = d.get(el, 0) + 1
ans = 0
for el in d:
... | 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 FUNC_CALL VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_O... |
You are given an array $a_1, a_2, \dots , a_n$ consisting of integers from $0$ to $9$. A subarray $a_l, a_{l+1}, a_{l+2}, \dots , a_{r-1}, a_r$ is good if the sum of elements of this subarray is equal to the length of this subarray ($\sum\limits_{i=l}^{r} a_i = r - l + 1$).
For example, if $a = [1, 2, 0]$, then there ... | t = int(input())
for _ in range(t):
n = int(input())
a = input()
f = {(0): 1}
current = 0
res = 0
for i in a:
current += int(i) - 1
if current in f:
res += f[current]
else:
f[current] = 0
f[current] += 1
print(res) | 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 DICT NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VA... |
You are given an array $a_1, a_2, \dots , a_n$ consisting of integers from $0$ to $9$. A subarray $a_l, a_{l+1}, a_{l+2}, \dots , a_{r-1}, a_r$ is good if the sum of elements of this subarray is equal to the length of this subarray ($\sum\limits_{i=l}^{r} a_i = r - l + 1$).
For example, if $a = [1, 2, 0]$, then there ... | for _ in range(int(input())):
length = int(input())
array = list(map(int, list(input())))
pi = [0, array[0]]
for i in range(2, length + 1):
pi += [pi[i - 1] + array[i - 1]]
pi_i = [(pi[i] - i) for i in range(length + 1)]
equal_pi_i = {}
for i in range(length + 1):
if pi_i[i] ... | 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 VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR LIST BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP V... |
You are given an array $a_1, a_2, \dots , a_n$ consisting of integers from $0$ to $9$. A subarray $a_l, a_{l+1}, a_{l+2}, \dots , a_{r-1}, a_r$ is good if the sum of elements of this subarray is equal to the length of this subarray ($\sum\limits_{i=l}^{r} a_i = r - l + 1$).
For example, if $a = [1, 2, 0]$, then there ... | def process(n, c):
di = {(0): 1}
ans = 0
temp = 0
for ele in c:
temp += ele
if temp not in di:
di[temp] = 1
else:
di[temp] += 1
ans += di[temp] - 1
print(ans)
for t in range(int(input())):
n = int(input())
c = [(int(k) - 1) for k in i... | FUNC_DEF ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUM... |
You are given an array $a_1, a_2, \dots , a_n$ consisting of integers from $0$ to $9$. A subarray $a_l, a_{l+1}, a_{l+2}, \dots , a_{r-1}, a_r$ is good if the sum of elements of this subarray is equal to the length of this subarray ($\sum\limits_{i=l}^{r} a_i = r - l + 1$).
For example, if $a = [1, 2, 0]$, then there ... | def prefix(arr):
lst = [0] * len(arr)
lst[0] = arr[0]
for i in range(1, len(arr)):
lst[i] = lst[i - 1] + arr[i]
return lst
def good(arr):
pre = prefix(arr)
dic = {}
ans = 0
for i in range(len(pre)):
if pre[i] == i + 1:
ans += 1
if pre[i] - i not in d... | FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR B... |
You are given an array $a_1, a_2, \dots , a_n$ consisting of integers from $0$ to $9$. A subarray $a_l, a_{l+1}, a_{l+2}, \dots , a_{r-1}, a_r$ is good if the sum of elements of this subarray is equal to the length of this subarray ($\sum\limits_{i=l}^{r} a_i = r - l + 1$).
For example, if $a = [1, 2, 0]$, then there ... | import sys
input = sys.stdin.readline
for _ in range(int(input())):
n = int(input())
a = list(map(int, list(input()[:n])))
ans = 0
d = [0] * (n * 10)
x = 0
for i in range(n):
d[x] += 1
x += a[i] - 1
ans += d[x]
print(ans) | IMPORT ASSIGN VAR VAR 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 VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR BIN_O... |
You are given an array $a_1, a_2, \dots , a_n$ consisting of integers from $0$ to $9$. A subarray $a_l, a_{l+1}, a_{l+2}, \dots , a_{r-1}, a_r$ is good if the sum of elements of this subarray is equal to the length of this subarray ($\sum\limits_{i=l}^{r} a_i = r - l + 1$).
For example, if $a = [1, 2, 0]$, then there ... | t = int(input())
for _ in range(t):
n = int(input())
arr = [(int(i) - 1) for i in input()]
freq = {(0): 1}
pre = 0
for i in range(n):
pre += arr[i]
freq[pre] = freq.get(pre, 0) + 1
ans = 0
for i in freq:
m = freq[i]
ans += m * (m - 1) // 2
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMB... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.