Permutation in String Problem
Permutation in String Problem — ExecCode Easy DSA Practice
Solve the Permutation in String problem on ExecCode. Free online easy DSA practice in Sliding Window. Write and run code in Java, C++, Python — no signup required to run.
Problem description
Given strings s1 and s2, determine whether any contiguous substring of s2 is a permutation of s1. A permutation must have the same length and the same character counts as s1, only the order may differ. Therefore the window size is fixed at len(s1): add the next character from s2, drop the old left character when the window becomes too large, and compare the window frequency with the required frequency.
Examples
Input {"s1": "ab", "s2": "eidbaooo"}; Output True. Input {"s1": "ab", "s2": "eidboaoo"}; Output False. Input {"s1": "adc", "s2": "dcda"}; Output True
Constraints
1 ≤ s1.length, s2.length ≤ 10⁴ s1 and s2 consist of lowercase English letters
Practice Permutation in String free on ExecCode. Browse DSA problems, topic map, and placement guides.