Compute Billable Hours From Overlapping Contractor Time Logs
Last updated: November 29, 2026
Quick Overview
Contractors log work sessions as (expert_id, start_minute, end_minute) from several devices, so sessions for the same expert can overlap. Return each expert's billable minutes, counting any minute at most once.
Mercor
November 29, 20260
0
0 solved
Contractors log work sessions as (expert_id, start_minute, end_minute) from several devices, so sessions for the same expert can overlap. Return each expert's billable minutes, counting any minute at most once.
Mercor pays a large global pool of hourly experts, so time tracking that never double-bills a lab and never underpays an expert is core product logic. A phone screen uses this to check clean interval merging, grouping, and attention to dirty input.
What the Interviewer Expects
- Group sessions by expert before merging
- Sort each expert's intervals and merge overlapping or touching spans
- Ignore zero-length or inverted sessions explicitly
- State O(n log n) time and O(n) space
- Discuss whether touching intervals (end == next start) merge
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 cap billable time at 8 hours per calendar day in the expert's time zone?
- Sessions now stream in out of order; how do you keep running totals without re-sorting everything?
- How would you flag experts whose overlapping sessions look like fraud rather than multi-device noise?
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 (expert_id, start, end) tuples in minutes. Output is a dict expert_id -> billable minutes. A minute covered by two sessions (laptop plus browser tab) counts once. Sessions with ...
High-Level Design
- Bucket sessions per expert in a hash map.
- For each expert, sort by start.
- Sweep once, keeping a current span; extend it while the next start is inside it, otherwise close it and add its lengt...