For this task your code should take two sorted arrays of integers X and Y as input. It should compute the sum of the absolute distances between each integer in X and its closest number in Y.
Examples:
X = (1 5,9) Y = (3,4,7) The distance is 2 + 1 + 2.
X = (1,2,3) Y = (0,8) The distance is 1 + 2 + 3.
Your code can take input in any way that is convenient.
The main restriction is that your code must run in linear time in the sum of the length of the two arrays.. (You can assume that adding two integers takes constant time.)