Skip to content
RSS feed tkhwang on GitHub tkhwang on Twitter

Heap (Priority Queue) in javascript

✨ Leetcode

What are the environments for the programming languages? - Leetcode

Leetcode supports the following open source library as default.

For Priority Queue / Queue data structures,
you may use version 4.1 datastructures-js/priority-queue and datastructures-js/queue.
const minHeap = new MinPriorityQueue({ compare: (a, b) => a - b });
const maxHeap = new MaxPriorityQueue({ compare: (a, b) => b - a });

for (const num of nums) {
  minHeap.enqueue(num);
  maxHeap.enqueue(num);
}

while (maxHeap.size()) {
  const check = maxHeap.front();
  const max = maxHeap.dequeue();
}

while (minHeap.size()) {
  const check = minHeap.front();
  const min = minHeap.dequeue();
}

// methods
{
  min, max;
}
Heap.size();
{
  min, max;
}
Heap.isEmpty();
{
  min, max;
}
Heap.toArray();

✨ Implementation

...

πŸ—’οΈ Typical problems

List

πŸ“š References