Implement topological sort from string input | Netflix Coding Question