30. Is Binary Number Multiple of 3
My approach
- 2^0 % 3 = 1
- 2^1 % 3 = 2
- 2^2 % 3 = 1
- 2^3 % 3 = 2
.... so on- 11 (3) -> 2 + 1 = 3
- 110 (6) -> 1 + 2 = 3
- 1111 (15) -> 2 + 1 + 2 + 1 = 6
- 1010100 (84) -> 1 + 1 + 1 = 3
- 10110111 (183) -> 2 + 2 + 1 + 1 + 2 + 1 = 9Time and Auxiliary Space Complexity
Code (C++)
Contribution and Support
Last updated