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
/** | |
* Calculates the maximum borrowing power based on income and various parameters | |
* @param incomeAfterTax - Annual income after tax | |
* @param annualExpenses - Annual living expenses (default: 24000) | |
* @param baseRate - Base interest rate for the loan (default: 0.0619) | |
* @param bufferRate - Additional buffer rate added to base rate for stress testing (default: 0.038) | |
* @param loanPeriodYears - Duration of the loan in years (default: 30) | |
* @param marginPercentage - Percentage of income used as margin (default: 0.000) | |
* @param marginFloor - Minimum margin amount regardless of income (default: 7000) | |
* @param marginCeiling - Maximum margin amount regardless of income (default: 0) |
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
/* | |
https://leetcode.com/problems/step-by-step-directions-from-a-binary-tree-node-to-another/ | |
IDEA: | |
- If we find the lowest common ancestor of the two nodes we're looking for, then we just | |
need to find the path from the start to the LCA, and from the LCA to the target. | |
- Maintain two stacks; one for the start, and one for the end. | |
- The path from the LCA to the start node will just be some number of 'U's, because | |
the LCA must be equal to or above the start node (by definition). | |
- The path from the LCA to the end node will be some number of 'L's or 'R's. |
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
#convert SRID to _______ outputDirectory inputShapefileWithAdjacent .dbf, .prj, .shx files | |
ogr2ogr -t_srs EPSG:4326 ~/Desktop/london_boroughs greater_london_const_region.shpu | |
#convert to psql | |
# creating tables where necessary | |
# inputShapefileWithAdjacent .dbf, .prj, .shx files | |
# piping the output to this postgis database | |
shp2pgsql -c ~/Desktop/london_boroughs/greater_london_const_region.shp | psql -d os_boundaries | |
# BotsonGIS cheatsheet |
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
/* | |
Pure recursive approach. | |
Branching factor of, at worst, a.length. | |
Yields O(len(a)^len(a)), which is about has bad as it gets... | |
*/ | |
const stockWithKTransactionsRecursive = (k, a) => { | |
const maxProfit = (i, k) => { // on the ith day, with k transactions remaining | |
if(i <= 0) return 0; // if it's day 0, we can't make a profit since we need at least one previous day to buy on | |
if(k === 0) return 0; // if we have no transactions remaining, just return 0; |
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
type void struct{} | |
type g = map[string](map[string]float64) | |
type stringSet = map[string]void | |
var member void | |
func calcEquation(equations [][]string, values []float64, queries [][]string) []float64 { | |
// 1. Make a directed, weighted graph out of each equation | |
graph, seen := make(g), make(stringSet) | |
for i, vars := range equations { |
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
/* | |
IDEA: Iff: | |
- The robot is facing North after the instructions, AND | |
- The robot was displaced by any non-zero amount, THEN | |
the robot will hare off into the sunset. | |
Otherwise, the robot will loop endlessly. | |
Proof: Lots of drawing on square-ruled paper. | |
*/ |
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
func findMaximumXOR(nums []int) int { | |
result := 0 | |
root := trieNode{} | |
for _, num := range nums { | |
maxAgainstNum := root.maxAgainst(num) | |
if maxAgainstNum > result { | |
result = maxAgainstNum | |
} | |
root.insert(num) |
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
/** | |
* // Definition for a Node. | |
* function Node(val) { | |
* this.val = val; | |
* this.left = null; | |
* this.right = null; | |
* this.parent = null; | |
* }; | |
*/ |
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
/** | |
* @param {number[]} nums | |
* @return {number} | |
*/ | |
/* | |
IDEA: | |
- Do a prefix-multiply, i.e., a rolling product from left to | |
right. | |
- This strategy depends on the number of negative numbers in | |
the input. |
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
/** | |
* @param {string} secret | |
* @param {string} guess | |
* @return {string} | |
*/ | |
var getHint = function(secret, guess) { | |
let [bulls, cows] = [0, 0]; | |
const secretDigits = new Array(10).fill(0); | |
for(let i=0; i<secret.length; i++){ |
NewerOlder