JuniorArray

Special Array I

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.

Example 1
Inputnums = [1]
Outputtrue
There is only one element, so the answer is true.
Example 2
Inputnums = [2,1,4]
Outputtrue
The two adjacent pairs, (2, 1) and (1, 4), both contain numbers with different parity.

Constraints

  • 1 <= nums.length <= 100
  • 1 <= nums[i] <= 100

Asked at 6 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate