Algorithms · Level 1 Complexity

Big-O: Spot the Hidden Loop

Find duplicate sign-ups in one pass with a set, and see why a nested loop or x in a list gets 100 times slower when the data grows 10 times.

  • O(n) vs O(n²)
  • x in list is a hidden loop
  • set lookups in one step

Big-O describes how work grows with the input. One loop over n items is O(n); a loop inside a loop is O(n²): 10 times more data, 100 times slower. Trap: x in a_list is a hidden loop. A set checks membership in one step.

seen = set()
for user in users:
    if user in seen:  # 1 step (list: n)
        print("again:", user)
    seen.add(user)

Write has_duplicate(emails): True if any email appears more than once. One test sends 5,000 sign-ups, so loop once. Example: has_duplicate(['[email protected]', '[email protected]', '[email protected]']) → True.

solution.py
Test Suites Pending
Output