-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFindB.java
More file actions
32 lines (31 loc) · 927 Bytes
/
FindB.java
File metadata and controls
32 lines (31 loc) · 927 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
import java.util.HashMap;
import java.util.Scanner;
public class FindB {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
int t=s.nextInt();
for(int i=0;i<t;i++){
int n=s.nextInt();
int q=s.nextInt();
int[] arr=new int[n];
for(int j=0;j<n;j++){
arr[j]=s.nextInt();
}
for(int x=0;x<q;x++){
int a=s.nextInt();
int b=s.nextInt();
System.out.println(helper(arr,a-1,b-1));
}
}
}
static String helper(int[] arr,int st,int en){
HashMap<Integer,Integer> h=new HashMap<>();
int n=(en-st+1)/2;
if(en-st+1==1) return "NO";
for(int i=st;i<=en;i++){
h.put(arr[i],h.getOrDefault(arr[i],0)+1);
if(h.get(arr[i])>n) return "NO";
}
return "YES";
}
}