Spend it All

From Tiktok interviews, this coding interview problem gives a budget and a circular array of costs. Starting at index 0, repeatedly traverse 0..n-1, buy items when their cost is ≤ budget, skip otherwise, and subtract the cost from the budget. Stop when the budget is below the smallest cost. Return the total number of purchases. A concise interview question for careful iteration.

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Input Variables
Execution Result: