Minimum steps to reach the Nth stair in jumps of perfect power of 2 | Java program for the above approach ; 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 ; Driver Code ; Number of stairs ; Function Call
import java . util . * ; class GFG { static int stepRequired ( int N ) { int cnt = 0 ; while ( N > 0 ) { N = N & ( N - 1 ) ; cnt ++ ; } return cnt ; } public static void main ( String [ ] args ) { int N = 23 ; System . out . print ( stepRequired ( N ) ) ; } }