You are given an integer array prices representing the daily price history of a stock, where prices[i] is the stock price on the ith day.

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

Return the number of smooth descent periods.

&nbsp;
Example 1:

Input: prices = [3,2,1,4]
Output: 7
Explanation: 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.


Example 2:

Input: prices = [8,6,7,7]
Output: 4
Explanation: There are 4 smooth descent periods: [8], [6], [7], and [7]
Note that [8,6] is not a smooth descent period as 8 - 6 ≠ 1.


Example 3:

Input: prices = [1]
Output: 1
Explanation: There is 1 smooth descent period: [1]


&nbsp;
Constraints:


	1 &lt;= prices.length &lt;= 105
	1 &lt;= prices[i] &lt;= 105


import sys
class Solution:
    def getDescentPeriods(self, prices: List[int]) -> int: 
        def calculate(k,ans):
            if k>1:
                ans+=((k-1)*(k))//2 
				#Sum of Natural Numbers
                return ans
            else:
                return ans
        end = 0
        start = 0
        prev= sys.maxsize
        k= 0
        ans = 0
        while end<len(prices):     
            if prev- prices[end]==1 or prev == sys.maxsize:
                k+=1
                prev = prices[end]
                end+=1    
            else:             
                ans = calculate(k,ans)
                start = end
                if end<len(prices):
                    prev = sys.maxsize
                k=0
        if k>1:
            ans = calculate(k,ans)
			
        return ans+len(prices)
class Solution {
    public long getDescentPeriods(int[] prices) {
        int i=0;
        int j=1;
        long ans=1;
        while(j<prices.length){
            if( prices[j-1]-prices[j]==1){
            //It means that j(current element) can be part of previous subarrays (j-i)
            //and can also start a subarray from me (+1). So add (j-i+1) in total Subarrays
                int count=j-i+1;
                ans+=count;
            }else{
            //It means that j cannot be part of previous subarrays but can start subarray from me. So, ans+=1
                i=j;
                ans+=1;
            }
            j++;
        }
        return ans;
    }
}
class Solution {
public:
    long long getDescentPeriods(vector<int>& prices) {
        long long ans = 0;
        long long temp = 0;
        for(int i=1; i<prices.size(); i++){
            if(prices[i - 1] - prices[i] == 1){
                temp++;
                ans += temp;
            }
            else{
                temp = 0;
            }
        }
        ans += prices.size();
        return ans;
    }
};
var getDescentPeriods = function(prices) {
    const n = prices.length;

    let left = 0;
    let totRes = 0;

    while (left < n) {
        let count = 1;

        let right = left + 1;

        while (right < n && prices[right] + 1 === prices[right - 1]) {
            count += (right - left + 1);
            ++right;
        }

        totRes += count;

        left = right;
    }

    return totRes;
};
Number of Smooth Descent Periods of a Stock