7 kyu

Queue time counter

555 of 1,716GiacomoSorbi

Description:

You managed to send your friend to queue for tickets in your stead, but there is a catch: he will get there only if you tell him how much that is going to take. And everybody can only take one ticket at a time, then they go back in the last position of the queue if they need more (or go home if they are fine).

Each ticket takes one minutes to emit, the queue is well disciplined, Brit-style, and so it moves smoothly, with no waste of time.

You will be given an array/list/vector with all the people queuing and the initial position of your buddy, so for example, knowing that your friend is in the third position (that we will consider equal to the index, 2 (3 in COBOL): he is the guy that wants 3 tickets!) and the initial queue is [2, 5, 3, 4, 6].

The first dude gets his ticket and the queue goes now like this [5, 3, 4, 6, 1], then [3, 4, 6, 1, 4] and so on. In the end, our buddy will be queuing for 12 minutes, true story!

Build a function to compute it, resting assured that only positive integers are going to be there and you will be always given a valid index; but we also want to go to pretty popular events, so be ready for big queues with people getting plenty of tickets.

Queues
Lists
Algorithms

Stats:

CreatedJul 21, 2018
PublishedJul 21, 2018
Warriors Trained4891
Total Skips78
Total Code Submissions7114
Total Times Completed1716
JavaScript Completions555
Ruby Completions63
Python Completions711
Crystal Completions10
C++ Completions230
Haskell Completions37
C# Completions115
C Completions73
COBOL Completions7
Java Completions32
Total Stars85
% of votes with a positive feedback rating91% of 332
Total "Very Satisfied" Votes287
Total "Somewhat Satisfied" Votes30
Total "Not Satisfied" Votes15
Total Rank Assessments4
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • GiacomoSorbi Avatar
  • adrian.eyre Avatar
  • Madjosz Avatar
  • KataSideKick Avatar
  • hobovsky Avatar
  • cliffstamp Avatar
  • trashy_incel Avatar
  • user8436785 Avatar
  • akar-0 Avatar
  • Just4FunCoder Avatar
  • LosBlobbos Avatar
  • saudiGuy Avatar
Ad