Permutation in String
Given strings s1 and s2, return true if s2 contains a substring that is a permutation of s1 (a contiguous block with exactly s1's character counts), and false otherwise.
Open official problem prompt ↗Decide whether some contiguous slice of s2 is an exact rearrangement of s1.
You carry a fixed set of Scrabble tiles (s1) and drag a window of that many slots along a longer rack (s2). You are happy the instant the tiles in the window are exactly your set, in any order.
- Input
- s1 = "ab", s2 = "eidbaooo"
- Output
- true
- Why
- s2 contains the substring "ba" (indices 3-4), which is a permutation of "ab".
1 <= s1.length, s2.length <= 10^4s1 and s2 consist of lowercase English letters