Skip to content
Decoder

Permutation in String

Medium

Problem

Given two strings s1 and s2, return true if s2 contains a contiguous substring that is a rearrangement of `s1` (same letters, same counts), and false otherwise.

Example 1

Input
s1 = "ab", s2 = "eidbaooo"
Output
true
Why
"ba"

Example 2

Input
s1 = "ab", s2 = "eidboaoo"
Output
false

Example 3

Input
s1 = "adc", s2 = "dcda"
Output
true
Why
"cda"

Constraints

  • 1 <= s1.length, s2.length <= 10^4
  • s1 and s2 consist of lowercase English letters.

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.