link to my code https://ide.codingblocks.com/s/244551
Unable o pass test case 2 and 3
tried the built in sort but still it is not passing test case 2 and 3
@jatin111
import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
if(n>1 && n<1000) {
int[] a = new int[n];
for (int i = 0; i < a.length; i++) {
a[i] = sc.nextInt();
}
Arrays.sort(a);
int d = sc.nextInt();
int l = 0;
int r = a.length - 1;
while (l < r) {
if (a[l] + a[r] == d) {
System.out.println(a[l] + " and " + a[r]);
l++;
r–;
}
else if(a[l] + a[r] > d) {
r–;
}
else {
l++;
}
}
}
}
}
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.