Overlap Duration of Two Time Intervals
Updated
Problem statement
For this exercise, you receive two time intervals after their timestamps have been extracted and normalized: [startA,endA) and [startB,endB).
For this exercise, assume timestamps are integer minutes on the same timeline and both intervals are half-open: the start is included and the end is excluded. An interval with equal start and end is empty.
Return the elapsed number of minutes covered by both intervals. Disjoint, touching or empty intervals have overlap duration 0.
Input and output
This function receives four already-normalized endpoints and returns the duration of their intersection.
Function
overlapDuration(startA: int, endA: int, startB: int, endB: int) → intExamples
Example 1
startA = 10endA = 20startB = 15endB = 30return = 5The common interval is [15,20), lasting five minutes.
Example 2
startA = 5endA = 20startB = 8endB = 12return = 4The second interval is contained in the first, so their common interval is [8,12).
Example 3
startA = 1endA = 4startB = 4endB = 9return = 0The intervals touch at 4 but share no positive-duration time.
Constraints
- For this exercise, assume
0 <= startA <= endA <= 1000000000and0 <= startB <= endB <= 1000000000. - The supplied integers are normalized elapsed minutes; no JSON parsing, timezone conversion or external request is required.
- The returned duration lies in
[0,1000000000]and fits a signed 32-bit integer.
More Scale AI Phone Screen questions
- Four-Player Trick-Taking Card Game SimulationOA · PHONE SCREEN · Seen Aug 2026
- Task Processor: Dependencies and DeadlinesPHONE SCREEN · Seen Aug 2026
- Best Poker Category with a JokerPHONE SCREEN · ONSITE INTERVIEW · Seen Jun 2026
- Free Time for Every Meeting RoomPHONE SCREEN · Seen Apr 2026
- Free Windows Between Busy IntervalsOA · PHONE SCREEN · Seen Apr 2026
- Order Queries by Shortest Processing TimePHONE SCREEN · Seen Apr 2026
- Party Time by Town and Quiet Gaps by CityPHONE SCREEN · Seen Jan 2026
- Party Windows and Dead Zone TimePHONE SCREEN · Seen Oct 2025
- Multi-Head Attention BlockPHONE SCREEN · Seen Mar 2025
- Top-K SamplerPHONE SCREEN · Seen Mar 2025
Similar questions at other companies
- Parking Fee CalculatorBreeze · PHONE SCREEN
- Merchant Payout Reserve CalculatorStripe · PHONE SCREENStripe interview questions
- Sqrt(x)LinkedIn · PHONE SCREENLinkedIn interview questions
- Automation Pipeline, Part 1: Single WorkerPlaid · PHONE SCREENPlaid interview questions
- Subtract Two Large Number StringsStackAdapt · PHONE SCREENStackAdapt interview questions
- Circular Primes Below a LimitAmazon · PHONE SCREEN
- Palindrome NumberKotak Mahindra Bank · PHONE SCREENKotak Mahindra Bank interview questions
- Streaming AverageXantium · PHONE SCREEN
- Fair Coin from a Biased CoinAnthropic · PHONE SCREENAnthropic interview questions
- Stack Formula InterpreterTypeSafe AI · PHONE SCREEN