forked from DHEERAJHARODE/Hacktoberfest2024-Open-source-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlcqs.java
53 lines (45 loc) · 1.09 KB
/
lcqs.java
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
44
45
46
47
48
49
50
51
52
53
import java.io.*;
import java.util.*;
public class Main{
public static void main(String[] args) throws Exception {
Scanner scn = new Scanner(System.in);
int n1 = scn.nextInt();
int [] arr1 = new int [n1];
for(int i =0;i<arr1.length;i++){
arr1[i]=scn.nextInt();
}
HashMap<Integer,Boolean> h = new HashMap();
for(int j = 0 ;j<arr1.length ; j++){
int a = arr1[j];
h.put(a,false);
}
for(int k = 0;k<arr1.length;k++){
int b = arr1[k];
if(h.containsKey(b-1)){
continue;
}else{
h.put(b,true);
}
}
int count =0;
int start =0;
for(Integer f : h.keySet()){
if(h.containsKey(f)==true){
int count1 =1;
int e=f;
while(h.containsKey(f+1)){
count1++;
f=f+1;
}
if(count<count1){
count=count1;
start=e;
}
}
}
for(int l = 0;l<count;l++){
System.out.println(start);
start=start+1;
}
}
}