Is the answer in test cases correct?


  • 1
    A

    I was doing the problem : http://oj.leetcode.com/problems/word-ladder/, in which I applied BFS type approach on an undirected graph.. For the given test case (attached below) I think we can achieve the transformation in a single step, by going from "a" - > "c" , wherein both the said words exist in the dictionary , and the resulting transformation requires minimum steps. Why is the answer then 2?

    Input: "a", "c", ["a","b","c"]

    Output: 1

    Expected: 2


  • 0
    S

    Yes, it might a little bit confused.

    But you can assume that the answer is always more than 2, except 0, which means there is no available transformation. Since no matter the transformation is, start word and end word will be in it.

    For this test case, the transformation path would be 'a'->'b', length is 2. If some transformation is like 'a'->'b'->'c', the answer would be 3.


Log in to reply
 

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