Solution Review: Sequential Search
Let’s take a detailed look at the previous challenge’s solution.
We'll cover the following
Solution
The array passed to the function may or may not be sorted. We have to iterate throughout the array until we find the key if it’s available. When the desired element is found in the array, we return true
. If the desired element is not found at any index of the array, then the if
statement inside the loop doesn’t become true
and we reach the end of the loop. Consequently, we execute the last line of the function and return false
.
Let’s look at the illustration below to better understand how it actually works.
Level up your interview prep. Join Educative to access 80+ hands-on prep courses.