Katkat

Build a Pivot Table Aggregator

SigmacomputingSoftware Engineer · Technical Screen

Last 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:

  1. In the basic version, aggregate records by (row_key, column_key) and compute the sum for each group.
  2. Return the result in a structure that allows efficient lookup by row key and column key.
  3. As a follow-up, explain how you would extend the implementation to support other aggregation functions such as average and minimum.

Example input:

[
 ("A", "X", 10),
 ("A", "X", 20),
 ("A", "Y", 5),
 ("B", "X", 7)
]

Expected result for sum:

  • A / X -> 30
  • A / Y -> 5
  • B / X -> 7

In your explanation, describe what intermediate state must be maintained so that average and minimum can also be computed correctly.