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
/** | |
* 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
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
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 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 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 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
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
import React from 'react'; | |
import ExecutionEnvironment from 'exenv'; | |
/* | |
* Author: Md. Rakibulalam | |
* Dependencies : npm install --save exenv | |
* If you want to exclude render dom releated components from server side render | |
*/ | |
export default (WrappedComponent) => { | |
const hocComponent = ({ ...props }) => { |
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
for (var sum = 0, i = 0, j = 1, k = 2; 4e6 > j + k; i++) i = j + k, j = k, k = i, sum += 0 == i % 2 ? i : 0; | |
result: '4613730' |