🧑‍🎓Very Easy C++ Approach✨ Detailed Explanation✅....Beats 99.99% solutions on LeetCode ❤️‍🔥
Intuition\nFirst of all I tried to analyse that what are the different amounts in which the customer will be paying the bill and then I realised that this could
# Intuition\nFirst of all I tried to analyse that what are the different amounts in which the customer will be paying the bill and then I realised that this could be solved using simple if-else-if ladder statements.\n\n![image.png](https://assets.leetcode.com/users/images/aa8aef4a-9d0b-4907-baa2-c85904bc47bc_1723697817.2916007.png)\n\n\n# Approach\n- Initialise two variables `five_bill` and `ten_bill` which will denote the count of the 5 dollar bills and 10 dollar bills respectively.\n- Traverse through the bills vector using for loop.\n- If amount given by customer is equal to 5 then increment the count of five_bill.\n- Else if amount given by the customer is equal to 10 then check if `five_bill>0` then increment `ten_bill` and decrement `five_bill` else return `false`.\n- Else check if `(five_bill>0 and ten_bill>0)` then decrement `five_bill` and `ten_bill` else check if `five_bill>2` then decrease count of `five_bill` by 3 else return `false`;\n- Finally, return `true` if nothing is returned till now.\n\n# Complexity\n- **Time complexity:** O(N) \u23F3\n\n- **Space complexity:** O(1) \uD83D\uDE80\n\n# Code\n```\nclass Solution {\npublic:\n    bool lemonadeChange(vector<int>& bills) {\n        int five_bill=0, ten_bill=0;\n        for(auto x: bills){\n            if(x==5) ++five_bill;\n            else if(x==10){\n                if(five_bill>0){\n                    --five_bill;\n                    ++ten_bill;\n                }\n                else return false;\n            }\n            else {\n                if(five_bill>0 and ten_bill>0){\n                    --five_bill;\n                    --ten_bill;\n                }\n                else if(five_bill>2){\n                    five_bill-=3;\n                }\n                else return false;\n            }\n        }\n        return true;\n    }\n};\n```\n\n*Please upvote\uD83D\uDC4D if you found it helpful guys as it would encourage me to post more such solutions. \uD83D\uDE07*
['Array', 'C++']