Detect a Permuted Pattern in a Contiguous Window

Quick Overview

Detect a Permuted Pattern in a Contiguous Window. Return whether s2 contains a contiguous substring that is a permutation of s1.

Detect a Permuted Pattern in a Contiguous Window

Company: Meta

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Other

### Problem Return whether s2 contains a contiguous substring that is a permutation of s1. Every character occurrence of s1 must be used once in that window. ```cpp class Solution { public: bool checkInclusion(string s1, string s2); }; ``` ### Examples **Example 1:** ```text s1 = "aab", s2 = "xabaq" Output: true Explanation: Window "aba" has two a characters and one b. ``` **Example 2:** ```text s1 = "abc", s2 = "abxdce" Output: false Explanation: No length-three window has exactly a, b, c. ``` ### Constraints - Each string has 1..10000 characters drawn from English lowercase letters. ### Clarifying Questions Compare multiplicities in fixed-length windows, including repeated letters. ```hint Read the boundary condition What common summary identifies every permutation of a word? ``` ### Contract considerations Compare multiplicities in fixed-length windows, including repeated letters.

Overview: Detect a Permuted Pattern in a Contiguous Window. Return whether s2 contains a contiguous substring that is a permutation of s1.

Meta logo
Meta
Sep 13, 2026
mediumSoftware EngineerOtherCoding & Algorithms
0
0

Problem

Return whether s2 contains a contiguous substring that is a permutation of s1. Every character occurrence of s1 must be used once in that window.

class Solution {
public:
    bool checkInclusion(string s1, string s2);
};

Examples

Example 1:

s1 = "aab", s2 = "xabaq"
Output: true
Explanation: Window "aba" has two a characters and one b.

Example 2:

s1 = "abc", s2 = "abxdce"
Output: false
Explanation: No length-three window has exactly a, b, c.

Constraints

  • Each string has 1..10000 characters drawn from English lowercase letters.

Clarifying Questions Guidance

Compare multiplicities in fixed-length windows, including repeated letters.

Contract considerations

Compare multiplicities in fixed-length windows, including repeated letters.