16+ years of Software Engineering, 9+ years specializing in Android mobile apps.
Aspiring for E6 level roles.
So, this happened in Dec, 2020.
https://leetcode.com/discuss/interview-question/982506/facebook-phone-connected-components-in-graph
Reached out to the recruiter about the disconnect during the interview.
Recruiter suggested re-do another phone interview.
Zero-sum. Given array of interger, find all the combinations that sum is 0.
Input = [-1, 0,0, 0, 1, 2, 3, -2]
Output = (-1, 1), (0,0), (-2, 2) .
My solution -
Input-array is unsorted, duplicates allowed. Output can be Set of combinations ? Interviewer said Set as output is OK, any combinations of two elements only, in any order, must be unique only.
Brute-force of course, is O ( N ^ 2 ). I suggested using hash based visited data-structure, add space-complexity to save on time-complexity for optimal strategy. Is there a better most optimal solution ?
Interview environment is coder-pad. no execution. no test-runs, only plain text-editor for coding.
My solution was -
public Set<int[]> zeroSum ( int[] input ) {
Set<int[]> result = new HashSet<>();
// Return Empty Set for edge-case.
if ( input == null || input.length == 0 ) {
return result;
}
Set<Integer> visited = new HashSet<>();
for ( int value : input ) {
int target = 0 - value;
if ( visited.contains ( target ) ) {
visited.remove ( target );
result.add ( new int[] { value, target } ); //This. I should have been more careful with the follow-up.
} else {
visited.add ( value );
}
}
return result;
}Interviewer immediately appended 0 to example input-array = [ -1, 0,0, 0, 1, 2, 3, -2, 0 ]
I should definitely have taken a hint from that - instead, I reasoned that int[]{ 0, 0 } will be the same as another int[]{ 0 , 0 }, so hash-based Set will anyways not allow Duplicates.
I was so wrong. Such a silly mistake, so much experience and prep wasted!!!
There was a Merge Intervals problem as well, that I had solved correctly also.
I can't think of any other reason for the rejection, other than a silly mistake.
A test-run enabled, unlike coder-pad, should have been easier to spot the silly mistake, for an experienced engineer ?