Problem Link - Search an element in an array in Arrays
Problem Statement:
You are given an array A of size N and an element X. Your task is to find whether the array A contains the element X or not.
Approach:
- We iterate through the array and check whether any element in the array is equal to X.
- If we find X in the array, we can stop the search and output “YES”.
- If we complete the iteration without finding X, we output “NO”.
Complexity:
- Time Complexity:
O(N)
Iterated through the whole array. - Space Complexity:
O(1)
No extra space is used.