PracHub
QuestionsCoachesLearningGuidesInterview Prep

Quick Overview

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.

  • Medium
  • Meta
  • Coding & Algorithms
  • Software Engineer

Compute top-N active customers

Company: Meta

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: HR Screen

Maintain and return the top N customers by cumulative activity amount, where activity is defined as the sum of deposit amounts, pay amounts, and transfer amounts only when the transfer is successfully accepted (expired transfers contribute nothing). Design data structures and an API (e.g., getTopNActivity(N)) that support near‑real‑time updates as operations occur and efficient queries. Specify update and query complexities, handle late accept events that change a customer’s activity, ensure correctness when transfers expire, define deterministic tie‑breaking (e.g., by customerId then most‑recent activity), and discuss how you would handle changing N between queries and scale to millions of customers.

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.

Simulate customer activity updates and top-N queries with deterministic tie-breaking by customer id.

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

  1. Clarify edge cases before coding.
  2. Keep the return value deterministic.
Last updated: Jun 27, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Find Shortest Unique Prefixes - Meta (medium)
  • Compute Exclusive Execution Times - Meta (medium)
  • Solve Tree Columns And Maze Variants - Meta (medium)
  • Solve Tree Diameter and Palindromic Counts - Meta (medium)
  • Simulate Monster Team Battles - Meta (hard)