Checkpoint: Top-K frequent words
Challenge on lesson: Checkpoint: STL in Combination
CHALLENGE
Difficulty: intermediate+25 XP
Implement std::vector<std::string> top_k(const std::vector<std::string>& words, std::size_t k) returning the k most frequent words ordered by count descending; ties are broken lexicographically (smaller word first). If there are fewer than k distinct words, return all of them (still ordered). Combine a counting std::map with a sort (or a std::priority_queue) โ the tie-break rule is the part most solutions get wrong.
Press Submit to check your solution.
Back to lesson: Checkpoint: STL in Combination