Start learning free

LESSON 352 OF 678 · TWO POINTERS

Array Diff

Practice O(n log n)

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).


STEP 1 OF 11
    Ctrl + Enter to check