-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTask1.java
More file actions
35 lines (30 loc) · 907 Bytes
/
Copy pathTask1.java
File metadata and controls
35 lines (30 loc) · 907 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
import java.util.HashMap;
import java.util.Map;
public class Task1 {
public static void main(String[] args) {
String[] A = {"CC0","AB0",};
int[] B = {12,12};
System.out.println(solution(A,B));
}
public static String solution(String[] A, int[] B){
Map<String,Integer> map = new HashMap<>();
String maxInvestmentCountry="";
int maxValue=0;
for(int i=0;i<A.length;i++) {
String country = A[i].substring(0, 2);
int val;
if (map.containsKey(country)) {
val = map.get(country);
val += B[i];
} else {
val = B[i];
}
map.put(country, val);
if (val > maxValue) {
maxValue = val;
maxInvestmentCountry = country;
}
}
return maxInvestmentCountry;
}
}