I participated in a phone screen interview for a Software Engineer position at Meta. The interview consisted of two coding questions, each requiring an optimal solution within a 40-minute timeframe. I began by asking clarifying questions to ensure a thorough understanding of the problem, including edge cases. I then presented a brute-force approach followed by optimal solutions, complete with time and space complexity analysis. I confirmed the optimality of my solutions with the interviewer. I coded both solutions within the allotted time and provided clear explanations of my thought process, including dry runs and edge case scenarios. After the interview, I verified my solutions on a coding platform, confirming their correctness and optimal performance. The only area for potential improvement was three lines of duplicated code in the second solution. I acknowledged this to the interviewer, explaining that with additional time, I could refactor to eliminate the duplication. No behavioral questions were asked. Following the coding portion, I had a brief five-minute Q&A session with the interviewer. Despite my belief that the interview went well, I received a rejection email. The feedback cited code duplication in the second question, specifically the three lines I had previously mentioned. I have extensive experience building large-scale systems and leading engineering teams. I found the rejection surprising, given my preparation and positive mock interview experiences. The provided code for the second question, which involved merging three sorted lists while avoiding duplicates using three pointers (without using a min-heap), is included below:
` private static final int LARGE_VALUE = Integer.MAX_VALUE;
public List<Integer> mergeThreeSortedListsAvoidingDuplicatesUsingThreePointers(int[] a, int[] b, int[] c) {
List<Integer> output = new ArrayList<>();
int lengthA = a.length, lengthB = b.length, lengthC = c.length;
int total = lengthA+lengthB+lengthC;
int pointerA = 0, pointerB = 0, pointerC = 0;
for( int i = 0; i < total; i++ ) {
int itemA = pointerA < lengthA ? a[pointerA] : LARGE_VALUE;
int itemB = pointerB < lengthB ? b[pointerB] : LARGE_VALUE;
int itemC = pointerC < lengthC ? c[pointerC] : LARGE_VALUE;
if ( itemA <= itemB && itemA <= itemC ) {
if ( output.size() == 0 || output.get(output.size()-1) != itemA ) { output.add(itemA); } // duplicate?
pointerA++;
} else if ( itemB <= itemA && itemB <= itemC ) {
if ( output.size() == 0 || output.get(output.size()-1) != itemB ) { output.add(itemB); } // duplicate?
pointerB++;
} else if ( itemC <= itemA && itemC <= itemB ) {
if ( output.size() == 0 || output.get(output.size()-1) != itemC ) { output.add(itemC); } // duplicate?
pointerC++;
}
}
return output;
}
`
An alternative solution to reduce code duplication is shown below: ` int itemToAdd = -1;
if ( itemA <= itemB && itemA <= itemC ) {
itemToAdd = itemA;
pointerA++;
} else if ( itemB <= itemA && itemB <= itemC ) {
itemToAdd = itemB;
pointerB++;
} else if ( itemC <= itemA && itemC <= itemB ) {
itemToAdd = itemC;
pointerC++;
}
// ensure duplicate items are not added to the output by looking at the last item
if ( output.size() == 0 || output.get(output.size()-1) != itemToAdd ) { output.add(itemToAdd); } // moved to the end to reduce duplication
`