Ctrl K

Alternating Parity Check

Easy
You are given an integer array values. Check whether even and odd numbers alternate in it, meaning every two adjacent elements have different parity. Return True if they do and False otherwise. A single-element array counts as alternating.
Example 1
values=[7, 10, 3, 4] → True

Odd, even, odd, even: neighbours always differ in parity.

Example 2
values=[2, 5, 9] → False

5 and 9 are neighbours and both odd.

Example 3
values=[42] → True

There are no neighbours, so nothing can break the rule.

Constraints
  • 1 ≤ len(values) ≤ 100
  • 1 ≤ values[i] ≤ 100
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsPair With a Target Sum EasySqueeze Repeats Out of a Sorted Array EasyDrop the Unwanted Value EasySlot on a Sorted Shelf EasyAdd One to a Digit Array Easy
loading Python…
Input
values=[7, 10, 3, 4]
Expected
True

Run checks the first 3 tests in your browser. Submit checks all 121 tests on the server, hidden ones included.