<p>You are given an integer array <code>prices</code> representing the daily price history of a stock, where <code>prices[i]</code> is the stock price on the <code>i<sup>th</sup></code> day.</p>

<p>A <strong>smooth descent period</strong> of a stock consists of <strong>one or more contiguous</strong> days such that the price on each day is <strong>lower</strong> than the price on the <strong>preceding day</strong> by <strong>exactly</strong> <code>1</code>. The first day of the period is exempted from this rule.</p>

<p>Return <em>the number of <strong>smooth descent periods</strong></em>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> prices = [3,2,1,4]
<strong>Output:</strong> 7
<strong>Explanation:</strong> There are 7 smooth descent periods:
[3], [2], [1], [4], [3,2], [2,1], and [3,2,1]
Note that a period with one day is a smooth descent period by the definition.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> prices = [8,6,7,7]
<strong>Output:</strong> 4
<strong>Explanation:</strong> There are 4 smooth descent periods: [8], [6], [7], and [7]
Note that [8,6] is not a smooth descent period as 8 - 6 &ne; 1.
</pre>

<p><strong class="example">Example 3:</strong></p>

<pre>
<strong>Input:</strong> prices = [1]
<strong>Output:</strong> 1
<strong>Explanation:</strong> There is 1 smooth descent period: [1]
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= prices.length &lt;= 10<sup>5</sup></code></li>
	<li><code>1 &lt;= prices[i] &lt;= 10<sup>5</sup></code></li>
</ul>

class Solution:
    def getDescentPeriods(self, prices: List[int]) -> int:
        '''Approach: Sliding Window with Math. The problem asks to count the number
        of smooth descent periods of a stock. So for that case what if we find
        a window that fullfils the smooth descent period that would be counted one.
        but also if we found the maximum window avaliable in that slot then all sub
        windows are also eligible. For that case we can generate a math formula using
        some proofs which will end up being the combnatorics of n with 2. Then we
        will do this for every window that fullfills the criteria. One thing not to
        forget is each day also fullfills the criteria for that case we are expected
        to add the length of the given price on the final answer'''

        #Step1: declare variables for ease of use
        left, right = 0, 1
        length = len(prices) #due to the fact that every element also fullfills the criteria
        answer = length

        #Step2: iterate until the list gets exhausted
        while right < length:

            #check if the current window is fullfilling the criteria
            while right < length and prices[right - 1] - prices[right] == 1:
                right += 1

            window = right - left
            cur = (window - 1) * window // 2
            answer += cur
            left = right
            right += 1

        return answer
        #Time Complexity: O(n)
        #Space Complexity: O(1)


322