• Challenge Author
    + 1 comment

    think about it this way.

    Convert the number to binary format.

    1010 -> (010 - 10 ) -> 10
    

    If a number at any given point of time is a power of 2, then it will be of the form

    10000(xtimes)
    

    Then, remove the right most 0 from the binary representation of the number

    else

    remove the left most 1 and also remove any left most 0s till you find a 1.

    Example:-

    1010
    

    this is not a power of 2 ( why? ), so this number gets reduced to 010 = 10 ( 2 in decimal )

    10
    

    this is a power of 2.

    so, I remove the right most 0 and the game ends.