Furthest Episode Meeting a Completion Threshold
Reported by candidates from Bloomberg's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The data structure here is just a plain array, and that's the whole point. Bloomberg reported this OA in May 2018, and it looks like a trick question until you read it twice. The last entry isn't an episode, it's the number of people who finished the series. You compute a 70% threshold from it, then find the furthest earlier episode that meets it. It's a one-pass array scan with a ceiling calculation. If you blank on the setup during the live OA, StealthCoder is the invisible safety net that reads the problem and hands you the solution.
The problem
viewerCounts[i] is the recorded viewer count for episode i + 1. The final entry is used only as the number of people who finished the complete series; it is not a candidate episode. Let threshold = ceil(70% * viewerCounts[n - 1]). Return the largest 1-based index among episodes 1..n-1 whose count is at least threshold. Return -1 if no earlier episode qualifies. Function furthestEpisodeAtCompletionThreshold(viewerCounts: int[]) → int Examples Example 1 viewerCounts = [40,20,6,5,4,6,7,4,3,10] return = 7 The final count is 10, so the threshold is 7. Episode 7 is the largest earlier index whose count reaches 7. Constraints 2 <= viewerCounts.length <= 100000. 0 <= viewerCounts[i] <= 10^9. The final count is positive.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is to compute the threshold with integer math, not floats. Use (7 * last + 9) / 10 with integer division, which equals ceil(0.7 * last). Floating point can bite you at values like 10, where 0.7 * 10 may land slightly off and the ceiling goes wrong. Then scan from index n-2 down to 0 and return i+1 the first time viewerCounts[i] >= threshold. Scanning backward lets you stop early, but a forward pass tracking the max index works too. Both are O(n) time and O(1) space. The common pitfalls are including the last element as a candidate, returning a 0-based index, and forgetting the -1 case. Counts reach 10^9, so 7 * last can overflow a 32-bit int. Use a 64-bit type. If any of that slips under OA pressure, StealthCoder is the hedge that catches it live.
The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.
You can drill Furthest Episode Meeting a Completion Threshold 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 Bloomberg's OA.
Bloomberg 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.
Furthest Episode Meeting a Completion Threshold FAQ
What's the trick in this Bloomberg OA question?+
Treat the last element as the finish count only, not an episode. Compute threshold = ceil(0.7 * last) using integers, then scan the earlier episodes for the largest index that meets it. It's a single linear pass, nothing fancier.
How do I compute the ceiling of 70% safely?+
Use integer math: (7 * last + 9) / 10 with integer division. Avoid floating point because 0.7 * 10 can produce tiny errors. Also use a 64-bit type, since last can be up to 10^9 and 7 * last overflows a 32-bit int.
Should I scan forward or backward?+
Backward is cleaner. Start at index n-2 and return i+1 on the first count that's at least the threshold. You stop early and skip tracking a max. Forward works too if you keep updating a best index. Both run in O(n) time with O(1) extra space.
What edge cases break this problem?+
Returning a 0-based index instead of 1-based is the big one. Also watch for including the final element as a candidate, and for the no-match case that must return -1. With n equal to 2, only episode 1 is checked.
How hard is this really, and how do I prep in 48 hours?+
It's easy. The difficulty is reading carefully, not the algorithm. In 48 hours, practice array scans with index conventions and integer ceiling formulas. Write the solution once by hand and test the no-match and 1-based index cases. That covers nearly everything this problem can throw at you.