Skip to content
LC-2110 Medium LeetCode

2110. Number of Smooth Descent Periods of a Stock

Read the full problem statement on LeetCode.
Difficulty: medium Acceptance: 59% Topics: Array, Math, Dynamic Programming
View full problem on LeetCode
Reference solution (spoiler · python)
# Time:  O(n)
# Space: O(1)

class Solution(object):
    def getDescentPeriods(self, prices):
        """
        :type prices: List[int]
        :rtype: int
        """
        result = l = 0
        for i in xrange(len(prices)):
            l += 1
            if i+1 == len(prices) or prices[i]-1 != prices[i+1]:
                result += l*(l+1)//2
                l = 0
        return result

Solution from kamyu104/LeetCode-Solutions · MIT