Two numbers n and x are read, followed by n integers representing an array v sorted in ascending order (v[0] < v[1] < ... < v[n-1]). Print the position (1-based) at which x appears in the array, or -1 if x is not present. The search must be performed using a recursive binary search function.
Define a recursive function binSearch(v, lo, hi, x) that returns the position of x in v between indices lo and hi, or -1 if not found. At each call compute mid = (lo + hi) / 2 and:
- if
v[mid] == x, returnmid + 1(1-based position); - if
x < v[mid], recurse on the left half[lo, mid-1]; - if
x > v[mid], recurse on the right half[mid+1, hi].
Base case: if lo > hi, return -1.