Problem Brief

Event Time

INTERNOA

Feel free to checkout the image source at the bottom of the page for the original problem statement 🦜

Imagine an exclusive event that everyone is eager to attend. The doors open at time 0, and people begin to arrive, each with their own special time of arrival, counted in seconds since the start of the event. But there’s a little twist — before anyone can step inside, they must go through a thorough ID check. This check takes exactly 5 minutes (or 300 seconds) per person. Now, here’s where things get tricky: if a person arrives and sees that there are already more than 10 people waiting in line for the ID check, they decide to leave immediately. They simply cannot bear the wait and head home without ever getting their ID checked. Your task is to determine the time each person will finish their ID check, starting from the time they arrived at the event. If someone leaves upon arrival because the queue is too long, their “processed” time will be the same as their arrival time — no ID check for them! Here are a few more things to keep in mind: The queue size is determined by how many people are waiting to begin their ID check. The person currently getting checked doesn’t count toward the queue. If multiple people arrive at exactly the same moment and the queue grows, the person who has fewer people ahead of them will be processed first, while the others will patiently wait their turn. Your goal is to return an array of integers where each number represents the exact moment in seconds when a person finishes their ID check — or if they left immediately, it’s simply their arrival time. Now, go ahead and figure out who gets into this exclusive event and when their ID checks are complete!

1Example 1

Input
times = [4, 400, 450, 500]
Output
[304, 700, 1000, 1300]
Explanation
Feel free to checkout the iamge source below for the original explanation :) In a bustling office, a series of events unfolded as people lined up for their ID checks: At the stroke of 4, the first visitor arrived. Since the office was empty, they were immediately ushered in for their ID check. The queue was a quiet, empty space. By 304, the first visitor had completed their ID check and left, leaving the queue just as serene as before. As the clock struck 400, the second visitor walked in. With no one in sight, they too started their ID check right away. The queue remained empty. When the third visitor arrived at 450, the office was still busy with the second visitor inside. So, they patiently took their place in the queue, now marked by a single name. Shortly after, at 500, the fourth visitor arrived. Noting the presence of one person already waiting, they joined the queue, which now held two names. At 700, the second visitor's ID check was completed, freeing up the office for the third visitor to step up. The queue now had just one name waiting. The clock struck 1000, and with the third visitor's check finished, the fourth visitor began theirs. The queue was now empty, with only the hum of activity left. By 1300, the fourth and final visitor finished their ID check, bringing an end to the day’s lineup of visitors.

2Example 2

Input
times = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
Output
[301, 601, 901, 1201, 1501, 1801, 2101, 2401, 2701, 3001, 3301, 3601, 13, 14, 15]
Explanation
Feel free to checkout the iamge source below for the original explanation 🐟 Once upon a time at a grand event, the first guest arrived at the stroke of 1 o’clock and began their ID check right away. Soon after, a wave of 11 more guests arrived, each one joining the queue behind the first guest. The queue grew longer with each new arrival, as they patiently waited their turn. However, as the queue stretched beyond 10 people, the last three guests took one look at the growing line and decided to leave. They felt overwhelmed by the number of people waiting and chose to forgo their ID checks, disappearing into the crowd instead. And so, the event continued with the queue still bustling with anticipation.

Constraints

Limits and guarantees your solution can rely on.

Unknown for now
public int[] processAttendees(int[] times) {
  // write your code here
}
Input

times

[4, 400, 450, 500]

Output

[304, 700, 1000, 1300]

Sign in to submit your solution.