package algorithm.search;
import java.util.HashMap;
import java.util.Map;
/**
* The type Count occurrence.
*/
public class countOccurrence {
/**
* Count int.
*
* @param arr the arr
* @param key the key
* @return the int
*/
public static int count(int[] arr , int key){
Map map = new HashMap();
for(int i =0;ikey){
end = mid-1;
}else if(arr[mid] key) {
end1 = mid1 - 1;
} else if (arr[mid1] < key) {
start1 = mid1 + 1;
}
}
//Get difference of ri8 and left
if (result == -1 || result1 == -1)
return (result1 - result);
return (result1 - result + 1);
}
/**
* Main.
*
* @param args the args
*/
public static void main(String[] args){
int arr[] = {-5,-3,0,1,3,3,3,3,4,5};
int key = 3;
System.out.println("The key \""+ key + "\" occurs " + getFrequency(arr, key) + " times in the Array.");
}
}