Max Distance

Given an array A of integers, find the maximum of j - i subjected to the constraint of A[i] <= A[j].

If there is no solution possible, return -1.

Example :

A : [3 5 4 2]

Output : 2 
for the pair (3, 4)

Interview Code Editor
Hints
  • Hint 1
  • Hint 2
  • Solution Approach
  • Complete Solution
4495 successful submissions.
Asked In:
  • Google
  • Amazon
Click here to jump start your coding interview preparation