CT914

The Recursive Search: Implement Linear Search Recursively

EasyL4 · Loop LordAcceptance: 0.0%XP: 35

In the Academy of Prime City, the Professor of Recursion teaches that any iterative algorithm can be expressed recursively. Linear search is no exception. The recursive approach checks the first element, and if it doesn't match, recursively searches the rest of the array. "Check the first element," the Professor says. "If it matches the target, return index 0. Otherwise, recursively search the subarray starting at index 1, and add 1 to the result. If the array is empty, return -1." Given an array of N integers and a target T, find the index of the first occurrence of T using recursive linear search. If T is not found, output -1. Constraints: 1 <= N <= 10^4, -10^9 <= array[i], T <= 10^9 Input: 5 3 1 4 1 5 4 Output: 2 Input: 3 1 2 3 5 Output: -1

Constraints:

1 <= N <= 10^4, -10^9 <= array[i], T <= 10^9

Tags:

linear-search recursive search
Loading...
Test Cases:No test cases
No test cases available.
The Recursive Search: Implement Linear Search Recursively - EASY Coding Problem | CodeTikki