Practice: Top K Frequent Elements
Problem: https://leetcode.com/problems/top-k-frequent-elements/
Recognition reminder: count frequencies first, then select the k largest. The selection step is where the interesting choice lives.
Before you start (the five-beat rhythm)
- Your Pattern Card for this week is already written.
- Name the pattern aloud and write your approach as a plain-English comment before any code.
- Struggle floor: 25 minutes unaided. No hints, no AI, no Discuss tab.
- If stuck past the floor, ask the tutor for a hint. Six rungs, one per ask.
- Debrief in your commit message before moving to the next problem.
Your target
Target time complexity: ____
Target space complexity: ____
Sorting the counts is O(n log n). Bucket sort by frequency is O(n). A size-k heap is O(n log k); you will meet that angle again in Week 8. Know the trade among the three.
Where your code goes
Write your solution in your own work repo (see getting-started.md), not in this folder. This folder ships only the problem spec and a provided-example test (tests/test_provided.py). The judge is the oracle; the tutor will not confirm your answer by reading it.
Debrief (paste into your commit message)
1. What pattern did this turn out to be?
2. What was the trigger phrase or input shape that should have made me reach for it?
3. What was the time and space complexity, and what would dominate at scale?
4. What edge case would have broken my first attempt?
5. What would I do differently in three days when I see this cold?