Peak Participants Finder

Algorithm Simulation Sorting

You are given a list of events representing join and leave actions in an online meeting. Each event is represented as an object with two properties:

  • timestamp: an integer representing the time of the event
  • type: a string that is either 'join' or 'leave'

Assume that:

  • Every participant's join event occurs before their corresponding leave event.
  • Multiple events can occur at the same timestamp. In the case of ties at a particular timestamp, process all join events before leave events.

Your task is to write a function that processes this list of events and returns two pieces of information:

  1. The maximum number of participants present simultaneously during the meeting.
  2. The earliest timestamp at which this maximum number occurred.

Example Input:

[
  { "timestamp": 5, "type": "join" },
  { "timestamp": 10, "type": "join" },
  { "timestamp": 15, "type": "leave" },
  { "timestamp": 10, "type": "join" },
  { "timestamp": 20, "type": "leave" },
  { "timestamp": 25, "type": "leave" }
]

Requirements:

  • The function should correctly handle events that have the same timestamp.
  • The input list of events may not be provided in sorted order.
  • Return or output the results in a clear format (e.g., as a tuple, an array, or an object) as appropriate for your chosen programming language.

Design your solution considering the efficiency of your approach.


Loading...