cheetcode

18. Permutation in StringMedium

Check whether one string contains a permutation of another.

Given two strings s1 and s2, return true if s2 contains a permutation of s1, or false otherwise.

In other words, return true if one of s1's permutations is a substring of s2.

Maintain only the current window state as it expands or shrinks. Watch for the exact condition that makes a window valid, invalid, or worth recording.

Examples

Input: s1 = "ab", s2 = "eidbaooo"
Output: true
Input: s1 = "ab", s2 = "eidboaoo"
Output: false

Constraints

  • 1 <= s1.length, s2.length <= 10,000
  • s1 and s2 consist of lowercase English letters.