My first instinct was to just reach for datetime and I had to stop myself.
Convert each date to an absolute day count from a fixed reference (e.g., 0000-01-01) by summing days in prior years, months, and the day of month, using a manually implemented leap year function. Then return the absolute difference between the two counts.
Pro tip: Mention that you can avoid hardcoding month lengths by using a cumulative days array and adding 1 for February in leap years. Also, clarify that the Gregorian leap year rule applies to years >= 1582, but for simplicity assume proleptic Gregorian calendar.
Confirm the date range, whether the Gregorian calendar is proleptic, and how to handle invalid dates. Ask if the input is guaranteed valid.
Write a function isLeapYear(year) that returns true if year is divisible by 400, or divisible by 4 but not by 100.
For a given date, calculate total days from year 0 to that date: sum days for full years (365 or 366), then days for full months using a cumulative array adjusted for leap year, then add the day of month.
Compute the absolute difference between the two day counts and return it as an integer.
Verify with cases like same date, leap day, year boundaries, and large year gaps to ensure correctness.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.