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
| // Linear Space | |
| function houseRobber1(houses) { | |
| let max_gold = [] | |
| for(let i = 0; i < houses.length; i++) { | |
| let current = houses[i]; | |
| let prevMax = max_gold[i - 1] || 0; | |
| let twoBackMax = max_gold[i - 2] || 0; | |
| max_gold.push(Math.max(current + twoBackMax, prevMax)); |
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 nThFibonacci(n) { | |
| if(n <= 1) return 1 | |
| return nThFibonacci(n - 1) + nThFibonacci(n - 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 nThFibonacciTable(n) { | |
| let table = [1, 1] | |
| for (let i = 2; i <= n; i++) { | |
| let nextFib = table[i - 1] + table[i - 2] | |
| table.push(nextFib) | |
| } | |
| return table[n] | |
| } |
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
| let nthFib = (n) => n <= 1 ? 1 : nthFib(n - 1) + nthFib(n - 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 PowerSet(str) { | |
| let result = [] | |
| function constructSubSet(subSet, index) { | |
| if(index >= str.length) { | |
| result.push(subSet) | |
| return | |
| } | |
| constructSubSet(subSet, index + 1) | |
| constructSubSet(subSet + str[index], index + 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 addNode(graph, nodeToAdd) { | |
| if(graph[nodeToAdd] === undefined) { | |
| graph[nodeToAdd] = new Set() | |
| } | |
| return graph | |
| } | |
| function addConnection(graph, origin, destination) { | |
| addNode(graph, origin) |
OlderNewer