code: public boolean inOrder() {
          SortedSet<Integer> prev = null;
          for (SortedSet<Integer> cell : cells) {
              if (prev == null) {
                  prev = cell;
              } else {
                  int first = cell.first();
                  int last = cell.last();
                  if (first > prev.first() && last > prev.last()) {
                      prev = cell;
                  } else {
                      return false;
                  }
              }
          }
          return true;
      }
docs: Check whether the cells are ordered such that for cells i and j,
  first(j) &gt; first(i) and last(j) &gt; last(i).
  
  @return true if all cells in the partition are ordered