MathWorks interview question

BFS and String Manipulation.