Easiest C++ / Python3 / Java / C / Python / C# -- Solutions beats 100% One Pass Solutions.
Intuition\n\n\n\n\n\n\nC++ []\nclass Solution {\npublic:\n    int timeRequiredToBuy(vector<int>& tickets, int k) {\n        int cnt = 0, cn = tickets[k];\n     
# Intuition\n![0ehh83fsnh811.jpg](https://assets.leetcode.com/users/images/36f3b7d7-1036-4b78-bd01-65094b47049c_1712631327.383651.jpeg)\n![Screenshot 2024-04-09 082418.png](https://assets.leetcode.com/users/images/0b7118ce-fe2e-4c8c-ad2a-728db7a87116_1712631335.593573.png)\n![Screenshot 2024-04-09 082407.png](https://assets.leetcode.com/users/images/344029ee-aa7c-4a4e-9907-47c9783cf753_1712631340.8787644.png)\n![Screenshot 2024-04-09 082217.png](https://assets.leetcode.com/users/images/af423b0f-077d-40b6-bcb0-cb590989d214_1712631345.516715.png)\n![Screenshot 2024-04-09 082031.png](https://assets.leetcode.com/users/images/d182fdda-b8c2-4d00-8407-96ae840021ff_1712631351.598419.png)\n![Screenshot 2024-04-09 082810.png](https://assets.leetcode.com/users/images/374bc104-f786-4dae-800e-693151ca5557_1712631515.5004663.png)\n```C++ []\nclass Solution {\npublic:\n    int timeRequiredToBuy(vector<int>& tickets, int k) {\n        int cnt = 0, cn = tickets[k];\n        for (int i = 0; i < tickets.size(); i++)\n            cnt += min(cn - (i > k), tickets[i]);\n        return cnt;\n    }\n};\n```\n```python3 []\nclass Solution:\n    def timeRequiredToBuy(self, tickets: List[int], k: int) -> int:\n        cnt = 0\n        while tickets[k] > 0:\n            for u in range(len(tickets)):\n                if tickets[u] != 0:\n                    tickets[u] -= 1\n                    cnt += 1\n                    if u == k and tickets[k] == 0:\n                        return cnt\n\n        return cnt\n```\n```C# []\npublic class Solution {\n    public int TimeRequiredToBuy(int[] tickets, int k) {\n        int time = 0;\n        for (int i = 0; i < tickets.Length; i++){\n            if (i <= k)\n                time += Math.Min(tickets[i], tickets[k]);\n            else\n                time += Math.Min(tickets[i], tickets[k] - 1);\n        }\n        return time;\n    }\n}\n```\n```java []\nclass Solution {\n    public int timeRequiredToBuy(int[] tickets, int k) {\n        int res = 0;\n        while (tickets[k] != 0) {\n            for (int i = 0; i < tickets.length; i++) {\n                if (tickets[i] > 0 && tickets[k] != 0) {\n                    tickets[i]--;\n                    res++;\n                }\n            }\n        }\n        return res;\n    }\n}\n```\n```python []\nclass Solution(object):\n    def timeRequiredToBuy(self, tickets, k):\n        """\n        :type tickets: List[int]\n        :type k: int\n        :rtype: int\n        """\n        time = 0\n\n        for x in range(len(tickets)):\n            if tickets[x] >= tickets[k]:\n                time += tickets[k]\n            elif tickets[x] < tickets[k]:\n                time += tickets[x]\n\n            if x > k and tickets[x] >= tickets[k]:\n                time -= 1\n\n        return time\n```\n```C []\nint timeRequiredToBuy(int* tickets, int ticketsSize, int k) {\n    int cnt = 0, cn = tickets[k];\n    for (int i = 0; i < ticketsSize; i++)\n        cnt += fmin(cn - (i > k), tickets[i]);\n    return cnt;\n}\n```\n\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n    O(n)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n    O(1)\n# Code\n```\nclass Solution {\npublic:\n    int timeRequiredToBuy(vector<int>& tickets, int k) {\n        int cnt = 0, cn = tickets[k];\n        for (int i = 0; i < tickets.size(); i++)\n            cnt += min(cn - (i > k), tickets[i]);\n        return cnt;\n    }\n};\n```\n# Please upvote if it\'s useful\n![th.jpeg](https://assets.leetcode.com/users/images/41badb63-39c7-4b76-8d93-b8a9bd909590_1712631546.4291751.jpeg)\n
['Array', 'Queue', 'C', 'Simulation', 'Python', 'C++', 'Java', 'Python3']