Skip to content

Instantly share code, notes, and snippets.

View j-quelly's full-sized avatar

Jamie Kelly j-quelly

View GitHub Profile
@j-quelly
j-quelly / countClouds.js
Created August 13, 2019 18:20
count clouds
function sweepClouds({ skyMap, y, x }) {
if (!skyMap[y]) {
return;
}
if (!skyMap[y][x]) {
return;
}
if (skyMap[y][x] === '1') {
class Node:
def __init__(self, value):
self.value = value
self.next = None
class Queue:
def __init__(self):
self.head = None
@j-quelly
j-quelly / queue.js
Last active February 17, 2019 04:24
// files to queue
let filesToProcess = [
'file1',
'file2',
'file3',
'file4',
'file5',
'file6',
'file7',
'file8',
function get(object, prop, notFound = undefined) {
if (object) {
if (prop in object) {
return object[prop];
}
}
return notFound;
}
function depthFirst(tree, order, isNotSymmetrical, callback) {
@j-quelly
j-quelly / swapLexOrder.js
Created January 10, 2019 03:42
Given a string str and array of pairs that indicates which indices in the string can be swapped, return the lexicographically largest string that results from doing the allowed swaps. You can swap indices any number of times.
function quickSort(nums) {
// base case
if (nums.length <= 1) {
return nums;
}
// grab a pivot
const pivot = nums.pop();
// divide
@j-quelly
j-quelly / groupingDishes.js
Created January 6, 2019 01:28
You have a list of dishes. Each dish is associated with a list of ingredients used to prepare it. You want to group the dishes by ingredients, so that for each ingredient you'll be able to find all the dishes that contain it (if there are at least 2 such dishes). Return an array where each element is a list with the first element equal to the na…
function groupingDishes(dishes) {
const ingredientMap = dishes.reduce((map, dish) => {
dish.slice(1).forEach((ingredient) => {
if (!map[ingredient]) {
map[ingredient] = [dish[0]];
} else {
// if happens more than once it should be an ingredient
map[ingredient].push(dish[0]);
}
});
@j-quelly
j-quelly / rearrangeLastN.js
Last active January 6, 2019 00:53
Note: Try to solve this task in O(list size) time using O(1) additional space, since this is what you'll be asked during an interview. Given a singly linked list of integers l and a non-negative integer n, move the last n list nodes to the beginning of the linked list.
// Definition for singly-linked list:
// function ListNode(x) {
// this.value = x;
// this.next = null;
// }
//
function getArryFromList(l) {
let current = l;
const results = [];
while(current) {
// Definition for singly-linked list:
// function ListNode(x) {
// this.value = x;
// this.next = null;
// }
//
function reverseNodesInKGroups(l, k) {
let temp = k;
let current = l;
const results = [];
// Definition for singly-linked list:
// function ListNode(x) {
// this.value = x;
// this.next = null;
// }
//
function mergeTwoLinkedLists(l1, l2) {
const list = [];
let left = l1;
let right = l2;
// Definition for singly-linked list:
// function ListNode(x) {
// this.value = x;
// this.next = null;
// }
//
function getNumber(list) {
let current = list;
let num = [];