It is giving me tle

@17manishms There are some mistakes in putting the brackets and at some places you have used the wrong variable i.e. due to typing error i think.
So i suggest to go through your code once again, and you can figure it out easily because the code is almost correct but there are some curly braces and variable issues like in first while loop you have used next<n conditions but the value of ‘next’ is not changed anywhere after that.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.