Dsa
Intervals
Easy
The Bonus Shift Calculator
A consultant works several shifts in a day. The company pays a 'bonus rate' during specific time windows. Given the consultant's work intervals and the bonus time windows, calculate the total duration the consultant was working while a bonus window was active. All intervals are inclusive.
Input Format:
- Line 1: N (number of work shifts).
- Next N lines: start and end of each shift.
- Next line: M (number of bonus windows).
- Next M lines: start and end of each bonus window.
Output Format:
- Total bonus time (integer).
Example:
Input:
1
9 17
2
0 10
16 24
Output:
2
(Explanation: Intersection of [9,17] with [0,10] is [9,10] length 1. Intersection with [16,24] is [16,17] length 1. Total 2.)
Key concepts
interval intersectionsummation
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now