Top Category by Revenue
You're a data analyst at Whetcode Supply, an online shop selling desk gear. Next quarter's buying budget is split into price tiers, and each tier is argued out on its own: among products priced at or below that tier's ceiling, which category brought in the most money? The founder has been clear about the rule: it is decided on money, not on how many boxes left the warehouse. A category can shift piles of cheap notebooks and still earn less than a category that sold six desks. The ceiling under discussion comes with the request.
The order system was built to stay small. An order records which product went out and how many, and nothing about what it cost — money, categories and the unit price that decides which tier a product falls in all live in the catalogue instead.
products_df — the catalogue. price is the cost of a single unit; category is how the buying team groups the range.
| id | name | category | price |
|---|---|---|---|
| 1 | Wireless Mouse | electronics | 25.0 |
| 2 | Standing Desk | furniture | 350.0 |
| 3 | Desk Lamp | furniture | 40.0 |
| 4 | Mechanical Keyboard | electronics | 85.0 |
| 5 | Notebook Set | office | 12.0 |
orders_df — one row per order. quantity is how many units of that product_id were bought.
| id | customer_id | product_id | quantity | order_date |
|---|---|---|---|---|
| 1 | 1 | 1 | 2 | 2023-02-01 |
| 2 | 1 | 4 | 1 | 2023-02-01 |
| 3 | 2 | 2 | 1 | 2023-02-10 |
| 4 | 3 | 3 | 3 | 2023-03-05 |
| 5 | 4 | 5 | 5 | 2023-03-11 |
| 6 | 1 | 3 | 1 | 2023-04-02 |
| 7 | 5 | 1 | 4 | 2023-05-20 |
| 8 | 2 | 5 | 2 | 2023-05-22 |
| 9 | 3 | 4 | 1 | 2023-06-01 |
| 10 | 5 | 2 | 1 | 2023-06-15 |
Input
Both DataFrames above are already built for you — the catalogue and order rows are not read from input. What does arrive is a single line holding the tier's ceiling, a price in dollars.
Task: Print the name of the single category that brought in the most money across all orders for products priced at or below that ceiling, as a bare string — no quotes, no brackets, no surrounding list. A product priced exactly on the ceiling belongs to the tier. If two categories were tied, print whichever comes first alphabetically.
Example: if kitchenware had out-earned every other category in the tier, you'd print kitchenware.
Sign in to solve this problem
Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.
Sign in