Problem
Ask
Submissions

Problem: Permutation in String

Medium
30 min
Explore how to identify if any permutation of a given string appears as a contiguous substring within another. This lesson teaches you to apply the sliding window technique to efficiently solve permutation checks, a common pattern in coding interviews.

Statement

Given two strings, s1 and s2, determine whether any permutation of s1 appears as a contiguous substring within s2. In other words, return TRUE if s2 contains a substring that uses the same characters as s1, with the same frequencies, but possibly in a different order. Otherwise, FALSE.

A permutation of a string is any possible arrangement of all its characters. For example, for the string “ab”, the permutations are: “ab” and “ba”.

Constraints:

  • 11 \leq s1.length, s2.length 104\leq 10^4

  • s1 and s2 consist of lowercase English letters.

Problem
Ask
Submissions

Problem: Permutation in String

Medium
30 min
Explore how to identify if any permutation of a given string appears as a contiguous substring within another. This lesson teaches you to apply the sliding window technique to efficiently solve permutation checks, a common pattern in coding interviews.

Statement

Given two strings, s1 and s2, determine whether any permutation of s1 appears as a contiguous substring within s2. In other words, return TRUE if s2 contains a substring that uses the same characters as s1, with the same frequencies, but possibly in a different order. Otherwise, FALSE.

A permutation of a string is any possible arrangement of all its characters. For example, for the string “ab”, the permutations are: “ab” and “ba”.

Constraints:

  • 11 \leq s1.length, s2.length 104\leq 10^4

  • s1 and s2 consist of lowercase English letters.