Top 150 InterviewEasy

Permutation In String

Detailed guide and Python implementation for the 'Permutation In String' problem.

Problem Statement

Easy

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 a substring of s2.

Write a function checkInclusion(s1: str, s2: str) -> bool.

Constraints
  • 1 <= len(s1), len(s2) <= 10^4
  • s1 and s2 consist of lowercase English letters

Examples

Example 1
Input
s1 = "ab", s2 = "eidbaooo"
Output
True
Explanation

s2 contains one permutation of s1: "ba" (starting at index 3).

Example 2
Input
s1 = "ab", s2 = "eidboaoo"
Output
False
Explanation

No permutation of "ab" exists as a contiguous substring in s2.

Need a Hint?
Consider using Sliding Window-specific data structures like sets or heaps.
Edge Cases to Watch
  • Empty input structures
  • Single element inputs
  • Large numerical bounds

Ready to Solve?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

Open in Editor

Recommended Python Resources

Expand your knowledge with related interactive tutorials, cheat sheets, and code comparisons.