I went with a hash map of sets, one entry per user, each set holding the accounts they follow.
Clarify the requirements: the snapshot is static, so we can preprocess the follow relationships into a data structure optimized for membership queries. A hash set of (follower, followee) pairs gives O(1) average query time, but we should also discuss trade-offs with adjacency lists and memory considerations.
Pro tip: Mention that if the graph is dense, a bitset or Bloom filter could be more memory-efficient, but for sparse graphs a hash set is ideal. Also, note that the choice depends on whether we need to answer many queries or just a few.
Ask about the scale of the network (number of users, average follows per user), whether the snapshot is truly static, and if there are memory constraints. This shows you consider practical factors before choosing a data structure.
Suggest storing the follow relationships as a hash set of ordered pairs (A, B) or as an adjacency list (hash map from user to set of followees). Explain that this allows O(1) average-time membership checks.
State that the query complexity is O(1) average for hash-based structures, but worst-case O(n) if many collisions. Compare with alternatives like sorted arrays (O(log n) with binary search) or bitsets (O(1) but high memory).
Mention that preprocessing takes O(E) time to build the structure, where E is the number of edges. Memory is O(E) for hash set, which is efficient for sparse graphs. For dense graphs, consider bitsets or Bloom filters.
Conclude that for a static snapshot with frequent membership queries, a hash set of pairs is a good default. If memory is tight and false positives are acceptable, a Bloom filter could be used, but it requires a fallback.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.