Given two arrays of integers, find a pair of integers, one from each array, whose absolute difference is the closest to zero.
Example:
Input: first = [4, 1, 8],
second = [12, 3, 17]
Output: [4, 3]
Explanation: |4 - 3| = 1 which is the closest to 0
Note:
Your algorithm should run in O(n log n) time and use O(1) extra space (not counting the sort itself and the returned pair).
Walkthroughs of the solution. Try the steps first, then watch to compare approaches.
Free plan: 30 tutor messages. PRO is unlimited.
Saved
Ctrl + Enter to check
