Second most expensive product per category
Lazada wants the runner-up priced item in each category.
For each category in products, return the category and the second highest price in that category as second_highest. Assume no two products in a category share the same price.
Schema
| id | INT |
| category | TEXT |
| price | NUMERIC(10,2) |
Example input
Stuck? Ask the coach for a nudge that won't give the answer away, or reveal the reference solution and a short walkthrough of why it works.
The interviewer's next question
Good. Now do the same for the THIRD highest price per category, as third_highest — categories with fewer than three products should simply not appear.
Solving follow-ups — the questions an interviewer actually asks next — unlocks with a Basic plan.
See Basic plansRM 25/mo · cancel anytime
One more: for each category, how much cheaper is the second-highest priced item than the highest, as price_gap?
Solving follow-ups — the questions an interviewer actually asks next — unlocks with a Basic plan.
See Basic plansRM 25/mo · cancel anytime