THINK FIRST·CODE LATER

← All labs

Retention policy enforcer

Problem

Implement StudyBuddy's storage-limitation job, which runs every night.

Input:

TODAY day
POLICY
<lines: dataType retentionDays>
DATA
<lines: itemId dataType createdDay [HOLD]>

Days are integers (day numbers). An item must be deleted if today - createdDay >= retentionDays for its type — unless it is marked HOLD (a legal hold, e.g., an ongoing misconduct case), in which case it is kept and reported. An item whose type has no policy is flagged: itemId: NO POLICY (review) — data without a retention rule is a finding, not something to keep silently.

Output per item, in input order: itemId: KEEP (d days left), itemId: DELETE (expired d days ago) (d = today - createdDay - retentionDays; 0 means it expires today), itemId: KEEP (legal hold, expired) or itemId: KEEP (legal hold) depending on whether it would otherwise be expired, or itemId: NO POLICY (review).

At the end: Delete: x, Keep: y, Hold: h, No policy: z.

Input:

TODAY 200
POLICY
chat 90
post 180
log 30
DATA
c1 chat 100
c2 chat 150
p1 post 10
p2 post 30 HOLD
l1 log 170
x1 photo 50

Output:

c1: DELETE (expired 10 days ago)
c2: KEEP (40 days left)
p1: DELETE (expired 10 days ago)
p2: KEEP (legal hold)
l1: DELETE (expired 0 days ago)
x1: NO POLICY (review)
Delete: 3, Keep: 1, Hold: 1, No policy: 1

Write it here or in your IDE, then paste it. Compile and test it yourself before comparing. Your code stays in your browser — it is never sent to or stored on the server.