Please help me in PERMPAL

please check for any errors in the below code for PERMPAL question also and clarify.

@ajinkyabedekar I am not able to understand by reading your code what you intended to do. Could you please help in understanding the code by providing your approach to the problem and how you implemented it.