Linear Search Element Problem

Linear Search Element Problem — ExecCode School DSA Practice

Solve the Linear Search Element problem on ExecCode. Free online school DSA practice in Arrays - Basics. Write and run code in Java, C++, Python — no signup required to run.

Problem description

Given an array of integers and a target value, find the 0-based index of the first occurrence of the target in the array. Your task is to solve Linear Search Element. If the target is not found, return -1.

Examples

Input 5 1 2 3 4 5 3; Output 2. Input 5 1 2 3 4 5 6; Output -1

Constraints

1 <= n <= 10^5

Practice Linear Search Element free on ExecCode. Browse DSA problems, topic map, and placement guides.