PIXELBANKv9.1.0
Menu

Problem Statement

Container images share layers by content digest. Given the layers of several images, compute the total on-disk size counting each unique layer digest only once.

Background

A registry stores each layer once, keyed by digest. The disk footprint of a set of images is the sum of sizes over distinct digests, even if many images reference the same layer.

Your Task

def total_disk(images):
  • images: list of images, each a list of (digest, size) tuples.
  • Return the summed size of unique digests (int).

Input Format

  • images (list of lists of (str, int)).

Output Format

  • A single int.

Sample

print(total_disk([[("a", 100), ("b", 50)], [("a", 100), ("c", 30)]]))

Output:

180

Example:

Input:
print(total_disk([[("a", 100), ("b", 50)], [("a", 100), ("c", 30)]]))
Output:
180
Reasoning:
  • Identify all unique layer digests across the two images. Image 1 contains layers "a" and "b", while Image 2 contains layers "a" and "c". The distinct set of digests is {"a","b","c"}\{\text{"a"}, \text{"b"}, \text{"c"}\}.
  • Determine the size associated with each unique digest. Since each digest maps to a single size, we have: "a" →\rightarrow 100, "b" →\rightarrow 50, and "c" →\rightarrow 30. Note that "a" appears in both images but is counted only once.
  • Sum the sizes of these unique layers to find the total disk footprint: 100+50+30=180100 + 50 + 30 = 180.
  • The final output is 180

Constraints:

  • Count each digest once (same digest implies same size).
  • Sum sizes of the distinct digests.
  • Return an int.
🔒

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.