- Видео 74
- Просмотров 5 771
codeTips
Индия
Добавлен 10 мар 2023
Hello, my name is Rochak and welcome to my channel codeTips.
Here I make videos related to dsa.
Here I make videos related to dsa.
Largest Pair Sum | GFG Problem of the Day | Arrays | gfg potd
In this video I'll be discussing the solution of Largest Pair Sum.
GfG Problem Link : www.geeksforgeeks.org/problems/pair-sum--120604/1
Code in pinned comment
Timestamps :
0:00 - Problem Statement
0:49 - Explanation
08:27 - Code
#dsa #problemsolving #datastructureandalgorithm
GfG Problem Link : www.geeksforgeeks.org/problems/pair-sum--120604/1
Code in pinned comment
Timestamps :
0:00 - Problem Statement
0:49 - Explanation
08:27 - Code
#dsa #problemsolving #datastructureandalgorithm
Просмотров: 56
Видео
XOR Linked List | GFG Problem of the Day | Linked List
Просмотров 204День назад
In this video I'll be discussing the solution of XOR Linked List. GFG Problem Link : www.geeksforgeeks.org/problems/xor-linked-list/1 Code in pinned comment Timestamps : 0:00 - Problem Statement 0:35 - Explanation 15:33 - Code #dsa #problemsolving #datastructureandalgorithm
Find the number of islands | GfG Problem of the Day | Graph | DFS | Connected Components
Просмотров 1072 дня назад
In this video I'll be discussing the solution of Find the number of islands. GfG Problem Link : www.geeksforgeeks.org/problems/find-the-number-of-islands/1 Code in pinned comment Timestamps : 0:00 - Problem Statement 1:11 - Explanation 14:10 - Code #dsa #problemsolving #datastructureandalgorithm
Not a subset sum | GfG Problem of the Day | Arrays
Просмотров 3113 дня назад
In this video I'll be discussing the solution of Not a subset sum. GfG Problem Link : www.geeksforgeeks.org/problems/smallest-number-subset1220/1 Code in pinned comment Timestamps : 0:00 - Problem Statement 0:30 - Explanation 6:50 - Code #dsa #problemsolving #datastructureandalgorithm
Deletion and Reverse in Circular Linked List | GfG Problem of the Day | Linked List
Просмотров 2754 дня назад
In this video I'll be discussing the solution of Deletion and Reverse in Circular Linked List. GfG Problem Link : www.geeksforgeeks.org/problems/deletion-and-reverse-in-linked-list/1 Code in pinned comment Timestamps : 0:00 - Problem Statement 0:43 - Explanation 12:06 - Code #dsa #problemsolving #datastructureandalgorithm
Majority Vote | GfG Problem of the Day | Arrays | Moore's Voting Algorithm
Просмотров 265 дней назад
In this video I'll be discussing the solution of Majority Vote. GfG Problem Link : www.geeksforgeeks.org/problems/majority-vote/1 Code in pinned comment Timestamps : 0:00 - Problem Statement 0:30 - Explanation 9:05 - Code #dsa #problemsolving #datastructureandalgorithm
Kadane's Algorithm | GfG Problem of the Day | Arrays
Просмотров 122Месяц назад
In this video I'll be discussing the solution of Kadane's Algorithm. GfG Problem Link : www.geeksforgeeks.org/problems/kadanes-algorithm-1587115620/1 Code in pinned comment Timestamps : 0:00 - Problem Statement 0:40 - Explanation 10:26 - Code #dsa #problemsolving #datastructureandalgorithm
Count ways to N'th Stair | GfG Problem of the Day | Dynamic Programming
Просмотров 134Месяц назад
In this video I'll be discussing the solution of Count ways to N'th Stair. GfG Problem Link : www.geeksforgeeks.org/problems/count-ways-to-nth-stairorder-does-not-matter5639/1 Timestamps : 0:00 - Problem Statement 1:00 - Explanation 7:09 - Code #dsa #problemsolving #dynamicprogramming #datastructureandalgorithm
Minimum number of deletions and insertions | GfG Problem of the Day | Dynamic Programming
Просмотров 178Месяц назад
In this video I'll be discussing the solution of Minimum number of deletions and insertions. GfG Problem Link : www.geeksforgeeks.org/problems/minimum-number-of-deletions-and-insertions0209/1 Timestamps : 0:00 - Problem Statement 1:20 - Explanation 11:06 - Code #dsa #problemsolving #dynamicprogramming #datastructureandalgorithm
Minimum Cost Path | GfG Problem of the Day | Dijkstra's Algorithm
Просмотров 548Месяц назад
In this video I'll be discussing the solution of Minimum Cost Path. GfG Problem Link : www.geeksforgeeks.org/problems/minimum-cost-path3833/1 Timestamps : 0:00 - Problem Statement 0:58 - Explanation 7:28 - Code #dsa #problemsolving #datastructureandalgorithm
Max sum path in two arrays | GfG Problem of the Day | Arrays
Просмотров 72Месяц назад
In this video I'll be discussing the solution of Max sum path in two arrays. GfG Problem Link : www.geeksforgeeks.org/problems/max-sum-path-in-two-arrays/1 Timestamps : 0:00 - Problem Statement 1:10 - Explanation 8:26 - Code #dsa #problemsolving #datastructureandalgorithm
Sorted subsequence of size 3 | GfG Problem of the Day | Arrays
Просмотров 37Месяц назад
In this video I'll be discussing the solution of Sorted subsequence of size 3. GfG Problem Link : www.geeksforgeeks.org/problems/sorted-subsequence-of-size-3/1 Timestamps : 0:00 - Problem Statement 0:41 - Explanation 8:34 - Code #dsa #problemsolving #datastructureandalgorithm
0 - 1 Knapsack Problem | GfG Problem of the Day | Dynamic Programming
Просмотров 125Месяц назад
In this video I'll be discussing the solution of 0 - 1 Knapsack Problem. GfG Problem Link : www.geeksforgeeks.org/problems/0-1-knapsack-problem0945/1 Timestamps : 0:00 - Problem Statement 1:16 - Explanation 11:36 - Code #dsa #problemsolving #dynamicprogramming #datastructureandalgorithm
Left View of Binary Tree | GfG Problem of the Day | Binary Tree
Просмотров 73Месяц назад
In this video I'll be discussing the solution of Left View of Binary Tree. GfG Problem Link : www.geeksforgeeks.org/problems/left-view-of-binary-tree/1 Timestamps : 0:00 - Problem Statement 0:42 - Explanation 5:45 - Code #dsa #problemsolving #binarytree #datastructureandalgorithm
Alien Dictionary | GfG Problem of the Day | Graph | Topological Sort
Просмотров 90Месяц назад
In this video I'll be discussing the solution of Alien Dictionary. GfG Problem Link : www.geeksforgeeks.org/problems/alien-dictionary/1 Timestamps : 0:00 - Problem Statement 0:55 - Explanation 18:14 - Code #dsa #problemsolving #graph #datastructureandalgorithm
Instead of using O(2N). I have solved it in O(N), here is my approach class Solution { public: int pairsum(vector<int> &arr) { // code here int greater1=arr[0]; int greater2=arr[1]; int n=arr.size(); for(int i=2;i<n;i++){ int smaller=(greater1<greater2)?greater1:greater2; int other=greater1+greater2-smaller; if(arr[i]>smaller){ smaller=arr[i]; } if(greater1<greater2){ greater1=smaller; } else if(greater1>greater2){ greater2=smaller; } } return greater1+greater2; } }; BTW: thanks for making consistent videos, it really helps me keep going bro 😀
Yes, so instead of using two for loops, you have written multiple if else condition inside one for loop. So yeah that's great, and thanks for your kind words.😀
Let's Connect 🤝 : LinkedIn : www.linkedin.com/in/rochak-vyas17/ Code :- class Solution { public: int pairsum(vector<int> &arr) { int n=arr.size(); int maxi=INT_MIN; for(int i=0;i<n;i++){ if(arr[i]>maxi){ maxi=arr[i]; } } int secmaxi=INT_MIN; for(int i=0;i<n;i++){ if(arr[i]>secmaxi&&arr[i]<maxi){ secmaxi=arr[i]; } } return maxi+secmaxi; } };
Let's Connect 🤝 : LinkedIn : www.linkedin.com/in/rochak-vyas17/ Code :- struct Node *insert(struct Node *head, int data) { Node* newnode=new Node(data); newnode->npx=XOR(NULL,head); if(head!=NULL){ Node* temp=XOR(head->npx,NULL); head->npx=XOR(temp,newnode); } head=newnode; return head; } vector<int> getList(struct Node *head) { vector<int>ans; Node* prev=NULL; while(head!=NULL){ ans.push_back(head->data); Node* temp=head; head=XOR(prev,head->npx); prev=temp; } return ans; }
Let's Connect 🤝 : LinkedIn : www.linkedin.com/in/rochak-vyas17/ Code :- class Solution { public: void dfs(vector<vector<char>>&grid,vector<vector<int>>&vis,int i,int j,int n, int m){ if(i>=n||j>=m||i<0||j<0||grid[i][j]=='0'||vis[i][j]==1){ return; } vis[i][j]=1; dfs(grid,vis,i+1,j,n,m); dfs(grid,vis,i-1,j,n,m); dfs(grid,vis,i,j+1,n,m); dfs(grid,vis,i,j-1,n,m); dfs(grid,vis,i+1,j+1,n,m); dfs(grid,vis,i-1,j-1,n,m); dfs(grid,vis,i+1,j-1,n,m); dfs(grid,vis,i-1,j+1,n,m); } int numIslands(vector<vector<char>>& grid) { int n=grid.size(); int m=grid[0].size(); int ans=0; vector<vector<int>>vis(n,vector<int>(m,0)); for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ if(grid[i][j]=='1'&&!vis[i][j]){ dfs(grid,vis,i,j,n,m); ans++; } } } return ans; } };
but how 1,3 is a subset. the concept of subset is that , all the elements need to be consecutive
Thing which you are talking about is known as subarray.
Let's Connect 🤝 : LinkedIn : www.linkedin.com/in/rochak-vyas17/ Code :- class Solution { public: long long findSmallest(vector<int> &arr) { long long ans=1; int n=arr.size(); for(int i=0;i<n;i++){ if(arr[i]>ans){ return ans; } else{ ans=ans+arr[i]; } } return ans; } };
long long findSmallest(vector<int> &arr) { long long res=1; for(int i=0;i<arr.size();i++){ if(res<arr[i]) break; res=res+arr[i]; } return res; }
Let's Connect 🤝 : LinkedIn : www.linkedin.com/in/rochak-vyas17/ Code : class Solution { public: // Function to reverse a circular linked list Node* reverse(Node* head) { if(head==NULL||head->next==head){ return head; } Node* prev=NULL; Node* curr=head; Node* next; do{ next=curr->next; curr->next=prev; prev=curr; curr=next; }while(curr!=head); head->next=prev; head=prev; return head; } // Function to delete a node from the circular linked list Node* deleteNode(Node* head, int key) { if(head==NULL){ return NULL; } if(head->data==key){ if(head->next==head){ delete head; return NULL; } Node* last=head; while(last->next!=head){ last=last->next; } last->next=head->next; Node* temp=head; head=head->next; delete temp; return head; } Node* prev; Node* curr=head; while(curr->next!=head){ if(curr->data==key){ prev->next=curr->next; delete curr; return head; } prev=curr; curr=curr->next; } return head; } };
Let's Connect 🤝 : LinkedIn : www.linkedin.com/in/rochak-vyas17/ Code : class Solution { public: // Function to find the majority elements in the array vector<int> findMajority(vector<int>& nums) { int candidate1=nums[0]; int candidate2=nums[1]; int vote1=0; int vote2=0; int n=nums.size(); vector<int>ans; for(int i=0;i<n;i++){ if(nums[i]==candidate1){ vote1++; } else if(nums[i]==candidate2){ vote2++; } else if(vote1==0){ candidate1=nums[i]; } else if(vote2==0){ candidate2=nums[i]; } else{ vote1--; vote2--; } } vote1=0; vote2=0; int flag=0; for(int i=0;i<n;i++){ if(nums[i]==candidate1){ vote1++; } else if(nums[i]==candidate2){ vote2++; } } if(vote1>n/3){ ans.push_back(candidate1); flag=1; } if(vote2>n/3){ ans.push_back(candidate2); flag=1; } if(!flag){ return {-1}; } return ans; } };
Let's Connect 🤝 : LinkedIn : www.linkedin.com/in/rochak-vyas17/ Code : class Solution { public: long long maxSubarraySum(vector<int> &arr) { int n=arr.size(); long long sum=0; long long maxi=INT_MIN; for(int i=0;i<n;i++){ sum+=arr[i]; maxi=max(maxi,sum); if(sum<0){ sum=0; } } return maxi; } };
return int(n/2) +1
Yeah this can also work
your solution ok but for longer run learn the dp variation that is the take from the problem
Let's Connect 🤝 : LinkedIn : www.linkedin.com/in/rochak-vyas17/ Code : class Solution{ public: int nthStair(int n){ int dp[n+1]; dp[1]=1; dp[2]=2; for(int i=3;i<=n;i++){ dp[i]=dp[i-2]+1; } return dp[n]; } };
Bhai solution link bhi dal diya kr
Ok, I'll keep it from now
Easy Peasy ☺☺
Let's Connect 🤝 : LinkedIn : www.linkedin.com/in/rochak-vyas17/
Bhai solution github pe dalke uska link share kr diya kr,baaki sb thik hai. sahi ja raha hai tu👍
TY :)
Glad you liked it
Great Explanation Bhaiya , Love You 🧡🧡🧡🧡 Bhaiya i think there will be no need of visited vector as we are using priority_queue ...
Glad that you liked it. And yeah we do need visited array because when we are going to our neighboring elements it can happen that we come across same element as neighbor with some other element.
@@codetips-byRochak see this once Bhaiya , I don't use vis , and it works i think it will work bcz until we are not finding the less value of dist array then we will not update pq , and if we are not updating pq then it will empty when all element are visited.. pls conform this 🙏🙏... class Solution{ public: int dx[4]={-1,0,1,0}; int dy[4]={0,1,0,-1}; int minimumCostPath(vector<vector<int>>& grid){ int n=grid.size(); priority_queue<pair<int,pair<int,int>>,vector<pair<int,pair<int,int>>>,greater<pair<int,pair<int,int>>>>pq; vector<vector<int>>dist(n,vector<int>(n,1e9)); dist[0][0]=grid[0][0]; pq.push({grid[0][0],{0,0}}); while(!pq.empty()){ int cost=pq.top().first; int xCo=pq.top().second.first; int yCo=pq.top().second.second; pq.pop(); for(int i=0;i<4;i++){ int newX=xCo+dx[i]; int newY=yCo+dy[i]; if(newX>=0&&newX<n&&newY>=0&&newY<n){ if(dist[newX][newY]>grid[newX][newY]+cost){ dist[newX][newY]=grid[newX][newY]+cost; pq.push({dist[newX][newY],{newX,newY}}); } } } } return dist[n-1][n-1]; } };
Yes bro it does work, but what I mean to say is it's safer to use visited array (although it does not require in this question), just as a template to solve these kind of question. It doesn't require in this question but it might require in some other variation for these kind of problems.
@@codetips-byRochak got it 🧡🧡🧡🧡☺☺☺☺
@@codetips-byRochak ook Got It
why not DP?
Dp will increase the complexity by reaching out to each and every state( because just imagine, if we are at cell x,y and we go to top, and again through some other path we again come across x,y with some lower path sum, so we are going to same node again and again, so here we are not restricted with one forward direction, we are also considering backward direction, so it can keep on going to find minimum sum, by going forward direction, backward direction,forward direction again, and so on....), but Dijkstra will stop when we encounter bottom right cell, because that will be minimum sum because we are keeping min heap. Hope you understood.
Let's Connect 🤝 : LinkedIn : www.linkedin.com/in/rochak-vyas17/
Let's Connect 🤝 : LinkedIn : www.linkedin.com/in/rochak-vyas17/
Let's Connect 🤝 : LinkedIn : www.linkedin.com/in/rochak-vyas17/
Let's Connect 🤝 : LinkedIn : www.linkedin.com/in/rochak-vyas17/
Let's Connect 🤝 : LinkedIn : www.linkedin.com/in/rochak-vyas17/
HWLLO BHAI
Let's Connect 🤝 : LinkedIn : www.linkedin.com/in/rochak-vyas17/
Let's Connect : LinkedIn : www.linkedin.com/in/rochak-vyas17/
thank.. u bhai..
Welcome
class Solution { public: int t=0; void gettime(map<Node*,Node*>&mp,Node* start){ queue<Node*>q; q.push(start); map<Node*,int>vis; vis[start]=1; while(!q.empty()){ int s=q.size(); int flag=0; for(int i=0;i<s;i++){ Node* node=q.front(); q.pop(); if(node->left&&!vis[node->left]){ flag=1; vis[node->left]=1; q.push(node->left); } if(node->right&&!vis[node->right]){ flag=1; vis[node->right]=1; q.push(node->right); } if(mp[node]&&!vis[mp[node]]){ flag=1; vis[mp[node]]=1; q.push(mp[node]); } } if(flag){ t++; } } } Node* bfs(Node* root, int target,map<Node*,Node*>&mp){ queue<Node*>q; Node* start; q.push(root); while(!q.empty()){ Node* node=q.front(); q.pop(); if(node->data==target){ start=node; } if(node->left){ mp[node->left]=node; q.push(node->left); } if(node->right){ mp[node->right]=node; q.push(node->right); } } return start; } int minTime(Node* root, int target) { map<Node*,Node*>mp; Node* start=bfs(root,target,mp); gettime(mp,start); return t; } };
Bro solution link dedo
I have pinned the code in comment. You can check it out
Code is giving tle now
No bro, it is still getting all 1115 test cases passed. I think you might not have popped the element out of the queue. That might be one reason for tle.
I have pinned the code in comment. You can check it out. It is getting accepted.
@@codetips-byRochakSorry, nothing was wrong in the code, the same code now getting accepted
There might be something wrong, otherwise it can't happen. But yeah, happy to hear that it got accepted
@@codetips-byRochak thank you
amazing explanation
Glad you liked it
@@codetips-byRochakgiving tle now
Let's Connect : LinkedIn : www.linkedin.com/in/rochak-vyas17/
Let's Connect : LinkedIn : www.linkedin.com/in/rochak-vyas17/
Very clear explanation, Thankyou.
Glad it was helpful!
Let's Connect : LinkedIn : www.linkedin.com/in/rochak-vyas17/
bhai link toh de de previous video kaa description me, pura maja kharab kar diya
I have added the video link in the description. Sorry for the inconvenience.
Let's Connect 🤝 : LinkedIn : www.linkedin.com/in/rochak-vyas17/
Let's Connect 🤝 : LinkedIn : www.linkedin.com/in/rochak-vyas17/
Let's Connect 🤝 : LinkedIn : www.linkedin.com/in/rochak-vyas17/
Let's Connect 🤝 : LinkedIn : www.linkedin.com/in/rochak-vyas17/
thanks for the video bro..this is the most simple yet the best approach in youtube 💛
Thanks🙂 Means a lot 😀😀
Let's Connect 🤝 : LinkedIn : www.linkedin.com/in/rochak-vyas17/
👌
Thank you🙂🙂
Let's Connect 🤝 : LinkedIn : www.linkedin.com/in/rochak-vyas17/
your sliding windows approach is very helpful brother🙏🙏💥
Glad to hear that🙂🙂
Let's Connect 🤝 : LinkedIn : www.linkedin.com/in/rochak-vyas17/
Let's Connect 🤝 : LinkedIn : www.linkedin.com/in/rochak-vyas17/
Let's Connect 🤝 : LinkedIn : www.linkedin.com/in/rochak-vyas17/
Let's Connect 🤝 : LinkedIn : www.linkedin.com/in/rochak-vyas17/