It seems to run fine in most cases

why is it giving TLE in some cases?

Hi @vipulch
refer this https://ide.codingblocks.com/s/626358

youve just posted your answer here, can you tell me why mine didnt work?

ur code is failing on sample test case only… u have to print nodes in sorted order… and if no node is present then print 0… for that u will have to use a vector/array only…

Hi, it is clear… shall I mark it as resolved??

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.