Dsa
Arrays
Medium
Maximum Difference Between Indices
Given an array of integers, find the maximum difference between indices i and j such that arr[j] > arr[i] and j > i.
Input Format:
- The first line contains a single integer n (1 <= n <= 10^5), the size of the array.
- The second line contains n integers, separated by spaces, representing the elements of the array.
Output Format:
- Print a single integer, the maximum difference or -1 if no such pair exists.
Example:
Input:
5
2 3 10 6 4
Output:
2
Key concepts
arraystwo_pointersdifference
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now