I had a screening interview for a Software Engineer position at Meta.
The first question was similar to the problem "Next Greater Element II." I used a stack of pairs to store the index and element value. The interviewer then moved to the next question.
The second question was the problem "Vertical Order Traversal of a Binary Tree." I attempted to solve this using a pre-order traversal and maintaining the horizontal distance at each step. However, we also needed to maintain the vertical distance, so I proposed sorting after passing the vertical distance (from the root).
The interviewer asked if there was a better way, and I suggested a BFS approach where elements are inserted in a level order traversal, then sorted at the end by horizontal distance. He pointed out that a normal sort might alter the vertical order at the same horizontal distance. I had a misconception about how the sort function works with vector pairs; I thought it only considered the first element, but this was incorrect. I later discovered that I needed a custom comparator to sort only by the first element of the vector.
I was surprised by the rejection, as I believed I had solved both questions correctly and understood the correct approaches. The bug in the second question might have been the reason for rejection, but I received no feedback. My suggestion to others is to thoroughly understand the internal workings of all functions used. Although correcting the solution would have taken only a couple of minutes, the interviewer may not always be lenient.