Stock spread

Write codeEasy10 min

Your task

A warehouse dashboard shows the stock count of one product across several bins. Write a function that returns the spread of the counts: the difference between the largest and smallest values in the list. If the list is empty or has a single bin, the spread is 0. Example: counts [4, 9, 2, 7] gives a spread of 7 (9 minus 2).

Examples

stock_spread(counts: list[int]) -> int
Example 1
Inputstock_spread([4, 9, 2, 7])
Output7