Determine whether an array is special by checking that every pair of adjacent elements has opposite parity.
Given an integer array, decide whether it is special: every pair of adjacent elements must have different parity. In other words, as you scan from left to right, no two consecutive numbers may both be even or both be odd.
Return true if the array is special, otherwise return false.
Input Format
- A single integer array
nums. nums[i]is an integer.
Output Format
- Return a boolean value indicating whether the array is special.
Constraints
- The array contains at least one element.
- Check only adjacent pairs.
- Use integer parity (
x % 2).
Example 1
Input
nums = [1,2,3,4]
Output
true
Explanation
Each adjacent pair has opposite parity: (1,2), (2,3), and (3,4).
Example 2
Input
nums = [2,4,6]
Output
false
Explanation
The first pair (2,4) has the same parity, so the array is not special.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.