← Optiver Interview Insights

Optiver·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Jun 2026

Summary

Interviewed for a Software Engineer role at Optiver and got a calendar arithmetic problem that looked deceptively simple. No date libraries allowed, which is where it gets annoying fast.

Questions Asked (1)

Q1

Given two date strings in YYYY-MM-DD format, compute the absolute number of days between them from scratch. No date or calendar libraries. You need to handle leap years and varying month lengths yourself.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

The leap year rule is where people slip up.

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 or 1970-01-01) by summing days for full years, months, and days, then take the absolute difference. Handle leap years by checking divisibility rules (divisible by 4, except centuries unless divisible by 400) and use a month-length array that adjusts for February. Validate inputs and discuss edge cases like invalid dates or same dates.

Pro tip: Before coding, clarify assumptions: ask if the input dates are guaranteed valid and if the range is within a reasonable bound (e.g., years 1–9999). This shows you think about robustness and avoids over-engineering.

1. Clarify requirements and edge cases

Confirm input format, validity, and expected output. Discuss edge cases: same date, leap years, month-end, year boundaries, and invalid dates.

2. Design helper functions

Outline functions: isLeapYear(year), daysInMonth(year, month), and daysSinceEpoch(year, month, day) that returns total days from a fixed reference.

3. Implement day-count conversion

Compute total days by summing days for all prior years (365 or 366), days for prior months in the current year, and the day of month. Use a loop or formula.

4. Compute absolute difference

Calculate the absolute difference between the two day counts. Ensure the result is non-negative.

5. Test and validate

Walk through examples (e.g., 2019-01-01 to 2020-01-01 = 365, 2020-02-28 to 2020-03-01 = 2) and check edge cases like leap day and year boundaries.

Key Points to Mention

  • Leap year rules: divisible by 4, except centuries unless divisible by 400.
  • Month lengths: 31, 28/29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31.
  • Absolute day count from a fixed epoch simplifies difference calculation.
  • Time complexity: O(1) if using formula, O(years) if looping; space O(1).
  • Edge cases: same date, leap day, year boundaries, invalid inputs.
  • Validation: check date validity (e.g., month 1-12, day within month range).

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