You are given a single word. Determine in how many distinct ways the entire word can be formed by concatenating chemical element symbols from the periodic table, in order.
An element symbol is either a single letter (for example H, C, S, Y, I) or two letters (for example Si, Cs). Matching is case-insensitive: the letters of word are compared against element symbols ignoring case.
A valid formation is a sequence of element symbols whose concatenation, read left to right, exactly reproduces word. Two formations are different if they split the word at any different position or use any different symbol. Return the total count of valid formations.
word = "Physics" return = 4
The four formations are P - H - Y - Si - C - S, P - H - Y - Si - Cs, P - H - Y - S - I - C - S, and P - H - Y - S - I - Cs.
Constraints:
wordconsists only of alphabetic letters.- Matching between letters of
wordand element symbols is case-insensitive. - Each element symbol used must be a valid periodic table symbol of length 1 or 2.
- The symbols of a formation, concatenated in order, must equal
wordwith no leftover characters.
- Fountain SafetyONSITE INTERVIEW · Seen Jun 2026
- Consolidate On-Call RotationsOA · Seen Jun 2026
- Detonate Bombs with Chain ReactionsONSITE INTERVIEW · Seen May 2026
- Evaluate a Nested Math ExpressionONSITE INTERVIEW · Seen May 2026
- Tic-Tac-Toe Game StatusPHONE SCREEN · Seen May 2026
- Longest Dictionary TokenizationPHONE SCREEN · Seen May 2026
- Minimum Cars for Rental RequestsONSITE INTERVIEW · Seen Apr 2026
- Shortest Path with Mandatory WaypointONSITE INTERVIEW · Seen Apr 2026
public int countWordFormations(String word) {
// write your code here
}