Problem · String
All Long Subsequences Are Dictionary Words
Learn this problemProblem statement
Given a lowercase string text and a finite lowercase dictionary, consider every subsequence of text whose length is at least 3. A subsequence keeps relative order and is identified by its resulting string; repeated ways to form the same string do not change the decision.
Return two booleans:
answer[0]is true exactly when every considered subsequence appears in the dictionary.answer[1]is true exactly when, for every considered subsequence, at least one dictionary word is an anagram of it.
If text.length < 3, both statements are vacuously true. Duplicate dictionary entries have no effect.
Function
allSubsequencesAreWords(text: String, dictionary: String[]) → boolean[]Examples
Example 1
text = "abc"dictionary = ["abc","cab"]return = [true,true]The only qualifying subsequence is abc. It is present directly and also has dictionary anagrams.
Example 2
text = "abc"dictionary = ["bca"]return = [false,true]The subsequence abc is not itself in the dictionary, but bca is an anagram of it.
Example 3
text = "abcd"dictionary = ["abc","abd","acd","bcd","abcd"]return = [true,true]The four length-three subsequences and the full length-four subsequence all appear directly, so both conditions hold.
Constraints
0 <= text.length <= 180 <= dictionary.length <= 200000textand every dictionary word contain only lowercase English letters.- Each dictionary word has length at most
18. - The total number of dictionary characters is at most
1000000.