Skip to content

Commit 6c48b48

Browse files
authored
Create widest-pair-of-indices-with-equal-range-sum.py
1 parent f16de7a commit 6c48b48

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Time: O(n)
2+
# Space: O(n)
3+
4+
import itertools
5+
6+
7+
class Solution(object):
8+
def widestPairOfIndices(self, nums1, nums2):
9+
"""
10+
:type nums1: List[int]
11+
:type nums2: List[int]
12+
:rtype: int
13+
"""
14+
lookup = {0:-1}
15+
result = total = 0
16+
for i, (n1, n2) in enumerate(itertools.izip(nums1, nums2)):
17+
total += n1-n2
18+
if total not in lookup:
19+
lookup[total] = i
20+
result = max(result, i-lookup[total])
21+
return result

0 commit comments

Comments
 (0)