Run Time error in playing with bits

Why I’m getting run time error? Please help me in getting correct solution.

Hey @dhanshree_p18

int countSetBits(int a, int b){
	int ans=0;
	for(int i=a;i<=b;i++){
        int j=0;//added this
		while( i>>j ){ //updated this
			ans +=((i>>j)&1); //updated this
			j++;//updated this
		}
	}
	return ans;
}

Earlier u are making i=0 again in every iteration hence giving runtime error

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.