class RewriteRowAndColumnsWithZeros {

  public void rewrite(int[][] matrix) {
    validateInput(matrix);

    Set<Integer> rowsToSkip = new HashSet<Integer>();
    Set<Integer> columnsToSkip = new HashSet<Integer>();
    for (int i = 0; i < matrix.length; i++) {
      for (int j = 0; j < matrix[i].length; j++) {
        if (shouldPaintRowAndColumn(matrix, i, j, rowsToSkip, columnsToSkip)) {
          rewriteRow(matrix, i, rowsToSkip);
          rewriteColumn(matrix, j, columnsToSkip);
        }
      }
    }
  }

}