Skip to content

Commit 43df46c

Browse files
author
Gonzalo Diaz
committed
[Hacker Rank] Interview Preparation Kit: Dictionaries and Hashmaps: Sherlock and Anagrams. Clean Code: better variable naming.
1 parent 09517b8 commit 43df46c

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/sherlock_and_anagrams.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,17 @@ export function sherlockAndAnagrams(s: string): number {
3434

3535
let count = 0;
3636
// Final Anagram list
37-
for (const i of Object.keys(candidates)) {
38-
const total = candidates[i].length;
37+
for (const word of Object.keys(candidates)) {
38+
const quantity_of_anagrams = candidates[word].length;
3939
const k = 2;
4040

41-
if (total <= 1) {
42-
delete candidates[i];
41+
if (quantity_of_anagrams <= 1) {
42+
delete candidates[word];
4343
} else {
4444
// Binomial coefficient: https://en.wikipedia.org/wiki/Binomial_coefficient
4545
count += Math.floor(
46-
factorial(total) / (factorial(k) * factorial(total - k))
46+
factorial(quantity_of_anagrams) /
47+
(factorial(k) * factorial(quantity_of_anagrams - k))
4748
);
4849
}
4950
}

0 commit comments

Comments
 (0)