# LeetCode 2110. Number of Smooth Descent Periods of a Stock in F#

## URL

[Number of Smooth Descent Periods of a Stock - LeetCode](https://leetcode.com/problems/number-of-smooth-descent-periods-of-a-stock/description/?envType=daily-question&envId=2025-12-15)

## Code

[dotnet-study/fsharp/leetcode/challenge/202512/number\_of\_smooth\_descent\_periods\_of\_a\_stock/main.fsx at master · syohex/dotnet-study](https://github.com/syohex/dotnet-study/blob/master/fsharp/leetcode/challenge/202512/number_of_smooth_descent_periods_of_a_stock/main.fsx)

```fsharp
let getDescentPeriods (prices: int list) : int64 =
    let len = List.length prices

    let countCombinations left right =
        let count = right - left
        (1 + count) * count / 2

    let rec getDescentPeriods' prices prev left acc =
        match prices with
        | [] -> acc + (int64 <| countCombinations left len)
        | (i, h) :: t ->
            if h = prev - 1 then
                getDescentPeriods' t h left acc
            else
                let acc = acc + (int64 <| countCombinations left i)
                getDescentPeriods' t h i acc

    let prev = List.head prices
    let prices = prices |> List.indexed |> List.skip 1
    getDescentPeriods' prices prev 0 0L
```
