You are given a list of integers nums. Consider the elements of nums in sorted order. Return the largest difference between two adjacent elements in that order. If nums has fewer than two elements, return 0.
You must write an algorithm that runs in O(n) time.
Examples
Example 1
Input: nums = [3,6,9,1]
Output: 3
Explanation: Sorted, nums is [1,3,6,9]. The adjacent differences are 2, 3, and 3, so the largest is 3.
Example 2
Input: nums = [10]
Output: 0
Example 3
Input: nums = [1,1,1,1]
Output: 0
Constraints
0≤n≤105 where n=nums.length
0≤nums[i]≤109
Loading editor...
Run checks the sample cases; Submit runs every case.
Samples 3
Custom 0
passedwrong answertime limiterrorran, no expected valuenot run