Medium · Strings

Group Shifted Strings

Given an array of non-empty lowercase words strings, group the words that are shifts of one another (every letter moved forward by the same number of steps, with z wrapping around to a) and return the groups in any order.

Examples

Example 1

[abc, bcd, xyz, az]

Output: [["abc","bcd","xyz"],["az"]]

Example 2

[acef, a, z, ry]

Output: [["acef"],["a","z"],["ry"]]

Rebuild it in the studio

Open every published interview problem, solution, scene, and memory room free, with no account.

More Strings problems