Implement BFS shortest paths with reconstruction | MathWorks Interview Question