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
class Solution{ public: // Your are required to complete this function // function should return root of the modified BST vector<Node*> nums; void inorder(Node* root){ if(!root) return; inorder(root->left); nums.push_back(root); inorder(root->right); } Node* buildBST(int l, int r, vector<Node*>& nums){ if(l>r) return NULL; int m = (l+r)/2; nums[m]->left = buildBST(l, m-1, nums); nums[m]->right = buildBST(m+1, r, nums); return nums[m]; } Node* buildBalancedTree(Node* root) { inorder(root); return buildBST(0, nums.size()-1, nums); } };

βœ¨πŸ”°πŸ”°πŸ”°πŸ”°πŸ”°πŸ”°πŸ”°βœ¨ βœ¨πŸ”°COURSES πŸ”°βœ¨ βœ¨πŸ”°πŸ”°πŸ”°πŸ”°πŸ”°πŸ”°πŸ”°βœ¨ 1⃣ D0T \/\/Δ’B D€V 2⃣ $upr€m€ DSβˆ† 3⃣ P\/\/ W€B D€V 4⃣ βˆ†LPHβˆ† B@tch 5⃣ UDMY βˆ†NDR01D D€V ⚠️How To Access Link⚠️ ✨SHARE WITH YOUR FRIENDS✨

πŸ”° Python In Hindi πŸ”° πŸ‘‰πŸΌ Free Lectures βœ… ⭐Free Certificate⭐ πŸ”—Link - https://linkpays.in/Python-Hindi (How To Access The Li
πŸ”° Python In Hindi πŸ”° πŸ‘‰πŸΌ Free Lectures βœ… ⭐Free Certificate⭐ πŸ”—Link - https://linkpays.in/Python-Hindi (How To Access The Link)

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

class Solution { public: unordered_setst1; vectorans; void inorder(Node *root, int num){ if(!root){return;} inorder(root->left, num); if(num==0){st1.insert(root->data);} if(num==1){ if(st1.find(root->data)!=st1.end()){ ans.push_back(root->data); } } inorder(root->right, num); } vector findCommon(Node *root1, Node *root2) { inorder(root1, 0); inorder(root2, 1); return ans; } };

I Will Post One MOOCs Link Daily. πŸ”°Free Course + CertificateπŸ”° πŸ‘‰πŸΌ Do You Want This ⁉️
Anonymous voting

✨ Free MOOCs Platform ✨ ⭐ 300,000+ Courses & Free Certificates πŸ”—Link - Mind Luster πŸ”°One Of The Best MOOCs SiteπŸ”°

✨ Free MOOCs Platform ✨ ⭐ 300,000+ Courses & Free Certificate πŸ”—Link - Mind Luster πŸ”°One Of The Best MOOCs SiteπŸ”°

13th October : C++ Solution ☝🏼 β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€” πŸ™‹πŸ»β€β™‚οΈAny Query ⁉️ Join Us βœ… - @GFG_Answer ⭐ We Are 200 Now ⭐

class Solution{ public: int out; void inOrder(Node* node, int x){ if(!node) return; inOrder(node->left, x); if(node->data <= x) out = node->data; else return; inOrder(node->right, x); } int floor(Node* root, int x) { out = -1; inOrder(root, x); return out; } };

12th October : C++ Solution ☝🏼 β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€” πŸ™‹πŸ»β€β™‚οΈDiscussion ⁉️ Join βœ… @GFG_Answer ⚠️ Get Free T-ShirtπŸ‘• ⚠️ ⚑ T.me/GeeksForGeeks_POTD/437

class Solution { public: unordered_map mp; string solve(Node* node) { if(node==NULL)return ""; string ans=""; string l=solve(node->left); string r=solve(node->right); ans=l+"#"+to_string(node->data)+"#"+r; if(node->left || node->right)mp[ans]++; return ans; } int dupSub(Node *root) { string x=solve(root); for(auto o:mp) { if(o.second>1) { return true; } } return false; } };

So, 555 Subs Pe - ✨⚑PW WE DEV⚑✨ Upload Kare⁉️
Anonymous voting

11th October : C++ Solution ☝🏼 β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€” πŸ™‹πŸ»β€β™‚οΈDiscussion ⁉️ Join βœ… @GFG_Answer ⚠️ Get Free T-ShirtπŸ‘• ⚠️ ⚑ T.me/GeeksForGeeks_POTD/437

class Solution{ public: //Function to check whether a binary tree is balanced or not. int height(Node *root) { if(root == NULL) return 0; return max(height(root -> left), height(root -> right)) + 1; } bool isBalanced(Node *root) { if(root == NULL) return true; if(isBalanced(root -> left) && isBalanced(root -> right)) { if(abs(height(root -> left) - height(root -> right)) <= 1) return true; } return false; } };

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

class Solution { private: void atLevelK(Node* root, int k, vector &ans){ if(root){ if(k==0) ans.push_back(root->data); atLevelK(root->left,k-1,ans); atLevelK(root->right,k-1,ans); } } int helper(Node* root, int k, vector &ans, int target, bool &t){ if(root==NULL) return -1; if(!t and root->data==target){ atLevelK(root,k,ans); t = true; return 1; } int l = helper(root->left,k,ans,target,t); int r = helper(root->right,k,ans,target,t); if(l==-1 and r==-1) return -1; else if(r==-1){ if(k-l==0){ ans.push_back(root->data); return -1; } else atLevelK(root->right,k-l-1,ans); return l+1; } else{ if(k-r==0){ ans.push_back(root->data); return -1; } else atLevelK(root->left,k-r-1,ans); return r+1; } } public: vector KDistanceNodes(Node* root, int target , int k){ vector ans; bool t = false; helper(root,k, ans,target,t); sort(ans.begin(),ans.end()); return ans; } };

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

class Solution{ public: //Function to find the height of a binary tree. int max_h = 0; int solve(struct Node* node, int h){ if(node->right == NULL && node->left == NULL)return max_h = max(max_h, h); else if(node->right == NULL){ solve(node->left, h+1); } else if(node->left == NULL){ solve(node->right, h+1); } else{ solve(node->right, h+1); solve(node->left, h+1); } } int height(struct Node* node){ if(!node)return 0; max_h = solve(node, 1); return max_h; } };