Trains the technique from
LeetCode 1360Number of Days Between Two DatesThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
An archivist pulls two paper slips out of a box. Each slip carries the date it was stamped, and the archivist wants to know how far apart in whole days the two stampings were.
A stamp is written as YYYY-MM-DD: four digits for the year, a hyphen, two digits for the month, another hyphen, two digits for the day. 1985-04-07 is the seventh of April, 1985.
Given the two stamps slip_a and slip_b, return how many days one stamping was after the other. The slips come out of the box in no particular order, so slip_a may be the later of the two; the answer is never negative. Two slips stamped on the same day are zero days apart, and two slips stamped on consecutive days are one day apart.
Dates follow the Gregorian calendar. Months hold 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30 and 31 days in order, except that the second month holds 29 days in a leap year. A year is a leap year when it is divisible by 4, with one exception: a year divisible by 100 is a leap year only when it is also divisible by 400. So 1900 and 2100 are ordinary years while 1600, 2000 and 2400 are leap years.
Example 1
2024 is divisible by 4 and not by 100, so its second month runs to the 29th. Stepping from 26 February: 27, 28, 29 February, then 1, 2, 3, 4, 5 March, which is eight days.
Example 2
Here `slip_a` is the later stamp and the count is still reported unsigned. 2100 is divisible by 100 but not by 400, so its second month has 28 days: 31 days in the first month plus 28 in the second gets from 1 January to 1 March.
Example 3
Both slips carry the same stamp, so nothing separates them.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def days_apart(slip_a: str, slip_b: str) -> int:public int daysApart(String slipA, String slipB)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.