← Block Interview Insights

Block·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
May 2026

Summary

Square coding interview, one question, pretty focused on data structures and API design. Not a lot of context given upfront so you kind of have to feel your way through what they actually want.

Questions Asked (1)

Q1

Design and implement a class that processes a stream of transactions between customers, and supports a query to check whether two specific customers have ever transacted directly with each other.

Algorithms & Data StructuresSystem Design
Author's notes

Looks simple at first glance and that's kind of the problem.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying requirements: what defines a transaction (e.g., amount, timestamp), whether the stream is unbounded, and query frequency. Then propose a design using a hash map from customer ID to a set of customer IDs they have transacted with, which supports O(1) insertion and O(1) query. Discuss trade-offs like memory usage and potential for distributed processing if the stream is large.

Pro tip: Mention that you would use a symmetric data structure (e.g., add both directions) to ensure queries work regardless of transaction direction, and consider using a Bloom filter for memory efficiency if false positives are acceptable.

1. Clarify requirements and constraints

Ask about transaction volume, query frequency, memory limits, and whether the stream is real-time or batch. Confirm if transactions are directed (A pays B) or undirected.

2. Choose data structures

Propose a hash map where each key is a customer ID and the value is a set of customer IDs they have transacted with. This gives O(1) average insertion and query time.

3. Handle stream processing

Describe how to process each transaction: extract customer IDs, and if they are different, add each to the other's set. Consider concurrency if multiple threads process the stream.

4. Implement query method

For a query (customer1, customer2), check if customer1 exists in the map and if customer2 is in its set. Return true if so, else false.

5. Discuss scalability and optimizations

Address memory usage for large streams, potential sharding by customer ID, and alternatives like Bloom filters for approximate membership if exactness is not required.

Key Points to Mention

  • Time complexity: O(1) average for both insertion and query using hash map and set.
  • Space complexity: O(E) where E is the number of unique transactions (edges).
  • Handling directed vs undirected transactions: store both directions for undirected queries.
  • Concurrency: use thread-safe data structures or partitioning if processing in parallel.
  • Scalability: consider distributed hash tables or sharding for very large customer bases.
  • Edge cases: self-transactions (ignore), duplicate transactions (sets handle automatically), and missing customers (return false).

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