Ad
  • Default User Avatar

    Hi. Unfortunately, your solution is incomplete. Consider this input:

    {0, 2, 13, 1}.

    Your program cannot find a solution, while it exists, e.g.:

    {0, 10, 20, 30, 31, 32, 33, 34, 24, 14, 4, 3, 2, 12, 13, 23, 22, 21, 11, 1}.

    Moreover, on this input:

    {53, 49, 38, 69}

    it returns a path of length 26:

    {53, 43, 44, 45, 46, 47, 48, 49, 39, 38, 37, 36, 35, 34, 33, 32, 42, 52, 62, 63, 64, 65, 66, 67, 68, 69},

    while there is a path of length 20:

    {53, 43, 33, 23, 24, 25, 26, 27, 28, 29, 39, 49, 48, 38, 37, 47, 57, 67, 68, 69}.