GeeksForGeeks - POTD | GFG POTD Answer
کانال بسته
1 218
مشترکین
اطلاعاتی وجود ندارد24 ساعت
-97 روز
-5730 روز
آرشیو پست ها
24th November : C++ Solution ☝🏼
—————————————————————
🙋🏻♂️Discussion ⁉️
Join ✅ @GFG_Answer
class Solution {
public:
vector nthRowOfPascalTriangle(int n) {
long long mod = 1000000007;
vector> v(n + 1);
v[0].push_back(1);
for (int i = 1; i <= n; i++) {
v[i].push_back(1);
for (int j = 1; j < i; j++) {
long long val = (v[i - 1][j - 1] + v[i - 1][j]) % mod;
v[i].push_back(val);
}
v[i].push_back(1);
}
return v[n-1];
}
};
23rd November : C++ Solution ☝🏼
—————————————————————
🙋🏻♂️Discussion ⁉️
Join ✅ @GFG_Answer
class Solution{
public:
int height(Node *node) {
if (node == NULL) {
return 0;
}
return (node->height);
}
int getBalance(Node *node) {
if (node == NULL) {
return 0;
}
return (height(node->left) - height(node->right));
}
Node *leftRotate(Node *node) {
Node *x = node->right;
Node *y = x->left;
x->left = node;
node->right = y;
node->height = max(height(node->left), height(node->right)) + 1;
x->height = max(height(x->left), height(x->right)) + 1;
return x;
}
Node *rightRotate(Node *node) {
Node *x = node->left;
Node *y = x->right;
x->right = node;
node->left = y;
node->height = max(height(node->left), height(node->right)) + 1;
x->height = max(height(x->left), height(x->right)) + 1;
return x;
}
/*You are required to complete this method */
Node* insertToAVL(Node* node, int data) {
if (node == NULL) {
return (new Node(data));
}
if (data < node->data) {
node->left = insertToAVL(node->left, data);
}
else if (data > node->data) {
node->right = insertToAVL(node->right, data);
}
else {
return node;
}
node->height = 1 + max(height(node->left), height(node->right));
int balance = getBalance(node);
if ((balance > 1) && (data < node->left->data)) {
return rightRotate(node);
}
if ((balance < -1) && (data > node->right->data)) {
return leftRotate(node);
}
if ((balance > 1) && (data > node->left->data)) {
node->left = leftRotate(node->left);
return rightRotate(node);
}
if ((balance < -1) && (data < node->right->data)) {
node->right = rightRotate(node->right);
return leftRotate(node);
}
return node;
}
};
21st November : C++ Solution ☝🏼
—————————————————————
🙋🏻♂️Discussion ⁉️
Join ✅ @GFG_Answer
class Solution{
public:
bool solve(struct Node* r1, struct Node* r2){
if((r1==NULL and r2!=NULL ) or (r1!=NULL and r2==NULL)) return false;
if(r1==NULL and r2==NULL)
return true;
if(r1->data!=r2->data)
return false;
bool s1=solve(r1->left, r2->right);
if(s1==false)
return false;
bool s2=solve(r1->right, r2->left);
return s2;
}
// return true/false denoting whether the tree is Symmetric or not
bool isSymmetric(struct Node* root)
{
if(root==NULL)
return true;
return solve(root->left, root->right);
}
};
21st November : C++ Solution ☝🏼
—————————————————————
🙋🏻♂️Discussion ⁉️
Join ✅ @GFG_Answer
⚡Support Guys
YouTube.com/@afzalmiryt
class Solution
{
public:
//Function to check if two trees are identical.
bool isIdentical(Node *r1, Node *r2)
{
if(r1 == NULL && r2 == NULL) return true;
else if((r1 == NULL && r2 != NULL) || (r1 != NULL && r2 == NULL)) return false;
if(r1->data != r2->data) return false;
bool ans = isIdentical(r1->left, r2->left);
ans &= isIdentical(r1->right, r2->right);
return ans;
}
};
This Is Our Discussion Group
➡️ @GFG_Answer Tap To Join
Many Of You Haven't Joined Yet😐
20th November : C++ Solution ☝🏼
—————————————————————
🙋🏻♂️Discussion ⁉️
Join ✅ @GFG_Answer
⚡Support Guys
YouTube.com/@afzalmiryt
class Solution{
public:
int solve(Node *root, int k, map &s, int sum)
{
if(root == NULL)
return 0;
int c = 0;
sum += root -> data;
if(s.find(sum-k) != s.end())
c += s[sum - k];
s[sum]++;
int left = solve(root -> left, k, s, sum);
int right = solve(root -> right, k, s, sum);
s[sum]--;
return c + left + right;
}
int sumK(Node *root,int k)
{
map s;
s[0]++;
return solve(root, k, s, 0);
}
};
18th November : C++ Solution ☝🏼
—————————————————————
🙋🏻♂️Discussion ⁉️
Join ✅ @GFG_Answer
class Solution
{
public:
Node* findIntersection(Node* head1, Node* head2)
{
Node *start=NULL, *q=NULL;
int d1,d2;
while(head1!=NULL && head2!=NULL){
d1=head1->data;
d2=head2->data;
if(d1==d2){
Node* node = new Node(d1);
if(start==NULL){
start=node;
q=node;
}
else{
q->next=node;
q=node;
}
head1=head1->next;
head2=head2->next;
}
else if(d1next;
}
else if(d2next;
}
}
return start;
}
};
18th November : C++ Solution ☝🏼
—————————————————————
🙋🏻♂️Discussion ⁉️
Join ✅ @GFG_Answer
⚡Earn ₹300⚡
t.me/GeeksForGeeks_POTD/582
class Solution
{
public:
Node* reverseDLL(Node * head)
{
if(head==NULL || head->next==NULL ){
return head;
}
Node* previ=NULL;
Node* curr=head;
Node* forw=NULL;
while(curr!=NULL){
forw=curr->next;
curr->next=previ;
curr->prev=forw;
previ=curr;
curr=forw;
}
return previ;
}
};
Repost from GeeksForGeeks - POTD | GFG POTD Answer
⚡5paisa ₹300 Reward⚡
1. Go To Link 🔗₹300
2. Open FREE 5paisa Account
3. Get ₹300 Cash Reward.
⚡Refer To Earn More Rewards⚡
⚡Go To refer.5paisa.com To Check Your Total Amount.
⚡5paisa ₹300 Reward⚡
1. Go To Link 🔗₹300
2. Open FREE 5paisa Account
3. Get ₹300 Cash Reward.
⚡Refer To Earn More Rewards⚡
⚡Go To refer.5paisa.com To Check Your Total Amount.
17th November : C++ Solution ☝🏼
—————————————————————
🙋🏻♂️Discussion ⁉️
Join ✅ @GFG_Answer
⚡ My laptop Review ⚡
https://youtu.be/D-EzAzrBRls
class Solution
{
pair solve(Node* root)
{
if(root -> left == NULL and root -> right == NULL)
return {root, root};
if(root -> left == NULL)
{
pair right = solve(root -> right);
root -> right = right.first;
right.first -> left = root;
return {root, right.second};
}
if(root -> right == NULL)
{
pair left = solve(root -> left);
left.second -> right = root;
root -> left = left.second;
return {left.first, root};
}
pair left = solve(root -> left);
pair right = solve(root -> right);
left.second -> right = root;
root -> left = left.second;
root -> right = right.first;
right.first -> left = root;
return {left.first, right.second};
}
public:
//Function to convert binary tree into circular doubly linked list.
Node *bTreeToCList(Node *root)
{
if(root == NULL)
return NULL;
pair res = solve(root);
res.first -> left = res.second;
res.second -> right = res.first;
return res.first;
}
};
