Skip to content
Get started

Subarrays summing to 3, negatives included

How many contiguous, non-empty subarrays of

[2, -1, 3, -2, 1, 2, -3, 4, -1, 2, 1, -2]

have sum exactly 33?

Show hints (2)+
  1. A subarray sum is a difference of two prefix sums.
  2. Count, for each prefix, how many earlier prefixes are exactly 3 smaller - and seed the map with P0=0P_0 = 0.

Answer

Reveal answer →

12

Create a free account to see the full worked solution and track your progress.

Interview format: Prop Trading, Systematic & Data-Driven Trading

Related questions