First Dictionary Word from Note Letters
Problem statement
Given a string note and an ordered array words, return the first word that can be formed by rearranging letters from note.
For this exercise, assume first means the smallest dictionary index; all characters are lowercase English letters; and each note occurrence may be used at most once per candidate. Candidates are checked independently, so a failed candidate consumes nothing. The needed letters may be separated and appear in any order.
For this exercise, assume every dictionary word is nonempty, the note and dictionary may be empty, and no match returns the empty string.
Function
firstWord(note: String, words: String[]) → StringExamples
Example 1
note = "tacappse"words = ["cat","bird","apple"]return = "cat"The source1854853 input is retained; its displayed code selects cat.
Example 2
note = "tacjbcebef"words = ["cat","baby","bird","fruit"]return = "cat"The literal source1362251 first answer is cat.
Example 3
note = "bacdrigb"words = ["cat","baby","bird","fruit"]return = "bird"The literal source1362251 second answer is bird, using separated letters.
Constraints
- For this exercise, assume
0 <= note.length <= 2000and0 <= words.length <= 200. - Each word contains from
1through500lowercase English letters.