Count Distinct Treatment Days Across Overlapping Episodes
Last updated: November 29, 2026
Quick Overview
Each provider in a case reports treatment episodes as inclusive date ranges that may overlap or touch. Compute the total number of distinct calendar days on which the claimant was under some treatment.
EvenUp
November 29, 20260
0
0 solved
Each provider in a case reports treatment episodes as inclusive date ranges that may overlap or touch. Compute the total number of distinct calendar days on which the claimant was under some treatment.
Duration of care is a common input to how EvenUp-style demands describe the severity of an injury, and summing ranges naively double counts concurrent physical therapy and chiropractic care. The interviewer is checking the interval merge pattern and correct handling of inclusive endpoints.
What the Interviewer Expects
- Recognizes the interval union pattern
- Sorts by start and merges overlapping or adjacent inclusive ranges
- Gets the off-by-one right for inclusive day counts
- Handles reversed ranges from bad extraction
- States complexity clearly
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Return the merged ranges themselves, not just the count.
- How would you answer many queries like 'days treated between dates X and Y'?
- What if episodes stream in one at a time and you need the running total?
- How would you weight days by provider type?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: list of (start, end) datetime.date pairs, inclusive. Ranges may overlap (PT Jan 5 to Jan 12 during ortho Jan 1 to Jan 10) or touch (Jan 12 and Jan 13 are consecutive days and should form on...
High-Level Design
Normalize each pair so start is not after end, sort by start, and sweep while holding a current merged block. A new range whose start is at most one day after the current end extends the block; otherw...