L2. Lemonade Change | Greedy Algorithm Playlist

Поделиться
HTML-код
  • Опубликовано: 5 окт 2024
  • Find problem link, notes in step 12: takeuforward.o...
    Follow me on socials: linktr.ee/take...

Комментарии • 50

  • @mohit7717
    @mohit7717 12 часов назад

    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 4 месяца назад +16

    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 4 месяца назад +3

      do strings on your own bro, i finished it. Solutions tab in LC is more than enough

  • @kathakalisaha9735
    @kathakalisaha9735 2 месяца назад +3

    i never thought greedy algo will be that easy, maybe because you are explaining it

  • @shwetanshusinha2690
    @shwetanshusinha2690 4 месяца назад +6

    Needed this playlist very badly.

  • @tushar9701
    @tushar9701 4 месяца назад +3

    Most Awaited playlist 🔥

  • @vighneshshankar1468
    @vighneshshankar1468 4 месяца назад +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?

  • @deepkodes4434
    @deepkodes4434 7 дней назад +1

    the main crux is choosing 10 5 for $20 over three 5's ,
    take the eg below if u want
    5555 10 20 10

  • @mehulthuletiya497
    @mehulthuletiya497 4 месяца назад +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;
    }
    };

  • @KKKK-pl8yf
    @KKKK-pl8yf 4 месяца назад +12

    Can we expect Stack and Queue playlist by end of this month or next month ?

    • @oppie335
      @oppie335 4 месяца назад +14

      Studying greedy you became greedy bruh😂

    • @yassenfathi526
      @yassenfathi526 2 месяца назад +1

      It's out bro

  • @UECAshutoshKumar
    @UECAshutoshKumar 19 дней назад +1

    Thank you 🙏

  • @jritzeku
    @jritzeku 3 месяца назад +1

    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.

  • @Cool96267
    @Cool96267 4 месяца назад

    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?

  • @Learner010
    @Learner010 4 месяца назад +8

    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 4 месяца назад +7

      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 4 месяца назад +1

      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 4 месяца назад +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 4 месяца назад

      @@jarvis3551thanks mate!!

    • @tanishkarawat5266
      @tanishkarawat5266 4 месяца назад

      correct! Figured it out on own lol

  • @kartikeykatyal7816
    @kartikeykatyal7816 4 месяца назад +3

    we want string playlist

  • @shresthjain7557
    @shresthjain7557 2 месяца назад +3

    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.

  • @utkarshsingh09
    @utkarshsingh09 Месяц назад

    Understood Sir!

  • @teeyaojha4365
    @teeyaojha4365 4 месяца назад +2

    please add link to this video in a2z sheet
    it just shows coming soon

  • @AdityaSrivastava-x3r
    @AdityaSrivastava-x3r 2 месяца назад +1

    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

  • @MJBZG
    @MJBZG Месяц назад

    super easy, understood

  • @KartikeyTT
    @KartikeyTT 4 месяца назад +1

    ty sir

  • @SibiRanganathL
    @SibiRanganathL 25 дней назад

    Understood

  • @sanchitdeepsingh9663
    @sanchitdeepsingh9663 3 месяца назад

    Thanks sir

  • @Shivi32590
    @Shivi32590 2 месяца назад

    thank you

  • @066_PRAVEENR-rl6py
    @066_PRAVEENR-rl6py 17 дней назад +1

    I dont how it's working.....😢

  • @catlord777x3
    @catlord777x3 2 месяца назад

    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

  • @learnergood
    @learnergood 2 месяца назад

    Hi Striver, How to find out for the problem we have to use greedy algorithm?

  • @ayushgaurabh8604
    @ayushgaurabh8604 3 месяца назад

    awesome

  • @subee128
    @subee128 3 месяца назад

    thanks

  • @StudyYuv
    @StudyYuv 2 месяца назад

    thanksss bro

  • @harshitjaiswal9439
    @harshitjaiswal9439 4 месяца назад

    understood

  • @jeethora586
    @jeethora586 3 месяца назад

    strings pleaseeeeeeeeee

  • @KartikeyTT
    @KartikeyTT 3 месяца назад +1

    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;
    }
    };

  • @lofi_feels1924
    @lofi_feels1924 4 месяца назад +2

    Are y har video m string string krna jruri h kya ispe s lgta ki tum log yaha bhi spoon feeding le rahe ho🙂

  • @Flash-qr5oh
    @Flash-qr5oh 4 месяца назад

    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;
    }

  • @harshalgarg1676
    @harshalgarg1676 Месяц назад

    US

  • @mohammadumaidansari5087
    @mohammadumaidansari5087 2 месяца назад

    Understood

  • @shashankvashishtha4454
    @shashankvashishtha4454 2 месяца назад

    understood

  • @adityapandey23
    @adityapandey23 2 месяца назад

    Understood

  • @pranavmisra5870
    @pranavmisra5870 3 месяца назад

    Understood