Problem 220767 · easy · Phase 02 Linear Data Structures

Savings Goal Day

arrays · prefix-sums · first-index

transactions lists the daily changes to a savings account (deposits positive, withdrawals negative), starting from a balance of 0. Return the index of the first day on which the balance is at least target, or -1 if that never happens.

Examples

Input:  transactions = [50, 30, 40, 100], target = 100
Output: 2
Explanation: Balances are 50, 80, 120, 220; day 2 is the first to reach 100.

Input:  transactions = [10, 20], target = 100
Output: -1

Constraints

  • 0 <= len(transactions) <= 10**5
  • 1 <= target <= 10**9
  • Target: O(n) time; stop as soon as the goal is reached.

Goals

  • Combine a running total with an early return
  • Handle negative entries that pull the total back down
Starting Python…