Object-Oriented Programming · C3.ai · Medium
You receive a continuous stream of tuples, each of the form (company, shares). Build a data structure that supports two operations: insert(company, shares): record a tuple from the stream. When a company shows up more than once, its share amounts add up, so the company's total is the sum of every share value inserted for it. getTopK(k): return the k companies currently holding the largest total number of shares. The value of k can differ from one call to the next. Make…