Find the largest absolute difference between any two neighboring elements in a circular array.
You are given a circular array of integers. In a circular array, the element after the last element is the first element.
Your task is to compute the maximum absolute difference between every pair of adjacent elements in the circle.
For each index , consider the pair . Return the maximum value of over all indices.
Input Format
- An integer array
numsof lengthn. - The array is treated as circular, so the last element is adjacent to the first element.
Output Format
- Return a single integer: the maximum absolute difference between adjacent elements in the circular array.
Constraints
- Values may be negative or positive integers
- Use the circular wrap-around pair between the last and first elements
Example 1
Input
nums = [1, 2, 3, 1]
Output
2
Explanation
Adjacent absolute differences are |1-2|=1, |2-3|=1, |3-1|=2, and |1-1|=0. The maximum is 2.
Example 2
Input
nums = [8, -1, 5]
Output
9
Explanation
The circular adjacent pairs are (8, -1), (-1, 5), and (5, 8). Their absolute differences are 9, 6, and 3. The maximum is 9.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.