Skip to content

Practice Maximum Difference Between Increasing Elements

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Easy#2016
LeetCode Problem

Maximum Difference Between Increasing Elements

Problem Statement

Given a 0-indexed integer array nums of size n, find the maximum difference between nums[i] and nums[j] (i.e., nums[j] - nums[i]), such that 0 <= i < j < n and nums[i] < nums[j]. Return the maximum difference. If no such i and j exists, return -1.

Source: Maximum Difference Between Increasing Elements on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums = [7,1,5,4]
Output
4

# Example 2

Input
nums = [9,4,3,2]
Output
-1

# Example 3

Input
nums = [1,5,2,10]
Output
9

Constraints

n == nums.length
2 <= n <= 1000
1 <= nums[i] <= 10^9

Related LeetCode Problems

Practice more problems similar to Maximum Difference Between Increasing Elements.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.