L2. Lemonade Change | Greedy Algorithm Playlist

  Рет қаралды 43,896

take U forward

take U forward

Күн бұрын

Пікірлер: 55
@mohit7717
@mohit7717 Ай бұрын
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
@ritikkumarsingh5902
@ritikkumarsingh5902 6 ай бұрын
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!
@user-fw4kz3bb4g
@user-fw4kz3bb4g 6 ай бұрын
do strings on your own bro, i finished it. Solutions tab in LC is more than enough
@deepkodes4434
@deepkodes4434 2 ай бұрын
the main crux is choosing 10 5 for $20 over three 5's , take the eg below if u want 5555 10 20 10
@shwetanshu13
@shwetanshu13 6 ай бұрын
Needed this playlist very badly.
@kathakalisaha9735
@kathakalisaha9735 4 ай бұрын
i never thought greedy algo will be that easy, maybe because you are explaining it
@mehulthuletiya497
@mehulthuletiya497 6 ай бұрын
// 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; } };
@tushar9701
@tushar9701 6 ай бұрын
Most Awaited playlist 🔥
@shresthjain7557
@shresthjain7557 4 ай бұрын
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.
@keshavbadhekar
@keshavbadhekar Ай бұрын
Why aren't such helpful comments placed at the top instead of comments like 'Thank you, bhaiya... you're a god'
@Jigyarth
@Jigyarth 27 күн бұрын
cool got it
@UECAshutoshKumar
@UECAshutoshKumar 2 ай бұрын
Thank you 🙏
@shauryatomer1058
@shauryatomer1058 5 күн бұрын
thanks for another great video
@vighneshshankar1468
@vighneshshankar1468 6 ай бұрын
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?
@Cool96267
@Cool96267 6 ай бұрын
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?
@jritzeku
@jritzeku 5 ай бұрын
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.
@Learner010
@Learner010 6 ай бұрын
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
@saisumanth1739
@saisumanth1739 6 ай бұрын
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
@ketanlalcheta4558
@ketanlalcheta4558 6 ай бұрын
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)...!
@jarvis3551
@jarvis3551 6 ай бұрын
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
@amogu_07
@amogu_07 6 ай бұрын
@@jarvis3551thanks mate!!
@tanishkarawat5266
@tanishkarawat5266 6 ай бұрын
correct! Figured it out on own lol
@KKKK-pl8yf
@KKKK-pl8yf 6 ай бұрын
Can we expect Stack and Queue playlist by end of this month or next month ?
@oppie335
@oppie335 5 ай бұрын
Studying greedy you became greedy bruh😂
@yassenfathi526
@yassenfathi526 4 ай бұрын
It's out bro
@catlord777x3
@catlord777x3 4 ай бұрын
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
@kartikeykatyal7816
@kartikeykatyal7816 6 ай бұрын
we want string playlist
@utkarshsingh09
@utkarshsingh09 3 ай бұрын
Understood Sir!
@Serenity_Boy
@Serenity_Boy Ай бұрын
class Solution { public: bool lemonadeChange(vector& bills) { int five = 0, ten = 0; // Initialize ten to 0 for (int i = 0; i < bills.size(); i++) { if (bills[i] == 5) { five++; } else if (bills[i] == 10) { if (five) { five--; ten++; } else { return false; } } else { // bills[i] == 20 if (five && ten) { five--; ten--; } else if (five >= 3) { five -= 3; } else { return false; } } } return true; } };
@teeyaojha4365
@teeyaojha4365 5 ай бұрын
please add link to this video in a2z sheet it just shows coming soon
@MJBZG
@MJBZG 3 ай бұрын
super easy, understood
@KartikeyTT
@KartikeyTT 6 ай бұрын
ty sir
@sanchitdeepsingh9663
@sanchitdeepsingh9663 5 ай бұрын
Thanks sir
@Shivi32590
@Shivi32590 4 ай бұрын
thank you
@pranavmisra5870
@pranavmisra5870 5 ай бұрын
Understood
@066_PRAVEENR-rl6py
@066_PRAVEENR-rl6py 2 ай бұрын
I dont how it's working.....😢
@AdityaSrivastava-x3r
@AdityaSrivastava-x3r 4 ай бұрын
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
@Flash-qr5oh
@Flash-qr5oh 5 ай бұрын
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; }
@subee128
@subee128 5 ай бұрын
thanks
@harshitjaiswal9439
@harshitjaiswal9439 5 ай бұрын
understood
@ayushgaurabh8604
@ayushgaurabh8604 5 ай бұрын
awesome
@learnergood
@learnergood 4 ай бұрын
Hi Striver, How to find out for the problem we have to use greedy algorithm?
@KartikeyTT
@KartikeyTT 5 ай бұрын
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; } };
@StudyYuv
@StudyYuv 4 ай бұрын
thanksss bro
@saurabhkumaryadav3892
@saurabhkumaryadav3892 27 күн бұрын
3:36 i have 2 10s but i dont have zeo wrong said it will be i don't have 5 will be there
@harshalgarg1676
@harshalgarg1676 3 ай бұрын
US
@jeethora586
@jeethora586 5 ай бұрын
strings pleaseeeeeeeeee
@lofi_feels1924
@lofi_feels1924 6 ай бұрын
Are y har video m string string krna jruri h kya ispe s lgta ki tum log yaha bhi spoon feeding le rahe ho🙂
@mohammadumaidansari5087
@mohammadumaidansari5087 4 ай бұрын
Understood
@shashankvashishtha4454
@shashankvashishtha4454 4 ай бұрын
understood
@adityapandey23
@adityapandey23 3 ай бұрын
Understood
@SibiRanganathL
@SibiRanganathL 2 ай бұрын
Understood
L4. Jump Game - I | Greedy Algorithm Playlist
10:53
take U forward
Рет қаралды 61 М.
Smart Sigma Kid #funny #sigma
00:33
CRAZY GREAPA
Рет қаралды 8 МЛН
СКОЛЬКО ПАЛЬЦЕВ ТУТ?
00:16
Masomka
Рет қаралды 3,5 МЛН
Lazy days…
00:24
Anwar Jibawi
Рет қаралды 6 МЛН
Greedy Algorithms Explained
17:48
Tech With Tim
Рет қаралды 113 М.
L5. Jump Game - II | Greedy Algorithm Playlist
16:45
take U forward
Рет қаралды 68 М.
L10. Minimum number of platforms required in a railway station
18:10
take U forward
Рет қаралды 39 М.
Gas Station - Greedy - Leetcode 134 - Python
15:47
NeetCode
Рет қаралды 142 М.
L13. Fractional Knapsack Algorithm
18:41
take U forward
Рет қаралды 53 М.
I gave 127 interviews. Top 5 Algorithms they asked me.
8:36
Sahil & Sarra
Рет қаралды 674 М.
Sorting Algorithms Explained Visually
9:01
Beyond Fireship
Рет қаралды 552 М.
Why is Python 150X slower than C?
10:45
Mehul - Codedamn
Рет қаралды 18 М.
L6. Job Sequencing Problem | Greedy Algorithm Playlist
16:07
take U forward
Рет қаралды 52 М.
Smart Sigma Kid #funny #sigma
00:33
CRAZY GREAPA
Рет қаралды 8 МЛН