This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function peak(arr) { | |
let leftsum = 0; | |
let rightsum = 0; | |
mid = Math.floor(arr.length / 2) | |
const hash = {} | |
while (mid > 0) { | |
leftsum = 0; | |
rightsum = 0; | |
for (x = mid - 1; x >= 0; x--) { | |
leftsum += arr[x] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* A priority queue stores a list of items but each can have a numeric priority value. | |
* Items with a higher priority are dequeued before items with a lower priority. | |
* Implemented as a hash of arrays where the hash keys are priority values. | |
*/ | |
function PriorityQueue() { //removed unused size variable | |
this.store = {}; // keys are priorities, values are arrays of elements | |
this.count = 0; | |
// either keep all the functions inside Priority Queue or outside. | |
// only keep properties of object inside constructor and define the Object properties on the prototype function so that its easy to read and follow the code. |
NewerOlder