All problems

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.

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