Linear Search - II
You are given an integer array nums and an integer target. Using recursion, return the smallest zero-based index at which target occurs in nums. If target is not present, return -1.
Note:
A normal iterative solution will pass the test cases, but the goal of this problem is to solve it using recursion and strengthen your understanding of recursive calls and base cases.
Example 1:
Input: nums = [2, 3, 4, 5, 3], target = 3
Output: 1
Explanation: The first occurrence of 3 is at index 1.
Example 2:
Input: nums = [2, -4, 4, 0, 10], target = 6
Output: -1
Explanation: The target 6 does not occur in nums.
Now Your Turn!
Pick the correct output for the given inputInput: nums = [1, 3, 5, -4, 1], target = 1
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- 1 <= nums.length <= 100
- -104 <= nums[i] <= 104
- -104 <= target <= 104