Tip: you can sort it in `O(n log n)` and then use binary search on top of sorted array. It will give you `O(n log n)` complexity instead of `O(n^2)`. But still, I'm a bit confusead about all this testing. I'll give you more details in last comment.