Google Phone Screen Minimise the function

You are given t testcases and in all the testcases you are given two arrays A and B, both of size n, it is also provided that array A is non-decreasing. You have to minimise the value of expression B[i] - B[j] + | A[i] – A[j] |, where |a| denotes the absolute value of a. For any i and j where i != j, print the minimised value.

For Example:-
5
-7 -3 6 7 10
2 5 -5 6 12

For i=2, and j=4, zero-based indexing the value of expression results into -5-12+ |6-10| = -17 + 4 = -13

Comments (6)