Given an integer array `nums` of size at least 2, find the difference between the maximum value located at an even index and the minimum value located at an odd index. Specifically, return the value of $max\_even - min\_odd$, where $max\_even$ is the maximum value among all elements at indices $0, 2, 4, \dots$ and $min\_odd$ is the minimum value among all elements at indices $1, 3, 5, \dots$.
Explanation: The elements at even indices are 4, 7, and 9 (max is 9). The elements at odd indices are 2 and 1 (min is 1). The difference is 9 - 1 = 8.
Explanation: The elements at even indices are -3 and -1 (max is -1). The elements at odd indices are 5 and 10 (min is 5). The difference is -1 - 5 = -6.
Iterating arrays and tracking min/max
No dry run loaded.
🚀 Practice this problem
Run code, get AI hints & track streak