Incerdible Hulk i am not able to pass all test case. Here but i am passing the given test case

#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
// let’s play
ios_base::sync_with_stdio(false);
cin.tie(NULL);

int no;
cin>>no;
int a[no];
for(int i=0;i<no;i++)
{
	cin>>a[i];
}
for(int i=0;i<no;i++)
{
	int k=a[i];
	 int msb=0;
while(k!=0) {
    k=k>>1;
    msb++;
}
int llon=pow(2,msb)-a[i]+1;
int kk=a[i]-pow(2,msb-1)+1;
  int ans=min(llon,kk);
  cout<<ans<<endl; 
}
return 0;

}

@sunneykumar309 in this question you simply have to count the no of set bits in the number .


dont forget to hit like and mark resolved if cleared :smiley:

in test case
10
first we will move onto 8->9->10
it will take 3 steps
so output will be 3.
am i right?

@sunneykumar309 it will be 2 as he can take a jump of 8 then 2 (both 8 and 2 are powers of 2)
so 2 moves

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.