You are given a table Inventory with the following structure:
item_id(int): Unique identifier for each itemitem_type(varchar): Type of item ('prime_eligible' or 'not_prime')item_category(varchar): Category of the itemsquare_footage(decimal): Square footage required for the item
Leetcode warehouse has 500,000 square feet of storage space and wants to maximize the number of items it can stock. The strategy is:
- First, stock as many prime_eligible items as possible
- Then, use the remaining space to stock the maximum number of not_prime items
Write a SQL query to find the number of prime and non-prime items that can be stored. Output the item_type with prime_eligible followed by not_prime and the maximum number of items that can be stocked.
Note: Item count must be a whole number (integer). If the count for the not_prime category is 0, output 0. Return results ordered by item count in descending order.
Table Schema
| Column Name | Type | Description |
|---|---|---|
item_id
PK
|
int | Unique identifier for each item |
item_type
|
varchar | Type of item ('prime_eligible' or 'not_prime') |
item_category
|
varchar | Category of the item |
square_footage
|
decimal | Square footage required for the item |
Input & Output
| item_id | item_type | item_category | square_footage |
|---|---|---|---|
| 1 | prime_eligible | books | 1000 |
| 2 | prime_eligible | electronics | 1000 |
| 3 | not_prime | sports | 2000 |
| 4 | not_prime | home | 3000 |
| item_type | item_count |
|---|---|
| prime_eligible | 500 |
| not_prime | 0 |
Prime items average 1000 sqft each, so we can fit 500,000/1000 = 500 prime items. This uses all available space (500 × 1000 = 500,000), leaving 0 space for non-prime items.
| item_id | item_type | item_category | square_footage |
|---|---|---|---|
| 1 | prime_eligible | books | 2000 |
| 2 | prime_eligible | electronics | 2000 |
| 3 | not_prime | sports | 1000 |
| 4 | not_prime | home | 1000 |
| item_type | item_count |
|---|---|
| not_prime | 250 |
| prime_eligible | 2 |
Prime items average 2000 sqft each, so we can fit 2 prime items (limited by available count). This uses 4000 sqft, leaving 496,000 sqft. Non-prime items average 1000 sqft each, so we can fit 496 non-prime items, but limited to available count of 2, so result is ordered by count.
| item_id | item_type | item_category | square_footage |
|---|---|---|---|
| 1 | not_prime | sports | 1500 |
| 2 | not_prime | home | 2500 |
| item_type | item_count |
|---|---|
| not_prime | 2 |
| prime_eligible | 0 |
No prime items available, so all 500,000 sqft goes to non-prime items. Non-prime items average 2000 sqft each, allowing 250 items, but only 2 items are available. Prime eligible shows 0 count.
Constraints
-
1 ≤ item_id ≤ 10^6 -
item_typeis either'prime_eligible'or'not_prime' -
1.00 ≤ square_footage ≤ 100000.00 -
Total warehouse space is
500,000square feet