DDSA Solutions

3423. Maximum Difference Between Adjacent Elements in a Circular Array

Time: O(n)
Space: O(1)

Problem Overview

Maximum Difference Between Adjacent Elements in a Circular Array (Unknown) asks you to solve a structured algorithmic task. This is a common Array pattern in coding interviews. Scan all adjacent pairs including wrap-around; return max absolute difference.

A full step-by-step explanation is being added. See the study guide for pattern-based practice.

Approach

Scan all adjacent pairs including wrap-around; return max absolute difference.

Related patterns: Array

3423.cs
C#
// Approach: Scan all adjacent pairs including wrap-around; return max absolute difference.
// Time: O(n) Space: O(1)

public class Solution
{
    public int MaxAdjacentDistance(int[] nums)
    {
        int ans = Math.Abs(nums[0] - nums[nums.Length - 1]);

        for (int i = 0; i + 1 < nums.Length; ++i)
            ans = Math.Max(ans, Math.Abs(nums[i] - nums[i + 1]));

        return ans;
    }
}
Was this solution helpful?

Related Problems