EFI Interview Question for Software Engineer / Developers

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

you could use a hash table to find common elements in o(n).

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

You could qualify your answer by saying Hash table vs Array depending on target platform and hardware. Both have O(1) lookup but vary in computational overhead. Hash table would be good for a device w/ little mem. Array is good for a device with a lot of mem.

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

I believe the solution the interviewers expect is the algo. They are not interested in which collections object you will be using.

The soultion should be: (lets say the first array has m elements and the second array has n elements. And x are the repeatitions in the first array of m elements)

Step 1: to remove all the duplicates from the first array by a linear search. it will be m*m and crete a new set containing m-x elements.

Step 2: now again perform linear search for each element of m-x elements array on the second array. and break the loop when the identical value is found. So the time taken is (m-x) * logn

So total time taken = m*m + (m-x) * logn

If there is a optimised solution please let me know.

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

In step 1, how can you remove those repetitions without looking at array 2. It is supposed to remove common elements.

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

You need to construct a Hash table of one of the arrays(I prefer the smaller one) . Then use to second array to hash into the table to see if they already exist. Solution is O(n).
Binary tree can be an answer but I would suggest an AVL tree rather than just a Binary tree as AVL is balanced and search is almost always lg n but this ofcourse involves additional operations for balancing.

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

sort both arrays by quicksort.it will take 2O(nlogn) time to sort.
Now number to number match both arrays.for eg.
let after sorting
a=1,2,4,4,6,8
b=2,3,4,5,7
so now match like this..
1!=2 and 1<2
next element frm a
2=2 match
2!= 3 and 2<3
next element frm a.
here length of a and b can be compared to get better result.

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

simplest solution.. since no efficency thing is asked .. remove duplicates in one array & do linear search with the other array removing any duplicates

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

since there was no efficiency thing mentioned.....simply merge the two arrays and then add it to a hash set.

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.