Lemonade Change

Problem Id: 860 Difficulty: Easy


Intuition

Solution


class Solution:
    def lemonadeChange(self, bills: List[int]) -> bool:
        five, ten, twenty = 0, 0, 0
        for pay in bills:
            if pay == 5:
                five += 1
            elif pay == 10:
                ten += 1
                five -= 1
                if five < 0:
                    return False
            else:
                twenty += 1
                if ten > 0:
                    ten -= 1
                    five -= 1
                else:
                    five -= 3
                if five < 0:
                    return False
        return True