Element Occurrence
Let's try to count elements. This lesson is of medium-level difficulty.
We'll cover the following
Problem statement
Suppose we are given a sorted array of integers, find the number of occurrences of a given target value. If the target is not found in the array, return -1
.
Constraints:
- contains values sorted in an ascending order.
Example 1:
Input: [5, 7, 7, 8, 8, 10], 8
Output: 2
Level up your interview prep. Join Educative to access 80+ hands-on prep courses.