MCPcopy Create free account
hub / github.com/neetcode-gh/leetcode / getHash

Function getHash

javascript/0049-group-anagrams.js:62–73  ·  view source on GitHub ↗
(word)

Source from the content-addressed store, hash-verified

60};
61
62const getHash = (word) => {
63 const frequency = new Array(26).fill(0);
64
65 for (const char of word) {
66 /* Time O(K) */
67 const charCode = getCode(char); /* Time O(1) | Space (1) */
68
69 frequency[charCode]++; /* | Space O(1) */
70 }
71
72 return buildHash(frequency);
73};
74
75const getCode = (char) => char.charCodeAt(0) - 'a'.charCodeAt(0);
76

Callers 1

groupWordsFunction · 0.85

Calls 2

buildHashFunction · 0.85
getCodeFunction · 0.70

Tested by

no test coverage detected