Open In App

Amazon Interview Experience | Set 221

I gave my round 1 amazon. There were two coding questions.

1) Given an integer n in the input, find its next sparse binary numberA sparse binary number is a number whose binary representation does not contain any consecutive 1s.



For eg.
72 is a sparse binary number, because its binary representation (01001000) does not contain any consecutive 1s.
17 is a sparse binary number, because its binary representation (00010001) does not contain any consecutive 1s.

Similarly,
12 is a non sparse binary number, because its binary representation (00001100) contains consecutive 1s.
43 is a non sparse binary number, because its binary representation (00101011) contains consecutive 1s.



Now, given an integer n in the input, find its next sparse binary number. n itself can be sparse or non sparse.

where n >= 0 and n {1,2,2}
2.You light second and third and extinguish first one . heights ->{1, 1,1}
3.You light all the candles. heights -{0,0,0}

Hope it helps aspirants.

Online mcq, there were around 20 and 13-14 were from https://www.geeksforgeeks.org/

Article Tags :