Second most expensive product per category
Lazada wants the runner-up price point in each category.
For each category in products, return one row with the second-highest distinct price as second_highest. Products may tie on price; a category with fewer than two distinct prices should not appear.
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