Back to problems

Optimize least-k revenue queries for read/write load

System Design · Databricks · Hard

You can model this as maintaining a mutable map from customer to total revenue, plus an optional ordered index to answer “smallest $$k$$ totals” efficiently. Assume revenue is stored as integer cents or fixed-point numbers to avoid floating point errors, and ties are broken by customer ID. 1. Maintaining customer revenue totals Nested input: orders → line items The nesting is flattened during aggregation. After this pass, each unique customer has one total revenue value. If…

Checking your access…