there n people line queuing buy ticket 0th person line n 1th person lineYou give 0indexed integer array ticket length n number ticket ith person like buy ticketsieach person take exactly 1 second buy ticket a person buy 1 ticket time end line happen instantaneously order buy ticket if person ticket leave buy person leave lineReturn time take person position k 0indexed finish buy ticket example 1input ticket 232 k 2output 6explanation in pass line buy ticket line 1 2 1 in second pass line buy ticket line 0 1 0the person position 2 successfully buy 2 ticket take 3 3 6 secondsexample 2input ticket 5111 k 0output 8explanation in pass line buy ticket line 4 0 0 0 in 4 pass person position 0 buying ticketsthe person position 0 successfully buy 5 ticket take 4 1 1 1 1 8 second Constraintsn ticketslength1 n 1001 ticketsi 1000 k n