Codeforces 1363B. Subsequence Hate Solution

   Solution in C++:

 ///La ilaha illellahu muhammadur rasulullah

///******Bismillahir-Rahmanir-Rahim******///

///AH Tonmoy

///Department of CSE,23rd batch

    ///Islamic University,Bangladesh

    1. #include <bits/stdc++.h>
    2. using namespace std;
    3. typedef long long ll;
    4. int main()
    5. {
    6. int t;
    7. cin >> t;
    8. while(t--)
    9. {
    10. string s;
    11. cin >> s;
    12. int z,o,z1,o1,ans=1e9,n,i,j;
    13. n=s.size();
    14. z=o=z1=o1=0;
    15. z=count(s.begin(),s.end(),'0');
    16. o=n-z;
    17. z1=z;
    18. o1=o;
    19. for(i=0; i<n; i++)
    20. {
    21. ans=min(ans,min(z1,o1));
    22. if(s[i]=='0')z1--,o1++;
    23. else
    24. o1--,z1++;
    25.  
    26. }
    27. cout<<ans<<endl;
    28. }
    29. }

    No comments

    Most View Post

    Recent post

    Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

      Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h &g...

    Powered by Blogger.