FastPrepFile Download Coverage Percentage

File Download Coverage Percentage

Persona logoPersona● MediumINTERNOA
Learn

Problem statement

A file has chunks numbered 1..totalChunks. Each inclusive interval records one completed download of every chunk in that range.

If requireTwice is false, return the integer percentage of chunks downloaded at least once, rounded down. If it is true, return 100 only when every chunk was downloaded at least twice; otherwise return 0.

Function

downloadCoveragePercent(totalChunks: int, intervals: int[][], requireTwice: boolean) → int

Examples

Example 1

totalChunks = 5intervals = [[3,4]]requireTwice = falsereturn = 40

Two of five chunks were downloaded.

Example 2

totalChunks = 5intervals = [[1,5],[1,5]]requireTwice = truereturn = 100

Every chunk appears in both intervals.

Example 3

totalChunks = 5intervals = [[1,5],[2,5]]requireTwice = truereturn = 0

Chunk 1 was downloaded only once.

Constraints

  • 1 <= totalChunks <= 100000.
  • 0 <= intervals.length <= 100000.
  • 1 <= start <= end <= totalChunks.

More Persona problems

See Persona hiring insights
public int downloadCoveragePercent(int totalChunks, int[][] intervals, boolean requireTwice) {
    // Compute ordinary or double coverage.
}
totalChunks5
intervals[[3,4]]
requireTwicefalse
expected40
Checking account…