Max Distance

Problem Description

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

Input Format

First and only argument is an integer array A.

Output Format

Return an integer denoting the maximum value of j - i;

Example Input

Input 1:

 A = [3, 5, 4, 2]

Example Output

Output 1:


Example Explanation

Explanation 1:

 Maximum value occurs for 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
  • Hint 1
  • Hint 2
  • Solution Approach
  • Complete Solution
Asked In:


Click here to start solving coding interview questions