Question:An array is defined to be a Filter array if it meets the following conditions
- a. If it contains 9 then it also contains 11.
- b. If it contains 7 then it does not contain 13.
So {1, 2, 3, 9, 6, 11} and {3, 4, 6, 7, 14, 16}, {1, 2, 3, 4, 10, 11, 13} and {3, 6, 5, 5, 13, 6, 13} are Filter arrays. The following arrays are not Filter arrays: {9, 6, 18} (contains 9 but no 11), {4, 7, 13} (contains both 7 and 13) Write a function named isFilter that returns 1 if its array argument is a Filter array, otherwise it returns.
Here is my solution please can you provide me most efficient solution of that and ,tell me how efficient my logic is here? no build-in functions and sorting etc. are allowed ,just core logic on Java , its ok in c or c++ . Solution
static int isFilter(int[] a){
int i,len=a.length,j,result=1,found9=0,found11=0,found7=0,found13=0;
for(i=0;i<len;i++){
if(a[i]==9 ){
found9=1;
for(j=0;j<len; j++){
if(a[j]==11){
found11=1;
}
}
}
if(a[i]==7){
found7=1;
for(j=0;j<len;j++){
if(a[j]==13){
found13=1;
}
}
}
}
if(found9==1 && found11!=1){
result=0;
}
if(found7==1 && found13!=0){
result=0;
}
return result;
}