Skip to content

Instantly share code, notes, and snippets.

Tommy Volk tvolk131

View GitHub Profile
View gist:e04913ca96ca143fb307ff978964647d
let russianDoll = (envelopes) => {
let maxCount = 0;
let indicesUsed = {};
let russianRecurse = (currentCount = 0, lastEnv = [-Infinity, -Infinity]) => {
if (currentCount > maxCount) {
maxCount = currentCount;
}
envelopes.forEach((envelope, index) => {
if (!indicesUsed[index] && envelope[0] > lastEnv[0] && envelope[1] > lastEnv[1]) {
indicesUsed[index] = true;
View gist:6cfd05ce4b48040299a20ffcbfee3810
class Cashinator {
constructor (initialAmount, taxPercentage, itemList) {
}
/**
* @return {*Current balance in the register}
*/
getBalance () {
}
View gist:dcb10b67eed2c74bddc7e3e4a6adf389
/**
* @param {number} capacity
*/
var LFUCache = function(capacity) {
this.nodes = {};
this.head = null;
this.tail = null;
this.size = 0;
this.capacity = capacity;
};
View gist:af6aeccf3e82e57ec002bf09aea8197a
let isVowel = (letter) => {
return (letter === 'a' || letter === 'e' || letter === 'i' || letter === 'o' || letter === 'u' || letter === 'A' || letter === 'E' || letter === 'I' || letter === 'O' || letter === 'U');
};
let vowelDoubler = (letters) => {
for (let i = 0; i < letters.length; i++) {
if (isVowel(letters[i])) {
letters.splice(i, 0, letters[i]);
i++;
}
View gist:ff815ef94b2cae2c3f877b0ba48efc81
/**
* @param {number[]} nums
* @return {number[]}
*/
var productExceptSelf = function(nums) {
let products = [];
let product = 1;
nums.forEach((num, i) => {
products[i] = product;
product *= num;
@tvolk131
tvolk131 / gist:b8df3566babbb7b60f35f43fb216f49f
Created Aug 10, 2017
Tree Path to Target Sum - HR Interview Prep
View gist:b8df3566babbb7b60f35f43fb216f49f
const hasPathToSum = function(node, targetSum) {
let hasSum = (sum, node) => {
sum += node.value;
if (node.children.length === 0) {
if (sum === targetSum) {
return true;
} else {
return false;
}
@tvolk131
tvolk131 / CashAmount
Created Aug 3, 2017
Hack Reactor CashAmount Interview Prep
View CashAmount
class CashAmount {
constructor (amount) {
this.pennyCount = 0;
this.addDoubleAmount(amount);
}
totalAsPennies () {
return this.pennyCount;
}
totalInPennies () {
View gist:b2224ce7f9750176624f4a932a5c1aae
const findLargestLevel = function(node) {
var getAllNodeSums = function(node, nodeSums) {
nodeSums.set(node, getNodeSum(node));
for(var i = 0; i < node.children.length; i++) {
getAllNodeSums(node.children[i], nodeSums);
}
}
var getNodeSum = function(node) {
You can’t perform that action at this time.