Trade Desk | SDE Internship OA 2024

Problem Description:

Imagine an exclusive event where attendees arrive at different times. The event starts at time 0. Each attendee undergoes an identification check that takes 5 minutes. If a person arrives and sees more than 10 people in the ID check queue, they leave immediately.

Your task is to implement a function that returns an array of integers representing the time when each person's identification check will be completed. The time should be in seconds since the start of the event.

Function Signature: public static int[] processEvent(int[] arrivalTimes)

Input:

  • arrivalTimes: An array of integers representing the arrival time of each person.

Output:

  • An array of integers representing the time when each person's identification check will be completed.

Rules:

  • The queue size is calculated by the number of people waiting to start their ID check, not already in the process of an ID check.
  • If a new person arrives at the same moment as when another person completes their ID check, the first person waiting in the queue should have their ID checked first, and the new person should wait in the queue.

Example:

public static void main(String[] args) {
    int[] arrivalTimes = {4, 400, 450, 500};
    int[] result = processEvent(arrivalTimes);

    // Expected Output: [304, 700, 1000, 1300]
    System.out.println(Arrays.toString(result));
}

Explanation:

Consider the scenario:

  • The first person arrives at time 4 and starts their ID check immediately. Queue: []
  • The second person arrives at time 400, and their ID check starts at time 304 (after the first person's ID check completes). Queue: []
  • The third person arrives at time 450, and their ID check starts at time 700 (after the second person's ID check completes). Queue: []
  • The fourth person arrives at time 500, and their ID check starts at time 1000 (after the third person's ID check completes). Queue: []

The output array represents the time when each person's identification check will be completed.

Please Note : If the size is already 10 , the processing time of the next person will be same as their arrival time.

Comments (2)