Apply Hourly and Daily Retention to VM Snapshot Schedules
Last updated: November 29, 2026
Quick Overview
Given a list of snapshots for one VM as (snapshot_id, epoch_seconds) and the current time, return the ids to keep under a policy that retains the newest snapshot in each of the last 24 hours and the newest snapshot in each of the last 7 days. Everything else is eligible for deletion.
Nutanix
November 29, 20260
0
0 solved
Given a list of snapshots for one VM as (snapshot_id, epoch_seconds) and the current time, return the ids to keep under a policy that retains the newest snapshot in each of the last 24 hours and the newest snapshot in each of the last 7 days. Everything else is eligible for deletion.
Protection policies in Prism let customers schedule frequent local snapshots with tiered retention, and the snapshot service has to decide which snapshots to expire on every run. In a phone screen this checks whether you can turn a policy into clean bucketing code and reason about boundaries such as a snapshot that counts for both the hourly and daily tier.
What the Interviewer Expects
- Buckets timestamps by hour and by day with integer division
- Keeps the newest snapshot per bucket rather than the first seen
- Uses a set so a snapshot kept by both tiers appears once
- Handles window boundaries and future timestamps explicitly
- Runs in O(n) time
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 add weekly and monthly tiers without duplicating code?
- Customers are in different time zones. How do day buckets change?
- A snapshot is referenced by a replication job in flight. How do you avoid deleting it?
- How would you make expiry idempotent if the service crashes halfway through deletes?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: snaps as (id, ts) pairs in any order, and now. A snapshot is hourly-eligible if now - ts < 24h and daily-eligible if now - ts < 7d. Within each hour bucket and each day bucket, keep o...
High-Level Design
Two dictionaries: hour -> (id, ts) and day -> (id, ts), where hour = ts // 3600 and day = ts // 86400. One pass over the snapshots updates whichever tiers the snapshot is eligible for, replaci...