Help me in solving SINGLEOP2 problem

My issue

can someone please explain the logic behind this question

My code

#include <iostream>
#include<bits/stdc++.h>
using namespace std;

int main() {
	int t;
	cin>>t;
	while(t--){
	        int n;
	        cin>>n;
	        string s;
	        cin>>s;
	        int ans=0;
	        for(int i=0;i<n;i++){
	                ans++;
	                if(s[i+1]=='1'){
	                        break;
	                }
	        }
	        cout<<ans<<endl;
	        }
	return 0;
}


Problem Link: SINGLEOP2 Problem - CodeChef

@anmolagrawal67
Since u have to minimize the value of x .
and u can divide the value of x by power of two which is >=2.
which means u are shifting the position of the bit by one which means u have to find the set bit in binary representation of x which is greater than 2^1. and then print that bit.
This is my code . Hope it will help.

#include <iostream>
using namespace std;

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--)
	{
	    int n;
	    cin>>n;
	    string s;
	    cin>>s;
	    int i;
	    for( i=1;i<n;i++)
	    {
	        if(s[i]=='1')
	        break;
	    }
	    cout<<i<<endl;
	}
	return 0;
}
1 Like