Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Lonely Ones Binary ones ( 1 ) can get lonely if only zeros ( 0 ) surround them. Formally, we call such 1 ' s

Lonely Ones
Binary ones (1) can get lonely if only zeros (0)
surround them. Formally, we call such 1's "sparse". A
number is defined as sparse if its binary
representation has no two consecutive bits set.
You are given an integer N and your task is to find
out if it is sparse or not.
Input
The input contains an integer N.
Output
'Print '1' if the number is sparse and '0' if the number
is not sparse.
Constraints
1N1018
Example #1
Explanation: The binary representation of 3615
100100. There are no consecutive ones present in
this. So it is a sparse number.
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

12th edition

133544613, 978-0133544619

More Books

Students also viewed these Databases questions

Question

Question What are the requirements for a SIMPLE 401(k) plan?

Answered: 1 week ago