Skip to content

Latest commit

 

History

History
14 lines (10 loc) · 556 Bytes

subarrays_sum_equals_length.md

File metadata and controls

14 lines (10 loc) · 556 Bytes

Count of subarrays having sum equal to its length

similar to

Explanation
  • You need to remember subarray(i, j) = prefix(i) - prefix(j)
  • relation reduced to prefix(i) - prefix(j) = i - j
  • relation reduced to prefix(i) - i = prefix(j) - j
  • count how much similar no.s present, apply nC2, as 2 distinct points make a subarray.
  • corner case, count each one individually.