Given a 0-indexed integer array nums
of size n
, find the maximum difference nums[j] - nums[i]
such that 0 <= i < j < n
and nums[i] < nums[j]
. Return the maximum difference; if no such pair exists, return -1.
June 16, 2025About 2 min
Given a 0-indexed integer array nums
of size n
, find the maximum difference nums[j] - nums[i]
such that 0 <= i < j < n
and nums[i] < nums[j]
. Return the maximum difference; if no such pair exists, return -1.