Run time error in the solution

please correct the error


and comment

@Adhyayan
Will get back to you asap.

@Adhyayan
Can you please tell your approach in brief?