Question
Parity Perfect Number
You are given an integer n. A number is called a Parity Perfect Number if it satisfies one of the following conditions:
1. All digits have the same parity (all even or all odd).
2. No two adjacent digits have the same parity (strictly alternating odd-even or even-odd).
Determine whether the given number n is a Parity Perfect Number.
1. All digits have the same parity (all even or all odd).
2. No two adjacent digits have the same parity (strictly alternating odd-even or even-odd).
Determine whether the given number n is a Parity Perfect Number.
Input
n: A single integer.
Output
Print "Yes" if n is a Parity Perfect Number, otherwise print "No".
Example
Example 1:
Input: 2468
Output: Yes
Explanation: All digits are even → Yes
Example 2:
Input: 1357
Output: Yes
Explanation: All digits are odd → Yes
Example 3:
Input: 1213
Output: No
Explanation: Alternating till the last pair (odd-even-odd-odd ❌ last two have same parity) → No
Example 4:
Input: 1234
Output: Yes
Explanation: Perfectly alternating odd-even-odd-even pattern ✔ → Yes
Input: 2468
Output: Yes
Explanation: All digits are even → Yes
Example 2:
Input: 1357
Output: Yes
Explanation: All digits are odd → Yes
Example 3:
Input: 1213
Output: No
Explanation: Alternating till the last pair (odd-even-odd-odd ❌ last two have same parity) → No
Example 4:
Input: 1234
Output: Yes
Explanation: Perfectly alternating odd-even-odd-even pattern ✔ → Yes