Google Interview Question for Java Developers


Country: United States




Comment hidden because of low score. Click to expand.
0
of 0 vote

public boolean inordersEqual(List<TreeNode> roots) {
	Set<String> inorders = new HashSet<>();
	for (TreeNode root : roots) {
		inorders.add(traverseInorder(root);
	}
	return inorders.size() == 1;
}

- Anonymous February 14, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

A simple solution is to save in-order tree walk of one of the trees on an array, then run the algorithm on the other trees and compare it with the array. If you do not allowed to use external memory, you should run the in-order tree walk on two trees at the same time. To do this you need to jump from in-order-tree-walk1 to in-order-tree-walk2 whenever a new node is printed in the in-order-tree-walk1 and compare it with the printed node in the in-order-tree-walk2. Inside a for loop do this process for the first tree and all other n-1 trees.
The point of the problem in my opinion is to see if you can manage multiple recursion (A recursion that includes more than one function) or not.

- nooreddin February 21, 2018 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

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.

Learn More

Resume Review

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.

Learn More

Mock Interviews

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.

Learn More