Implement topological sort from string input | Netflix Interview Question