Javascript and Priority Queues in coding interviews

Viewed 2884

One pretty big issue I've run into with JS is that it has no in built in priority queue unlike Java or Python (heapq).

I was just wondering in an interview situation, could you propose below solution and essentially 'pretend' that JS does indeed have a native Priority Queue structure:

https://leetcode.com/problems/merge-k-sorted-lists/discuss/10528/A-java-solution-based-on-Priority-Queue

Only asking because implementing a MinHeap is pretty complicated and not sure if I'll able to do it in a high stress environment.

1 Answers

I think it's fair to assume you can use an npm library to make JavaScript have capabilities comparable to other languages.

Google Closure Library has some useful structures implemented in JavaScript.

You can find goog.structs.PriorityQueue here.

Facebook similarly has fbjs.

You can find their Heap implementation here.

Related