Maximum Difference Between Increasing Elements
Real-world version: The Biggest Later RiseThe statement here is our own: the same inputs, outputs and technique.
A log holds the readings readings.
Return the largest amount by which some reading exceeds an earlier reading, or -1 when no reading in the log exceeds any reading before it.
Examples
Example 1
- Input
- readings = [8, 2, 9]
- Output
- 7
The 9 at the end exceeds the 2 before it by seven, which beats the 9 measured against the 8 at the front.
Example 2
- Input
- readings = [5, 4, 3]
- Output
- -1
Every reading is below the one before it, so nothing anywhere exceeds an earlier reading.
Example 3
- Input
- readings = [3, 8, 1, 9, 2]
- Output
- 8
The 9 measured against the 1 before it gives eight. The 8 near the front measured against the 3 gives only five, and nothing later beats eight.
Constraints
- 2 <= readings.length <= 1000
- 1 <= readings[i] <= 10^9
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def maximum_difference(readings: list[int]) -> int:public int maximumDifference(int[] readings)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 15 test cases: 15 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's