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

Function addFrequency

javascript/0242-valid-anagram.js:42–49  ·  view source on GitHub ↗
(str, map)

Source from the content-addressed store, hash-verified

40};
41
42const addFrequency = (str, map) => {
43 for (const char of str) {
44 /* Time O(N) */
45 const count = (map.get(char) || 0) + 1;
46
47 map.set(char, count); /* Space O(1) */
48 }
49};
50
51const subtractFrequency = (str, map) => {
52 for (const char of str) {

Callers 1

isAnagramFunction · 0.85

Calls 2

getMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected