Google Code Jam 2022 round1C Letter Blocks

solution

Check a letter appearance

First, check all of the middle letters, which all letters other than the first and last consecutive segment of letters.

If a letter in middle letter appears more than one input string, it is impossible to construct the megatower.