Can anyone provide a testcase where my soln is failing...

???.

Yes. You seemed to have over-interpreted the requirements; given n, you have to give (if possible) a prime p that is greater than or equal to n and between \ell and r. What it doesn’t say is that p must be close to n. So given:

1
90 112 3
6
100
110


the output should be:

97
101
-1
//