## Flipkart Interview Question for Software Engineer / Developers

• 0

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

If the sizes were not huge, we could have merged all 3 arrays into one and then done a linear scan to find numbers repeated thrice.
Here, maintain 3 pointers one for each list. If values at all 3 are same, increment commonCount. If not, increment the index of the list with the minimum value out of all 3. Keep doing this till all 3 pointers go out of range. Return commonCount

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

What if any file has duplicate order id? (A sorted list can have duplicates i believe)

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

Use Map/Reduce algorythm :)

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

well that would depend on the no. of orders :)
if you are getting only orders in order of hundreds then you dont need hadoop cluster to do the required job, a simple implementation of getting the intersection from 3 log files would do.

if log files are really big then map/reduce would help.

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

Step 1: Get the files in to the arrays
Step 2: Search the First array's element in second array and third array using binary search.
If exists in second and third arrays. return the order.
Step 3: Follow this step to the entire First array.

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

We need to take advantage of orders being sorted..

Metta's solution is best.. :)

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

Guys you can get a linear time algorithm by using modified merge. Using modified merge, find the common elements of first two arrays and store the result in fourth array. Again repeat the same procedure on third and fourth array. You get the answer.

By modified merge, I mean while merging select the common elements.

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

void modifiedMerge(int A[], int B[], int size1, int size2)
{
int i = 0;
int j= 0;
while(i<size1 && j<size2)
{
if(A[i]==B[j]) printf("%d ",A[i]);//you can store it in array
else if(A[i] < B[j]) i++;
else j++;
}
}

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

If you lyk the solution, plz. let me know :)

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

Note files are in sorted order and are huge, so in memory sort is ruled out.

Let all three files have 3 pointers if the current value of all the pointers is same, then the order is same in all files, now increment the pointers, always compare the pointer values until you reach the pointers in all three files with same value. Note increment the pointer which is lagging behind. This is a linear complexity algo.

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

This problem can be solved using Map Reduce.

Write three mapper classes which will read each file and retrieve each OrderId.
In the shuffle and Sort phase the data is segregated into block
The segregated blocks are passed to Reduce where Aggregation.

Correct me if any changes need to be done

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

@karthik- We should only compare the elements in array-3 which are present in array-2.

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

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

doing binary search is the good solution we are actually making use of the sorted order in this solution. @karthi :)

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.