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
| --[[ | |
| ===================================================================== | |
| ==================== READ THIS BEFORE CONTINUING ==================== | |
| ===================================================================== | |
| ======== .-----. ======== | |
| ======== .----------------------. | === | ======== | |
| ======== |.-""""""""""""""""""-.| |-----| ======== | |
| ======== || || | === | ======== | |
| ======== || KICKSTART.NVIM || |-----| ======== |
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
| const main = () => { | |
| findExchangeRate([['USD', 'JPY', 110],['USD', 'AUD', 1.45],['JPY', 'GBP', 0.0070]], ['GBP', 'AUD'], 1) | |
| } | |
| const findExchangeRate = (rates, toFrom, value) => { | |
| const to = toFrom[1]; | |
| const from = toFrom[0]; | |
| // build rate graph record | |
| const ratesGraph = {} | |
| rates.map(rate => { |
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
| convert_currency = (rates, from, to) => { | |
| const conversions = {}; | |
| // 1.45 / (0.0070 * 110) | |
| for(let i=0; i<rates.length; i++) { | |
| if (!conversions[rates[i][0]]) { | |
| conversions[rates[i][0]] = {}; | |
| } | |
| conversions[rates[i][0]][rates[i][1]] = rates[i][2]; |
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 DisjoinedSets() { | |
| this.parent = []; | |
| this.rank = []; | |
| this.find = (val) => { | |
| if (this.parent[val] === val) { | |
| return val; | |
| } else { | |
| return this.find(this.parent[val]); | |
| } |
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
| const getMinimumMoves = (k, d, a) => | |
| { | |
| let MAX = 100000; | |
| let n = a.length | |
| // Stores the number of moves | |
| // required to obtain respective | |
| // values from the given array | |
| let v = Array(MAX).fill(0) | |
| for(let i = 0; i < v.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
| isDevisible = (s, t) => { | |
| let l = 0; | |
| let r = 0; | |
| let repStart = 0; | |
| while(l < s.length) { | |
| if (s[l] === t[r]) { | |
| l++; | |
| r++; | |
| } else if (t[r] === undefined) { |
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
| //C = 8; | |
| //F = [1,3,2,1]; | |
| //V = [0,1,2,3]; | |
| //https://open.kattis.com/problems/magicalcows | |
| const nf = (maxCowsOnFarm, farms, visits) => { | |
| const dp = []; | |
| const freq = {}; |
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
| items=[{v: 5, w: 10}, {v: 1, w: 1}, {v: 3, w: 4}] | |
| knp = (items, maxWeight)=>{ | |
| const dp = []; | |
| for(let i=0; i<=items.length; i++) { | |
| for(let w=0; w<=maxWeight; w++) { | |
| if(!dp[i]) dp[i] = []; | |
| dp[i][w] = 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
| items=[{v: 5, w: 10}, {v: 1, w: 1}, {v: 3, w: 4}] | |
| knp = (items, selected, maxWeight, val)=>{ | |
| if (maxWeight === 0) return [val, selected]; | |
| if (maxWeight < 0) return [0, selected]; | |
| if (!items.length) return [val, selected]; | |
| let last = items[items.length-1]; | |
| let including = knp(items.slice(0, -1), selected.concat(last), maxWeight - last.w, val+last.v); | |
| let notIncluding = knp(items.slice(0, -1), selected, maxWeight, val); |
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
| arr = [5, 2, 8, 6, 3, 6, 5, 5]; | |
| longestContinuesSubseq = (a) => { | |
| let t = Array(a.length).fill(1); | |
| for(let i=1; i<t.length; i++) { | |
| let smalerUntilI = []; | |
| for(let j=0; j<i; j++) { | |
| if (a[j] < a[i]) { | |
| smalerUntilI.push(t[j]); |
NewerOlder