Build a Pivot Table Aggregator
SigmacomputingSoftware Engineer · Technical ScreenLast updated
This question evaluates a candidate's ability to implement data aggregation and efficient lookup structures, focusing on grouping, associative aggregations, and maintaining intermediate state for derived metrics.
Implement a function that builds a pivot table from a list of records. Each record contains a row_key, a column_key, and a numeric value.
Requirements:
- In the basic version, aggregate records by
(row_key, column_key)and compute thesumfor each group. - Return the result in a structure that allows efficient lookup by row key and column key.
- As a follow-up, explain how you would extend the implementation to support other aggregation functions such as
averageandminimum.
Example input:
[
("A", "X", 10),
("A", "X", 20),
("A", "Y", 5),
("B", "X", 7)
]
Expected result for sum:
A / X -> 30A / Y -> 5B / X -> 7
In your explanation, describe what intermediate state must be maintained so that average and minimum can also be computed correctly.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.