Special Array I - Problem
An array is considered special if the parity of every pair of adjacent elements is different. In other words, one element in each pair must be even, and the other must be odd.
You are given an array of integers nums. Return true if nums is a special array, otherwise, return false.
Input & Output
Example 1 — Special Array
$
Input:
nums = [1]
›
Output:
true
💡 Note:
Single element array is always special since there are no adjacent pairs to check.
Example 2 — Not Special Array
$
Input:
nums = [2,1,4]
›
Output:
true
💡 Note:
Elements are 2(even), 1(odd), 4(even). Adjacent pairs (2,1) and (1,4) both have different parity, so the array is special.
Example 3 — Not Special Array
$
Input:
nums = [4,3,1,6]
›
Output:
false
💡 Note:
Elements are 4(even), 3(odd), 1(odd), 6(even). Adjacent pair (3,1) both have odd parity, so array is not special.
Constraints
- 1 ≤ nums.length ≤ 100
- 1 ≤ nums[i] ≤ 100
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code