FastPrepFastPrep
Problem Brief

Maximum Adjacent Gap

OA

Given an integer array nums, return the maximum absolute difference between two adjacent elements.

If the array contains fewer than two elements, return 0.

1Example 1

Input
nums = [3,8,2,10]
Output
8
Explanation
The adjacent absolute differences are 5, 6, and 8, so the maximum is 8.

2Example 2

Input
nums = [7]
Output
0
Explanation
There are no adjacent pairs.

3Example 3

Input
nums = [-4,-10,6,1]
Output
16
Explanation
The largest adjacent absolute difference is between -10 and 6.

Constraints

Limits and guarantees your solution can rely on.

  • 1 <= nums.length <= 1000
  • -100000 <= nums[i] <= 100000
public int maxAdjacentGap(int[] nums) {
  // write your code here
}
Input

nums

[3,8,2,10]

Output

8

Sign in to submit your solution.