stock_items lists warehouse items (item_id, cost). With a fixed budget of 40, find the maximum number of items that can be bought without the total cost exceeding the budget. Buy cheapest first; when costs tie, the lower item_id is taken first. Output one row with columns: budget (always 40), max_items, selected_item_ids (the chosen item_ids sorted ascending and joined with '|', e.g. '2|5|7').
| Column | Type |
|---|---|
| item_id | INTEGER |
| cost | INTEGER |
| item_id | cost |
|---|---|
| 1 | 10 |
| 2 | 20 |
| 3 | 15 |
| 4 | 5 |
| 5 | 30 |
| budget | max_items | selected_item_ids |
|---|---|---|
| 40 | 3 | 1|3|4 |
Solve it in the live editor on this page — run on sample data, then submit against hidden tests.
‹ Annual Category Sales Growth · Weighted Search Volume Median ›
{{ totalCount }} questions in the style asked at Amazon, Microsoft, Google, Meta, Flipkart and more — {{ hardPct }}% Hard. Write SQL in a real database engine in your browser, run it on sample data, then evaluate against hidden tests.
Company tags show where this type of question is commonly reported in interviews. Questions, data and solutions are written by TechTown.
{{ cur.statement }}
No submissions yet. Press Evaluate to submit your query.
{{ solutionSql }}
{{ out.error }}
You have solved your 3 free questions — nice work! Log in (free) to unlock all 150 questions, keep your streak and appear on the leaderboard.