Problem title
Difficulty
Avg time to solve

Number Of Vehicles
Easy
15 mins
Left View Of a Binary Tree
Easy
10 mins
Is Height Balanced Binary Tree
Moderate
15 mins
Word Break II
Hard
15 mins
Copy And Reverse The Array
Easy
10 mins
Roots of the tree having minimum height
Moderate
25 mins
Reverse A LL
Moderate
30 mins
Print Reverse LinkedList
Easy
15 mins
Non-Decreasing Array
Moderate
35 mins
Binary Tree Pruning
Moderate
20 mins
21

Occurrence of X in a Sorted Array

Difficulty: EASY
Contributed By
Avg. time to solve
26 min

Problem Statement

You have been given a sorted array/list of integers of size N and an integer X. Find the total number of occurrences of X in the array/list.

Input Format
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.
Output Format
The only line of output will print the total number of occurrences of X in the array/list.
Note:
You are not required to print the expected output, it has already been taken care of. Just implement the function. 
Constraints:
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
Sample Input 1:
5 4
1 2 4 4 5 
Sample Output 1:
2
Explanation For Sample Input 1:
In the given list there are 2 occurrences of 4.
Sample Input 2:
 5 6
 1 2 4 4 5
Sample Output 2:
 0
Reset Code
Full screen
copy-code
Console