# Untitled

unknown
plain_text
7 months ago
1.8 kB
0
Indexable
Never
```import java.util.*;
class Solution1 {
public static void main(String[] args){
int arr[]={73,54,15,4,23,70,53,65,73,73,2,72,36,71,73,69,35,18,62,73,62,73,73,50,30,73,20,71,60,9,12,57,48,73,40,20,8,73,73,73,34,59,31,49,73,5,51,36,47,38,36,58,34,42,23,28,52,73};
int k=1;
System.out.println(countSubarrays(arr,k));
}
public static long countSubarrays(int[] arr, int ki) {
long c=0;
int max=Integer.MIN_VALUE;
for(int i=0;i<arr.length;i++){
if(arr[i]>max){
max=arr[i];
}
}
int b=0;
int k,i,j;
k=0;
i=0;
j=0;
for(i=0;i<arr.length-1;i++){
int p;
ArrayList<Integer> l=new ArrayList<>();
for(p=i;p<arr.length;p++){
if(check(l,max,ki)){
c++;
b++;
System.out.println(l);
break;
}
}
j=p;
while(i<=j && j<arr.length){
j++;
if(j<arr.length){
if(check(l,max,ki)){
c++;
System.out.println("i="+i+" "+l);
}
}

}
l.clear();
}
System.out.println(max);
System.out.println(arr.length);
return c;
}
public static boolean check(ArrayList<Integer> l,int max,int k){
int u=0;
for(int i=0;i<l.size();i++){
if(l.get(i)==max){
u++;
}
}
if(u>=k){
return true;
}
return false;
}
}
```