FastPrepEarliest Episode Meeting a Completion Threshold

Earliest Episode Meeting a Completion Threshold

Bloomberg LP logoBloomberg LP● EasyNEW GRADONSITE INTERVIEW
Learn

Problem statement

Each row of completionCounts describes one ten-episode series. completionCounts[s][e] is the number of users who finished episode e + 1 of series s. Counts in each row are nonincreasing because a user must finish an earlier episode before finishing a later one.

For each series, return the smallest one-based episode number n such that at least 70% of the users who finish episode n also finish episode 10. An episode with zero finishers does not qualify. Return -1 for a series when no episode qualifies.

Compare the ratio exactly with integer arithmetic: 10 * completionCounts[s][9] >= 7 * completionCounts[s][n - 1].

Function

earliestRetentionEpisodes(completionCounts: int[][]) → int[]

Examples

Example 1

completionCounts = [[100,95,90,85,80,75,70,70,70,70],[100,100,90,80,70,60,50,40,30,20],[100,0,0,0,0,0,0,0,0,0],[50,50,50,50,50,50,50,50,50,50]]return = [1,10,-1,1]

The first and fourth series meet the threshold from episode 1. The second first meets it at episode 10. The third loses everybody before completion, so no episode qualifies.

Example 2

completionCounts = [[100,90,80,70,60,50,40,35,35,35]]return = [6]

Episode 6 has 50 finishers and 35 finish the series, exactly 70%. Earlier episodes have a lower conditional completion rate.

Constraints

  • 1 <= completionCounts.length <= 100000.
  • Every row has exactly 10 values.
  • 0 <= completionCounts[s][e] <= 1000000000.
  • Each row is nonincreasing.
  • Use 64-bit arithmetic for the ratio comparison.

More Bloomberg LP problems

See Bloomberg LP hiring insights
public int[] earliestRetentionEpisodes(int[][] completionCounts) {
    // Write your code here.
}
completionCounts[[100,95,90,85,80,75,70,70,70,70],[100,100,90,80,70,60,50,40,30,20],[100,0,0,0,0,0,0,0,0,0],[50,50,50,50,50,50,50,50,50,50]]
expected[1,10,-1,1]
Checking account…