uz
Feedback
GeeksForGeeks - POTD | GFG POTD Answer

GeeksForGeeks - POTD | GFG POTD Answer

Yopiq kanal

🚩 Channel was restricted by Telegram

Ko'proq ko'rsatish
1 218
Obunachilar
Ma'lumot yo'q24 soatlar
-97 kunlar
-5730 kunlar
Postlar arxiv
class Solution 
{ 
    public: 
        void inorder(Node *root,int &sum) 
     { 
         if(root==NULL) 
         return ; 
        if(root->left==NULL && root->right==NULL) 
      {  sum=sum+root->data; 
        return ;} 
         
        inorder(root->left,sum); 
        inorder(root->right,sum); 
     } 
    public: 
        
        int sumOfLeafNodes(Node *root ){ 
             int sum=0; 
             inorder(root,sum); 
             return sum; 
        } 
};

17th February : C++ Solution☝🏼 β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€” πŸ™‹πŸ»β€β™‚οΈDiscussion ⁉️ Join βœ… @GFG_Answer

class Solution{ 
    public: 
    bool isMaxHeap(int arr[], int n) 
    { 
        queue<int> q; 
        q.push(arr[0]); 
         
        for(int i = 1; i < n; i++){ 
            int big = q.front(); 
            q.pop(); 
             
            if(arr[i] > big) 
                return 0; 
                 
            q.push(arr[i]); 
                 
            if(i + 1 < n){ 
                if(arr[i + 1] > big) 
                    return 0; 
                     
                q.push(arr[i + 1]); 
                ++i; 
            } 
        } 
         
        return 1; 
    } 
};

class Solution{ public: bool isMaxHeap(int arr[], int n) { queue q; q.push(arr[0]); for(int i = 1; i < n; i++){ int big = q.front(); q.pop(); if(arr[i] > big) return 0; q.push(arr[i]); if(i + 1 < n){ if(arr[i + 1] > big) return 0; q.push(arr[i + 1]); ++i; } } return 1; } };

16th February : C++ Solution☝🏼 β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€” πŸ™‹πŸ»β€β™‚οΈDiscussion ⁉️ Join βœ… @GFG_Answer

class Solution 
{ 
public: 
    void solve(Node* root,Node*&head) 
    { 
        if(root == NULL) 
        return; 
         
        solve(root->right,head); 
         
        root->right = head; 
        head = root; 
         
        solve(root->left,head); 
         
        root->left = NULL; 
    } 
     
    Node *flattenBST(Node *root) 
    { 
        Node* head = NULL; 
        solve(root,head); 
         
        return head; 
    } 
};

Best Learn in Public Platform ⁉️
Anonymous voting

15th February : C++ Solution☝🏼 β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€” πŸ™‹πŸ»β€β™‚οΈDiscussion ⁉️ Join βœ… @GFG_Answer

class Solution {
public:
 int isPossible(vector<vector<int>>paths){  
     for(auto &x : paths)  if(accumulate(x.begin(), x.end(), 0) & 1) return 0;
     return 1;
 }
};

14th February : C++ Solution☝🏼 β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€” πŸ™‹πŸ»β€β™‚οΈDiscussion ⁉️ Join βœ… @GFG_Answer

class Solution { 
public:vector<vector<int>>ans; 
    int timer=0; 
    void dfs(int node,int parent,vector<int> adj[],vector<int>&vis,vector<int>&dis,vector<int>&low){ 
        vis[node]=1; 
        dis[node]=low[node]=++timer; 
        for(auto it:adj[node]){ 
            if(it==parent)continue; 
            else if(vis[it]==1){ 
                low[node]=min(low[node],dis[it]); 
            } 
            else{ 
                dfs(it,node,adj,vis,dis,low); 
                low[node]=min(low[node],low[it]); 
                if(low[it]>dis[node]){ 
                    ans.push_back({min(it,node),max(it,node)}); 
                } 
            } 
        } 
         
    } 
    vector<vector<int>>criticalConnections(int v, vector<int> adj[]){ 
       vector<int>vis(v,0),dis(v,-1),low(v,-1); 
       for(int i=0;i<v;i++){ 
           if(vis[i]==0){ 
               dfs(i,-1,adj,vis,dis,low); 
           } 
       } 
       sort(ans.begin(), ans.end()); 
       return ans; 
    } 
};

13th February : C++ Solution☝🏼 β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€” πŸ™‹πŸ»β€β™‚οΈDiscussion ⁉️ Join βœ… @GFG_Answer

class Solution { public: Node* cloneGraph(Node* node) { if(!node) return NULL; unordered_map mp; queue q; q.push(node); mp[node] = new Node(node->val); while(!q.empty()){ Node* tmp = q.front(); q.pop(); for(auto &x : tmp->neighbors){ if(!mp.count(x)) mp[x] = new Node(x->val), q.push(x); mp[x]->neighbors.push_back(mp[tmp]); } } return mp[node]; } };

12th February : C++ Solution☝🏼 β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€” πŸ™‹πŸ»β€β™‚οΈDiscussion ⁉️ Join βœ… @GFG_Answer

class Solution{ public: int mod = 1e9 + 7; long long sequence(int n){ long long ans = 0; long long j = 1; for(int i=1; i<=n; i++) { long long val = 1; int k = i; while(k--) { val = (val * j) % mod; j++; } ans = ((ans%mod) + (val%mod)) % mod; } return ans; } };

11th February : C++ Solution☝🏼 β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€” πŸ™‹πŸ»β€β™‚οΈDiscussion ⁉️ Join βœ… @GFG_Answer

class Solution{ public: vector recamanSequence(int n){ unordered_map mp; vector ans(n); ans[0] = 0; ans[1] = 1; mp[0] = 0; mp[1] = 1; for(int i =2; i 0 && mp[x] == 0) { ans[i] = x; mp[x]++; } else { x = ans[i-1] + i; ans[i] = x; mp[x]++; } } return ans; } };

10th February : C++ Solution☝🏼 β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€” πŸ™‹πŸ»β€β™‚οΈDiscussion ⁉️ Join βœ… @GFG_Answer

class Solution { public: int dp[100][100][100]; int N; int solve(int i,int j,int k,vector<vector<int>> &arr){ if(i==N-1&&j==N-1&&k==arr[i][j]) return 1; if(k<=0i>=arr.size()j>=arr.size()) return 0; if(dp[i][j][k]!=-1) return dp[i][j][k]; return dp[i][j][k]=solve(i+1,j,k-arr[i][j],arr)+solve(i,j+1,k-arr[i][j],arr); } long long numberOfPath(int n, int k, vector<vector<int>> &arr){ N=n; memset(dp,-1,sizeof(dp)); return solve(0,0,k,arr); } };

9th February : C++ Solution☝🏼 β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€” πŸ™‹πŸ»β€β™‚οΈDiscussion ⁉️ Join βœ… @GFG_Answer