Spend it ALL: given a budget and circular array of costs, repeatedly buy items in order when affordable until budget < min cost; return number of purchases (n up to 2e5, budget up to 1e15)
Asked in the OA stage.
Implement count_purchases(costs, budget). The positive-cost array is traversed from index 0 in circular order. During each traversal, buy an item if its cost is at most the remaining budget. Return the total number of purchases.
costs is a list of positive integers, and budget is a nonnegative integer. Return an integer purchase count.
def count_purchases(costs, budget):