Total Server Downtime
Reported by candidates from Visa's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The naive version of Total Server Downtime looks easy until overlapping intervals double-count your uptime. Visa reported this one in September 2026, and it's a merge-intervals problem wearing a monitoring costume. You've got an OA coming and maybe 48 hours. The trap is that t goes up to 10^9, so you can't mark every second in an array. Sort, merge, subtract. If your head goes blank mid-assessment, StealthCoder runs invisibly as a safety net and shows you the merge logic while you type.
The problem
A server is monitored during every integer second from 1 through t, inclusive. You are given intervals, where intervals[i] = [start, end] means the server was running from second start through second end, inclusive. The uptime intervals may overlap. Return the total number of seconds in the monitoring window during which the server was not running. Function getTotalDowntime(intervals: int[][], t: int) → int Examples Example 1 intervals = [[1,3],[2,5]] t = 10 return = 5 The intervals overlap and cover seconds 1 through 5. The server is down during seconds 6 through 10, for a total of 5 seconds. Example 2 intervals = [[2,2],[5,7]] t = 8 return = 4 The server is up for seconds 2, 5, 6, and 7. Four of the eight monitored seconds are downtime. Example 3 intervals = [[1,2],[2,4],[7,8]] t = 9 return = 3 The first two intervals merge into [1,4], and [7,8] is separate. The server is up for 6 of the 9 monitored seconds, so total downtime is 3. Constraints 1 <= intervals.length <= 2 * 10^5. 1 <= t <= 10^9. 1 <= intervals[i][0] <= intervals[i][1] <= t.
Reported by candidates. Source: FastPrep
Pattern and pitfall
Sort intervals by start. Walk through them, tracking the end of the current merged block. If the next start is at most curEnd, extend curEnd with max(curEnd, end). Otherwise close the block and add (curEnd - curStart + 1) to uptime. Downtime is t minus total uptime. The edge case that breaks a naive solution is inclusivity. Intervals are inclusive on both ends, so [1,2] and [2,4] overlap, and a block length is end - start + 1. Another version of the trap is adjacent intervals like [1,2] and [3,4]. They don't overlap, but the counts still add correctly, so you don't need special handling. A boolean array of size t blows memory at 10^9. Sorting costs O(n log n) with n up to 2 * 10^5, which is fine. If you freeze on the merge condition during the live OA, StealthCoder is the hedge that gives you the working loop.
The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.
You can drill Total Server Downtime cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Visa's OA.
Visa reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Total Server Downtime FAQ
How hard is Total Server Downtime really?+
Easy to medium. It's the classic merge intervals pattern with one final subtraction. If you've seen merging overlapping intervals before, you can write it in ten minutes. The difficulty is only in the inclusive-endpoint math and the huge t value.
What's the trick to solve it?+
Sort by start, merge overlapping intervals, sum the merged lengths as end - start + 1, then return t minus that sum. Never build an array of size t, since t can reach 10^9.
Why does a boolean array of size t fail?+
With t up to 10^9, allocating a per-second array uses gigabytes of memory and takes too long to fill. Interval merging only touches the n intervals, so it runs in O(n log n) regardless of how large t is.
What edge cases should I test before submitting?+
Test touching intervals like [1,2],[2,4], which overlap and must merge. Test a single-second interval like [2,2]. Test one interval covering the whole window 1 to t, which should return 0. Test fully nested intervals, where max on the end matters.
How do I prepare for this in 48 hours?+
Write merge intervals from scratch twice, without looking. Then solve this one with the three examples from the problem. Focus on the sort comparator, the max update on the end, and the +1 for inclusive lengths. That covers nearly everything this Visa question tests.