Skip to content

Latest commit

 

History

History
18 lines (14 loc) · 332 Bytes

File metadata and controls

18 lines (14 loc) · 332 Bytes

01. Linear Search

Question Link

Solution

  1. Check one by one.
  2. If found then return index.
  3. else return -1.
int search(int arr[], int n, int k) {
  for(int i = 0; i < n; i++)
    if(arr[i] == k)
      return i + 1;
  return -1;
}