Inclusion of a Shuffled String into Another String

Published by Deep Xavier in

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", "edabitbooo") ➞ 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.

Watch a quick demo on how Edabit works.