Linear Search
Fundamentals & Basic Operations DSA practice problem on Onlearn.
Difficulty: easy.
Topics: Search for an Element in an Array and Return its Index, Arrays, Time Complexity, Space Complexity, Loops, Conditional Statements, iterative algorithms, complexity analysis, search algorithms, array traversal, array indexing, Linear Search, Array Traversal & Indexing.
Problem Statement Given an array of integers and an integer num, determine if num is present in the array. If num is found, print the index of its first occurrence. Otherwise, print 1. Input Specification Input consists of an array of integers and a single integer num. Output Specification Print the 0 based index of num if it is found in the array. If num is not found, print 1. Sample Test Cases Example 1: Input: Output: Explanation: The element 3 is present at index 2. Example 2: Input: Output: Explanation: The element 5 is present at index 0.