Refactored code to store parent pointer when computing cost table and using that to quickly assemble solution.