Problem · Array

Maximum Forward Difference

Learn this problem
EasyAtlassian logoAtlassianFULLTIMEOA

Problem statement

Return the maximum nums[j] - nums[i] over indices i < j with nums[i] <= nums[j]. Return -1 when no pair exists.

Function

maximumDifference(nums: int[]) → int

Examples

Example 1

nums = [7,2,3,10,1]return = 8

Choose 2 before 10; the later 1 cannot be paired backward with 10.

Constraints

  • 1 <= nums.length <= 100000
  • Values fit in a signed 32-bit integer and the result fits in int.

More Atlassian problems

drafts saved locally
public int maximumDifference(int[] nums) {
  // Write your code here.
}
nums[7,2,3,10,1]
expected8
checking account