Parcel Weight Lanes
Medium · two pointers
A sorting depot sends parcels down three lanes according to weight. The list weights holds the weight of every parcel in the order they arrived.
- A parcel lighter than
logoes in the light lane. - A parcel heavier than
higoes in the heavy lane. - Every other parcel (weight from
lotohi, both included) goes in the standard lane.
The trucks are loaded with the light lane first, then the standard lane, then the heavy lane. Inside each lane the parcels must stay in the order they arrived.
Return the list of weights in loading order.
Examples
Example 1
Input: weights = [12, 3, 25, 8, 14, 40, 9, 20], lo = 8, hi = 20
Output: [3, 12, 8, 14, 9, 20, 25, 40]
Light (below 8): 3. Standard (8 to 20): 12, 8, 14, 9, 20. Heavy (above 20): 25, 40. Each lane keeps its arrival order.
Example 2
Input: weights = [5, 5, 5], lo = 1, hi = 10
Output: [5, 5, 5]
Every parcel is standard, so nothing moves.
Example 3
Input: weights = [50, 1, 50, 1], lo = 2, hi = 3
Output: [1, 1, 50, 50]
No parcel is standard. The two light ones go first, then the two heavy ones.
Constraints
- 1 <= len(weights) <= 3000
- 1 <= weights[i] <= 10^9
- 1 <= lo <= hi <= 10^9