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: abs(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.
Walkthroughs of the solution. Try the steps first, then watch to compare approaches.
Free plan: 30 tutor messages. Premium is unlimited.
Saved
Ctrl + Enter to check