Problem bank

Problem 242 of 333MediumCodingP242

Count P&L windows summing to k

  1. You are given a list of daily P&L values (integers, possibly negative) and a target kk. Count the contiguous stretches of days whose total P&L is exactly kk. For example, with P&L [1,2,−1,1,2,−3,3][1, 2, -1, 1, 2, -3, 3] and k=3k = 3 the answer is 5. Aim for O(n)O(n) time.