I used Arrays.sort() to sort and i implemented my logic.it shows TLE
TLE(time limit exceeded)
Arrays.sort() is fine
follow this to handle the tle
public static void targetSum(int[] arr, int target){
Arrays.sort(arr);
int left = 0;
int right = arr.length - 1;
while (left < right) {
int sum = arr[left] + arr[right];
if (sum > target) {
right--;
} else if (sum < target) {
left++;
} else {
System.out.println(arr[left] + " and " + arr[right]);
left++;
right--;
}
}
}