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 pathToX(root, x) { | |
if (root === null) { | |
return null; | |
} | |
if (root.value === x) { | |
return [x]; | |
} | |
let leftPath = pathToX(root.left, x); | |
if (leftPath !== null) { |
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 fullyContains(first: Array, second: Array): boolean; | |
// | |
// given two **already sorted** arrays with unique elements, | |
// first and second, return true if the first array contains | |
// all the elements found in the second array | |
// | |
// fullyContains([1, 2, 3], [1, 2, 3]) => true | |
// fullyContains([1, 2, 3], [2, 3]) => true | |
// fullyContains([1, 2, 3], [4]) => false | |
// fullyContains([], []) => true |
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
['ab', 'c', 'd', 'ba', 'd'] => [['ab', 'ba'], ['c'], ['d', 'd'] | |
function countAnagrams(stringArray) { | |
let newArray = []; | |
for (let i = 0; i < stringArray.length; i++) { | |
let dontRunLoop = false; | |
let currentString = stringArray[i]; | |
for (let j = 0; j < newArray.length; j++) { |
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
input will be a graph | |
{ | |
v : ['A', 'B', 'C', 'D', E', 'F'], | |
e: { | |
'A': ['B'], | |
'B': ['A', 'C', 'D'], | |
'C': ['B', 'D'], | |
'D': ['B', 'C'], | |
'E': ['F'], | |
'F': ['E'] |
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 a matrix of 0s and you have to find the number of 1s | |
0001000 | |
0011100 | |
0110000 | |
1110000 | |
0100000 | |
function getRegionSize(matrix, row, column) { |
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 getAllPermutations(string) { | |
let results = []; | |
if (string.length === 1) { | |
results.push(string); | |
return results; | |
} | |
for (let i = 0; i < string.length; i++) { | |
let firstChar = string[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
function checkForLoopage(node) { | |
if (node === null) return false; | |
let fast = node.next; | |
let slow = node; | |
while (fast !== null && fast.next !== null) { | |
if (fast === slow) return true; | |
else { | |
fast = fast.next.next; |
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 reverse(node) { | |
if (node === null) { | |
return; | |
} else { | |
reverse(node.left); | |
reverse(node.right(; | |
} | |
let temp = node.left; | |
node.left = node.right; |
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
https://adventofcode.com/2018/day/3 | |
#1 @ 338,764: 20x24 | |
#2 @ 80,667: 12x26 | |
#3 @ 625,36: 17x22 | |
#4 @ 196,235: 25x13 | |
#5 @ 610,700: 25x21 | |
#6 @ 590,831: 20x13 | |
#7 @ 253,201: 29x22 |
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 makeToString(integer) { | |
let string = ""; | |
let numbers = { | |
0: "0", | |
1: "1", | |
2: "2", | |
3: "3", | |
4: "4", | |
5: "5", | |
6: "6", |
NewerOlder