608 B
608 B
DSA Tricks & Patterns
Task: Count character frequencies faster than map dsa counting array string retrieval production
Front
Write C++ to count character frequencies in a string using a
fixed-size array instead of std::map (assume lowercase a-z only).
Back
std::array<int, 26> freq{};
for (char c : s) freq[c - 'a']++;
Why: O(1) per access vs O(log n) for std::map. Use when alphabet
is bounded and small.