Fix the regression check for a shared discount function

Review the AI's codeEasy10 min

Your task

An AI agent refactored your applyDiscount(cart, code) function to support a new percent-off coupon. The coupon works, but the gift card and loyalty points flows call the same function. Before merging, your team runs every flow on fixed carts and compares each total before and after the change.

An assistant wrote find_changed_flows(flows, totals_before, totals_after). It is in the editor. It has a bug. Find it and fix it.

Input and output:

  • flows: the flow names, such as checkout or gift_card. A name can repeat.
  • totals_before: the total each flow produced before the change, in cents. Index i belongs to flows[i].
  • totals_after: the total each flow produced after the change, by the same index.
  • Return the flows to look at, in the order of flows.

Rules the tests check:

  • Check each entry of flows by its index, in order.
  • Flag the flow when either list has no total at its index. A flow that was not measured is not verified.
  • Flag the flow when its before and after totals differ.
  • Add the flow's name once for each flagged index, so a repeated name can appear more than once.

Examples

find_changed_flows(flows: list[str], totals_before: list[int], totals_after: list[int]) -> list[str]
Example 1
Inputfind_changed_flows(["checkout", "gift_card", "loyalty"], [1000, 500, 800], [900, 500, 800])
Output["checkout"]
Example 2
Inputfind_changed_flows(["checkout", "gift_card", "loyalty"], [1000, 500, 800], [900, 450, 800])
Output["checkout", "gift_card"]
Example 3
Inputfind_changed_flows(["checkout", "gift_card"], [1000, 500], [1000, 500])
Output[]