Challenge: Array Index Maximum Difference
Let’s solve the array index maximum difference problem.
We'll cover the following
Problem
Given an array arr[]
of integers, find the two largest differences between indices i
and j
in the array such that:
i
is less thanj
.- The difference between
j
andi
is the maximum among all possible pairs of indices in the array. - The element at index
j
is greater than the element at indexi
i.e.,arr[j]
>arr[i]
.
Input
An integer array.
Output
Maximum distance.
Sample input
array = { 33, 9, 10, 3, 2, 60, 30, 33, 1 }
Sample output
ArrayIndexMaxDiff : 6
Let’s look at the illustration to better understand the question.
Get hands-on with 1400+ tech skills courses.