Skip to content

Instantly share code, notes, and snippets.

View johntran's full-sized avatar
🌈
Make it last forever, FRIENDSHIP NEVER ENDS

johntran

🌈
Make it last forever, FRIENDSHIP NEVER ENDS
View GitHub Profile
@johntran
johntran / Refactoring.js
Created June 27, 2018 04:35
Programs are just generalized polynomials.
// AC + AD + BC + BD = (A+B)(C+D)
// Currently AC + AD + BC + BD
function intersect([low1, hi1], [low2, hi2]) {
if (low1 > low2) {
if (hi1 < hi2) {
return [low1, hi1];
} else {
return [low1, hi2];
}
@johntran
johntran / exponentialLaws.js
Created June 27, 2018 04:44
Programs are just generalized polynomials
// Exponential Laws
// B^(x+y) = B^x * B^y
// B^(x*2)
function addTimeOrTemp(x, isTime) {
if (isTime) {
this.time += x;
return this.time;
} else {
describe('Guest User Can Make Order Receipt', () => {
it('can visit app', () => {
return cy.visit('https://www.onehopewine.com/shop/wine/wine');
});
it('can add item', () => {
return cy
.get('#ProductScroll')
.find('.AddToCartButton')
.first()
.click()
@johntran
johntran / trees.md
Last active October 1, 2018 04:13
LA Big-O Problem Set: 2017 Sep 25

Trees 2018 Sep 26

christmas tree

Problem Set

Check if a tree is a BST

  • Given a binary tree, check if its a BST. A valid BST doesn't have to be complete or balanced. Duplicate elements are not allowed in a BST.
  • Solution runtime: O(N) time where N is the number of nodes in the tree.
/**
*
* (1) isBST
* Go down the tree, comparing the value of the left and right nodes to root node.
* Then call a recursive function that narrows:
* - the maximum value for left tree
* - the minimum value for the right tree
* A tree is BST if
* - the current value is within those limitations
* - the left node is less than the current value

Dynamic Programming 2018 Oct 2

dp

Problem Set

Fibonacci

  • I want to find a Fibonacci sequence for an integer.
  • The Fibonacci for n is the sum of the Fibonaccis of the previous two numbers.
  • Fibonacci(n) = Fibonacci(n-1) + Fibonacci(n-2)

Whiteboarding 2018 Oct 23

typing

Problem Set

Find the best times to buy and sell given an array of stock prices

The cost of a stock on each day is given in an array, find the single highest profit that you can make by buying and selling in those days. For example, if the given array is {100, 180, 260, 310, 40, 535, 695}, the maximum profit can earned by buying on day 4 and sell on day 6. It would return 694-40. If the given array of prices is sorted in decreasing order, return the lowest loss.