MAXBINSTR - Editorial

Problem Link

Setter: Rahul Kumar
Tester: Rahul Kumar
Editorialist: Rahul Kumar

DIFFICULTY:
SIMPLE - SIMPLE

PROBLEM:
Given a binary string. You need to transform the binary string such that it gives maximum value when converted to decimal number system. Print an integer, the converted number(in decimal number system).

**EXPLANATION:**To maximise the number we can observe that all the 1’s should be on left.

TIME COMPLEXITY:
O(|s|)

SOLUTION:

#include<bits/stdc++.h>
using namespace std;
#define int long long int 

int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int t;
    cin>>t;
    while(t--)
    {
        int res=0,zero=0,one=0;
        string str;
        cin>>str;
        int n=str.size();
        for(int i=0;i<n;i++)
        {
            if(str[i]=='1')
                one++;
            else
                zero++;
        }
        res=pow(2,n)-pow(2,zero)
        cout<<res<<"\n";
    }
}