- 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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]; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* (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 |
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.
https://gist.github.com/johntran - > graphs1030.md
https://gist.github.com/johntran - > algorithms20181106.md
https://gist.github.com/johntran - > 2018nov13.md