DIY: Group Shifted Strings
Solve the interview question "Group Shifted Strings" yourself in this lesson.
We'll cover the following
Given an array of strings (lowercase alphabets), we have to group all strings that are shifted versions of each other. For a string
abc, its shifted sequence can be
lmn because each character in both strings gets incremented by
1 to form the next character. Similarly, any three letter word that has a character difference of
1 between their letters will be shifted a sequence of
The input will be an array of strings. The following is an example input:
["acd", "dfg", "wyz", "yab", "mop", "bdfh", "b", "y", "moqs"]
The output will be an array of grouped strings. The following is an example output:
[ ["acd", "dfg" "wyz" "yab" "mop"] ["bdfh", "moqs"] ["b", "y"] ]
groupStrings(strs) function, where
strs is the array of strings. The function will return an array of grouped strings within an array.