File tree Expand file tree Collapse file tree 1 file changed +6
-5
lines changed
src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Original file line number Diff line number Diff line change @@ -34,16 +34,17 @@ export function sherlockAndAnagrams(s: string): number {
34
34
35
35
let count = 0 ;
36
36
// 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_anamgrams = candidates [ word ] . length ;
39
39
const k = 2 ;
40
40
41
- if ( total <= 1 ) {
42
- delete candidates [ i ] ;
41
+ if ( quantity_of_anamgrams <= 1 ) {
42
+ delete candidates [ word ] ;
43
43
} else {
44
44
// Binomial coefficient: https://en.wikipedia.org/wiki/Binomial_coefficient
45
45
count += Math . floor (
46
- factorial ( total ) / ( factorial ( k ) * factorial ( total - k ) )
46
+ factorial ( quantity_of_anamgrams ) /
47
+ ( factorial ( k ) * factorial ( quantity_of_anamgrams - k ) )
47
48
) ;
48
49
}
49
50
}
You can’t perform that action at this time.
0 commit comments