February 18 Lunchtime: Game with numbers Java NZEC

I tried this question in February Lunchtime, although couldn’t figure out the reason for NZEC. I’ve noticed multiple submissions getting NZECs and compared with the AC ones but couldn’t figure out via this method.

My logic was pretty simple

I used a dequeue after sorting as per requirements of the question and maintaining the required Array by removing elements from left or right based on situation (kind of 2 pointer method).

In every query, Bi, I have reduced the Dequeue.
It’ll be very helpful if you guys could help me with any situation of test case where Runtime Error could have been occurring.

Code Link: here