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 BST = new BinarySearchTree() | |
BST.insertNode(8) | |
BST.insertNode(3) | |
BST.insertNode(10) | |
BST.insertNode(1) | |
BST.insertNode(6) | |
BST.insertNode(14) | |
BST.insertNode(4) | |
BST.insertNode(7) |
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
/** | |
* @param {string} s | |
* @return {number} | |
*/ | |
function lengthOfLongestSubstring (s) { | |
// Base cases | |
if (s.length <= 1) | |
return s.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 lengthOfLongestSubstring(s) { | |
if (s.length <= 1) | |
return s.length | |
let lookup = new Map() | |
let len = s.length | |
let max = 0 | |
let start = 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
function timeConvertor(time) { | |
var PM = time.match('PM') ? true : false | |
time = time.split(':') | |
var min = time[1] | |
if (PM) { | |
var hour = 12 + parseInt(time[0],10) | |
var sec = time[2].replace('PM', '') |
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 productPuzzle(data) { | |
var len = data.length | |
var left = new Array(len) | |
var right = new Array(len) | |
// prepare the left array | |
left[0] = 1 | |
for(let i = 1; i < len; 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 deleteTree (root) { | |
let temp = []; | |
while (temp) { | |
let node = temp.pop(); | |
if (node.left) temp.push(node.left); | |
if (node.right) temp.push(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
function deleteTree(node) { | |
if (node == NULL) return; | |
// Delete left, right subtrees | |
deleteTree(node.left); | |
deleteTree(node.right); | |
deleteNode(node); | |
} |
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 lengthofLargestSubarrayWithContinuousElements = (arr) => { | |
arr.sort() | |
let count = [] | |
let inLen = arr.length | |
let j = 0 | |
let initalCount = 1 | |
for (let i = 0; i < inLen; 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
const combine = (instr, outstr, index) => { | |
for (var i = index; i < instr.length; i++) { | |
// append the character | |
outstr = outstr.concat(instr.charAt(i)); | |
//print the result | |
console.log(outstr); | |
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 printNodesAtLevelK = (root, k) => { | |
if (root === NULL) { | |
return; | |
} | |
if (k === 0) { | |
console.log(`Node at Level k = ${root.data}`); | |
return; |