Three Calls Within Three Seconds
Reported by candidates from Bloomberg's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The Bloomberg OA from February 2020 looks like a rate limiter, but it reduces to one question: how far back is the call two positions earlier? Timestamps come in nondecreasing order, and after each call you say whether the current call plus the two before it fit inside 3000 ms. If you're taking this OA in a day or two, relax. It's a short array problem with no real data structure needed. The trap is overbuilding it. If you blank on the simplest version, StealthCoder is the hedge running invisibly during the live assessment.
The problem
timestamps are nondecreasing call times in milliseconds. After each call, return whether at least three calls including the current one lie within a window of at most 3000 milliseconds, meaning current time minus the third-most-recent qualifying time is at most 3000. Function threeCallsWithinWindow(timestamps: long[]) → boolean[] Examples Example 1 timestamps = [0,1000,3000,7000,7500,8000] return = [false,false,true,false,false,true] Calls 0,1000,3000 fit exactly; later 7000,7500,8000 also fit. Constraints 0 <= timestamps.length <= 2 * 10^5. Timestamps are nondecreasing.
Reported by candidates. Source: FastPrep
Pattern and pitfall
Because timestamps never decrease, the three most recent calls are always the last three entries. So for index i, the answer is false when i < 2, otherwise timestamps[i] - timestamps[i-2] <= 3000. That's O(n) time and O(n) output, with no deque and no sliding window needed. Check it on the example: at index 2, 3000 - 0 = 3000, which is within the limit, so true. At index 3, 7000 - 1000 = 6000, so false. At index 5, 8000 - 7000 = 1000, so true. Common pitfalls: using < instead of <=, which breaks the exact-3000 case. Using int instead of long for the timestamps. Forgetting the empty input, which should return an empty array. Don't build a queue and evict old entries unless you want extra bugs with 2 * 10^5 inputs. If your head goes blank mid-OA, StealthCoder can surface this two-index comparison as a backup.
Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.
You can drill Three Calls Within Three Seconds 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. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Bloomberg's OA.
Bloomberg reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Three Calls Within Three Seconds FAQ
What's the trick in Three Calls Within Three Seconds?+
Sorted timestamps mean the third-most-recent call is just index i-2. Compare timestamps[i] - timestamps[i-2] against 3000. For the first two calls, return false. No queue or window structure is required, so the whole solution is a single loop.
How hard is this Bloomberg OA question really?+
Easy. It's a single pass with one subtraction per element. The difficulty is in reading the statement carefully, since the wording about a qualifying third-most-recent time sounds more complex than it is. Most of the risk is off-by-one and boundary mistakes.
Should I use a sliding window or deque?+
You can, but you don't need to. A deque that evicts calls older than 3000 ms works, though it adds code and bug surface. Since you only care about exactly three calls, the index i-2 check is simpler and just as fast at O(n).
What edge cases should I test before submitting?+
Test an empty array, one or two calls, which must be false, and a gap of exactly 3000, which must be true. Also test duplicate timestamps, since nondecreasing allows equal values. Use long for timestamps to avoid overflow on large inputs.
How do I prepare for this in 48 hours?+
Write this solution once from memory, then run the sample by hand. Spend the remaining time on similar array and sliding window problems with boundary conditions. The skill that matters is reducing the wording to a simple index comparison, not memorizing structures.