tiles: every character is one tile. You are also given a list of words words.
A word can be spelled if each of its letters gets a tile of its own: a single tile cannot be used twice within one word. Each word is spelled separately, starting from the full set of tiles.
Return the total length of all words in words that can be spelled.words=['team', 'meat', 'mate', 'tame', 'steam'], tiles='mteab' → 16
The tiles m, t, e, a, b spell "team", "meat", "mate" and "tame" (4 · 4 = 16 letters); "steam" needs an "s" we do not have.
words=['pool', 'lop', 'loop'], tiles='olp' → 3
"pool" and "loop" each need two o's, but there is only one "o" tile. Only "lop" fits, so the answer is 3.
words.length ≤ 1000words[i].length ≤ 100tiles.length ≤ 100words[i] and tiles consist of lowercase English letterswords=['team', 'meat', 'mate', 'tame', 'steam'], tiles='mteab'
16
Run checks the first 3 tests in your browser. Submit checks all 134 tests on the server, hidden ones included.