is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.
CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.
Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.
Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.
I'm using the following approach and it is giving result:
- devashish2008 March 26, 20171. read recursively till root.left is not null
2. print node data and if it has a right node then add it in a list
3. now read through the list
4. if it has no left right nodes then print data else call traverse method on this node again.
Please comment if this solution looks ok..
List<Node> queue = new ArrayList<Node>();
public void traverse(Node root)
{
if(root.left != null)
traverse(root.left);
System.out.print(root.data+" ");
if(root.right != null)
queue.add(root.right);
}
public void printqueue()
{
if(queue.size() == 0)
return;
if(queue.size() > 0)
{
Node t = queue.get(0);
if(t.left == null && t.right == null)
{ System.out.print(t.data);
queue.remove(0);
}
else {
traverse(t);
queue.remove(0);
}
printqueue();
}
}
public static void main(String args[])
{
Node n1 = new Node(2);
Node n2 = new Node(3);
Node n3 = new Node(4);
Node n4 = new Node(5);
Node n5 = new Node(7);
Node n6 = new Node(8);
Node n7 = new Node(6);
n1.left = n2;
n2.left = n4;
n2.right = n7;
n3.left = n5;
n3.right = n6;
n1.right = n3;
VerticalTree obj = new VerticalTree();
obj.traverse(n1);
obj.printqueue();
}