Skip to content
DeepForgeby svx
All problems
MediumData Structuresds-278

Write Buffer Coalescing

Problem

Coalesce buffered writes to measure how many were merged.

writes is a list of [start, end) byte ranges. Ranges that overlap or touch merge into one; after merging, report how many input writes disappeared into merges and the total covered bytes.

Return [coalesced_count, total_bytes].

Hint

Touching ranges where the next start equals the current end also merge.

Test cases

case 1
in: [[[0,4],[4,8],[10,12]]]
expected: [1,10]
case 2
in: [[]]
expected: [0,0]
case 3
in: [[[5,6]]]
expected: [0,1]
case 4
in: [[[1,3],[2,5],[7,9],[8,10]]]
expected: [2,7]
Starter codePython
def coalesce_writes(writes):
    # Your code here
    pass

4 test cases · run your code against them in the editor