Number of Smooth Descent Periods of a Stock LeetCode solution in C++
1class Solution {2public:3long long getDescentPeriods(vector<int> &prices) {4int n = prices.size();5int start = 0;6int end = 0;7long long ans = 1; // since, we will be starting our iteration from ist8// index910for (end = 1; end < n; end++) {11if (prices[end] == prices[end - 1] - 1) {12ans += end - start + 1;13}1415else {16start = end;17ans += end - start + 1;18}19}2021return ans;22}23};