Skip to content

Practice Number of Smooth Descent Periods of a Stock

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#2110
LeetCode Problem

Number of Smooth Descent Periods of a Stock

Problem Statement

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.

Source: Number of Smooth Descent Periods of a Stock on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
prices = [3,2,1,4]
Output
7

# Example 2

Input
prices = [8,6,7,7]
Output
4

# Example 3

Input
prices = [1]
Output
1

Constraints

1 <= prices.length <= 10^5
1 <= prices[i] <= 10^5

Related LeetCode Problems

Practice more problems similar to Number of Smooth Descent Periods of a Stock.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.