Swift solution
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# Co
# 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# Code\n```\nclass Solution {\n    func timeRequiredToBuy(_ tickets: [Int], _ k: Int) -> Int {\n        var result = 0\n        for i in 0 ..< k {\n            result += min(tickets[i], tickets[k])\n        }\n        result += tickets[k]\n        for i in k + 1 ..< tickets.count {\n            result += min(tickets[i], tickets[k] - 1)\n        }\n        return result\n    }\n}\n```
['Array', 'Queue', 'Swift', 'Simulation']