FastPrepGet Biggest Lions

Get Biggest Lions

Optiver logoOptiver● MediumINTERNOA
Learn

Problem statement

As a lion trainer, you are taking part in an international lion exhibition. Lions from your team and competing teams enter and leave the showroom according to a schedule. You know the schedule for your lions, and during the show you observe every lion entering and leaving.

At an inspection, return your lions currently in the room whose height is at least the height of the largest competing lion currently in the room. Return qualifying names in alphabetical order. If no competing lion is in the room, every one of your lions currently in the room qualifies.

Original class behavior

  • The constructor receives descriptions of your lions and their private schedule.
  • LionEntered(currentTime, height) records one observed entry.
  • LionLeft(currentTime, height) records one observed exit.
  • getBiggestLions() returns the qualifying names for the current room state.

Your schedule is followed exactly, so an event whose time and height match a pending scheduled entry or exit identifies one of your lions. Other events belong to competitors. When several events have the same timestamp, an inspection occurs either before all of them or after all of them, never between them.

FastPrep Runner Adapter

Implement LionCompetition(String[][] lions, String[][] schedule, String[] operations).

  • Each row of lions is [name, height].
  • Each row of schedule is [name, enterTime, exitTime].
  • ENTER currentTime height calls LionEntered.
  • EXIT currentTime height calls LionLeft.
  • INSPECT currentTime calls getBiggestLions.

Return one string-array row for every INSPECT command, in operation order.

Function

LionCompetition(lions: String[][], schedule: String[][], operations: String[]) → String[][]

Examples

Example 1

lions = [["marry","300"],["rob","250"]]schedule = [["marry","10","15"],["rob","13","20"]]operations = ["ENTER 8 200","ENTER 10 310","ENTER 10 300","INSPECT 11","ENTER 13 250","EXIT 13 310","INSPECT 13","EXIT 15 300","INSPECT 16","EXIT 16 200","EXIT 20 250"]return = [[],["marry","rob"],["rob"]]

At time 11, the competing lion of height 310 is taller than both of our lions in the room, so the first row is empty. At time 13, that competitor has left and the remaining competing maximum is 200, so both marry and rob qualify. At time 16, marry has left and rob still qualifies against the competing lion of height 200.

Constraints

  • Subsequent invocations of LionLeft and LionEntered methods are always called in order, according to the currentTime parameter.
  • The schedule is strictly followed - your lions enter and exit the room exactly at their specified times.
  • The lion inspection (invocation of the getBiggestLions method) takes place either before or after all lions scheduled to enter or leave the room at a given minute did that - never in between.
  • Lion names are unique.
  • Times (currentTime, enterTime and exitTime) are always whole numbers (and multiple events can occur at the same time).
  • A single lion enters the room only once during the show.

More Optiver problems

See Optiver hiring insights
public String[][] LionCompetition(String[][] lions, String[][] schedule, String[] operations) {
  // write your code here
}
lions[["marry","300"],["rob","250"]]
schedule[["marry","10","15"],["rob","13","20"]]
operations["ENTER 8 200","ENTER 10 310","ENTER 10 300","INSPECT 11","ENTER 13 250","EXIT 13 310","INSPECT 13","EXIT 15 300","INSPECT 16","EXIT 16 200","EXIT 20 250"]
expected[[], ["marry", "rob"], ["rob"]]
Checking account…