algorythms
Sliding Window
LC #567Medium

Permutation in String

Sliding Window
AmazonGoogleMetaBloomberg

Problem

Given strings s1 and s2, return true if s2 contains a permutation of s1.

stringsliding-windowhash-map

Constraints

  • 1 ≤ s1.length, s2.length ≤ 10⁴
  • s1 and s2 consist of lowercase English letters only

Example

Inputs1 = "ab", s2 = "eidbaooo"
Outputtrue
Why

s2 contains "ba" at index 3–4, which is a permutation of "ab"

Hints — reveal one at a time