Skip to content
Onsite

Permutation in String

MediumP2Coding

Return true if s2 contains a permutation of s1 as a substring, that is, some contiguous part of s2 that has the same letters as s1 with the same counts in any order. Otherwise return false.

Example 1

Input
s1 = "ab", s2 = "eidbaooo"
Output
true

Example 2

Input
s1 = "ab", s2 = "eidboaoo"
Output
false

Example 3

Input
s1 = "a", s2 = "a"
Output
true

Constraints

  • 1 <= s1.length, s2.length <= 10^4
  • Both strings consist of lowercase English letters.

Hints

Run checks the 3 visible tests, Submit all 12.