See my Code it has passed all test cases

See my Code it has passed all test cases.
it’s my approach, tell me it efficient code on the of complexity.

randomly i have come to an idea and I coded it.

surprisingly it has passed all test cases.

Once see it let me know also another way to solve it.

hello @deepak147852
this the most efficient approach for this problem in O(n).
u cannot reduce its time complexity furthur.

ok but i have an doubt.
in first iteration it will be print “\n”, then why it gave not any error

maybe output file contain empty first line.
check test file for this problem.

ok i will thank you so much