Don't jump directly to the solution.
Read the problem carefully and try to solve it on your own.
Solution :
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 | import java.util.Scanner; public class PlacementProblem1 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-->0) { int size = sc.nextInt(); int target = sc.nextInt(); int arr[] = new int[size]; for(int i=0; i<arr.length; i++) arr[i] = sc.nextInt(); for(int i=0; i<arr.length; i++) { boolean flag = false; for(int j=i+1; j<arr.length; j++) { if(arr[i]+arr[j]==target) { System.out.println(i+" "+j); flag = true; break; } } if(flag) break; } } } } |
t = int(input()) while t>0: lst = list(input().split(" ")) size, target = int(lst[0]), int(lst[1]) arr = list(map(int,input().split(" "))) for i in range(0,size): flag = False; for j in range(i+1,size): if arr[i]+arr[j]==target: print(i,j) flag = True break if flag : break t = t - 1
Thank you for reading this post.💓
If there is any problem with the solution. Write your query below 👇.