Skip to content

Instantly share code, notes, and snippets.

View kevinwucodes's full-sized avatar

Kevin Wu kevinwucodes

View GitHub Profile
@kevinwucodes
kevinwucodes / sql.sql
Last active November 5, 2019 17:39
sql - recursive employee hierarchy pinpointing a direct manager (with hierarchical order)
--taken directly from https://blogs.msdn.microsoft.com/simonince/2007/10/17/hierarchies-with-common-table-expressions/
--order logic taken from https://stackoverflow.com/questions/32858774/how-to-order-rows-by-hierarchy
/*
Org chart
----------
matt (1)
kirk (2)
chris (3)
tom (4)
@kevinwucodes
kevinwucodes / readme.md
Last active September 12, 2019 18:31
common utilities cheatcheat

Common Utilities Cheatsheet

@kevinwucodes
kevinwucodes / sql.sql
Created April 8, 2019 17:50
SQL - learn (random)
select *
from (
values
(1, 1, 156.32, 1)
,(null, 2, 468.96, 1)
) s (r1, r2, amount, id)
select *
from (
values
@kevinwucodes
kevinwucodes / readme.md
Created February 11, 2019 01:31
daily coding problem #81: Given a mapping of digits to letters (as in a phone number), and a digit string, return all possible letters the number could represent

Daily Coding Problem: Problem #81

Good morning! Here's your coding interview problem for today.

This problem was asked by Yelp.

Given a mapping of digits to letters (as in a phone number), and a digit string, return all possible letters the number could represent. You can assume each valid number in the mapping is a single digit.

For example if {“2”: [“a”, “b”, “c”], 3: [“d”, “e”, “f”], …} then “23” should return [“ad”, “ae”, “af”, “bd”, “be”, “bf”, “cd”, “ce”, “cf"].

@kevinwucodes
kevinwucodes / readme.md
Last active August 2, 2023 10:06
daily coding problem #69: Given a list of integers, return the largest product that can be made by multiplying any three integers.

Good morning! Here's your coding interview problem for today.

This problem was asked by Facebook.

Given a list of integers, return the largest product that can be made by multiplying any three integers.

For example, if the list is [-10, -10, 5, 2], we should return 500, since that's -10 * -10 * 5.

You can assume the list has at least three integers.

@kevinwucodes
kevinwucodes / readme.md
Last active January 21, 2019 04:06
daily coding problem #65: Given a N by M matrix of numbers, print out the matrix in a clockwise spiral.

Good morning! Here's your coding interview problem for today.

This problem was asked by Amazon.

Given a N by M matrix of numbers, print out the matrix in a clockwise spiral.

For example, given the following matrix:

[[1,  2,  3,  4,  5],

[6, 7, 8, 9, 10],

@kevinwucodes
kevinwucodes / readme.md
Created January 20, 2019 02:55
daily coding problem #63: find word in a 2D matrix scanning left-to-right, top-to-bottom

Good morning! Here's your coding interview problem for today.

This problem was asked by Microsoft.

Given a 2D matrix of characters and a target word, write a function that returns whether the word can be found in the matrix by going left-to-right, or up-to-down.

For example, given the following matrix:

[['F', 'A', 'C', 'I'],

@kevinwucodes
kevinwucodes / readme.md
Last active July 18, 2022 19:05
daily coding problem #28: Given a sequence of words and an integer line length k, return a list of strings which represents each line, fully justified

Good morning! Here's your coding interview problem for today.

This problem was asked by Palantir.

Write an algorithm to justify text. Given a sequence of words and an integer line length k, return a list of strings which represents each line, fully justified.

More specifically, you should have as many words as possible in each line. There should be at least one space between each word. Pad extra spaces when necessary so that each line has exactly length k. Spaces should be distributed as equally as possible, with the extra spaces, if any, distributed starting from the left.

If you can only fit one word on a line, then you should pad the right-hand side with spaces.

@kevinwucodes
kevinwucodes / readme.md
Last active February 13, 2024 18:32
daily coding problem #33: Compute the running median of a sequence of numbers

Good morning! Here's your coding interview problem for today.

This problem was asked by Microsoft.

Compute the running median of a sequence of numbers. That is, given a stream of numbers, print out the median of the list so far on each new element.

Recall that the median of an even-numbered list is the average of the two middle numbers.

For example, given the sequence [2, 1, 5, 7, 2, 0, 5], your algorithm should print out:

@kevinwucodes
kevinwucodes / readme.md
Last active December 9, 2023 21:12
daily coding problem #29: run-length encoding

Good morning! Here's your coding interview problem for today.

This problem was asked by Amazon.

Run-length encoding is a fast and simple method of encoding strings. The basic idea is to represent repeated successive characters as a single count and character. For example, the string "AAAABBBCCDAA" would be encoded as "4A3B2C1D2A".

Implement run-length encoding and decoding. You can assume the string to be encoded have no digits and consists solely of alphabetic characters. You can assume the string to be decoded is valid.

function decode(input) {