Count number of steps to cover a distance if steps can be taken in powers of 2 | Function to count the minimum number of steps ; count the number of set bits in a number ; Driver Code
function getMinSteps ( K ) { return countSetBits ( K ) ; } function countSetBits ( x ) { let setBits = 0 ; while ( x != 0 ) { x = x & ( x - 1 ) ; setBits ++ ; } return setBits ; } let n = 343 ; document . write ( getMinSteps ( n ) ) ;