using System; using System.Collections.Generic; using System.IO; using System.Linq; class Solution { static void Main(String[] args) { int n = Convert.ToInt32(Console.ReadLine()); string[] a_temp = Console.ReadLine().Split(' '); int[] a = Array.ConvertAll(a_temp,Int32.Parse); // your code goes here int diff = Int32.MaxValue; QuickSort(a,0,n-1); // Order the array. for(int i = 0; i < n - 1; i++){ int temp = Math.Abs(a[i] - a[i+1]); if(temp < diff) diff = temp; } Console.WriteLine(diff); } static void QuickSort(int[] a, int p, int q){ if(p + 10 < q){ int r = sortArray(a,p,q); QuickSort(a,p, r-1); QuickSort(a,r+1, q); } else{ insertionSort(a,p,q); } } static void insertionSort(int[] ar, int p, int q) { for(int i = p; i <= q; i++){ int last = ar[i]; int j = i-1; while(j >= 0 && last < ar[j]){ ar[j+1] = ar[j]; j = j-1; } ar[j+1] = last; } } static int sortArray(int[] a, int p, int q){ int pivot = a[p]; int i = p; int temp = 0; for(int j = p+1; j < a.Length; j++){ if(pivot > a[j]){ i++; temp = a[j]; a[j] = a[i]; a[i] = temp; } } temp = pivot; a[p] = a[i]; a[i] = temp; return i; } }