New update is available. Click here to update.

Last Updated: 22 Jul, 2020

Difficulty: Easy

```
The first line of the input contains two integers N and X. They represent the size of the array/list and X respectively.
The second line contains N single space-separated integer representing the array/list elements.
```

```
The only line of output will print the total number of occurrences of X in the array/list.
```

```
You are not required to print the expected output, it has already been taken care of. Just implement the function.
```

```
1 <= N <= 10^5
1 <= Arr[i] <= 10^9
Where Arr[i] represents the element i-th element in the array/list.
Time Limit: 1sec
```

- Use Binary search to get an index of the first occurrence of X in the input Array. Say the index at which X appeared first as ‘xStartIndex’.
- Use Binary search to get an index of the last occurrence of X in the input Array. Say the index at which X appeared last as ‘xEndIndex’.
- Return (xEndIndex – xStartIndex + 1).

SIMILAR PROBLEMS

Merge Two Sorted Arrays Without Extra Space

Posted: 19 Nov, 2022

Difficulty: Moderate

Search In A Sorted 2D Matrix

Posted: 23 Nov, 2022

Difficulty: Moderate

Ninja And The Strictly Increasing Array

Posted: 27 Nov, 2022

Difficulty: Moderate

Negative To The End

Posted: 16 Dec, 2022

Difficulty: Easy

Fake Coin Problem

Posted: 24 Dec, 2022

Difficulty: Easy

Popular Interview Problems: