I thought a problem which is as follows:

We have an array A of integers of size n, and we have test cases t and in every test cases we are given a number m and a range [s,e] i.e. we are given s and e and we have to find the closest number of m in the range of that array(A[s]-A[e]). 

You may assume array indexed are from 1 to n.

For example:

```
  A = {5, 12, 9, 18, 19}
  m = 13
  s = 4 and e = 5

```

So the answer should be 18.

Constraints:

```
n<=10^5
t<=n

```

All I can thought is an O(n) solution for every test case, and I think a better solution exists.