Alternate 1s And 0s

46
0
Home Programs Alternate 1s And 0s

The program must accept an integer N as the input. The program must print YES if the binary representation of N contains 1’s and O’s alternatively. Else the program must print NO as the output.

Boundary Condition(s):
2 <= N <= 10^8

Input Format:
The first line contains N.

Output Format:
The first line contains YES or NO.

Example Input/Output 1:
Input:
10
Output:
YES
Explanation:
The binary representation of 10 is 1010.Here the binary representation of 10 contains 1’s and O’s alternatively Hence the output is YES.

Example Input/Output 2:
Input
25
Output
NO

N = int(input())
_,binN= bin (N).split('b') #to  converts N to its binary representation  and remove ob prefix
flag=0
for i in range(len(binN)-1): 
	if binN[i] == binN[i+1]: 
		flag =-1
		break

if flag ==0:
	print("YES")
else:
	print("NO")
Hephzibai
WRITTEN BY

Hephzibai

Hephzibai is a driven third-year student at St. Joseph's Institute of Technology, specializing in Computer Science and Engineering. With a keen interest in data science and also in fullstack.
One of my greatest strengths lies in my programming skills, which I've honed through countless hours of practice and participation in coding challenges. Platforms like Skillrack, HackerRank, and others have been my playgrounds, where I've tackled a wide range of problems with creativity and determination.

Leave a Reply

Your email address will not be published. Required fields are marked *