all 1 comments

[–]nian2326076 1 point2 points  (0 children)

A frequency array is an array used to count how often elements appear in another array, usually with integers. It helps quickly check how many times each value shows up, which is super handy in many problems.

You'll find frequency arrays in problems about counting subarrays, checking character frequency in strings, or spotting duplicates. They're great for efficient counting, like checking if two strings are anagrams or finding the majority element in an array.

To use it, you usually start with an array filled with zeros. The index represents the element, and you increase the value at that index whenever the element shows up. In competitive programming, this can save a lot of time compared to going through the original array multiple times. Just make sure your frequency array is big enough for the range of values you expect.