What did you learn? Hash sets turn searches into checks.
Clever iteration order avoids double-counting. Only start from sequence beginnings.
Amortized analysis: the nested loop looks , but each element is processed at most twice. Total is . This problem shows that solutions sometimes require creative thinking, not just applying a pattern.