Get Trucks for Items 🥥
Learn this problemProblem statement
Amazon Warehouse delivers different items in different trucks having varied capacities.
Given an array, trucks, of n integers that represents the capacities of different trucks,
and an array, items, of m integers that represent the weights of different items, for each
item, find the index of the smallest truck which has a capacity greater than the item's weight. If there are
multiple such trucks, choose the one with the minimum index.
If there is no truck that can carry the item, report -1 as the answer for the corresponding item.
Note: Assume that the trucks are indexed starting from 0. Also, multiple items can be mapped to the same truck. Each item is mapped independently, hence the trucks do not lose any capacity when a particular item is mapped to it.
Function
getTrucksForItems(trucks: int[], items: int[]) → int[]
Complete the function getTrucksForItems in the editor below.
getTrucksForItems has the following parameters:
int trucks[n]: the capacities of the trucksint items[m]: the weights of the items
Examples
Example 1
trucks = [4, 5, 7, 2]items = [1, 2, 5]return = [3, 0, 2]
Example 2
trucks = [5, 3, 8, 1]items = [6, 10]return = [2, -1]Example 3
trucks = [1, 3, 5, 2, 3, 2]items = [1, 2, 3]return = [3, 1, 2]Constraints
More Amazon problems
- Secure Maximum DeliveriesOA · Seen Jul 2026
- Find Median from Data StreamONSITE INTERVIEW · Seen Jul 2026
- Handwritten SigmoidPHONE SCREEN · Seen Jul 2026
- Handwritten SoftmaxPHONE SCREEN · Seen Jul 2026
- Koko Eating BananasONSITE INTERVIEW · Seen Jul 2026
- Loyal Customers Across Two DaysONSITE INTERVIEW · Seen Jul 2026
- Maximum System Memory CapacityOA · Seen Jul 2026
- Package Delivery SystemOA · Seen Jul 2026