Maximum Consecutive Gap

Given an unsorted array, find the maximum difference between the successive elements in its sorted form.

Try to solve it in linear time/space.

Example :

Input : [1, 10, 5]
Output : 5 

Return 0 if the array contains less than 2 elements.

  • You may assume that all the elements in the array are non-negative integers and fit in the 32-bit signed integer range.
  • You may also assume that the difference will not overflow.
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.
Start solving Maximum Consecutive Gap on Interview Code Editor
Sign Up
to access hints and editorial solutions for Maximum Consecutive Gap
Asked In:
  • Hunan Asset
Click here to start solving coding interview questions