Files
cpp-flashcards/org/study_deck_02/toolkit/tricks.org
T
2026-06-01 18:12:40 +08:00

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.