Simple approach ✅ with visual explanation 🔥|| No queue needed || Python3
Intuition\nOne approach would be to simulate the exact scenario using a queue. That would work, but in the worst case it may take O(n^2) time because each secon
# Intuition\nOne approach would be to simulate the exact scenario using a queue. That would work, but in the worst case it may take O(n^2) time because each second would be needed to be counted in the loop.\n\nIs there something better, to figure out the time needed as we visit every element?\n\n# Approach\nFor the example [4, 2, 3, 5], we can draw out the time required in the queue-based scenario given in the question. \n\n\n\n![image.png](https://assets.leetcode.com/users/images/aa2b5987-7f20-429d-b897-dcd2f5c44085_1712638900.9264324.png)\nThe number of seconds required can be found by counting in the above figure - 4 + 4 + 1 + 0 + 1 till it takes  the 2nd index to have collected the 3 tickets. The rest of the hourglasses are not used.\n\nSo we can see the pattern - on the left, if greater number of tickets, it will only go till our tickets[k] at max, and if it\'s a lower number everything will be used. So we can get additional time of min(entry, target).\n\nOn the right, we will have the same calculation, just till one row less. You can understand from the code given below.\n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(1)\n\n# Code\n```\nclass Solution:\n    def timeRequiredToBuy(self, tickets: List[int], k: int) -> int:\n        res = 0\n        target = tickets[k]\n        for person, entry in enumerate(tickets):\n            if person <= k:\n                res += min(entry, target)\n            else:\n                if target <= entry:\n                    res += min(entry, target) - 1\n                else:\n                    res += min(entry, target)\n        \n        return res\n```\n\nIf the solution helped you understand better please upvote :)\n
['Array', 'Queue', 'Python3']