← 返回 optiver 的题目列表Days Between Two Dates
类型:qbank
A warm-up OA problem (often the first of the experienced/campus SWE OA, including a C variant): compute the number of days between two given calendar dates, handling months of varying length and leap years.
Requirements
Given two calendar dates, return the number of days between them.
Handle variable month lengths and leap-year rules correctly.
Appears in Python and C variants (the C version is phrased as "write a function comparing two dates").
Examples
Inputs like 2011-01-03 and 2011-01-05.
Notes
Equivalent to LeetCode 1360 (Number of Days Between Two Dates), as candidates have confirmed; a built-in date library handles it in most languages, but the C variant expects a manual day-count.
This is the easy half of the two-problem experienced/campus SWE OA, paired with the binary-tree / S-expression problem.
Preparation
Implement a "days since epoch" helper (cumulative month lengths + leap-year correction) and take the difference; verify across a leap-year boundary and avoid hard-coding a narrower year range than the prompt allows.