Shortest Rename Chain Between Two Identifiers Changing One Letter

Last updated: November 29, 2026

Quick Overview

Given a start identifier, a target identifier and a dictionary of valid identifiers of equal length, return the number of identifiers in the shortest chain from start to target where each step changes exactly one letter and every intermediate is in the dictionary, or 0 if impossible.

Microsoft
Coding & Algorithms
Software Engineer
Microsoft
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


Given a start identifier, a target identifier and a dictionary of valid identifiers of equal length, return the number of identifiers in the shortest chain from start to target where each step changes exactly one letter and every intermediate is in the dictionary, or 0 if impossible.

A BFS Hard problem common in Microsoft onsites, framed as a refactoring tool that only allows one-character renames through known symbols. The interviewer checks implicit graph construction, efficient neighbor generation with wildcard buckets, and may push for bidirectional BFS.

What the Interviewer Expects
  • Model identifiers as nodes with an edge for a one-letter difference
  • Generate neighbors through wildcard patterns instead of comparing all pairs
  • Run BFS for shortest path in an unweighted graph
  • Mark visited to avoid revisiting
  • Discuss bidirectional BFS for large dictionaries
Key Topics to Cover
BFS
implicit graphs
wildcard bucketing
bidirectional search
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
  • How would you return one actual shortest chain, or all of them?
  • How does bidirectional BFS change the complexity?
  • What if steps can also insert or delete a letter?
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 (same length L), list words. The target must be in words or the answer is 0. Output: number of identifiers in the chain including both ends. If start equals target, the an...

High-Level Design

Comparing every pair of words costs O(N^2 L). Instead, bucket words by wildcard patterns: cat belongs to *at, c*t, ca*. Two words are neighbors exactly when they share a pattern. BFS from `sta...


Submit Your Answer
Markdown supported