Hi!
I’m unable to compile my solution, however its works all fine locally on my IDE. Here is the code snippet:
public static void main(String args[]) {
Scanner sn = new Scanner(System.in);
int n = sn.nextInt(), idx = 0;
int[] nums = new int[n];
for(; idx < n; idx++) {
nums[idx] = sn.nextInt();
}
int target = sn.nextInt();
Arrays.sort(nums);
int lo = 0, hi = nums.length-1;
while (lo < hi) {
int sum = nums[lo] + nums[hi];
if (sum == target) {
System.out.println(nums[lo] + " and " + nums[hi]);
lo++;
hi--;
} else if (sum > n) {
hi--;
} else {
lo++;
}
}
}