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(val) { | |
this.value = val; | |
this.left = null; | |
this.right = null; | |
} | |
} | |
let nodes = [ | |
new Node('a'), //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
'use strict' | |
var num_list_1 = [3, 4, 2, 3, 1, 5]; | |
var num_list_2 = [3, 1, 2, 2]; | |
var num_list_3 = [4, 3, 1, 1, 4]; | |
function find_duplicate(num_list) { | |
// initializing | |
var slowIndex = num_list.length - 1; | |
var fastIndex = num_list.length - 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
'use strict' | |
// pigeon hole theory | |
// number range 1 - n | |
// array length n + 1 | |
const num_list = [10, 2, 4, 3, 2, 5, 6, 9, 8, 7, 1]; | |
const num_list2 = [10, 2, 4, 3, 5, 6, 9, 8, 7, 1, 8]; | |
function findDuplicate(num_list) { |
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 TreeNode(value) { | |
this.value = value; | |
this.left = null; | |
this.right = null; | |
} | |
var root = new TreeNode(15); | |
root.left = new TreeNode(7); | |
root.right = new TreeNode(26); | |
root.left.left = new TreeNode(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 Pair(key, value) { | |
this.key = key; | |
this.value = value; | |
this.next = null; | |
} | |
function HashMap(size) { | |
size = size || 35; | |
var storage = new Array(35); |
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 CakeType(weight, value) { | |
this.weight = weight; | |
this.value = value; | |
} | |
var cakeTypes = [ | |
new CakeType(7, 160), | |
new CakeType(3, 90), | |
new CakeType(2, 15), | |
]; |
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 CakeType(weight, value) { | |
this.weight = weight; | |
this.value = value; | |
} | |
var cakeTypes = [ | |
new CakeType(7, 160), | |
new CakeType(3, 90), | |
new CakeType(2, 15), | |
]; |
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 Queue() { | |
var inStack = []; | |
var outStack = []; | |
this.enqueue = function(num) { | |
inStack.push(num); | |
} | |
this.dequeue = function() { | |
if (outStack.length > 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
var sorted_lists = [ | |
[3, 4, 6, 10, 11, 15], | |
[1, 5, 8, 12, 14, 19], | |
[2, 7, 9, 13, 16, 17, 18], | |
[20, 22, 23, 25] | |
]; | |
function mergeSortedArrays(sortedLists) { | |
var pointers = new Array(sortedLists.length); |
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 Node(val) { | |
this.value = val; | |
this.left = null; | |
this.right = null; | |
} | |
var numList = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; | |
function buildTree(list, start, end) { | |
if (start > end) { |
NewerOlder