Reversing the direction of BFS removes the TLE and code gets accepted.

  • 1

    I reversed the direction of BFS, i.e., I searched from endWord to beginWord and then it got accepted. When I change it back, I get TLE.

  • 0

    Same. There are probably more valid words closer to beginWord than to endWord, resulting in a more focused BFS starting from endWord.

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.