Given the current state of a Hangman game, implement a function that selects the next letter with the highest likelihood of appearing in the secret word. Inputs:
(
-
the current pattern string showing revealed letters and placeholders (e.g., '_' for unknowns),
(
-
the set of letters already guessed (both correct and incorrect), and
(
-
a dictionary (word list). Compute the set of candidate words consistent with the pattern and excluding any letters known to be absent; then, among letters not yet guessed, choose the one that maximizes aggregate frequency across the candidate set. Clearly describe preprocessing of inputs, your algorithm, and time/space complexity. Specify and implement a deterministic tie-breaking policy for letters with equal frequency.