Element Symbol Spellings
Asked at Google
Reported by the problem's creator, not verified
A word can be spelled with chemical element symbols when it can be cut into consecutive pieces that are each a symbol. Matching ignores case, so "Physics" and "pHySiCs" are the same word and "Si" and "si" are the same symbol.
Implement count_spellings(symbols, word):
symbolsis a list of element symbols, each 1 to 3 letters.wordis the word to spell.- Return the number of ways to cut
wordentirely into pieces that are symbols, or0when there is no way.
Two spellings are different when they cut the word at different places; the same symbol listed twice (in any case) does not create extra spellings.
Examples
Example 1
Input: symbols =
["H","He","Li","Be","B","C","N","O","F","Ne","Na","Mg","Al","Si","P","S","Cl","Ar","K","Ca","Sc","Ti","V","Cr","Mn","Fe","Co","Ni","Cu","Zn","Ga","Ge","As","Se","Br","Kr","Rb","Sr","Y","Zr","Nb","Mo","Tc","Ru","Rh","Pd","Ag","Cd","In","Sn","Sb","Te","I","Xe","Cs","Ba","La","Ce","Pr","Nd","Pm","Sm","Eu","Gd","Tb","Dy","Ho","Er","Tm","Yb","Lu","Hf","Ta","W","Re","Os","Ir","Pt","Au","Hg","Tl","Pb","Bi","Po","At","Rn","Fr","Ra","Ac","Th","Pa","U","Np","Pu","Am","Cm","Bk","Cf","Es","Fm","Md","No","Lr","Rf","Db","Sg","Bh","Hs","Mt","Ds","Rg","Cn","Nh","Fl","Mc","Lv","Ts","Og"], word =PhysicsOutput:
4Explanation: The four spellings are P|H|Y|S|I|C|S, P|H|Y|Si|C|S, P|H|Y|S|I|Cs and P|H|Y|Si|Cs. The letters are compared without regard to case.