[Ques]https://www.hackerrank.com/challenges/counter-game/problem
[My ans]https://ide.codingblocks.com/#/s/29154
2
928688482745483
601636219320473
ans:
Louise
Louise
At this input, my code fail to run, tell me what is a problem with my code.
[Ques]https://www.hackerrank.com/challenges/counter-game/problem
[My ans]https://ide.codingblocks.com/#/s/29154
2
928688482745483
601636219320473
ans:
Louise
Louise
At this input, my code fail to run, tell me what is a problem with my code.
Given it’s a bitmasking problem, you should solve it using the concept of bitmasks.
e.g.
If N is not a power of 2, reduce the counter by the largest power of 2 less than N : This is equivalent to removing the first 1 until the number N is power of 2. Thus number of such operations would eqaute to count of all 1s before the last 1.
Example : If N=11010, the largest power of 2 less than N would be 10000, reducing N by it we get 1010, which is equivalent to removing first 1