If you're crazy about complexity's O, I have the impression it would be better to start by sorting it and then going through the array starting both from the beggining and the end, but only once, so it becomes O(nlogn). It's probably less readable though.
int i = 0;
int j = arr.length - 1;
while(i < arr.length && j >= 0)
int sum = arr[i] + arr[j];
if(sum == k)
else if (sum > k)
Andrei's solution was very smart as well, and I guess depending on complexity of contains and add of the Set object, you could get an algorithm with the same complexity.
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.