## 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

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.

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

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

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());

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

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

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?

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) :)

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).

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).

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.

### 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.