Group Handles That Are Letter Shifts of One Another
Last updated: November 29, 2026
Quick Overview
Given a list of lowercase handles, group together the ones that can be turned into each other by shifting every letter forward by the same amount (with z wrapping to a), and return the groups.
Meta
November 29, 20260
0
0 solved
Given a list of lowercase handles, group together the ones that can be turned into each other by shifting every letter forward by the same amount (with z wrapping to a), and return the groups.
A hashing question about choosing the right canonical key, in the style of Meta's grouping problems. The interviewer wants a key that is invariant under the shift and correct across the z to a wrap.
What the Interviewer Expects
- Defines a canonical key from the differences between adjacent letters
- Applies modulo 26 so that wraps like za and ab produce the same key
- Groups by key using a dictionary of lists
- Treats handles of different length as different groups automatically
- Gives O(total characters) time
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Characters can be digits too, with a separate 10-cycle. How does the key change?
- Find the largest group without materializing all groups.
- How would you run this over billions of handles in a batch job?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: handles, a list of lowercase strings. Output: a list of groups, each a list of handles that are shifts of each other. Single-letter handles are all shifts of each other. Order within groups f...
High-Level Design
Two handles are shifts of each other exactly when they have the same length and the same sequence of gaps (s[i] - s[i-1]) mod 26. That tuple of gaps is invariant under adding a constant to every let...