FastPrepPermutation in a String
Problems/Permutation in a String

Permutation in a String

PeopleStrong logoPeopleStrong● MediumFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a PeopleStrong online assessment. The report describes finding a permutation of one string inside another. We chose which characters can appear, what happens with empty text, and the limits. Our version is about 95% the same as the reported question.

Given strings pattern and text, return whether a contiguous substring of text is a permutation of pattern. A permutation uses exactly the same characters with the same multiplicities, in any order.

For this exercise, assume the pattern is nonempty and both strings contain only lowercase English letters. Return false when the text is shorter than the pattern.

Function

checkInclusion(pattern: String, text: String) → boolean

Examples

Example 1

pattern = "ab"text = "eidbaooo"return = true

The substring ba has the same two characters as ab.

Example 2

pattern = "ab"text = "eidboaoo"return = false

No length-2 contiguous substring contains one a and one b.

Constraints

  • For this exercise, assume 1 <= pattern.length <= 2000.
  • 0 <= text.length <= 20000.
  • Both strings use only characters a through z.
See PeopleStrong hiring insights
Saved
class Solution {
    public boolean checkInclusion(String pattern, String text) {
        // Write your solution here.
    }
}
Checking account…