Connect the nodes of same level

my whole code is correct i just want to know how to write printFunc for final output. see my code once u will understand what i am trying to say and sir i also want to optimize my code bcz it is getting me TLE error on leetcode… how can i optimize it… help me with pseudocode or any hint would be appreciate

Hey @amaaanahmedkhan987 please share link of leetcode problem that you are solving.

Tell me one thing, why do you want to make a print function. You just have to return a node and leetcode’s compiler will print it itself.

Just construct a linked list In which you are storing elements like this 1,#,2,3,#,4,5,6,7,# and return head of that list.
Take this for reference, it’s the same logic you have applied

i want print function for hackerblocks not for leetcode bcz we also have to print output

I wasn’t unaware that you wanted to submit it on hacker blocks.
Take this test case example
Input
10 3 5 4 1 -1 2 -1 -1 -1 -1 -1 -1
Output
-1 5 -1 1 2 -1
Print the next right node of all the nodes in a level order manner.

Rest i am also not sure as the format is not understandable. Moreover if it’s still not clear then You can reask your doubt some experienced TA will be assigned to you

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.