Https://ide.codingblocks.com/s/595403

Your approach is not correct

Correct approach
use a map to store all nodes of a given level
Like This
level 1 -> nodes which are at level 1
level 2 -> nodes which are at level 2

Correct Code: