Skip to content

Commit 3b80ade

Browse files
author
Partho Biswas
committed
no message
1 parent f7f6355 commit 3b80ade

File tree

3 files changed

+11
-14
lines changed

3 files changed

+11
-14
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -969,6 +969,7 @@ BFS, DFS, Dijkstra, Floyd–Warshall, Bellman-Ford, Kruskal, Prim's, Minimum Spa
969969
|05| [Underscorify_Substring](algoexpert.io/questions/Underscorify_Substring.md) | [Python](algoexpert.io/python/Underscorify_Substring.py)| --- | Hard | TODO: Check again. Difficult to analyse the space ad time complexity |
970970
|06| [Pattern_Matcher](algoexpert.io/questions/Pattern_Matcher.md) | [Python](algoexpert.io/python/Pattern_Matcher.py)|
971971
|07| [Smallest_Substring_Containing](algoexpert.io/questions/Smallest_Substring_Containing.md) | [Python](algoexpert.io/python/Smallest_Substring_Containing.py)|
972+
|08| [Group_Anagrams](algoexpert.io/questions/Group_Anagrams.md) | [Python](algoexpert.io/python/Group_Anagrams.py)|
972973

973974
</p>
974975
</details>
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from collections import defaultdict
2+
def groupAnagrams(words):
3+
anagrams = defaultdict(list)
4+
for word in words:
5+
sortedWord = "".join(sorted(word))
6+
anagrams[sortedWord].append(word)
7+
return list(anagrams.values())
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
# https://www.algoexpert.io/questions/Min%20Max%20Stack%20Construction
2-
3-
41
class MinMaxStack:
5-
62
def __init__(self):
73
# only contains the min and max value at any given time
84
# min_max_stack is an array of dictionary, which is the same length of stack
@@ -24,21 +20,14 @@ def push(self, number):
2420
if len(self.min_max_stack):
2521
last_min_max = self.min_max_stack[len(self.min_max_stack) - 1]
2622
new_min_max["min"] = min(last_min_max["min"], number)
27-
new_min_max["max"] = min(last_min_max["max"], number)
23+
new_min_max["max"] = max(last_min_max["max"], number)
2824
self.min_max_stack.append(new_min_max)
2925
self.stack.append(number)
3026

3127
# O(1) time | O(1) space
32-
def get_min(self):
28+
def getMin(self):
3329
return self.min_max_stack[len(self.min_max_stack) - 1]["min"]
3430

3531
# O(1) time | O(1) space
36-
def get_max(self):
32+
def getMax(self):
3733
return self.min_max_stack[len(self.min_max_stack) - 1]["max"]
38-
39-
40-
41-
42-
43-
44-

0 commit comments

Comments
 (0)