Permutation in String

Sliding Window, problem 5 of 7

Permutation in String

Medium

LC #567

stringfixed windowcounting

Not attempted yet

Given two lowercase strings s1 and s2, return True if some rearrangement of s1 appears in s2 as a contiguous substring, otherwise False.

Example 1

Input: s1 = "ab", s2 = "eidbaooo"
Output: True
"ba" appears at index 3.

Example 2

Input: s1 = "ab", s2 = "eidboaoo"
Output: False

Example 3

Input: s1 = "adc", s2 = "dcda"
Output: True
"cda" is a rearrangement of "adc".

Constraints

  • 1 ≤ len(s1), len(s2) ≤ 10^5
  • Only lowercase English letters.

Python

Loading draft…

Test results

9 tests available

No results yet

Run tests your code against the examples; Submit runs the hidden tests too.

3 examples, 6 hidden

Run examples, then submit all tests.