EASYasked at 2 companies

Number of Days Between Two Dates

A easy-tier problem at 51% community acceptance, tagged with Math, String. Reported in interviews at Optiver and 1 others.

Founder's read

You're given two dates as strings and need to return the number of days between them. Optiver and Accenture have both asked this. It's rated Easy, but the acceptance rate sits just above 51%, which tells you most people overthink it or fumble the date math. The trap is trying to write your own calendar logic instead of using what the language gives you. This problem punishes hand-rolled solutions with off-by-one errors and DST bugs. If this hits your live assessment and you blank on the standard approach, StealthCoder surfaces a working solution in seconds while the proctor sees nothing.

Companies asking
2
Difficulty
EASY
Acceptance
51%

Companies that ask "Number of Days Between Two Dates"

If this hits your live OA

Number of Days Between Two Dates is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by an Amazon engineer who realized the OA tests how well you memorized 200 problems, not how well you code.

Get StealthCoder
What this means

The real trick is recognizing this isn't a hard math problem; it's a standard library problem. Most languages have built-in date parsing and arithmetic. You parse both strings into date objects, subtract them, and extract the day count from the result. The failures come from two places: first, people try to validate leap years and month lengths by hand instead of trusting the standard library; second, they miscount inclusivity (do you include both endpoints or neither). The obvious dead-end approach is manual calendar logic; the correct move is to use DateTime or Date utilities designed for this. String parsing is straightforward; the Math topic here refers to date arithmetic, not complex algorithms. If you're unsure which library method returns days as an integer versus a duration object, StealthCoder handles that ambiguity during the live assessment.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Number of Days Between Two Dates recycles across companies for a reason. It's easy-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by an Amazon engineer who realized the OA tests how well you memorized 200 problems, not how well you code. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Number of Days Between Two Dates interview FAQ

Why is the acceptance rate only 51% if this is an Easy problem?+

Most candidates waste time writing leap-year logic or trying to count days manually instead of using language-built date libraries. Off-by-one errors and timezone confusion tank submissions. The problem isn't algorithmically hard; execution mistakes dominate.

Do I need to handle leap years and DST myself?+

No. Use your language's standard date or datetime library. Python's datetime module, JavaScript's Date object, or Java's LocalDate all handle leap years and DST automatically. Custom calendar math is where candidates fail.

Is this problem still asked at Optiver and Accenture?+

Both companies have confirmed asking it. It's a filtering problem; if you can't parse strings and use standard libraries cleanly, that signals to them. It's not about algorithmic depth; it's about not reinventing the wheel.

What's the most common mistake on this problem?+

Attempting to manually calculate days between dates by iterating through months or counting leap years. Candidates then introduce off-by-one errors. The solution is two to three lines with the right library call.

Does the order of the input dates matter?+

Check the problem statement, but typically you return the absolute difference or handle both orderings. The trick is using date subtraction, which is language-specific. Your standard library call will handle edge cases correctly if you use it right.

Want the actual problem statement? View "Number of Days Between Two Dates" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.