getting WA for discount on crackers:kharagpur online

I am not able to identify where i am going wrong.Anyone please identify my mistake.This is my solution link textand here is the link for the prblm link text

You are checking only one mapping. For example, i have a string abc which is to be converted to def. What you are checking is if a->d mapping is given in the provided input or not. But there can be a case that, say a->m and m->d is given. The you can convert ‘a’ to ‘m’ first and then ‘m’ to ‘d’. As it is written that you can apply any mapping any number of times, ‘a’ can be converted to ‘d’ in this two step procedure even if a->d is not given. So your code fails.

P.S. :- You can solve this using graphs. You have to just check if there is a path from ‘a’ to ‘d’ or not.

Thank you:).Understood now

1 Like