You are given a list of chemical element symbols and a word. Count the number of different ways to form the entire word by joining symbols from the list.
Symbols may be reused, and matching is case-insensitive. Each character of the word must belong to exactly one selected symbol.
PeriodicTableWordCounter
long countWaysToFormWord(List<String> elementSymbols, String word)
elementSymbols: The available chemical element symbols.word: The word that must be formed.Return the number of different sequences of element symbols whose concatenated letters equal word, ignoring letter case. Return 0 if the word cannot be formed.
"Co" matches "co", "CO", and "Co".elementSymbols is a valid chemical element symbol.1 ≤ elementSymbols.size() ≤ 1181 ≤ elementSymbols.get(i).length() ≤ 21 ≤ word.length() ≤ 90elementSymbols contains no duplicates when letter case is ignored.elementSymbols and word contain only English letters. countWaysToFormWord( elementSymbols = List.of("C", "O", "Co"), word = "CoCo")
Output: 4
The four possible sequences are:
C - O - C - OC - O - CoCo - C - OCo - Co countWaysToFormWord( elementSymbols = List.of("N", "Ne", "O"), word = "Neon")
Output: 1
The only possible sequence is Ne - O - N.
countWaysToFormWord( elementSymbols = List.of("He", "Li", "O"), word = "Hello")
Output: 0
No sequence of the provided element symbols forms the entire word.