Skip to content
CampusEduX

Count Occurrences in Sorted Array

Easyjavapythonccppjavascript

Given a sorted array and a target value, count how many times the target occurs.

Input Format

The first line contains two integers N and target. The second line contains N space-separated integers in non-decreasing order.

Output Format

Print the number of occurrences of target.

Related Problems

  • Linear Search
    Easy · java, python, c, cpp, javascript
    Solve Problem
  • Binary Search
    Easy · java, python, c, cpp, javascript
    Solve Problem
  • First Occurrence in Sorted Array
    Easy · java, python, c, cpp, javascript
    Solve Problem

Input (stdin)

Output

Run your code to see output here...