Permutation in String

Medium

This is an extra practice problem. It doesn't have walkthrough slides. You can solve it with the pattern template you already know. Open the hints if you get stuck.

Question

You get two strings of lowercase letters, s1 and s2. Return true if some stretch of letters in a row in s2 has exactly the same letters as s1. The order doesn't have to match. Otherwise, return false.

Input: s1 = "ab", s2 = "eidbaooo"

Output: true

The stretch "ba" starts at index 3. It has exactly the letters in "ab", just in a different order.

Input: s1 = "ab", s2 = "eidboaoo"

Output: false

No two-letter stretch of s2 uses exactly one "a" and one "b".

Input: s1 = "adc", s2 = "dcda"

Output: true

The last three letters of s2, "cda", have exactly the letters in "adc".

Clarify the problem

What are some questions you'd ask an interviewer?

Understand the problem

Which of these words contains a stretch of letters that uses exactly the same letters as "abc"?
"muckrake"
"bracket"
"cabinet"
"camel"

Remember to understand the problem and plan your approach before you start coding.