@@thepriestofvaranasi aise bewakoof baate karte ho tum log jisme logic nahi hota aur tum log dsa mai logic banake jindegi mai aage badhne ki sochte ho?😂Love Babbar ne roadmap bhi diya hai + pura free c++ ka placement based dsa playlist bhi banaya hai, which is genuinely good if one religiously follows his whole playlist, but y'all will hate no matter what and compare. Both Striver and Love Babbar are good in their own way and they both are genuinely awesome.
The approach you taught for implementing stack using single array works only for LinkedList implementation but not with array implementation however swapping of elements works with array impl.
The issue is with q.top() at 10:06 . The queue container in C++ does not have a top() member function. Instead, you should use q1.front() to access the front element of the queue.
i have done slightly different,correct me if i am wrong,i am adding the elements in normal fashion,but while pooping i m first removing it ,and then adding it at top
Implementing Stack with Queue or Queue with Stack, is there a real life situation when we need to do this or is it only for sharpening brain as a problem to solve?
I think, he is talking about a single push operation. In a single push operation, we are just using a for loop which is running for (size-1) times. So at the worst case the TC would be O(n). (assuming the push operation in queue inside the for loop takes constant time. ) Correct me if I am wrong.
@@aadityabedi3140 Yes in asymptotic analysis both will be same, but interviewer may ask to use only single queue... Like sometimes, if you are doing something on O(N) time but using 2 passes(two independent loops), they may ask to do it in single pass (if possible)
Sir I have query that we are just trying reverse the order of insertion so we are reversing the elements For that i am assuming that our queue is a stack if I add x to it it will added to end of queue but since it must obey stack property it must me added front of queue so we empty our queue elements and add x to it,then add all elements that we removed in order of the removal
Hello bhaiya, I have one question... please reply... I am a B.Sc(c.s) Student. Please help me to know can I get a job(above 5 lpa). I learnt enough C++ and completed DSA and going to start web development and also 3 star at codechef. I can learn anything for job after Graduation. Please help to me tell that can I get or I have to do MCA.
Hi Utkarsh, i saw this same comment on linkedIn post also...... So, i thought let me help you out, Don't worry you are doing very good. you don't need MCA. u will find job which will give you more than 5 lpa easily. just keep going...... I am pursuing masters (M.Sc IT) from DAIICT and i am a 2 star coder at codechef. So, Comparing the your situation with me you have done a greate job......
"some just give road maps and make videos" and here you find the actual content you need to follow.. Great work!
Bhai tum aaj har jagah mujhe comment sec me dikh rhe ho yaar :-)
@@souvikpanda7797 aur kahan dekhe ho😂
True 💯
Love Babbar - Ye lo ek roadmap aur isse sikh lo😂
@@thepriestofvaranasi aise bewakoof baate karte ho tum log jisme logic nahi hota aur tum log dsa mai logic banake jindegi mai aage badhne ki sochte ho?😂Love Babbar ne roadmap bhi diya hai + pura free c++ ka placement based dsa playlist bhi banaya hai, which is genuinely good if one religiously follows his whole playlist, but y'all will hate no matter what and compare. Both Striver and Love Babbar are good in their own way and they both are genuinely awesome.
Wow, I never knew this approach by using a single queue, great explanation 👏
We are so fortunate to have an innovator like you. Never seen this method before ❤
You not only teach, you make feel how to do programming ❤ no need to go for code after getting approach.
if you dont code you will forget
@@sunitasharma3016 i meant no need to find code from other, after getting approach we can write code our self.
Single queue solution was really what I want 🙌
Wow, what a method of implementing stack using single queue, hats off!!!
very clever, amazed by the single queue implementation! keep up the great work striver bhai!
UNDERSTOOD.......Thank You So Much for this wonderful video.............🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻
The approach you taught for implementing stack using single array works only for LinkedList implementation but not with array implementation however swapping of elements works with array impl.
That single queue method is so simple, yet so effective 💥
Bhaijaan kya samjha rahe ho❤️❤️,Matalb maine abhi c start ki hai aur mujhe bhi ye concept yaad hogya...are bhai❤️❤️
Great approach using only single queue
Should not the TC be O(N^2) as the elements are being copied from q1 to q2 for every value of /n??
best explanation for this question
The issue is with q.top() at 10:06 . The queue container in C++ does not have a top() member function. Instead, you should use q1.front() to access the front element of the queue.
I am confused if this was implemented with a single queue or two queues. Please can someone explain?
Channel Subscribed! Short, to the point and understable. 🤓
i have done slightly different,correct me if i am wrong,i am adding the elements in normal fashion,but while pooping i m first removing it ,and then adding it at top
BEST VDO!
Got 2 ways to approach the question
finally I understood after seeing lots of explanation , thanks
Implementing Stack with Queue or Queue with Stack, is there a real life situation when we need to do this or is it only for sharpening brain as a problem to solve?
Thanks bhaiya you are doing great job. Keep making videos like this
Thank you striver bhai ☺❣
Thanks bhaiya ❤
what do you mean when you swap? is it liggite operation?
it's not exactly a swap, probably u could say shifting of the elements from Q2 to Q1
Long live Bhaiya.....
Thank you for your efforts ☺️
Literally... Mind blowing man 🔥🔥🔥🔥
Well explained, thankyou!!
Awesome... good explanation
how come time complexity is O(n)?
When we are pushing n-1 elements for each element. It would be somewhere O(nx(n-1))
correct me if I am wrong
I think, he is talking about a single push operation. In a single push operation, we are just using a for loop which is running for (size-1) times. So at the worst case the TC would be O(n). (assuming the push operation in queue inside the for loop takes constant time. )
Correct me if I am wrong.
wont using 2 queues it will have space complexity as o(2n) because there are 2 queues used
if not then dont you think,we havent optimised it ,if they both are giving same space and time complexity
brother wont the space complexity in second approach be O(1) as we are using the queue itself
Wo queue ka space nai hoga kya 😵💫
@@takeUforward brother fer space aur time complexity dono appraoches ki same hi aa rhi aise toh, interviewer ko koi bhi bta skte approach?
@@aadityabedi3140 Yes in asymptotic analysis both will be same, but interviewer may ask to use only single queue...
Like sometimes, if you are doing something on O(N) time but using 2 passes(two independent loops), they may ask to do it in single pass (if possible)
Awesome Approach
thank u for such an awesome explanation striver
i have never seen this approach before
Also to implement Stack we can use a Linked List. But I suppose it will not be efficient solution.
What if I wanna insert negative elements..
Will pop not create a problem?
should by Q1.push(x) in 6:23.
Thanks Striver Bro
small typo, q.front() instead of q.top()
where can i find the all question at one place? is there any google sheet for that too?
Bro What is the difference between cp course in gfg vs dsa course in gfg. Can you help what to prefer?
using two queue our result is 3,4,2 and using one queue our result is 3,2,4 why so? please reply
Check the question properly.. first he used 3,4,2 for pushing in two queue but in single queue method , he pushed in the order of 3,2,4
Genius 💫
understood
Thank you bhaiya fo making this content
thanks
Absolutely loved the explanation
Why don't universities hire people like them??
Watch in 1.25x for a better experience XD
thnx
Sir I have query that we are just trying reverse the order of insertion so we are reversing the elements
For that i am assuming that our queue is a stack if I add x to it it will added to end of queue but since it must obey stack property it must me added front of queue so we empty our queue elements and add x to it,then add all elements that we removed in order of the removal
WHERE YOU WILL STORE THE REMOVED ELEMENTS? IT IS BUT OBVIOUS THAT YOU WILL NEED EXTRA O(N) SPACE FOR THAT.
-
BROTHER HOW CAN WE HANDLE DUPLICATE ELEMENTS HERE
Thank you Bhaiya
understood.
10:55 Why should we do the unoptimized approach before ? Makes as an extra question to remember
Awesome.
Understood 👍
Understood 💯💯💯
Understood
thnk u
Why many links in the SDE sheet are missing? after Day 13....???
Because videos are not uploaded.
@@takeUforward so this series will take another year to complete?😶
@@mohithguptakorangi1766 you have the problems, try it yourself.. i have uploaded 100+ problems :)
@@takeUforward Ok thank you, I'll try my best
Came here just to like the video to complete 🎯
understood!!
complexity for both is same so how using a single queue is optimized?
Just osm bhai🔥
thx sir
Awesome !!!
using same queue why not we simply return a[rear-1%n] for top() ?
and for pop() insert dummy val in a[rear-1%n] then rear-- ; will this work?
BROTHER TOP IS IN THE FRONT ELEMENT OF THE QUEUE AND CANT BE ACCESSED IN THE REAR END.
Nice video
wonderful video. Maza aa gaya 1.25x me
nice one
2023 batch still studying 😢
awesome awesome awesome awesome
Hello bhaiya,
I have one question... please reply...
I am a B.Sc(c.s) Student.
Please help me to know can I get a job(above 5 lpa).
I learnt enough C++ and completed DSA and going to start web development and also 3 star at codechef.
I can learn anything for job after Graduation.
Please help to me tell that can I get or I have to do MCA.
Hi Utkarsh, i saw this same comment on linkedIn post also...... So, i thought let me help you out, Don't worry you are doing very good. you don't need MCA. u will find job which will give you more than 5 lpa easily. just keep going......
I am pursuing masters (M.Sc IT) from DAIICT and i am a 2 star coder at codechef. So, Comparing the your situation with me you have done a greate job......
@@janvibuddhadev5367 thank you
u are the bestttt
striver bhaiya bada hi chikna padate he !!!
Nice 30-04-2024
great great great!!!
woow
After watching half of the video able to solve @ leetcode
2 stack || java
import java.util.LinkedList;
class MyStack {
Queue q1;
Queue q2;
public MyStack() {
q1 = new LinkedList();
q2 = new LinkedList();
}
public void push(int x) {
q2.offer(x);
while (!q1.isEmpty()) {
q2.offer(q1.poll());
}
Queue temp = q1;
q1 = q2;
q2 = temp;
}
public int pop() {
return q1.poll();
}
public int top() {
return q1.peek();
}
public boolean empty() {
return q1.isEmpty();
}
}
Single queue solution was really what I want 🙌
Thanks
understood
Understood