The frequency count answers "how many times does each value appear?" in a single pass. Instead of one accumulator, you keep one counter per distinct value, in an array (when values are small) or a hash map (when they are large or are words/characters).
For lowercase letters, an array of 26 counters works:
def solve(s):
freq = [0] * 26
for ch in s:
freq[ord(ch) - ord('a')] += 1 # bump this letter's counter
# e.g. return the count of 'a'
return freq[0]
static long[] solve(int n, long[] a) {
Map<Long, Long> freq = new HashMap<>();
for (long x : a) freq.merge(x, 1L, Long::sum); // count each value
// ... use the counts
return a;
}
This one table answers a whole family of questions with no second pass: the most frequent element, whether any value repeats, whether two strings are anagrams (equal frequency tables), the first non-repeating character. When a problem mentions "how many times", "duplicates", "most common", or "anagram", reach for a frequency count. It trades a little memory for turning repeated searching into instant lookups.