Home
Log in
DescriptionSubmissionsSolution
DescriptionSubmissionsSolution
Loading...

Log in to run or submit

s1 =
s2 =

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

A permutation of s1 appears in s2 if some window of length len(s1) has the same character counts.

Approach

Use a fixed-size sliding window over s2. Maintain 26-length frequency arrays for s1 and the current window. Slide by adding the new char and removing the left char.

Why it works

Two strings are permutations iff their frequency vectors match.

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

Idea

A permutation of s1 appears in s2 if some window of length len(s1) has the same character counts.

Approach

Use a fixed-size sliding window over s2. Maintain 26-length frequency arrays for s1 and the current window. Slide by adding the new char and removing the left char.

Why it works

Two strings are permutations iff their frequency vectors match.

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