DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
Back to Arena
medium
Sliding Window

Permutation in String

**Problem Statement:** 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 the substring of `s2`. **Hint / Expected Approach:** Fixed-size window + char frequency array **Edge Cases to Consider:** - (1) s1 longer than s2 - (2) s1 and s2 identical - (3) No permutation exists

Examples

Example 1
Input: "ab", "eidbaooo"
Output: True
Example 2
Input: "ab", "eidboaoo"
Output: False
Example 3
Input: "a", "a"
Output: True

Constraints

  • ▪1 <= data.length <= 10^5
  • ▪Memory complexity must be O(1) or O(k)
  • ▪Ensure non-overlapping pointer access

Watch Out For Edge Cases

  • ▪s1 longer than s2
  • ▪s1 and s2 identical
  • ▪No permutation exists
Frequently Asked At
GoogleAmazonMicrosoftAdobe