FastPrepOverlap Duration of Two Time Intervals
Problems/Overlap Duration of Two Time Intervals

Overlap Duration of Two Time Intervals

Scale AI logoScale AI● EasyNEW GRADPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Scale AI phone screen. The report describes pulling data out of nested JSON with a time-conversion helper that is given, then working out how two time ranges overlap. The exact schema, the number of intervals, the output value and one extra suggested field are not known. We chose two half-open intervals in whole minutes, and the return value is the overlap duration. Our version is about 70% the same as the reported question.

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) → int

Examples

Example 1

startA = 10endA = 20startB = 15endB = 30return = 5

The common interval is [15,20), lasting five minutes.

Example 2

startA = 5endA = 20startB = 8endB = 12return = 4

The second interval is contained in the first, so their common interval is [8,12).

Example 3

startA = 1endA = 4startB = 4endB = 9return = 0

The intervals touch at 4 but share no positive-duration time.

Constraints

  • For this exercise, assume 0 <= startA <= endA <= 1000000000 and 0 <= 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

Interview reports that mention this question

  • Scale AI New Grad SWE and MLE Question Bank
  • Scale AI New Grad SWE Phone Screen: 1 Experience

Scale AI interview experiences

  • Scale AI OA: What It Tests (2026)
  • Scale AI Forward Deployed Engineer Debugging Round: 1 Experience
  • Scale AI ML Research Engineering Intern Interviews: 1 Experience
  • Scale AI SWE Intern Debugging Interview: 9 Experiences
All Scale AI interview questionsSee Scale AI hiring insights
Saved
class Solution {
    public int overlapDuration(int startA, int endA, int startB, int endB) {
        // write your code here
    }
}
Checking account…