i dont know why my code is giving wrong answer , it works very fine on my machine , suggest test case here’s the link CodeChef: Practical coding for everyone
@ana1nd_9 it is quite difficult to understand ones code so i suggest you to have a look on my code i think then you will get where are you missing if even not then feel free to comment here again.