I knew this type of puzzle existed but blanked on the mechanics for a minute.
Use parity (XOR) to encode information: the first dwarf (at the back) announces the parity of all hats ahead, sacrificing his own guess to save the rest. Each subsequent dwarf deduces their own hat by comparing the announced parity with the hats they can see and the previous announcements.
Pro tip: Emphasize that the strategy guarantees all but the first dwarf guess correctly, and clarify that the first dwarf's guess is not random but a deliberate parity signal. This shows you understand the trade-off between individual and collective success.
Agree that the first dwarf will say 'black' if the number of black hats ahead is even, and 'white' if odd (or vice versa). This encodes the parity of the remaining hats.
The dwarf at the back counts the black hats ahead, computes parity, and announces the corresponding color. This may or may not match his own hat, but it conveys the parity to everyone.
Each following dwarf hears the previous announcements, sees the hats ahead, and knows the initial parity. By tracking how many black hats have been announced (excluding the first) and how many are visible, they deduce their own hat color.
Each dwarf updates the parity based on the previous dwarf's correct guess, ensuring that the parity information remains consistent for the next dwarf.
This strategy guarantees that all dwarves except possibly the first guess correctly. The first dwarf has a 50% chance of being correct, but the overall number of correct guesses is maximized.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.