- The question must make sense to you before you ask it
- Avoid being seen as a 'help vampire'
- This seems to be a hack reactor idea
| # Aliases go in bashrc, customizing $PATH environment variable in bash_profile | |
| export PS1="___________________ | \w @ \h (\u) \n| => " | |
| export PS2="| => " | |
| # Aliases | |
| alias git-pull-all="find . -maxdepth 3 -name .git -type d | rev | cut -c 6- | rev | xargs -I {} git -C {} pull" | |
| # Update bashrc gist: https://gist.github.com/Ashwinning/35f530be96754e71a138af842d147cf8 | |
| alias gistbash="gist -u 9d5f4e7e2139d93e6011f529d06c8b38 ~/.bash_profile" |
| /* | |
| Kth Missing Positive Number | |
| Given an array arr of positive integers sorted in a strictly increasing order, and an integer k. | |
| Find the kth positive integer that is missing from this array. | |
| Example 1: |
| " leader as spacebar | |
| let mapleader = " " | |
| " Enable syntax highlighting | |
| syntax on | |
| " Search Highlighting | |
| set hlsearch | |
| " Mute highlighting | |
| nnoremap <silent> <C-l> :<C-u>nohlsearch<CR><C-l> |
| array.sort((a,b) => a < b ? -1 : 1) |
K is a sum you want to equal or be greater than in your window.
If you make an array of prefix sums, B, then you're looking for B[left] <= B[right] - K which means
that the sum of the window in your original array A has to be >= K.
Given B[right], you're looking for B[left] such that B[left] <= B[right] - K.
You need to use an increasing monotonic queue because with each new B[i], the larger elements on the
left won't work as candidates to make some future element B[j] >= B[i] + K where j > i.
| // Time: O(number of vertices) | |
| // Space: O(number of vertices) | |
| // Using the params for course scheduler: | |
| const findOrder = (numCourses, prerequisites) => { | |
| /* | |
| // Make graph adjacency list if needed: | |
| const graph = new Map(); | |
| prerequisites.forEach(([course, prerequisite]) => { |
| const parent = Array(rows * cols).fill(0).map((value, index) => index); | |
| const rank = Array(rows * cols).fill(0); | |
| const find = (i) => { | |
| if (parent[i] !== i) parent[i] = find(parent[i]); | |
| return parent[i]; | |
| }; | |
| const union = (x, y) => { |
| const replace = (word, index, replacement) => { | |
| return word.substr(0, index) + replacement + word.substr(index + replacement.length); | |
| } | |
| // another replace: | |
| const replaceChar = (index, newChar, string) => { | |
| if (index < string.length) return `${string.substring(0, index)}${newChar}${string.substring(index + 1)}` | |
| } | |
| const differByCase = (c1, c2) => Math.abs(c1.charCodeAt(0) - c2.charCodeAt(0) === 32) |
| for (let i = 0; i < 26; i += 1) { | |
| const currentLetter = String.charCodeFrom(i + 97); | |
| } |