Skip to content

Instantly share code, notes, and snippets.

@manzaloros
manzaloros / .bash_profile
Last active February 5, 2021 02:24
My .bash_profile
# 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:
@manzaloros
manzaloros / .vimrc
Last active January 31, 2021 03:32
My .vimrc
" 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>
@manzaloros
manzaloros / sdi-how-to-ask-for-help.md
Created February 1, 2021 15:03
sdi how to ask for help

How to ask for help

Completely refactor the question

  • The question must make sense to you before you ask it

Google and stack overflow, a lot!

  • Avoid being seen as a 'help vampire'

Go through entire debugger's question

  • This seems to be a hack reactor idea
array.sort((a,b) => a < b ? -1 : 1)
@manzaloros
manzaloros / monotonic-queue-translated.md
Created June 15, 2021 19:01
Translated description of LC862. Shortest Subarray with Sum at Least K explanation

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] &gt;= B[i] + K where j &gt; i.

@manzaloros
manzaloros / topoSort.js
Last active July 13, 2021 13:26
Topological sort using depth first search
// 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]) => {
@manzaloros
manzaloros / union-find-template.js
Created July 16, 2021 22:36
Union Find Template
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) => {
@manzaloros
manzaloros / string-stuff.js
Last active November 8, 2022 16:05
String Stuff
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)
@manzaloros
manzaloros / iterate-lowercase.js
Created July 24, 2021 18:27
Iterate over all lowercase letters
for (let i = 0; i < 26; i += 1) {
const currentLetter = String.charCodeFrom(i + 97);
}