-
Notifications
You must be signed in to change notification settings - Fork 2
/
codefights treemap
105 lines (72 loc) · 2.97 KB
/
codefights treemap
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
Thumbtack helps Professionals (Pros) grow their business by identifying new customers. Upon registering on Thumbtack, a Pro specifies which categories of services they provide. To help match customer requests with qualified Pros, Thumbtack maintains a list of Pros grouped by service categories.
Given a list of pros and their category preferences, return the list of Pros for each category.
Example
For pros = ["Jack", "Leon", "Maria"] and
preferences = [["Computer repair", "Handyman", "House cleaning"],
["Computer lessons", "Computer repair", "Data recovery service"],
["Computer lessons", "House cleaning"]]
the output should be
proCategorization(pros, preferences) = [[["Computer lessons"], ["Leon", "Maria"]],
[["Computer repair"], ["Jack", "Leon"]],
[["Data recovery service"], ["Leon"]],
[["Handyman"], ["Jack"]],
[["House cleaning"], ["Jack", "Maria"]]]
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author shivam
*/
import java.util.*;
import java.util.List;
import java.util.ArrayList;
import java.util.TreeSet;
public class fffff {
public static void main(String[] args) {
String pros[] = {"Jack", "Leon", "Maria"};
String c[][] = {{"Computer repair", "Handyman", "House cleaning"},
{"Computer lessons", "Computer repair", "Data recovery service"},
{"Computer lessons", "House cleaning"}};
//String [][][] res= new String[5][1][1];
// System.out.println("shivam");
TreeSet<String> t = new TreeSet<String>();
int len=0;
for (int i=0;i<c.length;i++) {
for (int j=0;j<c[i].length;j++) {
if (t.add(c[i][j])) {
//System.out.print(c[i][j]+" ");
len++;
}
}
}
System.out.println(len);
//return res;
String res[][][]= new String[1][len][3];
int p=0;
Iterator itr;
itr = t.iterator();
TreeMap<String,List<String> > tmap;
tmap = new TreeMap<String,List<String>>();
while (itr.hasNext()) {
ArrayList<String> l = new ArrayList<String>();
String str=itr.next()+"";
// System.out.println(str);
for (int i=0;i<c.length;i++) {
for (int j=0;j<c[i].length;j++) {
if (c[i][j].equals(str)) {
l.add(pros[i]);
}
}
}
tmap.put(str,l);
// l.clear();
}
//printing TreeMap
for(Map.Entry m:tmap.entrySet()){
System.out.println(m.getKey()+" "+m.getValue());
}
}
}