added numberOfOccurrences function to solve the problem