description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
JJ has an array A initially of length N. He can perform the following operation on A: 1) Pick any index i (1 ≀ i ≀ |A|) such that A_{i} > 1 \\ 2) Select any two integers X and Y such that X + Y = A_{i} and X, Y β‰₯ 1 \\ 3) Replace A_{i} with X and Y Note that the length of the array increases by 1 after each operation....
def palindrom(a): count = 0 while len(a) > 1: if a[0] == a[-1]: del a[0] del a[-1] else: if a[0] > a[-1]: a[0] -= a[-1] del a[-1] else: a[-1] -= a[0] del a[0] count += 1 ...
FUNC_DEF ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR A...
JJ has an array A initially of length N. He can perform the following operation on A: 1) Pick any index i (1 ≀ i ≀ |A|) such that A_{i} > 1 \\ 2) Select any two integers X and Y such that X + Y = A_{i} and X, Y β‰₯ 1 \\ 3) Replace A_{i} with X and Y Note that the length of the array increases by 1 after each operation....
t = int(input()) for _ in range(t): input() l = list(map(int, input().split())) count = 0 while len(l) > 1: if l[0] == l[-1]: l.pop(0) l.pop() count -= 1 elif l[0] > l[-1]: l[0] -= l[-1] l.pop() else: l[-1] -...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR...
JJ has an array A initially of length N. He can perform the following operation on A: 1) Pick any index i (1 ≀ i ≀ |A|) such that A_{i} > 1 \\ 2) Select any two integers X and Y such that X + Y = A_{i} and X, Y β‰₯ 1 \\ 3) Replace A_{i} with X and Y Note that the length of the array increases by 1 after each operation....
t = int(input()) for i in range(t): n = int(input()) A = list(map(int, input().split()))[:n] count = 0 for i in range(len(A)): N = len(A) - 1 temp = 0 if i == N - i: break if A[i] < A[N - i]: temp = A[N - i] A[N - i] = A[i] ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR VAR IF V...
JJ has an array A initially of length N. He can perform the following operation on A: 1) Pick any index i (1 ≀ i ≀ |A|) such that A_{i} > 1 \\ 2) Select any two integers X and Y such that X + Y = A_{i} and X, Y β‰₯ 1 \\ 3) Replace A_{i} with X and Y Note that the length of the array increases by 1 after each operation....
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) x = 0 y = n - 1 ans = 0 while len(a) > 1: if a[0] == a[-1]: del a[0] del a[-1] elif a[0] < a[-1]: x = a[0] y = a[-1] del a[0] ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUM...
JJ has an array A initially of length N. He can perform the following operation on A: 1) Pick any index i (1 ≀ i ≀ |A|) such that A_{i} > 1 \\ 2) Select any two integers X and Y such that X + Y = A_{i} and X, Y β‰₯ 1 \\ 3) Replace A_{i} with X and Y Note that the length of the array increases by 1 after each operation....
a = [] for t in range(int(input())): n = input() a = list(map(int, input().split())) c = 0 while len(a) > 1: if a[0] == a[-1]: del a[0] del a[-1] else: if a[0] > a[-1]: a[0] -= a[-1] del a[-1] else: ...
ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMB...
JJ has an array A initially of length N. He can perform the following operation on A: 1) Pick any index i (1 ≀ i ≀ |A|) such that A_{i} > 1 \\ 2) Select any two integers X and Y such that X + Y = A_{i} and X, Y β‰₯ 1 \\ 3) Replace A_{i} with X and Y Note that the length of the array increases by 1 after each operation....
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) l = 0 r = n - 1 s = 0 while True: if a[l] < a[r]: a[r] -= a[l] l += 1 s += 1 elif a[r] < a[l]: a[l] -= a[r] r -= 1 s += 1 ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR VAR VA...
JJ has an array A initially of length N. He can perform the following operation on A: 1) Pick any index i (1 ≀ i ≀ |A|) such that A_{i} > 1 \\ 2) Select any two integers X and Y such that X + Y = A_{i} and X, Y β‰₯ 1 \\ 3) Replace A_{i} with X and Y Note that the length of the array increases by 1 after each operation....
t = int(input()) while t: n = int(input()) l = list(map(int, input().split())) i, j, count = 0, 0, 0 h = n // 2 if n % 2 == 0: pass else: h += 1 j = n - 1 while i < j: if l[i] == l[j]: i += 1 j -= 1 elif l[i] > l[j]: cou...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR IF VAR VAR VAR...
JJ has an array A initially of length N. He can perform the following operation on A: 1) Pick any index i (1 ≀ i ≀ |A|) such that A_{i} > 1 \\ 2) Select any two integers X and Y such that X + Y = A_{i} and X, Y β‰₯ 1 \\ 3) Replace A_{i} with X and Y Note that the length of the array increases by 1 after each operation....
for _ in range(int(input())): r = int(input()) - 1 s = list(map(int, input().split())) cout = 0 l = 0 while l < r: if s[l] != s[r]: cout = cout + 1 if s[l] > s[r]: s[l] = s[l] - s[r] r = r - 1 else: s[r] = s[...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR...
JJ has an array A initially of length N. He can perform the following operation on A: 1) Pick any index i (1 ≀ i ≀ |A|) such that A_{i} > 1 \\ 2) Select any two integers X and Y such that X + Y = A_{i} and X, Y β‰₯ 1 \\ 3) Replace A_{i} with X and Y Note that the length of the array increases by 1 after each operation....
t = int(input()) for i in range(t): n = int(input()) z = list(map(int, input().split())) ans = 0 j = 0 k = n - 1 while j < k: if z[j] == z[k]: j += 1 k -= 1 elif z[j] > z[k]: ans += 1 z[j] = z[j] - z[k] k -= 1 el...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER...
JJ has an array A initially of length N. He can perform the following operation on A: 1) Pick any index i (1 ≀ i ≀ |A|) such that A_{i} > 1 \\ 2) Select any two integers X and Y such that X + Y = A_{i} and X, Y β‰₯ 1 \\ 3) Replace A_{i} with X and Y Note that the length of the array increases by 1 after each operation....
t = int(input()) for i in range(t): n = int(input()) l = list(map(int, input().split())) i = 0 r = n - 1 count = 0 while i < r: x = l[i] y = l[r] if x < y: b = y - x l[r] = b count += 1 i = i + 1 elif x > y: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR...
JJ has an array A initially of length N. He can perform the following operation on A: 1) Pick any index i (1 ≀ i ≀ |A|) such that A_{i} > 1 \\ 2) Select any two integers X and Y such that X + Y = A_{i} and X, Y β‰₯ 1 \\ 3) Replace A_{i} with X and Y Note that the length of the array increases by 1 after each operation....
t = int(input()) for i in range(t): a = int(input()) b = list(map(int, input().split())) c = 0 while len(b) > 1: if b[0] == b[a - 1]: del b[0] del b[len(b) - 1] a = a - 2 elif b[0] < b[a - 1]: b[a - 1] = b[a - 1] - b[0] del b[0]...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP...
JJ has an array A initially of length N. He can perform the following operation on A: 1) Pick any index i (1 ≀ i ≀ |A|) such that A_{i} > 1 \\ 2) Select any two integers X and Y such that X + Y = A_{i} and X, Y β‰₯ 1 \\ 3) Replace A_{i} with X and Y Note that the length of the array increases by 1 after each operation....
t = int(input()) test = 0 while test < t: j = 0 n = int(input()) count = 0 arr = list(map(int, input().strip().split()))[:n] length = len(arr) while length > 1: if arr[0] == arr[length - 1]: arr.pop(length - 1) length = len(arr) arr.pop(0) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_C...
JJ has an array A initially of length N. He can perform the following operation on A: 1) Pick any index i (1 ≀ i ≀ |A|) such that A_{i} > 1 \\ 2) Select any two integers X and Y such that X + Y = A_{i} and X, Y β‰₯ 1 \\ 3) Replace A_{i} with X and Y Note that the length of the array increases by 1 after each operation....
t = int(input()) while t > 0: n = int(input()) arr = list(map(int, input().split())) c = 0 i = 0 j = n - 1 while i <= j: if arr[i] == arr[j]: i += 1 j -= 1 continue c += 1 if arr[i] > arr[j]: l = arr[i] - arr[j] ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR ASSIGN V...
JJ has an array A initially of length N. He can perform the following operation on A: 1) Pick any index i (1 ≀ i ≀ |A|) such that A_{i} > 1 \\ 2) Select any two integers X and Y such that X + Y = A_{i} and X, Y β‰₯ 1 \\ 3) Replace A_{i} with X and Y Note that the length of the array increases by 1 after each operation....
for i in range(int(input())): n = int(input()) l = list(map(int, input().split())) c = 0 while len(l) > 1: if l[0] == l[-1]: del l[0] del l[-1] elif l[0] < l[-1]: c += 1 x = l[-1] - l[0] del l[0] del l[-1] ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR...
JJ has an array A initially of length N. He can perform the following operation on A: 1) Pick any index i (1 ≀ i ≀ |A|) such that A_{i} > 1 \\ 2) Select any two integers X and Y such that X + Y = A_{i} and X, Y β‰₯ 1 \\ 3) Replace A_{i} with X and Y Note that the length of the array increases by 1 after each operation....
t = int(input()) for i in range(t): n = int(input()) l = [int(i) for i in input().split()] c = 0 if n == 0 or n == 1: print(0) else: while len(l) != 0 and len(l) != 1: if l[0] == l[-1]: l.pop() l.pop(0) else: c +...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC...
JJ has an array A initially of length N. He can perform the following operation on A: 1) Pick any index i (1 ≀ i ≀ |A|) such that A_{i} > 1 \\ 2) Select any two integers X and Y such that X + Y = A_{i} and X, Y β‰₯ 1 \\ 3) Replace A_{i} with X and Y Note that the length of the array increases by 1 after each operation....
t = int(input()) for i in range(t): n = int(input()) arr = list(map(int, input().split())) i, j = 0, n - 1 count = 0 while i < j: a = min(arr[i], arr[j]) b = max(arr[i], arr[j]) if arr[i] == arr[j]: i += 1 j -= 1 elif arr[i] < arr[j]: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR...
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K. (For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.) Return the number of good subarrays of A. Β  Example 1: Input: A = [1,2,1,2,3], K = ...
class Window: def __init__(self): self.counter = collections.Counter() def add(self, x): self.counter[x] += 1 def remove(self, x): self.counter[x] -= 1 if self.counter[x] == 0: self.counter.pop(x) def __len__(self): return len(self.counter) class...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_DEF VAR VAR NUMBER FUNC_DEF VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR...
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K. (For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.) Return the number of good subarrays of A. Β  Example 1: Input: A = [1,2,1,2,3], K = ...
class Solution: def subarraysWithKDistinct(self, A: List[int], K: int) -> int: return self.at_most_K(A, K) - self.at_most_K(A, K - 1) def at_most_K(self, A, k): left = 0 counter = collections.Counter() diff = 0 result = 0 for right in range(len(A)): ...
CLASS_DEF FUNC_DEF VAR VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR 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 VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER WHILE VAR VAR VAR VAR VAR NUMBER ...
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K. (For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.) Return the number of good subarrays of A. Β  Example 1: Input: A = [1,2,1,2,3], K = ...
class Solution: def subarraysWithKDistinct(self, A: List[int], K: int) -> int: last_seen = {} start = end = 0 ans = 0 for i, x in enumerate(A): last_seen[x] = i while len(last_seen) > K: if last_seen[A[start]] == start: del...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR DICT ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR WHILE FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR ...
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K. (For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.) Return the number of good subarrays of A. Β  Example 1: Input: A = [1,2,1,2,3], K = ...
class Solution: def subarraysWithKDistinct(self, A: List[int], K: int) -> int: def helper(A, K): d = defaultdict(int) begin = 0 end = 0 ans = float("-inf") count = 0 res = 0 while end < len(A): char = A[end...
CLASS_DEF FUNC_DEF VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMB...
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K. (For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.) Return the number of good subarrays of A. Β  Example 1: Input: A = [1,2,1,2,3], K = ...
class Solution: def subarraysWithKDistinct(self, A: List[int], K: int) -> int: m1, m2 = collections.Counter(), collections.Counter() def remove(m, n): m[n] -= 1 if not m[n]: del m[n] res = 0 left = right = -1 for i, n in enumerate(A)...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR RETURN VAR WHI...
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K. (For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.) Return the number of good subarrays of A. Β  Example 1: Input: A = [1,2,1,2,3], K = ...
class Solution: def subarraysWithKDistinct(self, A: List[int], K: int) -> int: n = len(A) if n < 1: return 0 result = 0 fc = Counter() c = Counter() l = 0 fr = 0 r = 0 while l < n: while fr < n and len(fc) < K: ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR WHILE VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER WHILE VAR VAR IF VAR VAR VAR F...
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K. (For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.) Return the number of good subarrays of A. Β  Example 1: Input: A = [1,2,1,2,3], K = ...
class Solution: def subarraysWithKDistinct(self, A: List[int], K: int) -> int: def atmost(k): i = 0 res = 0 d = defaultdict(int) for j, a in enumerate(A): if d[a] == 0: k -= 1 d[a] += 1 whil...
CLASS_DEF FUNC_DEF VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER WHILE VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR RETURN BIN_OP FUN...
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K. (For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.) Return the number of good subarrays of A. Β  Example 1: Input: A = [1,2,1,2,3], K = ...
class Accumulator: def __init__(self): self.KeyToCount = {} self.q = deque() def append(self, value): self.q.append(value) self.KeyToCount[value] = self.KeyToCount.get(value, 0) + 1 def popleft(self): v = self.q.popleft() if self.KeyToCount[v] == 1: ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR IF VAR VAR NUMBER VAR VAR VAR VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIG...
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K. (For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.) Return the number of good subarrays of A. Β  Example 1: Input: A = [1,2,1,2,3], K = ...
class Solution: def subarraysWithKDistinct(self, A: List[int], K: int) -> int: if not A: return 0 l = len(A) end = 0 left1 = 0 left2 = 0 map1 = collections.defaultdict(int) map2 = collections.defaultdict(int) ans = 0 while end < l:...
CLASS_DEF FUNC_DEF VAR VAR VAR IF VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER VAR VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR...
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K. (For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.) Return the number of good subarrays of A. Β  Example 1: Input: A = [1,2,1,2,3], K = ...
class Solution: def subarraysWithKDistinct(self, A: List[int], K: int) -> int: return self.atMostK(A, K) - self.atMostK(A, K - 1) def atMostK(self, A, k): start = 0 end = 0 res = 0 chars = collections.Counter() distinct = 0 while end < len(A): ...
CLASS_DEF FUNC_DEF VAR VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER WHILE VAR VAR VAR VAR VAR N...
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K. (For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.) Return the number of good subarrays of A. Β  Example 1: Input: A = [1,2,1,2,3], K = ...
class Solution: def subarraysWithKDistinct(self, A, K): return self.atMostK(A, K) - self.atMostK(A, K - 1) def atMostK(self, s, k): if not s: return 0 N = len(s) left, right = 0, 0 ret = 0 counter = collections.Counter() counter[s[right]] += ...
CLASS_DEF FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_DEF IF VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER WHILE VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER...
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K. (For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.) Return the number of good subarrays of A. Β  Example 1: Input: A = [1,2,1,2,3], K = ...
class Solution: def subarraysWithKDistinct(self, A: List[int], K: int) -> int: def at_most_k(arr, k): start = 0 counter = Counter() uniques = 0 res = 0 for i in range(len(A)): counter[A[i]] += 1 if counter[A[i]] ==...
CLASS_DEF FUNC_DEF VAR VAR VAR 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 VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER WHILE VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR RETURN VAR RE...
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K. (For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.) Return the number of good subarrays of A. Β  Example 1: Input: A = [1,2,1,2,3], K = ...
class Solution: def subarraysWithKDistinct(self, A: List[int], k: int) -> int: dic = {} n = len(A) left = 0 right = 0 cnt = 0 for i in range(n): if A[i] in dic: dic[A[i]] += 1 else: dic[A[i]] = 1 l =...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER I...
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K. (For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.) Return the number of good subarrays of A. Β  Example 1: Input: A = [1,2,1,2,3], K = ...
class Solution: def subarraysWithKDistinct(self, A: List[int], K: int) -> int: int_dict = {} int_sorted_list = [] current = 0 l = len(A) count = 0 while current < l: if int_dict.get(A[current]) != None: int_sorted_list.remove(A[current]) ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR DICT ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF FUNC_CALL VAR VAR VAR NONE EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER IF FUN...
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K. (For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.) Return the number of good subarrays of A. Β  Example 1: Input: A = [1,2,1,2,3], K = ...
class Solution: def subarraysWithKDistinct(self, A: List[int], K: int) -> int: sum = 0 begin = 0 end = 0 s = collections.defaultdict(int) lA = len(A) for i in range(lA): if len(s) >= K: s[A[i]] += 1 if s[A[i]] > 1: ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR ...
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K. (For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.) Return the number of good subarrays of A. Β  Example 1: Input: A = [1,2,1,2,3], K = ...
class Window: def __init__(self): self.count = collections.Counter() self.nonzero = 0 def add(self, x): self.count[x] += 1 if self.count[x] == 1: self.nonzero += 1 def remove(self, x): self.count[x] -= 1 if self.count[x] == 0: self.n...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_DEF VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER FUNC_DEF VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_...
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K. (For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.) Return the number of good subarrays of A. Β  Example 1: Input: A = [1,2,1,2,3], K = ...
class Solution: def subarraysWithKDistinct(self, A, K): cnt1, cnt2 = dict(), dict() res, i1, i2 = 0, 0, 0 for v in A: cnt1[v] = cnt1.get(v, 0) + 1 cnt2[v] = cnt2.get(v, 0) + 1 while len(cnt1) > K: cnt1[A[i1]] -= 1 if cnt1[A...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER WHILE FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER WHILE ...
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K. (For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.) Return the number of good subarrays of A. Β  Example 1: Input: A = [1,2,1,2,3], K = ...
class Solution: def subarraysWithKDistinct(self, A: List[int], K: int) -> int: n = len(A) if n < K: return 0 left = 0 right = 0 totalCount = 0 dp = [(0) for i in range(20001)] result = 0 for right in range(n): if dp[A[right]] =...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER WHILE VAR VAR IF VAR VAR VAR NUMBER VAR VA...
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K. (For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.) Return the number of good subarrays of A. Β  Example 1: Input: A = [1,2,1,2,3], K = ...
class Solution: def subarraysWithKDistinct(self, A: List[int], K: int) -> int: class UniqueCounter(object): def __init__(self): self.non_zero = 0 self.counts = collections.defaultdict(int) def add(self, x): if self.counts[x] == 0: ...
CLASS_DEF FUNC_DEF VAR VAR VAR CLASS_DEF VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER FUNC_DEF VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER FUNC_DEF RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR ...
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K. (For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.) Return the number of good subarrays of A. Β  Example 1: Input: A = [1,2,1,2,3], K = ...
class Window: def __init__(self): self.num = 0 self.dic = collections.defaultdict(int) def add(self, v: int) -> int: if self.dic[v] == 0: self.num += 1 self.dic[v] += 1 return self.num def remove(self, v: int) -> int: self.dic[v] -= 1 if...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF VAR IF VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER RETURN VAR VAR FUNC_DEF VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER RETURN VAR VAR CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR ...
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K. (For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.) Return the number of good subarrays of A. Β  Example 1: Input: A = [1,2,1,2,3], K = ...
class Solution: def subarraysWithKDistinct(self, A: List[int], K: int) -> int: return self.atMost(A, K) - self.atMost(A, K - 1) def atMost(self, A, K): if K == 0: return 0 hi, res = 0, 0 n = len(A) count = collections.defaultdict(int) for lo in range...
CLASS_DEF FUNC_DEF VAR VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR NUM...
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K. (For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.) Return the number of good subarrays of A. Β  Example 1: Input: A = [1,2,1,2,3], K = ...
class Solution: def subarraysWithKDistinct(self, A: List[int], K: int) -> int: d, t = defaultdict(int), defaultdict(int) a, b = K, K left, right = 0, 0 res = 0 for i, ele in enumerate(A): a -= 1 if d[ele] == 0 else 0 b -= 1 if t[ele] == 0 else 0 ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER NUMBER NUMBER VAR VAR VAR NUMBER NUMBER NUMBER VAR VAR NUMBER VAR VAR NUMBER WHILE VAR NUMBER VAR VAR VAR VAR NUMBER NU...
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K. (For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.) Return the number of good subarrays of A. Β  Example 1: Input: A = [1,2,1,2,3], K = ...
class Solution: def subarraysWithKDistinct(self, A: List[int], K: int) -> int: keyCounter = defaultdict(int) ALen = len(A) l = 0 r = 0 ans = 0 KNow = 0 while r <= ALen: if KNow == K: ans += 1 temp = 0 ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER VAR VA...
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K. (For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.) Return the number of good subarrays of A. Β  Example 1: Input: A = [1,2,1,2,3], K = ...
class Solution: def subarraysWithKDistinct(self, A: "List[int]", K: "int") -> "int": return self.subarraysWithAtMostKDistinct( A, K ) - self.subarraysWithAtMostKDistinct(A, K - 1) def subarraysWithAtMostKDistinct(self, s, k): lookup = collections.defaultdict(int) l,...
CLASS_DEF FUNC_DEF STRING STRING RETURN BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER STRING FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER WHILE VAR VAR VAR VAR VAR VA...
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K. (For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.) Return the number of good subarrays of A. Β  Example 1: Input: A = [1,2,1,2,3], K = ...
class Solution: def subarraysWithKDistinct(self, A, K): return self.atMostK(A, K) - self.atMostK(A, K - 1) def atMostK(self, A, K): count = collections.Counter() res = left = right = distinct = 0 while right < len(A): count[A[right]] += 1 if count[A[righ...
CLASS_DEF FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER WHILE VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR BIN_...
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K. (For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.) Return the number of good subarrays of A. Β  Example 1: Input: A = [1,2,1,2,3], K = ...
class Solution: def helper(self, A, B): count = 0 left = 0 right = 0 d = {} while right < len(A): if A[right] not in d: d[A[right]] = 0 d[A[right]] += 1 while len(d) > B: d[A[left]] -= 1 if d...
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 ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER VAR...
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K. (For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.) Return the number of good subarrays of A. Β  Example 1: Input: A = [1,2,1,2,3], K = ...
class Solution: def subarraysWithKDistinct(self, A: List[int], K: int) -> int: n = len(A) hashmap = {} l = 0 count = 0 ans = 0 sums = 1 for r in range(n): if A[r] in hashmap: hashmap[A[r]] += 1 else: has...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER WHILE VAR VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VA...
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K. (For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.) Return the number of good subarrays of A. Β  Example 1: Input: A = [1,2,1,2,3], K = ...
class Solution: def subarraysWithKDistinct(self, A: List[int], K: int) -> int: start = 0 first_uni = 0 re = 0 dd = {} for i, cur in enumerate(A): dd[cur] = dd.get(cur, 0) + 1 if len(dd) == K + 1: dd.pop(A[first_uni]) fi...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR IF FUNC_CALL VAR VAR VAR WHILE VAR VAR VAR ...
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K. (For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.) Return the number of good subarrays of A. Β  Example 1: Input: A = [1,2,1,2,3], K = ...
class Solution: def subarraysWithKDistinct(self, A: List[int], K: int) -> int: def atMost(K): N = len(A) ct = collections.Counter() ans = 0 i = 0 for j in range(N): ct[A[j]] += 1 if len(ct) <= K: ...
CLASS_DEF FUNC_DEF VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR VAR NU...
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K. (For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.) Return the number of good subarrays of A. Β  Example 1: Input: A = [1,2,1,2,3], K = ...
class Solution: def subarraysWithKDistinct(self, A: List[int], K: int) -> int: counter1, counter2 = collections.Counter(), collections.Counter() slow = fast = res = 0 for a in A: counter1[a], counter2[a] = counter1[a] + 1, counter2[a] + 1 while len(counter2) == K: ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER IF VAR VA...
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K. (For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.) Return the number of good subarrays of A. Β  Example 1: Input: A = [1,2,1,2,3], K = ...
class Window: def __init__(self): self.count = {} def add(self, elem): self.count.setdefault(elem, 0) self.count[elem] += 1 def remove(self, elem): self.count[elem] -= 1 if self.count[elem] == 0: del self.count[elem] def added_size(self, elem): ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FUNC_DEF EXPR FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER FUNC_DEF VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VA...
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K. (For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.) Return the number of good subarrays of A. Β  Example 1: Input: A = [1,2,1,2,3], K = ...
class Solution: def subarraysWithKDistinct(self, A: List[int], K: int) -> int: checkSet = OrderedDict() windowStart = 0 count = 0 ans = [] for i, n in enumerate(A): checkSet[n] = i checkSet.move_to_end(n) while len(checkSet) > K: ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER IF FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP FUNC_CALL VAR FU...
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K. (For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.) Return the number of good subarrays of A. Β  Example 1: Input: A = [1,2,1,2,3], K = ...
class Solution: def _identify_limit(self, A, current_limit, K, char_count_after_limit): char_count_after_limit = {k: v for k, v in char_count_after_limit.items()} unique_chars = { i for i in char_count_after_limit if char_count_after_limit[i] > 0 } while len(unique_chars...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR VAR NUMBER WHILE FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER RETURN BIN_OP...
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K. (For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.) Return the number of good subarrays of A. Β  Example 1: Input: A = [1,2,1,2,3], K = ...
class Solution: def subarraysWithAtMostK(self, A: List[int], K: int) -> int: result = i = 0 count = collections.Counter() for j in range(len(A)): if count[A[j]] == 0: K -= 1 count[A[j]] += 1 while K < 0: count[A[i]] -= 1 ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER WHILE VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR VAR FUNC_DEF VAR VAR VAR R...
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K. (For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.) Return the number of good subarrays of A. Β  Example 1: Input: A = [1,2,1,2,3], K = ...
class Solution: def subarraysWithKDistinct(self, A, K): def atMostK(A, K): count = collections.Counter() res, l, window_count = 0, 0, 0 for r, c in enumerate(A): if count[c] == 0: window_count += 1 count[c] += 1 ...
CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER WHILE VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR RETURN BIN_OP FUNC_CALL VAR VAR ...
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K. (For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.) Return the number of good subarrays of A. Β  Example 1: Input: A = [1,2,1,2,3], K = ...
class Solution: def subarraysWithKDistinct(self, A: List[int], K: int) -> int: return self.at_most(A, K) - self.at_most(A, K - 1) def at_most(self, A, K): if K == 0: return 0 window = {} left = 0 ret = 0 for right in range(len(A)): window...
CLASS_DEF FUNC_DEF VAR VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER WHILE VAR VAR FUNC_CAL...
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K. (For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.) Return the number of good subarrays of A. Β  Example 1: Input: A = [1,2,1,2,3], K = ...
class Solution: def subarraysWithKDistinct(self, A: List[int], K: int) -> int: def help(k): res = 0 left = 0 d = {} for i, ele in enumerate(A): d[ele] = d.get(ele, 0) + 1 while len(d) > k: d[A[left]] -= 1 ...
CLASS_DEF FUNC_DEF VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER WHILE FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR RETURN VAR RETURN BIN_OP FUNC_CAL...
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K. (For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.) Return the number of good subarrays of A. Β  Example 1: Input: A = [1,2,1,2,3], K = ...
class Solution: def subarraysWithKDistinct(self, A: List[int], K: int) -> int: length = len(A) class counter: def __init__(self): self.c = Counter() def addValue(self, num): self.c[num] += 1 def removeValue(self, num): ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_DEF VAR VAR NUMBER FUNC_DEF VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR IF F...
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K. (For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.) Return the number of good subarrays of A. Β  Example 1: Input: A = [1,2,1,2,3], K = ...
class Solution: def subarraysWithKDistinct(self, A: List[int], K: int) -> int: ans, ctr, lb, count = 0, {}, 0, 0 for i, val in enumerate(A): if val not in ctr: ctr[val] = 0 ctr[val] += 1 while len(ctr) > K: ctr[A[lb]] -= 1 ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER DICT NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR 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 VAR VAR VAR NUMBER FUNC_CALL VAR W...
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K. (For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.) Return the number of good subarrays of A. Β  Example 1: Input: A = [1,2,1,2,3], K = ...
class Solution: def _identify_limit(self, A, current_limit, K, char_count_after_limit): temp_char = A[current_limit] while char_count_after_limit.get(temp_char, 0) > 1: char_count_after_limit[temp_char] = char_count_after_limit[temp_char] - 1 current_limit += 1 t...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR WHILE FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR RETURN VAR VAR FUNC_DEF VAR VAR VAR ASSIGN VAR VAR LIST VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSI...
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K. (For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.) Return the number of good subarrays of A. Β  Example 1: Input: A = [1,2,1,2,3], K = ...
class Solution: def subarraysWithKDistinct(self, A: List[int], K: int) -> int: def remove(m, n): if m[n] == 1: del m[n] else: m[n] -= 1 m1, m2 = collections.Counter(), collections.Counter() res = 0 i1 = i2 = -1 for i0...
CLASS_DEF FUNC_DEF VAR VAR VAR FUNC_DEF IF VAR VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR WHILE BIN_OP VAR NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR RETURN ...
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K. (For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.) Return the number of good subarrays of A. Β  Example 1: Input: A = [1,2,1,2,3], K = ...
class Solution: def subarraysWithKDistinct(self, A: List[int], K: int) -> int: return self.helper(A, K) - self.helper(A, K - 1) def helper(self, A, K): counter = collections.Counter() p1 = p2 = 0 res = 0 while p2 < len(A): if counter[A[p2]] == 0: ...
CLASS_DEF FUNC_DEF VAR VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER WHILE VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER V...
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K. (For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.) Return the number of good subarrays of A. Β  Example 1: Input: A = [1,2,1,2,3], K = ...
class Solution: def subarraysWithKDistinct(self, A: List[int], K: int) -> int: if K > len(A): return 0 result = checker = windowStart = 0 hashMap = {} a_length = len(A) for windowEnd in range(a_length): curr_str = A[windowEnd] if curr_str ...
CLASS_DEF FUNC_DEF VAR VAR VAR IF VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR IF FUNC_CALL VAR VAR VA...
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K. (For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.) Return the number of good subarrays of A. Β  Example 1: Input: A = [1,2,1,2,3], K = ...
class Solution: def subarraysWithKDistinct(self, A: List[int], K: int) -> int: left1 = 0 left2 = 0 w1 = {} w2 = {} count = 0 for right, x in enumerate(A): if x in w1: w1[x] += 1 else: w1[x] = 1 if x ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER WHILE FUNC_CALL VAR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ...
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K. (For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.) Return the number of good subarrays of A. Β  Example 1: Input: A = [1,2,1,2,3], K = ...
class Solution: def subarraysWithKDistinct(self, A: List[int], K: int) -> int: result = 0 i, j = 0, 0 cnt = collections.Counter() l = 0 n = len(A) while j < n: if len(cnt) != K: cnt[A[j]] += 1 if len(cnt) == K: ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR...
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K. (For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.) Return the number of good subarrays of A. Β  Example 1: Input: A = [1,2,1,2,3], K = ...
class Solution: def subarraysWithKDistinct(self, A: List[int], K: int) -> int: good_start, bad_start = -1, -1 good_count, bad_count = {}, {} def add(count, element): if element not in count: count[element] = 0 count[element] += 1 def remove(...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR DICT DICT FUNC_DEF IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER FUNC_DEF VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR VAR WHILE VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VA...
This is the hard version of the problem. The difference between the versions is the constraint on $n$ and the required number of operations. You can make hacks only if all versions of the problem are solved. There are two binary strings $a$ and $b$ of length $n$ (a binary string is a string consisting of symbols $0$ a...
str1 = "First" str2 = "Second" def rev(c, cnt): if cnt % 2 == 0: return c if c == "0": c = "1" else: c = "0" return c def solve(): n = int(input()) a = input() b = input() ans = list() l, r = 0, n - 1 for i in range(n): if i % 2 == 0: ...
ASSIGN VAR STRING ASSIGN VAR STRING FUNC_DEF IF BIN_OP VAR NUMBER NUMBER RETURN VAR IF VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC...
This is the hard version of the problem. The difference between the versions is the constraint on $n$ and the required number of operations. You can make hacks only if all versions of the problem are solved. There are two binary strings $a$ and $b$ of length $n$ (a binary string is a string consisting of symbols $0$ a...
import sys input = sys.stdin.readline t = int(input()) for _ in range(t): n = int(input()) a = list(input()) b = list(input()) ans = [] l = 0 r = n - 1 for i in range(n - 1, -1, -1): if a[i] != b[i]: r = i break else: r = 0 if l == r: ...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER...
This is the hard version of the problem. The difference between the versions is the constraint on $n$ and the required number of operations. You can make hacks only if all versions of the problem are solved. There are two binary strings $a$ and $b$ of length $n$ (a binary string is a string consisting of symbols $0$ a...
def order(s): init = s[0] res = [] for i in range(len(s) - 1): if s[i] != s[i + 1]: init = s[i + 1] res.append(i + 1) if init == "1": res.append(len(s)) return res for _ in range(int(input())): n = int(input()) a = input() b = input() res = o...
FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSI...
This is the hard version of the problem. The difference between the versions is the constraint on $n$ and the required number of operations. You can make hacks only if all versions of the problem are solved. There are two binary strings $a$ and $b$ of length $n$ (a binary string is a string consisting of symbols $0$ a...
t = int(input()) while t: t -= 1 n = int(input()) l1 = input() l2 = input() ans = [] revert = False index = -1 for i in range(n): if i % 2 == 0: index += 1 c1 = index else: c1 = n - index - 1 if l1[c1] != l2[n - i - 1]: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER...
This is the hard version of the problem. The difference between the versions is the constraint on $n$ and the required number of operations. You can make hacks only if all versions of the problem are solved. There are two binary strings $a$ and $b$ of length $n$ (a binary string is a string consisting of symbols $0$ a...
for _ in range(int(input())): n = int(input()) s = input() s += "0" t = input() t += "0" t = t[::-1] result = [] for i in range(n): if s[i] != s[i + 1]: result.append(i + 1) for j in range(n): if t[j] != t[j + 1]: result.append(n - j) print...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR...
This is the hard version of the problem. The difference between the versions is the constraint on $n$ and the required number of operations. You can make hacks only if all versions of the problem are solved. There are two binary strings $a$ and $b$ of length $n$ (a binary string is a string consisting of symbols $0$ a...
t = int(input()) for i in range(t): n = int(input()) a = str(input()) b = str(input()) a = a + "0" b = b + "0" ans1 = [] ans2 = [] for j in range(1, n + 1): if a[j] != a[j - 1]: ans1.append(j) if b[j] != b[j - 1]: ans2.append(j) l = len(ans2) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER I...
This is the hard version of the problem. The difference between the versions is the constraint on $n$ and the required number of operations. You can make hacks only if all versions of the problem are solved. There are two binary strings $a$ and $b$ of length $n$ (a binary string is a string consisting of symbols $0$ a...
from _collections import deque for _ in range(int(input())): n = int(input()) a = input() b = input() c = [] ans = 0 for i in range(1, n): if a[i - 1] is not a[i]: c.append(i) ans += 1 if a[-1] is not b[-1]: c.append(n) ans += 1 for i in r...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR...
This is the hard version of the problem. The difference between the versions is the constraint on $n$ and the required number of operations. You can make hacks only if all versions of the problem are solved. There are two binary strings $a$ and $b$ of length $n$ (a binary string is a string consisting of symbols $0$ a...
from sys import stdin t = int(stdin.readline().strip()) for _ in range(t): n = int(stdin.readline().strip()) a = stdin.readline().strip() b = stdin.readline().strip() out = [] for i in range(n - 1): if a[i] != a[i + 1]: out.append(i + 1) current = a[-1] for i in range(n ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ...
This is the hard version of the problem. The difference between the versions is the constraint on $n$ and the required number of operations. You can make hacks only if all versions of the problem are solved. There are two binary strings $a$ and $b$ of length $n$ (a binary string is a string consisting of symbols $0$ a...
def flip(a, flip): if flip % 2 == 0: return a elif a == 1: return 0 else: return 1 for _ in range(int(input())): n = int(input()) a = list(map(int, list(input()))) b = list(map(int, list(input()))) i = 0 j = n - 1 ans = [] flipp = 0 while j >= 0: ...
FUNC_DEF IF BIN_OP VAR NUMBER NUMBER RETURN VAR IF VAR NUMBER RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR...
This is the hard version of the problem. The difference between the versions is the constraint on $n$ and the required number of operations. You can make hacks only if all versions of the problem are solved. There are two binary strings $a$ and $b$ of length $n$ (a binary string is a string consisting of symbols $0$ a...
from sys import stdin, stdout t = int(stdin.readline()) for _ in range(t): n = int(stdin.readline()) a = stdin.readline().strip() b = stdin.readline().strip() ans = [] idx = 0 flip = False for i in range(n - 1, -1, -1): if not flip and a[idx] == b[i] or flip and a[idx] != b[i]: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR VAR VAR VAR VAR VAR V...
This is the hard version of the problem. The difference between the versions is the constraint on $n$ and the required number of operations. You can make hacks only if all versions of the problem are solved. There are two binary strings $a$ and $b$ of length $n$ (a binary string is a string consisting of symbols $0$ a...
t = int(input()) for _ in range(t): n = int(input()) a = input() b = input() aToAllOnesOrZeros = [] for i in range(n - 1): if a[i] != a[i + 1]: aToAllOnesOrZeros.append(i + 1) bToAllOnesOrZeros = [] for i in range(n - 1): if b[i] != b[i + 1]: bToAllOne...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BI...
This is the hard version of the problem. The difference between the versions is the constraint on $n$ and the required number of operations. You can make hacks only if all versions of the problem are solved. There are two binary strings $a$ and $b$ of length $n$ (a binary string is a string consisting of symbols $0$ a...
for _ in range(int(input())): n = int(input()) a = input() l1 = list(a) b = input() l2 = list(b) t1 = [] t2 = [] i = 0 while i < n: while i < n and l1[i] == "0": i += 1 if i == n: break if i > 0: t1.append(i - 1) whi...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR VAR WHILE VAR VAR VAR VAR STRING VAR NUMBER IF VAR VAR IF VAR N...
This is the hard version of the problem. The difference between the versions is the constraint on $n$ and the required number of operations. You can make hacks only if all versions of the problem are solved. There are two binary strings $a$ and $b$ of length $n$ (a binary string is a string consisting of symbols $0$ a...
for _ in range(int(input())): n = int(input()) a = input() b = input() flag = 0 lft = 0 rht = n - 1 res = [] for i in range(n - 1, -1, -1): if flag == 0: if b[i] == a[lft]: res.append(1) lft += 1 else: if b[i] != a[rht]:...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CAL...
This is the hard version of the problem. The difference between the versions is the constraint on $n$ and the required number of operations. You can make hacks only if all versions of the problem are solved. There are two binary strings $a$ and $b$ of length $n$ (a binary string is a string consisting of symbols $0$ a...
def main(r): n = int(input()) a = input() b = input() st = 0 end = n - 1 ln = 0 swaps = "" if len(a) == 1: if a == b: print(0) else: print("1 1") return else: for i in range(0, n): if i % 2 == 0: if a...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING IF FUNC_CALL VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_O...
This is the hard version of the problem. The difference between the versions is the constraint on $n$ and the required number of operations. You can make hacks only if all versions of the problem are solved. There are two binary strings $a$ and $b$ of length $n$ (a binary string is a string consisting of symbols $0$ a...
def get_flipped(x, flips): if flips % 2 == 0: return x else: return "0" if x == "1" else "1" def solve(): n = int(input().strip()) a = input().strip() b = input().strip() ar = [] for i in range(n): this_bit = b[n - i - 1] first_bit = get_flipped(a[i // 2] if...
FUNC_DEF IF BIN_OP VAR NUMBER NUMBER RETURN VAR RETURN VAR STRING STRING STRING FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR B...
This is the hard version of the problem. The difference between the versions is the constraint on $n$ and the required number of operations. You can make hacks only if all versions of the problem are solved. There are two binary strings $a$ and $b$ of length $n$ (a binary string is a string consisting of symbols $0$ a...
for _ in range(int(input())): n = int(input()) a = input() b = input() a += "0" b += "0" l1, l2 = [], [] for i in range(1, n + 1): if a[i] != a[i - 1]: l1.append(i) if b[i] != b[i - 1]: l2.append(i) l2.reverse() l3 = l1 + l2 print(len(l3), ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR STRING VAR STRING ASSIGN VAR VAR LIST LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBE...
This is the hard version of the problem. The difference between the versions is the constraint on $n$ and the required number of operations. You can make hacks only if all versions of the problem are solved. There are two binary strings $a$ and $b$ of length $n$ (a binary string is a string consisting of symbols $0$ a...
for _ in range(int(input())): n = int(input()) a = [int(x) for x in input()] b = [int(x) for x in input()] a.append(0) b.append(0) ans = [] for i in range(n): if a[i] != a[i + 1]: ans.append(i + 1) for i in range(n - 1, -1, -1): if b[i] != b[i + 1]: ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_...
This is the hard version of the problem. The difference between the versions is the constraint on $n$ and the required number of operations. You can make hacks only if all versions of the problem are solved. There are two binary strings $a$ and $b$ of length $n$ (a binary string is a string consisting of symbols $0$ a...
for _ in range(int(input())): n = int(input()) a = [] b = [] a1 = list(input()) b1 = list(input()) for i in a1: a.append(int(i)) for i in b1: b.append(int(i)) pos1 = 0 pos2 = n - 1 reverse = 0 ans = [] for i in range(n - 1, -1, -1): if not reverse:...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIG...
This is the hard version of the problem. The difference between the versions is the constraint on $n$ and the required number of operations. You can make hacks only if all versions of the problem are solved. There are two binary strings $a$ and $b$ of length $n$ (a binary string is a string consisting of symbols $0$ a...
t = int(input()) for _ in range(t): n = int(input()) a = input() b = input() al = 0 ah = len(a) - 1 ac = len(a) - 1 ao = 0 is_flipped = False res = [] for i, c in enumerate(reversed(b)): if (c == a[ac]) ^ is_flipped: if ac == ah: ah -= 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VA...
This is the hard version of the problem. The difference between the versions is the constraint on $n$ and the required number of operations. You can make hacks only if all versions of the problem are solved. There are two binary strings $a$ and $b$ of length $n$ (a binary string is a string consisting of symbols $0$ a...
t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input())) b = list(map(int, input())) ans = [] f = 0 l, r = 0, n - 1 i = n - 1 while l <= r: if f == 0: if a[r] ^ f != b[i]: if a[l] ^ f == b[i]: ans.append(1) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER...
This is the hard version of the problem. The difference between the versions is the constraint on $n$ and the required number of operations. You can make hacks only if all versions of the problem are solved. There are two binary strings $a$ and $b$ of length $n$ (a binary string is a string consisting of symbols $0$ a...
def convert_to_1(s): L = [] for i in range(len(s) - 1): if s[i] != s[i + 1]: L.append(i + 1) if s[-1] == "0": L.append(len(s)) return L for i in " " * int(input()): n = int(input()) s1 = input() s2 = input() L1 = convert_to_1(s1) L2 = convert_to_1(s2) ...
FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN VAR FOR VAR BIN_OP STRING FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FU...
This is the hard version of the problem. The difference between the versions is the constraint on $n$ and the required number of operations. You can make hacks only if all versions of the problem are solved. There are two binary strings $a$ and $b$ of length $n$ (a binary string is a string consisting of symbols $0$ a...
t = int(input()) for i in range(t): n = int(input()) a = list(input()) a = list(map(int, a)) b = list(input()) b = list(map(int, b)) c = [] lst1 = [] i = 0 j = n - 1 idx = 0 while len(c) < n: if idx % 2 == 0: c.append(a[i]) i += 1 i...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR N...
This is the hard version of the problem. The difference between the versions is the constraint on $n$ and the required number of operations. You can make hacks only if all versions of the problem are solved. There are two binary strings $a$ and $b$ of length $n$ (a binary string is a string consisting of symbols $0$ a...
for _ in range(int(input())): n = int(input()) l1 = list(map(int, input())) l2 = list(map(int, input())) flip = False idx = 0 ans = [] for i in range(n - 1, -1, -1): if flip ^ (l1[idx] == l2[i]): ans.append(1) ans.append(i + 1) if flip: idx -= ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP V...
This is the hard version of the problem. The difference between the versions is the constraint on $n$ and the required number of operations. You can make hacks only if all versions of the problem are solved. There are two binary strings $a$ and $b$ of length $n$ (a binary string is a string consisting of symbols $0$ a...
t = int(input()) for _ in range(t): n = int(input()) list1 = list(map(int, input())) list2 = list(map(int, input())) ans = [] start = 0 invert = 0 for i in range(n - 1, 0 - 1, -1): aim = list2[i] if ( invert % 2 == 0 and list1[start + i] == aim ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP NUM...
This is the hard version of the problem. The difference between the versions is the constraint on $n$ and the required number of operations. You can make hacks only if all versions of the problem are solved. There are two binary strings $a$ and $b$ of length $n$ (a binary string is a string consisting of symbols $0$ a...
t = int(input()) while t > 0: t -= 1 n = int(input()) s1 = input() s2 = input() l = 0 r = n - 1 rev = False ans = [] for x in s2[-1::-1]: if not rev: if s1[r] == x: r -= 1 continue if s1[l] == x: ans.appe...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR NUMBER NUMBER IF VAR IF VAR VAR VAR VAR NUMBER IF VAR VAR VAR EXPR FUNC...
This is the hard version of the problem. The difference between the versions is the constraint on $n$ and the required number of operations. You can make hacks only if all versions of the problem are solved. There are two binary strings $a$ and $b$ of length $n$ (a binary string is a string consisting of symbols $0$ a...
for _ in range(int(input())): n = int(input()) a = list(map(int, list(input()))) b = list(map(int, list(input()))) ans = [] a0 = a[0] j = n - 1 k = 1 for i in range(n - 1, -1, -1): if b[i] == a0: ans.append(1) ans.append(i + 1) if (n - i) % 2 == 1: ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR ...
This is the hard version of the problem. The difference between the versions is the constraint on $n$ and the required number of operations. You can make hacks only if all versions of the problem are solved. There are two binary strings $a$ and $b$ of length $n$ (a binary string is a string consisting of symbols $0$ a...
def find(s1, s2): if len(s1) == 1: if s1 == s2: return [] else: return [1] indices = [-1] * len(s1) cur = len(s1) - 1 val = 0 for i in range(len(s1)): indices[cur] = val cur -= 2 val += 1 if cur < 0: break if ind...
FUNC_DEF IF FUNC_CALL VAR VAR NUMBER IF VAR VAR RETURN LIST RETURN LIST NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBE...
This is the hard version of the problem. The difference between the versions is the constraint on $n$ and the required number of operations. You can make hacks only if all versions of the problem are solved. There are two binary strings $a$ and $b$ of length $n$ (a binary string is a string consisting of symbols $0$ a...
import sys def input(): return sys.stdin.readline().rstrip() def input_split(): return [int(i) for i in input().split()] testCases = int(input()) answers = [] def update_zero(arr, diff, num_flips): if num_flips % 2 == 0: i = -diff arr[i] = 1 - arr[i] else: i = diff ...
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_DEF IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR VAR BIN_OP NUMBER VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR BIN_OP NUMBER VAR VAR FUNC_DEF IF BIN...
This is the hard version of the problem. The difference between the versions is the constraint on $n$ and the required number of operations. You can make hacks only if all versions of the problem are solved. There are two binary strings $a$ and $b$ of length $n$ (a binary string is a string consisting of symbols $0$ a...
import sys r = sys.stdin.readline def revAndnot(bit, idx): tmp = "" for i in range(idx): tmp += "1" if bit[i] == "0" else "0" return tmp[::-1] + bit[idx:] for _ in range(int(r())): n = int(r()) a = r().strip() b = r().strip() ans = [] flip = False idx = 0 for i in ra...
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR VAR VAR STRING STRING STRING RETURN BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSI...
This is the hard version of the problem. The difference between the versions is the constraint on $n$ and the required number of operations. You can make hacks only if all versions of the problem are solved. There are two binary strings $a$ and $b$ of length $n$ (a binary string is a string consisting of symbols $0$ a...
for _ in range(int(input())): n = int(input()) a = list(map(int, input())) b = list(map(int, input())) l, r = 0, n - 1 f = 0 o = [] while l != r: k = abs(r - l) if a[r] ^ f != b[k]: if a[l] ^ f == b[k]: o += (1,) o += (k + 1,) ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_...
This is the hard version of the problem. The difference between the versions is the constraint on $n$ and the required number of operations. You can make hacks only if all versions of the problem are solved. There are two binary strings $a$ and $b$ of length $n$ (a binary string is a string consisting of symbols $0$ a...
def task(): n = int(input()) a = input() b = input() answer = [] j = len(b) - 1 for i in range(len(a)): if i % 2 == 0: i1 = i // 2 else: i1 = n - 1 - i // 2 c = a[i1] if i % 2 != 0: c = "0" if c == "1" else "1" if c == b...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR V...
This is the hard version of the problem. The difference between the versions is the constraint on $n$ and the required number of operations. You can make hacks only if all versions of the problem are solved. There are two binary strings $a$ and $b$ of length $n$ (a binary string is a string consisting of symbols $0$ a...
for i in range(int(input())): n = int(input()) a = input() + "0" b = input() + "0" aToZero = [] bToZero = [] for i in range(0, n): if a[i] != a[i + 1]: aToZero.append(i + 1) if b[i] != b[i + 1]: bToZero.append(i + 1) aToZero += bToZero[::-1] print(...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN...
This is the hard version of the problem. The difference between the versions is the constraint on $n$ and the required number of operations. You can make hacks only if all versions of the problem are solved. There are two binary strings $a$ and $b$ of length $n$ (a binary string is a string consisting of symbols $0$ a...
t = int(input()) while t: t -= 1 n = int(input()) s1 = list(map(int, input())) s2 = list(map(int, input())) ans = [] start = 0 end = n - 1 flipped = 0 for i in range(n - 1, -1, -1): if end > start: if s1[end] == s2[i]: end -= 1 cont...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_...
This is the hard version of the problem. The difference between the versions is the constraint on $n$ and the required number of operations. You can make hacks only if all versions of the problem are solved. There are two binary strings $a$ and $b$ of length $n$ (a binary string is a string consisting of symbols $0$ a...
for tc in range(int(input())): n = int(input()) A = input() B = input() steps = [] for i in range(n): if i % 2 == 0: if A[int(i / 2)] != B[n - 1 - i]: steps.append(n - i) else: steps.append(1) steps.append(n - i) ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR ...
This is the hard version of the problem. The difference between the versions is the constraint on $n$ and the required number of operations. You can make hacks only if all versions of the problem are solved. There are two binary strings $a$ and $b$ of length $n$ (a binary string is a string consisting of symbols $0$ a...
import sys input = sys.stdin.readline T = int(input()) for _ in range(T): n = int(input()) a = input() b = input() scheck = [] pos = 0 pos1 = n - 1 reverse = 0 for j in range(n - 1, -1, -1): if not reverse: if a[pos] != b[j]: scheck.append(j + 1) ...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR IF...
This is the hard version of the problem. The difference between the versions is the constraint on $n$ and the required number of operations. You can make hacks only if all versions of the problem are solved. There are two binary strings $a$ and $b$ of length $n$ (a binary string is a string consisting of symbols $0$ a...
import sys from sys import stdin tt = int(input()) for loop in range(tt): n = int(input()) a = input() b = input() if n == None: if a[0] == b[0]: print(0) else: print(1, 1) sys.exit() ind = [None] * n tmp = 0 for i in range(n - 1, -1, -2): ...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR NONE IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR N...
This is the hard version of the problem. The difference between the versions is the constraint on $n$ and the required number of operations. You can make hacks only if all versions of the problem are solved. There are two binary strings $a$ and $b$ of length $n$ (a binary string is a string consisting of symbols $0$ a...
for _ in range(int(input())): n = int(input()) arr = list(input()) brr = list(input()) a = 0 b = n - 1 k = 0 ans = [] for i in range(n - 1, -1, -1): if k == 0: if arr[a] == brr[i]: ans.append(1) ans.append(i + 1) k = 1 ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER IF V...
This is the hard version of the problem. The difference between the versions is the constraint on $n$ and the required number of operations. You can make hacks only if all versions of the problem are solved. There are two binary strings $a$ and $b$ of length $n$ (a binary string is a string consisting of symbols $0$ a...
for _ in range(int(input())): n = int(input()) A = input() B = input() a = [] b = [] for i in A: a.append(i) for i in B: b.append(i) c = [] cnt = 0 x = 0 y = n - 1 for i in range(n - 1, -1, -1): if cnt % 2 == 0: if b[i] == "1": ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBE...