Home
Log in
DescriptionSubmissionsSolution
DescriptionSubmissionsSolution
Loading...

Log in to run or submit

s =
t =

Codey

Practise coding problems, test your solutions and track your progress.

Explore

  • Problems
  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

© 2026 Codey. Personal learning project.

Solution
Updated: 2026-02-23

Idea

Use a sliding window that expands until it covers all required characters, then shrinks to minimal.

Approach

Maintain a frequency map need for t and a missing counter for how many required characters are still unmet. Expand r to satisfy requirements, then shrink l while keeping the window valid.

Why it works

Every time the window becomes valid, shrinking from the left finds the smallest valid window ending at r. The global best over all r is the answer.

Code
Loading...
Complexity
Time: O(n)
Space: O(1)
Solution
Updated: 2026-02-23

Idea

Use a sliding window that expands until it covers all required characters, then shrinks to minimal.

Approach

Maintain a frequency map need for t and a missing counter for how many required characters are still unmet. Expand r to satisfy requirements, then shrink l while keeping the window valid.

Why it works

Every time the window becomes valid, shrinking from the left finds the smallest valid window ending at r. The global best over all r is the answer.

Code
Loading...
Complexity
Time: O(n)
Space: O(1)