Can One Dictionary Word Supply the Target Letters?
Problem statement
Given a nonempty string target and an array words, return whether at least one word can supply every letter occurrence of the target.
For this exercise, assume all characters are lowercase English letters and the target must be constructed by rearranging character occurrences from one candidate word. Each occurrence is used at most once. Do not concatenate whole words or combine letters from several candidates.
For this exercise, assume candidates are checked independently. Return false if no candidate supplies the target, including an empty dictionary.
Function
canSupplyTarget(target: String, words: String[]) → booleanExamples
Example 1
target = "aab"words = ["ab","bbaa"]return = trueThis authored example can construct the target from one supplying candidate.
Example 2
target = "aa"words = ["a","ab"]return = falseThis authored example cannot reuse the single a in any candidate.
Example 3
target = "ab"words = ["a","b"]return = falseThis authored example does not combine letters across different dictionary words.
Constraints
- For this exercise, assume
1 <= target.length <= 500,0 <= words.length <= 200and1 <= words[i].length <= 2000. - All strings contain lowercase English letters.