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
static httpBuildQuery(data = {}) { | |
return Object.keys(data) | |
.map((k) => { | |
return encodeURIComponent(k) + '=' + encodeURIComponent(data[k]); | |
}) | |
.join('&'); | |
} |
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 luckBalance(k, contests) { | |
return contests.sort(([a,x],[b,y])=>y-x || b-a) | |
.reduce((memo,[l,t],key)=>{ | |
memo += t===1 && key<k? l: t===1 && key>=k?-l:l | |
return memo; | |
},0) | |
} |
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 getMinimumCost(k, c) { | |
return c.sort((a,b)=>b-a).reduce((memo,value,key)=>{ | |
const i=Math.floor(key/k); | |
memo+=(i+1)*value; | |
return memo; | |
},0) | |
} |
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 maxMin(k, arr) { | |
const sortArray=arr.sort((a,b)=>a-b); | |
const lengthArray=sortArray.length; | |
let unfairValue=Infinity; | |
for(let i=0; i<=lengthArray-k; i++) | |
{ | |
const groupArray=sortArray.slice(i,i+k); | |
const value=groupArray[k-1]-groupArray[0]; | |
unfairValue=unfairValue<value?unfairValue:value; |
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 sockMerchant(n, ar) { | |
const pairs={}; | |
return ar.reduce((memo,value)=>{ | |
if(pairs.hasOwnProperty(value)) | |
{ | |
pairs[value]=pairs[value]+1; | |
memo+=pairs[value]%2===0?1:0 | |
}else{ | |
pairs[value]=1 | |
} |
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 countingValleys(n, s) { | |
let level=0,vally=0; | |
for(let i=0; i<=n; i++) | |
{ | |
if(s[i]==='D') | |
{ | |
--level | |
}else if(s[i]==='U'){ | |
if(++level===0) vally++; | |
} |
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
/** | |
* Descending based Priority Queue with less complexity | |
**/ | |
class PriorityQueue { | |
constructor() { | |
this.queue = []; | |
} | |
enqueue(element) { | |
this.queue=[...this.queue, element].sort(([ v, p ], [ v1, p1 ]) => p1 - p); |
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
/*stack solutions*/ | |
function isBalanced(s) { | |
const brackets={'{':'}','(':')','[':']'}; | |
const arr=s.split(''); | |
const stack=[]; | |
/* if the length is odd*/ | |
if(arr.length%2!==0) return 'NO'; | |
for(let i=0; i<arr.length; i++) | |
{ |
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
class Node { | |
constructor(value) { | |
this.value = 0; | |
this.label = 0; | |
this.distance = -1; | |
this.visited = false; | |
this.edges = []; | |
} | |
addEdge(node) { | |
this.edges.push(node); |
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
/* | |
*/ | |
class Graph{ | |
constructor(n, cost_road,cost_lib) | |
{ | |
this.size=n; | |
this.costRoad=cost_road; | |
this.costLib=cost_lib; | |
this.adjancies={} | |
this.visited={}; |