File tree Expand file tree Collapse file tree 1 file changed +13
-4
lines changed
src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps Expand file tree Collapse file tree 1 file changed +13
-4
lines changed Original file line number Diff line number Diff line change @@ -31,7 +31,8 @@ def sherlock_and_anagrams(s_word: str) -> int:
31
31
else :
32
32
candidates [anagram_candidate ] = [substr ]
33
33
34
- count : int = 0
34
+ total : int = 0
35
+ q_candidates = 0
35
36
# Final Anagram list
36
37
for word in list (candidates ):
37
38
quantity_of_anagrams = len (candidates [word ])
@@ -41,10 +42,18 @@ def sherlock_and_anagrams(s_word: str) -> int:
41
42
del candidates [word ]
42
43
else :
43
44
# Binomial coefficient: https://en.wikipedia.org/wiki/Binomial_coefficient
44
- count += math .factorial (quantity_of_anagrams ) // (
45
+ q_candidates += quantity_of_anagrams
46
+
47
+ count = math .factorial (quantity_of_anagrams ) // (
45
48
math .factorial (k ) * math .factorial (quantity_of_anagrams - k )
46
49
)
50
+ total += count
51
+
52
+ LOGGER .debug ('Partial anagrams of %s: %i' , word , count )
47
53
48
- LOGGER .debug ('Sherlock_and_anagrams() Filtered candidates %i' , count )
54
+ LOGGER .debug (
55
+ 'sherlock_and_anagrams(%s) Filtered # candidates: %i' , s_word , q_candidates
56
+ )
57
+ LOGGER .debug ('sherlock_and_anagrams(%s) # anagrams: %i' , s_word , total )
49
58
50
- return count
59
+ return total
You can’t perform that action at this time.
0 commit comments