Skip to content
CampusEduX

Linear Search

Easyjavapythonccppjavascript

Given an array and a target value, find the first position where the target occurs.

Input Format

The first line contains two integers N and target. The second line contains N space-separated integers.

Output Format

Print the zero-based index of the first occurrence of target, or -1 if it is absent.

Related Problems

  • Binary Search
    Easy · java, python, c, cpp, javascript
    Solve Problem
  • First Occurrence in Sorted Array
    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...