Problemlimit order exchange simulator

Session: Sign in to solve

Solution.txt

Relief Courier Queue

Problem

A relief organization hires local couriers for individual deliveries. Design ReliefCourierQueue to record each available courier's quoted fee and dispatch the lowest-cost available courier.

Requirements

  • Empty start. Construction starts with no available couriers.
  • Post courier. postCourier adds the courier ID and fee to the available couriers.
  • Fee-priority dispatch. dispatch removes and returns the available courier whose fee is smallest.
  • Availability lookup. isAvailable returns whether the courier ID is present.

API

SignatureReturnsBehavior
ReliefCourierQueue()Not applicableCreates an empty queue.
postCourier(courierId: string, fee: integer)voidAdds the courier and its fee.
dispatch()stringRemoves and returns the lowest-fee available courier.
isAvailable(courierId: string)booleanReports current availability.

Examples

StepOperationResult
1ReliefCourierQueue()Queue created
2postCourier("RIDGE", 70)No return value
3postCourier("VALLEY", 20)No return value
4dispatch()"VALLEY"
5isAvailable("VALLEY")false
6isAvailable("RIDGE")true

Constraints

  • At most 12 couriers are posted and at most 30 public method calls occur.
  • Courier IDs match [A-Za-z0-9_-]{1,24}.
  • 1 <= fee <= 1000.
  • Courier IDs and fees are unique.
  • dispatch is called only when at least one courier is available.
  • Arguments are not null.

Notes

Calls are sequential.

PRIVATE WORKSPACE

Checking your session…

The statement is public. The editor, editorial, submissions, and saved work are private.