forked from codereport/HackerRank
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHourRank_30_P1.java
More file actions
29 lines (28 loc) · 877 Bytes
/
Copy pathHourRank_30_P1.java
File metadata and controls
29 lines (28 loc) · 877 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
// code_report Solution
// https://youtu.be/uOG3QyxIjso
public static List<String> solve(List<String> names) {
HashSet<String> s = new HashSet<>();
HashMap<String, Integer> m = new HashMap<>();
List<String> l = new ArrayList<>();
for (String name : names) {
if (m.containsKey(name)) {
int n = m.get(name);
m.put(name, n+1);
l.add(name + " " + Integer.toString(n+1));
} else {
m.put(name, 1);
String t = "";
boolean inserted = false;
for (char c : name.toCharArray()) {
t += c;
if (!inserted && !s.contains(t) ) {
inserted = true;
l.add(t);
}
s.add(t);
}
if (!inserted) l.add(t);
}
}
return l;
}