Skip to content

Instantly share code, notes, and snippets.

@Merce0897
Created October 30, 2022 09:01
Show Gist options
  • Save Merce0897/a3d429604e085e33bd1c566481d4bded to your computer and use it in GitHub Desktop.
Save Merce0897/a3d429604e085e33bd1c566481d4bded to your computer and use it in GitHub Desktop.
function maxNumberOfBalloons(text: string): number {
let result = new Map()
for (let i = 0; i < text.length; i++) {
result.set(text[i],(result.get(text[i]) || 0) + 1)
}
let count = 0
if (result.get('l') >= result.get('b') * 2) {
count = result.get('b')
} else {
count = Math.floor(result.get('l') / 2)
}
while (count > 0) {
if (
result.get('b') >= count &&
result.get('a') >= count &&
result.get('l') >= count * 2 &&
result.get('o') >= count * 2 &&
result.get('n') >= count
) {
return count
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment