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...
Log in to run your code. Your draft is saved in this browser.Log inSign up