Count business days excluding holidays
Company: Airtable
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
## Problem: Count Working Days Between Two Dates
Given a start date, an end date (inclusive), and a set of holiday dates, compute the number of **working days**.
A working day is a date that:
- is **not** Saturday or Sunday, and
- is **not** in the provided holiday set.
### Input
- `startDate`: string in `YYYY-MM-DD`
- `endDate`: string in `YYYY-MM-DD` (guaranteed `endDate >= startDate`)
- `holidays`: list of distinct date strings in `YYYY-MM-DD`
### Output
- An integer: number of working days in `[startDate, endDate]`.
### Example
- `startDate = 2026-12-24`
- `endDate = 2026-12-28`
- `holidays = [2026-12-25]`
Dates:
- 12/24 Thu (work)
- 12/25 Fri (holiday, not work)
- 12/26 Sat (weekend)
- 12/27 Sun (weekend)
- 12/28 Mon (work)
Output: `2`
### Constraints (typical)
- Date range length up to \(10^6\) days for a naive iteration; design an approach appropriate to the stated constraints.
- Holiday count up to \(10^5\).
Quick Answer: This question evaluates proficiency in date and calendar arithmetic, handling set-based exclusions (holiday lists), and reasoning about algorithmic efficiency for counting working days across potentially large ranges.
Count weekdays in the inclusive date range excluding listed holiday dates. Dates use YYYY-MM-DD.
Constraints
- endDate >= startDate
- Holiday strings are distinct but are deduplicated defensively
Examples
Input: ('2026-12-24', '2026-12-28', ['2026-12-25'])
Expected Output: 2
Input: ('2026-06-27', '2026-06-28', [])
Expected Output: 0
Input: ('2026-06-22', '2026-06-26', ['2026-06-22', '2026-06-28'])
Expected Output: 4
Hints
- Count full weeks in O(1), then handle the remainder and holidays.