FreeCareerPath
Build the PrimitiveMedium

Permutation in String

Write `contains_permutation(pattern, text)` returning `True` when any permutation of `pattern` appears as a contiguous substring of `text`. contains_permutation("ab", "eidbaooo") -> True ("ba") contains_permutation("ab", "eidboaoo") -> False The window is a fixed width, so this is simpler than it looks: slide it one character at a time, adding on the right and removing on the left. Comparing whole count maps at each step is O(26n); maintaining a count of how many characters currently match is O(n).

What to expect: A timer starts when you begin. Edit the starter code, run it against the test suite as many times as you like, then finish when you're done. The reference solution and interviewer follow-up questions unlock only after you finish.

Log in to start this session

Timed sessions and your results for "Permutation in String" are saved to your account — logging in takes a few seconds.

Permutation in String — FreeCareerPath