Intervals and greedy frontiers
Interval problems depend on endpoint rules. A reporting union may merge touching ranges even when two bookings sharing an endpoint don't overlap. Write that rule beside your comparison before implementing a scan. Then sort in the order that makes one local decision safe: starts for a union, ends for maximum compatible sessions, or starts with a heap of active ends for room demand.
A greedy algorithm needs a reason its discarded choices can't improve the answer. Earliest finishing sessions leave more room for later sessions. A covered-prefix scan can stop at the first uncovered gap because later starts can't fill it. The final exercise uses a similar frontier argument on a line of reachable platforms. Distinguish the current frontier from the farthest next frontier so you count whole breadth-first layers rather than individual indexes.
sessions = [[0,7], [1,3], [3,5], [5,6]]
end-time order:
[1,3] -> choose, end = 3
[3,5] -> choose, end = 5
[5,6] -> choose, end = 6
[0,7] -> skip
maximum count = 3
The first chosen session ends at 3. Replacing it with the long session ending at 7 can't create room for any extra later session, so the earlier finish is safe. After that choice, apply the same argument to the remaining compatible sessions. Equality is allowed because each interval is half open: a session ending at 3 releases its resource for a new session starting at 3. This example needs a greater-than-or-equal compatibility test. The union exercise deliberately uses a different rule, combining touching reporting ranges, so copy the reasoning rather than copying a comparison from a nearby problem.