Interval Representation
An interval is a compact promise about a continuous range, and most interview bugs come from not deciding exactly what its two endpoints mean.
The Pair Is the Contract
An interval is usually modeled as [start, end]: one number names where the range begins, and the other names where it stops. In Java interview problems, that almost always becomes either one int[] of length two or an int[][] collection where each row is one interval.
That representation is deliberately small. It keeps the algorithm focused on comparisons between boundaries rather than object design. For [[1,3],[2,6],[8,10]], the row [1,3] means start = 1 and end = 3. The outer array is just the list of ranges to sort, merge, select, or compare.
Closed vs Half-Open Ranges
A closed interval [1,3] includes both endpoints: 1, 2, and 3 are inside the range if the domain is integer. A half-open interval [1,3) includes 1 and 2, but not 3. Many scheduling APIs prefer half-open ranges because a meeting from 10 to 11 and a meeting from 11 to 12 do not conflict.
Most LeetCode interval array problems use closed-looking notation unless the prompt explicitly says otherwise. Calendar booking problems often use half-open language, even when they still display arrays. The notation changes the overlap test, so do not treat endpoint convention as cosmetic.
Endpoint Convention Changes Overlap
For closed intervals, touching endpoints count as shared coverage. [1,3] and [3,5] overlap because the value 3 belongs to both. The overlap condition is a <= d && c <= b for intervals [a,b] and [c,d].
For half-open intervals, touching endpoints usually do not conflict. [1,3) and [3,5) are adjacent, not overlapping, because the first interval has already ended when the second starts. The strict version becomes a < d && c < b. That one-character difference is the source of many accepted or rejected edge cases.
Why Arrays Dominate Interview Encoding
The plain int[][] representation is fast to scan, easy to sort with Arrays.sort, and close to the way test cases are written. It also makes the core invariant visible: every decision is about interval[0] as the start and interval[1] as the end.
Custom classes can improve readability in production, but they add ceremony in an interview unless the problem already provides an Interval type. The safest habit is to translate the prompt into two names immediately: start and end. Once those names are clear, sorting, overlap checks, and merge logic become local boundary comparisons.
Closed and half-open overlap tests
The representation is identical, but the endpoint convention changes <= to < when touching boundaries should be allowed.
Key Takeaways
- An interval pair stores start at index 0 and end at index 1.
- Closed intervals include both endpoints, while half-open intervals exclude the right endpoint.
- Touching endpoints overlap for closed intervals but not for half-open scheduling ranges.
- Decide endpoint semantics before writing the comparison logic.