-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHORSES.cpp
More file actions
43 lines (39 loc) · 718 Bytes
/
HORSES.cpp
File metadata and controls
43 lines (39 loc) · 718 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <iostream>
#define ll long long
using namespace std;
int sort(ll int arr[],int size){
int i=0,j=0;
int temp;
for(i=0;i<size;i++){
for(j=0;j<size-i-1;j++){
if( arr[j]>arr[j+1]){
temp=arr[j+1];
arr[j+1]=arr[j];
arr[j]=temp;
}
}
}
int min=arr[1]-arr[0];
for(i=0;i<size-1;i++){
if (min>arr[i+1]-arr[i]){
min=arr[i+1]-arr[i];
}
}
return min;
}
int main(){
int t,n;
ll int p;
cin>>t;
while(t!=0){
cin>>n;
ll int arr[n]={0};
for(int i=0;i<n;i++){
cin>>p;
arr[i]=p;
}
cout<<sort(arr,n)<<endl;
t--;
}
return 0;
}