← Ramp Interview Insights

Ramp·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Jun 2026Remote

Summary

Ramp coding round for a software engineer role. The whole session was basically one extended design-and-implement question about a banking system, with a twist on ranking accounts by outgoing activity. More algorithmic than I expected for a fintech company.

Questions Asked (1)

Q1

You're building a banking system with CREATE_ACCOUNT, DEPOSIT, and TRANSFER operations. Now add a TOP_ACTIVITY(timestamp, n) query that returns the top n accounts ranked by total outgoing transaction amount, with ties broken alphabetically by account ID. How do you design the data structure to make this efficient, and what's the cost per operation?

Algorithms & Data StructuresSystem DesignTechnical Trade-offs
Author's notes

I knew immediately they wanted a heap or sorted set, but I fumbled explaining the key design.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the requirements and constraints, then propose a data structure that maintains a running total of outgoing amounts per account and supports efficient top-n queries. Discuss the trade-offs between different approaches (e.g., sorted list vs. heap vs. balanced BST) and analyze the time complexity for each operation, including the TOP_ACTIVITY query.

Pro tip: Mention that in a real banking system, you'd likely need to handle concurrent updates and consider persistence, but for this question, focus on the core data structure and algorithmic efficiency. Also, note that ties are broken alphabetically, so the structure must support that ordering.

1. Clarify requirements and assumptions

Ask about the expected frequency of operations, the size of n relative to the number of accounts, and whether the timestamp is just a point-in-time snapshot or if historical queries are needed. Assume we need to answer queries at any given timestamp, but since operations are sequential, we can maintain the current state.

2. Design the core data structure

Propose maintaining a hash map from account ID to balance and total outgoing amount. Additionally, maintain a balanced binary search tree (or a skip list) keyed by (total outgoing amount, account ID) to support efficient top-n queries. Alternatively, use a max-heap with lazy deletion, but note that ties and updates require careful handling.

3. Analyze operation costs

For CREATE_ACCOUNT: O(1) to insert into hash map and O(log A) to insert into the tree (A = number of accounts). For DEPOSIT: O(1) to update balance. For TRANSFER: O(1) to update balances and O(log A) to update the tree for the sender's outgoing total (remove old entry, insert new). For TOP_ACTIVITY: O(n) to retrieve the top n from the tree (in-order traversal) or O(n log n) if using a heap, but with a tree it's O(n) after finding the starting point.

4. Discuss trade-offs and alternatives

Compare with using a sorted array (O(A) update, O(1) query) or a heap (O(log A) update, O(n log A) query). Highlight that the balanced BST gives O(log A) updates and O(n) queries, which is optimal for frequent updates and moderate n. Mention that if n is small, a heap might be simpler.

5. Consider edge cases and optimizations

Address ties: since the tree is keyed by (amount, account ID), ties are automatically broken alphabetically. Discuss handling of zero outgoing amounts (should they be included? Probably not, as they have no outgoing transactions). Also, consider if we need to support deletion of accounts or if accounts are permanent.

Key Points to Mention

  • Use a hash map for O(1) access to account balances and outgoing totals.
  • Maintain a balanced BST (e.g., red-black tree) keyed by (outgoing_total, account_id) to support efficient top-n queries and tie-breaking.
  • Time complexities: CREATE_ACCOUNT O(log A), DEPOSIT O(1), TRANSFER O(log A), TOP_ACTIVITY O(n) (or O(n log A) if using a heap).
  • Trade-offs: balanced BST vs. heap vs. sorted list; BST offers O(log A) updates and O(n) queries, which is good for frequent updates.
  • Tie-breaking is handled by including account ID in the key, ensuring alphabetical order for equal amounts.
  • Consider concurrency and persistence in a real system, but for the interview, focus on the data structure and algorithmic efficiency.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.