Pseudocode Compiler
Practice

Linear Search

HARDAlgorithms

Read N (1 ≤ N ≤ 10), then N integers into an array, then a target value. Output the 1-based position of the first occurrence of the target in the array, or -1 if not found.

Input: N, then N integers, then the target. Output: The position (1-based) or -1.

Example:

Input:  5
        10  30  20  40  50
        30
Output: 2
Premium is coming soon. All grading features are currently unlocked.

Sample Test Cases

Test 1: Found at index 2
Inputs: 5, 10, 30, 20, 40, 50, 30
Expected: 2
Test 2: Not found
Inputs: 5, 10, 30, 20, 40, 50, 99
Expected: -1
Test 3: Found at index 1
Inputs: 3, 5, 5, 5, 5
Expected: 1
Press Ctrl+Enter to run your code
or Ctrl+Shift+Enter to grade