Permutation in String
You get two strings, s1 and s2. Find out whether s2 contains s1 with its letters in some order, as one piece of letters in a row. Our example: s1 = "loot", s2 = "tollotool" — yes: "loto" at index 3.
- input
s1,s2: two strings of lowercase English letters.- returns
trueifs2has the letters ofs1in some order as one piece of letters in a row, otherwisefalse.- constraints
- 1 ≤ s1.length, s2.length ≤ 10⁴
- s1 and s2 have lowercase English letters only
- examples
- Open a test in the tests panel: it shows the input and the expected answer.
/**
* @param {string} s1
* @param {string} s2
* @return {boolean}
*/
function checkInclusion(s1, s2) {
}
Ctrl ↵
format
reset
saved in this browser
Stuck?
See the solution run step by step on our example, then why it works and its complexity.
Next: more sliding window problems
- 643Maximum Average Subarray IEasysolve
- 28Find the Index of the First Occurrence in a StringEasysolve
- 3Longest Substring Without Repeating CharactersMediumsolve
- 209Minimum Size Subarray SumMediumsolve
- 424Longest Repeating Character ReplacementMediumsolve
- 76Minimum Window SubstringHardsolve
- 30Substring with Concatenation of All WordsHardsolve
The problem and its statement belong to LeetCode. Here are our own retelling, example and solution. Patterns Hero is not affiliated with LeetCode.