Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 5725 |

@blackshadows | 5685 |

@akhayrutdinov | 5111 |

@mb1973 | 4989 |

@Quandray | 4908 |

@saiujwal13083 | 4156 |

@sanjay05 | 3762 |

@marius_valentin_dragoi | 3511 |

@sushant_a | 3453 |

@KshamaGupta | 3318 |

@the_coder95 | 3302 |

Complete Leaderboard | |

Handle | Score |

@shashi1iitk | 398 |

@Suniti Jain | 114 |

@ankish2000nayak | 104 |

@gopalsethlnct | 94 |

@senthil1185 | 90 |

@esmadhan | 90 |

@gyanadipta07 | 89 |

@satwikdash2000 | 85 |

@varunmishra3040 | 83 |

@gamec1634 | 82 |

@pj_1721 | 80 |

Complete Leaderboard |

Given an array **A[]** of **N** positive integers. The task is to find the maximum of **j - i** subjected to the constraint of **A[i] <= A[j]**.

**Example 1:**

**Input:
**N = 2
A[] = {1,10}
**Output: **1**
Explanation: **A[0]<=A[1] so (j-i)
is 1-0 = 1.

**Example 2:**

**Input:
**N = 9
A[] = {34,8,10,3,2,80,30,33,1}
**Output: **6**
Explanation: **In the given array
A[1] < A[7] satisfying the required
condition(A[i] <= A[j]) thus giving
the maximum difference of j - i
which is 6(7-1).

**Your Task:**

The task is to complete the function **maxIndexDiff**() which finds and returns maximum index difference. Printing the output will be handled by driver code.

**Constraints:**

1 ≤ N ≤ 10^{7}

0 ≤ A[i] ≤ 10^{18}

**Expected Time Complexity: **O(N).

**Expected Auxiliary Space: **O(N).

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes
Maximum Index

...

Please choose 'ReadOnlyMode' if you needn't to 'Edit' the problem e.g. viewing OJ's solution, TestCase Files (TCFs), TimeLimit etc.