Skip to content

Instantly share code, notes, and snippets.

View kevinahn7's full-sized avatar

Kevin Ahn kevinahn7

View GitHub Profile
function pathToX(root, x) {
if (root === null) {
return null;
}
if (root.value === x) {
return [x];
}
let leftPath = pathToX(root.left, x);
if (leftPath !== null) {
// function fullyContains(first: Array, second: Array): boolean;
//
// given two **already sorted** arrays with unique elements,
// first and second, return true if the first array contains
// all the elements found in the second array
//
// fullyContains([1, 2, 3], [1, 2, 3]) => true
// fullyContains([1, 2, 3], [2, 3]) => true
// fullyContains([1, 2, 3], [4]) => false
// fullyContains([], []) => true
['ab', 'c', 'd', 'ba', 'd'] => [['ab', 'ba'], ['c'], ['d', 'd']
function countAnagrams(stringArray) {
let newArray = [];
for (let i = 0; i < stringArray.length; i++) {
let dontRunLoop = false;
let currentString = stringArray[i];
for (let j = 0; j < newArray.length; j++) {
// For a matrix of 0s and you have to find the number of 1s
0001000
0011100
0110000
1110000
0100000
function getRegionSize(matrix, row, column) {
function getAllPermutations(string) {
let results = [];
if (string.length === 1) {
results.push(string);
return results;
}
for (let i = 0; i < string.length; i++) {
let firstChar = string[i];
function checkForLoopage(node) {
if (node === null) return false;
let fast = node.next;
let slow = node;
while (fast !== null && fast.next !== null) {
if (fast === slow) return true;
else {
fast = fast.next.next;
function reverse(node) {
if (node === null) {
return;
} else {
reverse(node.left);
reverse(node.right(;
}
let temp = node.left;
node.left = node.right;
https://adventofcode.com/2018/day/3
#1 @ 338,764: 20x24
#2 @ 80,667: 12x26
#3 @ 625,36: 17x22
#4 @ 196,235: 25x13
#5 @ 610,700: 25x21
#6 @ 590,831: 20x13
#7 @ 253,201: 29x22
function makeToString(integer) {
let string = "";
let numbers = {
0: "0",
1: "1",
2: "2",
3: "3",
4: "4",
5: "5",
6: "6",