Skip to content

Commit d4236fa

Browse files
author
Gonzalo Diaz
committed
[REFACTOR] [Hacker Rank] Interview Preparation Kit: Dictionaries and Hashmaps: Sherlock and Anagrams. Better logging.
1 parent 1af4df8 commit d4236fa

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/sherlock_and_anagrams.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ def sherlock_and_anagrams(s_word: str) -> int:
3131
else:
3232
candidates[anagram_candidate] = [substr]
3333

34-
count: int = 0
34+
total: int = 0
35+
q_candidates = 0
3536
# Final Anagram list
3637
for word in list(candidates):
3738
quantity_of_anagrams = len(candidates[word])
@@ -41,10 +42,18 @@ def sherlock_and_anagrams(s_word: str) -> int:
4142
del candidates[word]
4243
else:
4344
# 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) // (
4548
math.factorial(k) * math.factorial(quantity_of_anagrams - k)
4649
)
50+
total += count
51+
52+
LOGGER.debug('Partial anagrams of %s: %i', word, count)
4753

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)
4958

50-
return count
59+
return total

0 commit comments

Comments
 (0)