Compute top-N active customers
Company: Meta
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: Medium
Interview Round: HR Screen
Quick Answer: This question evaluates a candidate's competence in designing efficient data structures and streaming/top‑K algorithms, handling event-driven updates, correctness under late or expired events, deterministic tie‑breaking, and scalability to millions of customers.
Constraints
- deposit and pay add amount to that customer.
- An accepted transfer adds amount to both endpoints; expired transfers do not count.
Examples
Input: ([["deposit","c1",10],["pay","c2",7],["transfer","t1","c1","c2",5],["top",2],["accept","t1"],["top",2]],)
Expected Output: [[['c1', 10], ['c2', 7]], [['c1', 15], ['c2', 12]]]
Explanation: Accepted transfers add activity to both endpoints.
Input: ([["transfer","t1","a","b",3],["expire","t1"],["accept","t1"],["top",2]],)
Expected Output: [[]]
Explanation: Expired transfers contribute nothing.
Hints
- Clarify edge cases before coding.
- Keep the return value deterministic.