Here’s the link to the problem: http://www.codechef.com/ACMKG14R/problems/ACM14KG3
I have built a graph having nodes a-z. and mapped each rule (a->b, b->c, etc) as edges of the graph.
Go through each character of both strings( say, character a and b) and check if both nodes a and b are connected using a depth-first-search.
I have got a lot of wrong answers during the contest. It might be due to few edge cases which I could miss or my approach could have been outright wrong.
Please help me figure it out.
Here’s my code: http://ideone.com/qyZW2D