Back to Practice Dashboard
Top 150 InterviewEasy
Permutation In String
Learn how to solve the 'Permutation In String' problem. This detailed resource details brute force and optimized approaches.
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?
Maintain a sliding window boundary using two pointers. Expand the right boundary, and contract the left boundary if criteria are violated.
Edge Cases to Watch
- Empty list or null input variables
- Single item lists/arrays
- Extremely large input bounds causing integer or stack overflow
Ready to Solve?
Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.