← Optiver Interview Insights

Optiver·Software Engineer·Online Assessment (OA)·Intermediate

Intermediate
May 2026

Summary

Optiver software engineer interview with a coding problem that sounds deceptively simple until you realize they explicitly ban any date library. Had to implement everything from scratch including leap year logic, which is where most people probably trip up.

Questions Asked (1)

Q1

Given two date strings in YYYY-MM-DD format, return the absolute number of days between them. You cannot use any built-in date or calendar library. You must implement leap year logic yourself using the standard Gregorian calendar rules.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

My first instinct was to just reach for datetime and I had to stop myself.

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 (e.g., 0000-01-01) by summing days in prior years, months, and the day of month, using a manually implemented leap year function. Then return the absolute difference between the two counts.

Pro tip: Mention that you can avoid hardcoding month lengths by using a cumulative days array and adding 1 for February in leap years. Also, clarify that the Gregorian leap year rule applies to years >= 1582, but for simplicity assume proleptic Gregorian calendar.

1. Clarify requirements and edge cases

Confirm the date range, whether the Gregorian calendar is proleptic, and how to handle invalid dates. Ask if the input is guaranteed valid.

2. Implement leap year check

Write a function isLeapYear(year) that returns true if year is divisible by 400, or divisible by 4 but not by 100.

3. Compute days from a reference date

For a given date, calculate total days from year 0 to that date: sum days for full years (365 or 366), then days for full months using a cumulative array adjusted for leap year, then add the day of month.

4. Calculate absolute difference

Compute the absolute difference between the two day counts and return it as an integer.

5. Test with edge cases

Verify with cases like same date, leap day, year boundaries, and large year gaps to ensure correctness.

Key Points to Mention

  • Leap year rule: divisible by 400, or divisible by 4 and not by 100.
  • Use a cumulative days array for months: [0,31,59,90,120,151,181,212,243,273,304,334] and add 1 for February in leap years.
  • Convert each date to an absolute day count from a fixed reference (e.g., 0000-01-01) to simplify difference calculation.
  • Handle edge cases: same date, leap day, year boundaries, and large year gaps.
  • Time complexity: O(1) if using arithmetic formulas, or O(years) if looping; space complexity O(1).
  • Avoid built-in date libraries; implement all logic manually.

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