Zomato: Suggest a new dish price between the 1/3 and 2/3 points of past prices
Problem. You get the prices of a merchant's existing dishes. Suggest a price for a new dish that is higher than the value at the one-third position of the price distribution and lower than the value at the two-thirds position.
Example. If past prices run from 10 to 60, the suggested price should fall between 20 and 30.
Discussion.
- First approach: sort the prices and read off the values at the two cut points. This runs in O(n log n).
- Follow-up: track the two cut points with a pair of heaps (a min-heap and a max-heap) instead of fully sorting, and suggest a value between their tops. The candidate wrote pseudo-code for this version.
Context. It came at the end of a round dominated by a project deep dive and an LLD task modelling a configurable restaurant menu (sizes, crusts, toppings). The candidate stressed that heaps and sorting fundamentals mattered in this loop. No input size limits were given.
Comments 0
No comments yet. Ask the author something, or add what happened in your own round.