Maximum width ramp
Your task
Given an integer array a, a 'ramp' is a pair of indices (i, j) with i < j and a[i] <= a[j]. Return the maximum width j - i of any ramp. If no ramp exists, return 0. The array may contain duplicates and negative numbers; length can be 0.
Examples
max_index_distance_with_diff(a: list[int], k: int) -> intExample 1
Input
max_index_distance_with_diff([6, 0, 8, 2, 1, 5], 0)Output
4