description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
Given an array arr[] of n integers. Count the total number of sub-array having total distinct elements same as that of total distinct elements of the original array.
Example 1:
Input:
N=5
arr[] = {2, 1, 3, 2, 3}
Output: 5
Explanation:
Total distinct elements in array is 3
Total sub-arrays that satisfy the condition
... | class Solution:
def countDistinctSubarray(self, a, n):
w = len(set(a))
count = 0
i = 0
d = {}
s = 0
for i in range(n):
d[a[i]] = d.get(a[i], 0) + 1
while len(d) >= w:
count += n - i
d[a[s]] -= 1
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER WHILE FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CA... |
Given an array arr[] of n integers. Count the total number of sub-array having total distinct elements same as that of total distinct elements of the original array.
Example 1:
Input:
N=5
arr[] = {2, 1, 3, 2, 3}
Output: 5
Explanation:
Total distinct elements in array is 3
Total sub-arrays that satisfy the condition
... | class Solution:
def countDistinctSubarray(self, arr, n):
s = set(arr)
cnt_distinct = len(s)
ans = self.atmost(arr, cnt_distinct) - self.atmost(arr, cnt_distinct - 1)
return ans
def atmost(self, arr, B):
i = 0
j = 0
d = {}
cnt = 0
while j ... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR ... |
Given an array arr[] of n integers. Count the total number of sub-array having total distinct elements same as that of total distinct elements of the original array.
Example 1:
Input:
N=5
arr[] = {2, 1, 3, 2, 3}
Output: 5
Explanation:
Total distinct elements in array is 3
Total sub-arrays that satisfy the condition
... | class Solution:
def countDistinctSubarray(self, arr, n):
ans = 0
target_length = len(set(arr))
d = {}
length = 0
left = 0
for i in range(n):
if arr[i] not in d or d[arr[i]] == 0:
length += 1
d[arr[i]] = 1
else:
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER WHILE VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBE... |
Given an array arr[] of n integers. Count the total number of sub-array having total distinct elements same as that of total distinct elements of the original array.
Example 1:
Input:
N=5
arr[] = {2, 1, 3, 2, 3}
Output: 5
Explanation:
Total distinct elements in array is 3
Total sub-arrays that satisfy the condition
... | class Solution:
def countDistinctSubarray(self, arr, n):
sp_set = set()
for i in arr:
sp_set.add(i)
k = len(sp_set)
dp = {}
right, window, ans = 0, 0, 0
for left in range(n):
while right < n and window < k:
dp[arr[right]] = dp.... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER IF VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF... |
Given an array arr[] of n integers. Count the total number of sub-array having total distinct elements same as that of total distinct elements of the original array.
Example 1:
Input:
N=5
arr[] = {2, 1, 3, 2, 3}
Output: 5
Explanation:
Total distinct elements in array is 3
Total sub-arrays that satisfy the condition
... | class Solution:
def countDistinctSubarray(self, arr, n):
l = len(set(arr))
dp = {}
for xi in arr:
dp[xi] = 0
solve = 0
c = 0
i = 0
j = 0
while j < n:
dp[arr[j]] += 1
if dp[arr[j]] == 1:
c += 1
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER WHILE VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUM... |
Given an array arr[] of n integers. Count the total number of sub-array having total distinct elements same as that of total distinct elements of the original array.
Example 1:
Input:
N=5
arr[] = {2, 1, 3, 2, 3}
Output: 5
Explanation:
Total distinct elements in array is 3
Total sub-arrays that satisfy the condition
... | class Solution:
def countDistinctSubarray(self, nums, n):
k = len(set(nums))
return self.subarraysWithatmostkDistinct(
nums, k
) - self.subarraysWithatmostkDistinct(nums, k - 1)
def subarraysWithatmostkDistinct(self, nums, k):
memo = {}
Count = release = 0
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR DICT ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER WHILE VAR VAR FUNC_CALL VAR VAR VAR VAR... |
Given an array arr[] of n integers. Count the total number of sub-array having total distinct elements same as that of total distinct elements of the original array.
Example 1:
Input:
N=5
arr[] = {2, 1, 3, 2, 3}
Output: 5
Explanation:
Total distinct elements in array is 3
Total sub-arrays that satisfy the condition
... | class Solution:
def countDistinctSubarray(self, arr, n):
tot = 0
mp = {}
for i in arr:
if i not in mp:
mp[i] = 0
tot += 1
mp = {}
l = 0
r = 0
tem = 0
while True:
if tem == tot:
br... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR BI... |
Given an array arr[] of n integers. Count the total number of sub-array having total distinct elements same as that of total distinct elements of the original array.
Example 1:
Input:
N=5
arr[] = {2, 1, 3, 2, 3}
Output: 5
Explanation:
Total distinct elements in array is 3
Total sub-arrays that satisfy the condition
... | class Solution:
def countDistinctSubarray(self, arr, n):
d = {}
k = 0
for i in arr:
if i not in d:
d[i] = 1
k += 1
else:
d[i] += 1
l = 0
r = 0
x = 0
dl = {}
s = 0
for i in... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR ... |
Given an array arr[] of n integers. Count the total number of sub-array having total distinct elements same as that of total distinct elements of the original array.
Example 1:
Input:
N=5
arr[] = {2, 1, 3, 2, 3}
Output: 5
Explanation:
Total distinct elements in array is 3
Total sub-arrays that satisfy the condition
... | class Solution:
def countDistinctSubarray(self, arr, n):
s = set(arr)
d = {e: (0) for e in s}
z, k = 0, 0
ns = set()
c = 0
while k < len(arr):
ns.add(arr[k])
d[arr[k]] += 1
k += 1
while len(ns) == len(s):
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER WHILE FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUM... |
Given an array arr[] of n integers. Count the total number of sub-array having total distinct elements same as that of total distinct elements of the original array.
Example 1:
Input:
N=5
arr[] = {2, 1, 3, 2, 3}
Output: 5
Explanation:
Total distinct elements in array is 3
Total sub-arrays that satisfy the condition
... | class Solution:
def countDistinctSubarray(self, arr, n):
d = {}
for i in arr:
d[i] = d.get(i, 0) + 1
r = 0
k = len(d)
d = {}
ans = 0
countdist = 0
for l in range(0, n):
while r < n and countdist < k:
d[arr[r]] =... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR WHILE VAR VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER IF ... |
Given an array arr[] of n integers. Count the total number of sub-array having total distinct elements same as that of total distinct elements of the original array.
Example 1:
Input:
N=5
arr[] = {2, 1, 3, 2, 3}
Output: 5
Explanation:
Total distinct elements in array is 3
Total sub-arrays that satisfy the condition
... | class Solution:
def countDistinctSubarray(self, arr, n):
d = {}
for i in range(len(arr)):
if arr[i] in d:
d[arr[i]] = d[arr[i]] + 1
else:
d[arr[i]] = 1
i = 0
j = 0
re = 0
d1 = {}
while j < len(arr):
... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR NUMBER A... |
Given an array arr[] of n integers. Count the total number of sub-array having total distinct elements same as that of total distinct elements of the original array.
Example 1:
Input:
N=5
arr[] = {2, 1, 3, 2, 3}
Output: 5
Explanation:
Total distinct elements in array is 3
Total sub-arrays that satisfy the condition
... | class Solution:
def countDistinctSubarray(self, arr, n):
counter = dict.fromkeys(arr, 0)
zeroset = set(arr)
count = 0
i, j, count = 0, -1, 0
while i < n and j < n:
while len(zeroset) > 0:
j = j + 1
if j >= n:
br... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER WHILE VAR VAR VAR VAR WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VA... |
Given an array arr[] of n integers. Count the total number of sub-array having total distinct elements same as that of total distinct elements of the original array.
Example 1:
Input:
N=5
arr[] = {2, 1, 3, 2, 3}
Output: 5
Explanation:
Total distinct elements in array is 3
Total sub-arrays that satisfy the condition
... | class Solution:
def mapAdd(self, dic, val):
if val in dic:
dic[val] += 1
else:
dic[val] = 1
def mapSub(self, dic, val):
dic[val] -= 1
if dic[val] == 0:
del dic[val]
def getCount(self, arr):
dSet = set()
for val in arr:
... | CLASS_DEF FUNC_DEF IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_DEF VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN V... |
Given an array arr[] of n integers. Count the total number of sub-array having total distinct elements same as that of total distinct elements of the original array.
Example 1:
Input:
N=5
arr[] = {2, 1, 3, 2, 3}
Output: 5
Explanation:
Total distinct elements in array is 3
Total sub-arrays that satisfy the condition
... | class Solution:
def countDistinctSubarray(self, arr, n):
i, j = 0, 0
m = {}
count = 0
ori = len(set(arr))
ans = 0
while j < n:
if arr[j] not in m:
m[arr[j]] = 1
count += 1
else:
m[arr[j]] += 1
... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER WHILE VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR ... |
Given an array arr[] of n integers. Count the total number of sub-array having total distinct elements same as that of total distinct elements of the original array.
Example 1:
Input:
N=5
arr[] = {2, 1, 3, 2, 3}
Output: 5
Explanation:
Total distinct elements in array is 3
Total sub-arrays that satisfy the condition
... | class Solution:
def countDistinctSubarray(self, arr, n):
d = {}
for i in arr:
d[i] = 0
k = len(d)
count, j, w = 0, 0, 0
for i in range(n):
while k != w and j < n:
d[arr[j]] += 1
if d[arr[j]] == 1:
w ... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR V... |
Given a string S, find the length of the longest substring without repeating characters.
Example 1:
Input:
S = "geeksforgeeks"
Output:
7
Explanation:
Longest substring is
"eksforg".
Example 2:
Input:
S = "abdefgabef"
Output:
6
Explanation:
Longest substring are
"abdefg" , "bdefga" and "defgab".
Your Task:
You don't ... | class Solution:
def longestUniqueSubsttr(self, S):
start = 0
end = 0
maxLen = 0
charDict = {}
while end < len(S):
if S[end] in charDict and charDict[S[end]] >= start:
start = charDict[S[end]] + 1
charDict[S[end]] = end
end ... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR RETURN VAR |
Given a string S, find the length of the longest substring without repeating characters.
Example 1:
Input:
S = "geeksforgeeks"
Output:
7
Explanation:
Longest substring is
"eksforg".
Example 2:
Input:
S = "abdefgabef"
Output:
6
Explanation:
Longest substring are
"abdefg" , "bdefga" and "defgab".
Your Task:
You don't ... | class Solution:
def longestUniqueSubsttr(self, S):
d = {}
i, j, ans = 0, 0, 0
n = len(S)
while j < n:
if S[j] not in d:
d[S[j]] = j
else:
ans = max(ans, j - i)
a = d[S[j]]
while i <= a:
... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR WHILE VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR F... |
Given a string S, find the length of the longest substring without repeating characters.
Example 1:
Input:
S = "geeksforgeeks"
Output:
7
Explanation:
Longest substring is
"eksforg".
Example 2:
Input:
S = "abdefgabef"
Output:
6
Explanation:
Longest substring are
"abdefg" , "bdefga" and "defgab".
Your Task:
You don't ... | class Solution:
def longestUniqueSubsttr(self, s):
s_set = set()
j = 0
ans = -1
for i in range(len(s)):
if s[i] not in s_set:
s_set.add(s[i])
else:
while j < i and s[i] in s_set:
s_set.remove(s[j])
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR WHILE VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VA... |
Given a string S, find the length of the longest substring without repeating characters.
Example 1:
Input:
S = "geeksforgeeks"
Output:
7
Explanation:
Longest substring is
"eksforg".
Example 2:
Input:
S = "abdefgabef"
Output:
6
Explanation:
Longest substring are
"abdefg" , "bdefga" and "defgab".
Your Task:
You don't ... | class Solution:
def longestUniqueSubsttr(self, s):
n = len(s)
ans = 0
mem = {}
l = 0
for i in range(n):
if s[i] not in mem.keys():
mem[s[i]] = i
else:
ans = max(ans, i - l)
while l < mem[s[i]]:
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR WHILE VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR IF BIN_OP VAR VAR VAR A... |
Given a string S, find the length of the longest substring without repeating characters.
Example 1:
Input:
S = "geeksforgeeks"
Output:
7
Explanation:
Longest substring is
"eksforg".
Example 2:
Input:
S = "abdefgabef"
Output:
6
Explanation:
Longest substring are
"abdefg" , "bdefga" and "defgab".
Your Task:
You don't ... | class Solution:
def longestUniqueSubsttr(self, S):
d = {}
l = r = 0
maxlen = 0
while r < len(S):
if S[r] in d:
l = max(d[S[r]] + 1, l)
d[S[r]] = r
maxlen = max(maxlen, r - l + 1)
r += 1
return maxlen | CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER RETURN VAR |
Given a string S, find the length of the longest substring without repeating characters.
Example 1:
Input:
S = "geeksforgeeks"
Output:
7
Explanation:
Longest substring is
"eksforg".
Example 2:
Input:
S = "abdefgabef"
Output:
6
Explanation:
Longest substring are
"abdefg" , "bdefga" and "defgab".
Your Task:
You don't ... | class Solution:
def longestUniqueSubsttr(self, S):
n = len(S)
seen = set()
left = 0
right = 0
max_len = 0
while left < n and right < n:
if S[right] not in seen:
seen.add(s[right])
right += 1
max_len = max(ma... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER RETURN VAR |
Given a string S, find the length of the longest substring without repeating characters.
Example 1:
Input:
S = "geeksforgeeks"
Output:
7
Explanation:
Longest substring is
"eksforg".
Example 2:
Input:
S = "abdefgabef"
Output:
6
Explanation:
Longest substring are
"abdefg" , "bdefga" and "defgab".
Your Task:
You don't ... | class Solution:
def longestUniqueSubsttr(self, s):
n = len(s)
freq = {}
l, r = 0, 0
res = 0
while r < n:
while s[r] in freq:
del freq[s[l]]
l += 1
freq[s[r]] = 1 + freq.get(s[r], 0)
res = max(res, r - l + 1)... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR WHILE VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER RETURN VAR |
Given a string S, find the length of the longest substring without repeating characters.
Example 1:
Input:
S = "geeksforgeeks"
Output:
7
Explanation:
Longest substring is
"eksforg".
Example 2:
Input:
S = "abdefgabef"
Output:
6
Explanation:
Longest substring are
"abdefg" , "bdefga" and "defgab".
Your Task:
You don't ... | class Solution:
def longestUniqueSubsttr(self, S):
hashSet = set()
l = 0
r = 0
n = len(S)
maxLen = -1
while r < n:
while S[r] in hashSet:
hashSet.remove(S[l])
l += 1
hashSet.add(S[r])
maxLen = max(ma... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR WHILE VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER RETURN VAR |
Given a string S, find the length of the longest substring without repeating characters.
Example 1:
Input:
S = "geeksforgeeks"
Output:
7
Explanation:
Longest substring is
"eksforg".
Example 2:
Input:
S = "abdefgabef"
Output:
6
Explanation:
Longest substring are
"abdefg" , "bdefga" and "defgab".
Your Task:
You don't ... | class Solution:
def longestUniqueSubsttr(self, S):
d = {}
j = 0
ans = 0
for i in range(len(s)):
item = s[i]
if item in d:
j = max(j, d[item] + 1)
d[item] = i
ans = max(ans, i - j + 1)
return ans | CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR |
Given a string S, find the length of the longest substring without repeating characters.
Example 1:
Input:
S = "geeksforgeeks"
Output:
7
Explanation:
Longest substring is
"eksforg".
Example 2:
Input:
S = "abdefgabef"
Output:
6
Explanation:
Longest substring are
"abdefg" , "bdefga" and "defgab".
Your Task:
You don't ... | class Solution:
def longestUniqueSubsttr(self, S):
dict1 = {}
i = j = 0
max_len = 0
while j < len(s):
if S[j] not in dict1:
dict1[S[j]] = 1
max_len = max(max_len, j - i + 1)
j += 1
else:
while S[... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR VAR NUMBER RETURN VAR |
Given a string S, find the length of the longest substring without repeating characters.
Example 1:
Input:
S = "geeksforgeeks"
Output:
7
Explanation:
Longest substring is
"eksforg".
Example 2:
Input:
S = "abdefgabef"
Output:
6
Explanation:
Longest substring are
"abdefg" , "bdefga" and "defgab".
Your Task:
You don't ... | class Solution:
def longestUniqueSubsttr(self, S):
i, j = 0, 0
fMap = {}
lenMax = 0
while j < len(S):
fMap[S[j]] = fMap.get(S[j], 0) + 1
while fMap[S[j]] > 1:
fMap[S[i]] -= 1
i += 1
lenMax = max(lenMax, j - i + 1)
... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER WHILE VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER RETURN VAR |
Given a string S, find the length of the longest substring without repeating characters.
Example 1:
Input:
S = "geeksforgeeks"
Output:
7
Explanation:
Longest substring is
"eksforg".
Example 2:
Input:
S = "abdefgabef"
Output:
6
Explanation:
Longest substring are
"abdefg" , "bdefga" and "defgab".
Your Task:
You don't ... | class Solution:
def longestUniqueSubsttr(self, S):
a = []
maxm = 0
if len(S) == 1:
return 1
for i in S:
if i not in a:
a.append(i)
else:
if maxm < len(a):
maxm = len(a)
c = a.inde... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR RETURN FUNC_CAL... |
Given a string S, find the length of the longest substring without repeating characters.
Example 1:
Input:
S = "geeksforgeeks"
Output:
7
Explanation:
Longest substring is
"eksforg".
Example 2:
Input:
S = "abdefgabef"
Output:
6
Explanation:
Longest substring are
"abdefg" , "bdefga" and "defgab".
Your Task:
You don't ... | class Solution:
def longestUniqueSubsttr(self, S):
max_len = 0
current_len = 0
char_set = set()
left = 0
right = 0
while right < len(S):
if S[right] not in char_set:
char_set.add(S[right])
current_len += 1
m... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR |
Given a string S, find the length of the longest substring without repeating characters.
Example 1:
Input:
S = "geeksforgeeks"
Output:
7
Explanation:
Longest substring is
"eksforg".
Example 2:
Input:
S = "abdefgabef"
Output:
6
Explanation:
Longest substring are
"abdefg" , "bdefga" and "defgab".
Your Task:
You don't ... | class Solution:
def longestUniqueSubsttr(self, S):
has = [(-1) for _ in range(256)]
left = 0
right = 0
n = len(S)
res = 0
while right < n:
if has[ord(S[right])] != -1:
left = max(has[ord(S[right])] + 1, left)
has[ord(S[right])]... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CAL... |
Given a string S, find the length of the longest substring without repeating characters.
Example 1:
Input:
S = "geeksforgeeks"
Output:
7
Explanation:
Longest substring is
"eksforg".
Example 2:
Input:
S = "abdefgabef"
Output:
6
Explanation:
Longest substring are
"abdefg" , "bdefga" and "defgab".
Your Task:
You don't ... | class Solution:
def longestUniqueSubsttr(self, S):
i, j = 0, 0
maxi = -9999
n = len(S)
d = {}
while j < n:
if S[j] in d:
while S[i] != S[j]:
d[S[i]] -= 1
if d[S[i]] == 0:
del d[S[i]]
... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT WHILE VAR VAR IF VAR VAR VAR WHILE VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN... |
Given a string S, find the length of the longest substring without repeating characters.
Example 1:
Input:
S = "geeksforgeeks"
Output:
7
Explanation:
Longest substring is
"eksforg".
Example 2:
Input:
S = "abdefgabef"
Output:
6
Explanation:
Longest substring are
"abdefg" , "bdefga" and "defgab".
Your Task:
You don't ... | class Solution:
def longestUniqueSubsttr(self, s):
if len(s) == 0:
return 0
start = 0
maxl = 0
d = {}
for i in range(len(s)):
if s[i] in d and start <= d[s[i]]:
start = d[s[i]] + 1
else:
maxl = max(maxl, i -... | CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR VAR RETURN VAR |
Given a string S, find the length of the longest substring without repeating characters.
Example 1:
Input:
S = "geeksforgeeks"
Output:
7
Explanation:
Longest substring is
"eksforg".
Example 2:
Input:
S = "abdefgabef"
Output:
6
Explanation:
Longest substring are
"abdefg" , "bdefga" and "defgab".
Your Task:
You don't ... | class Solution:
def longestUniqueSubsttr(self, str):
l = 0
res = 0
a = {}
arr = []
for r in range(len(str)):
while str[r] in a:
ele = arr.pop(0)
del a[ele]
l += 1
arr.append(str[r])
a[str[r]]... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR |
Given a string S, find the length of the longest substring without repeating characters.
Example 1:
Input:
S = "geeksforgeeks"
Output:
7
Explanation:
Longest substring is
"eksforg".
Example 2:
Input:
S = "abdefgabef"
Output:
6
Explanation:
Longest substring are
"abdefg" , "bdefga" and "defgab".
Your Task:
You don't ... | class Solution:
def longestUniqueSubsttr(self, S):
n = len(S)
if n == 0:
return 0
res = float("-inf")
has = set()
left = 0
for right in range(n):
if S[right] in has:
while left < right and S[right] in has:
h... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR WHILE VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP B... |
Given a string S, find the length of the longest substring without repeating characters.
Example 1:
Input:
S = "geeksforgeeks"
Output:
7
Explanation:
Longest substring is
"eksforg".
Example 2:
Input:
S = "abdefgabef"
Output:
6
Explanation:
Longest substring are
"abdefg" , "bdefga" and "defgab".
Your Task:
You don't ... | class Solution:
def longestUniqueSubsttr(self, S):
hashmap = {}
left = 0
right = 0
i = -1
j = -1
max_len = -int(1000000000.0)
while right < len(S):
if S[right] not in hashmap:
hashmap[S[right]] = 1
else:
... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR V... |
Given a string S, find the length of the longest substring without repeating characters.
Example 1:
Input:
S = "geeksforgeeks"
Output:
7
Explanation:
Longest substring is
"eksforg".
Example 2:
Input:
S = "abdefgabef"
Output:
6
Explanation:
Longest substring are
"abdefg" , "bdefga" and "defgab".
Your Task:
You don't ... | class Solution:
def longestUniqueSubsttr(self, S):
j = 0
i = 0
x = {}
max_len = 0
while j < len(S):
if S[j] not in x:
x[S[j]] = 1
else:
max_len = max(max_len, j - i)
while i < j and S[i] != S[j]:
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR WHILE VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIG... |
Given a string S, find the length of the longest substring without repeating characters.
Example 1:
Input:
S = "geeksforgeeks"
Output:
7
Explanation:
Longest substring is
"eksforg".
Example 2:
Input:
S = "abdefgabef"
Output:
6
Explanation:
Longest substring are
"abdefg" , "bdefga" and "defgab".
Your Task:
You don't ... | class Solution:
def longestUniqueSubsttr(self, S):
s = {}
left = output = 0
for right, num in enumerate(S):
if num in s:
left = max(left, s[num] + 1)
output = max(output, right - left + 1)
s[num] = right
return output | CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR RETURN VAR |
Given a string S, find the length of the longest substring without repeating characters.
Example 1:
Input:
S = "geeksforgeeks"
Output:
7
Explanation:
Longest substring is
"eksforg".
Example 2:
Input:
S = "abdefgabef"
Output:
6
Explanation:
Longest substring are
"abdefg" , "bdefga" and "defgab".
Your Task:
You don't ... | class Solution:
def longestUniqueSubsttr(self, S):
l = []
s1 = ""
for i in S:
if i not in s1:
s1 += i
else:
l.append(s1)
k = s1.index(i)
s1 = s1[k + 1 :] + i
l.append(s1)
l.sort(key=len)
... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR STRING FOR VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR NUMBER |
Given a string S, find the length of the longest substring without repeating characters.
Example 1:
Input:
S = "geeksforgeeks"
Output:
7
Explanation:
Longest substring is
"eksforg".
Example 2:
Input:
S = "abdefgabef"
Output:
6
Explanation:
Longest substring are
"abdefg" , "bdefga" and "defgab".
Your Task:
You don't ... | class Solution:
def longestUniqueSubsttr(self, S):
n = len(S)
cur_len = 1
max_len = 1
prev_index = -1
visited = {}
for i in S:
visited[i] = -1
visited[S[0]] = 0
for i in range(1, n):
prev_index = visited[S[i]]
if pr... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR VAR IF VAR NUMBER BIN_OP VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BI... |
Given a string S, find the length of the longest substring without repeating characters.
Example 1:
Input:
S = "geeksforgeeks"
Output:
7
Explanation:
Longest substring is
"eksforg".
Example 2:
Input:
S = "abdefgabef"
Output:
6
Explanation:
Longest substring are
"abdefg" , "bdefga" and "defgab".
Your Task:
You don't ... | class Solution:
def longestUniqueSubsttr(self, S):
if len(S) == 1 or S == S[0] * len(S):
return 1
start = 0
l = 0
i = 1
while i < len(S):
if S[i] in S[start:i]:
while start < i:
if S[start] == S[i]:
... | CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR WHILE VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR BIN_OP V... |
Given a string S, find the length of the longest substring without repeating characters.
Example 1:
Input:
S = "geeksforgeeks"
Output:
7
Explanation:
Longest substring is
"eksforg".
Example 2:
Input:
S = "abdefgabef"
Output:
6
Explanation:
Longest substring are
"abdefg" , "bdefga" and "defgab".
Your Task:
You don't ... | class Solution:
def longestUniqueSubsttr(self, S):
dic = {}
cm = count = i = 0
while i < len(S):
if S[i] in dic:
if cm < count:
cm = count
count = 0
i = dic[S[i]] + 1
dic = {}
else:
... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR DICT ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR RETURN VAR RETURN VAR |
Given a string S, find the length of the longest substring without repeating characters.
Example 1:
Input:
S = "geeksforgeeks"
Output:
7
Explanation:
Longest substring is
"eksforg".
Example 2:
Input:
S = "abdefgabef"
Output:
6
Explanation:
Longest substring are
"abdefg" , "bdefga" and "defgab".
Your Task:
You don't ... | class Solution:
def longestUniqueSubsttr(self, S):
mp = {}
ans = 0
i = 0
for j in range(len(S)):
if S[j] in mp:
i = max(mp[S[j]], i)
ans = max(ans, j - i + 1)
mp[S[j]] = j + 1
return ans | CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR |
Given a string S, find the length of the longest substring without repeating characters.
Example 1:
Input:
S = "geeksforgeeks"
Output:
7
Explanation:
Longest substring is
"eksforg".
Example 2:
Input:
S = "abdefgabef"
Output:
6
Explanation:
Longest substring are
"abdefg" , "bdefga" and "defgab".
Your Task:
You don't ... | class Solution:
def longestUniqueSubsttr(self, str1):
r = 0
l = 0
map = {}
MxLen, n, lent = 0, len(str1), 0
while r < n:
if map.get(str1[r], -1) != -1:
l = max(map[str1[r]] + 1, l)
map[str1[r]] = r
MxLen = max(MxLen, r - l ... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER WHILE VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBE... |
Given a string S, find the length of the longest substring without repeating characters.
Example 1:
Input:
S = "geeksforgeeks"
Output:
7
Explanation:
Longest substring is
"eksforg".
Example 2:
Input:
S = "abdefgabef"
Output:
6
Explanation:
Longest substring are
"abdefg" , "bdefga" and "defgab".
Your Task:
You don't ... | class Solution:
def longestUniqueSubsttr(self, s):
temp = ""
ans = 0
for i in range(len(s)):
ch = s[i]
if ch not in temp:
temp += ch
ans = max(ans, len(temp))
else:
temp += ch
while temp[0] !... | CLASS_DEF FUNC_DEF ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR WHILE VAR NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER RETURN VAR |
Given a string S, find the length of the longest substring without repeating characters.
Example 1:
Input:
S = "geeksforgeeks"
Output:
7
Explanation:
Longest substring is
"eksforg".
Example 2:
Input:
S = "abdefgabef"
Output:
6
Explanation:
Longest substring are
"abdefg" , "bdefga" and "defgab".
Your Task:
You don't ... | class Solution:
def longestUniqueSubsttr(self, s):
n = len(s)
res = 0
prev = [-1] * 256
i = 0
for j in range(n):
i = max(i, prev[ord(s[j])] + 1)
maxEnd = j - i + 1
res = max(res, maxEnd)
prev[ord(s[j])] = j
return res | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VA... |
Given a string S, find the length of the longest substring without repeating characters.
Example 1:
Input:
S = "geeksforgeeks"
Output:
7
Explanation:
Longest substring is
"eksforg".
Example 2:
Input:
S = "abdefgabef"
Output:
6
Explanation:
Longest substring are
"abdefg" , "bdefga" and "defgab".
Your Task:
You don't ... | class Solution:
def longestUniqueSubsttr(self, S):
i = -1
j = -1
mlen = 0
hashmap = {}
le = len(S) - 1
while True:
f1 = False
f2 = False
while i < le:
f1 = True
i += 1
ch = S[i]
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR ... |
Given a string S, find the length of the longest substring without repeating characters.
Example 1:
Input:
S = "geeksforgeeks"
Output:
7
Explanation:
Longest substring is
"eksforg".
Example 2:
Input:
S = "abdefgabef"
Output:
6
Explanation:
Longest substring are
"abdefg" , "bdefga" and "defgab".
Your Task:
You don't ... | class Solution:
def longestUniqueSubsttr(self, s):
d = {}
l = 0
ml = 0
for r in range(len(s)):
if s[r] not in d:
ml = max(ml, r - l + 1)
elif d[s[r]] < l:
ml = max(ml, r - l + 1)
else:
l = d[s[r]] + ... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR... |
Given a string S, find the length of the longest substring without repeating characters.
Example 1:
Input:
S = "geeksforgeeks"
Output:
7
Explanation:
Longest substring is
"eksforg".
Example 2:
Input:
S = "abdefgabef"
Output:
6
Explanation:
Longest substring are
"abdefg" , "bdefga" and "defgab".
Your Task:
You don't ... | class Solution:
def longestUniqueSubsttr(self, arr):
r, l = 0, 0
max_len = 0
count_fr = {}
while r < len(arr):
if count_fr.get(arr[r], -1) != -1:
l = max(count_fr[arr[r]] + 1, l)
max_len = max(max_len, r - l + 1)
count_fr[arr[r]] =... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT WHILE VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER RETURN VAR |
Given a string S, find the length of the longest substring without repeating characters.
Example 1:
Input:
S = "geeksforgeeks"
Output:
7
Explanation:
Longest substring is
"eksforg".
Example 2:
Input:
S = "abdefgabef"
Output:
6
Explanation:
Longest substring are
"abdefg" , "bdefga" and "defgab".
Your Task:
You don't ... | class Solution:
def longestUniqueSubsttr(self, s):
n = len(s)
hm = {}
l = 0
r = 0
ans = 0
while r < n:
if s[r] in hm:
l = max(l, hm[s[r]] + 1)
hm[s[r]] = r
ans = max(ans, r - l + 1)
r += 1
return... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER RETURN VAR |
Given a string S, find the length of the longest substring without repeating characters.
Example 1:
Input:
S = "geeksforgeeks"
Output:
7
Explanation:
Longest substring is
"eksforg".
Example 2:
Input:
S = "abdefgabef"
Output:
6
Explanation:
Longest substring are
"abdefg" , "bdefga" and "defgab".
Your Task:
You don't ... | class Solution:
def longestUniqueSubsttr(self, s: str) -> int:
max_len = 0
left, right = 0, 0
unique_chars = set()
while right < len(s):
if s[right] not in unique_chars:
unique_chars.add(s[right])
right += 1
max_len = max(m... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER RETURN VAR VAR |
Given a string S, find the length of the longest substring without repeating characters.
Example 1:
Input:
S = "geeksforgeeks"
Output:
7
Explanation:
Longest substring is
"eksforg".
Example 2:
Input:
S = "abdefgabef"
Output:
6
Explanation:
Longest substring are
"abdefg" , "bdefga" and "defgab".
Your Task:
You don't ... | class Solution:
def longestUniqueSubsttr(self, S):
l = 0
r = 0
max = 0
a = ""
for i in s:
if i in a[l:r]:
while a[l] != i:
l += 1
l += 1
a += i
if r - l + 1 > max:
max = r... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR VAR IF VAR VAR VAR VAR WHILE VAR VAR VAR VAR NUMBER VAR NUMBER VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER RETURN VAR |
Given a string S, find the length of the longest substring without repeating characters.
Example 1:
Input:
S = "geeksforgeeks"
Output:
7
Explanation:
Longest substring is
"eksforg".
Example 2:
Input:
S = "abdefgabef"
Output:
6
Explanation:
Longest substring are
"abdefg" , "bdefga" and "defgab".
Your Task:
You don't ... | class Solution:
def longestUniqueSubsttr(self, S):
maxi = -(10**9)
dic = {}
start = 0
for i in range(len(S)):
if S[i] not in dic:
dic[S[i]] = i
else:
if start < dic[S[i]] + 1:
start = dic[S[i]] + 1
... | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR IF VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR... |
Given a string S, find the length of the longest substring without repeating characters.
Example 1:
Input:
S = "geeksforgeeks"
Output:
7
Explanation:
Longest substring is
"eksforg".
Example 2:
Input:
S = "abdefgabef"
Output:
6
Explanation:
Longest substring are
"abdefg" , "bdefga" and "defgab".
Your Task:
You don't ... | class Solution:
def longestUniqueSubsttr(self, S):
ans = 0
l = 0
A = set()
for i in range(len(S)):
while S[i] in A:
A.remove(S[l])
l = l + 1
A.add(S[i])
ans = max(ans, len(A))
return ans | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN VAR |
Given a string S, find the length of the longest substring without repeating characters.
Example 1:
Input:
S = "geeksforgeeks"
Output:
7
Explanation:
Longest substring is
"eksforg".
Example 2:
Input:
S = "abdefgabef"
Output:
6
Explanation:
Longest substring are
"abdefg" , "bdefga" and "defgab".
Your Task:
You don't ... | class Solution:
def longestUniqueSubsttr(self, S):
n = len(S)
d = {}
for i in range(n):
d[S[i]] = -1
d[S[0]] = 0
l = 1
maxx = 1
for i in range(1, n):
x = d[S[i]]
if x == -1 or i - l > x:
l += 1
e... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR VAR IF VAR NUMBER BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN... |
Given a string S, find the length of the longest substring without repeating characters.
Example 1:
Input:
S = "geeksforgeeks"
Output:
7
Explanation:
Longest substring is
"eksforg".
Example 2:
Input:
S = "abdefgabef"
Output:
6
Explanation:
Longest substring are
"abdefg" , "bdefga" and "defgab".
Your Task:
You don't ... | class Solution:
def longestUniqueSubsttr(self, S):
l = []
r = []
if len(set(S)) == len(S):
return len(S)
for i in S:
if i not in r:
r += [i]
else:
l += [len(r)]
p = i
while True:
... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST IF FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR FOR VAR VAR IF VAR VAR VAR LIST VAR VAR LIST FUNC_CALL VAR VAR ASSIGN VAR VAR WHILE NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER VAR LIST VAR VAR LIST FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VA... |
Given a string S, find the length of the longest substring without repeating characters.
Example 1:
Input:
S = "geeksforgeeks"
Output:
7
Explanation:
Longest substring is
"eksforg".
Example 2:
Input:
S = "abdefgabef"
Output:
6
Explanation:
Longest substring are
"abdefg" , "bdefga" and "defgab".
Your Task:
You don't ... | class Solution:
def longestUniqueSubsttr(self, S):
seen = {}
mL = float("-inf")
start, end = 0, 0
while end < len(S):
if S[end] in seen:
start = max(start, seen[S[end]] + 1)
seen[S[end]] = end
mL = max(mL, end - start + 1)
... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER RETURN VAR FUNC_CALL VAR STRING VA... |
Given a string S, find the length of the longest substring without repeating characters.
Example 1:
Input:
S = "geeksforgeeks"
Output:
7
Explanation:
Longest substring is
"eksforg".
Example 2:
Input:
S = "abdefgabef"
Output:
6
Explanation:
Longest substring are
"abdefg" , "bdefga" and "defgab".
Your Task:
You don't ... | class Solution:
def longestUniqueSubsttr(self, S):
char = [(0) for i in range(250)]
n = len(S)
j = 0
ans = 0
i = 0
while j < n:
char[ord(S[j])] += 1
if char[ord(S[j])] > 1:
while char[ord(S[j])] > 1:
char[or... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VA... |
Given a string S, find the length of the longest substring without repeating characters.
Example 1:
Input:
S = "geeksforgeeks"
Output:
7
Explanation:
Longest substring is
"eksforg".
Example 2:
Input:
S = "abdefgabef"
Output:
6
Explanation:
Longest substring are
"abdefg" , "bdefga" and "defgab".
Your Task:
You don't ... | class Solution:
def longestUniqueSubsttr(self, S):
length = len(S)
first = 0
second = 0
max = 1
count_list = []
for i in range(26):
count_list.append(0)
while second < length:
while count_list[ord(S[second]) - ord("a")]:
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER WHILE VAR VAR WHILE VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING NUMBER VAR N... |
Given a string S, find the length of the longest substring without repeating characters.
Example 1:
Input:
S = "geeksforgeeks"
Output:
7
Explanation:
Longest substring is
"eksforg".
Example 2:
Input:
S = "abdefgabef"
Output:
6
Explanation:
Longest substring are
"abdefg" , "bdefga" and "defgab".
Your Task:
You don't ... | class Solution:
def longestUniqueSubsttr(self, S):
start = end = m = 0
dic = {}
for i, c in enumerate(S):
if c in dic and dic[c] >= start:
m = max(m, end - start)
start = dic[c] + 1
dic[c] = i
end += 1
return max(m,... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR NUMBER ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR |
There are several cards arranged in a row, and each has an associated number of points. The points are given in the integer array cardPoints of size N.
In one step, you can take one card from beginning or from the end of the row. You have to take exactly k cards.
Your score is the sum of the points of the cards you hav... | class Solution:
def maxScore(self, a, n, k):
sumf = sum(a[:k])
sumb = sum(a[n - k : n])
bf = 0
ef = k - 1
bb = n - 1
eb = n - k
ans = 0
x = 1
while x <= k:
if sumf >= sumb:
ans += a[bf]
sumf -= a[bf]... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER... |
There are several cards arranged in a row, and each has an associated number of points. The points are given in the integer array cardPoints of size N.
In one step, you can take one card from beginning or from the end of the row. You have to take exactly k cards.
Your score is the sum of the points of the cards you hav... | class Solution:
def maxScore(self, cardPoints, n, k):
n = len(cardPoints)
res = sumi = sum(cardPoints[:k])
left = k - 1
right = n - 1
while left >= 0:
sumi -= cardPoints[left]
sumi += cardPoints[right]
res = max(res, sumi)
left... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR |
There are several cards arranged in a row, and each has an associated number of points. The points are given in the integer array cardPoints of size N.
In one step, you can take one card from beginning or from the end of the row. You have to take exactly k cards.
Your score is the sum of the points of the cards you hav... | class Solution:
def maxScore(self, a, N, k):
s = sum(a[:k])
e = 0
m = max(s, e)
j = len(a) - 1
for i in range(k - 1, -1, -1):
e += a[j]
s -= a[i]
m = max(m, s + e)
j -= 1
k -= 1
return m | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER RETURN VAR |
There are several cards arranged in a row, and each has an associated number of points. The points are given in the integer array cardPoints of size N.
In one step, you can take one card from beginning or from the end of the row. You have to take exactly k cards.
Your score is the sum of the points of the cards you hav... | class Solution:
def maxScore(self, cardPoints, N, k):
s = 0
for i in range(N - k, N):
s += cardPoints[i]
p = s
for i in range(k):
h = cardPoints[N - (k - i)]
p = p - h + cardPoints[i]
s = max(s, p)
return s | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR |
There are several cards arranged in a row, and each has an associated number of points. The points are given in the integer array cardPoints of size N.
In one step, you can take one card from beginning or from the end of the row. You have to take exactly k cards.
Your score is the sum of the points of the cards you hav... | class Solution:
def maxScore(self, arr, n, k):
l, r = 0, n - k
summ = max_sum = sum(arr[r:])
for r in range(n - k, n):
summ = summ - arr[r] + arr[l]
l += 1
if summ > max_sum:
max_sum = summ
return max_sum | CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER BIN_OP VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR RETURN VAR |
There are several cards arranged in a row, and each has an associated number of points. The points are given in the integer array cardPoints of size N.
In one step, you can take one card from beginning or from the end of the row. You have to take exactly k cards.
Your score is the sum of the points of the cards you hav... | class Solution:
def maxScore(self, cardPoints, N, k):
maxScore = 0
sumTotal = sum(cardPoints[:k])
maxScore = max(maxScore, sumTotal)
for i in range(k):
sumTotal = sumTotal - cardPoints[k - 1 - i] + cardPoints[N - 1 - i]
maxScore = max(maxScore, sumTotal)
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR |
There are several cards arranged in a row, and each has an associated number of points. The points are given in the integer array cardPoints of size N.
In one step, you can take one card from beginning or from the end of the row. You have to take exactly k cards.
Your score is the sum of the points of the cards you hav... | class Solution:
def maxScore(self, a, n, k):
ans = 0
for i in range(k):
ans += a[i]
res = ans
j = n - 1
while i >= 0:
ans = ans - a[i] + a[j]
res = max(res, ans)
i -= 1
j -= 1
return res | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR |
There are several cards arranged in a row, and each has an associated number of points. The points are given in the integer array cardPoints of size N.
In one step, you can take one card from beginning or from the end of the row. You have to take exactly k cards.
Your score is the sum of the points of the cards you hav... | class Solution:
def maxScore(self, cardPoints, N, k):
tot = sum(cardPoints)
ans = 0
res = 0
for i in range(N - k):
res += cardPoints[i]
ans = tot - res
for i in range(N - k, N):
res += cardPoints[i] - cardPoints[i - (N - k)]
ans = ... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR RETURN VAR |
There are several cards arranged in a row, and each has an associated number of points. The points are given in the integer array cardPoints of size N.
In one step, you can take one card from beginning or from the end of the row. You have to take exactly k cards.
Your score is the sum of the points of the cards you hav... | class Solution:
def maxScore(self, cardPoints, N, k):
left, right = 0, len(cardPoints) - k
total = sum(cardPoints[right:])
res = total
while right < len(cardPoints):
total += cardPoints[left] - cardPoints[right]
res = max(total, res)
left += 1
... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR |
There are several cards arranged in a row, and each has an associated number of points. The points are given in the integer array cardPoints of size N.
In one step, you can take one card from beginning or from the end of the row. You have to take exactly k cards.
Your score is the sum of the points of the cards you hav... | class Solution:
def maxScore(self, A, N, k):
req = len(A) - k
summ = sum(A)
partSum = sum(A[0:req])
mini = partSum
for i in range(req, N):
old = i - req
partSum -= A[old]
partSum += A[i]
mini = min(mini, partSum)
return... | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN BIN_OP VAR VAR |
There are several cards arranged in a row, and each has an associated number of points. The points are given in the integer array cardPoints of size N.
In one step, you can take one card from beginning or from the end of the row. You have to take exactly k cards.
Your score is the sum of the points of the cards you hav... | class Solution:
def maxScore(self, cardPoints, N, k):
cur = sum(cardPoints[:k])
maxs = cur
x = len(cardPoints)
for i in range(k):
cur = cur + cardPoints[x - 1 - i]
cur = cur - cardPoints[k - 1 - i]
maxs = max(maxs, cur)
return maxs | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR |
There are several cards arranged in a row, and each has an associated number of points. The points are given in the integer array cardPoints of size N.
In one step, you can take one card from beginning or from the end of the row. You have to take exactly k cards.
Your score is the sum of the points of the cards you hav... | class Solution:
def maxScore(self, cardPoints, N, k):
cardPoints = cardPoints[N - k :] + cardPoints[:k]
i, j = 0, 0
maxi = 0
sum_ = 0
count = 0
N = len(cardPoints)
while j < N:
sum_ += cardPoints[j]
count += 1
if count < k:... | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUM... |
There are several cards arranged in a row, and each has an associated number of points. The points are given in the integer array cardPoints of size N.
In one step, you can take one card from beginning or from the end of the row. You have to take exactly k cards.
Your score is the sum of the points of the cards you hav... | class Solution:
def maxScore(self, cardPoints, N, k):
n = len(cardPoints)
left, right = 0, n - k
total_sum = sum(cardPoints[right:])
ans_sum = total_sum
for i in range(k):
total_sum += cardPoints[left] - cardPoints[right]
ans_sum = max(ans_sum, total_... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR |
There are several cards arranged in a row, and each has an associated number of points. The points are given in the integer array cardPoints of size N.
In one step, you can take one card from beginning or from the end of the row. You have to take exactly k cards.
Your score is the sum of the points of the cards you hav... | class Solution:
def maxScore(self, cardPoints, N, k):
ans = 0
for i in range(k):
ans += cardPoints[i]
cur = ans
for i in range(k - 1, -1, -1):
cur -= cardPoints[i]
cur += cardPoints[N - k + i]
ans = max(cur, ans)
return ans | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR |
There are several cards arranged in a row, and each has an associated number of points. The points are given in the integer array cardPoints of size N.
In one step, you can take one card from beginning or from the end of the row. You have to take exactly k cards.
Your score is the sum of the points of the cards you hav... | class Solution:
def maxScore(self, cardPoints, N, k):
summa = 0
for i in range(N - k):
summa += cardPoints[i]
mini = summa
for i in range(k):
summa -= cardPoints[i]
summa += cardPoints[i + N - k]
mini = min(mini, summa)
return ... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR VAR |
There are several cards arranged in a row, and each has an associated number of points. The points are given in the integer array cardPoints of size N.
In one step, you can take one card from beginning or from the end of the row. You have to take exactly k cards.
Your score is the sum of the points of the cards you hav... | class Solution:
def maxScore(self, cardPoints, N, k):
total_points = sum(cardPoints)
if k == len(cardPoints):
return total_points
remain_size = N - k
curr_sum = sum(cardPoints[:remain_size])
mini_sum = curr_sum
for i in range(remain_size, len(cardPoints))... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN BIN_OP VAR VAR |
There are several cards arranged in a row, and each has an associated number of points. The points are given in the integer array cardPoints of size N.
In one step, you can take one card from beginning or from the end of the row. You have to take exactly k cards.
Your score is the sum of the points of the cards you hav... | class Solution:
def maxScore(self, cardPoints, N, k):
arr = cardPoints
n = len(cardPoints)
t = sum(cardPoints)
r = n - k
sub = sum(arr[:r])
min_s = sub
for i in range(r, n):
sub += arr[i]
sub -= arr[i - r]
min_s = min(min_s... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN BIN_OP VAR VAR |
There are several cards arranged in a row, and each has an associated number of points. The points are given in the integer array cardPoints of size N.
In one step, you can take one card from beginning or from the end of the row. You have to take exactly k cards.
Your score is the sum of the points of the cards you hav... | class Solution:
def maxScore(self, arr, N, k):
i = 0
j = N - k
total = sum(arr[j:])
ans = total
while j < N:
total = total + arr[i] - arr[j]
ans = max(ans, total)
i = i + 1
j = j + 1
return ans | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR |
There are several cards arranged in a row, and each has an associated number of points. The points are given in the integer array cardPoints of size N.
In one step, you can take one card from beginning or from the end of the row. You have to take exactly k cards.
Your score is the sum of the points of the cards you hav... | class Solution:
def maxScore(self, cardPoints, N, k):
sum1 = 0
ans = 0
i = 0
j = N - 1
sum1 = 0
while i < k:
sum1 = sum1 + cardPoints[i]
ans = max(ans, sum1)
i = i + 1
i = i - 1
while i >= 0 and j >= 0:
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ... |
There are several cards arranged in a row, and each has an associated number of points. The points are given in the integer array cardPoints of size N.
In one step, you can take one card from beginning or from the end of the row. You have to take exactly k cards.
Your score is the sum of the points of the cards you hav... | class Solution:
def maxScore(self, cardPoints, N, k):
suff = [0]
for el in cardPoints[::-1]:
suff.append(suff[-1] + el)
ans = 0
temp = 0
for i in range(k + 1):
ans = max(ans, temp + suff[k - i])
if i < len(cardPoints):
temp... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST NUMBER FOR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR IF VAR FUNC_CALL VAR VAR VAR VAR VAR RETURN VAR |
There are several cards arranged in a row, and each has an associated number of points. The points are given in the integer array cardPoints of size N.
In one step, you can take one card from beginning or from the end of the row. You have to take exactly k cards.
Your score is the sum of the points of the cards you hav... | class Solution:
def maxScore(self, cardPoints, N, k):
o_s = sum(cardPoints[N - k :])
m = o_s
i = 0
j = N - k - 1
while j < N - 1:
j += 1
o_s = o_s - cardPoints[j] + cardPoints[i]
i += 1
m = max(m, o_s)
return m | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR |
There are several cards arranged in a row, and each has an associated number of points. The points are given in the integer array cardPoints of size N.
In one step, you can take one card from beginning or from the end of the row. You have to take exactly k cards.
Your score is the sum of the points of the cards you hav... | class Solution:
def maxScore(self, cardPoints, N, k):
start_sum = 0
end_sum = sum(cardPoints[-k:])
max_sum = end_sum
for i in range(k):
start_sum = start_sum + cardPoints[i]
end_sum = end_sum - cardPoints[N - k + i]
current_sum = start_sum + end_s... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR |
There are several cards arranged in a row, and each has an associated number of points. The points are given in the integer array cardPoints of size N.
In one step, you can take one card from beginning or from the end of the row. You have to take exactly k cards.
Your score is the sum of the points of the cards you hav... | class Solution:
def maxScore(self, card, N, k):
n = len(card)
r = n - k
total = sum(card[n - k :])
res = total
l = 0
while r < n:
total = total + card[l] - card[r]
res = max(res, total)
r += 1
l += 1
return res | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR |
There are several cards arranged in a row, and each has an associated number of points. The points are given in the integer array cardPoints of size N.
In one step, you can take one card from beginning or from the end of the row. You have to take exactly k cards.
Your score is the sum of the points of the cards you hav... | class Solution:
def maxScore(self, cardPoints, N, k):
window = N - k
if window == 0:
return sum(cardPoints)
window_sum = sum(cardPoints[: window - 1])
total_sum = sum(cardPoints)
max_sum = 0
for i in range(window - 1, N):
window_sum += cardPoi... | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER RETURN FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER RETUR... |
There are several cards arranged in a row, and each has an associated number of points. The points are given in the integer array cardPoints of size N.
In one step, you can take one card from beginning or from the end of the row. You have to take exactly k cards.
Your score is the sum of the points of the cards you hav... | class Solution:
def maxScore(self, cardPoints, N, k):
startpoint = N - 1
endpoint = k - 1
rollingsum = sum(cardPoints[0 : endpoint + 1])
maxsum = rollingsum
for i in range(k):
rollingsum = rollingsum - cardPoints[endpoint] + cardPoints[startpoint]
sta... | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR |
There are several cards arranged in a row, and each has an associated number of points. The points are given in the integer array cardPoints of size N.
In one step, you can take one card from beginning or from the end of the row. You have to take exactly k cards.
Your score is the sum of the points of the cards you hav... | class Solution:
def maxScore(self, arr, n, k):
if k == n:
return sum(arr)
left_sum = 0
right_sum = 0
for i in range(k):
left_sum += arr[i]
ll = 0
lr = k - 1
rr = n - 1
rl = n - k
count = left_sum
suma = left_sum... | CLASS_DEF FUNC_DEF IF VAR VAR RETURN FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VA... |
There are several cards arranged in a row, and each has an associated number of points. The points are given in the integer array cardPoints of size N.
In one step, you can take one card from beginning or from the end of the row. You have to take exactly k cards.
Your score is the sum of the points of the cards you hav... | class Solution:
def maxScore(self, cardPoints, N, k):
i, j, ans = 0, 0, float("inf")
state = 0
window = N - k
count = 0
for j in range(N):
state += cardPoints[j]
count += 1
if count > window:
state -= cardPoints[i]
... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR NUMBER NUMBER FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR VAR |
There are several cards arranged in a row, and each has an associated number of points. The points are given in the integer array cardPoints of size N.
In one step, you can take one card from beginning or from the end of the row. You have to take exactly k cards.
Your score is the sum of the points of the cards you hav... | class Solution:
def maxScore(self, cardPoints, N, k):
sum = 0
res = 0
Sum = []
Score = 0
n = len(cardPoints)
for i in range(n):
sum += cardPoints[i]
Sum.append(sum)
for i in range(k + 1):
j = i + n - k - 1
if i ... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP... |
Given a string, find the length of the longest substring without repeating characters.
Examples:
Given "abcabcbb", the answer is "abc", which the length is 3.
Given "bbbbb", the answer is "b", with the length of 1.
Given "pwwkew", the answer is "wke", with the length of 3. Note that the answer must be a substring, ... | class Solution:
def lengthOfLongestSubstring(self, s):
L, res, last = -1, 0, {}
for R, char in enumerate(s):
if char in last and last[char] > L:
L = last[char]
elif R - L > res:
res = R - L
last[char] = R
return res | CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR NUMBER NUMBER DICT FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR RETURN VAR |
Given a string, find the length of the longest substring without repeating characters.
Examples:
Given "abcabcbb", the answer is "abc", which the length is 3.
Given "bbbbb", the answer is "b", with the length of 1.
Given "pwwkew", the answer is "wke", with the length of 3. Note that the answer must be a substring, ... | class Solution:
def lengthOfLongestSubstring(self, s):
result = 0
if len(s) == 0:
return result
hashmap = {}
start = 0
for i in range(len(s)):
if s[i] in hashmap:
start = max(hashmap[s[i]] + 1, start)
hashmap[s[i]] = i
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR |
Given a string, find the length of the longest substring without repeating characters.
Examples:
Given "abcabcbb", the answer is "abc", which the length is 3.
Given "bbbbb", the answer is "b", with the length of 1.
Given "pwwkew", the answer is "wke", with the length of 3. Note that the answer must be a substring, ... | class Solution:
def lengthOfLongestSubstring(self, s):
head = 0
dic = {}
res = 0
for i in range(len(s)):
if s[i] in dic and dic[s[i]] >= head:
res = max(res, i - head)
head = dic[s[i]] + 1
dic[s[i]] = i
return max(res, ... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR RETURN FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR |
Given a string, find the length of the longest substring without repeating characters.
Examples:
Given "abcabcbb", the answer is "abc", which the length is 3.
Given "bbbbb", the answer is "b", with the length of 1.
Given "pwwkew", the answer is "wke", with the length of 3. Note that the answer must be a substring, ... | class Solution:
def lengthOfLongestSubstring(self, s):
record = {}
result = 0
start = -1
for i, x in enumerate(s):
if x in record:
start = max(start, record[x])
record[x] = i
result = max(result, i - start)
return result | CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR RETURN VAR |
Given a string, find the length of the longest substring without repeating characters.
Examples:
Given "abcabcbb", the answer is "abc", which the length is 3.
Given "bbbbb", the answer is "b", with the length of 1.
Given "pwwkew", the answer is "wke", with the length of 3. Note that the answer must be a substring, ... | class Solution:
def lengthOfLongestSubstring(self, s):
idx = i = 0
record = set()
count = 0
maxcount = 0
while i < len(s):
if s[i] in record:
record.remove(s[idx])
count -= 1
idx += 1
else:
... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR RETURN VAR |
Given a string, find the length of the longest substring without repeating characters.
Examples:
Given "abcabcbb", the answer is "abc", which the length is 3.
Given "bbbbb", the answer is "b", with the length of 1.
Given "pwwkew", the answer is "wke", with the length of 3. Note that the answer must be a substring, ... | class Solution:
def lengthOfLongestSubstring(self, s):
dic = {}
start = max_len = 0
for i, c in enumerate(s):
if c in dic and start <= dic[c]:
start = dic[c] + 1
else:
max_len = max(max_len, i - start + 1)
dic[c] = i
... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR RETURN VAR |
Given a string, find the length of the longest substring without repeating characters.
Examples:
Given "abcabcbb", the answer is "abc", which the length is 3.
Given "bbbbb", the answer is "b", with the length of 1.
Given "pwwkew", the answer is "wke", with the length of 3. Note that the answer must be a substring, ... | class Solution:
def lengthOfLongestSubstring(self, s):
char_dict = {}
longest_run = 0
current_run = 0
distance = 2
for i, char in enumerate(s):
if char in char_dict:
distance = i - char_dict[char]
if distance <= current_run:
... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR VAR RETURN VAR |
Given a string, find the length of the longest substring without repeating characters.
Examples:
Given "abcabcbb", the answer is "abc", which the length is 3.
Given "bbbbb", the answer is "b", with the length of 1.
Given "pwwkew", the answer is "wke", with the length of 3. Note that the answer must be a substring, ... | class Solution:
def lengthOfLongestSubstring(self, s):
helper_dict = {}
longest_start = 0
longest_end = -1
current_start = 0
for char_index, char in enumerate(s):
if char not in helper_dict or helper_dict[char] < current_start:
helper_dict[char] =... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR IF BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN BIN_OP BIN_OP VAR VAR NUMBER |
Given a string, find the length of the longest substring without repeating characters.
Examples:
Given "abcabcbb", the answer is "abc", which the length is 3.
Given "bbbbb", the answer is "b", with the length of 1.
Given "pwwkew", the answer is "wke", with the length of 3. Note that the answer must be a substring, ... | class Solution:
def lengthOfLongestSubstring(self, s):
start = 0
end = 0
seen_set = set()
longest_substring = ""
while end < len(s):
end += 1
currentelem = s[end - 1]
if currentelem not in seen_set:
seen_set.add(currentelem... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING WHILE VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR IF BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR WHILE VAR BIN_OP VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL... |
Utkarsh has recently started taking English-language classes to improve his reading and writing skills. However, he is still struggling to learn English. His teacher gave him the following problem to improve his vowel-identification skills:
There is a string S of length N consisting of lowercase English letters only. ... | T = int(input())
for vinay in range(T):
N = int(input())
S = input()
count = 0
ans1 = ""
ans2 = ""
for c in range(N - 1, -1, -1):
if count % 2 == 0:
ans2 = S[c] + ans2
else:
ans1 += S[c]
if S[c] == "a" or S[c] == "e" or S[c] == "i" or S[c] == "o" o... | 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 ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR IF VAR VAR ST... |
Utkarsh has recently started taking English-language classes to improve his reading and writing skills. However, he is still struggling to learn English. His teacher gave him the following problem to improve his vowel-identification skills:
There is a string S of length N consisting of lowercase English letters only. ... | kt = int(input())
while kt:
p = int(input())
s = input()
ans = []
for i in s:
ans.append(i)
h = p - 1
while h >= 0 and s[h] not in ["a", "e", "i", "o", "u"]:
h -= 1
h -= 1
st = 0
end = h
dirl = 0
ind = h
while ind >= 0:
temp = []
while ind ... | 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 VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR LIST STRING STRING STRING STRING STRING VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN ... |
Utkarsh has recently started taking English-language classes to improve his reading and writing skills. However, he is still struggling to learn English. His teacher gave him the following problem to improve his vowel-identification skills:
There is a string S of length N consisting of lowercase English letters only. ... | t = int(input())
for i in range(t):
n = int(input())
s = input()
l = ["a", "e", "i", "o", "u"]
a = []
temp = ""
cnt = 0
for i in range(len(s)):
if i != 0 and s[i] in l:
a.append(temp)
temp = ""
cnt += 1
temp += s[i]
ans = []
if cnt ... | 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 LIST STRING STRING STRING STRING STRING ASSIGN VAR LIST ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR... |
Utkarsh has recently started taking English-language classes to improve his reading and writing skills. However, he is still struggling to learn English. His teacher gave him the following problem to improve his vowel-identification skills:
There is a string S of length N consisting of lowercase English letters only. ... | t = int(input())
for _ in range(t):
n = int(input())
s = input()[::-1]
left = []
right = []
back = True
for c in s:
if back:
right.append(c)
else:
left.append(c)
if c in "aeuio":
back = not back
right.reverse()
print("".join(lef... | 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 NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FU... |
Utkarsh has recently started taking English-language classes to improve his reading and writing skills. However, he is still struggling to learn English. His teacher gave him the following problem to improve his vowel-identification skills:
There is a string S of length N consisting of lowercase English letters only. ... | for _ in range(0, int(input())):
n = int(input())
s = input()
ans = [" "] * n
vowel = 0
left, right = 0, n - 1
for i in range(n - 1, -1, -1):
if vowel & 1 == 1:
ans[left] = s[i]
left += 1
else:
ans[right] = s[i]
right -= 1
v... | FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR VA... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.