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
Coding & Algorithms
Software Engineer
Meta
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

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
BFS
Implicit graphs
Shortest path
Hashing
Strings
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
  • 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 Problems
Sample 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...


Submit Your Answer
Markdown supported