Given a 0-indexed integer array nums of size n, find the maximum value of nums[j] - nums[i] over all pairs 0 <= i < j < n with nums[i] < nums[j]. Return that maximum, or -1 if no such pair exists.
Given a 0-indexed integer array nums of size n, find the maximum value of nums[j] - nums[i] over all pairs 0 <= i < j < n with nums[i] < nums[j]. Return that maximum, or -1 if no such pair exists.
Example 1:
Input: {"nums":[7,1,5,4]}
Output: 4
Constraints:
n=nums.length
2≤n≤1000
1≤nums[i]≤109
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"nums":[7,1,5,4]}
best starts at -1, meaning no increasing pair has been found yet.