-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHighFive.py
30 lines (22 loc) · 848 Bytes
/
HighFive.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
import heapq
class Solution:
def highFive(self, items: List[List[int]]) -> List[List[int]]:
dict = {}
for i, v in items:
if i in dict:
# if length less than 5 -> push to heap
if len(dict[i])<5:
heappush(dict[i],v)
elif (dict[i][0])<v: #if 0th value is les than current
heapreplace(dict[i],v) #replace
else:
dict[i] = [v] #set value with heap intialisation []
output = []
# making the output -> list
for i in dict:
li = []
li.append(i)
avg = sum(dict[i])//len(dict[i])
li.append(avg)
output.append(li)
return output