Find existing element
Input
recursive_binary_search([1, 2, 3, 4, 5], 3)
Output
2
Middle element is 3 at index 2; recursion finds and returns its index.
Full lesson preview
Use recursion to locate a target value in a sorted list and return its index or -1 if absent.
Problem statement
Task
Examples
Input
recursive_binary_search([1, 2, 3, 4, 5], 3)
Output
2
Middle element is 3 at index 2; recursion finds and returns its index.
Input format
Output format
Constraints
Samples
Input
recursive_binary_search([10, 20, 30, 40], 30)
Output
2
30 is at index 2.