THINK FIRST·CODE LATER

← All labs

Technical-debt register: what to repay first?

Problem

Plan technical-debt repayment for the next Sprint.

Input: first line capacityHours. Then items id principalHours interestHoursPerSprint risk until the end of input, where risk is LOW, MEDIUM or HIGH.

For each item compute the payback period principal / interest (in Sprints; if interest is 0, payback is infinite → print never). Order the items for repayment:

  1. all HIGH-risk items first,
  2. then by payback ascending (shorter first; never last),
  3. then by id alphabetically.

Go through the ordered list and select each item whose principal still fits in the remaining capacity (skip the ones that do not fit; smaller later items may still fit). Print the ordered list:

1. id: principal P h, interest I h/sprint, payback X sprints, risk R -> SELECTED|DEFERRED

(payback with one decimal or never), then Selected: h/capacity hours and Interest saved per sprint: s h (sum of interest of selected items).

Input:

16
matching-refactor 12 3 MEDIUM
notif-switch 6 4 LOW
no-tests-auth 10 1 HIGH
old-logging 2 0 LOW

Output:

1. no-tests-auth: principal 10 h, interest 1 h/sprint, payback 10.0 sprints, risk HIGH -> SELECTED
2. notif-switch: principal 6 h, interest 4 h/sprint, payback 1.5 sprints, risk LOW -> SELECTED
3. matching-refactor: principal 12 h, interest 3 h/sprint, payback 4.0 sprints, risk MEDIUM -> DEFERRED
4. old-logging: principal 2 h, interest 0 h/sprint, payback never, risk LOW -> DEFERRED
Selected: 16/16 hours
Interest saved per sprint: 5 h

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.