fence, one character per board: 'X' is a broken board and 'O' is a sound one.
A single patch covers exactly three adjacent boards and makes all of them sound; covering boards that are already fine is allowed.
Return the smallest number of patches that leaves the whole fence sound.fence="OXXOOOXO" → 2
One patch covers boards 1–3 and a second covers boards 5–7.
fence="XOOOX" → 2
Broken boards 0 and 4 are too far apart for a single patch.
fence="OOO" → 0
Nothing to fix.
fence is 'X' or 'O'fence="OXXOOOXO"
2
Run checks the first 3 tests in your browser. Submit checks all 169 tests on the server, hidden ones included.