Compute prices, distances, and Top-K for orders
Company: Coinbase
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: Medium
Interview Round: Onsite
Build functions for a food‑delivery analytics module.
Data:
- Restaurants: id, (x, y) location, menu mapping item -> price.
- Orders: id, restaurantId, timestamp (Unix ms), line items: (item, quantity).
Tasks:
(a) Given the user's (x, y) and a target item, return the restaurant
(s) offering the lowest price for that item and, among ties, the nearest by Euclidean distance (return id and distance).
(b) For a time window [start, end), compute total revenue, order count, and average order value.
(c) For a time window [start, end), return Top K orders by total price (id, total) and Top K items by quantity sold (item, quantity). Specify tie‑breaking rules, chosen data structures, and complexity.
Quick Answer: This question evaluates algorithmic problem solving and data-structure design for spatial queries, price lookup, time-windowed revenue aggregation, and Top-K computation, including reasoning about tie-breaking and computational complexity.