forked from adityabisoi/ds-algo-solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
solution.java
39 lines (33 loc) · 1.19 KB
/
solution.java
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
/*
Way to go ahead:
Keep track of the index and the complement value
in a hasmap and as we can our input, check if we
see a complement
if we do see one then just print out its' index
and our current index
Time complexity: O(n) //The number of flavors we have to look at
Space complexity: O(n) //The number of flavors we store the complement of
*/
import java.io.*;
import java.util.*;
public class solution {
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named solution. */
Scanner input = new Scanner(System.in);
int t = input.nextInt();
for(int a0 = 0; a0 < t; a0++)
{
int money = input.nextInt();
int flavors = input.nextInt();
Map<Integer, Integer> complements = new HashMap<>();
for(int i = 1; i <= flavors; i++)
{
int cost = input.nextInt();
if(complements.containsKey(cost))
System.out.println(complements.get(cost) + " " + i);
else
complements.put(money-cost, i);
}
}
}
}