Easiest Approach || T.C: O(n) || S.C: O(n) || Beats 100%
Intuition\n Describe your first thoughts on how to solve this problem. \n- The core of this problem is to manage the change you have efficiently. Since customer
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n- The core of this problem is to manage the change you have efficiently. Since customers can only pay with Dollar 5, Dollar 10,or Dollar 20 bills, you need to ensure that you always have enough smaller bills on hand to provide the necessary change.\n\n1. **Dollar 5 Bill**: When a customer pays with a Dollar 5 bill, you simply increase your count of Dollar 5 bills. No change is required.\n\n2. **Dollar 10 Bill**: If a customer pays with a  Dollar 10 bill, you need to give them Dollar 5 as change. Therefore, you decrease the count of Dollar 5 bills and increase the count of Dollar 10 bills. If you don\'t have a Dollar 5 bill to give as change, you can\'t proceed, and the answer is false.\n\n3. **Dollar 20 Bill**: If a customer pays with a Dollar 20 bill, you can give change in two ways:\n\n- Preferably, give one  Dollar 10 bill and one Dollar 5 bill as change. This way, you maximize the higher denomination bills for future transactions.\n- If you don\'t have a Dollar 10 bill, you must give three  Dollar 5 bills as change. If neither option is possible, the answer is false.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. **Track the Count of Dollar 5 and Dollar 10 Bills**: We use two variables, fivenote and tennote, to keep track of the number of Dollar 5 and Dollar 10 bills we have at any point.\n2. **Iterate Through Each Bill**: For each bill in the bills array:\n   - If it\'s a Dollar 5 bill, increment fivenote.\n   - If it\'s a Dollar 10 bill, check if you have a Dollar 5 bill to give as change. If so, decrement fivenote and increment tennote. If not, return false.\n   - If it\'s a Dollar 20 bill, try to give one Dollar 10 bill and one Dollar 5 bill as change. If not possible, try giving three Dollar 5 bills. If neither is possible, return false.\n3. **Return True**: If you\'ve successfully provided change for all customers, return true.\n\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    bool lemonadeChange(vector<int>& bills) {\n\n        int fivenote=0;\n        int tennote=0;\n\n        for(auto bill:bills)\n        {\n            if(bill==5) fivenote++;\n            if(bill==10)\n            {\n                if(fivenote>=1){\n                    fivenote--;\n                    tennote++;\n                }\n                else return false;\n            }\n            if(bill==20)\n            {\n                if(tennote>=1 && fivenote>=1)\n                {\n                    tennote--;\n                    fivenote--;\n                }else if(fivenote>=3) fivenote=fivenote-3;\n                else return false;\n            }\n        }\n        return true;\n    }\n};\n```\n\n![upvote.jpg](https://assets.leetcode.com/users/images/4c2f8c8e-fe19-44b4-9b2c-76afd821e01d_1723728931.6508322.jpeg)\n
['Array', 'Greedy', 'C++']