Start learning free

LESSON 232 OF 348 · TWO POINTERS

Array Diff in Scala

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


STEP 1 OF 11
    Ctrl + Enter to check

    Array Diff in Scala

    Keep going with ScalaAbout 340 step-by-step lessons, from your first line of code to coding interviews. Free to start.
    Start learning free