Skip to content

Multi-Account Cheating

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 kk IPs, canonicalizing that list costs O(klogk)O(k log k). The set stores one signature per user in the worst case.

03 · Solution

Reference solution

1def multi_account_cheating(users):
2 seen = set()
3
4 for _, ips in users:
5 signature = tuple(sorted(ips))
6 if signature in seen:
7 return True
8 seen.add(signature)
9
10 return False