Hi Striver, I just wanted to thank you for your incredible DSA tutorials. Your clear explanations and thorough examples have made a huge difference in my understanding and proficiency. Thanks to your videos, I've become very proficient in DSA, which has significantly boosted my confidence and performance in my coding Keep up the great work, you're making a big difference! Thank you very much🥹🥹🥹
it can also be solved using a stack //User function template for C++ class Solution { public: //Function to find if there is a celebrity in the party or not. int celebrity(vector& M, int n) { // code here stack st; //push all into stack for(int i = 0; i
Celebrity should not only nobody but also he should be known by everyone. If he know nobody and nobody know him then he becomes a tik toker, not a celebrity.
An edge to be considered is what if both arr[i][j]==1 && arr[j][i]==1, so i++,j--; so for both if((arr[i][j]==1 && arr[j][i]==1) || (arr[i][j]==0 && arr[j][i]==0)) i++,j--; In either case if you dont add this in the code, it will still run fine, mentioned it just to improve readability.
If top does not know down and down does not know top as well then top and down both will not move and will cause runtime error. I think you should explain that part like this:- while (low < high) { if (M[low][high] == 1) { // Case 1: low knows high => low cannot be the celebrity low++; } else { // Case 2: low does not know high => high cannot be the celebrity high--; } }
I didnot understand why did you teach celebrity problem in stack and queue playlist. I thought tis problem can be solved using stack and queues you taught bruteforce and the optmal using two pointers and where is the stack approach
we have O(1) space complexity in optimal solution and your solution having O(N); how can your solution is better than optimal? but yes, thanks for giving solution using Stack as this problem is included in stack and queue playlist.
@@KshitijVispute-wb6ze Instead of using the top and down variables, push all indices from 0 to n into a stack. For each iteration, pop the top 2 elements and check if there is a candidate celebrity. If yes, push the candidate back into the stack. This way, you would be left with 1 element if there is a celebrity. You would still have to perform the final check
1:34 , Yes you are , The GOAT of DSA for a reason!❤
Considering all the efforts and contributions you are the real celebrity vaiya. Thanks for everything.
waiting for this stack and queue playlist its finally here , many thanks to @takeuforward for the amazing content
i think it would be top++ down -- instead of top-- and down -- for else condition inside the while loop
Yes
common sense, you can correct it yourself.
Is this course is completed?@@kanishkaparwal3060
Oh GOD, I was about to say yeah you are the celebrity, but it sounds more good when he said it himself. Now let's get back to the video.
Hi Striver,
I just wanted to thank you for your incredible DSA tutorials. Your clear explanations and thorough examples have made a huge difference in my understanding and proficiency. Thanks to your videos, I've become very proficient in DSA, which has significantly boosted my confidence and performance in my coding
Keep up the great work, you're making a big difference! Thank you very much🥹🥹🥹
Yes, you are the celebrity Sir
Sir ji why is the celebrity problem in the stack/queue topic? didn't see any stack/queue usage
Same doubt...did you get any answer for it
Same doubt did you know the answer yet 😂
Vhi soch rha hoon 🥲
it can also be solved using a stack
//User function template for C++
class Solution
{
public:
//Function to find if there is a celebrity in the party or not.
int celebrity(vector& M, int n)
{
// code here
stack st;
//push all into stack
for(int i = 0; i
@@harshitminhas5875 99% Correct
How is this problem related to stack and queue?
Celebrity should not only nobody but also he should be known by everyone. If he know nobody and nobody know him then he becomes a tik toker, not a celebrity.
arre gajab bhai
Hi but we did not use stack or queue in this
An edge to be considered is what if both arr[i][j]==1 && arr[j][i]==1, so i++,j--;
so for both if((arr[i][j]==1 && arr[j][i]==1) || (arr[i][j]==0 && arr[j][i]==0)) i++,j--;
In either case if you dont add this in the code, it will still run fine, mentioned it just to improve readability.
yaa ,I was also thinking of this while watching
If top does not know down and down does not know top as well then top and down both will not move and will cause runtime error.
I think you should explain that part like this:-
while (low < high) {
if (M[low][high] == 1) {
// Case 1: low knows high => low cannot be the celebrity
low++;
} else {
// Case 2: low does not know high => high cannot be the celebrity
high--;
}
}
else low++ high--; because they both cannot be the celeibrity//////////////// add this condition
easy problem only thing to evaluate that there will be either o or 1 celebrity
wonderful intution and thought process
what is the intuition? Also why do I need to check?
GETTING YOU BROTHER RAJ
Optimal Solution - 7:48
every other people knows the celebrity 1 but 1 doesn't know himself ?😅
why are we checking if the top is greater than bottom or not ,cuz the top and bottom would end up at the same position after the while loop
celebrity to ho aap.
Hello, which tool you are using to write on a ipad. I want to install that tool for my sessions
I didnot understand why did you teach celebrity problem in stack and queue playlist. I thought tis problem can be solved using stack and queues you taught bruteforce and the optmal using two pointers and where is the stack approach
u can also solve this using stack
great solution
int celebrity(vector& M, int n) {
int top=0;
int bottom= n-1;
while(topbottom) return -1;
for(int i=0;i
thanks striver
thanks bhaiya
using stack we can have a better(between brute and optimal) solution with TC-O(2*n) and SC-O(n)
int findCelebrity(int n) {
stackst;
for(int i(0);i
we have O(1) space complexity in optimal solution and your solution having O(N); how can your solution is better than optimal?
but yes, thanks for giving solution using Stack as this problem is included in stack and queue playlist.
Yes, you are famous.
I have a doubt
why is this a stack problem ?
You can solve it by stack also which I did when i first saw the question
Achha doubt he bhai😂
@@RAJPATEL-ir7ly could you please explain how can you solve this using a stack?
@@KshitijVispute-wb6ze Instead of using the top and down variables, push all indices from 0 to n into a stack. For each iteration, pop the top 2 elements and check if there is a candidate celebrity. If yes, push the candidate back into the stack. This way, you would be left with 1 element if there is a celebrity. You would still have to perform the final check
Thank you.
UNDERSTOOD;
thanks sir
1:34 , Yes you are 😂😂😂
thanks
🙃