Reputation: 1215
As per the supported runtime for different languages in https://support.leetcode.com/hc/en-us/articles/360011833974-What-are-the-environments-for-the-programming-languages-, I am using https://github.com/datastructures-js/priority-queue#fromarray as this is a function of the supported library.
However, when I use
const maxHeap = MaxPriorityQueue.fromArray(nums);
I get an error
Line 11 in solution.js
const maxHeap = MaxPriorityQueue.fromArray(nums);
^
TypeError: MaxPriorityQueue.fromArray is not a function
Line 11: Char 36 in solution.js (findKthLargest)
Line 34: Char 19 in solution.js (Object.<anonymous>)
Line 16: Char 8 in runner.js (Object.runner)
Line 23: Char 26 in solution.js (Object.<anonymous>)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:17:47
This is in accordance with the example provided https://github.com/datastructures-js/priority-queue#js-3
Upvotes: 3
Views: 430
Reputation: 68
I think it is kind of late to answer, but I'm going to answer anyway because I was facing the same issue.
The problem is that Leetcode uses version 4.1 of the library, and in this version, the fromArray
doesn't exist yet.
Sadly, from what I looked up, there's no alternative to that method.
Doc: https://www.npmjs.com/package/@datastructures-js/priority-queue/v/4.1.0
Upvotes: 3