Return true if ransomNote can be built from the letters of magazine, using each magazine letter at most once.
Count the magazine's letters once, then spend one count per note letter. A count going below zero means we ran out.
1function canConstruct(ransomNote: string, magazine: string): boolean {2const count = new Map<string, number>();3for (const c of magazine) count.set(c, (count.get(c) ?? 0) + 1);4for (const c of ransomNote) {5const left = (count.get(c) ?? 0) - 1;6if (left < 0) return false;7count.set(c, left);8}9return true;10}
Count the 4 magazine letters.
Space: play/pause · ←/→: step