-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInteresting_Array.java
More file actions
51 lines (43 loc) · 911 Bytes
/
Interesting_Array.java
File metadata and controls
51 lines (43 loc) · 911 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import java.util.*;
import java.io.*;
public class Interesting_Array {
public static void main(String args[]) throws IOException {
//write your code here
Scanner sc=new Scanner(System.in);
int T=sc.nextInt();
while(T--!=0)
{
int N=sc.nextInt();
int arr[]=new int[N];
for(int i=0;i<N;i++)
{
arr[i]=sc.nextInt();
}
int K=sc.nextInt();
int flag=0;
int left=0;
int right=N-1;
for(int i=left;i<right;)
{
if(arr[left]+arr[right]==K)
{
flag++;
System.out.println(left+" "+right) ;
break;
}
else if(arr[left]+arr[right]>K)
{
right--;
}
else
{
left++;
}
}
if(flag==0)
{
System.out.println("no answer") ;
}
}
}
}