LeetCode solutions

2233. Number of Smooth Descent Periods of a Stock

My accepted Python solution to LeetCode problem 2233, Number of Smooth Descent Periods of a Stock, running in 71ms.

  • Difficulty: Medium
  • Python
  • Runtime 71ms
  • Memory 31.7MB

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 71ms, memory 31.7MB, accepted 2025-12-30.

python
class Solution:
    def getDescentPeriods(self, prices: List[int]) -> int:
        n = len(prices)
        result = 0
        current_length = 1
        
        for i in range(1, n):
            if prices[i] == prices[i-1] - 1:
                current_length += 1
            else:
                # Add all subarrays from previous descent period
                result += (current_length * (current_length + 1)) // 2
                current_length = 1
        
        # Add remaining descent period
        result += (current_length * (current_length + 1)) // 2
        
        return result

Source