Word Formation
Given a list of strings words
and a string letters
, return the length of longest string in words
that can be made from letters in letters
. If no word can be made, return 0
.
Note that you can’t reuse letters.
Constraints
n ≤ 10,000
wheren
is the length ofwords
m ≤ 1,000
wherem
is the length ofletters
https://binarysearch.com/problems/Word-Formation
Examples
Example 1
Input
- words =
['the', 'word', 'love', 'scott', 'finder', 'dictionary']
- letters =
fanierdow
Output
- answer =
6
Explanation
We can make the word finder
out of our letters, which has the longest length of 6.
Example 2
Input
- words =
['credit', 'nirvana', 'karma', 'empathy', 'hang', 'aaaaaaaaa']
- letters =
afnvlfkm
Output
- answer =
0
Explanation
We can’t make any of these words with the letters we have.
Leave a comment