Why the output is incorrect ?

  • -2

    Input: "a", "c", ["a","b","c"]
    Output: 1
    Expected: 2

    "a" can be changed to "c" by changing only one character. So minimum number of transformations must be 1.

  • 2

    There is only one transformation in the shortest path, however, look at this from the problem:

    As one shortest transformation is "hit" -> "hot" -> "dot" -> "dog" -> "cog",
    return its length 5. 

    The answer to this problem is not the number of transformations, but the number of words in the chain. In your case, the chain is "a" -> "c", which has 2 words in the chain, as seen in the expected answer. As a simple correction to your problem, take your return value and add 1 to it.

  • 0

    ya.. thanks a lot. got it.

Log in to reply

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