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 arr1 = [1, 3, 5, 7, 11, 17, 21]; | |
const arr2 = [-1, 0, 2, 3, 9, 11, 29]; | |
function intersection(arr1, arr2) { | |
let result = []; | |
let p1 = 0, p2 = 0; | |
while((p1 < arr1.length) && (p2 < arr2.length)) { | |
if (arr1[p1] == arr2[p2]) { |
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 stockSpan(array) { | |
let answer = []; | |
array.forEach((stock, index) => { | |
let count = 1; | |
for(let i = index - 1; (i >= 0) && (array[i] <= stock); i--) { | |
count++; | |
} |
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
// a + b * c + d | |
// a b c * + d + | |
// a + b * c + d | |
// a b c * + d + | |
function infixToPostfix(input) { |
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 BNode { | |
constructor (value) { | |
this.data = value; | |
this.left = null; | |
this.right = null; | |
} | |
search(values) { | |
let c = values.indexOf(this.data) >=0 ? 1 : 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
class BNode { | |
constructor (value) { | |
this.data = value; | |
this.left = null; | |
this.right = null; | |
} | |
search(values) { | |
let c = values.indexOf(this.data) >=0 ? 1 : 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
class Node { | |
constructor(value) { | |
this.value = value; | |
this.children = []; | |
} | |
add(child) { | |
this.children.push(child); | |
} |
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 = value; | |
this.children = []; | |
} | |
add(child) { | |
this.children.push(child); | |
} |
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 = value; | |
this.children = []; | |
} | |
add(child) { | |
this.children.push(child); | |
} |
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 TrieNode { | |
constructor (value, note="") { | |
this.value = value; | |
this.note = note; | |
this.children = new Array(26); | |
} | |
addChildNode (char, value=null) { | |
let index = char.charCodeAt(0) - 97; | |
this.children[index] = this.children[index] || new TrieNode(null, char); |
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 traverse(node, level=0) { | |
let indent = ""; | |
for (let i = 0; i < level; i++) { | |
indent += "*"; | |
} | |
console.log(`${indent}${node.nodeName}`); | |
if (node.childNodes.length > 0 ){ | |
node.childNodes.forEach(traverse, level+1); | |
} | |
} |