Please correct the code

hi @anuranjan8319918906 this approach is not generating outputs in the correct order. I am sharing an alternate approach, hope it helps. https://ide.codingblocks.com/s/301715