A bank account has a sequence of money transactions. A positive amount represents money received, while a negative amount represents money sent.
Find the longest consecutive transaction sequence whose net amount is exactly targetNetAmount.
Return only the number of transactions in that sequence.
TransactionAnalyzer
public int longestNetSequence( List<Integer> transactionAmounts, int targetNetAmount)
transactionAmounts contains the transaction amounts in chronological order.targetNetAmount is the required net transaction amount.targetNetAmount.0 if no such sequence exists.targetNetAmount exactly.transactionAmounts list must not be modified.1 ≤ transactionAmounts.size() ≤ 200,000-10,000 ≤ transactionAmounts.get(i) ≤ 10,000-1,000,000,000 ≤ targetNetAmount ≤ 1,000,000,000transactionAmounts and its elements are never null.longestNetSequence( transactionAmounts = List.of(500, -200, 300, -100, 400, -300, 200), targetNetAmount = 900)
Output: 5
The first five transactions have a net amount of 500 - 200 + 300 - 100 + 400 = 900.
longestNetSequence( transactionAmounts = List.of(200, -500, 100, -200, 300, -100), targetNetAmount = -300)
Output: 4
The transactions -500, 100, -200, 300 have a net amount of -300.
longestNetSequence( transactionAmounts = List.of(100, 200, -50), targetNetAmount = 1,000)
Output: 0
No consecutive transaction sequence has a net amount of 1,000.