2073 Time Needed to Buy Tickets CPP
Intuition\n Describe your first thoughts on how to solve this problem. \nThe time it takes to go around once with all the tickets is n. Until a ticket reaches z
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe time it takes to go around once with all the tickets is n. Until a ticket reaches zero, it will continue to be consumed by n.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nYou can consume tickets at once by calculating the minimum value and multiplying it by n. Since k may be 0, 1 can be left and processed as the minimum value.\n\nThen, you can repeat it until the kth becomes 0 while consuming one sequentially.\n\n# Complexity\n- Time complexity : O(n)\n- Space complexity : O(1) \n\n# Code\n```\nclass Solution {\npublic:\n    int timeRequiredToBuy(vector<int>& tickets, int k) {\n        int n = tickets.size();\n        int ans = 0;\n        while (1) {\n            int min = *min_element(tickets.begin(), tickets.end());\n            if (min != 0 and min+1 < tickets[k]) {\n                for (int i = 0; i < n; ++i) {\n                    tickets[i] -= min;\n                }\n                ans += n * min;\n            } else {\n                break;\n            }\n        }\n        int i = 0;\n        while (tickets[k]) {\n            if (tickets[i]) {\n                tickets[i]--;\n                ans++;\n            }\n            i = (i+1)%n;\n        }\n        return ans;\n    }\n};\n```
['Array', 'Queue', 'Simulation', 'C++']