Count the days a closing price went up
Your task
A stock's daily closing prices are listed in date order. An analyst wants to know how often the price rose from one day to the next.
Write count_price_rises(prices) that returns how many days closed higher than the day before.
Input and output:
prices: a list of up to 100,000 closing prices in date order, each an integer between 0 and 1,000,000,000. It may be empty.- Returns an integer.
Rules:
- Compare each day only with the day immediately before it.
- A day counts only when its price is strictly greater than the day before. A tie does not count.
- The first day has no day before it, so it never counts. An empty list or a single day returns 0.
Examples
count_price_rises(prices: list[int]) -> intExample 1
Input
count_price_rises([3, 4, 2, 5, 5])Output
2Example 2
Input
count_price_rises([10, 10, 10])Output
0Example 3
Input
count_price_rises([1, 3, 2, 4])Output
2