#challenge
💻 Largest Gap | #easy
Given an array of integers, return the largest gap between elements of the sorted version of that array.
Here's an illustrative example. Consider the array:
9, 4, 26, 26, 0, 0, 5, 20, 6, 25, 5
... which, after sorting, becomes the array:
0, 0, 4, 5, 5, 6, 9, 20, 25, 26, 26
... so that we now see that the largest gap in the array is the gap of 11 between 9 and 20.
Examples:
#interview
💻 Largest Gap | #easy
Given an array of integers, return the largest gap between elements of the sorted version of that array.
Here's an illustrative example. Consider the array:
9, 4, 26, 26, 0, 0, 5, 20, 6, 25, 5
... which, after sorting, becomes the array:
0, 0, 4, 5, 5, 6, 9, 20, 25, 26, 26
... so that we now see that the largest gap in the array is the gap of 11 between 9 and 20.
Examples:
LargestGap(new int[] { 9, 4, 26, 26, 0, 0, 5, 20, 6, 25, 5 }) ➞ 11🏆 Leave your solutions in the comments. The solution will be posted below in a couple of hours 👇
// After sorting get { 0, 0, 4, 5, 5, 6, 9, 20, 25, 26, 26 }
// Largest gap of 11 between 9 and 20
LargestGap(new int[] { 14, 13, 7, 1, 4, 12, 3, 7, 7, 12, 11, 5, 7 }) ➞ 4
// After sorting get { 1, 3, 4, 5, 7, 7, 7, 7, 11, 12, 12, 13, 14 }
// Largest gap of 4 between 7 and 11
#interview