↓Skip to main content
  1. LeetCode/

LeetCode 3423: Maximum Difference Between Adjacent Elements in a Circular Array

·1 min· ·
LeetCode Easy Array
Wei Yi Chung
Author
Wei Yi Chung
Working at the contributing of open source, distributed systems, and data engineering.
Table of Contents

Meta Data
#

Difficulty: easy First Attempt: 2025-07-17

  • Submissions: Accepted (first try)

Approach
#

Take the maximum absolute difference over adjacent pairs (Array Template 1). Circular means the last and first elements are adjacent too. In Python nums[-1] is the last element, so starting i at 0 and comparing with nums[i - 1] covers every adjacent pair at once.

My Solution
#

class Solution:
    def maxAdjacentDistance(self, nums: List[int]) -> int:
        return max(abs(nums[i] - nums[i - 1]) for i in range(len(nums)))

I originally added abs(nums[-1] - nums[0]) separately, which is equivalent.

Complexity
#

Time O(n), space O(1).

Mistakes to Avoid
#

  • Remember the ends are adjacent too.

Interview Explanation
#

I take the maximum difference over adjacent pairs including last and first; comparing with nums[i - 1] from i = 0 naturally includes that pair. Time O(n).

Related

LeetCode 3550: Smallest Index With Digit Sum Equal to Index
·1 min
LeetCode Easy Math Array
LeetCode 3550 note: check indices in increasing order, computing each digit sum; the first match is the answer
LeetCode 1979: Find Greatest Common Divisor of Array
·1 min
LeetCode Easy Math Number-Theory Gcd Array
LeetCode 1979 note: find the minimum and maximum, then take their GCD with Euclid’s algorithm
LeetCode 1920: Build Array from Permutation
·1 min
LeetCode Easy Array Simulation
LeetCode 1920 note: follow the definition ans[i] = nums[nums[i]]; for O(1) extra space, stack the new value times n on top of the old one
LeetCode 2094: Finding 3-Digit Even Numbers
·2 mins
LeetCode Easy Hash-Table Enumeration Array
LeetCode 2094 note: enumerate the even numbers 100 to 998 instead and check that each digit needed is available; Counter subtraction keeps only positives
LeetCode 2176: Count Equal and Divisible Pairs in an Array
·1 min
LeetCode Easy Array
LeetCode 2176 note: n is only 100, so enumerate all pairs; the condition is equal values and the index product i * j divisible by k
LeetCode 3507: Minimum Pair Removal to Sort Array I
·2 mins
LeetCode Easy Simulation Array
LeetCode 3507 note: n is tiny, so simulate; the right side of a slice assignment must be a list