When people practice algorithms they often try to remember as many templates as they can. Hash map, sliding window, prefix sum. The names are useful. The memory of a pasted loop is not, because the next problem changes one constraint and the template silently gives the wrong answer.

What you are actually storingLink to this heading

A hash map is a decision about lookup. You pay memory so that a question you will ask many times, "have I seen this key?", is cheap. If you cannot name the key, you do not have a hash map problem yet. You have a wish.

A sliding window is a promise about a range. As the right edge moves forward, the left edge moves only when the range stops satisfying the rule. The invariant is the whole technique. If you cannot say what is true inside the window after each step, you are just moving two indexes and hoping.

A prefix sum turns a question about a range into a question about two points. Subarray Sum Equals K is the classic: the sum from i to j is prefix[j] - prefix[i]. Once you see that, the hash map is only there to remember how many times each prefix has occurred.

Where memorizing failsLink to this heading

Group Anagrams is not "sort every string because the template says so". Sorting is one way to give anagrams the same key. A count of letters is another. Both are hash maps. The problem is the key, not the sort.

The same thing happens with prefix sums when the array contains negatives. A growing window no longer works, because a larger range is not a larger sum. People who memorized the positive-only window keep the same loop and get a confident wrong answer.

In Go, none of this is about the standard library. map will not save you from an invariant you never wrote down. Write the invariant in a comment before the loop. If you cannot, you are not ready to code it.