-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcampusCup.py
145 lines (119 loc) · 5.18 KB
/
campusCup.py
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
"""
https://app.codesignal.com/company-challenges/dropbox/RMJDiTprBf5HQY3oa
Dropbox holds a competition between schools called CampusCup. If you verify an email address from a college,
university, or higher education institution, you earn 20 points toward your school's overall ranking. When a
school receives at least 100 points, all of its registered members receive an additional 3 Gb of bonus space each.
When the school receives at least 200 points, its registered members receive an additional 8 Gb. If the school
receives at least 300 points, its members receive an additional 15 Gb. And finally, when a school receives at
least 500 points, members receive an additional 25 Gb each.
You are given n registered emails, all of them unique. Each email has the following format: "<name>@<domain>",
where <name> and <domain> are non-empty strings consisting of lowercase letters and a '.'. Identical domains
correspond to the same school and vice versa.
Your task is to make a scoreboard, i.e. to sort the schools according to the amount of bonus space they each
received (per student not in total). School A must be higher in the standings than school B if A received more
space than B, or if they received equal number of gigabytes but the domain string of school A is lexicographically
smaller than the one of school B.
campusCup(emails) = ["mit.edu", "rain.ifmo.ru"].
"mit.edu" scored 40 points, and "rain.ifmo.ru" just 20. Both universities got no additional space, so "mit.edu"
must be higher in the standings because it is lexicographically smaller than "rain.ifmo.ru".
For
the output should be
campusCup(emails) = ["harvard.edu", "student.spbu.ru"].
"harvard.edu" - 100 points, 3 Gb of additional space.
"student.spbu.ru" - 140 points, also 3 Gb of additional space.
"harvard.edu" must be higher in the standings because it is lexicographically smaller than "student.spbu.ru".
For
the output should be
campusCup(emails) = ["rain.ifmo.ru", "mit.edu"].
"mit.edu" - 20 points, no additional space.
"rain.ifmo.ru" - 100 points, 3 Gb of additional space.
Therefore, "rain.ifmo.ru" must be higher in the standings.
Input/Output
[execution time limit] 4 seconds (py)
[input] array.string emails
Registered emails.
Guaranteed constraints:
2 ≤ emails.length ≤ 40,
5 ≤ emails[i].length ≤ 20.
[output] array.string
emails: ["[email protected]",
The list of unique school domains sorted as described above
"""
from collections import defaultdict
import collections
def campusName(email):
return email.split('@')[-1]
def campusCup(emails):
campusMails = defaultdict(int)
for i in emails:
nameCampus = campusName(i)
campusMails[nameCampus] += 20
ordCampus = {0: [], 1: [], 2: [], 3: [], 4: []}
print(campusMails)
for campus in campusMails:
if campusMails[campus] < 100:
ordCampus[4].append(campus)
elif 100 <= campusMails[campus] < 200:
ordCampus[3].append(campus)
elif 200 <= campusMails[campus] < 300:
ordCampus[2].append(campus)
elif 300 <= campusMails[campus] < 500:
ordCampus[2].append(campus)
else:
ordCampus[1].append(campus)
for i in ordCampus:
ordCampus[i].sort()
l = lambda dic: [item for list in dic for item in dic[list]]
return l(ordCampus)
print(campusCup(["[email protected]",
"[email protected]"]))