LeetCode Challenge Day 91 β 2110. Number of Smooth Descent Periods of a Stock
Nitin Ahirwal / December 15, 2025
Hey folks π
This is Day 91 of my LeetCode streak π
Today's problem is 2110. Number of Smooth Descent Periods of a Stock β a clean problem where consistency in thinking beats brute force.
π Problem Statement
You are given an integer array prices, where prices[i] represents the stock price on the i-th day.
A smooth descent period:
- Consists of one or more contiguous days
- Each day's price is exactly 1 less than the previous day
- A single day always counts as a valid period
Goal:
Return the total number of smooth descent periods.
π‘ Intuition
Every individual day forms a valid smooth descent period.
The important observation is:
A smooth descent only continues when the price drops by exactly 1.
So instead of checking all possible subarrays, we track:
- The length of the current descending streak
- How many valid periods end at each day
If a streak has length k, it contributes k smooth descent periods ending at that position.
π Approach
- Initialize:
curr = 1β current descent streak lengthans = 1β the first day itself
- Traverse the array from index
1:- If
prices[i - 1] - prices[i] === 1, incrementcurr - Otherwise, reset
currto1
- If
- Add
currtoansat each step - Return
ansafter completing the traversal
This ensures all valid periods are counted efficiently in one pass.
β±οΈ Complexity Analysis
-
Time Complexity:
O(n)β single pass through the array -
Space Complexity:
O(1)β constant extra space
π§βπ» Code (JavaScript)
/**
* @param {number[]} prices
* @return {number}
*/
var getDescentPeriods = function(prices) {
let ans = 1; // first day itself
let curr = 1; // current descent length
for (let i = 1; i < prices.length; i++) {
if (prices[i - 1] - prices[i] === 1) {
curr += 1; // extend descent
} else {
curr = 1; // reset
}
ans += curr;
}
return ans;
};
π― Reflection
This problem reinforces a core lesson:
-
Track what ends at the current index
-
Let patterns accumulate naturally
-
One-pass solutions are often hiding in plain sight
That wraps up Day 91 of my LeetCode challenge π₯
Staying consistent, one problem at a time π
Happy Coding π¨βπ»