Show problems as
Classic problem #2016EasyArray

Maximum Difference Between Increasing Elements

Real-world version: The Biggest Later Rise
Tracked in this browser only
Read Maximum Difference Between Increasing Elements on LeetCode(opens in a new tab)

The 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.

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