C++ || Beats 96.57% solutions || Simple || Easy || O(n)
Intuition\n Describe your first thoughts on how to solve this problem. \nThe solution uses an unordered map "mpp" to track the number of $5 and $10 bills.This i
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe solution uses an unordered map "mpp" to track the number of $5 and $10 bills.This is important because when a customer buys a lemonade with a $10 or $20,we have to give back specific amounts of change.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nCreating an unordered_map<int, int> mpp to keep track of the number of $5 and $10 bills.\nUsing a loop to iterate over each element in bills vector,representing the payment from each customer.\n\nIf customer pays $5, no change is required, simply incrementing the count of $5 "mpp[5]++;".\n\nIf customer pays $10, we need to give $5 as change, so we are checking if we have have at least $5 bill "mpp[5] > 0",If its true we are decrementing the count of $5 bills "mpp[5]--;" and incrementing the count of $10 bills "mpp[10]++;".\nIf we don\'t have a $5 bill, return false.\n\nIf customer pays $20, we need to give $10 as a change, so first we are checking if we can give one $10 bill and one $5 bill as a change "(mpp[5] > 0 && mpp[10] > 0)", if we can then we are decrementing the count of both $10 and $5 bill "(mpp[5]--; mpp[10]--;)". If we cannot provide a $10 bill, then checking if we have at least three $5 bills "(mpp[5] >= 3)" if we do, give a three $5 bills as change and decrements its count "mpp[5] -= 3;"\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nTC - O(n)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nSC - O(1)\n\n# Code\n```\nclass Solution {\npublic:\n    bool lemonadeChange(vector<int>& bills) {\n        unordered_map<int , int>mpp;\n        \n        for(int it : bills){\n            if(it == 5){\n                mpp[5]++;\n            }\n            if(it == 10){\n                if(mpp[5] > 0){\n                    mpp[5]--;\n                    mpp[10]++;\n                }\n                else{\n                    return false;\n                }\n            }\n            else if(it == 20){\n                if(mpp[5] > 0 && mpp[10] > 0){\n                    mpp[5]--;\n                    mpp[10]--;\n                }\n                else if(mpp[5] >= 3){\n                    mpp[5] -= 3;\n                }\n                else{\n                    return false;\n                }\n            }\n        }\n        return true;\n    }\n};\n```
['C++']