Help me in solving MANYCHEF

Hi! I was solving question MANYCHEF and after reading it’s editorial where the question was solved while iterating from end to start of the string.I have done the same thing but i iterated from start to end.
I don’t know why my code is producing wrong answer. Please help. Why is my approach not working?

Here is link to question MANYCHEF Problem - CodeChef. Here is my solution CodeChef: Practical coding for everyone. Here is editorialist’s solution https://s3.amazonaws.com/codechef_shared/download/Solutions/COOK30/Setter/MANYCHEF.c

You are not printing the lexicographically smallest string. Here is the test case-

Input
1
F????F??
Your Output
FCHEFFAA
Expected Output
FACHEFAA

EDIT: Why the setters code runs backwards, is that, for any case with “???F” (i.e. 4 ‘?’ marks and a F), going backwards will automatically give “ACHEF” which is lexicographically smaller. But going from front will convert that “???” to chef and give a comparatively lexicographically bigger string.

1 Like

oh!! Right . Got it. Thank you very much for your help.

^^ You’re welcome dear.

Vijju123. You are like angel for beginner like us who couldn’t find fault in their code,and don’t have enough karma to ask questions. You just save us from our code nightmares. It’s is a great effort from your side. Keep answering!!!

1 Like