Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Loop through the line of people and decrement the number of tickets for each to buy one at a time as if simulating the line moving forward. Keep track of how many tickets have been sold up until person k has no more tickets to buy.
Remember that those who have no more tickets to buy will leave the line.