description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
Given two arrays of integers nums1 and nums2, return the number of triplets formed (type 1 and type 2) under the following rules:
Type 1: Triplet (i, j, k) if nums1[i]2 == nums2[j] * nums2[k] where 0 <= i < nums1.length and 0 <= j < k < nums2.length.
Type 2: Triplet (i, j, k) if nums2[i]2 == nums1[j] * nums1[k] where ... | class Solution:
def numTriplets(self, nums1: List[int], nums2: List[int]) -> int:
n = len(nums1)
m = len(nums2)
nums1prod = [[(nums1[i] * nums1[j]) for i in range(n)] for j in range(n)]
nums2prod = [[(nums2[i] * nums2[j]) for i in range(m)] for j in range(m)]
nums1sq = [(x**... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR V... |
Given two arrays of integers nums1 and nums2, return the number of triplets formed (type 1 and type 2) under the following rules:
Type 1: Triplet (i, j, k) if nums1[i]2 == nums2[j] * nums2[k] where 0 <= i < nums1.length and 0 <= j < k < nums2.length.
Type 2: Triplet (i, j, k) if nums2[i]2 == nums1[j] * nums1[k] where ... | class Solution:
def numTriplets(self, nums1: List[int], nums2: List[int]) -> int:
ans = 0
n = len(nums1)
m = len(nums2)
sq1 = list(map(lambda x: x**2, nums1))
sq2 = list(map(lambda x: x**2, nums2))
d1 = dict()
d2 = dict()
for num1 in list(set(nums1)):... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR V... |
Given two arrays of integers nums1 and nums2, return the number of triplets formed (type 1 and type 2) under the following rules:
Type 1: Triplet (i, j, k) if nums1[i]2 == nums2[j] * nums2[k] where 0 <= i < nums1.length and 0 <= j < k < nums2.length.
Type 2: Triplet (i, j, k) if nums2[i]2 == nums1[j] * nums1[k] where ... | class Solution:
def numTriplets(self, nums1: List[int], nums2: List[int]) -> int:
def cal(nums1, nums2):
ans = 0
for a in nums1:
d = collections.defaultdict(lambda: 0)
sq = a * a
for ib in range(0, len(nums2)):
b =... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER IF VAR NUMBER VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR VAR VAR VAR VAR NUMB... |
Given two arrays of integers nums1 and nums2, return the number of triplets formed (type 1 and type 2) under the following rules:
Type 1: Triplet (i, j, k) if nums1[i]2 == nums2[j] * nums2[k] where 0 <= i < nums1.length and 0 <= j < k < nums2.length.
Type 2: Triplet (i, j, k) if nums2[i]2 == nums1[j] * nums1[k] where ... | class Solution:
def wrapper(self, toSquare, toProd):
table = {}
for integer in toSquare:
squared = integer**2
if squared not in table:
table[squared] = 1
else:
table[squared] += 1
counter = 0
i = 0
while i <... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER VAR NUM... |
Given two arrays of integers nums1 and nums2, return the number of triplets formed (type 1 and type 2) under the following rules:
Type 1: Triplet (i, j, k) if nums1[i]2 == nums2[j] * nums2[k] where 0 <= i < nums1.length and 0 <= j < k < nums2.length.
Type 2: Triplet (i, j, k) if nums2[i]2 == nums1[j] * nums1[k] where ... | class Solution:
def numTriplets(self, nums1: List[int], nums2: List[int]) -> int:
def fun(arr):
res = {}
for i in range(len(arr) - 1):
for j in range(i + 1, len(arr)):
if arr[i] * arr[j] in res.keys():
res[arr[i] * arr[j]]... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR FUNC_DEF ASSIGN VAR DICT FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL V... |
Given two arrays of integers nums1 and nums2, return the number of triplets formed (type 1 and type 2) under the following rules:
Type 1: Triplet (i, j, k) if nums1[i]2 == nums2[j] * nums2[k] where 0 <= i < nums1.length and 0 <= j < k < nums2.length.
Type 2: Triplet (i, j, k) if nums2[i]2 == nums1[j] * nums1[k] where ... | class Solution:
def numTriplets(self, nums1: List[int], nums2: List[int]) -> int:
def helper(nums, lookup):
res = 0
for maxNum in nums:
prod = maxNum * maxNum
for n in lookup.keys():
if n <= maxNum and not prod % n:
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR IF VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER BIN_OP VAR VAR VAR VAR RETURN VAR RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR... |
Given two arrays of integers nums1 and nums2, return the number of triplets formed (type 1 and type 2) under the following rules:
Type 1: Triplet (i, j, k) if nums1[i]2 == nums2[j] * nums2[k] where 0 <= i < nums1.length and 0 <= j < k < nums2.length.
Type 2: Triplet (i, j, k) if nums2[i]2 == nums1[j] * nums1[k] where ... | class Solution:
def numTriplets(self, nums1: List[int], nums2: List[int]) -> int:
m = len(nums1)
n = len(nums2)
mat2 = [[(0) for i in range(n)] for i in range(n)]
def fillUpper(m, nums):
mat = [[(0) for i in range(m)] for i in range(m)]
mapp1 = defaultdict(i... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN... |
Given two arrays of integers nums1 and nums2, return the number of triplets formed (type 1 and type 2) under the following rules:
Type 1: Triplet (i, j, k) if nums1[i]2 == nums2[j] * nums2[k] where 0 <= i < nums1.length and 0 <= j < k < nums2.length.
Type 2: Triplet (i, j, k) if nums2[i]2 == nums1[j] * nums1[k] where ... | class Solution:
def numTriplets(self, nums1: List[int], nums2: List[int]) -> int:
rev, n1, n2 = 0, Counter(nums1), Counter(nums2)
for i in range(len(nums1) - 1):
for j in range(i + 1, len(nums1)):
t = (nums1[i] * nums1[j]) ** (1 / 2)
if t == int(t) and t ... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP NUMBER NUMBER IF VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR FOR ... |
Given two arrays of integers nums1 and nums2, return the number of triplets formed (type 1 and type 2) under the following rules:
Type 1: Triplet (i, j, k) if nums1[i]2 == nums2[j] * nums2[k] where 0 <= i < nums1.length and 0 <= j < k < nums2.length.
Type 2: Triplet (i, j, k) if nums2[i]2 == nums1[j] * nums1[k] where ... | class Solution:
def numTriplets(self, nums1: List[int], nums2: List[int]) -> int:
m1, m2 = collections.Counter(), collections.Counter()
result = 0
for i in range(len(nums1) - 1):
for j in range(i + 1, len(nums1)):
n = sqrt(nums1[i] * nums1[j])
if ... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR... |
Given two arrays of integers nums1 and nums2, return the number of triplets formed (type 1 and type 2) under the following rules:
Type 1: Triplet (i, j, k) if nums1[i]2 == nums2[j] * nums2[k] where 0 <= i < nums1.length and 0 <= j < k < nums2.length.
Type 2: Triplet (i, j, k) if nums2[i]2 == nums1[j] * nums1[k] where ... | class Solution:
def numTriplets(self, nums1: List[int], nums2: List[int]) -> int:
comp1, comp2 = defaultdict(set), defaultdict(set)
if not nums1 or not nums2:
return 0
n, m = len(nums1), len(nums2)
ans = 0
c1, c2 = Counter([(num**2) for num in nums1]), Counter(
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL V... |
Given two arrays of integers nums1 and nums2, return the number of triplets formed (type 1 and type 2) under the following rules:
Type 1: Triplet (i, j, k) if nums1[i]2 == nums2[j] * nums2[k] where 0 <= i < nums1.length and 0 <= j < k < nums2.length.
Type 2: Triplet (i, j, k) if nums2[i]2 == nums1[j] * nums1[k] where ... | class Solution:
def numTriplets(self, nums1: List[int], nums2: List[int]) -> int:
def count(nums1, nums2):
pairs = []
N1, N2 = len(nums1), len(nums2)
result = 0
for i in range(N2):
for j in range(i + 1, N2):
pairs.append((... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER VAR VAR V... |
Given two arrays of integers nums1 and nums2, return the number of triplets formed (type 1 and type 2) under the following rules:
Type 1: Triplet (i, j, k) if nums1[i]2 == nums2[j] * nums2[k] where 0 <= i < nums1.length and 0 <= j < k < nums2.length.
Type 2: Triplet (i, j, k) if nums2[i]2 == nums1[j] * nums1[k] where ... | class Solution:
def numTriplets(self, nums1: List[int], nums2: List[int]) -> int:
dic1, dic2 = collections.Counter(nums1), collections.Counter(nums2)
ans = 0
m, n = len(nums1), len(nums2)
for i in range(m):
for j in range(i + 1, m):
target = nums1[i] * nu... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VA... |
Given two arrays of integers nums1 and nums2, return the number of triplets formed (type 1 and type 2) under the following rules:
Type 1: Triplet (i, j, k) if nums1[i]2 == nums2[j] * nums2[k] where 0 <= i < nums1.length and 0 <= j < k < nums2.length.
Type 2: Triplet (i, j, k) if nums2[i]2 == nums1[j] * nums1[k] where ... | class Solution:
def numTriplets(self, a: List[int], b: List[int]) -> int:
n = len(a)
m = len(b)
pro1 = {}
pro2 = {}
for i in range(n):
for j in range(n):
if i != j:
pro1[a[i] * a[j]] = (
pro1[a[i] * a[j]... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR V... |
Given two arrays of integers nums1 and nums2, return the number of triplets formed (type 1 and type 2) under the following rules:
Type 1: Triplet (i, j, k) if nums1[i]2 == nums2[j] * nums2[k] where 0 <= i < nums1.length and 0 <= j < k < nums2.length.
Type 2: Triplet (i, j, k) if nums2[i]2 == nums1[j] * nums1[k] where ... | class Solution:
def numTriplets(self, nums1: List[int], nums2: List[int]) -> int:
n1 = [(x * x) for x in nums1]
n2 = [(x * x) for x in nums2]
dnum1 = collections.Counter(n1)
dnum2 = collections.Counter(n2)
ans = 0
nums1.sort()
nums2.sort()
m1 = max(dn... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN... |
Given two arrays of integers nums1 and nums2, return the number of triplets formed (type 1 and type 2) under the following rules:
Type 1: Triplet (i, j, k) if nums1[i]2 == nums2[j] * nums2[k] where 0 <= i < nums1.length and 0 <= j < k < nums2.length.
Type 2: Triplet (i, j, k) if nums2[i]2 == nums1[j] * nums1[k] where ... | class Solution:
def numTriplets(self, nums1: List[int], nums2: List[int]) -> int:
def helper(nums1, nums2):
s = [(n * n) for n in nums1]
count = 0
d = collections.defaultdict(list)
for i in range(len(nums2)):
d[nums2[i]].append(i)
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR FUNC_DEF ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER BIN_OP VAR VAR VAR VAR IF VAR VAR BIN_OP VA... |
Given two arrays of integers nums1 and nums2, return the number of triplets formed (type 1 and type 2) under the following rules:
Type 1: Triplet (i, j, k) if nums1[i]2 == nums2[j] * nums2[k] where 0 <= i < nums1.length and 0 <= j < k < nums2.length.
Type 2: Triplet (i, j, k) if nums2[i]2 == nums1[j] * nums1[k] where ... | class Solution:
def numTriplets(self, nums1: List[int], nums2: List[int]) -> int:
ret = 0
m, n = len(nums1), len(nums2)
_map1, _map2 = Counter(nums1), Counter(nums2)
for i in range(m):
nums2_map = {**_map2}
for j in range(n):
nums2_map[nums2[j... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR DICT VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR NUMB... |
Given two arrays of integers nums1 and nums2, return the number of triplets formed (type 1 and type 2) under the following rules:
Type 1: Triplet (i, j, k) if nums1[i]2 == nums2[j] * nums2[k] where 0 <= i < nums1.length and 0 <= j < k < nums2.length.
Type 2: Triplet (i, j, k) if nums2[i]2 == nums1[j] * nums1[k] where ... | class Solution:
def numTriplets(self, nums1: List[int], nums2: List[int]) -> int:
d = {}
ct = 0
M = len(nums1)
N = len(nums2)
for i in range(M):
if nums1[i] * nums1[i] in d:
d[nums1[i] * nums1[i]] += 1
else:
d[nums1[i] ... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUM... |
Given two arrays of integers nums1 and nums2, return the number of triplets formed (type 1 and type 2) under the following rules:
Type 1: Triplet (i, j, k) if nums1[i]2 == nums2[j] * nums2[k] where 0 <= i < nums1.length and 0 <= j < k < nums2.length.
Type 2: Triplet (i, j, k) if nums2[i]2 == nums1[j] * nums1[k] where ... | class Solution:
def numTriplets(self, nums1: List[int], nums2: List[int]) -> int:
def count(n1, n2):
l2 = len(n2)
cnt = Counter()
for k in range(l2):
for j in range(k):
v = n2[k] * n2[j]
cnt[v] += 1
ans... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR BIN_OP VAR VAR RETURN VAR RETURN BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR... |
Given two lists of closed intervals, each list of intervals is pairwise disjoint and in sorted order.
Return the intersection of these two interval lists.
(Formally, a closed interval [a, b] (with a <= b) denotes the set of real numbers x with a <= x <= b. The intersection of two closed intervals is a set of real numb... | class Solution:
def intervalIntersection(
self, A: List[List[int]], B: List[List[int]]
) -> List[List[int]]:
res = []
while A and B:
start1, end1 = A[0][0], A[0][1]
start2, end2 = B[0][0], B[0][1]
if end1 <= end2:
if start2 <= start1:
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR VAR ASSIGN VAR LIST WHILE VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER VAR NUMBER NUMBER IF VAR VAR IF VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR IF VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL ... |
Given two lists of closed intervals, each list of intervals is pairwise disjoint and in sorted order.
Return the intersection of these two interval lists.
(Formally, a closed interval [a, b] (with a <= b) denotes the set of real numbers x with a <= x <= b. The intersection of two closed intervals is a set of real numb... | class Solution:
def overlap(self, lst):
lst.sort(key=lambda x: x[0])
if lst[0][1] >= lst[1][0]:
return True
return False
def add_data(self, start_a, end_a, start_b, end_b, res):
if self.overlap([(start_a, end_a), (start_b, end_b)]):
start, end = max(star... | CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF IF FUNC_CALL VAR LIST VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF VAR VAR VAR VAR VAR VAR IF VAR VAR R... |
Given two lists of closed intervals, each list of intervals is pairwise disjoint and in sorted order.
Return the intersection of these two interval lists.
(Formally, a closed interval [a, b] (with a <= b) denotes the set of real numbers x with a <= x <= b. The intersection of two closed intervals is a set of real numb... | class Solution:
def intervalIntersection(
self, A: List[List[int]], B: List[List[int]]
) -> List[List[int]]:
intervals = deque()
while A and B:
a, b = A[-1], B[-1]
x, y = max(a[0], b[0]), min(a[1], b[1])
if x <= y:
intervals.appendleft... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR WHILE VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR RETURN VAR VAR VAR VAR |
Given two lists of closed intervals, each list of intervals is pairwise disjoint and in sorted order.
Return the intersection of these two interval lists.
(Formally, a closed interval [a, b] (with a <= b) denotes the set of real numbers x with a <= x <= b. The intersection of two closed intervals is a set of real numb... | class Solution:
def intervalIntersection(
self, A: List[List[int]], B: List[List[int]]
) -> List[List[int]]:
extremum = [item for t in A for item in t] + [item for t in B for item in t]
extremum.sort()
counter_a = 0
counter_b = 0
next_a = A[counter_a] if A else N... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR NONE ASSIGN VAR VAR VAR VAR NONE ASSIGN VAR VAR VAR NUMBER NUMBER NONE ASSIGN VAR VAR VAR NUMBER NUMBER NONE ASSIGN VAR DICT FUNC_DEF VAR VAR... |
Given two lists of closed intervals, each list of intervals is pairwise disjoint and in sorted order.
Return the intersection of these two interval lists.
(Formally, a closed interval [a, b] (with a <= b) denotes the set of real numbers x with a <= x <= b. The intersection of two closed intervals is a set of real numb... | class Solution:
def intervalIntersection(
self, A: List[List[int]], B: List[List[int]]
) -> List[List[int]]:
if not A or not B:
return []
ans = []
i = j = 0
while i < len(A) and j < len(B):
lo = max(A[i][0], B[j][0])
hi = min(A[i][1], ... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR VAR IF VAR VAR RETURN LIST ASSIGN VAR LIST ASSIGN VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR IF VAR VAR NU... |
Given two lists of closed intervals, each list of intervals is pairwise disjoint and in sorted order.
Return the intersection of these two interval lists.
(Formally, a closed interval [a, b] (with a <= b) denotes the set of real numbers x with a <= x <= b. The intersection of two closed intervals is a set of real numb... | class Solution:
def intervalIntersection(
self, A: List[List[int]], B: List[List[int]]
) -> List[List[int]]:
time_points = list()
for interval in A + B:
time_points.append((interval[0], +1))
time_points.append((interval[1] + 1, -1))
sorted_points = sorted... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR B... |
Given two lists of closed intervals, each list of intervals is pairwise disjoint and in sorted order.
Return the intersection of these two interval lists.
(Formally, a closed interval [a, b] (with a <= b) denotes the set of real numbers x with a <= x <= b. The intersection of two closed intervals is a set of real numb... | class Solution:
def intervalIntersection(
self, A: List[List[int]], B: List[List[int]]
) -> List[List[int]]:
if not A or not B:
return []
MergedList = A + B
MergedList.sort()
result = []
for i in range(len(MergedList)):
if i == 0:
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR VAR IF VAR VAR RETURN LIST ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR LIST FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER FUNC_CALL ... |
Given two lists of closed intervals, each list of intervals is pairwise disjoint and in sorted order.
Return the intersection of these two interval lists.
(Formally, a closed interval [a, b] (with a <= b) denotes the set of real numbers x with a <= x <= b. The intersection of two closed intervals is a set of real numb... | class Solution:
def intervalIntersection(
self, A: List[List[int]], B: List[List[int]]
) -> List[List[int]]:
self.k1 = None
self.k2 = None
self.res2 = []
def intersections_append2(k: (int, int), v: int):
k1 = self.k1
k2 = self.k2
if k... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR VAR ASSIGN VAR NONE ASSIGN VAR NONE ASSIGN VAR LIST FUNC_DEF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NONE VAR NONE VAR NUMBER VAR VAR NUMBER VAR IF VAR EXPR FUNC_CALL VAR NUMBER VAR IF FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR NUMBE... |
Given two lists of closed intervals, each list of intervals is pairwise disjoint and in sorted order.
Return the intersection of these two interval lists.
(Formally, a closed interval [a, b] (with a <= b) denotes the set of real numbers x with a <= x <= b. The intersection of two closed intervals is a set of real numb... | class Solution:
def intervalIntersection(
self, A: List[List[int]], B: List[List[int]]
) -> List[List[int]]:
i = 0
j = 0
ans = []
while i < len(A) and j < len(B):
if A[i][0] >= B[j][0] and A[i][1] <= B[j][1]:
ans.append([A[i][0], A[i][1]])
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER... |
Given two lists of closed intervals, each list of intervals is pairwise disjoint and in sorted order.
Return the intersection of these two interval lists.
(Formally, a closed interval [a, b] (with a <= b) denotes the set of real numbers x with a <= x <= b. The intersection of two closed intervals is a set of real numb... | class Solution:
def intervalIntersection(
self, A: List[List[int]], B: List[List[int]]
) -> List[List[int]]:
state = [False, False]
A_index = [0, 0]
B_index = [0, 0]
result = []
def get_event(events, index):
if index[0] >= len(events):
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR VAR ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR LIST FUNC_DEF IF VAR NUMBER FUNC_CALL VAR VAR RETURN NUMBER RETURN VAR VAR NUMBER VAR NUMBER WHILE NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR V... |
Given two lists of closed intervals, each list of intervals is pairwise disjoint and in sorted order.
Return the intersection of these two interval lists.
(Formally, a closed interval [a, b] (with a <= b) denotes the set of real numbers x with a <= x <= b. The intersection of two closed intervals is a set of real numb... | class Solution:
def intervalIntersection(
self, A: List[List[int]], B: List[List[int]]
) -> List[List[int]]:
i = 0
j = 0
result = []
while i < len(A) and j < len(B):
if self.overlap(A[i], B[j]):
result.append(self.intersection(A[i], B[j]))
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR VAR VAR VAR FUNC_DEF RETURN... |
Given two lists of closed intervals, each list of intervals is pairwise disjoint and in sorted order.
Return the intersection of these two interval lists.
(Formally, a closed interval [a, b] (with a <= b) denotes the set of real numbers x with a <= x <= b. The intersection of two closed intervals is a set of real numb... | class Solution:
def intervalIntersection(
self, A: List[List[int]], B: List[List[int]]
) -> List[List[int]]:
if not A or not B:
return []
m, n = len(A), len(B)
result = []
i = j = 0
while i < m and j < n:
start = max(A[i][0], B[j][0])
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR VAR IF VAR VAR RETURN LIST ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR NUMBER WHILE VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR LIS... |
Given two lists of closed intervals, each list of intervals is pairwise disjoint and in sorted order.
Return the intersection of these two interval lists.
(Formally, a closed interval [a, b] (with a <= b) denotes the set of real numbers x with a <= x <= b. The intersection of two closed intervals is a set of real numb... | class Solution:
def intervalIntersection(
self, A: List[List[int]], B: List[List[int]]
) -> List[List[int]]:
counter_a = 0
counter_b = 0
next_a = A[counter_a] if A else None
next_b = B[counter_b] if B else None
max_a = A[-1][1] if A else None
max_b = B[-1... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR NONE ASSIGN VAR VAR VAR VAR NONE ASSIGN VAR VAR VAR NUMBER NUMBER NONE ASSIGN VAR VAR VAR NUMBER NUMBER NONE ASSIGN VAR NONE ASSIGN VAR NONE ASSIGN VAR LIST FUNC_DEF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NON... |
Given two lists of closed intervals, each list of intervals is pairwise disjoint and in sorted order.
Return the intersection of these two interval lists.
(Formally, a closed interval [a, b] (with a <= b) denotes the set of real numbers x with a <= x <= b. The intersection of two closed intervals is a set of real numb... | class Solution:
def intervalIntersection(
self, A: List[List[int]], B: List[List[int]]
) -> List[List[int]]:
res3 = []
self.k1 = None
self.k2 = None
self.res2 = []
def intersections_append2(k: (int, int), v: int):
k1 = self.k1
k2 = self.k... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR NONE ASSIGN VAR NONE ASSIGN VAR LIST FUNC_DEF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NONE VAR NONE VAR NUMBER VAR VAR NUMBER VAR IF VAR EXPR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR LIST VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER EX... |
Given two lists of closed intervals, each list of intervals is pairwise disjoint and in sorted order.
Return the intersection of these two interval lists.
(Formally, a closed interval [a, b] (with a <= b) denotes the set of real numbers x with a <= x <= b. The intersection of two closed intervals is a set of real numb... | class Solution:
def intervalIntersection(
self, A: List[List[int]], B: List[List[int]]
) -> List[List[int]]:
result = []
while len(A) != 0 and len(B) != 0:
a_start, a_end = A[0]
b_start, b_end = B[0]
start = max(a_start, b_start)
end = min... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR VAR ASSIGN VAR LIST WHILE FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR LI... |
Given two lists of closed intervals, each list of intervals is pairwise disjoint and in sorted order.
Return the intersection of these two interval lists.
(Formally, a closed interval [a, b] (with a <= b) denotes the set of real numbers x with a <= x <= b. The intersection of two closed intervals is a set of real numb... | class Solution:
def intervalIntersection(
self, A: List[List[int]], B: List[List[int]]
) -> List[List[int]]:
p1, p2 = 0, 0
res = []
while p1 < len(A) and p2 < len(B):
if not (B[p2][1] < A[p1][0] or A[p1][1] < B[p2][0]):
res.append((max(A[p1][0], B[p2]... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR LIST WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR N... |
Given two lists of closed intervals, each list of intervals is pairwise disjoint and in sorted order.
Return the intersection of these two interval lists.
(Formally, a closed interval [a, b] (with a <= b) denotes the set of real numbers x with a <= x <= b. The intersection of two closed intervals is a set of real numb... | class Solution:
def intervalIntersection(
self, A: List[List[int]], B: List[List[int]]
) -> List[List[int]]:
NA = len(A)
NB = len(B)
if NA == 0 or NB == 0:
return []
pA = 0
pB = 0
res = []
while pA < NA and pB < NB:
sA = A[... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER RETURN LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF V... |
Given two lists of closed intervals, each list of intervals is pairwise disjoint and in sorted order.
Return the intersection of these two interval lists.
(Formally, a closed interval [a, b] (with a <= b) denotes the set of real numbers x with a <= x <= b. The intersection of two closed intervals is a set of real numb... | class Solution:
def intervalIntersection(
self, A: List[List[int]], B: List[List[int]]
) -> List[List[int]]:
ans = []
if not A or not B:
return ans
cur_a = A.pop(0)
cur_b = B.pop(0)
while cur_a and cur_b:
if cur_a[0] <= cur_b[1] and cur_a[... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR VAR ASSIGN VAR LIST IF VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER WHILE VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST FUNC_CALL VAR VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR IF ... |
Given two lists of closed intervals, each list of intervals is pairwise disjoint and in sorted order.
Return the intersection of these two interval lists.
(Formally, a closed interval [a, b] (with a <= b) denotes the set of real numbers x with a <= x <= b. The intersection of two closed intervals is a set of real numb... | class Solution:
def intervalIntersection(
self, A: List[List[int]], B: List[List[int]]
) -> List[List[int]]:
res3 = []
a_idx = 0
b_idx = 0
if a_idx >= len(A) or b_idx >= len(B):
return []
redo_step = False
while a_idx < len(A) and b_idx < len(... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR RETURN LIST ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER VA... |
Given two lists of closed intervals, each list of intervals is pairwise disjoint and in sorted order.
Return the intersection of these two interval lists.
(Formally, a closed interval [a, b] (with a <= b) denotes the set of real numbers x with a <= x <= b. The intersection of two closed intervals is a set of real numb... | def intersection(a: List, b: List) -> List:
l = max(a[0], b[0])
r = min(a[1], b[1])
if l <= r:
return [l, r]
else:
return None
def union(a: List, b: List) -> List:
l = min(a[0], b[0])
r = max(a[1], b[1])
i = intersection(a, b)
if i:
return [l, r]
else:
... | FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR VAR RETURN LIST VAR VAR RETURN NONE VAR FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR RETURN LIST... |
Given two lists of closed intervals, each list of intervals is pairwise disjoint and in sorted order.
Return the intersection of these two interval lists.
(Formally, a closed interval [a, b] (with a <= b) denotes the set of real numbers x with a <= x <= b. The intersection of two closed intervals is a set of real numb... | class Solution:
def intervalIntersection(
self, A: List[List[int]], B: List[List[int]]
) -> List[List[int]]:
ite1 = 0
ite2 = 0
lenA = len(A)
lenB = len(B)
ans = []
while ite1 < lenA and ite2 < lenB:
curA = A[ite1]
curB = B[ite2]
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST WHILE VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC... |
Given two lists of closed intervals, each list of intervals is pairwise disjoint and in sorted order.
Return the intersection of these two interval lists.
(Formally, a closed interval [a, b] (with a <= b) denotes the set of real numbers x with a <= x <= b. The intersection of two closed intervals is a set of real numb... | class Solution:
def intervalIntersection(
self, A: List[List[int]], B: List[List[int]]
) -> List[List[int]]:
i, j = 0, 0
res = []
A.append([math.inf, math.inf])
B.append([math.inf, math.inf])
while i < len(A) - 1 or j < len(B) - 1:
(i1_s, i1_e), (i2_s... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR IF VAR VAR EXPR FUNC_CALL VAR LIST FUNC_... |
Given two lists of closed intervals, each list of intervals is pairwise disjoint and in sorted order.
Return the intersection of these two interval lists.
(Formally, a closed interval [a, b] (with a <= b) denotes the set of real numbers x with a <= x <= b. The intersection of two closed intervals is a set of real numb... | class Solution:
def intervalIntersection(
self, A: List[List[int]], B: List[List[int]]
) -> List[List[int]]:
if len(A) == 0 or len(B) == 0:
return []
a_start, a_end = A[0]
b_start, b_end = B[0]
start = max(a_start, b_start)
end = min(a_end, b_end)
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER RETURN LIST ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR IF VAR VAR RETURN FUNC_CALL VAR VAR VAR NUMBER RETURN FUNC_CALL VAR VAR NUMBER VAR ... |
Given two lists of closed intervals, each list of intervals is pairwise disjoint and in sorted order.
Return the intersection of these two interval lists.
(Formally, a closed interval [a, b] (with a <= b) denotes the set of real numbers x with a <= x <= b. The intersection of two closed intervals is a set of real numb... | class Solution:
def intervalIntersection(
self, A: List[List[int]], B: List[List[int]]
) -> List[List[int]]:
i, j, ans = 0, 0, []
while i < len(A) and j < len(B):
a, b = A[i], B[j]
if not (a[1] < b[0] or a[0] > b[1]):
ans.append([max(a[0], b[0]), ... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER LIST WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST FUNC_CALL VAR VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR NUMBER V... |
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given 2 arrays W = (W_{1}, W_{2}, .., W_{N}) and C = (C_{1}, C_{2}, .., C_{N}) with N elements each. A range [l, r] is unique if all the elements C_{l}, C_{l+1}, .., C_{r} are unique (ie. no duplicates). The sum of the range is W_... | for _ in range(int(input())):
input()
C = list(map(int, input().split()))
W = list(map(int, input().split()))
s, i = set([C[0]]), 0
c = mx = W[0]
for j in range(1, len(C)):
while C[j] in s:
mx = max(mx, c)
s.remove(C[i])
c -= W[i]
i += 1
... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR LIST VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL ... |
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given 2 arrays W = (W_{1}, W_{2}, .., W_{N}) and C = (C_{1}, C_{2}, .., C_{N}) with N elements each. A range [l, r] is unique if all the elements C_{l}, C_{l+1}, .., C_{r} are unique (ie. no duplicates). The sum of the range is W_... | def solution(C, W):
low = 0
k = {}
k[C[low]] = 0
maxi = W[0]
ans = W[0]
for i in range(1, len(C)):
if C[i] not in k.keys():
ans += W[i]
k[C[i]] = i
elif k[C[i]] >= low:
j = low
while j <= k[C[i]]:
ans -= W[j]
... | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR WHILE VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR ASSIGN VA... |
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given 2 arrays W = (W_{1}, W_{2}, .., W_{N}) and C = (C_{1}, C_{2}, .., C_{N}) with N elements each. A range [l, r] is unique if all the elements C_{l}, C_{l+1}, .., C_{r} are unique (ie. no duplicates). The sum of the range is W_... | t = int(input())
while t != 0:
n = int(input())
c = input()
c = [int(x) for x in c.split(" ")]
w = input()
w = [int(x) for x in w.split(" ")]
arr = [0] * n
max = w[0]
sum = w[0]
lo = 0
hi = 1
arr[c[0]] = 1
while hi < n:
if arr[c[hi]] == 0:
arr[c[hi]] =... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR ... |
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given 2 arrays W = (W_{1}, W_{2}, .., W_{N}) and C = (C_{1}, C_{2}, .., C_{N}) with N elements each. A range [l, r] is unique if all the elements C_{l}, C_{l+1}, .., C_{r} are unique (ie. no duplicates). The sum of the range is W_... | from itertools import accumulate
red = lambda: list(map(int, input().split()))
for i in range(int(input())):
n = int(input())
l = red()
wi = list(map(int, ("0 " + input()).split()))
wis = list(accumulate(wi))
j = m = 0
s = set()
for i in range(n):
while j < n and l[i] in s:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL BIN_OP STRING FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ... |
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given 2 arrays W = (W_{1}, W_{2}, .., W_{N}) and C = (C_{1}, C_{2}, .., C_{N}) with N elements each. A range [l, r] is unique if all the elements C_{l}, C_{l+1}, .., C_{r} are unique (ie. no duplicates). The sum of the range is W_... | for t in range(int(input())):
n = int(input())
cost = list(map(int, input().strip().split()))
weight = list(map(int, input().strip().split()))
s = [0] * (n + 1)
for i in range(n):
s[i + 1] = s[i] + weight[i]
ans = 0
i = 0
d = {}
for j in range(n):
if cost[j] not in d:... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASS... |
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given 2 arrays W = (W_{1}, W_{2}, .., W_{N}) and C = (C_{1}, C_{2}, .., C_{N}) with N elements each. A range [l, r] is unique if all the elements C_{l}, C_{l+1}, .., C_{r} are unique (ie. no duplicates). The sum of the range is W_... | cases = int(input())
for x in range(cases):
nums = int(input())
array = list(map(int, input().split()))
weights = [0] + list(map(int, input().split()))
dictionary = {}
prev = 0
score = 0
for index in range(nums):
weights[index + 1] += weights[index]
item = array[index]
... | 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 BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUN... |
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given 2 arrays W = (W_{1}, W_{2}, .., W_{N}) and C = (C_{1}, C_{2}, .., C_{N}) with N elements each. A range [l, r] is unique if all the elements C_{l}, C_{l+1}, .., C_{r} are unique (ie. no duplicates). The sum of the range is W_... | for _ in range(int(input())):
n = int(input())
c = list(map(int, input().split()))
w = list(map(int, input().split()))
ans = 0
s = []
s.append(w[0])
for i in w[1:]:
s.append(s[-1] + i)
f = [-1] * (n + 1)
cs = 0
t = 0
for i in range(n):
if f[c[i]] == -1 or f[c[... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR NUMBER FOR VAR VAR NUMBER EXPR FUNC_CALL... |
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given 2 arrays W = (W_{1}, W_{2}, .., W_{N}) and C = (C_{1}, C_{2}, .., C_{N}) with N elements each. A range [l, r] is unique if all the elements C_{l}, C_{l+1}, .., C_{r} are unique (ie. no duplicates). The sum of the range is W_... | hash = []
for i in range(1000000):
hash.append(0)
for t in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
w = list(map(int, input().split()))
for i in range(n):
hash[i] = 0
maxx = max(w)
l = 0
r = 1
s = w[0]
hash[a[0]] += 1
if r < n:
... | ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR 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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ... |
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given 2 arrays W = (W_{1}, W_{2}, .., W_{N}) and C = (C_{1}, C_{2}, .., C_{N}) with N elements each. A range [l, r] is unique if all the elements C_{l}, C_{l+1}, .., C_{r} are unique (ie. no duplicates). The sum of the range is W_... | def maxsegm(C, W):
d, s, t, i, r = {(0): 0}, set(), 0, 0, 0
for j in range(len(C)):
t += W[j]
d[j + 1] = t
while C[j] in s:
s.remove(C[i])
i += 1
s.add(C[j])
r = max(r, t - d[i])
return r
for _ in range(int(input())):
input()
C = list... | FUNC_DEF ASSIGN VAR VAR VAR VAR VAR DICT NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR WHILE VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR RETURN VAR FOR... |
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given 2 arrays W = (W_{1}, W_{2}, .., W_{N}) and C = (C_{1}, C_{2}, .., C_{N}) with N elements each. A range [l, r] is unique if all the elements C_{l}, C_{l+1}, .., C_{r} are unique (ie. no duplicates). The sum of the range is W_... | def find(n, c, w):
big = 0
sum = 0
sum1 = 0
j = 0
a = [(0) for i in range(n)]
m = {}
x = -1
while j < n:
sum1 += w[j]
a[j] = sum1
if c[j] not in m:
if x >= 0:
sum = a[j] - a[x]
else:
sum = a[j]
m[... | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR VAR ... |
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given 2 arrays W = (W_{1}, W_{2}, .., W_{N}) and C = (C_{1}, C_{2}, .., C_{N}) with N elements each. A range [l, r] is unique if all the elements C_{l}, C_{l+1}, .., C_{r} are unique (ie. no duplicates). The sum of the range is W_... | for _ in range(int(input())):
N = int(input())
C = list(map(int, input().split()))
W = list(map(int, input().split()))
vi = [0] * N
M = 0
Sum = 0
L = 0
for i in range(N):
if vi[C[i]] == 0:
Sum += W[i]
vi[C[i]] = 1
else:
M = max(M, Sum)
... | 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR F... |
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given 2 arrays W = (W_{1}, W_{2}, .., W_{N}) and C = (C_{1}, C_{2}, .., C_{N}) with N elements each. A range [l, r] is unique if all the elements C_{l}, C_{l+1}, .., C_{r} are unique (ie. no duplicates). The sum of the range is W_... | for _ in range(int(input())):
n = int(input())
c = [int(i) for i in input().split()]
w = [int(i) for i in input().split()]
b = [(-1) for i in range(n)]
sry = [w[0]]
for i in range(1, n):
sry.append(sry[-1] + w[i])
ans = 0
sp = 0
d = 0
i = 0
while i < n:
if b[c... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VA... |
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given 2 arrays W = (W_{1}, W_{2}, .., W_{N}) and C = (C_{1}, C_{2}, .., C_{N}) with N elements each. A range [l, r] is unique if all the elements C_{l}, C_{l+1}, .., C_{r} are unique (ie. no duplicates). The sum of the range is W_... | t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x = [0]
for i in b:
x.append(x[-1] + i)
ans = [0] * n
d = {}
c = 0
for i in range(n):
try:
e = d[a[i]]
c = x[i + 1] - x... | 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN... |
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given 2 arrays W = (W_{1}, W_{2}, .., W_{N}) and C = (C_{1}, C_{2}, .., C_{N}) with N elements each. A range [l, r] is unique if all the elements C_{l}, C_{l+1}, .., C_{r} are unique (ie. no duplicates). The sum of the range is W_... | t = int(input())
for test in range(t):
n = int(input())
c_array = [i for i in map(int, input().split())]
w_array = [i for i in map(int, input().split())]
seen = [(False) for i in range(n)]
result_sum = 0
i = 0
j = 0
max_sum = 0
while j < n:
if seen[c_array[j]] == True:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ... |
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given 2 arrays W = (W_{1}, W_{2}, .., W_{N}) and C = (C_{1}, C_{2}, .., C_{N}) with N elements each. A range [l, r] is unique if all the elements C_{l}, C_{l+1}, .., C_{r} are unique (ie. no duplicates). The sum of the range is W_... | t = int(input())
for _ in range(t):
n = int(input())
C = list(map(int, input().split()))
W = list(map(int, input().split()))
Ws = [W[0]]
for i in range(1, n):
Ws.append(Ws[-1] + W[i])
S = [(0, 0)]
R = [-1] * n
R[C[0]] = 0
ini = 0
for i in range(1, n):
a = C[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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN... |
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given 2 arrays W = (W_{1}, W_{2}, .., W_{N}) and C = (C_{1}, C_{2}, .., C_{N}) with N elements each. A range [l, r] is unique if all the elements C_{l}, C_{l+1}, .., C_{r} are unique (ie. no duplicates). The sum of the range is W_... | t = int(input())
while t:
t -= 1
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = temp = 0
d = [0] * n
i = j = k = 0
while i < n:
while j < n and d[a[j]] == 0:
d[a[j]] = 1
temp += b[j]
j += 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR VAR NUMBER WHILE... |
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given 2 arrays W = (W_{1}, W_{2}, .., W_{N}) and C = (C_{1}, C_{2}, .., C_{N}) with N elements each. A range [l, r] is unique if all the elements C_{l}, C_{l+1}, .., C_{r} are unique (ie. no duplicates). The sum of the range is W_... | for _ in range(int(input())):
n = int(input())
c = list(map(int, input().split()))
w = list(map(int, input().split()))
a = [0] * 1000001
i = j = sum = ans = 0
while i < n:
while j < n and a[c[j]] == 0:
a[c[j]] = 1
sum += w[j]
j += 1
ans = max(s... | 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR VAR VAR VAR NUMBER WHILE VAR VAR WHILE VAR VAR VA... |
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given 2 arrays W = (W_{1}, W_{2}, .., W_{N}) and C = (C_{1}, C_{2}, .., C_{N}) with N elements each. A range [l, r] is unique if all the elements C_{l}, C_{l+1}, .., C_{r} are unique (ie. no duplicates). The sum of the range is W_... | t = int(input())
for _ in range(t):
n = int(input())
indexes = list(map(int, input().split()))
values = list(map(int, input().split()))
leftsum = [-1] * n
lastindex = [-1] * n
startindex = 0
tempindex = 0
maxsum = 0
tempsum = 0
totalsum = 0
for i in range(n):
if lasti... | 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUM... |
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given 2 arrays W = (W_{1}, W_{2}, .., W_{N}) and C = (C_{1}, C_{2}, .., C_{N}) with N elements each. A range [l, r] is unique if all the elements C_{l}, C_{l+1}, .., C_{r} are unique (ie. no duplicates). The sum of the range is W_... | for t in range(int(input())):
n = int(input())
c = list(map(int, input().split()))
w = list(map(int, input().split()))
pres = [0]
for i in range(n):
pres.append(pres[-1] + w[i])
i, j = 0, 1
ma = 0
x = {c[0]}
while i < n:
if j < n and c[j] not in x:
x.add(c... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASS... |
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given 2 arrays W = (W_{1}, W_{2}, .., W_{N}) and C = (C_{1}, C_{2}, .., C_{N}) with N elements each. A range [l, r] is unique if all the elements C_{l}, C_{l+1}, .., C_{r} are unique (ie. no duplicates). The sum of the range is W_... | def answer():
c = [0] * (n + 1)
ans, i, j, s = 0, 0, 0, 0
for i in range(n):
while j < n and c[a[j]] == 0:
c[a[j]] += 1
s += w[j]
j += 1
ans = max(ans, s)
if j == n:
break
c[a[i]] -= 1
s -= w[i]
return ans
for i in... | FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUN... |
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given 2 arrays W = (W_{1}, W_{2}, .., W_{N}) and C = (C_{1}, C_{2}, .., C_{N}) with N elements each. A range [l, r] is unique if all the elements C_{l}, C_{l+1}, .., C_{r} are unique (ie. no duplicates). The sum of the range is W_... | for _ in range(int(input())):
n = int(input())
c = list(map(int, input().split()))
w = list(map(int, input().split()))
d = {}
j = 0
i = 0
ans = 0
mans = 0
while i < n:
if d.get(c[i], 0) == 0:
ans += w[i]
if ans > mans:
mans = ans
... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR... |
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given 2 arrays W = (W_{1}, W_{2}, .., W_{N}) and C = (C_{1}, C_{2}, .., C_{N}) with N elements each. A range [l, r] is unique if all the elements C_{l}, C_{l+1}, .., C_{r} are unique (ie. no duplicates). The sum of the range is W_... | t = int(input())
for t1 in range(t):
n = int(input())
a = []
b = []
a = list(map(int, input().strip().split(" ")))
b = list(map(int, input().strip().split(" ")))
s = 0
e = 0
max = 0
sum = 0
bucket = [0] * n
for i in range(n):
if bucket[a[i]] == 0:
e = 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 LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBE... |
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given 2 arrays W = (W_{1}, W_{2}, .., W_{N}) and C = (C_{1}, C_{2}, .., C_{N}) with N elements each. A range [l, r] is unique if all the elements C_{l}, C_{l+1}, .., C_{r} are unique (ie. no duplicates). The sum of the range is W_... | T = int(input())
for eachCase in range(T):
N = int(input())
C = list(map(int, input().split()))
W = list(map(int, input().split()))
seen = [False] * N
L = R = 0
maxSum = currentSum = 0
while True:
while R < N and not seen[C[R]]:
currentSum += W[R]
seen[C[R]] =... | 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER WHIL... |
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given 2 arrays W = (W_{1}, W_{2}, .., W_{N}) and C = (C_{1}, C_{2}, .., C_{N}) with N elements each. A range [l, r] is unique if all the elements C_{l}, C_{l+1}, .., C_{r} are unique (ie. no duplicates). The sum of the range is W_... | def list_input():
return list(map(int, input().split()))
def map_input():
return map(int, input().split())
def map_string():
return input().split()
for _ in range(int(input())):
n = int(input())
c = list_input()
w = list_input()
last = [0] * (n + 5)
pref = [0]
for i in w:
... | FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR ... |
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given 2 arrays W = (W_{1}, W_{2}, .., W_{N}) and C = (C_{1}, C_{2}, .., C_{N}) with N elements each. A range [l, r] is unique if all the elements C_{l}, C_{l+1}, .., C_{r} are unique (ie. no duplicates). The sum of the range is W_... | t = int(input())
while t:
t -= 1
n = int(input())
C = [int(x) for x in input().strip().split()]
W = [int(x) for x in input().strip().split()]
C_location = []
latest_location = []
for i in range(0, n):
C_location.append(False)
latest_location.append(-1)
maxm_unique_sum = -... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR NUM... |
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given 2 arrays W = (W_{1}, W_{2}, .., W_{N}) and C = (C_{1}, C_{2}, .., C_{N}) with N elements each. A range [l, r] is unique if all the elements C_{l}, C_{l+1}, .., C_{r} are unique (ie. no duplicates). The sum of the range is W_... | t = int(input())
for u in range(t):
prefix = []
n = int(input())
c = input().split()
for val in range(len(c)):
c[val] = int(c[val])
w = input().split()
for val in range(len(w)):
w[val] = int(w[val])
prefix.append(0)
for val in range(len(w)):
prefix.append(prefix[v... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VA... |
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given 2 arrays W = (W_{1}, W_{2}, .., W_{N}) and C = (C_{1}, C_{2}, .., C_{N}) with N elements each. A range [l, r] is unique if all the elements C_{l}, C_{l+1}, .., C_{r} are unique (ie. no duplicates). The sum of the range is W_... | t = int(input())
for i in range(t):
n = int(input())
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
res = 0
d1 = {}
sum1 = 0
s1 = []
max1 = 0
k = -1
for j in range(n):
sum1 += l2[j]
s1.append(sum1)
if d1.get(l1[j], -1) == -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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUM... |
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given 2 arrays W = (W_{1}, W_{2}, .., W_{N}) and C = (C_{1}, C_{2}, .., C_{N}) with N elements each. A range [l, r] is unique if all the elements C_{l}, C_{l+1}, .., C_{r} are unique (ie. no duplicates). The sum of the range is W_... | t = int(input())
for x in range(t):
n = int(input())
c = list(map(int, input().split()))
w = list(map(int, input().split()))
u = []
s = 0
st = set()
i = 0
d = dict()
while i < n:
if c[i] not in st:
s = s + w[i]
st.add(c[i])
d[c[i]] = 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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIG... |
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given 2 arrays W = (W_{1}, W_{2}, .., W_{N}) and C = (C_{1}, C_{2}, .., C_{N}) with N elements each. A range [l, r] is unique if all the elements C_{l}, C_{l+1}, .., C_{r} are unique (ie. no duplicates). The sum of the range is W_... | t = int(input())
for i in range(t):
n = int(input())
c = [int(x) for x in input().split()]
w = [int(x) for x in input().split()]
s = []
for i in range(n):
if i == 0:
s.append(w[0])
else:
s.append(s[-1] + w[i])
l = 0
r = 0
j = 0
su = 0
mas =... | 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 FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL V... |
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given 2 arrays W = (W_{1}, W_{2}, .., W_{N}) and C = (C_{1}, C_{2}, .., C_{N}) with N elements each. A range [l, r] is unique if all the elements C_{l}, C_{l+1}, .., C_{r} are unique (ie. no duplicates). The sum of the range is W_... | for t in range(int(input())):
n = int(input())
ar2 = input().split()
x = {}
for i in range(n):
ar2[i] = int(ar2[i])
x[ar2[i]] = False
ar = input().split()
ar[0] = int(ar[0])
for i in range(1, n):
ar[i] = int(ar[i])
ar[i] = ar[i - 1] + ar[i]
ar.append(0)
... | 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 DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_... |
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given 2 arrays W = (W_{1}, W_{2}, .., W_{N}) and C = (C_{1}, C_{2}, .., C_{N}) with N elements each. A range [l, r] is unique if all the elements C_{l}, C_{l+1}, .., C_{r} are unique (ie. no duplicates). The sum of the range is W_... | t = int(input())
for i in range(t):
n = int(input())
c = list(map(int, input().split()))
w = list(map(int, input().split()))
s = set([])
start = 0
s.add(c[0])
maxi = w[0]
sumi = w[0]
for j in range(1, n):
sumi += w[j]
if c[j] not in s:
s.add(c[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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR LIST ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSI... |
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given 2 arrays W = (W_{1}, W_{2}, .., W_{N}) and C = (C_{1}, C_{2}, .., C_{N}) with N elements each. A range [l, r] is unique if all the elements C_{l}, C_{l+1}, .., C_{r} are unique (ie. no duplicates). The sum of the range is W_... | t = int(input())
for i in range(t):
n = int(input())
c = list(map(int, input().split()))
w = list(map(int, input().split()))
d = {}
for j in c:
d[j] = 0
s, a, ans = 0, 0, 0
for k in range(n):
d[c[k]] += 1
while d[c[k]] == 2:
d[c[a]] -= 1
s -= w... | 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER... |
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given 2 arrays W = (W_{1}, W_{2}, .., W_{N}) and C = (C_{1}, C_{2}, .., C_{N}) with N elements each. A range [l, r] is unique if all the elements C_{l}, C_{l+1}, .., C_{r} are unique (ie. no duplicates). The sum of the range is W_... | for _ in range(int(input())):
n = int(input())
c = list(map(int, input().split()))
w = list(map(int, input().split()))
prefix, maxi, l = [], 0, 0
unique = {}
for i in range(n):
if not i:
prefix.append(w[i])
else:
prefix.append(prefix[i - 1] + w[i])
... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR LIST NUMBER NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR EXPR FUNC_... |
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given 2 arrays W = (W_{1}, W_{2}, .., W_{N}) and C = (C_{1}, C_{2}, .., C_{N}) with N elements each. A range [l, r] is unique if all the elements C_{l}, C_{l+1}, .., C_{r} are unique (ie. no duplicates). The sum of the range is W_... | for _ in range(int(input())):
N = int(input())
C = list(map(int, input().split()))
W = list(map(int, input().split()))
sumW = [0] * N
sumW[0] = W[0]
for i in range(1, N):
sumW[i] = W[i] + sumW[i - 1]
l = 0
r = 0
maxsum = -1
status = [None] * N
while l < N and r < N:
... | 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR A... |
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given 2 arrays W = (W_{1}, W_{2}, .., W_{N}) and C = (C_{1}, C_{2}, .., C_{N}) with N elements each. A range [l, r] is unique if all the elements C_{l}, C_{l+1}, .., C_{r} are unique (ie. no duplicates). The sum of the range is W_... | for tt in range(int(input())):
n = int(input())
m = {}
for i in range(n):
m[i] = -1
c = [int(i) for i in input().split()]
w = [int(i) for i in input().split()]
ans = 0
j = 0
i = 0
sm = 0
while i < n:
if m[c[i]] != -1:
h = m[c[i]]
for k in r... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER... |
Given an array arr[] of distinct integers of size N and a value sum, the task is to find the count of triplets (i, j, k), having (i<j<k) with the sum of (arr[i] + arr[j] + arr[k]) smaller than the given value sum.
Example 1:
Input: N = 4, sum = 2
arr[] = {-2, 0, 1, 3}
Output: 2
Explanation: Below are triplets with
su... | class Solution:
def countTriplets(self, arr, n, sumo):
arr.sort()
cnt = 0
for i in range(n - 2):
j = i + 1
k = n - 1
target_sum = sumo - arr[i]
while j < k:
res = arr[i] + arr[j] + arr[k]
if res < sumo:
... | CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR IF VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER RETURN VAR |
Given an array arr[] of distinct integers of size N and a value sum, the task is to find the count of triplets (i, j, k), having (i<j<k) with the sum of (arr[i] + arr[j] + arr[k]) smaller than the given value sum.
Example 1:
Input: N = 4, sum = 2
arr[] = {-2, 0, 1, 3}
Output: 2
Explanation: Below are triplets with
su... | class Solution:
def countTriplets(self, arr, N, sum):
arr.sort()
count = 0
for i in range(N - 2):
first, last = i + 1, N - 1
while first < last:
req = arr[i] + arr[first] + arr[last]
if req >= sum:
last -= 1
... | CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR IF VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER RETURN VAR |
Given an array arr[] of distinct integers of size N and a value sum, the task is to find the count of triplets (i, j, k), having (i<j<k) with the sum of (arr[i] + arr[j] + arr[k]) smaller than the given value sum.
Example 1:
Input: N = 4, sum = 2
arr[] = {-2, 0, 1, 3}
Output: 2
Explanation: Below are triplets with
su... | class Solution:
def countTriplets(self, arr, n, sumo):
arr.sort()
c = 0
for i in range(len(arr)):
tar = sumo - arr[i]
si = i + 1
ei = n - 1
while si <= ei:
if arr[si] + arr[ei] < tar:
c += ei - si
... | CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER RETURN VAR |
Given an array arr[] of distinct integers of size N and a value sum, the task is to find the count of triplets (i, j, k), having (i<j<k) with the sum of (arr[i] + arr[j] + arr[k]) smaller than the given value sum.
Example 1:
Input: N = 4, sum = 2
arr[] = {-2, 0, 1, 3}
Output: 2
Explanation: Below are triplets with
su... | class Solution:
def pair_sum(self, arr, start, end, sumo, a):
i, j = start, end
cnt = 0
while i < j:
curr_sum = a + arr[i] + arr[j]
if arr[i] == a:
i += 1
elif arr[j] == a:
j -= 1
elif curr_sum < sumo:
... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ... |
Given an array arr[] of distinct integers of size N and a value sum, the task is to find the count of triplets (i, j, k), having (i<j<k) with the sum of (arr[i] + arr[j] + arr[k]) smaller than the given value sum.
Example 1:
Input: N = 4, sum = 2
arr[] = {-2, 0, 1, 3}
Output: 2
Explanation: Below are triplets with
su... | class Solution:
def countTriplets(self, arr, n, sumo):
n = len(arr)
if n <= 2:
return 0
arr.sort()
ctr = 0
for idx, num in enumerate(arr):
i, j = idx + 1, n - 1
while i < j:
if arr[i] + arr[j] + num >= sumo:
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER RETURN VAR |
Given an array arr[] of distinct integers of size N and a value sum, the task is to find the count of triplets (i, j, k), having (i<j<k) with the sum of (arr[i] + arr[j] + arr[k]) smaller than the given value sum.
Example 1:
Input: N = 4, sum = 2
arr[] = {-2, 0, 1, 3}
Output: 2
Explanation: Below are triplets with
su... | class Solution:
def countTriplets(self, arr, n, s):
c = 0
arr.sort()
for i in range(n - 2):
j, k = i + 1, n - 1
while j < k:
if arr[i] + arr[j] + arr[k] >= s:
k -= 1
elif arr[i] + arr[j] + arr[k] < s:
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER RETURN VAR |
Given an array arr[] of distinct integers of size N and a value sum, the task is to find the count of triplets (i, j, k), having (i<j<k) with the sum of (arr[i] + arr[j] + arr[k]) smaller than the given value sum.
Example 1:
Input: N = 4, sum = 2
arr[] = {-2, 0, 1, 3}
Output: 2
Explanation: Below are triplets with
su... | class Solution:
def countTriplets(self, arr, n, sumo):
cnt = 0
arr.sort()
for l in range(0, n):
i, j = l + 1, n - 1
while i < j:
sum = arr[l] + arr[i] + arr[j]
if sum < sumo:
cnt += j - i
i += 1
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR IF VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER RETURN VAR |
Given an array arr[] of distinct integers of size N and a value sum, the task is to find the count of triplets (i, j, k), having (i<j<k) with the sum of (arr[i] + arr[j] + arr[k]) smaller than the given value sum.
Example 1:
Input: N = 4, sum = 2
arr[] = {-2, 0, 1, 3}
Output: 2
Explanation: Below are triplets with
su... | class Solution:
def countTriplets(self, arr, n, sumo):
result = 0
arr.sort()
for i in range(n - 2):
if i > 0 or arr[i] != arr[i - 1]:
start = i + 1
end = n - 1
while start < end:
if arr[i] + arr[start] + arr[end... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER RETURN VAR |
Given an array arr[] of distinct integers of size N and a value sum, the task is to find the count of triplets (i, j, k), having (i<j<k) with the sum of (arr[i] + arr[j] + arr[k]) smaller than the given value sum.
Example 1:
Input: N = 4, sum = 2
arr[] = {-2, 0, 1, 3}
Output: 2
Explanation: Below are triplets with
su... | class Solution:
def countTriplets(self, arr, n, sumo):
ans = 0
arr.sort()
for i in range(n):
j = i + 1
e = n - 1
c = 0
s = 0
while j < e:
if arr[i] + arr[j] + arr[e] >= sumo:
e = e - 1
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP V... |
Given an array arr[] of distinct integers of size N and a value sum, the task is to find the count of triplets (i, j, k), having (i<j<k) with the sum of (arr[i] + arr[j] + arr[k]) smaller than the given value sum.
Example 1:
Input: N = 4, sum = 2
arr[] = {-2, 0, 1, 3}
Output: 2
Explanation: Below are triplets with
su... | class Solution:
def countTriplets(self, arr, n, sumo):
ans = 0
arr = sorted(arr)
for i in range(len(arr)):
l, r = i + 1, len(arr) - 1
while l < r:
curr = arr[i] + arr[l] + arr[r]
if curr >= sumo:
r -= 1
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR IF VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER RETURN VAR |
Given an array arr[] of distinct integers of size N and a value sum, the task is to find the count of triplets (i, j, k), having (i<j<k) with the sum of (arr[i] + arr[j] + arr[k]) smaller than the given value sum.
Example 1:
Input: N = 4, sum = 2
arr[] = {-2, 0, 1, 3}
Output: 2
Explanation: Below are triplets with
su... | class Solution:
def countTriplets(self, arr, n, sumo):
nums = sorted(arr)
count = 0
start = 0
while start < len(nums):
sub_start, sub_end = start + 1, len(nums) - 1
while sub_start < sub_end:
if nums[sub_start] + nums[sub_end] < sumo - nums[st... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR |
Given an array arr[] of distinct integers of size N and a value sum, the task is to find the count of triplets (i, j, k), having (i<j<k) with the sum of (arr[i] + arr[j] + arr[k]) smaller than the given value sum.
Example 1:
Input: N = 4, sum = 2
arr[] = {-2, 0, 1, 3}
Output: 2
Explanation: Below are triplets with
su... | class Solution:
def countTriplets(self, arr, n, sumo):
arr = sorted(arr)
count = 0
for i in range(n):
left = i + 1
right = n - 1
while left < right:
sum1 = arr[i] + arr[left] + arr[right]
if sum1 < sumo:
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER R... |
Given an array arr[] of distinct integers of size N and a value sum, the task is to find the count of triplets (i, j, k), having (i<j<k) with the sum of (arr[i] + arr[j] + arr[k]) smaller than the given value sum.
Example 1:
Input: N = 4, sum = 2
arr[] = {-2, 0, 1, 3}
Output: 2
Explanation: Below are triplets with
su... | class Solution:
def countTriplets(self, arr, n, sumo):
arr.sort()
ans = 0
for i in range(n):
a = i + 1
b = n - 1
while a < b:
if arr[a] + arr[b] + arr[i] < sumo:
ans += b - a
a += 1
e... | CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER RETURN VAR |
Given an array arr[] of distinct integers of size N and a value sum, the task is to find the count of triplets (i, j, k), having (i<j<k) with the sum of (arr[i] + arr[j] + arr[k]) smaller than the given value sum.
Example 1:
Input: N = 4, sum = 2
arr[] = {-2, 0, 1, 3}
Output: 2
Explanation: Below are triplets with
su... | class Solution:
def countTriplets(self, nums, n, s):
c = 0
n = len(nums)
nums.sort()
for i in range(n - 2):
j, k = i + 1, n - 1
while j < k:
if nums[i] + nums[j] + nums[k] >= s:
k -= 1
else:
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER RETURN VAR |
Given an array arr[] of distinct integers of size N and a value sum, the task is to find the count of triplets (i, j, k), having (i<j<k) with the sum of (arr[i] + arr[j] + arr[k]) smaller than the given value sum.
Example 1:
Input: N = 4, sum = 2
arr[] = {-2, 0, 1, 3}
Output: 2
Explanation: Below are triplets with
su... | class Solution:
def countTriplets(self, a, n, s):
c = 0
a = sorted(a)
for i in range(n):
j = i + 1
k = n - 1
while j < k:
if a[i] + a[j] + a[k] >= s:
k = k - 1
else:
c += k - j
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER RETURN VAR |
Given an array arr[] of distinct integers of size N and a value sum, the task is to find the count of triplets (i, j, k), having (i<j<k) with the sum of (arr[i] + arr[j] + arr[k]) smaller than the given value sum.
Example 1:
Input: N = 4, sum = 2
arr[] = {-2, 0, 1, 3}
Output: 2
Explanation: Below are triplets with
su... | class Solution:
def countTriplets(self, arr, n, target):
i = 0
arr.sort()
count = 0
while i < n - 2:
j = i + 1
k = n - 1
while j < k:
if arr[i] + arr[j] + arr[k] < target:
count += k - j
j +=... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN 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())):
n = int(input())
a = list(map(int, input().split(" ")))
s, e, c = 0, n - 1, 0
if n == 1:
print(c)
else:
while s < e:
if a[s] < a[e]:
a[e] = a[e] - a[s]
c += 1
s += 1
elif a[s] > a[e]... | 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 STRING ASSIGN VAR VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR WHILE VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP 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())
for _ in range(t):
n = int(input())
arr = list(map(int, input().split()))
count = 0
while len(arr) > 1:
if arr[0] == arr[-1]:
del arr[0]
del arr[-1]
else:
if arr[0] > arr[-1]:
arr[0] = arr[0] - arr[-1]
d... | 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 NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER 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.... | for t in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
l = 0
r = n - 1
c = 0
while l < r:
if a[l] == a[r]:
l += 1
r -= 1
elif a[l] < a[r]:
a[r] = a[r] - a[l]
l += 1
c += 1
else:
... | 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 VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR 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 _ in range(t):
n = int(input())
a = list(map(int, input().split()))
if n % 2 == 0:
size = n // 2 - 1
else:
size = n // 2
lz = 0
leftel = a[0]
rightel = a[n - 1]
ct = 0
rz = n - 1
while len(a) > 1:
if a[0] == a[-1]:
del a[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 IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN 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.... | for i in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
l = 0
r = len(a) - 1
count = 0
while l < r:
if a[l] == a[r]:
l = l + 1
r = r - 1
elif a[l] < a[r]:
a[r] = a[r] - a[l]
l = l + 1
count = c... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR N... |
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.... | n = int(input())
for i in range(n):
size = int(input())
arr = input()
arr = [int(x) for x in arr.split()]
count = 0
f = 0
l = len(arr) - 1
while True:
while arr[f] == arr[l] and f < l:
f += 1
l -= 1
if f >= l:
break
if arr[f] < arr[... | 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 VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE NUMBER WHILE VAR VAR VAR VAR VAR VAR VAR NUMBER 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.... | n = int(input())
def pal(arr):
x = 0
i, j = 0, len(arr) - 1
while i <= j:
if arr[i] == arr[j]:
i += 1
j -= 1
elif arr[i] > arr[j]:
arr[i] -= arr[j]
j -= 1
x = x + 1
else:
arr[j] -= arr[i]
i += 1
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FOR... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.