Untitled
unknown
plain_text
a year ago
417 B
7
Indexable
public int maxDistance(int[] nums1, int[] nums2) {
int i = 0, j = 0;
int maxDist = 0;
while (i < nums1.length && j < nums2.length) {
if (nums1[i] <= nums2[j]) {
maxDist = Math.max(maxDist, j - i);
j++; // Try to increase j for a larger distance
} else {
i++; // nums1[i] > nums2[j], move i forward
}
}
return maxDist;
}
Editor is loading...
Leave a Comment