Score a cost advisor on savings that actually landed

Agent buildEasy10 minAmazon style

Your task

Engineers rightsizing cloud resources by hand never keep up, so an advisor agent proposes cost optimizations that a person approves. You score the agent on savings that actually landed, not on what it claims.

Write realized_savings_report(statuses, projected_savings, realized_savings, days_to_incident, incident_window_days): the report that scores the agent.

  • statuses (list of str): for each proposal, "applied" (approved and shipped), "proposed" or "rejected".
  • projected_savings (list of int): the savings the agent projected for each proposal.
  • realized_savings (list of int): how much the bill actually dropped. It may be negative.
  • days_to_incident (list of int): days from applying the change to the next incident on that resource, or -1 if none followed.
  • incident_window_days (int): an incident within this many days takes away a change's credit.
  • Index i in each list is one proposal. Return [identified, realized, credited, acceptance_pct].

Rules:

  1. identified is the sum of projected_savings over every proposal.
  2. realized is the sum of realized_savings over applied proposals only. A status other than exactly applied adds only to identified.
  3. credited is like realized, but leaves out any applied proposal whose days_to_incident is from 0 to incident_window_days, both ends included.
  4. acceptance_pct is the number of applied proposals times 100, divided by the number of proposals and rounded down. With no proposals it is 0.

Examples

realized_savings_report(statuses: list[str], projected_savings: list[int], realized_savings: list[int], days_to_incident: list[int], incident_window_days: int) -> list[int]
Example 1
Inputrealized_savings_report(["applied", "proposed", "rejected"], [1200, 800, 500], [900, 0, 0], [-1, -1, -1], 14)
Output[2500, 900, 900, 33]
Example 2
Inputrealized_savings_report(["applied", "applied"], [1000, 1000], [1000, 950], [3, -1], 14)
Output[2000, 1950, 950, 100]
Example 3
Inputrealized_savings_report(["applied", "rejected", "applied", "proposed"], [300, 900, 700, 250], [250, 0, 800, 0], [-1, -1, -1, -1], 14)
Output[2150, 1050, 1050, 50]