Group Shifted Strings

Medium · Hashing · about 15 minutes

Asked at Meta, Uber, Google, Amazon.

Shifting a string moves every letter to the next one ('z' wraps to 'a'), so "abc" can shift to "bcd", and "az" to "ba". Strings that can be shifted into each other form a shifting sequence. Group the given lowercase strings by shifting sequence. Return the groups in any order; strings inside a group may be in any order.

Related guides