Skip to main content
Intermediatecoding Verified

Nodes are 4-digit codes and you can move between codes that differ by one digit step; only some codes are allowed. Find the minimum number of transitions from a start code to a target, or -1.

ReportedSource: GeeksforGeeks interview experience: Uber SDE-1 off-campus

Quick answerFree

BFS over 4-digit codes; neighbours change one digit by +/-1 (wrapping), filtered to allowed codes; first time you reach the target is the minimum. O(10^4 · 8).

Detailed answer· ~100 words

Interview Prep

Unlock the full answer with Interview Prep

Get a ~100-word model answer and a runnable reference solution, plus 61 more DSA questions.

Also in Pro (₹499 / 90 days).

Reference solution· runs in the browser sandbox

Interview Prep
Unlock with Interview Prep

+ 61 more DSA questions in Interview Prep, each with the full answer.

Discussion