Permutation in String
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 the substring of s2.

30:00

Permutation in String
medium
Topics
Companies

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 the substring of s2.

Example 1:
Input: {"s1":"ab","s2":"eidbaooo"}
Output: true
Constraints:
  • 1s1.length,s2.length1041 \leq s_1.\text{length}, s_2.\text{length} \leq 10^4

  • s1s_1 and s2s_2 consist of lowercase English letters.

Input
arr ={"s1":"ab","s2":"eidbaooo"}
s2 = "eidbaooo"
e
i
d
b
a
o
o
o
0
1
2
3
4
5
6
7
Window:
[0...1]
Matches:
0
s1 "ab" character count

Empty

Current window character count

Empty

Algorithm Insight:

A permutation has the same character frequencies. We slide a window of size |s1| over s2,
checking if the window's character count matches s1's count.

Variables
No variables to display
DepthFunction Call
1checkInclusion(s1="ab", s2="eidbaooo")
0/8