Loading section...

Interval Representation in Python

Concepts: pyIntervalRepresentation, pyDatetimeIntervals, pyTouchingConvention

Before you start coding, you need to decide how to represent intervals. This is not just a style question. The choice of representation affects mutability (can you update the end in-place?), readability, and what the interviewer expects. Most LeetCode problems hand you List[List[int]], so tuples are usually wrong there. In production code, dataclasses are almost always the right choice. Know all three and know when to use each. Tuples vs Lists vs Dataclass Datetime Intervals In production, intervals are rarely integers. They are datetimes. The comparison logic is identical — datetime objects support < and > natively — but you need to be precise about timezone handling (always use timezone-aware datetimes, never naive), and the 'gap' between intervals is a timedelta, not an integer. The Tou