Skip to content

Instantly share code, notes, and snippets.

View kanglicheng's full-sized avatar
🦜
LLMs ftw

Kang-Li (Stephen) Cheng kanglicheng

🦜
LLMs ftw
View GitHub Profile
@kanglicheng
kanglicheng / g320.cc
Created July 30, 2017 05:02 — forked from chrisirhc/g320.cc
Gild Puzzle 320: Gymnast Tower
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
struct comp {
bool operator() (const pair <int, int> i, const pair <int, int> j) const
{ return (i.first<j.first); }
@kanglicheng
kanglicheng / The Technical Interview Cheat Sheet.md
Created August 2, 2017 19:49 — forked from tsiege/The Technical Interview Cheat Sheet.md
This is my technical interview cheat sheet. Feel free to fork it or do whatever you want with it. PLEASE let me know if there are any errors or if anything crucial is missing. I will add more links soon.

Studying for a Tech Interview Sucks, so Here's a Cheat Sheet to Help

This list is meant to be a both a quick guide and reference for further research into these topics. It's basically a summary of that comp sci course you never took or forgot about, so there's no way it can cover everything in depth. It also will be available as a gist on Github for everyone to edit and add to.

Data Structure Basics

###Array ####Definition:

  • Stores data elements based on an sequential, most commonly 0 based, index.
  • Based on tuples from set theory.

Nesting Exercises

Basic Requirements

Review :

  • Retrieve the value "comeGetMe!" in each of the following data structures. Store them in variable(s)/data structure(s) of your choice.
var arrayA = ["hello", "world", "hack", "reactor", "comeGetMe!", "is", "awesome"];
var arrayB = [true, false, 100, 200, "comeGetMe!", "Batman", "Robin",];

Slides

  1. Write a function called average that takes an array of numbers as a parameter and returns the average of those numbers.

    After you write your function, you can test it using the above inputs to make sure that it behaves correctly.

  2. Write a function called min that finds the smallest number in an array of numbers.

Introduction to Higher-Order Functions

Lessons

Slides 1

Slides 2

Two Forms of Functions

#METHODS
# EASY
# Write a method that returns its argument converted to a string.
def my_to_s(arg)
return arg.to_s
end
# Write a method that returns its argument rounded to the nearest integer.
def my_round(num)
@kanglicheng
kanglicheng / linked_list.js
Created February 15, 2018 03:05
outco warmup
class Node {
constructor(id) {
this.id = id;
this.next = null;
}
}
let head = new Node(5);
// head.next = new Node(3);
// head.next.next = new Node(22);
# Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution(object):
def sumNumbers(self , root):
if not root:
@kanglicheng
kanglicheng / bruce.js
Last active April 6, 2018 01:31
practice with bruce
function findMaxHalfSum(arr) {
let max = 0;
let answer;
let hash = {};
for (let k = 0; k <= arr.length/2; k++) {
let leftHalf = arr.slice(0, k).reduce((a,b) => {return a+b}, 0);
let rightHalf = arr.slice(arr.length/2 + k).reduce((a,b) => {return a+b}, 0);
if (leftHalf + rightHalf > max) {
max = leftHalf + rightHalf;
answer = k;