Merge Overlapping Billable Time Entries Per Client Matter
Last updated: November 29, 2026
Quick Overview
Given raw time entries as (matter_id, start_minute, end_minute), merge overlapping or touching entries within each matter and report the true billable minutes per matter.
Harvey
November 29, 20260
0
0 solved
Given raw time entries as (matter_id, start_minute, end_minute), merge overlapping or touching entries within each matter and report the true billable minutes per matter.
Harvey sells to law firms where time and matter data feed into how value is measured, so an early screen often uses a small, domain-flavored intervals problem. The interviewer checks that you group before merging, sort correctly, and avoid double counting when entries overlap.
What the Interviewer Expects
- Group entries by matter before merging
- Sort by start time and merge in one pass
- Decide explicitly whether touching intervals merge
- Ignore or reject zero and negative length entries
- State O(n log n) complexity and why
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
- How would you also return the overlapping minutes that were double logged?
- What changes if entries stream in and you must keep merged spans up to date?
- How do you handle entries that cross midnight in different time zones?
- Can you cap billable time per day per matter?
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 is a list of (matter_id, start, end) tuples in minutes. For each matter, overlapping or touching spans should merge ([0,30] and [30,45] become [0,45]). Output the merged spans and the bi...
High-Level Design
- Bucket entries by matter in a hash map.
- For each bucket, sort by start.
- Sweep: if the next start is at or before the current end, extend the current end; otherwise open a new span.
- Billabl...