-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathlargestRange.cpp
More file actions
41 lines (38 loc) · 1012 Bytes
/
largestRange.cpp
File metadata and controls
41 lines (38 loc) · 1012 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
#include <bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>> t;
while(t--){
int n;
cin>> n;
int arr[n];
for(int i=0; i<n; i++)
cin>> arr[i];
sort(arr, arr+n);
int min, max, min1, max1, count =1, max_count=1;
min = min1 = max = max1 = arr[0];
for(int i=1; i<n; i++){
if(arr[i] == (arr[i-1]+1)){
max1 = arr[i];
count++;
if(count > max_count) max_count = count;
}
else{
if(count >= max_count){
min = min1;
max = max1;
}
count = 1;
min1 = arr[i];
max1 = arr[i];
}
}
if(count >= max_count){
min = min1;
max = max1;
}
cout<<"range: (" << min <<", " << max <<")"<< endl;
}
return 0;
}