Function S2CellId.getCommonAncestorLevel

Returns the level of the lowest common ancestor of this cell and "other", that is, the maximum level such that parent(level) == other.parent(level). Returns -1 if the two cells do not have any common ancestor (i.e., they are from different faces).

int getCommonAncestorLevel (
  S2CellId other
) const;