2073. Time Needed to Buy Tickets
Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 71% Topics: Array, Queue, Simulation
View full problem on LeetCode Reading material
Reference solution (spoiler · python)
# Time: O(n)
# Space: O(1)
class Solution(object):
def timeRequiredToBuy(self, tickets, k):
"""
:type tickets: List[int]
:type k: int
:rtype: int
"""
return sum(min(x, tickets[k] if i <= k else tickets[k]-1) for i, x in enumerate(tickets))
Solution from kamyu104/LeetCode-Solutions · MIT
Similar questions