How do I speed up java solution to SPOJ HACKRNDM



problem link:
and this is what I have tried:

The problem has got only 19 successful submissions in java.


Try making algorithmic changes. It would become easy once the element are sorted. After that you can run a binary search on ‘element+2’.