We express the initial line of n people as an array, tickets = [ticket(0),ticket(1),...,ticket(n-1)] where each tickers, denotes the number of tickets that person i wishes to buy. If Jesse is located at postion p. How many seconds will it take for him to purchase the tickets.
For example if tickets = [1,2,5] and p=1 the first five
Following rules should apply:
1.The person at the head of the line can by exactly one ticket and must exit the line
2.If a person needs to purchase additional tickets, they must re-enter the end of the line in wait to be sold the next ticket (assume exit and re-entry takes 0 seconds)
3.Each ticket sale dates exactly one second.
Find the time taken