Explore Library
Code QuizAdvanced

Reconstructing Path From Parents

Find the mistake when rebuilding a path by following parent pointers.

Codejavascript
function reconstructPath(parent, start, goal) {
  const path = [];
  let current = goal;
  while (current !== start) {
    path.push(current);
    current = parent[current];
  }
  // start was never added
  return path.reverse();
}

What is the bug in this path reconstruction?