Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Model the problem as a graph problem. Add an edge from one character to another if you need to convert between them.
What if one character needs to be converted into more than one character?
There would be no solution. Thus, every node can have at most one outgoing edge.
How to process a linked list?
How to process a cycle?
What if there is a character with no outgoing edge? You can use it to break all cycles!