Click4Ai

9.

Easy

Write a function find_index(arr, value) that returns the index of the first occurrence of a given value in an array. Return -1 if the value is not found.

Example:

Input: arr = [10, 20, 30, 40, 50], value = 30

Output: 2

Constraints:

  • Array length: 1 <= len(arr) <= 1000
  • Return -1 if not found
  • Do not use .index() or np.where()
  • Test Cases

    Test Case 1
    Input: [10, 20, 30, 40, 50], 30
    Expected: 2
    Test Case 2
    Input: [1, 2, 3, 4, 5], 1
    Expected: 0
    Test Case 3
    Input: [1, 2, 3], 7
    Expected: -1
    + 2 hidden test cases