Implement a function called max_index_diff that finds the maximum index difference between two elements in a list such that the element at the higher index is greater than the element at the lower index. The function should iterate through the list to determine this difference and return the maximum difference found.
Input/Output Requirements
Input: The function takes two parameters:
arr: a list of integers representing the array.
n: an integer representing the size of the array arr.
Output: The function returns an integer, which is the maximum index difference found. If no such indices exist where the element at a higher index is greater than the element at a lower index, the function should return -1.
Implementation Instructions
Create a file named /app/solution.py.
Inside the file, implement the max_index_diff function according to the provided logic.
Ensure the function adheres to the described input/output requirements.
Example
python
# Example usage:
result = max_index_diff([1, 2, 3, 4, 5], 5)
print(result) # Output: 4 (the max index difference is 4, from arr[0] to arr[4])
result = max_index_diff([5, 4, 3, 2, 1], 5)
print(result) # Output: -1 (since no arr[j] > arr[i] exists)
Note
In the provided implementation, ensure that edge cases, such as an empty array, are properly handled.