This file contains 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
Delete local and remote branches | |
git branch -D <branchName> | |
git push origin :<branchName> | |
Push local branch to remote | |
git push origin <branchName> | |
Hard Reset | |
git fetch --all | |
git reset --hard origin/<branchName> |
This file contains 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
function getPurmutations(s: string, b: string) { | |
if (s.length > b.length) { | |
return 0 | |
} | |
const desiredChars = {} | |
const possiblePurmutations = {} // contain the starting index for the purmutation, and the remaining characters that need to be found | |
let purmutationsCount = 0 | |
for (const char of s) { |
This file contains 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
const array1 = [13, 27, 35, 40, 49, 55, 59] | |
const array2 = [17, 35, 39, 40, 55, 58, 60] | |
// Goal: Get common entries of two arrays, both arrays are the same length and consist of all unique elements. | |
// Best concievable run time = O(A) || O(B) | |
function getCommonEntries(arr1: number[], arr2: number[]) { | |
let index1 = 0 | |
let index2 = 0 | |
const arraySize = arr1.length |
This file contains 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
// Can make an insert, remove, replace | |
// find out if two strings are one or zero edits away from each others | |
function hasOneOrLessEdits(str1: string, str2: string): boolean { | |
// Best case is O(N) since the string should be the same size, if they are not then we know they the answer is false | |
debugger | |
if (Math.abs(str1.length - str2.length) > 1) { | |
return false | |
} | |
let countEdits = 0 |
This file contains 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
/* | |
Assume you have a method called isSubstring() which checks if one word is a subtring of another. | |
Given two strings, s1 and s2, write code to check if s2 is a rotation of s1 using only one call to | |
isSubstring(). Eg "waterbottle is a rotation of erbottlewat" | |
*/ | |
function checkSubstr(s1: string, s2: string): boolean { | |
if (s1.length !== s2.length) { | |
return false | |
} | |
const rotationByIndex = new Map() |
This file contains 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
/* | |
Rotate a NxN matrix by 90 degrees in place where each pixel in the matrix is 4 bytes. | |
*/ | |
/* example call: | |
rotateMatrix(sanitizeData([ | |
[1,2,3], | |
[8,9,4], | |
[7,6,5] | |
])) |
This file contains 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
// If an element in an NxM matrix is zero, then every element in that row and column should be zero | |
function zeroOutMatrix(m: number[][]): number[][] { | |
const zeroedRows = new Map() | |
const zeroedCols = new Map() | |
for (let r = 0; r < m.length; ++r) { | |
for (let c = 0; c < m[r].length; c++){ | |
if (m[r][c] === 0) { | |
zeroedCols.set(c, true) | |
zeroedRows.set(r, true) |
This file contains 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
function deleteDuplicates(head: Node): Node { | |
const occurredVals = new Map() | |
let node = head | |
occurredVals.set(node.data, true) | |
while (node.next != null) { | |
if (occurredVals.get(node.next.data) === true) { | |
node.next = node.next.next | |
} else { | |
occurredVals.set(node.next.data, true) |
This file contains 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
function returnKthToLast(head: Node, k: number): Node | null { | |
let delta = 0 | |
let node = head | |
while (delta < k) { | |
node = node.next | |
++delta | |
if (!node) { | |
return null |
This file contains 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
function deleteSomeNode(node: Node) { | |
if (!node) { | |
return | |
} | |
if (!node.next) { | |
node = undefined | |
} | |
if (node.next) { |
OlderNewer