Linear Search
Linear Search
EasyArrays55% accepted
Given an array of N integers and a target value T, find the index of the first occurrence of T. If T is not in the array, print -1. This is the simplest search algorithm — just check each element one by one.
Approach
Given N integers and a target T, print the 0-based index of the first occurrence of T, or -1 if not found.
Input
5 3
1 3 5 3 7
Output
1
More Arrays problems
Browse all coding problems →solution.py
Loading editor...
Test 1
Test 2
Test 3
Press Run to test your custom input, or Submit to judge against all test cases.
Sign in to continue
Create a free account to run code, submit solutions and track progress.
- Free forever — no credit card
- 10+ languages with live execution
- Points, streaks & leaderboards