-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdominant.java
More file actions
51 lines (48 loc) · 1.3 KB
/
dominant.java
File metadata and controls
51 lines (48 loc) · 1.3 KB
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
/* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class dominant
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter how many arrays you want to check : ");
int T = sc.nextInt();
for(int i = 0;i < T;i++)
{
System.out.println("Enter the size of the array : ");
int N = sc.nextInt();
int[] A = new int[N];
System.out.println("Enter the array elements : ");
for(int j =0;i < A.length;i++)
{
A[i]=sc.nextInt();
}
boolean result = findDominant(A);
if(result == true)
{
System.out.println("YES");
}
else
{
System.out.println("NO");
}
}
}
static boolean findDominant(int[] A)
{
for(int i = 0;i < A.length;i++)
{
for(int j = 0;j < A.length;j++)
{
if(A[i] == A[j] && i!=j)
{
return true;
}
}
}
return false;
}
}