Why is the brute-force approach less ideal here?
Practice this question from Top K Frequent Elements - Frequency Heap Pattern Practice Quiz, with options and an explanation.
Question
Why is the brute-force approach less ideal here?
Option A — Correct answer
Sorting all unique values costs O(m log m).
Option B
It always uses constant time
Option C
It avoids all comparisons
Option D
It requires no extra state
Explanation
Sorting all unique values costs O(m log m).