Skip to content
DeepForgeby svx
All problems
MediumData Structuresds-285

Leveled Compaction Score

Problem

Compute leveled compaction scores for an LSM tree.

The score of a level is its file count divided by its capacity; levels over 1.0 are candidates for compaction. levels and capacities are parallel lists.

Return the list of scores as floats.

Hint

A score above one means the level has more files than its target capacity.

Test cases

case 1
in: [[4,2,0],[2,4,8]]
expected: [2,0.5,0]
case 2
in: [[3,5],[3,10]]
expected: [1,0.5]
case 3
in: [[0,0],[1,1]]
expected: [0,0]
case 4
in: [[10,1],[2,100]]
expected: [5,0.01]
Starter codePython
def compaction_scores(levels, capacities):
    # Your code here
    pass

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