https://practice.geeksforgeeks.org/problems/connect-nodes-at-same-level/1-this was the hackerrank problem.they had given to complete the required function in editor below
https://ide.codingblocks.com/s/156275-this was the function of it ,but it was showing wrong .
what was the wrong in the code?
Count nodes at same level in tree
Errors In your code on https://ide.codingblocks.com/s/156275
- You have done j++ instead of ++j.
++j would first increment j and then return the value of j while j++ would first return the value of j and then increment it.
Example j = 5
j++ = returns 5 and increments j to 6
++j = increments j to 6 and then returns 6 - You have incremented j both in your first if statement and second if statement. While it should be only be incremented once for the left and right node, as they are on the same level.
- you have not defined the data type for it (iterator) in line 27
- Check my code on https://ide.codingblocks.com/s/156904 for necessary corrections
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.