FastPrepFurthest Episode Meeting a Completion Threshold

Furthest Episode Meeting a Completion Threshold

Bloomberg LP logoBloomberg LP● EasyNEW GRADONSITE INTERVIEW
Learn

Problem statement

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.

More Bloomberg LP problems

See Bloomberg LP hiring insights
public int furthestEpisodeAtCompletionThreshold(int[] viewerCounts) {
  // Write your code here.
}
viewerCounts[40,20,6,5,4,6,7,4,3,10]
expected7
Checking account…