Linear Search Problem Statement
Given a random integer array/list ARR
of size N
, and an integer X
, you are required to search for the integer X
in the given array/list using Linear Search.
Return the index at which X
is found. If X
appears multiple times, return the index of its first occurrence. If X
is not present, return -1
.
Example:
Input:
t = 1
N = 5
ARR = [1, 2, 3, 4, 5]
X = 3
Output:
2
Explanation:
X
is located at index 2
in ARR
.
Constraints:
1 ≤ t ≤ 10^2
0 ≤ N ≤ 10^5
-2^{31} ≤ X ≤ (2^{31}) - 1
- Time Limit: 1 sec

AnswerBot
4mo
Linear search algorithm to find the first occurrence of an integer in an array.
Iterate through the array and compare each element with the target integer.
Return the index if the target integer is foun...read more
Help your peers!
Add answer anonymously...
Wipro Software Developer interview questions & answers
A Software Developer was asked 3d agoQ. What are the OOPS principles in C#?
A Software Developer was asked 3d agoQ. What is an extension method and how do you implement it?
A Software Developer was asked 3d agoQ. What is asynchronous programming?
Popular interview questions of Software Developer
A Software Developer was asked 2mo agoQ1. What languages have you used?
A Software Developer was asked 3mo agoQ2. What are your qualities?
A Software Developer was asked 5mo agoQ3. What is an operating system?
Top HR questions asked in Wipro Software Developer
A Software Developer was asked 1mo agoQ1. Tell me about yourself.
A Software Developer was asked 1mo agoQ2. Tell me about your work experience.
A Software Developer was asked 4mo agoQ3. What is your expected salary?
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

