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
Coding & Algorithms
Software Engineer
Meta
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

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
hash map
canonical form
modular arithmetic
grouping
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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...


Submit Your Answer
Markdown supported