Link: https://leetcode.com/problems/arithmetic-slices/
Solution:
Topics: greedy, subarray, reservoir
Intuition
Basically this is what I like to call a reservoir pattern. If an arithmetic slice contains N slices, then a newly added element creates exactly N+1 more slices. In other words, our current reservoir gets reabsorbed every time our slice grows (and plus one).
For example:
When our slice ends, we just set our current
variable to 0, signifying that we are no longer counting an arithmetic sequence.
Implementation
Visual