The most asked coding interview - #4
Return the Maximum absolute difference of values and indices
In this article we will be discussing one of the most asked coding interview
The problem statement goes as follows:
Problem statement
Given an array
A
determine the maximum possible value of the following expression:
$f(i,j) =| A[i]-A[j] | +|i-j|$
Example
Input : A = {1, 3, -1} Output : 5 because the maximum value obtainable is: => f(1,2) = |3 - (-1)| + |1-2| = 5
Input : A={3, -2, 5, -4} Output : 10 => f(1, 4) = f(4, 1) = |3 - (-4)| + |1 - 4| = 10 Note that in this case we can also obtain 10 from => f(3, 4) = f(4, 3) = |5 - (-4)| + |3 - 4| = 10Read More »The most asked coding interview - #4