bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 860. Lemonade Change

860. Lemonade Change

Leetcode Solutions

Greedy Change Making for Lemonade Stand

  1. Initialize two counters for 5and5 and 10 bills, both set to 0.
  2. Loop through each bill in the bills array.
    • If the bill is 5,incrementthe5, increment the 5 bill counter.
    • If the bill is 10,checkifwehavea10, check if we have a 5 bill to give as change. If yes, decrement the 5billcounterandincrementthe5 bill counter and increment the 10 bill counter. If no, return false.
    • If the bill is 20,firsttrytogivea20, first try to give a 10 and a 5billaschange.Ifnotpossible,trytogivethree5 bill as change. If not possible, try to give three 5 bills. If neither is possible, return false.
  3. If we can give change to all customers, return true.
UML Thumbnail

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...
bugfree Icon
OR