All problems
1037EasyArray

The Biggest Later Rise

Tracked in this browser only
Write code

Trains the technique from

LeetCode 2016Maximum Difference Between Increasing Elements

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

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 is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def maximum_difference(readings: list[int]) -> int:
Java
public int maximumDifference(int[] readings)
September 7
Apply