Given a 0-indexed integer array `nums`, identify the maximum element located at the even indices and the minimum element located at the odd indices. Return these results as a two-element array `[max_even, min_odd]`.
Explanation: The elements at even indices (0, 2, 4) are [5, 9, 7], with a maximum value of 9. The elements at odd indices (1, 3, 5) are [2, 1, 6], with a minimum value of 1. Thus, the output is [9, 1].
Explanation: The elements at even indices (0, 2, 4) are [-3, -5, 0], with a maximum value of 0. The elements at odd indices (1, 3) are [10, 20], with a minimum value of 10. Thus, the output is [0, 10].
Iterating arrays and tracking min/max
No dry run loaded.
🚀 Practice this problem
Run code, get AI hints & track streak