Challenge: Count Element Occurrence
We'll cover the following
Problem Statement
Given a sorted array of integers, find the frequency of the occurrence of a given target value in the array.
If the value is not found in the array at all, return 0
Input
A sorted array and a target value
Output
The number of times that it occurs in the array
Sample Input
int arr[] = {-5,-3,0,1,3,3,3,4,5};
int s = 3;
Sample Output
3
Coding Exercise
Take a close look and design a step-by-step algorithm before jumping on to the implementation. This problem is designed for your practice, so try to solve it on your own first. If you get stuck, you can always refer to the hint and solution provided in the code tab. Good Luck!
Level up your interview prep. Join Educative to access 70+ hands-on prep courses.