Earliest Minute When All Recurring Dispatch Jobs Fire Together
Last updated: November 29, 2026
Quick Overview
Each background job fires at minutes t where t mod period_i equals offset_i. Given the (period, offset) pairs, return the smallest non-negative minute when every job fires at once, or -1 if that never happens. Periods need not be coprime.
Uber
November 29, 20260
0
0 solved
Each background job fires at minutes t where t mod period_i equals offset_i. Given the (period, offset) pairs, return the smallest non-negative minute when every job fires at once, or -1 if that never happens. Periods need not be coprime.
An Uber onsite math problem dressed as scheduling for marketplace batch jobs (surge recompute, payout sweeps, cache refresh). The interviewer looks for the Chinese Remainder Theorem generalized to non-coprime moduli, plus careful handling of the impossible case.
What the Interviewer Expects
- Recognizes a system of congruences
- Merges two congruences at a time using the extended gcd
- Detects inconsistency when offsets differ mod gcd
- Keeps numbers bounded by reducing mod lcm
- Explains why brute force over lcm is too slow
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 return the first k common minutes after a given time?
- What if a job can drift by up to one minute?
- How large can the lcm get, and what does that mean for 64-bit languages?
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: list of (period, offset) with period >= 1 and 0 <= offset < period. Output: smallest t >= 0 satisfying all t = offset_i (mod period_i), or -1. Brute force up to the lcm can be astrono...
High-Level Design
Fold the congruences pairwise. Current state is t = r (mod m). To add t = a (mod n), write t = r + m*k and solve m*k = a - r (mod n). Let g = gcd(m, n). A solution exists only if g divides...