Had a screening interview for Meta a few days back.
They asked:
- Kth largest element in the array.
Provided MinHeap solution.
- Subarray sum equals k.
I was able to give cumulative sum solution
Result: reject
I guess the interviewer was looking for the most optimized solution.
(Quick Select for Q1 and using HashMap for Q2)
Follow up questions:
- Can you dry run your code for given example?
- How would you test your code? (My answer: check for boundary cases like empty array, null values, invalid chars in integer array)