Maximum Later Difference
Problem statement
Choose indices i < j in nums such that nums[j] > nums[i]. Return the largest possible difference nums[j] - nums[i].
Return -1 when no strictly positive later-minus-earlier difference exists. Equal values do not form a valid pair.
Function
maximumLaterDifference(nums: int[]) → intExamples
Example 1
nums = [3,6,10,1,4,6,5]return = 7The value ten appears after three, producing the source example's difference seven.
Example 2
nums = [5,5,4]return = -1All later differences are zero or negative.
Constraints
1 <= nums.length <= 10^5.-10^9 <= nums[i] <= 10^9.