AlgoLounge

Permutation In String

medium

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.

Examples

Example 1

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

s2 contains one permutation of s1: "ba".

Example 2

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

Constraints

  • 1 <= s1.length, s2.length <= 10⁴
  • s1 and s2 consist of lowercase English letters.
TypeScript
Loading editor…
List of test cases (10)
Case 1
s1 = "ab"
s2 = "eidbaooo"
Case 2
s1 = "ab"
s2 = "eidboaoo"
Case 3
s1 = "a"
s2 = "a"
Case 4
s1 = "ab"
s2 = "a"
Case 5
s1 = "adc"
s2 = "dcda"
Case 6
s1 = "abc"
s2 = "bbbca"
Case 7
s1 = "abc"
s2 = "ccccbbbbaaaa"
Case 8
s1 = "hello"
s2 = "ooolleoooleh"
Case 9
s1 = "ab"
s2 = "ab"
Case 10
s1 = "abc"
s2 = "cba"