Maximum Absolute Difference
Problem You are given an array of N integers, A1, A2, .... AN . Return the 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 and i != j. Problem Constraints 1 <= N <= 100000 -10 9 <= A[i] <= 10 9 Example Input Input 1: A = [1, 3, -1] Input 2: A = [3, 2, 5, 1] Example Output Output 1: 5 Output 2: 4 Explanation 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. Question Link https://www.interviewbit.com/problems/maximum-absolute-difference/ Solution We have to find the maximum value of the function f(i,j) = |A[i]-A[j]| + |i-j|. Solution 1: Brute Force A simple solution is to apply two loops and calculate the maximum of the the function f. Algorithm: Initialize diff=0, res=0,...