You are given a rectangular board consisting of several light panels. Character j of element i of board represents the panel in row i, column j. '*' means the panel is on, and '.' means it's off. When you touch a panel, its state will be toggled. In other words, if you touch a panel that's on, it will turn off, and if you touch a panel that's off, it will turn on. Because the panels are so sensitive, when you touch a panel, all of its horizontally, vertically, and diagonally adjacent panels will also toggle their states.
Your goal is to have all the light panels in the board be on at the same time. Return the minimum number of touches required to achieve this goal, or return -1 if it is impossible.
|