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
Coding & Algorithms
Software Engineer
Mercor
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

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
interval merging
sorting
hash maps
data validation
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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
  1. Bucket sessions per expert in a hash map.
  2. For each expert, sort by start.
  3. Sweep once, keeping a current span; extend it while the next start is inside it, otherwise close it and add its lengt...

Submit Your Answer
Markdown supported

Related Questions