Skip to content

Commit 4e12cf7

Browse files
authored
Update Find_Synonyms
1 parent 555786a commit 4e12cf7

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

Algorithms/Python/Graphs/Find_Synonyms

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
'''
2+
Problem:
23
If a is a synonym of b and b is a synonym of c, this implies that a is a synonym of c and c is a synonym of a
34

45
"advice:counsel counsel:suggestion suggestion:advice activity:briskness briskness:liveliness"
5-
briskness
6-
[liveliness, activity]
76

87
In this example, advice, counsel, suggestion are all synonyms of each other, while advice is not a synonym of activity.
98

@@ -23,6 +22,10 @@ word
2322
Convert string of synonyms -> adjacency list -> Loop adjacency list -> DFS from each node if it matches input word. Append to result list.
2423
TC: O(N + M^2), N = Chars in string, M = Unique Words
2524
SC: O(M)
25+
26+
"advice:counsel counsel:suggestion suggestion:advice activity:briskness briskness:liveliness"
27+
briskness
28+
[liveliness, activity]
2629
'''
2730

2831
from collections import defaultdict
@@ -56,6 +59,7 @@ class Solution:
5659
return res[1:] if res else res
5760

5861

62+
5963
solution = Solution()
6064
print(solution.listSynonyms("advice:counsel counsel:suggestion suggestion:advice activity:briskness briskness:liveliness", "briskness"))
6165
print(solution.listSynonyms("advice:counsel counsel:suggestion suggestion:advice activity:briskness briskness:liveliness", "rock"))

0 commit comments

Comments
 (0)