Last updated
Find the list of packages each vehicle can carry without exceeding its fixed capacity.
Find the list of packages each vehicle can carry without exceeding its fixed capacity.
Your dataset contains two logistics tables: 1. A Vehicle table with the vehicle ID and maximum carrying capacity 2. A Packages table with each package ID, package weight, and the vehicle assigned to carry it Analyze whether assigned packages can be loaded into each vehicle without crossing the vehicle's capacity.
| Column | Type | Key / Notes |
|---|---|---|
| ID | INT | PK |
| Capacity | INT |
| Column | Type | Key / Notes |
|---|---|---|
| ID | INT | PK |
| Weight | INT | |
| vehicle_ID | INT | FK |
Vehicle — 4 rows
| ID | Capacity |
|---|---|
| 1 | 550 |
| 2 | 650 |
| 3 | 500 |
| 4 | 600 |
Packages — 30 rows
| ID | Weight | vehicle_ID |
|---|---|---|
| 1 | 55 | 1 |
| 2 | 60 | 1 |
| 3 | 65 | 2 |
| 4 | 70 | 2 |
| 5 | 75 | 3 |
| 6 | 80 | 3 |
| 7 | 85 | 4 |
| 8 | 90 | 4 |
| 9 | 95 | 1 |
| 10 | 100 | 2 |
| 11 | 52 | 3 |
| 12 | 57 | 4 |
| 13 | 62 | 1 |
| 14 | 67 | 2 |
| 15 | 72 | 3 |
| 16 | 77 | 4 |
| 17 | 82 | 1 |
| 18 | 87 | 2 |
| 19 | 92 | 3 |
| 20 | 97 | 4 |
| 21 | 54 | 1 |
| 22 | 59 | 2 |
| 23 | 64 | 3 |
| 24 | 69 | 4 |
| 25 | 74 | 1 |
| 26 | 79 | 2 |
| 27 | 84 | 3 |
| 28 | 89 | 4 |
| 29 | 94 | 1 |
| 30 | 99 | 2 |
Vehicle Capacity Allocation: What is the comma-separated list of packages each vehicle can carry without exceeding its capacity? The packages should be selected in ascending order of their weight. The final result table should have vehicle_id and packages columns.
Your output should look like this (partial example):
| vehicle_id | packages |
|---|---|
| 1 | 21,1,2,13,25,17,29 |
| 2 | 22,3,14,4,26,18,30 |
| 3 | 11,23,15,5,6,27 |