Skip to content

Practice Maximum Gap

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#164
LeetCode Problem

Maximum Gap

Problem Statement

Given an integer array nums, return the maximum difference between two successive elements in its sorted form. If the array contains less than two elements, return 0. You must write an algorithm that runs in linear time and uses linear extra space.

Source: Maximum Gap on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums = [3,6,9,1]
Output
3

# Example 2

Input
nums = [10]
Output
0

Constraints

1 <= nums.length <= 10^5
0 <= nums[i] <= 10^9

Related LeetCode Problems

Practice more problems similar to Maximum Gap.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.