Minimum steps to reach the Nth stair in jumps of perfect power of 2 | Function to count the number of jumps required to reach Nth stairs . ; Till N becomes 0 ; Removes the set bits from the right to left ; Number of stairs ; Function Call
function stepRequired ( N ) { let cnt = 0 ; while ( N ) { N = N & ( N - 1 ) ; cnt ++ ; } return cnt ; } let N = 23 ; document . write ( stepRequired ( N ) ) ;