Skip to content
BASA DSA

Permutation In String

MediumSliding Window

Return whether a contiguous substring of s2 is a permutation of s1.

Example 1

Input
s1 = "ac"
s2 = "zzcayy"
Output
true

Explanation

ca appears contiguously in zzcayy and is a permutation of ac.

Example 2

Input
s1 = "ac"
s2 = "abbbcc"
Output
false

Explanation

a and c occur but never together in a length-two window.

Example 3

Input
s1 = "aa"
s2 = "baa"
Output
true

Explanation

The final aa window matches the two required a occurrences.

Constraints

  • 1 <= string lengths <= 10000
  • Strings contain lowercase English letters

Function contractcheckInclusionArguments: json, json
Loading draft…
SolutionRuns on your device
Loading draft…