[Python] | BruteForce and O(N)
Please upvote if you find it helpful\n\nBruteForce:\n\nclass Solution:\n    def timeRequiredToBuy(self, tickets: list[int], k: int) -> int:\n        secs = 0 \n
Please upvote if you find it helpful\n\nBruteForce:\n```\nclass Solution:\n    def timeRequiredToBuy(self, tickets: list[int], k: int) -> int:\n        secs = 0 \n        i = 0\n        while tickets[k] != 0:\n            if tickets[i] != 0: # if it is zero that means we dont have to count it anymore\n                tickets[i] -= 1 # decrease the value by 1 everytime\n                secs += 1 # increase secs by 1\n\n            i = (i + 1) % len(tickets) # since after getting to the end of the array we have to return to the first value so we use the mod operator\n            \n        return secs\n```\n\nO(N):\n```\nclass Solution:\n    def timeRequiredToBuy(self, tickets: List[int], k: int) -> int:\n        return sum(min(x, tickets[k] if i <= k else tickets[k] - 1) for i, x in enumerate(tickets))\n```\nThe values before tickets[k] will appear min(x, t[x]) times and values after tickets[k] will appear min(x, t[x] -1) times\nLet\'s take an example:\n`tickets = [5, 2, 3, 4]` and `k = 2`\n```1st iteration: [4, 1, 2, 3]```\n```2nd iteration: [3, 0, 1, 2]```\n```3rd iteration: [2, 0, 0, 1]```\nYou see `tickets[0]` appeared 3 times which is min(5, 3) and that is 3, \n             `tickets[1]` appeared 2 times which is min(2, 3) that is 2, \n\t\t\t `tickets[2]` appeared 3 times which is min(3, 3) that is 3 and \n\t\t\t `tickets[3]` appeared 2 times which is min(4, 2) that is 2.\n
['Python', 'Python3']