Hey interviewers, My language of choice for interviews JavaScript/TypeScript (let’s not go into the merits of the language plz). There are no built in min/max heap or Python-like `heapq.heappush` libraries and writing the whole implementation from scratch in an interview that says asks for the Kth largest element is quite the time sink. I’ve written my own Min/MaxHeap classes but because they’re fairly exhaustive they’re about 100 lines. Would you accept an answer that used copy/pasted code for that DS knowing that limitation of JS? Obviously I’d be writing the implementation to the main question myself/ad hoc during the interview. Just not the “basic” heap code. Thanks!
Just use import of npm package. Many languages require import of ds. Edit: Oh, I understand what you mean. If you are in coderpad and don't have one... Yes copy paste makes sense. Hackerrank will usually explicitly pre import using npm via yarn. Leetcode has the enabled npm package clearly labeled in their FAQ.
Kth largest is done using linear (worst case) algos.
With QuickSelect!? because that worst case is O(N^2). AVERAGE is O(N).
Introselect is one of them.
Depends if you need to run the solution. At Meta you’re unlikely to execute the code, so I’d just tell the interviewer that I’m assuming an implementation of the data structure exists and call it with what you imagine the API would look like.
Ok cool. That’s fair… although the Meta CoderPad did in fact run code during my tech screen 🤣 The interviewer was very surprised.
I just ask the interviewer I’m going to paste a heap class in here for the answer.