ar
Feedback
LeetCode, GeeksForGeeks Problem of the day solution

LeetCode, GeeksForGeeks Problem of the day solution

الذهاب إلى القناة على Telegram

Complete daily challenges from LeetCode, GeeksForGeeks and redeem their rewards Channel link : https://t.me/leetcode_gfg_potd

إظهار المزيد
1 250
المشتركون
+224 ساعات
+147 أيام
+2930 أيام
أرشيف المشاركات
class Solution { public: int findMinArrowShots(vector>& points) { sort(points.begin(),points.end()); if(points.size()<=1)return 1; vector>intervals; int s=points[0][0]; int e=points[0][1]; int prev=0; for(int i=1;ie) { intervals.push_back({s,e}); prev=i-1; s=sL; e=eL; } else { e=min(e,eL); } } if(prev!=points.size()-1) intervals.push_back({s,e}); return intervals.size(); } };

LeetCode | Daily challenge :

class Solution { public: //Function to return the level order traversal of a tree. vector levelOrder(Node* node) { queue q; vector v; q.push(node); while(!q.empty()){ Node* temp = q.front(); q.pop(); v.push_back(temp->data); if(temp->left){ q.push(temp->left); } if(temp->right){ q.push(temp->right); } } return v; } };

GFG | Problem of the day :

class Solution { public: vector> insert(vector>& intervals, vector& newInterval) { map m; int n = intervals.size(); vector> ret,temp; vector v,vv; for(int i=0;i= ret[i+1][0]) { if(ret[i][1] > ret[i+1][1]) ret[i+1][1] = ret[i][1]; ret[i+1][0] = ret[i][0]; ret.erase(it); } else { i++; it++; } } return ret; } };

LeetCode | Daily challenge :

class Solution{ public: // your task is to complete this function int countPairs(struct Node* head1, struct Node* head2, int x) { unordered_map mp; int ans=0; while(head1){ mp[(head1->data)]++; head1=head1->next; } while(head2){ ans+=mp.find(x-head2->data)!=mp.end(); head2=head2->next; } return ans; } };

GFG | Problem of the day :

class Solution { public: int findMaxLength(std::vector& nums) { std::unordered_map prefixSum; prefixSum[0] = -1; int sum = 0, result = 0, n = nums.size(); for (int i = 0; i < n; i++) { sum += (nums[i] == 0 ? -1 : 1); if (prefixSum.count(sum)) result = std::max(i - prefixSum[sum], result); else prefixSum[sum] = i; } return result; } };

LeetCode | Daily challenge :

class Solution { public: //Function to delete a node without any reference to head pointer. void deleteNode(Node *del_node) { Node *p=del_node; Node *q=p->next; while(q->next!=NULL){ swap(p->data,q->data); p=q; q=q->next; } swap(p->data,q->data); p->next=NULL; delete(q); } };

GFG | Problem of the day :

class Solution { public: vector productExceptSelf(vector& nums) { vectorans(nums.size(),1); for(int i=1;i=0;i--){ suff_prod*=nums[i+1]; ans[i]*=suff_prod; } return ans; } };

LeetCode | Daily challenge :

class Solution { public: // your task is to complete this function void sort(Node **head) { Node* odd=*head; Node* even=(*head)->next; Node* evenhead=even; //checking if linkedlist is empty if((*head==NULL ||(*head)->next==NULL)) { return; } //dividing odd and even linkedlist while(even!=NULL && even->next!=NULL) { odd->next=odd->next->next; even->next=even->next->next; odd=odd->next; even=even->next; } //Reversing Even linkedlist Node* temp=evenhead; Node* prev=NULL; Node* front; while(temp!=NULL) { front=temp->next; temp->next=prev; prev=temp; temp=front; } //adding reversed even linkedlist to end of odd linkedlist odd->next=prev; } };

GFG | Problem of the day :

class Solution { public: int numSubarraysWithSum(vector& nums, int goal) { int n = nums.size(); int result = 0; int prefixSum = 0; unordered_mapmp; mp[0] = 1; for(int i=0; i

LeetCode | Daily challenge :

class Solution { public: int largestSubsquare(int N, vector> A) { vector> top(N,vector(N,0)); vector> left(N,vector(N,0)); for (int i=0;i0) { int top1 = i-currentValue +1; int left1 = j-currentValue + 1; if ((left[top1][j] >= currentValue) && (top[i][left1] >= currentValue)) { maxSubSq = max(maxSubSq,currentValue); break; } currentValue--; } } } return maxSubSq; } };

GFG | Problem of the day :