public void solve(char[][] board) {

    // mark all the 'O's that are reachable from boarder
    // change them to 'P', then change all other 'O's to X
    // change 'P' back to O. done
    if (board == null || board.length == 0 || board[0].length == 0) {
      return;
    }

    for (int i = 0 ; i < board.length ; i++) {
      helper(board, i, 0);
      helper(board, i, board[0].length - 1);
    }
    for (int j = 0 ; j < board[0].length ; j++) {
      helper(board, 0, j);
      helper(board, board.length - 1, j);
    }

    for (int i = 0 ; i < board.length ; i++) {
      for (int j = 0 ; j < board[0].length ; j++) {
        if (board[i][j] == 'O') {
          board[i][j] = 'X';
        } else if (board[i][j] == 'P') {
          board[i][j] = 'O';
        }
      }
    }
  }