2 years after college I started first time greedy algorithm... Teacher or guide like you everyone wants in their start of their careers. Thank you so much Striver
Striver, your DSA Sheet is absolutely phenomenal! It's been an invaluable resource for mastering data structures and algorithms. Looking forward to the remaining topics, especially the much-anticipated sections on strings and heaps. Thanks for all your hard work!
Thankyou so much Striver for all you efforts throughout in delivering us so much valuable content. Any student / working professional can now be able to transition their career without paying money for courses. Would also like your insights on the point : While preparing for interviews most of the aspirants are going through the videos solely and solving the question after completely watching the video. And also are feeling lazy trying to solve the question on our own. What is the best way to complete any topic without being lazy and how should an aspirant approach any topic/playlist?
I was about to ask why this problem falls under greedy. This question and answer help me get my answer. Thanks to both of you.. and ofcourse a big thank to striver for as usual quality content (that too free of cost)...!
suppose u have five = 3 and 10 = 1, now u have bill = 20 u have 2 possibility: either give 3 five or give 1 five and 1 ten suppose u give 3 five so now u have 0 five now imagine next bill = 10 for this u need 1 five but u have already exhausted all five so u cant give a change but if u have thought greedily and have given 1 ten and 1 five then u could have given change for bill 10 also THEREFORE GREEDY IN THIS PROBLEM IS SAVING AS MANY FIVE AS POSSIBLE SO THAT WE CAN GIVE CHANGE TO MAKE BILLS
Those who are wondering where is greedy approach in this question: suppose a customer pays 20 Rs then we first try to give him change by giving 10 Rs and 5 Rs and if are unable to do then we given three 5 Rs change , in this way saving 5 Rs for future customers.
Bhiya pahle wala style se padhaiye . Pahle aap different platform ( GFG , Leetcode) se problem statement show kar ke padhate the to jayada samjh me aata tha 😢😢😢 abhi thoda problem hota hai
I think the quality of Video have decreased!! B'coz comming up with this solution is nothing, but I was hopping for this question or solving was involving greedy technique and mindset, that help us also understand greedy rather superficial definition
int lemonadeChange(vector bills) { int five = 0, ten = 0; for (int i : bills) { if (i == 5) five++; else if (i == 10) five--, ten++; else if (ten > 0) ten--, five--; else five -= 3; if (five < 0) return false; } return true; }
2 years after college I started first time greedy algorithm... Teacher or guide like you everyone wants in their start of their careers. Thank you so much Striver
Striver, your DSA Sheet is absolutely phenomenal! It's been an invaluable resource for mastering data structures and algorithms. Looking forward to the remaining topics, especially the much-anticipated sections on strings and heaps. Thanks for all your hard work!
do strings on your own bro, i finished it. Solutions tab in LC is more than enough
i never thought greedy algo will be that easy, maybe because you are explaining it
Needed this playlist very badly.
Most Awaited playlist 🔥
I have a doubt, in this questioon we have had just 5 as cost. What if cost is user defined, then how does it work?
the main crux is choosing 10 5 for $20 over three 5's ,
take the eg below if u want
5555 10 20 10
// TC: O(N)
// SC: O(1)
class Solution {
public:
bool lemonadeChange(vector& bills) {
int fives = 0, tens = 0;
for (int bill : bills) {
if (bill == 5) { // Case-01: 05
fives++;
} else if (bill == 10) { // Case-02: 10
if (fives == 0) {
return false;
}
fives--;
tens++;
} else {
if (tens > 0 && fives > 0) { // Case-03: 20
tens--;
fives--;
} else if (fives >= 3) {
fives -= 3;
} else {
return false;
}
}
}
return true;
}
};
Can we expect Stack and Queue playlist by end of this month or next month ?
Studying greedy you became greedy bruh😂
It's out bro
Thank you 🙏
IT would be neat to have solution for larger bills as well like 100,50 etc.to see how wed need to loop inside our loop.
Thankyou so much Striver for all you efforts throughout in delivering us so much valuable content. Any student / working professional can now be able to transition their career without paying money for courses.
Would also like your insights on the point :
While preparing for interviews most of the aspirants are going through the videos solely and solving the question after completely watching the video. And also are feeling lazy trying to solve the question on our own. What is the best way to complete any topic without being lazy and how should an aspirant approach any topic/playlist?
It will be great if you had explained why are we going for 10,5 first and 5,5,5 second in case of 20
It prefers to give one $10 and one $5 bill as change if possible ,because this leaves us with more $5 bills for future transactions
I was about to ask why this problem falls under greedy. This question and answer help me get my answer. Thanks to both of you.. and ofcourse a big thank to striver for as usual quality content (that too free of cost)...!
suppose u have five = 3 and 10 = 1, now u have bill = 20
u have 2 possibility:
either give 3 five or give 1 five and 1 ten
suppose u give 3 five so now u have 0 five
now imagine next bill = 10
for this u need 1 five but u have already exhausted all five so u cant give a change but if u have thought greedily and have given 1 ten and 1 five then u could have given change for bill 10 also
THEREFORE GREEDY IN THIS PROBLEM IS SAVING AS MANY FIVE AS POSSIBLE SO THAT WE CAN GIVE CHANGE TO MAKE BILLS
@@jarvis3551thanks mate!!
correct! Figured it out on own lol
we want string playlist
Those who are wondering where is greedy approach in this question:
suppose a customer pays 20 Rs then we first try to give him change by giving 10 Rs and 5 Rs and if are unable to do then we given three 5 Rs change , in this way saving 5 Rs for future customers.
Understood Sir!
please add link to this video in a2z sheet
it just shows coming soon
Bhiya pahle wala style se padhaiye . Pahle aap different platform ( GFG , Leetcode) se problem statement show kar ke padhate the to jayada samjh me aata tha 😢😢😢 abhi thoda problem hota hai
super easy, understood
ty sir
Understood
Thanks sir
thank you
I dont how it's working.....😢
I think the quality of Video have decreased!!
B'coz comming up with this solution is nothing, but I was hopping for this question or solving was involving greedy technique and mindset, that help us also understand greedy rather superficial definition
Hi Striver, How to find out for the problem we have to use greedy algorithm?
awesome
thanks
thanksss bro
understood
strings pleaseeeeeeeeee
C++ Solution of above video
class Solution {
public:
bool lemonadeChange(vector& bills) {
int five=0;
int ten=0;
for(int i=0; i=1 && five>=1){
ten--;
five--;
}
else if( five>=3){
five-=3;
}
else{
return false;
}
}
else{
five++;
}
}
return true;
}
};
Are y har video m string string krna jruri h kya ispe s lgta ki tum log yaha bhi spoon feeding le rahe ho🙂
int lemonadeChange(vector bills) {
int five = 0, ten = 0;
for (int i : bills) {
if (i == 5) five++;
else if (i == 10) five--, ten++;
else if (ten > 0) ten--, five--;
else five -= 3;
if (five < 0) return false;
}
return true;
}
US
Understood
understood
Understood
Understood