How to solve CHEFAFD ?

Can someone explain how to solve CHEFAFD ? I can’t think of anything other than brute force for this.

Link : CodeChef: Practical coding for everyone

2 Likes