# 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:**

- $1 \leq nums.length \leq 10^4$
- $-10^4 \leq nums[i] \leq 10^4$
- $nums$ contains values sorted in an
**ascending**order. - $-10^4 \leq target \leq 10^4$

**Example 1:**

```
Input: [5, 7, 7, 8, 8, 10], 8
Output: 2
```

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.