Skip to content

Instantly share code, notes, and snippets.

@deepaksinghvi
Last active June 24, 2023 12:42
Show Gist options
  • Save deepaksinghvi/cf5b19e19c5c98b84db37b2dcd006c3c to your computer and use it in GitHub Desktop.
Save deepaksinghvi/cf5b19e19c5c98b84db37b2dcd006c3c to your computer and use it in GitHub Desktop.
LargestGap
import java.util.Arrays;
public class LargestGap {
public static void main(String[] args) {
System.out.println(largestGap(new int[]{9, 4, 26, 26, 0, 0, 5, 20, 6, 25, 5}));
}
public static int largestGap(int[] numbers) {
int result = 0;
Arrays.sort(numbers);
for(int i=0;i<numbers.length-1;i++) {
int diff = numbers[i+1]- numbers[i];
if (result < diff) {
result = diff;
}
}
return result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment