Skip to content

Commit f16de7a

Browse files
authored
Create widest-pair-of-indices-with-equal-range-sum.cpp
1 parent 0d4957f commit f16de7a

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Time: O(n)
2+
// Space: O(n)
3+
4+
class Solution {
5+
public:
6+
int widestPairOfIndices(vector<int>& nums1, vector<int>& nums2) {
7+
unordered_map<int, int> lookup = {{0, -1}};
8+
int result = 0, total = 0;
9+
for (int i = 0; i < size(nums1); ++i) {
10+
total += nums1[i] - nums2[i];
11+
if (!lookup.count(total)) {
12+
lookup[total] = i;
13+
}
14+
result = max(result, i - lookup[total]);
15+
}
16+
return result;
17+
}
18+
};

0 commit comments

Comments
 (0)