Count Blocks Freed by Deleting Each Snapshot Copy
Last updated: November 29, 2026
Quick Overview
A volume has a set of block IDs referenced by the active file system and several snapshots, each a set of block IDs. For each snapshot, return how many blocks would be returned to free space if only that snapshot were deleted.
Netapp
November 29, 20260
0
0 solved
A volume has a set of block IDs referenced by the active file system and several snapshots, each a set of block IDs. For each snapshot, return how many blocks would be returned to free space if only that snapshot were deleted.
ONTAP Snapshot copies share blocks with the active file system and with each other, so the space a snapshot 'uses' is only the blocks nobody else references. This warm-up checks that you can reason about shared ownership with sets and counters and explain why the naive sum of snapshot sizes overstates reclaimable space.
What the Interviewer Expects
- Recognizes a block is freed only if no other snapshot and not the active file system references it
- Builds a reference count across snapshots in one pass instead of comparing every pair
- Deduplicates block IDs within a single snapshot before counting
- Runs in time linear in the total number of block references
- Explains why per-snapshot reclaimable totals do not add up to the space freed by deleting several snapshots together
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you answer 'how much space is freed if I delete snapshots A and C together'?
- Snapshots are stored as bitmaps of 2 billion blocks. How does the approach change?
- How would you keep these numbers current as new writes and snapshots arrive, without recomputing from scratch?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Inputs: active, the block IDs the live file system points to, and snapshots, a map from snapshot name to block IDs. Output: for each snapshot, the count of blocks referenced by that snapshot and b...
High-Level Design
A block is freeable for snapshot S if S references it, no other snapshot references it, and the active file system does not. So count, for every block, how many snapshots hold it. Then for each snapsh...