A textile mill logs each day's automated loom pattern as a single positive integer. When that integer n is written in binary (with no leading zero bits), each bit — read from the most significant bit down to the least significant bit — records whether the corresponding pick (a single pass of the weft thread) was raised (1) or lowered (0).
A pattern only qualifies for the mill's premium "twill-alternating" certification when every two consecutive picks strictly alternate between raised and lowered — that is, no two adjacent bits in the binary representation of n are equal.
Given the integer logged for a day's pattern, determine whether it qualifies for certification.
A single line containing one integer n.
Print YES if the binary representation of n has no two equal adjacent bits, otherwise print NO.
1 <= n <= 2^31 - 1Example 1
Input
5
Expected
YES
Explanation
5 in binary is 101. Reading the bits 1, 0, 1, every adjacent pair (1,0) and (0,1) differs, so the pattern qualifies. Output: YES.
Example 2
Input
7
Expected
NO
Explanation
7 in binary is 111. The first two bits, 1 and 1, are adjacent and equal, so the pattern fails to qualify. Output: NO.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →