Skip to content
CampusEduX

First Occurrence in Sorted Array

Easyjavapythonccppjavascript

Given a sorted array that may contain duplicate values, find the first index at which a target value appears.

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 first index of target, or -1 if it does not exist.

Related Problems

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

Input (stdin)

Output

Run your code to see output here...