I'll trace ["i", "love", "leetcode", "i", "love", "coding"] with k = 2. Frequencies: i:2, love:2, leetcode:1, coding:1.
Process (i,2): heap has room, push. Process (love,2): push. The heap min is (love,2) because at equal frequency, "love" comes after "i" alphabetically, making it the weaker candidate.
Process (leetcode,1): frequency loses to the heap min's frequency . Don't add. Same for (coding,1). Pop the heap: love, then i. Reverse: ["i", "love"].
Counting frequencies takes . Each of unique words does one heap operation at , giving total. Space is for the map plus for the heap.