Wrong output in "Incredible Hulk" problem

IN THIS PROBLEM, NONE OF THE TEST CASES ARE PASSING THOUGH ALL THE MANUAL INPUTS GOT CORRECT OUTPUTS.

import java.util.*;
public class MinSteps
{
static long count;
public static long minSteps(long n)
{
if(n==0)
return count;
if((n&(n-1))==0)
{
count++;
return count;
}
else
{
count++;
n–;
}
return minSteps(n);
}
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int T=sc.nextInt();
for(int i=0;i<T;i++)
{
count=0;
System.out.println(minSteps(sc.nextInt()));
}
}
}

@vinay86048

  1. Check if the number is power of 2 .
    For e.g., n = 4 so 4 & 3 == 1 ? hence power of 2.
    ……1.1 If yes then return 1.
  2. Count the number of set bits.
  3. This count is the answer.

run your code for this testcase
input:
1
7
output:
3

your output:
4

Why the output should come as 3? Please explain. I think it should be 4. In first jump, he will reach 4 then in three more steps, he will reach 7.

@vinay86048
first
2^2 1st step
2^1 2nd step
2^0 3rd step

4+2+1=7 so three steps

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.