Leetcode 2195 Solution

This article provides solution to leetcode question 2195 (time-needed-to-buy-tickets)

https://leetcode.com/problems/time-needed-to-buy-tickets

Solution

class Solution:
    def timeRequiredToBuy(self, tickets: List[int], k: int) -> int:
        ans = 0

        for i, ticket in enumerate(tickets):
            if i <= k:
                ans += min(tickets[k], ticket)
            else:
                ans += min(tickets[k] - 1, ticket)

        return ans