C++ Solution || Comments || Easy || Explained
Intuition\n Describe your first thoughts on how to solve this problem. \nCreate 3 variable to count no. of $coins$ like cnt5 = 0, cnt10 = 0, cnt20 = 0 and now i
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nCreate 3 variable to count no. of $coins$ like `cnt5 = 0, cnt10 = 0, cnt20 = 0` and now increment and decrement according to the received amount.\n\n*Refer code for more details*\n\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---\n\n# Code\n```\nclass Solution {\npublic:\n    bool lemonadeChange(vector<int>& bills) \n    {\n        int cnt5 = 0,cnt10 = 0,cnt20 = 0;\n\n        //handling the case\n        //if no 5 coin is present than no change\n        if(bills[0] != 5){\n            return false;\n        }\n\n        for(int i = 0;i<bills.size();i++)\n        {\n            if(bills[i] == 5)\n            {\n                cnt5++;\n            }\n            else if(bills[i] == 10)\n            {\n                //if we have $5 coin fine \n                //otherwise no change available\n                if(cnt5 > 0)\n                {\n                    cnt5--;\n                    cnt10++;\n                }\n                else{return false;}\n            }\n            else if(bills[i]==20)\n            {\n                //case1\n                //one $10 coin and $5 coin needed\n                if(cnt10>0 && cnt5>0){cnt5--;cnt10--;cnt20++;}\n\n                //case2\n                //we need three $5 coins\n                else if(cnt5>=3){cnt5 -= 3;cnt20++;}\n\n                //otherwise no change\n                else{return false;}\n            }\n        }\n        return true;\n    }\n};\n```\n* ***Try to understand the code rather than coping.***\n* ***If you liked my work than upvote my solution.***\n\n\t\t\t\t\t\t\t\t\t\t AND\n\t\t\t\t\t\t\t\t\t\t \n\t\t\t\t\t\t\t\t**** Happy Coding ****\n\t\t\t\t\t\t**** Keep Solving, Keep Upgrading **** \n
['Array', 'C++']