Leetcode Problem 1855. Maximum Distance Between a Pair of Values

1855. Maximum Distance Between a Pair of Values

Leetcode Solutions

Two Pointers Approach

  1. Initialize two pointers p1 and p2 to 0.
  2. Initialize max_distance to 0.
  3. While p1 < len(nums1) and p2 < len(nums2), do the following: a. If nums1[p1] is greater than nums2[p2], increment p1. b. Otherwise, if p2 - p1 is greater than max_distance, update max_distance to p2 - p1. c. Increment p2.
  4. Return max_distance.
UML Thumbnail

Binary Search Approach

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...