You are given a start word and an end word of equal length, and a dictionary of valid words. In one move you may change exactly one letter to form a new word that must be in the dictionary. Find the minimal number of moves to transform the start into the end; return -1 if impossible. Implement an efficient solution. Follow-ups:
(
-
Optimize neighbor generation by introducing a reusable neighbor() function and wrap it with an LRU cache; explain eviction policy and complexity trade-offs.
(
-
The dictionary can be updated at runtime (words added/removed). Ensure correctness and thread-safety for queries while updates occur; specify how to synchronize or invalidate the neighbor cache (e.g., fine-grained locking around dictionary access or versioned snapshots) without assuming concurrent search execution.