Looks simple at first glance and that's kind of the problem.
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.
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.
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.
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.
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.
Address memory usage for large streams, potential sharding by customer ID, and alternatives like Bloom filters for approximate membership if exactness is not required.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.