WorkspaceLearning path
Level 1 · Foundations
BUILD YOUR INTUITION

HashSet

Remember membership without storing a separate associated value.

THE MENTAL MODEL

When should this come to mind?

Remember membership without storing a separate associated value.

Duplicate detectionAlready visitedUnique values

What makes it work

Membership is expected O(1); storing k unique values takes O(k) space.

When to choose something else

If you need counts or indices, use a map instead.

See the pattern in action

Change the input. Follow the state. Make it yours.