implemented the solution for counting the number of occurrence of an element in a given array