Problem · Array
Maximum Adjacent Gap
Given an integer array nums, return the maximum absolute difference between two adjacent elements.
If the array contains fewer than two elements, return 0.
Examples
01 · Example 1
nums = [3,8,2,10] return = 8
The adjacent absolute differences are 5, 6, and 8, so the maximum is 8.
02 · Example 2
nums = [7] return = 0
There are no adjacent pairs.
03 · Example 3
nums = [-4,-10,6,1] return = 16
The largest adjacent absolute difference is between -10 and 6.
Constraints
1 <= nums.length <= 1000-100000 <= nums[i] <= 100000
public int maxAdjacentGap(int[] nums) {
// write your code here
}nums[3,8,2,10]
expected8
sign in to submit