File Download Coverage Percentage
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) → intExamples
Example 1
totalChunks = 5intervals = [[3,4]]requireTwice = falsereturn = 40Two of five chunks were downloaded.
Example 2
totalChunks = 5intervals = [[1,5],[1,5]]requireTwice = truereturn = 100Every chunk appears in both intervals.
Example 3
totalChunks = 5intervals = [[1,5],[2,5]]requireTwice = truereturn = 0Chunk 1 was downloaded only once.
Constraints
1 <= totalChunks <= 100000.0 <= intervals.length <= 100000.1 <= start <= end <= totalChunks.