You are given a non-negative integer n. Your task is to determine whether its digits alternate in parity when read from left to right.
The digits must alternate between odd and even, or even and odd, throughout the number. Two consecutive digits must never have the same parity. Return Yes if the digits alternate in parity; otherwise, return No.
Input: n = 1234
Output: Yes
Explanation: The digits have alternating parity: 1 (odd), 2 (even), 3 (odd), and 4 (even).
Input: n = 1245
Output: No
Explanation: The digits 2 and 4 are both even, so the parity alternation is broken.
Input: n = 8
Output: Yes
Explanation: A single-digit number satisfies the condition because there are no consecutive digits to compare.
Sign in to write, run, and submit your solution against the full test suite.