en
Feedback
GeeksForGeeks - POTD | GFG POTD Answer

GeeksForGeeks - POTD | GFG POTD Answer

Closed channel

🚩 Channel was restricted by Telegram

Show more
1 218
Subscribers
No data24 hours
-97 days
-5730 days
Posts Archive
10th June : C++ Solution☝🏼 ———————————————————— 🙋🏻‍♂️Discussion ⁉️ Join ✅ @GFG_Answer

class Solution {
  public:

    void matchPairs(int n, char nuts[], char bolts[]) {
        
        char charr[]={'!', '#', '$','%', '&', '*', '?', '@', '^'};
        vector<char>nut;
        vector<char>bolt;
        for(int i=0;i<9;i++){
            for(int j=0;j<n;j++){
                if(charr[i]==nuts[j]){
                    nut.push_back(nuts[j]);
                }
                if(charr[i]==bolts[j])
                bolt.push_back(bolts[j]);
            }
        }
        for(int i=0;i<n;i++){
            nuts[i]=nut[i];
            bolts[i]=bolt[i];
        }
    }
};

9th June : C++ Solution☝🏼 ———————————————————— Don't Mute 🔇 New Contest Updates Coming ⚡ Hack4Bengal 3.0 Hackathon ———————————————————— 🙋🏻‍♂️Discussion ⁉️ Join ✅ @GFG_Answer

class Solution {
  public:
    void zigZag(int n, vector<int> &arr) {
        for(int i=1;i<n;i++){
            if(i%2!=0){
                if(arr[i-1]>arr[i]) {
                    swap(arr[i-1],arr[i]);
                }
            }
            else{
                if(arr[i]>arr[i-1]){
                    swap(arr[i],arr[i-1]);
                }
            }
        }
        
    }
};

Eastern India's Biggest Hackathon 🔥 Hack4Bengal 3.0 Is Here 🔥🔥 🗓 Date : June 28, 3PM - June 30, 12PM 📍Venue : JIS Colleg
Eastern India's Biggest Hackathon 🔥
Hack4Bengal 3.0 Is Here 🔥🔥 🗓 Date : June 28, 3PM - June 30, 12PM 📍Venue : JIS College of engg. 🔥 Register Nowww 🔥

8th June : C++ Solution☝🏼 ———————————————————— Don't Mute 🔇 New Contest Updates Coming ⚡ ———————————————————— 🙋🏻‍♂️Discussion ⁉️ Join ✅ @GFG_Answer

class Solution {
  public:
int findExtra(int n, int arr1[], int arr2[]) {
        
        for(int i=0; i<n; i++){
            if(arr1[i]!=arr2[i]){
                return i;
            }
        }
    }
};

Do You Registered For This Contest ⁉️ ⚡ https://bit.ly/hack2skill-humanAIze
Anonymous voting

HumanAIze Hackathon 👨🏻‍💻Participate the AI Gaming 🎮 Contest and earn Exclusive 🤩 Goodies 🔥🔥 ⚡ Register for HumanAIze H
HumanAIze Hackathon <Fintech Edition>
👨🏻‍💻Participate the AI Gaming 🎮 Contest and earn Exclusive 🤩 Goodies 🔥🔥 ⚡ Register for HumanAIze Hackathon <Fintech Edition> through the link. 🔗https://bit.ly/hack2skill-humanAIze You will get a confirmation ✅ mail along with AI Gaming Contest google form link 🔗. ✅ Register and get a chance to earn exclusive goodies 🎁. 👨🏻‍💻 The Contest is happening this Saturday, 8th June, 12 Noon (IST) onwards.

7th June : C++ Solution☝🏼 ———————————————————— 🙋🏻‍♂️Discussion ⁉️ Join ✅ @GFG_Answer

class Solution {
  public:
  
  int maxOccured(int n, int l[], int r[], int maxx) {
        int pref[maxx+2]={0};
        int ans=-1,mx=-1e9;
        for(int i=0;i<n;i++){
            pref[l[i]]++;
            pref[r[i]+1]--;
        }
        for(int i=1;i<=maxx;i++){
            pref[i]+=pref[i-1];
            if(pref[i]>mx){
                mx=pref[i];
                ans=i;
            }
        }
        return ans;
    }
};

Anyone Doing Google Arcade June Trivia '24 ⁉️

6th June : C++ Solution☝🏼 ———————————————————— 🙋🏻‍♂️Discussion ⁉️ Join ✅ @GFG_Answer

class Solution {
  public:
    long long max_sum(int a[], int n) {
        long long  sum=0,cs=0,N=n;
        for(long long i=0;i<N;i++){
           sum+=a[i];
           cs+=i*a[i];
        }
        long long res=cs;
        for(long long  j=1;j<N;j++){
            cs=cs-(sum-a[j-1])+a[j-1]*(N-1);
            if(res<cs)
                res=cs;
        }
        return res;
      
    }
};

5th June : C++ Solution☝🏼 ———————————————————— 🙋🏻‍♂️Discussion ⁉️ Join ✅ @GFG_Answer

class Solution {
  public:
    int findSwapValues(int a[], int n, int b[], int m) {
        // t.me/geeksforgeeks_POTD
        
        set<int>st;
        int suma = 0;
        int sumb = 0;
        for(int i = 0 ; i < n ; i++ )
        {
            suma += a[i];
            st.insert(a[i]);
        }
        
        for(int i = 0 ; i < m ; i++ )
        {
            sumb += b[i];
        }
        
        
        if((sumb-suma)%2 != 0) return -1;

        
        for(int i = 0 ; i < m ; i++ )
        {
            if(st.find((suma-sumb)/2+b[i]) != st.end())
            {
                return 1; 
            }
        }
        return -1;
    }
};

4th June : C++ Solution☝🏼 ———————————————————— 🙋🏻‍♂️Discussion ⁉️ Join ✅ @GFG_Answer

class Solution {
  public:
    string binaryNextNumber(string s) {
        int i=s.size()-1;
        while(i>=0&&s[i]!='0'){
            s[i]='0';
            i--;
        }
        if(i<0)s='1'+s;
        else s[i]='1';
        reverse(s.begin(),s.end());
        while(true){
            int n=s.size();
            if(s[n-1]=='0')s.pop_back();
            else break;
        }
        reverse(s.begin(),s.end());
        return s;
    }
};

3rd June : C++ Solution☝🏼 ———————————————————— 🙋🏻‍♂️Discussion ⁉️ Join ✅ @GFG_Answer

class Solution {
  public:
    int mod=1e9+7;

    // t.me/Geeksforgeeks_POTD

    long long power(long long a,long long b){
        long long ans=1;
        while(b){
            if(b%2)ans*=a;
            b>>=1;
            a*=a;
            a%=mod;
            ans%=mod;
        }
        return ans;
    }
    long long solve(int n,vector<int> &dp){
        if(n==2) return 1;
        if(n==3) return 3;
        if(dp[n]!=-1)return dp[n];
        return dp[n]=((solve(n-1,dp) + power(2,n-2))%mod+ solve(n-2,dp))%mod;
    }
    int numberOfConsecutiveOnes(int n) {
        vector<int> dp(n+1,-1);
        return solve(n,dp);
    }
};