0PricingLogin
Competitive Programming Academy · Lesson

Sets for Membership and Dedup

Test existence in constant time.

What a Set Buys You

A set stores unique items with no order, and its real power is answering 'is this here?' in roughly constant time. ⚡

Why Not Just a List

Checking membership in a list scans every element, so it is O(n). A set hashes the value and jumps straight to the bucket instead.

All lessons in this course

  1. Sets for Membership and Dedup
  2. Dictionaries as Lookup Tables
  3. Counter and defaultdict in Action
  4. Group and Bucket with a Map
← Back to Competitive Programming Academy