← Back to challenges

Inclusion of a Shuffled String into Another String

JavaScriptHardalgorithmsconditionsloopsstrings

Instructions

The function is given two strings s1 and s2. Determine if one of the permutations of characters of s1 is a substring of s2, return true / false.

Examples

checkInclusion("ab", "innokodakademijabooo") ➞ true
// "ab" is in s2.

checkInclusion("ab", "edaoboat") ➞ false
// neither "ab" or "ba" is in s2.

checkInclusion("adc", "dcda") ➞ true
// "cda" is a permutation of "adc" and it is in s2.

checkInclusion("sgyuws", "oldqwqdmlvsguswyfbj") ➞ true
// "sguswy" is a permutation of s1 and it is in s2.

Notes

All characters in both strings are lowercase letters.

javascript
Loading editor…
⌘ ↵ to run
Walks through the solution with reasoning and edge cases.