← Square Interview Insights

Square·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Jun 2026

Summary

Square coding interview, one question about transaction graph lookups. Pretty focused and not too long, but the problem had some interesting design decisions hiding under the surface.

Questions Asked (1)

Q1

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

Algorithms & Data StructuresSystem DesignData Modeling
Author's notes

My first instinct was a hashmap where each customer maps to a set of everyone they've transacted with.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying requirements: transaction volume, query frequency, and whether the stream is real-time or batch. Then propose a data model that stores each unique customer pair in a hash set for O(1) query, and discuss trade-offs like memory usage and scalability.

Pro tip: Mention that you would normalize the pair (e.g., sort customer IDs) to avoid duplicates and ensure consistent lookups. Also, consider using a probabilistic data structure like a Bloom filter if memory is constrained, but be clear about false positives.

1. Clarify Requirements

Ask about expected transaction rate, number of customers, query frequency, and memory constraints to guide design choices.

2. Design Data Model

Propose storing each unique customer pair in a hash set, using a normalized key (e.g., min-max or sorted tuple) to ensure consistency.

3. Process Stream

For each transaction, extract the two customer IDs, normalize the pair, and insert into the set if not already present.

4. Answer Query

For a query, normalize the given pair and check membership in the set, returning true if present.

5. Discuss Trade-offs and Scalability

Address memory usage (O(P) where P is number of unique pairs), potential for distributed storage, and alternatives like Bloom filters for approximate answers.

Key Points to Mention

  • Use of a hash set for O(1) average-case query time.
  • Normalization of customer pairs (e.g., sorting IDs) to avoid duplicates.
  • Memory complexity: O(P) where P is number of unique pairs, which could be large.
  • Scalability considerations: sharding by customer ID or using distributed cache.
  • Alternative: Bloom filter for memory efficiency with false positives.
  • Handling of concurrent updates and thread safety if needed.

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