C++ solution||Beginner friendly solution
Approach\n\n1. Initialize count to 0. This variable will keep track of the total number of tickets bought.\n2. Start a loop where pass represents the number of 
# Approach\n\n1. Initialize `count` to **0**. This variable will keep track of the total number of tickets bought.\n2. Start a loop where `pass` **represents the number of passes made to buy tickets**. This loop continues until the kth person has recieved the number of tickets wanted i.e. `tickets[k]` **becomes zero**.\n3. Inside the outer loop, there\'s another loop that iterates over tickets array (indexed by i).\n4. For each value in tickets array, if it has available tickets (`tickets[i] != 0`), **increment the count** to reflect the purchase of one ticket and **decrease the count of available tickets** for that type by one (`tickets[i] = tickets[i] - 1`).\n5. Check if the number of available tickets for the specified person k **has become zero**. If it has, `break` out of the inner loop.\n6. Repeat steps 3-5 until the number of tickets required by person **k becomes zero**.\n7. Finally, `return` the **total count** of tickets bought (`count`).\n\n# Complexity\n- Time complexity:\nO(n^2)\n**Reason:** The code contains a nested loop where the outer loop runs until `tickets[k]` becomes 0 and the inner loop iterates over all elements in the tickets vector. This results in a quadratic time complexity.\n\n- Space complexity:\nO(1)\n**Reason:** The space complexity of this solution is **O(1)** because we are using a constant amount of extra space regardless of the size of the input.\n\n![Screenshot 2024-04-09 140635.png](https://assets.leetcode.com/users/images/51005606-5194-455e-9d2a-50bdeac4e7eb_1712653820.9058864.png)\n\n\n\n# Code\n```\nclass Solution {\npublic:\n    int timeRequiredToBuy(vector<int>& tickets, int k) {\n        int count = 0;\n        for (int pass = 0; tickets[k] != 0; pass++) {\n            for (int i = 0; i < tickets.size(); i++) {\n                if (tickets[i] != 0) {\n                    count++;\n                    tickets[i] = tickets[i] - 1;\n                }\n                if (tickets[k] == 0) {\n                    break;\n                }\n            }\n        }\n        return count;\n    }\n};\n```
['Array', 'C++']