01 · Question
Each user has an unordered list of IP addresses they have connected from. Return whether two users have exactly the same IP addresses.
Example:
- Input:
[("mike", ["203.0.113.10"]), ("bob", ["222.0.0.5", "111.0.0.10"]), ("bob2", ["111.0.0.10", "222.0.0.5"])] - Output:
true
02 · Analysis
The same IPs may appear in different orders. Sort each user's IPs and convert the result to one immutable canonical key. Equal unordered lists now produce equal keys, so a set detects duplicates.
If a user has IPs, canonicalizing that list costs . The set stores one signature per user in the worst case.