Prime Batch Warehouse Capacity
Amazon 🧠 Hard SQL
Beginner Mode

Objective

Write a SQL query to determine the maximum number of prime and non-prime batches that can be stored in a 500,000 square-foot warehouse. Prime batches must be fully stocked first, and any remaining space should be used for non-prime batches.

Table Schema:

  • inventory
Column Type Description
item_id INTEGER Unique identifier for the item
item_type VARCHAR Type of item ('prime_eligible' or 'not_prime')
square_footage INTEGER Space required per batch of this item
item_count INTEGER Number of batches available for this item

Task Requirements:

  • Calculate the total number of prime batches and their total square footage
  • All prime batches are stocked first (assume they fit within the warehouse)
  • Use the remaining space to calculate the maximum number of non-prime batches that can be stored
  • Output prime results before non-prime results

Output columns: item_type, max_batch_count

Examples

Example 1:

Input:

inventory
item_countitem_iditem_typesquare_footage
2001prime_eligible500
1502prime_eligible500
3003not_prime700
2504not_prime700

Output:
item_typemax_batch_count
prime_eligible350
not_prime464
Quick Solution

Code Environment

Sign in or try as guest to run your code.

Sign In

Track

Question Difficulty Company Access
Need more practice in this area? Explore more questions →