Fewest Single-Letter Edits to Turn One Username Into Another
Last updated: November 29, 2026
Quick Overview
Given a start username, a target username of the same length, and a list of available usernames, return the length of the shortest chain from start to target where each step changes exactly one letter and every intermediate name is available, or 0 if impossible.
Meta
November 29, 20260
0
0 solved
Given a start username, a target username of the same length, and a list of available usernames, return the length of the shortest chain from start to target where each step changes exactly one letter and every intermediate name is available, or 0 if impossible.
This is word ladder in the style of Meta's onsite graph questions, framed around suggesting nearby available handles on Instagram. The interviewer checks that you model names as nodes in an implicit graph, use BFS for shortest path, and generate neighbors efficiently instead of comparing every pair of words.
What the Interviewer Expects
- Models each username as a node with edges for one-letter differences
- Uses BFS because every edge has equal weight
- Generates neighbors with wildcard patterns or letter substitution, not all-pairs comparison
- Marks nodes visited when enqueued
- Mentions bidirectional BFS for large dictionaries
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
- Return one actual shortest chain, not just its length.
- How does bidirectional BFS change the cost?
- What if insertions and deletions are also allowed?
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: start, target, and names (all same length, lowercase). Output: number of names in the shortest chain including both ends, or 0. The start need not be in the list; the target must be. List...
High-Level Design
Build an index from wildcard patterns to names: for cat, the patterns are *at, c*t, ca*. Two names are neighbors exactly when they share a pattern. BFS from start level by level. For each po...