public static int eliminate(final int[] cellIndices, final int[] spans, final ArrayList eliminated) {
    final int size = cellIndices.length;
    if (size != spans.length) {
      throw new IllegalArgumentException("size mismatch: " + size + ", " + spans.length);
    }
    if (eliminated != null && eliminated.size() != 0) {
      throw new IllegalArgumentException("eliminated must be empty");
    }

    int cellCount = 0;
    for (int i = 0; i < size; i++) {
      cellCount = Math.max(cellCount, cellIndices[i] + spans[i]);
    }

    for (int cell = cellCount - 1; cell >= 0; cell--) {
      // check if we should eliminate cell

      boolean starts = false;
      boolean ends = false;

      for (int i = 0; i < size; i++) {
        if (cellIndices[i] == cell) {
          starts = true;
        }
        if (cellIndices[i] + spans[i] - 1 == cell) {
          ends = true;
        }
      }

      if (starts && ends) {
        continue;
      }

      if (eliminated != null) {
        eliminated.add(Integer.valueOf(cell));
      }

      // eliminate cell
      for (int i = 0; i < size; i++) {
        final boolean decreaseSpan = cellIndices[i] <= cell && cell < cellIndices[i] + spans[i];
        final boolean decreaseIndex = cellIndices[i] > cell;

        if (decreaseSpan) {
          spans[i]--;
        }

        if (decreaseIndex) {
          cellIndices[i]--;
        }
      }

      cellCount--;
    }

    return cellCount;
  }
public static int eliminate(final int[] cellIndices, final int[] spans, final ArrayList eliminated)