-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhdfcArray.java
More file actions
79 lines (59 loc) · 1.33 KB
/
hdfcArray.java
File metadata and controls
79 lines (59 loc) · 1.33 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package coding;
import java.util.Scanner;
public class hdfcArray {
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
int N=sc.nextInt();
int arr[]=new int[N];
for (int i = 0; i < arr.length; i++) {
arr[i]=sc.nextInt();
}
int T=sc.nextInt();
int query[][]=new int[T][3];
for (int i = 0; i < T; i++) {
for (int j = 0; j < 3; j++) {
query[i][j]=sc.nextInt();
}
}
// for (int i = 0; i < query.length; i++) {
// System.out.println(query[i][0]+" "+query[i][1]+" "+query[i][2]);
// }
for (int i = 0; i < T; i++) {
if(isPossible(arr, query[i][0], query[i][1], query[i][2])) {
System.out.println("Yes");
}else {
System.out.println("No");
}
}
}
public static boolean isPossible(int arr[],int l,int r,int k) {
boolean flag=false;
for (int i = 0; i < arr.length-k+1; i++) {
if(!isUniue(arr, i, i+k-1)) {
flag=false;
}else {
flag=true;
for (int j = i; j < i+k; j++) {
if(arr[i]<l || arr[j]>r) {
flag=false;
break;
}
}
if(flag) {
return flag;
}
}
}
return flag;
}
public static boolean isUniue(int arr[], int low, int high) {
for(int i=low;i<high;i++) {
for (int j = i+1; j < high; j++) {
if(arr[i]==arr[j]) {
return false;
}
}
}
return true;
}
}