← All coding problems
Permutation in String
mediumSliding Window+20 XPTime limit 2s
Does s2 contain some rearrangement of s1 as a contiguous substring? For example s1 = ab, s2 = eidbaooo → true (it contains ba).
Input:
- line 1:
s1 - line 2:
s2
Output: true or false.
Constraints: 1 ≤ length of s1, s2 ≤ 10⁵; lowercase English letters.
Think about it: slide a window of length len(s1) over s2 and compare letter counts (26 numbers) — update the counts in O(1) per step.
Sample input 1
ab eidbaooo
Sample output 1
true
Sample input 2
ab eidboaoo
Sample output 2
false
📖 Stuck? Learn the pattern
Read input from standard input and print the answer to standard output. Your code runs in a secure sandbox against the samples (Run) and hidden tests (Submit).