459 views
0 votes
0 votes

You are given an array of N integers, A1, A2 ,…, AN. Return maximum value of f(i, j) for all 1 ≤ i, j ≤ N.
f(i, j) is defined as |A[i] - A[j]| + |i - j|, where |x| denotes absolute value of x.

For example,

A=[1, 3, -1]

f(1, 1) = f(2, 2) = f(3, 3) = 0
f(1, 2) = f(2, 1) = |1 - 3| + |1 - 2| = 3
f(1, 3) = f(3, 1) = |1 - (-1)| + |1 - 3| = 4
f(2, 3) = f(3, 2) = |3 - (-1)| + |2 - 3| = 5

So, we return 5.

 

Source - https://www.interviewbit.com/problems/maximum-absolute-difference/

Please log in or register to answer this question.

Related questions

5 votes
5 votes
1 answer
1
pyuri asked Oct 4, 2015
11,111 views
Difference between relocatable machine code and absolute machine code!!!1
1 votes
1 votes
0 answers
3
PriDix asked Jul 10, 2017
2,519 views
What are relocatable addresses ? Is it the entire source code which is relocatable before loading phase or only addresses used by control statements like goto, switch et...
1 votes
1 votes
2 answers
4
Himanshu1 asked Dec 4, 2015
732 views