Day 21 of 100 day of code

Hey there! It's day 21 of my 100 days of code journey, and I'm excited to share what went down today. Today was all about tackling problems on CodeChef and diving back into the C++ world to understand some cool coding tricks.

So, here's the scoop: I spent my time cracking four problems on CodeChef. It felt awesome to figure them out, like solving little puzzles. It's amazing how each problem you solve boosts your confidence and makes you feel like a coding superhero.

But wait, there's more! I also revisited something called the Standard Template Library (STL) in C++. Think of it as a magical toolbox that makes coding a bit easier. I played around with different ways to solve problems, and it was like discovering new spells in a video game.

In this blog, I want to share the fun stuff from today's coding session — how taking on challenges can be a blast, why solving problems feels like winning, and why understanding the magic behind coding tools is a game-changer.

So, come along on this coding journey with me. Let's unravel the cool stuff that happened on the 21st day and see how every bit of coding makes us better wizards in this digital world.

1st question

#include <bits/stdc++.h>
using namespace std;
bool solve(string s){
    unordered_map<char,int> mp;
    for(auto it:s){
        mp[it]++;
    }
    for(auto it:mp){
        if((it.second)%2==1){
            return false;
        }
    }
    return true;
}
int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        string s;
        cin>>s;
       if(n%2==1){
        cout<<"NO"<<endl;
       }else{
            if(solve(s)){
                cout<<"YES"<<endl;
            }else{
                cout<<"NO"<<endl;
            }
       }
    }
}

question 2

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

ll solve(ll a,ll o){
   return gcd(a,o);
}

int main(){
    int t;
    cin>>t;
    while(t--){
        ll a,o;
        cin>>a>>o;
        ll ans = solve(a,o);
        cout<<ans<<endl;
    }
}

question 3

#include <bits/stdc++.h>
using namespace std;
int solve(int *arr,int n){
    map<int,int> mp;
    int maxi = -1;
    for(int i=0;i<n;i++){
        mp[arr[i]]++;
    }
    for(auto it:mp){
        maxi = max(maxi,it.second);
    }
    return n-maxi;
}
int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        int arr[n];
        for(int i =0;i<n;i++){
            cin>>arr[i];
        }
        int ans = solve(arr,n);
        cout<<ans<<endl;
    }
}

question 4

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


void solution(){
    ll n;
    cin>>n;
    string s;
    cin>>s;
    ll a=0,b=0;
    for(auto it:s){
        if(it == '1') a++;
        else b++;
    }

    if(abs(a-b)>1){
        cout<<"NO"<<endl;
        return;
    }
    for(auto it:s){
        if(it=='1') a--;
        else b--;

        if(abs(a-b)>1){
            cout<<"No"<<endl;
            return;
        }
    }

    cout<<"Yes"<<endl;

}



int main(){
    int t;
    cin>>t;
    while(t--){
        solution();
    }



}

I delved into the concept of comparative functions and their role in inbuilt sorting algorithms. It fascinated me how these functions allow us to tailor the sorting process, giving us the freedom to achieve results based on our specific preferences or custom choices.

comparative function:

Let's break it down a bit. A comparative function is like your personal guide for sorting. It tells the computer how to decide the order of things. Imagine you have a list of numbers, and you want them sorted in a way that makes sense to you. That's where a comparative function steps in.

For instance, you might want the numbers arranged from smallest to largest or the other way around. With a comparative function, you can customize this sorting process based on your preferences. It's like having a sorting assistant that follows your rules.

During today's coding adventures, I played around with these comparative functions in conjunction with inbuilt sorting algorithms. The result? The ability to sort things the way I wanted. It's a bit like having a magic wand in coding – wave it in a certain way, and voila, your data is sorted just the way you like it.