forked from architsingla13/InterviewBit-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNobleInteger.java
More file actions
34 lines (29 loc) · 729 Bytes
/
NobleInteger.java
File metadata and controls
34 lines (29 loc) · 729 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
package Array;
import java.util.ArrayList;
import java.util.Collections;
/**
* Author - archit.s
* Date - 22/08/18
* Time - 12:08 AM
*/
public class NobleInteger {
public int solve(ArrayList<Integer> A) {
Collections.sort(A);
for(int i=0;i<A.size();){
int num = A.get(i);
while(i<A.size() && A.get(i) == num){
i++;
}
if(i-1<A.size() && A.get(i-1) == (A.size()-i)){
return 1;
}
}
return -1;
}
public static void main(String[] args) {
ArrayList<Integer> A = new ArrayList<>();
A.add(1);
A.add(2);
System.out.println(new NobleInteger().solve(A));
}
}