Monotype Interview Question for Senior Software Development Engineers


Country: India
Interview Type: In-Person




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

check question?id=14952616

- naren December 05, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1. Create two iterators. Start a while loop looping through one of the iterators
2. increment the second iterator with each loop
3. If iterator1.next() == iterator2.next(), return that node.

- Anonymous December 05, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Your solution is O(n^2), think of O(n) solution.

- Guest December 08, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Put the contents of the smaller list into a HashSet and then iterate over the larger list until you find an object that is contained in the HashSet.

public static T getFirstCommonElement(List<T> list1, List<T> list2){
	List<T> smallList, largeList;
	if(list1.size() < list2.size()){
		smallList = list1;
		largeList = list2;
	}
	else{
		smallList = list2;
		largeList = list1;
	}

	HashSet<T> set = new HashSet<T>(smallList.size());
	set.addAll(smallList);

	for(T obj : largeList){
		if(set.contains(obj)){
			return obj;
		}
	}
	return null;
}

- zortlord December 10, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

are you assuming that small list and large list will have numbers in the same order after the first common node. I am not getting the question which asked us to find if they merge, meaning they have same ordered numbers in the list after a common node?

- Chinmay December 10, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

if the list can be traversed both forwards and backwards... that should be enough of a hint to find out if they're merged in O(1) :)

- Aaa December 12, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Let two list be L1 and L2. Count the number of nodes in list L1, lets say its c1. Then reverse list L2( you can do it using three pointers). Again count number of nodes in L1, lets says count now is c2.

if(c1 == c2)
Lists do not merge
else
(c1 - c2) common nodes between L1 and L2.

All the operations are O(N) so overall time complexity is O(N).

- nikhils.codecracker January 25, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Let two list be L1 and L2. Count the number of nodes in list L1, lets say its c1. Then reverse list L2( you can do it using three pointers). Again count number of nodes in L1, lets says count now is c2.

if(c1 == c2)
Lists do not merge
else
(c1 - c2) common nodes between L1 and L2.

All the operations are O(N) so overall time complexity is O(N).

- nikhils.codecracker January 25, 2015 | 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