Rising readings
EasyOnline Assessment
Count how many readings are strictly greater than the reading immediately before them.
A monitor records integer readings in the order they arrived. Compare each reading with the one just before it; the very first reading has no predecessor, so it is never counted. A reading equal to its predecessor does not count.
Input: readings, a list of integers.
Output: an integer, the number of positions i >= 1 where readings[i] > readings[i - 1]. If readings has fewer than two entries, return 0.
Example 1
- Input:
- [[3,6,4,4,9]]
- Output:
- 2
- Explanation
- 6 is greater than 3 and 9 is greater than 4, so those two count. 4 is lower than 6 and the second 4 only equals the first, so neither counts.
Example 2
- Input:
- [[1,2,3,4,5]]
- Output:
- 4
- Explanation
- Every reading after the first is larger than the one before it, so all 4 comparisons count.
Example 3
- Input:
- [[8,5,5,3]]
- Output:
- 0
- Explanation
- The readings never go up: 5 is lower than 8, the second 5 equals the first, and 3 is lower than 5. The answer is 0.
Constraints
0 <= readings.length <= 10,000-1,000,000 <= readings[i] <= 1,000,000