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 / functionHoisting.js
Created December 16, 2019 23:02
Function Hoisting: Assume that `foo` is the main function
export default function foo() {
return bar();
}
function bar() {
return baz();
}
function baz() {
return 42;
export default function useToggle(initial = false) {
const [open, setToggle] = useState(initial);
return {
open,
set: setToggle,
setOpen: () => setToggle(true),
setClose: () => setToggle(false),
reset: () => setToggle(initial),
toggle: () => setToggle(prev => !prev),
};

https://gist.github.com/johntran - > big2019Feb19.md

Algorithms 2019 02 19

systems

Problem Set

SumZero

Given an array of positive and negative numbers, find if there is a subarray (of size at-least one) with 0 sum and return the subarray.

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.

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)
/**
*
* (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