Skip to content
RED SAGSkills
easy15 ptsgreedy

Load Parcels Onto Vans

A depot has parcels with weights parcels[i] and vans with load limits vans[j]. Each van can carry at most one parcel, and a parcel fits in a van only when its weight is at most the van's limit.

Return the largest number of parcels that can be shipped at once.

Example 1

Input: parcels = [1,2,3], vans = [1,1]
Output: 1
Explanation: Only one van is available for parcels of weight 1 or less.

Example 2

Input: parcels = [1,2], vans = [1,2,3]
Output: 2
Explanation: Both parcels fit.

Constraints

  • 0 <= parcels.length, vans.length <= 2 * 10^4
  • 1 <= parcels[i], vans[j] <= 10^5
Hint 1

Sort both lists.

Hint 2

Give each van, smallest first, to the lightest parcel that is still waiting, if it fits.

Good practice for: Backend Developer, Full Stack Developer, Data Engineer, Cloud Engineer, Mobile App Developer

Run checks your code on 3 sample tests. Submit runs all 8 tests, including hidden ones, and earns points. Use console.log to debug. Python's first run can take a few seconds while it starts.