Skip to content

Commit 4ef1f90

Browse files
authored
Create maximum-distance-between-a-pair-of-values.cpp
1 parent 3ce6600 commit 4ef1f90

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 + m)
2+
// Space: O(1)
3+
4+
class Solution {
5+
public:
6+
int maxDistance(vector<int>& nums1, vector<int>& nums2) {
7+
int result = 0, i = 0, j = 0;
8+
while (i < size(nums1) && j < size(nums2)) {
9+
if (nums1[i] > nums2[j]) {
10+
++i;
11+
} else {
12+
result = max(result, j - i);
13+
++j;
14+
}
15+
}
16+
return result;
17+
}
18+
};

0 commit comments

Comments
 (0)