Problems > Days Apart > Editorial

Days Apart — Solution & Editorial

Back to the Problem

Convert each date to a day count from a fixed epoch with the civil-days formula (or era/400-year arithmetic) and subtract — no month-walking loops needed.

Complexity: O(1)

Watch out: Leap-century rules (1900 no, 2000 yes) break naive 365.25-based math.