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)

NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.
Start solving Max Distance on Interview Code Editor
Sign Up
to access hints and editorial solutions for Max Distance
7718 successful submissions.
Asked In:
  • Google
  • Amazon
Click here to start solving coding interview questions