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
//did not complete | |
/** | |
* @param {number[][]} envelopes | |
* @return {number} | |
*/ | |
var maxEnvelopes = function(envelopes) { | |
let max = 0; | |
let sortedByHeightEnvelopes = envelopes.sort((a,b)=>{return a[0] < b[0]}); | |
let recurseHeight = (currentHeight, remainingEnvelopes, currentCount) => { |
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 CashRegister { | |
constructor(csv, salesTax, startingBalance) { | |
this.balance = startingBalance; | |
this.transactions_report = []; | |
this.items_report = []; | |
this.currentTransaction = {}; | |
} | |
viewBalance () { | |
//return balance | |
} |
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 messageBus = {}; | |
class Channel{ | |
constructor() { | |
this.topicSubscriptionCache = {}; | |
} | |
publish(topic, payload) { | |
if (payload) { | |
//find array of callbacks for topic in cache | |
if(this.topicSubscriptionCache[topic]) { |
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
**/Constraints | |
The challenge in this problem is in meeting its (arbitrary) constraints: | |
Do not convert into strings or manipulate strings at all. | |
Do not create any other data structures. | |
In particular, don't instantiate a new array. | |
The big-O of the solution should be O(n). **/ | |
let vowelDoubler = (letters) => { |
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 productExceptSelf = function(nums) { | |
let zeroCount = 0; | |
let productWithoutZero = 1; | |
let product = nums.reduce((accum, num)=>{ | |
if(num === 0) {zeroCount++} | |
if(num !== 0) {productWithoutZero *= num} | |
return accum * num; | |
}, 1); | |
return nums.map((num, 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
var kthSmallest = function(root, k) { | |
let kSmallestElement = NaN; | |
let findLastKNodes = (node, isRightNode, parentCountFromLeftTree) => { | |
var nthElement = 1; | |
if(node.left) { | |
nthElement += findLastKNodes(node.left, isRightNode); | |
} | |
if (node.right) { | |
findLastKNodes(node.right, true, nthElement); | |
nthElement += 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
class Tree { | |
constructor(name, val) { | |
this.value = val; | |
this.children = []; | |
this.name = name; | |
} | |
addChild(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 CashAmount{ | |
constructor(amount) { | |
this.value = amount; | |
} | |
//converts amount to pennies | |
totalInPennies() { | |
return this.value * 100; | |
} |
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 findLargestLevel = function(node) { | |
let currLevel = [node] | |
let i = 0; | |
let index = [[0, node.value]]; | |
while(currLevel.length > 0) { | |
nextLevel = []; | |
i++; | |
//function that moves currlevl children to nextlevel children | |
for(let parent = 0; parent < currLevel.length; parent++) { | |
//nextLevel.push(children) |
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 generate = function(numRows) { | |
var triangle = []; | |
var counter = 0; | |
while(counter < numRows){ | |
var lastRow = triangle[triangle.length - 1]; | |
var newRow = []; | |
if (!lastRow) {newRow.push(1); | |
} else { | |
lastRow.forEach(function(num, i){ | |
for(var j = i; j < i + 2; j++){ |
NewerOlder