Implement Table Aggregation
Problem Description
You are given a table represented as a list of rows. Each row contains two fields:
key: a string that identifies a group.value: an integer.
Your task is to write a function that aggregates this table by key. For each distinct key, the function should calculate the sum of all corresponding values.
Example
Input rows:
- (A, 3)
- (B, 5)
- (A, 2)
- (B, 1)
- (C, 4)
Output:
- (A, 5)
- (B, 6)
- (C, 4)
The order of the output pairs does not matter unless explicitly specified.
Follow-up Discussions
- How would you extend your implementation to support other aggregation functions, such as
MAX, in addition toSUM? - If the table is too large to fit into memory, how would you process it efficiently?
AI interview prep
Core dilemma
Balancing memory constraints, I/O efficiency, and extensibility for various aggregation functions when processing massive datasets.
3 tradeoffs and 3 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Implement Table Aggregation
Problem Description
You are given a table represented as a list of rows. Each row contains two fields:
key: a string that identifies a group.value: an integer.
Your task is to write a function that aggregates this table by key. For each distinct key, the function should calculate the sum of all corresponding values.
Example
Input rows:
- (A, 3)
- (B, 5)
- (A, 2)
- (B, 1)
- (C, 4)
Output:
- (A, 5)
- (B, 6)
- (C, 4)
The order of the output pairs does not matter unless explicitly specified.
Follow-up Discussions
- How would you extend your implementation to support other aggregation functions, such as
MAX, in addition toSUM? - If the table is too large to fit into memory, how would you process it efficiently?