Beats 100%EASY C++ CODE
Intuition\n Describe your first thoughts on how to solve this problem. \nGREEDY APPROACH\n# Approach\n Describe your approach to solving the problem. \n1. Initi
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nGREEDY APPROACH\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Initialization: The function uses two counters: f for the number of 5 bills and t for the number of 10 bills.\n\n2. Decision Points:\n\n ->For a 10 bill, ensure you have a 5 bill to give as change.\n ->For a 20 bill, prioritize using one 10 bill and one 5 bill for change if available; otherwise, use three 5 bills.\n\n3. Processing Bills:\n\n ->5 Bill : Increment the 5 bill counter (f).\n ->10 Bill: Increment the 10 bill counter (t) and check if there is at least one 5 bill to provide change. If not, return false.\n ->20 Bill: Try to provide change using one 10 bill and one 5 bill. If that\'s not possible, check if there are at least three 5 bills. If neither option is available, return false.\n\n4. Final Result:\n         If the function manages to provide the correct change for all transactions, it returns true; otherwise, it returns false.\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(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        int f=0,t=0;\n        int n=bills.size();\n        for(int i=0;i<n;i++)\n        {\n            if(bills[i]==5)f++;\n            else if(bills[i]==10)\n            {\n                t++;\n                if(f>0)\n                {\n                    f--;\n                    continue;\n                }\n                return false;\n            }\n            else\n            {\n                if(f>0&&t>0)\n                {\n                    f--,t--;\n                    continue;\n                }\n                else if(f>=3)\n                {\n                    f-=3;\n                    continue;\n                }\n                return false;\n            }\n        }\n        return true;\n    }\n};\n\n```\n![lc upvote.jpg](https://assets.leetcode.com/users/images/2fe74a3a-98c1-4297-9b4b-7063ae9eab39_1723701790.8613887.jpeg)\n
['Array', 'Greedy', 'C++']