WHY -1 is also coming in my o/p. my o/p{1 2 4 -1} expected o/p {1 2 4}

private void leftView(Node root) {
if(root == null)
return;

   LinkedList<Node> que = new  LinkedList<>();
   que.addLast(root);
   while(que.size() > 0){
	
	   System.out.print(que.getFirst().data + " ");
	   int size = que.size();
	   while(size-- != 0){
		   Node dn = que.removeFirst();
		   if(dn.left != null){
			   que.addLast(dn.left);
		   }

		      if(dn.right != null){
			   que.addLast(dn.right);
			  }
	   }
   }

}

CODE : https://ide.codingblocks.com/s/612298

Hey @ayush_r18,
In this problem, -1 is denoting null.
So, instead of making this comparison:

You should use

Here’s your updated code : https://ide.codingblocks.com/s/613546

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.