Write Unit Tests for a Calendar Date Range Overlap Function

Last updated: November 29, 2026

Quick Overview

Implement a function that returns how many days two inclusive date ranges share, as used when checking an Outlook out-of-office period against a project schedule, and write a unit test suite that would give you confidence shipping it.

Microsoft
Software Engineering Fundamentals
Software Engineer
Microsoft
November 29, 2026
Software Engineer
Phone Screen
Software Engineering Fundamentals
Easy

0

0

0 solved


Implement a function that returns how many days two inclusive date ranges share, as used when checking an Outlook out-of-office period against a project schedule, and write a unit test suite that would give you confidence shipping it.

Microsoft screens frequently ask candidates to test their own code, a habit rooted in the company's long software testing tradition. The interviewer is less interested in the one-line formula than in whether the candidate systematically finds boundary cases: touching endpoints, containment, symmetry, leap days, and invalid input.

What the Interviewer Expects
  • Clarifies inclusive versus exclusive endpoints before coding
  • Implements overlap with max of starts and min of ends
  • Covers boundary cases, not just the happy path
  • Tests symmetry and invalid inputs
  • Keeps each test focused with a descriptive name
Key Topics to Cover
unit testing
boundary value analysis
equivalence classes
date arithmetic
How to Approach This
  1. Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
  2. Choose data structures based on access patterns, not familiarity.
  3. Prefer immutable data and message passing over shared mutable state for concurrency.
  4. Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
  • How would you test this with property-based testing?
  • How do time zones change the problem if the inputs are datetimes?
  • Which of your tests would catch an off-by-one error, and why?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice System Design Problems
Sample Answer
Requirements
  • Inputs are four date values for two inclusive ranges (an out-of-office from Jan 1 to Jan 5 includes both days).
  • Output: number of overlapping days, 0 if disjoint.
  • Inverted ranges (start af...
High-Level Design

Overlap is [max(starts), min(ends)]; it is non-empty only when that start is not after that end. For inclusive ranges the length is end - start + 1 days, clamped at 0.

For the tests, use **equiva...


Submit Your Answer
Markdown supported