BackeasyArrays

Parity-Indexed Extremes Solution

Problem Statement

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]`.

Example 1
Input
nums = [5, 2, 9, 1, 7, 6]
Output
[9, 1]

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].

Example 2
Input
nums = [-3, 10, -5, 20, 0]
Output
[0, 10]

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].

Constraints

  • 2 <= nums.length <= 10^5
  • -10^9 <= nums[i] <= 10^9
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free