description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Given an array of N elements and L and R, print the number of sub-arrays such that the value of the maximum array element in that subarray is at least L and at most R. Example 1: Input : Arr[] = {2, 0, 11, 3, 0} L = 1 and R = 10 Output : 4 Explanation: The sub-arrays {2}, {2, 0}, {3} and {3, 0} have maximum in range 1-...
class Solution: def countSubarrays(self, a, n, L, R): res = 0 N = n A = a start = 0 count = 0 for i in range(N): if A[i] >= L and A[i] <= R: count = i - start + 1 res = res + i - start + 1 elif A[i] < L: ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN...
Given an array of N elements and L and R, print the number of sub-arrays such that the value of the maximum array element in that subarray is at least L and at most R. Example 1: Input : Arr[] = {2, 0, 11, 3, 0} L = 1 and R = 10 Output : 4 Explanation: The sub-arrays {2}, {2, 0}, {3} and {3, 0} have maximum in range 1-...
class Solution: def countSubarrays(self, nums, a, left, right): def count(bound): ans = cnt = 0 for x in nums: if x <= bound: cnt = cnt + 1 else: cnt = 0 ans += cnt return ans ...
CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR VAR RETURN VAR RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER
Given a binary array arr of size N and an integer target, return the number of non-empty subarrays with a sum equal to target. Note : A subarray is the contiguous part of the array. Example 1: Input: N = 5 target = 2 arr[ ] = {1, 0, 1, 0, 1} Output: 4 Explanation: The 4 subarrays are: {1, 0, 1, _, _} {1, 0, 1, 0, _} {_...
class Solution: def numberOfSubarrays(self, nums, n, k): s = 0 p = 0 h = {(0): 1} for j in nums: p += j if p - k in h: s += h[p - k] if p in h: h[p] += 1 else: h[p] = 1 return s
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT NUMBER NUMBER FOR VAR VAR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER RETURN VAR
Given a binary array arr of size N and an integer target, return the number of non-empty subarrays with a sum equal to target. Note : A subarray is the contiguous part of the array. Example 1: Input: N = 5 target = 2 arr[ ] = {1, 0, 1, 0, 1} Output: 4 Explanation: The 4 subarrays are: {1, 0, 1, _, _} {1, 0, 1, 0, _} {_...
class Solution: def numberOfSubarrays(self, arr, N, target): d = dict() ans = 0 temp = 0 for i in range(len(arr)): temp += arr[i] if temp == target: ans += 1 if temp - target in d: ans += d[temp - target] ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER RETURN VAR
Given a binary array arr of size N and an integer target, return the number of non-empty subarrays with a sum equal to target. Note : A subarray is the contiguous part of the array. Example 1: Input: N = 5 target = 2 arr[ ] = {1, 0, 1, 0, 1} Output: 4 Explanation: The 4 subarrays are: {1, 0, 1, _, _} {1, 0, 1, 0, _} {_...
class Solution: def numberOfSubarrays(self, Arr, N, k): count = 0 sums = {(0): 1} sum = 0 for num in Arr: sum += num rem = sum - k if rem in sums: count += sums[rem] sums[sum] = sums.get(sum, 0) + 1 return count
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER RETURN VAR
Given a binary array arr of size N and an integer target, return the number of non-empty subarrays with a sum equal to target. Note : A subarray is the contiguous part of the array. Example 1: Input: N = 5 target = 2 arr[ ] = {1, 0, 1, 0, 1} Output: 4 Explanation: The 4 subarrays are: {1, 0, 1, _, _} {1, 0, 1, 0, _} {_...
class Solution: def numberOfSubarrays(self, arr, N, target): def atMostSub(S): if S < 0: return 0 res = 0 i = 0 for j in range(N): S -= arr[j] while S < 0: S += arr[i] i ...
CLASS_DEF FUNC_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR WHILE VAR NUMBER VAR VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER
Given a binary array arr of size N and an integer target, return the number of non-empty subarrays with a sum equal to target. Note : A subarray is the contiguous part of the array. Example 1: Input: N = 5 target = 2 arr[ ] = {1, 0, 1, 0, 1} Output: 4 Explanation: The 4 subarrays are: {1, 0, 1, _, _} {1, 0, 1, 0, _} {_...
class Solution: def numberOfSubarrays(self, arr, N, target): return self.atMost(arr, N, target) - self.atMost(arr, N, target - 1) def atMost(self, arr, N, target): i = 0 ans = 0 count = 0 for j in range(N): count = count + arr[j] while count > ta...
CLASS_DEF FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR
Given a binary array arr of size N and an integer target, return the number of non-empty subarrays with a sum equal to target. Note : A subarray is the contiguous part of the array. Example 1: Input: N = 5 target = 2 arr[ ] = {1, 0, 1, 0, 1} Output: 4 Explanation: The 4 subarrays are: {1, 0, 1, _, _} {1, 0, 1, 0, _} {_...
class Solution: def numberOfSubarrays(self, arr, N, target): m = {} su = count = 0 for i in range(N): su += arr[i] if su == target: count += 1 if su - target in m.keys(): count += m[su - target] if su not in m.k...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR IF VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER RETURN VAR
Given a binary array arr of size N and an integer target, return the number of non-empty subarrays with a sum equal to target. Note : A subarray is the contiguous part of the array. Example 1: Input: N = 5 target = 2 arr[ ] = {1, 0, 1, 0, 1} Output: 4 Explanation: The 4 subarrays are: {1, 0, 1, _, _} {1, 0, 1, 0, _} {_...
class Solution: def numberOfSubarrays(self, arr, N, target): sums, s, count = {(0): 1}, 0, 0 for i in arr: s += i if s - target in sums: count += sums[s - target] sums[s] = sums.get(s, 0) + 1 return count
CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR DICT NUMBER NUMBER NUMBER NUMBER FOR VAR VAR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER RETURN VAR
Given a binary array arr of size N and an integer target, return the number of non-empty subarrays with a sum equal to target. Note : A subarray is the contiguous part of the array. Example 1: Input: N = 5 target = 2 arr[ ] = {1, 0, 1, 0, 1} Output: 4 Explanation: The 4 subarrays are: {1, 0, 1, _, _} {1, 0, 1, 0, _} {_...
class Solution: def numberOfSubarrays(self, A, n, S): psum = {(0): 1} curr_sum = 0 res = 0 for i in A: curr_sum += i if curr_sum - S in psum.keys(): res += psum.get(curr_sum - S) psum[curr_sum] = psum.get(curr_sum, 0) + 1 r...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF BIN_OP VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER RETURN VAR
Given a binary array arr of size N and an integer target, return the number of non-empty subarrays with a sum equal to target. Note : A subarray is the contiguous part of the array. Example 1: Input: N = 5 target = 2 arr[ ] = {1, 0, 1, 0, 1} Output: 4 Explanation: The 4 subarrays are: {1, 0, 1, _, _} {1, 0, 1, 0, _} {_...
class Solution: def numberOfSubarrays(self, arr, N, target): return self.helper(arr, target) - self.helper(arr, target - 1) def helper(self, arr, target): left = 0 su = 0 n = len(arr) ans = 0 for right in range(0, n): su += arr[right] whi...
CLASS_DEF FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR WHILE VAR VAR VAR VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR
Given a binary array arr of size N and an integer target, return the number of non-empty subarrays with a sum equal to target. Note : A subarray is the contiguous part of the array. Example 1: Input: N = 5 target = 2 arr[ ] = {1, 0, 1, 0, 1} Output: 4 Explanation: The 4 subarrays are: {1, 0, 1, _, _} {1, 0, 1, 0, _} {_...
class Solution: def numberOfSubarrays(self, arr, N, target): summa1 = 0 summa2 = 0 count = 0 i = 0 j = 0 for item in arr: while i < N and summa1 < target: summa1 += arr[i] i += 1 while j < N and (summa2 < target...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR WHILE VAR VAR VAR VAR VAR VAR VAR VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER IF VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR VAR RETURN VAR
Given a binary array arr of size N and an integer target, return the number of non-empty subarrays with a sum equal to target. Note : A subarray is the contiguous part of the array. Example 1: Input: N = 5 target = 2 arr[ ] = {1, 0, 1, 0, 1} Output: 4 Explanation: The 4 subarrays are: {1, 0, 1, _, _} {1, 0, 1, 0, _} {_...
class Solution: def numberOfSubarrays(self, arr, N, target): count = 0 left = 0 right = 0 suma = 0 while left <= right and right < N: suma += arr[right] if suma > target: suma = suma - arr[right] right -= 1 ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER VA...
Given a binary array arr of size N and an integer target, return the number of non-empty subarrays with a sum equal to target. Note : A subarray is the contiguous part of the array. Example 1: Input: N = 5 target = 2 arr[ ] = {1, 0, 1, 0, 1} Output: 4 Explanation: The 4 subarrays are: {1, 0, 1, _, _} {1, 0, 1, 0, _} {_...
class Solution: def numberOfSubarrays(self, arr, N, target): dict = {(0): 1} s = 0 c = 0 for i in range(N): s += arr[i] ch = s - target if ch in dict: c += dict[ch] if s not in dict: dict[s] = 1 ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER RETURN VAR
Given a binary array arr of size N and an integer target, return the number of non-empty subarrays with a sum equal to target. Note : A subarray is the contiguous part of the array. Example 1: Input: N = 5 target = 2 arr[ ] = {1, 0, 1, 0, 1} Output: 4 Explanation: The 4 subarrays are: {1, 0, 1, _, _} {1, 0, 1, 0, _} {_...
class Solution: def numberOfSubarrays(self, arr, N, target): sum = count = 0 res = dict() res[0] = 1 for i in arr: sum += i if sum in res: res[sum] += 1 else: res[sum] = 1 if sum - target in res: ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER NUMBER FOR VAR VAR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR RETURN VAR
Given a binary array arr of size N and an integer target, return the number of non-empty subarrays with a sum equal to target. Note : A subarray is the contiguous part of the array. Example 1: Input: N = 5 target = 2 arr[ ] = {1, 0, 1, 0, 1} Output: 4 Explanation: The 4 subarrays are: {1, 0, 1, _, _} {1, 0, 1, 0, _} {_...
class Solution: def numberOfSubarrays(self, nums, N, goal): count = 0 window_sum = 0 window_start = 0 sum_dict = {(0): 1} for window_end in range(len(nums)): window_sum += nums[window_end] if window_sum - goal in sum_dict: count += sum...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER RETURN VAR
Given a binary array arr of size N and an integer target, return the number of non-empty subarrays with a sum equal to target. Note : A subarray is the contiguous part of the array. Example 1: Input: N = 5 target = 2 arr[ ] = {1, 0, 1, 0, 1} Output: 4 Explanation: The 4 subarrays are: {1, 0, 1, _, _} {1, 0, 1, 0, _} {_...
class Solution: def numberOfSubarrays(self, arr, N, target): return self.sumAtMost(arr, N, target) - self.sumAtMost(arr, N, target - 1) def sumAtMost(self, arr, N, target): i, j, ans = 0, 0, 0 state = 0 while j < N: state += arr[j] while state > target: ...
CLASS_DEF FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR WHILE VAR VAR VAR VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER RETURN VAR
Given a binary array arr of size N and an integer target, return the number of non-empty subarrays with a sum equal to target. Note : A subarray is the contiguous part of the array. Example 1: Input: N = 5 target = 2 arr[ ] = {1, 0, 1, 0, 1} Output: 4 Explanation: The 4 subarrays are: {1, 0, 1, _, _} {1, 0, 1, 0, _} {_...
class Solution: def numberOfSubarrays(self, arr, n, target): ans = 0 j = 0 cnt = 0 temp = 0 for i in range(n): cnt += arr[i] if cnt == target: temp = 0 while cnt == target and j <= i: temp += 1 ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR VAR RETURN VAR
Given a binary array arr of size N and an integer target, return the number of non-empty subarrays with a sum equal to target. Note : A subarray is the contiguous part of the array. Example 1: Input: N = 5 target = 2 arr[ ] = {1, 0, 1, 0, 1} Output: 4 Explanation: The 4 subarrays are: {1, 0, 1, _, _} {1, 0, 1, 0, _} {_...
class Solution: def numberOfSubarrays(self, nums, N, goal): sum = 0 count_sum = {} count = 0 for r in range(len(nums)): sum += nums[r] if sum == goal: count += 1 if count_sum.get(sum - goal, 0): count += count_sum[s...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER RETURN VAR
Given a binary array arr of size N and an integer target, return the number of non-empty subarrays with a sum equal to target. Note : A subarray is the contiguous part of the array. Example 1: Input: N = 5 target = 2 arr[ ] = {1, 0, 1, 0, 1} Output: 4 Explanation: The 4 subarrays are: {1, 0, 1, _, _} {1, 0, 1, 0, _} {_...
class Solution: def numberOfSubarrays(self, nums, N, goal): mapi = [0] * (N + 1) sum_ = 0 mapi[0] = 1 result = 0 for num in nums: sum_ += num if sum_ - goal >= 0: result += mapi[sum_ - goal] mapi[sum_] += 1 return r...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR VAR VAR VAR NUMBER RETURN VAR
Given a binary array arr of size N and an integer target, return the number of non-empty subarrays with a sum equal to target. Note : A subarray is the contiguous part of the array. Example 1: Input: N = 5 target = 2 arr[ ] = {1, 0, 1, 0, 1} Output: 4 Explanation: The 4 subarrays are: {1, 0, 1, _, _} {1, 0, 1, 0, _} {_...
class Solution: def numberOfSubarrays(self, A, N, S): l = count = res = s = 0 for r, i in enumerate(A): s += i if i == 1: count = 0 while l <= r and s >= S: if s == S: count += 1 s -= A[l] ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR VAR RETURN VAR
Given a binary array arr of size N and an integer target, return the number of non-empty subarrays with a sum equal to target. Note : A subarray is the contiguous part of the array. Example 1: Input: N = 5 target = 2 arr[ ] = {1, 0, 1, 0, 1} Output: 4 Explanation: The 4 subarrays are: {1, 0, 1, _, _} {1, 0, 1, 0, _} {_...
class Solution: def numberOfSubarrays(self, arr, N, target): d = {} sm = 0 ans = 0 d[0] = 1 for i in range(N): sm += arr[i] ans += d.get(sm - target, 0) if d.get(sm, -4) == -4: d[sm] = 1 else: d[...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR VAR NUMBER RETURN VAR
Given a binary array arr of size N and an integer target, return the number of non-empty subarrays with a sum equal to target. Note : A subarray is the contiguous part of the array. Example 1: Input: N = 5 target = 2 arr[ ] = {1, 0, 1, 0, 1} Output: 4 Explanation: The 4 subarrays are: {1, 0, 1, _, _} {1, 0, 1, 0, _} {_...
class Solution: def numberOfSubarrays(self, arr, N, target): count = 0 i, j = 0, 0 sum_ = 0 while j < N: sum_ += arr[j] if sum_ < target: j += 1 elif sum_ == target: count += 1 start = i ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR WHILE VAR VAR ...
Given a binary array arr of size N and an integer target, return the number of non-empty subarrays with a sum equal to target. Note : A subarray is the contiguous part of the array. Example 1: Input: N = 5 target = 2 arr[ ] = {1, 0, 1, 0, 1} Output: 4 Explanation: The 4 subarrays are: {1, 0, 1, _, _} {1, 0, 1, 0, _} {_...
class Solution: def atmost(self, arr, target): if target < 0: return 0 cs = 0 s = 0 res = 0 for i in range(len(arr)): cs = cs + arr[i] while cs > target: cs = cs - arr[s] s = s + 1 res = res + i ...
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER RETURN VAR FUNC_DEF RETUR...
Given a binary array arr of size N and an integer target, return the number of non-empty subarrays with a sum equal to target. Note : A subarray is the contiguous part of the array. Example 1: Input: N = 5 target = 2 arr[ ] = {1, 0, 1, 0, 1} Output: 4 Explanation: The 4 subarrays are: {1, 0, 1, _, _} {1, 0, 1, 0, _} {_...
class Solution: def numberOfSubarrays(self, arr, N, target): k = {} i = 0 c = 0 s = 0 while i < len(arr): s += arr[i] if s == target: c += 1 if s - target in k: c += k[s - target] if s not in k: ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER RETURN VAR
Given a binary array arr of size N and an integer target, return the number of non-empty subarrays with a sum equal to target. Note : A subarray is the contiguous part of the array. Example 1: Input: N = 5 target = 2 arr[ ] = {1, 0, 1, 0, 1} Output: 4 Explanation: The 4 subarrays are: {1, 0, 1, _, _} {1, 0, 1, 0, _} {_...
class Solution: def numberOfSubarrays(self, arr, N, target): sum1 = 0 j = 0 d = {} count = 0 while j < N: sum1 = sum1 + arr[j] if sum1 == target: count = count + 1 if sum1 - target in d: count = count + d[su...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN ...
Given a binary array arr of size N and an integer target, return the number of non-empty subarrays with a sum equal to target. Note : A subarray is the contiguous part of the array. Example 1: Input: N = 5 target = 2 arr[ ] = {1, 0, 1, 0, 1} Output: 4 Explanation: The 4 subarrays are: {1, 0, 1, _, _} {1, 0, 1, 0, _} {_...
class Solution: def numberOfSubarrays(self, nums, N, goal): n = len(nums) c = {} c[0] = 1 total = 0 res = 0 for i in range(n): total += nums[i] if total - goal in c: res += c[total - goal] if total in c: ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER RETURN VAR
Given a binary array arr of size N and an integer target, return the number of non-empty subarrays with a sum equal to target. Note : A subarray is the contiguous part of the array. Example 1: Input: N = 5 target = 2 arr[ ] = {1, 0, 1, 0, 1} Output: 4 Explanation: The 4 subarrays are: {1, 0, 1, _, _} {1, 0, 1, 0, _} {_...
class Solution: def numberOfSubarrays(self, arr, N, target): s = 0 c = 0 di = {} for i in range(len(arr)): s += arr[i] if s == target: c += 1 if s - target in di: c += di[s - target] if s not in di: ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER RETURN VAR
Given a binary array arr of size N and an integer target, return the number of non-empty subarrays with a sum equal to target. Note : A subarray is the contiguous part of the array. Example 1: Input: N = 5 target = 2 arr[ ] = {1, 0, 1, 0, 1} Output: 4 Explanation: The 4 subarrays are: {1, 0, 1, _, _} {1, 0, 1, 0, _} {_...
class Solution: def numberOfSubarrays(self, arr, N, target): ans = 0 s, e, sum = 0, 0, 0 while e < N: if sum < target: sum += arr[e] if sum == target: ans += 1 e += 1 elif arr[e] == 1: ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER WHILE VAR VAR IF VAR VAR VAR VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER WHILE VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR NUMBER VAR NUMBER V...
Given a linked list of N nodes such that it may contain a loop. A loop here means that the last node of the link list is connected to the node at position X(1-based index). If the link list does not have any loop, X=0. Remove the loop from the linked list, if it is present, i.e. unlink the last node which is forming th...
class Solution: def removeLoop(self, head): d = {} d[head] = 1 while head.next != None: if head.next in d: head.next = None break else: d[head.next] = 1 head = head.next
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR VAR NUMBER WHILE VAR NONE IF VAR VAR ASSIGN VAR NONE ASSIGN VAR VAR NUMBER ASSIGN VAR VAR
Given a linked list of N nodes such that it may contain a loop. A loop here means that the last node of the link list is connected to the node at position X(1-based index). If the link list does not have any loop, X=0. Remove the loop from the linked list, if it is present, i.e. unlink the last node which is forming th...
class Solution: def removeLoop(self, head): fast = head slow = head while fast and fast.next: fast = fast.next.next slow = slow.next if fast == slow: break if fast == None or fast.next == None: return size = 0 ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR IF VAR NONE VAR NONE RETURN ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ...
Given a linked list of N nodes such that it may contain a loop. A loop here means that the last node of the link list is connected to the node at position X(1-based index). If the link list does not have any loop, X=0. Remove the loop from the linked list, if it is present, i.e. unlink the last node which is forming th...
class Solution: def removeLoop(self, head): curr = head while curr.next != None and curr.next.data != -1: curr.data = -1 curr = curr.next curr.next = None return head
CLASS_DEF FUNC_DEF ASSIGN VAR VAR WHILE VAR NONE VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NONE RETURN VAR
Given a linked list of N nodes such that it may contain a loop. A loop here means that the last node of the link list is connected to the node at position X(1-based index). If the link list does not have any loop, X=0. Remove the loop from the linked list, if it is present, i.e. unlink the last node which is forming th...
class Solution: def removeLoop(self, head): if head.next == None: return t = head t.data = -1 while t.next != None: if t.next.data == -1: t.next = None break elif t.next == None: return t...
CLASS_DEF FUNC_DEF IF VAR NONE RETURN ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NONE IF VAR NUMBER ASSIGN VAR NONE IF VAR NONE RETURN ASSIGN VAR VAR ASSIGN VAR NUMBER
Given a linked list of N nodes such that it may contain a loop. A loop here means that the last node of the link list is connected to the node at position X(1-based index). If the link list does not have any loop, X=0. Remove the loop from the linked list, if it is present, i.e. unlink the last node which is forming th...
class Solution: def removeLoop(self, head): slow = head fast = head loopExists = False while fast and fast.next: slow = slow.next fast = fast.next.next if slow == fast: loopExists = True break if loopExists:...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR VAR ...
Given a linked list of N nodes such that it may contain a loop. A loop here means that the last node of the link list is connected to the node at position X(1-based index). If the link list does not have any loop, X=0. Remove the loop from the linked list, if it is present, i.e. unlink the last node which is forming th...
class Solution: def removeLoop(self, head): slowPtr = fastPtr = head while fastPtr and fastPtr.next: prev = slowPtr slowPtr = slowPtr.next fastPtr = fastPtr.next.next if slowPtr == fastPtr: startPtr = head while startPt...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR WHILE VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NONE
Given a linked list of N nodes such that it may contain a loop. A loop here means that the last node of the link list is connected to the node at position X(1-based index). If the link list does not have any loop, X=0. Remove the loop from the linked list, if it is present, i.e. unlink the last node which is forming th...
class Solution: def removeLoop(self, head): if head is None or head.next is None: return slow = head fast = head while fast is not None and fast.next is not None: slow = slow.next fast = fast.next.next if slow == fast: ...
CLASS_DEF FUNC_DEF IF VAR NONE VAR NONE RETURN ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR NONE VAR NONE ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR IF VAR VAR RETURN ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR WHILE VAR VAR AS...
Given a linked list of N nodes such that it may contain a loop. A loop here means that the last node of the link list is connected to the node at position X(1-based index). If the link list does not have any loop, X=0. Remove the loop from the linked list, if it is present, i.e. unlink the last node which is forming th...
class Solution: def removeLoop(self, head): if not head and not head.next: return 1 hashMap = {} prev = None current = head while current: if current in hashMap: prev.next = None return hashMap[current] = Tr...
CLASS_DEF FUNC_DEF IF VAR VAR RETURN NUMBER ASSIGN VAR DICT ASSIGN VAR NONE ASSIGN VAR VAR WHILE VAR IF VAR VAR ASSIGN VAR NONE RETURN ASSIGN VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR RETURN
Given a linked list of N nodes such that it may contain a loop. A loop here means that the last node of the link list is connected to the node at position X(1-based index). If the link list does not have any loop, X=0. Remove the loop from the linked list, if it is present, i.e. unlink the last node which is forming th...
class Solution: def removeLoop(self, head): seen = set() curr = head startOfLoop = None while True: if not curr.next: return if curr in seen: startOfLoop = curr break seen.add(curr) curr ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NONE WHILE NUMBER IF VAR RETURN IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE NUMBER IF VAR VAR ASSIGN VAR NONE ASSIGN VAR VAR RETURN
Given a linked list of N nodes such that it may contain a loop. A loop here means that the last node of the link list is connected to the node at position X(1-based index). If the link list does not have any loop, X=0. Remove the loop from the linked list, if it is present, i.e. unlink the last node which is forming th...
class Solution: def detectLoop(self, head): slow_p = head fast_p = head while True: if slow_p is None or fast_p is None: return False slow_p = slow_p.next if fast_p.next is None: return False fast_p = fast_p.nex...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR WHILE NUMBER IF VAR NONE VAR NONE RETURN NUMBER ASSIGN VAR VAR IF VAR NONE RETURN NUMBER ASSIGN VAR VAR IF VAR VAR RETURN VAR RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NONE ASSIGN VAR VAR ASSIGN VAR VAR IF VAR IF VAR VAR WHILE VAR VAR ASSIGN VAR VAR ...
Given a linked list of N nodes such that it may contain a loop. A loop here means that the last node of the link list is connected to the node at position X(1-based index). If the link list does not have any loop, X=0. Remove the loop from the linked list, if it is present, i.e. unlink the last node which is forming th...
class Solution: def removeLoop(self, head): meet = self.detectLoop(head) if meet is None: return head if meet == head: curr = head while curr.next != head: curr = curr.next curr.next = None return head curr ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NONE RETURN VAR IF VAR VAR ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR VAR ASSIGN VAR NONE RETURN VAR ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NONE RETURN VAR FUNC_DEF ASSIGN VAR VAR VAR VAR WHILE VAR NONE VAR NONE ASSIGN VAR...
Given a linked list of N nodes such that it may contain a loop. A loop here means that the last node of the link list is connected to the node at position X(1-based index). If the link list does not have any loop, X=0. Remove the loop from the linked list, if it is present, i.e. unlink the last node which is forming th...
class Solution: def isLoop(self, head): slow = head fast = head while fast is not None and fast.next is not None: fast = fast.next.next slow = slow.next if fast == slow: return slow return None def removeLoop(self, head): ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR NONE VAR NONE ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR RETURN VAR RETURN NONE FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NONE RETURN ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NONE IF VAR VAR WHILE VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR ...
Given a linked list of N nodes such that it may contain a loop. A loop here means that the last node of the link list is connected to the node at position X(1-based index). If the link list does not have any loop, X=0. Remove the loop from the linked list, if it is present, i.e. unlink the last node which is forming th...
class Solution: def removeLoop(self, head): mp = set() prev = None while head is not None: if head in mp: prev.next = None return True else: mp.add(head) prev = head head = head.next ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NONE WHILE VAR NONE IF VAR VAR ASSIGN VAR NONE RETURN NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN NUMBER
Given a linked list of N nodes such that it may contain a loop. A loop here means that the last node of the link list is connected to the node at position X(1-based index). If the link list does not have any loop, X=0. Remove the loop from the linked list, if it is present, i.e. unlink the last node which is forming th...
class Solution: def removeLoop(self, head): d = set() prev = None cur = head while cur: if cur in d: prev.next = None return else: d.add(cur) prev = cur cur = cur.next
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NONE ASSIGN VAR VAR WHILE VAR IF VAR VAR ASSIGN VAR NONE RETURN EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR
Given a linked list of N nodes such that it may contain a loop. A loop here means that the last node of the link list is connected to the node at position X(1-based index). If the link list does not have any loop, X=0. Remove the loop from the linked list, if it is present, i.e. unlink the last node which is forming th...
class Solution: def removeLoop(self, head): s = head f = head while f.next != None or f.next.next != None: s = s.next f = f.next.next if f.next == None: return if f.next.next == None: return if s == ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR NONE VAR NONE ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NONE RETURN IF VAR NONE RETURN IF VAR VAR IF VAR NONE VAR NONE RETURN ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR WHILE VAR VAR ASSIGN VAR VAR ASSIGN VAR NONE
Given a linked list of N nodes such that it may contain a loop. A loop here means that the last node of the link list is connected to the node at position X(1-based index). If the link list does not have any loop, X=0. Remove the loop from the linked list, if it is present, i.e. unlink the last node which is forming th...
class Solution: def removeLoop(self, head): fast = head.next slow = head while fast != slow: if fast is None or fast.next is None: return fast = fast.next.next slow = slow.next length = 1 fast = fast.next while fast...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR VAR IF VAR NONE VAR NONE RETURN ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR VAR ASSIGN VAR V...
Given a linked list of N nodes such that it may contain a loop. A loop here means that the last node of the link list is connected to the node at position X(1-based index). If the link list does not have any loop, X=0. Remove the loop from the linked list, if it is present, i.e. unlink the last node which is forming th...
class Solution: def removeLoop(self, head): if head == None: return None if head.next == None: return head slow = head fast = head.next prev = None l = set() while slow and fast and fast.next: if slow in l: ...
CLASS_DEF FUNC_DEF IF VAR NONE RETURN NONE IF VAR NONE RETURN VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NONE ASSIGN VAR FUNC_CALL VAR WHILE VAR VAR VAR IF VAR VAR ASSIGN VAR NONE RETURN VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR
Given a linked list of N nodes such that it may contain a loop. A loop here means that the last node of the link list is connected to the node at position X(1-based index). If the link list does not have any loop, X=0. Remove the loop from the linked list, if it is present, i.e. unlink the last node which is forming th...
class Solution: def loop(self, head): slow = head fast = head while fast and fast.next: slow = slow.next fast = fast.next.next if slow == fast: return slow return None def removeLoop(self, head): flag = self.loop(head)...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR RETURN VAR RETURN NONE FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NONE RETURN VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR ...
Given a linked list of N nodes such that it may contain a loop. A loop here means that the last node of the link list is connected to the node at position X(1-based index). If the link list does not have any loop, X=0. Remove the loop from the linked list, if it is present, i.e. unlink the last node which is forming th...
class Solution: def removeLoop(self, head): mp = {} tmp = head while head: mp[head] = True if head.next in mp: head.next = None break head = head.next return tmp
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR VAR WHILE VAR ASSIGN VAR VAR NUMBER IF VAR VAR ASSIGN VAR NONE ASSIGN VAR VAR RETURN VAR
Given a linked list of N nodes such that it may contain a loop. A loop here means that the last node of the link list is connected to the node at position X(1-based index). If the link list does not have any loop, X=0. Remove the loop from the linked list, if it is present, i.e. unlink the last node which is forming th...
def find(head): fast = head slow = head while fast != None and fast.next != None: fast = fast.next.next slow = slow.next if slow == fast: return slow return 1 def get(head): inter = find(head) if inter == 1: return 1 slow = head while slow !=...
FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR NONE VAR NONE ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR RETURN VAR RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR ...
Given a linked list of N nodes such that it may contain a loop. A loop here means that the last node of the link list is connected to the node at position X(1-based index). If the link list does not have any loop, X=0. Remove the loop from the linked list, if it is present, i.e. unlink the last node which is forming th...
class Solution: def removeLoop(self, head): l = set() cur = head while cur: if cur.next in l: cur.next = None l.add(cur) cur = cur.next
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR WHILE VAR IF VAR VAR ASSIGN VAR NONE EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR
Given a linked list of N nodes such that it may contain a loop. A loop here means that the last node of the link list is connected to the node at position X(1-based index). If the link list does not have any loop, X=0. Remove the loop from the linked list, if it is present, i.e. unlink the last node which is forming th...
class Solution: def removeLoop(self, head): slow = head fast = head t = None flag = False while fast.next != None and fast.next.next != None: fast = fast.next.next slow = slow.next if slow == fast: flag = True ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NONE ASSIGN VAR NUMBER WHILE VAR NONE VAR NONE ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER RETURN VAR IF VAR VAR WHILE VAR VAR ASSIGN VAR VAR ASSIGN VAR NONE RETURN VAR ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASS...
Given a linked list of N nodes such that it may contain a loop. A loop here means that the last node of the link list is connected to the node at position X(1-based index). If the link list does not have any loop, X=0. Remove the loop from the linked list, if it is present, i.e. unlink the last node which is forming th...
class Solution: def removeLoop(self, head): temp1 = temp2 = head prev = None while temp1 != None and temp2 != None and temp2.next != None: temp1 = temp1.next prev = temp2.next temp2 = temp2.next.next if temp1 == temp2: break ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR NONE WHILE VAR NONE VAR NONE VAR NONE ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR NONE WHILE VAR NONE VAR NONE ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR NONE
Given a linked list of N nodes such that it may contain a loop. A loop here means that the last node of the link list is connected to the node at position X(1-based index). If the link list does not have any loop, X=0. Remove the loop from the linked list, if it is present, i.e. unlink the last node which is forming th...
class Solution: def removeLoop(self, head): Freq = {} total_nodes = 0 pos = 0 prev = None temp = head while temp != None: if temp not in Freq: pos += 1 Freq[temp] = pos total_nodes += 1 else: ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NONE ASSIGN VAR VAR WHILE VAR NONE IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NONE
Given a linked list of N nodes such that it may contain a loop. A loop here means that the last node of the link list is connected to the node at position X(1-based index). If the link list does not have any loop, X=0. Remove the loop from the linked list, if it is present, i.e. unlink the last node which is forming th...
class Solution: def removeLoop(self, head): slow = head fast = head loopExist = False while fast and fast.next: slow = slow.next fast = fast.next.next if slow == fast: loopExist = True break if loopExist: ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR VAR ASSIGN VAR NONE
Given a linked list of N nodes such that it may contain a loop. A loop here means that the last node of the link list is connected to the node at position X(1-based index). If the link list does not have any loop, X=0. Remove the loop from the linked list, if it is present, i.e. unlink the last node which is forming th...
class Solution: def removeLoop(self, head): slow = head while slow.next: if slow.next.data == float("inf"): slow.next = None break slow.data = float("inf") slow = slow.next
CLASS_DEF FUNC_DEF ASSIGN VAR VAR WHILE VAR IF VAR FUNC_CALL VAR STRING ASSIGN VAR NONE ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR
Given a linked list of N nodes such that it may contain a loop. A loop here means that the last node of the link list is connected to the node at position X(1-based index). If the link list does not have any loop, X=0. Remove the loop from the linked list, if it is present, i.e. unlink the last node which is forming th...
class Solution: def removeLoop(self, head): slow = head fast = head while fast and fast.next: slow = slow.next fast = fast.next.next if slow == fast: break if not fast or not fast.next: return head ptr1 = head ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR IF VAR VAR RETURN VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR VAR ASSIGN VAR NONE RETURN VAR
Given a linked list of N nodes such that it may contain a loop. A loop here means that the last node of the link list is connected to the node at position X(1-based index). If the link list does not have any loop, X=0. Remove the loop from the linked list, if it is present, i.e. unlink the last node which is forming th...
class Solution: def removeLoop(self, head): slow = head fast = head prev1 = None while slow.next and fast.next and fast.next.next: prev1 = slow slow = slow.next fast = fast.next.next if slow == fast: break if sl...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NONE WHILE VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR IF VAR VAR RETURN IF VAR VAR ASSIGN VAR NONE RETURN ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NONE
Given a linked list of N nodes such that it may contain a loop. A loop here means that the last node of the link list is connected to the node at position X(1-based index). If the link list does not have any loop, X=0. Remove the loop from the linked list, if it is present, i.e. unlink the last node which is forming th...
class Solution: def removeLoop(self, head): slow = fast = head while slow and fast and fast.next: slow = slow.next fast = fast.next.next if slow == fast: break if slow == head: while fast.next != slow: fast = fa...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR WHILE VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR IF VAR VAR WHILE VAR VAR ASSIGN VAR VAR ASSIGN VAR NONE IF VAR VAR ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NONE
Given a linked list of N nodes such that it may contain a loop. A loop here means that the last node of the link list is connected to the node at position X(1-based index). If the link list does not have any loop, X=0. Remove the loop from the linked list, if it is present, i.e. unlink the last node which is forming th...
class Solution: def removeLoop(self, head): front = head second = head while second != None: front = front.next if second.next is not None: second = second.next.next else: second = second.next if second == front...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR NONE ASSIGN VAR VAR IF VAR NONE ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR VAR ASSIGN VAR NONE RETURN RETURN
Given a linked list of N nodes such that it may contain a loop. A loop here means that the last node of the link list is connected to the node at position X(1-based index). If the link list does not have any loop, X=0. Remove the loop from the linked list, if it is present, i.e. unlink the last node which is forming th...
class Node: def __init__(self, val): self.next = None self.data = val class Solution: def removeLoop(self, head): slow, fast = head, head t = 0 while slow and fast and fast.next: slow = slow.next fast = fast.next.next if slow == fas...
CLASS_DEF FUNC_DEF ASSIGN VAR NONE ASSIGN VAR VAR CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR VAR IF VAR VAR WHILE VAR VAR ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NONE RETURN VAR
Given a linked list of N nodes such that it may contain a loop. A loop here means that the last node of the link list is connected to the node at position X(1-based index). If the link list does not have any loop, X=0. Remove the loop from the linked list, if it is present, i.e. unlink the last node which is forming th...
class Solution: def removeLoop(self, head): prev = None s = set() while head != None: if head in s: prev.next = None break s.add(head) prev = head head = head.next return head
CLASS_DEF FUNC_DEF ASSIGN VAR NONE ASSIGN VAR FUNC_CALL VAR WHILE VAR NONE IF VAR VAR ASSIGN VAR NONE EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR
Given a linked list of N nodes such that it may contain a loop. A loop here means that the last node of the link list is connected to the node at position X(1-based index). If the link list does not have any loop, X=0. Remove the loop from the linked list, if it is present, i.e. unlink the last node which is forming th...
class Solution: def removeLoop(self, head): curr = head visited_nodes = set() while curr.next is not None: if curr.next in visited_nodes: break visited_nodes.add(curr) curr = curr.next curr.next = None
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR WHILE VAR NONE IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR NONE
Given a linked list of N nodes such that it may contain a loop. A loop here means that the last node of the link list is connected to the node at position X(1-based index). If the link list does not have any loop, X=0. Remove the loop from the linked list, if it is present, i.e. unlink the last node which is forming th...
class Solution: def removeLoop(self, start): slow = start fast = start.next while fast and fast != slow: slow = slow.next fast = fast.next if fast: fast = fast.next if fast is None: return 0 slow = start ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR ASSIGN VAR VAR IF VAR NONE RETURN NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NONE
Given a linked list of N nodes such that it may contain a loop. A loop here means that the last node of the link list is connected to the node at position X(1-based index). If the link list does not have any loop, X=0. Remove the loop from the linked list, if it is present, i.e. unlink the last node which is forming th...
class Solution: def removeLoop(self, head): Freq = {} temp = head prev = None while temp != None: if temp not in Freq: Freq[temp] = 1 else: break prev = temp temp = temp.next if temp != None: ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR VAR ASSIGN VAR NONE WHILE VAR NONE IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NONE ASSIGN VAR NONE RETURN VAR RETURN VAR
Given a linked list of N nodes such that it may contain a loop. A loop here means that the last node of the link list is connected to the node at position X(1-based index). If the link list does not have any loop, X=0. Remove the loop from the linked list, if it is present, i.e. unlink the last node which is forming th...
class Solution: def removeLoop(self, head): map_ = {} curr = head while curr.next != None and curr.next not in map_: map_[curr] = True curr = curr.next curr.next = None
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR VAR WHILE VAR NONE VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NONE
Given a linked list of N nodes such that it may contain a loop. A loop here means that the last node of the link list is connected to the node at position X(1-based index). If the link list does not have any loop, X=0. Remove the loop from the linked list, if it is present, i.e. unlink the last node which is forming th...
class Solution: def removeCycle(self, slow, head): curr = head while curr: ptr = slow while ptr.next is not slow and ptr.next is not curr: ptr = ptr.next if ptr.next == curr: ptr.next = None return curr ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR WHILE VAR ASSIGN VAR VAR WHILE VAR VAR VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR NONE RETURN ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR VAR WHILE VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR RETURN VAR RETURN NONE FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR NONE VAR NONE ASSIGN...
Given a linked list of N nodes such that it may contain a loop. A loop here means that the last node of the link list is connected to the node at position X(1-based index). If the link list does not have any loop, X=0. Remove the loop from the linked list, if it is present, i.e. unlink the last node which is forming th...
class Solution: def removeLoop(self, head): if head == None: return temp1 = head temp2 = None s = set() while temp1 != None: if temp1 in s: temp2.next = None return s.add(temp1) temp2 = temp1 ...
CLASS_DEF FUNC_DEF IF VAR NONE RETURN ASSIGN VAR VAR ASSIGN VAR NONE ASSIGN VAR FUNC_CALL VAR WHILE VAR NONE IF VAR VAR ASSIGN VAR NONE RETURN EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR
Given a linked list of N nodes such that it may contain a loop. A loop here means that the last node of the link list is connected to the node at position X(1-based index). If the link list does not have any loop, X=0. Remove the loop from the linked list, if it is present, i.e. unlink the last node which is forming th...
class Solution: def removeLoop(self, head): temp = head prev = head while temp != None: if temp.data == -4: prev.next = None return prev = temp temp.data = -4 temp = temp.next
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR NONE IF VAR NUMBER ASSIGN VAR NONE RETURN ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR
Given a linked list of N nodes such that it may contain a loop. A loop here means that the last node of the link list is connected to the node at position X(1-based index). If the link list does not have any loop, X=0. Remove the loop from the linked list, if it is present, i.e. unlink the last node which is forming th...
class Solution: def removeLoop(self, head): def detect(head): slow = head fast = head while slow and fast: slow = slow.next fast = fast.next if fast: fast = fast.next if slow == fast: ...
CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR ASSIGN VAR VAR IF VAR VAR RETURN VAR RETURN NONE ASSIGN VAR FUNC_CALL VAR VAR IF VAR NONE RETURN NONE ASSIGN VAR VAR ASSIGN VAR NONE WHILE VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR VAR ASSIG...
Given a linked list of N nodes such that it may contain a loop. A loop here means that the last node of the link list is connected to the node at position X(1-based index). If the link list does not have any loop, X=0. Remove the loop from the linked list, if it is present, i.e. unlink the last node which is forming th...
class Solution: def removeLoop(self, head): slow = Node(None) slow.next = head head = fast = slow while fast and fast.next: slow = slow.next fast = fast.next.next if fast == slow: slow = head while fast.next != slow...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR NONE ASSIGN VAR VAR ASSIGN VAR VAR VAR WHILE VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NONE RETURN
Given a linked list of N nodes such that it may contain a loop. A loop here means that the last node of the link list is connected to the node at position X(1-based index). If the link list does not have any loop, X=0. Remove the loop from the linked list, if it is present, i.e. unlink the last node which is forming th...
class Solution: def removeLoop(self, head): headMap = {} headMap[head] = 1 while head.next is not None: w = headMap.get(head.next, 0) + 1 headMap[head.next] = w if w == 2: head.next = None break head = head.next
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR VAR NUMBER WHILE VAR NONE ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER ASSIGN VAR NONE ASSIGN VAR VAR
Given a linked list of N nodes such that it may contain a loop. A loop here means that the last node of the link list is connected to the node at position X(1-based index). If the link list does not have any loop, X=0. Remove the loop from the linked list, if it is present, i.e. unlink the last node which is forming th...
def isloop(head): fast, slow = head, head if head == None: return 0 while fast != None and fast.next != None: fast = fast.next.next slow = slow.next if fast == slow: return fast return None class Solution: def removeLoop(self, head): temp = islo...
FUNC_DEF ASSIGN VAR VAR VAR VAR IF VAR NONE RETURN NUMBER WHILE VAR NONE VAR NONE ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR RETURN VAR RETURN NONE CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NONE RETURN ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR VAR ASSIGN VAR NONE RET...
Given a linked list of N nodes such that it may contain a loop. A loop here means that the last node of the link list is connected to the node at position X(1-based index). If the link list does not have any loop, X=0. Remove the loop from the linked list, if it is present, i.e. unlink the last node which is forming th...
class Solution: def removeLoop(self, head): slow = head fast = head while slow and fast and fast.next: slow = slow.next fast = fast.next.next if slow == fast: break slow = head while slow != fast and fast != None: ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR WHILE VAR VAR VAR NONE ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR NONE VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR NONE RETURN NUMBER RETURN NUMBER
Given a linked list of N nodes such that it may contain a loop. A loop here means that the last node of the link list is connected to the node at position X(1-based index). If the link list does not have any loop, X=0. Remove the loop from the linked list, if it is present, i.e. unlink the last node which is forming th...
class Solution: def removeLoop(self, head): tmp = head while True: if tmp.next == None: break if tmp.next.data == "a": tmp.next = None break tmp.data = "a" tmp = tmp.next
CLASS_DEF FUNC_DEF ASSIGN VAR VAR WHILE NUMBER IF VAR NONE IF VAR STRING ASSIGN VAR NONE ASSIGN VAR STRING ASSIGN VAR VAR
Given a linked list of N nodes such that it may contain a loop. A loop here means that the last node of the link list is connected to the node at position X(1-based index). If the link list does not have any loop, X=0. Remove the loop from the linked list, if it is present, i.e. unlink the last node which is forming th...
class Solution: def removeLoop(self, head): mpp = {} temp = head while True: mpp[temp] = True if temp.next == None: return elif temp.next in mpp: temp.next = None return temp = temp.next ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR VAR WHILE NUMBER ASSIGN VAR VAR NUMBER IF VAR NONE RETURN IF VAR VAR ASSIGN VAR NONE RETURN ASSIGN VAR VAR RETURN
Given a linked list of N nodes such that it may contain a loop. A loop here means that the last node of the link list is connected to the node at position X(1-based index). If the link list does not have any loop, X=0. Remove the loop from the linked list, if it is present, i.e. unlink the last node which is forming th...
class Solution: def removeLoop(self, head): d = {} curr = head d[head] = 1 while curr.next: if curr.next in d: curr.next = None return 1 else: d[curr.next] = 1 curr = curr.next
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR VAR ASSIGN VAR VAR NUMBER WHILE VAR IF VAR VAR ASSIGN VAR NONE RETURN NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR
Given a linked list of N nodes such that it may contain a loop. A loop here means that the last node of the link list is connected to the node at position X(1-based index). If the link list does not have any loop, X=0. Remove the loop from the linked list, if it is present, i.e. unlink the last node which is forming th...
class Solution: def removeLoop(self, head): dict = {} temp = head while temp.next != None: if temp.next in dict: temp.next = None return 1 else: dict[temp] = 1 temp = temp.next return 0
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR VAR WHILE VAR NONE IF VAR VAR ASSIGN VAR NONE RETURN NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR RETURN NUMBER
Given a linked list of N nodes such that it may contain a loop. A loop here means that the last node of the link list is connected to the node at position X(1-based index). If the link list does not have any loop, X=0. Remove the loop from the linked list, if it is present, i.e. unlink the last node which is forming th...
class Solution: def removeLoop(self, head): itr = head s = set() while itr: if itr.next in s: itr.next = None return head else: s.add(itr) itr = itr.next return head
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR WHILE VAR IF VAR VAR ASSIGN VAR NONE RETURN VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR RETURN VAR
You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(s) in s that is a concatenation of each word in words exactly once and without any intervening characters. Example 1: Input: s = "barfoothefoobarman", words = ["foo","bar"] Output: [0,9] Exp...
class Solution: def findSubstring(self, s, words): m, n, k, result, wordbase = len(s), len(words), len(words[0]), [], {} for value in words: if value in wordbase: wordbase[value] += 1 else: wordbase[value] = 1 for i in range(min(k, m -...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER LIST DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR DICT VAR VAR WHILE BIN_OP VAR BIN_OP VAR VAR...
You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(s) in s that is a concatenation of each word in words exactly once and without any intervening characters. Example 1: Input: s = "barfoothefoobarman", words = ["foo","bar"] Output: [0,9] Exp...
class Solution(object): def findSubstring(self, s, words): if not s or not words or not words[0]: return [] n = len(s) k = len(words[0]) t = len(words) * k req = {} for w in words: req[w] = req[w] + 1 if w in req else 1 ans = [] ...
CLASS_DEF VAR FUNC_DEF IF VAR VAR VAR NUMBER RETURN LIST ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR ...
You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(s) in s that is a concatenation of each word in words exactly once and without any intervening characters. Example 1: Input: s = "barfoothefoobarman", words = ["foo","bar"] Output: [0,9] Exp...
class Solution: def findSubstring(self, s, words): result = [] lenWord = len(words[0]) numOfWords = len(words) lenSubstring = lenWord * numOfWords dic = {} for word in words: if word in dic: dic[word] += 1 else: ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR DICT ASSIGN VAR VAR ASSI...
You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(s) in s that is a concatenation of each word in words exactly once and without any intervening characters. Example 1: Input: s = "barfoothefoobarman", words = ["foo","bar"] Output: [0,9] Exp...
class Solution: def findSubstring(self, s, words): lword = len(words[0]) n = len(words) lwords = n * lword if not s or not lwords: return res = [] dic = {} for key in words: dic[key] = [0, 0] for key in words: dic[k...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR RETURN ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR LIST NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR WHILE VAR BIN_OP FUNC_CALL VAR VAR VAR ...
You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(s) in s that is a concatenation of each word in words exactly once and without any intervening characters. Example 1: Input: s = "barfoothefoobarman", words = ["foo","bar"] Output: [0,9] Exp...
class Solution: def findSubstring(self, s, words): if not s or not words: return [] lens, lenw, numw = len(s), len(words[0]), len(words) res = [] end = lens // lenw * lenw for i in range(lenw): start = sidx = i record = words[:] ...
CLASS_DEF FUNC_DEF IF VAR VAR RETURN LIST ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR IF VAR VAR ...
You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(s) in s that is a concatenation of each word in words exactly once and without any intervening characters. Example 1: Input: s = "barfoothefoobarman", words = ["foo","bar"] Output: [0,9] Exp...
class Solution: def findSubstring(self, s, words): if not words: return [] word_len = len(words[0]) word_set = {} for word in words: word_set[word] = word_set.get(word, 0) + 1 scopes = [([], {}) for _ in range(word_len)] results = [] f...
CLASS_DEF FUNC_DEF IF VAR RETURN LIST ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR LIST DICT VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR VAR B...
You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(s) in s that is a concatenation of each word in words exactly once and without any intervening characters. Example 1: Input: s = "barfoothefoobarman", words = ["foo","bar"] Output: [0,9] Exp...
class Solution: def findSubstring(self, s, words): hash = {} res = [] wsize = len(words[0]) for str in words: if str in hash: hash[str] += 1 else: hash[str] = 1 for start in range(0, len(words[0])): slidingW...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR IF ...
You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(s) in s that is a concatenation of each word in words exactly once and without any intervening characters. Example 1: Input: s = "barfoothefoobarman", words = ["foo","bar"] Output: [0,9] Exp...
class Solution(object): def findSubstring(self, s, words): if not s or not words: return [] result, sLen, numW, wLen = [], len(s), len(words), len(words[0]) if sLen < numW * wLen: return [] dic = collections.defaultdict(int) for i in words: ...
CLASS_DEF VAR FUNC_DEF IF VAR VAR RETURN LIST ASSIGN VAR VAR VAR VAR LIST FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR VAR RETURN LIST ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_C...
You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(s) in s that is a concatenation of each word in words exactly once and without any intervening characters. Example 1: Input: s = "barfoothefoobarman", words = ["foo","bar"] Output: [0,9] Exp...
class Solution: def findSubstring(self, s, words): L = len(s) length = len(words[0]) Length = length * len(words) result = [] word_dict = {} for word in words: word_dict[word] = word_dict[word] + 1 if word in word_dict else 1 for i in range(length...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR DICT WHILE BIN_OP VAR VAR VAR ASS...
Bike loves looking for the second maximum element in the sequence. The second maximum element in the sequence of distinct numbers x1, x2, ..., xk (k > 1) is such maximum element xj, that the following inequality holds: <image>. The lucky number of the sequence of distinct positive integers x1, x2, ..., xk (k > 1) is t...
n = int(input()) l = [int(e) for e in input().split()] s = [l[0]] m = 0 for i in range(1, n): if l[i] < s[-1]: m = max(m, l[i] ^ s[-1]) else: while len(s) != 0 and l[i] > s[-1]: x = s.pop() m = max(m, l[i] ^ x) if len(s) != 0: m = max(m, l[i] ^ s[-1]) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR FUNC_CAL...
Bike loves looking for the second maximum element in the sequence. The second maximum element in the sequence of distinct numbers x1, x2, ..., xk (k > 1) is such maximum element xj, that the following inequality holds: <image>. The lucky number of the sequence of distinct positive integers x1, x2, ..., xk (k > 1) is t...
n = int(input()) arr = list(map(int, input().split())) s = [] ans = 0 for i in range(n): while s != []: ans = max(ans, arr[i] ^ s[-1]) if arr[i] < s[-1]: break else: s.pop() s.append(arr[i]) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR LIST ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL V...
Bike loves looking for the second maximum element in the sequence. The second maximum element in the sequence of distinct numbers x1, x2, ..., xk (k > 1) is such maximum element xj, that the following inequality holds: <image>. The lucky number of the sequence of distinct positive integers x1, x2, ..., xk (k > 1) is t...
import sys input_lines = [line.strip() for line in sys.stdin.readlines() if line.strip()] n = int(input_lines[0]) array = [int(x) for x in input_lines[1].split()] def directional_max_xor(array, n): max_xor = 0 stack = [array[0]] for i in range(1, n): if array[i] > stack[-1]: _1st_max ...
IMPORT ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR WHILE FUNC_CALL VAR VAR NUMBER VAR VAR...
Given a string you need to print the size of the longest possible substring that has exactly K unique characters. If there is no possible substring then print -1. Example 1: Input: S = "aabacbebebe", K = 3 Output: 7 Explanation: "cbebebe" is the longest substring with K distinct characters. Example 2: Input: S = "aaa...
class Solution: def longestKSubstr(self, s, k): n = len(s) dic = {} ans = -1 i = 0 j = 0 while j < n: if s[j] in dic: dic[s[j]] += 1 else: dic[s[j]] = 1 if len(dic) > k: ans = max(ans...
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 VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR WHILE FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR V...
Given a string you need to print the size of the longest possible substring that has exactly K unique characters. If there is no possible substring then print -1. Example 1: Input: S = "aabacbebebe", K = 3 Output: 7 Explanation: "cbebebe" is the longest substring with K distinct characters. Example 2: Input: S = "aaa...
class Solution: def longestKSubstr(self, s, k): d = {} i = 0 j = 0 max1 = -1 while i < len(s): if s[i] in d: d[s[i]] += 1 else: if len(d) == k: max1 = max(max1, i - j) while len(d...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR WHILE FUNC_CALL VAR VAR VAR IF VAR VAR VAR NUMBER VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN V...
Given a string you need to print the size of the longest possible substring that has exactly K unique characters. If there is no possible substring then print -1. Example 1: Input: S = "aabacbebebe", K = 3 Output: 7 Explanation: "cbebebe" is the longest substring with K distinct characters. Example 2: Input: S = "aaa...
class Solution: def longestKSubstr(self, s, k): i, j = 0, 0 d = {} n = len(s) l = -1 while j < n: d[s[j]] = d.get(s[j], 0) + 1 if len(d) == k: l = max(l, j - i + 1) if len(d) > k: while len(d) > k: ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR WHILE FUNC_CALL VAR VAR V...
Given a string you need to print the size of the longest possible substring that has exactly K unique characters. If there is no possible substring then print -1. Example 1: Input: S = "aabacbebebe", K = 3 Output: 7 Explanation: "cbebebe" is the longest substring with K distinct characters. Example 2: Input: S = "aaa...
class Solution: def longestKSubstr(self, s, k): b = set() for i in s: b.add(i) if len(b) < k: return -1 l, r, res = 0, 0, 0 map_ = {} while r < len(s): map_[s[r]] = map_.get(s[r], 0) + 1 while len(map_) > k: ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR RETURN NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR DICT WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER WHILE FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR V...
Given a string you need to print the size of the longest possible substring that has exactly K unique characters. If there is no possible substring then print -1. Example 1: Input: S = "aabacbebebe", K = 3 Output: 7 Explanation: "cbebebe" is the longest substring with K distinct characters. Example 2: Input: S = "aaa...
class Solution: def longestKSubstr(self, S, K): ans = float("-inf") left = 0 freq = {} for right in range(len(S)): freq[S[right]] = freq.get(S[right], 0) + 1 while len(freq) > k: freq[S[left]] -= 1 if freq[S[left]] == 0: ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL 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 VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_...
Given a string you need to print the size of the longest possible substring that has exactly K unique characters. If there is no possible substring then print -1. Example 1: Input: S = "aabacbebebe", K = 3 Output: 7 Explanation: "cbebebe" is the longest substring with K distinct characters. Example 2: Input: S = "aaa...
class Solution: def longestKSubstr(self, s, k): mx = -1 i, j = 0, 0 tmp = {} while j < len(s): tmp[s[j]] = 1 + tmp.get(s[j], 0) if len(tmp) < k: j += 1 elif len(tmp) == k: mx = max(mx, j - i + 1) j +...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR DICT WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER IF FUNC_CALL VAR V...
Given a string you need to print the size of the longest possible substring that has exactly K unique characters. If there is no possible substring then print -1. Example 1: Input: S = "aabacbebebe", K = 3 Output: 7 Explanation: "cbebebe" is the longest substring with K distinct characters. Example 2: Input: S = "aaa...
class Solution: def longestKSubstr(self, s, k): map = {} end = 0 start = 0 found = False maxLen = 0 while end < len(s): while len(map) <= k and end < len(s): if s[end] not in map: map[s[end]] = 0 map[s[e...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR VAR IF VAR BIN_OP BIN_OP VAR VAR...
Given a string you need to print the size of the longest possible substring that has exactly K unique characters. If there is no possible substring then print -1. Example 1: Input: S = "aabacbebebe", K = 3 Output: 7 Explanation: "cbebebe" is the longest substring with K distinct characters. Example 2: Input: S = "aaa...
class Solution: def longestKSubstr(self, s, k): maxi = -1 d = dict() distinct = 0 left = 0 for i in range(len(s)): right = i if s[i] in d: d[s[i]] += 1 else: d[s[i]] = 1 distinct += 1 ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR WHILE VAR VAR VA...
Given a string you need to print the size of the longest possible substring that has exactly K unique characters. If there is no possible substring then print -1. Example 1: Input: S = "aabacbebebe", K = 3 Output: 7 Explanation: "cbebebe" is the longest substring with K distinct characters. Example 2: Input: S = "aaa...
class Solution: def longestKSubstr(self, s, k): char_count = {} head = 0 current = 0 ans = -1 for char in s: if char in char_count: char_count[char] += 1 else: char_count[char] = 1 length = len(char_count) ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR WHILE FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER...
Given a string you need to print the size of the longest possible substring that has exactly K unique characters. If there is no possible substring then print -1. Example 1: Input: S = "aabacbebebe", K = 3 Output: 7 Explanation: "cbebebe" is the longest substring with K distinct characters. Example 2: Input: S = "aaa...
class Solution: def longestKSubstr(self, s, k): m = {} for x in s: m[x] = 0 uniq = 0 i = 0 j = 0 res = 0 n = len(s) while j < n: while j < n: if m[s[j]] == 0: uniq += 1 m[s[j]...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR WHILE VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP V...