What is a shortest distance?

  • 1

    I don't understand the problem.
    If we have an array of words:

    ["practice", "makes", "perfect", "coding", "makes"]

    then "coding" and "practice" are 2 words apart ("makes" and "perfect"), not 3 like the problem states.
    Same as "makes" and "coding" are 1 word apart.

    What am I missing?

  • 2


    "coding" and "practice": abs(3-0) = 3
    "makes" and "coding": abs(4-3) = 1

    For the second case, you're probably looking at the wrong "makes", otherwise you'd say the distance is zero.

Log in to reply

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