Skip to content

Commit b3025ae

Browse files
committed
Complated daily question and addition mediums
1 parent 38a0cc5 commit b3025ae

6 files changed

+66
-4
lines changed

README.md

+7-4
Large diffs are not rendered by default.
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class Solution:
2+
def edgeScore(self, edges: List[int]) -> int:
3+
nodeSums = defaultdict(int)
4+
5+
for i, targetEdge in enumerate(edges) :
6+
nodeSums[targetEdge] += i
7+
8+
return max(nodeSums.keys(), key=lambda x : (nodeSums[x], -x))

my-submissions/m2374 v2 array.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class Solution:
2+
def edgeScore(self, edges: List[int]) -> int:
3+
nodeSums = [0] * len(edges)
4+
5+
for i, targetEdge in enumerate(edges) :
6+
nodeSums[targetEdge] += i
7+
8+
return max([i for i in range(len(edges))], key=lambda x: (nodeSums[x], -x))
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution:
2+
def edgeScore(self, edges: List[int]) -> int:
3+
nodeSums = [0] * len(edges)
4+
5+
maxx = 0
6+
indx = 0
7+
for i, targetEdge in enumerate(edges) :
8+
nodeSums[targetEdge] += i
9+
if maxx < nodeSums[targetEdge] or (maxx == nodeSums[targetEdge] and indx > targetEdge):
10+
maxx = nodeSums[targetEdge]
11+
indx = targetEdge
12+
13+
return indx

my-submissions/m451.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution:
2+
def frequencySort(self, s: str) -> str:
3+
cnt = Counter(s)
4+
5+
output = [(-1 * freq, val) for val, freq in cnt.items()]
6+
heapq.heapify(output)
7+
8+
actualOutput = []
9+
10+
while output :
11+
freq, val = heapq.heappop(output)
12+
actualOutput.extend([val] * (freq * -1))
13+
14+
return ''.join(actualOutput)

my-submissions/m826 Daily heap.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution:
2+
def maxProfitAssignment(self, difficulty: List[int], profit: List[int], worker: List[int]) -> int:
3+
heap = [(-profit[i], difficulty[i]) for i in range(len(difficulty))]
4+
heapq.heapify(heap)
5+
6+
worker.sort()
7+
8+
output = 0
9+
while worker and heap:
10+
if worker[-1] >= heap[0][1] :
11+
output += -heap[0][0]
12+
worker.pop()
13+
else :
14+
heapq.heappop(heap)
15+
16+
return output

0 commit comments

Comments
 (0)