← Optiver Interview Insights

Optiver·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
May 2026

Summary

Optiver software engineer interview with a coding problem that looked straightforward until I actually had to implement it from scratch. No date libraries allowed, which is where things got uncomfortable fast.

Questions Asked (1)

Q1

Given two dates as (year, month, day) tuples where the first is guaranteed to be earlier, compute the number of days between them without using any built-in date or time library. You are given a helper function DaysInMonth(month, year) that returns the number of days in a given month.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

I thought I had this immediately and started coding before really thinking it through.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Convert each date to an absolute day count from a fixed reference point (e.g., year 0) by summing days for full years, full months, and remaining days. Then subtract the earlier date's count from the later date's count to get the difference. Use the provided DaysInMonth helper and handle leap years correctly.

Pro tip: Explicitly state your assumptions about leap years (e.g., every year divisible by 4 is a leap year, except centuries not divisible by 400) and confirm with the interviewer. This shows attention to detail and avoids ambiguity.

1. Clarify requirements and assumptions

Confirm the date range, leap year rules, and whether the helper function accounts for leap years. Ask if the dates are within a reasonable range (e.g., years 1 to 9999) to avoid overflow concerns.

2. Define an absolute day count function

Write a helper that converts a (year, month, day) tuple to the number of days since a fixed reference (e.g., Jan 1, year 0). Sum days for all full years before the given year, then days for full months before the given month, then add the day.

3. Implement leap year logic

Create a function to determine if a year is a leap year (divisible by 4, except centuries unless divisible by 400). Use this to adjust the number of days in February and the total days per year.

4. Compute the difference

Call the absolute day count function for both dates and subtract the earlier from the later. Return the result as the number of days between them.

5. Test with edge cases

Verify with cases like same date (0 days), consecutive days (1 day), leap year boundaries (Feb 28 to Mar 1 in a leap year), and year boundaries. Discuss potential off-by-one errors.

Key Points to Mention

  • Leap year rules: divisible by 4, except centuries unless divisible by 400.
  • Using a fixed reference point (e.g., year 0) to simplify absolute day count calculation.
  • Leveraging the provided DaysInMonth helper to avoid hardcoding month lengths.
  • Time complexity: O(year difference) if summing year by year, or O(1) with formula; space complexity O(1).
  • Handling edge cases: same date, leap years, month/year boundaries, and large year differences.
  • Potential off-by-one errors when counting days inclusively vs exclusively; clarify whether the end date is included.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.