← Sliding Window

Pattern Recognition Drill

#104 — Permutation in String

Medium Sliding Window

The Problem

Given strings s1 and s2, return true if s2 contains a permutation of s1 as a substring.

What approach would you use?

Think about it before scrolling down.

Key Signals

Sliding Window

Fixed window of size len(s1). Compare frequency counts. O(n).

Alt: Hash Map

Maintain a 'matches' counter for how many of 26 chars have equal counts. O(n).

Common Trap

Don't generate all permutations — that's O(n!). The frequency count comparison is key.

← #103