Given an array as input A[0,1,2,3…N], in this array two elements A* and A[j] are said to be adjacent if there is no element in range (A*,A[j]) i.e, if A*=1 and A[j]=5 then A* and A[j] are said to be adjacent if array doesn’t contain element in range (1,5).

Calculate the maximum possible distance j-i where j and i are indices of adjacent element in given array.

Expected time complexity: O(N logN)