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.