Missing Element in Sorted Array
Reported by candidates from Bloomberg's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The whole problem hinges on one array property: nums is strictly increasing, so you can count gaps without touching every integer. Bloomberg reported this one in October 2019, and it's a clean binary search disguised as a counting puzzle. You get a sorted array and a k up to 10^9, so any loop that walks value by value dies. If you've got an OA invite and 48 hours, learn the missing-count formula and you're mostly done. StealthCoder sits invisibly on your screen as a safety net if you blank mid-assessment, but the idea here is short enough to own tonight.
The problem
nums is strictly increasing. Starting after nums[0], consider positive integer values absent from the array in ascending order. Return the k-th missing value. Function missingElement(nums: int[], k: int) → int Examples Example 1 nums = [4,7,9,10] k = 3 return = 8 The missing values are 5, 6, and 8. Constraints 1 <= nums.length <= 5 * 10^4. 1 <= k <= 10^9. The answer fits in signed 32-bit range.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick: at index i, the number of missing values before nums[i] is nums[i] - nums[0] - i. That count never decreases as i grows, so it's monotonic and binary search fits. Find the smallest index i where missing(i) >= k. Then the answer sits between nums[i-1] and nums[i], and it equals nums[i-1] + (k - missing(i-1)). If no index reaches k, the answer is past the end: nums[last] + (k - missing(last)). Common pitfall: off-by-one on the boundary, and forgetting that counting starts after nums[0], not from 1. Another one is looping up to k, which is 10^9 and times out. Test with [4,7,9,10], k=3 and expect 8. If you freeze during the live Bloomberg OA, StealthCoder can hand you the binary search skeleton, but you should still trace the example yourself.
If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.
You can drill Missing Element in Sorted Array 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 by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as missing element in sorted array. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Bloomberg's OA.
Bloomberg reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Missing Element in Sorted Array FAQ
What's the trick in Missing Element in Sorted Array?+
Missing count before index i is nums[i] - nums[0] - i. It's non-decreasing, so binary search for the first index where that count reaches k. Then compute the answer from the previous element plus the leftover k. No value-by-value walking needed.
How hard is this really?+
Medium. The idea is short, but the boundary math trips people. If you've done binary search on a derived monotonic quantity before, this is about 15 minutes. If not, expect to burn time on off-by-one errors.
Why can't I just loop through numbers until I find the k-th missing?+
k goes up to 10^9. A linear walk over values is too slow. Even a linear scan over the array is fine at 5 * 10^4, but jumping by gap size is what matters. Binary search gets you O(log n).
What edge cases should I test?+
Test when the k-th missing value lies beyond the last element, when k is 1, and when the array has length 1. Also check the example [4,7,9,10] with k=3 returning 8. Those catch most boundary bugs.
How do I prep this in 48 hours?+
Write the missing-count function by hand, then code the binary search twice from scratch. Trace the Bloomberg example, then one case where the answer falls past the array end. Practice explaining why the count is monotonic.