Count Months Whose First Day Is Sunday
Company: Walmart Labs
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Overview: Count months beginning on Sunday across an inclusive Gregorian year range without a calendar library, using the 2000 weekday anchor and correct forward, backward, and leap-year arithmetic.
Constraints
- 1900 <= start_year <= end_year <= 9999.
- The range includes January through December in both boundary years.
- A leap year is divisible by 400, or divisible by 4 but not by 100.
- Use the proleptic Gregorian calendar without a built-in date or calendar library.
- January 1, 2000 was a Saturday.
Examples
Input: (2000, 2024)
Expected Output: 43
Explanation: The inclusive 25-year range contains 43 Sunday month starts.
Input: (2000, 2000)
Expected Output: 1
Explanation: In leap year 2000, October begins on Sunday.
Hints
- Advance a month's first weekday by its length modulo seven.
- Reach the starting year by moving forward or backward from the 2000 anchor.