Skip to content

Instantly share code, notes, and snippets.

View manderly's full-sized avatar

Mandi Burley manderly

View GitHub Profile
@manderly
manderly / leetcode22-november22.ts
Created November 12, 2022 13:46
Leetcode #22 Generate Parenthesis updated November 2022
function nextPermutation(previousPermutations: string[][]): string[] {
const nextPermutationsLength = previousPermutations.length;
let nextPermutations = [];
for (let i = 0; i < nextPermutationsLength; i++) {
// each of the previous permutations becomes our "inner" permutations (array)
const innerPermutations = previousPermutations[i];
// calculate how many outer permutations we need based on where we are in the loop
const outerPermutationsLength = nextPermutationsLength - 1 - i;
@manderly
manderly / leetcode22.ts
Created August 23, 2021 15:29
Leetcode 22: Generate Parentheses
function generateParenthesis(n: number): string[] {
if (n === 1) { return ["()"]; }
let result = new Set<string>();
let previousCombos = generateParenthesis(n-1);
for (let i in previousCombos) {
let combo = previousCombos[i];
// wrap all previous entries in parens and put those in the set
@manderly
manderly / leetcode1101
Created August 1, 2021 16:58
Leetcode 1101 The Earliest Moment When Everyone Become Friends
function earliestAcq(logs: number[][], n: number): number {
logs.sort((a:number[], b:number[]) => {
return (a[0] - b[0]);
});
let mapOfSets = new Map();
// put every friend ID into its own individual set - O(n)
for (let i = 0; i < n; i++) {
let allPosts = [ {id: 123, name: "test post 1"},
{id: 456, name: "test post 2"}
];
let allReplies = [ {id: 1, replyTo: 123, name: 'reply 1', read: false},
{id: 2, replyTo: 123, name: 'reply 2', read: false},
{id: 3, replyTo: 456, name: 'reply 3', read: false}
];
// simulate a server response with 1s wait time
const getRepliesToPost = async (id: number) => {
// Closure example, sort of a companion to my JS example:
// https://repl.it/@MandiGrant/JSClosureExample
// combineNames is a function that returns a function.
var combineNames = (firstName) {
return (lastName) => firstName + ' ' + lastName;
};
/* If you call it like this,
@manderly
manderly / main.dart
Created February 18, 2020 19:45
Simple closure in Dart
// Closure example, sort of a companion to my JS example:
// https://repl.it/@MandiGrant/JSClosureExample
// combineNames is a function that returns a function.
var combineNames = (firstName) {
return (lastName) => firstName + ' ' + lastName;
};
void main() {
// Call it with a first name and then call *that* function with a last name
.amazin-product-box {
background-color:#ffffff;
color:#181c1a;
}
.amazin-product-box h3 {
margin:16px 0px;
}