A string can be shifted by replacing every letter with the next letter of the alphabet (with z wrapping to a). So "abc" shifts to "bcd", and "az" shifts to "ba". Two strings belong to the same group if one can be shifted into the other any number of times.
Write groupShiftedStrings(strings) that returns the groups as an array of arrays, in any order.
- All strings use lowercase letters only
- Strings of different lengths are never in the same group
- Single letters all belong together, because
"a" shifts to "b" and so on - Build a canonical key for each string, then group by key