Exclude overlapping lists while keeping disjoint- and sub-lists?

Per comment,

f[l1_, l2_] := MemberQ[{l1, l2, {}}, l1 ⋂ l2]

should do the job handily, and look at 10.x (if you're on it) functions like ContainsAll, etc. for alternative ways of doing the same.

Edit: BTW - I assumed sorted lists w/o duplicates, as in your example. If they're not sorted,

 f[l1_, l2_] := MemberQ[Sort /@ {l1, l2, {}}, l1 ⋂ l2]

takes care of that.

If duplication in a list is allowed, you'll need to describe how that's to be handled.

If the lists are as in the OP (strictly sequential integers with no duplication), this will be goofy fast on large lists:

f3[l1_, l2_] := 
 OrderedQ[{l1[[1]], l2[[1]], l2[[-1]], l1[[-1]]}] || 
  OrderedQ[{l2[[1]], l1[[1]], l1[[-1]], l2[[-1]]}] || 
   (l1[[1]] > l2[[-1]] || l2[[1]] > l1[[-1]])

For this one, you will need 10.2 or higher (ContainsAll was introduced in 10.2):

f[l1_, l2_] := Or[
 DisjointQ[l1, l2],
 ContainsAll[l1, l2],
 ContainsAll[l2, l1]
]

Including this solution because it might be easier to read this code since it closely encodes your written description.


ClearAll[g]
g = Through[Or[ContainsNone, ContainsOnly, ContainsAll]@##]&;

g[{1,2,3}, {4,5}]

True

g[{1,2,3,4,5}, {4,5}]

True

g[{1,2,3,4}, {4,5}]

False