← DiffPush

Minimum Platforms

Standard Bar Greedy Approach · Medium O(n log n) · O(1)

The Loading Dock Scheduling Audit

A distribution hub logs delivery truck arrivals and departures on one operating day, all times in 24-hour codes. A dock frees up only strictly after a truck pulls out — a truck arriving at the exact moment another departs needs its own dock. The yard master wants the smallest dock count that keeps every truck moving without waiting.

Input: Two integer arrays: arr (arrival times) and dep (departure times), as HHMM codes.

Output: Return the minimum number of docks (platforms) required.

Constraints

Examples

Example 1

Input: {"arr":[900,940,950,1100,1500,1800],"dep":[910,1200,1120,1130,1900,2000]}
Output: 3
Around 1100, three trucks are simultaneously on-site (950, 1100 arrivals against the 1200 departure).

Example 2

Input: {"arr":[900,1100,1235],"dep":[1000,1200,1240]}
Output: 1
Each truck departs before the next arrives, so one dock cycles through all three.

Solve this in your browser →

Also on LeetCode ↗