Many string questions really ask how many times each character appears: the first non-repeating character, the most frequent letter, or whether two strings match. A count array of size 26 answers these in one pass with very little code. Use an int[26] for lowercase letters and an int[256] or a HashMap when any character can appear. Do not reach for nested loops to count, because that turns an O(n) problem into O(n²).