Open darwinrlo opened 4 years ago
LeetCode: Sort Characters By Frequency
Grokking: Maximum Distinct Elements
The solution uses a min-heap. Pretty sure a max-heap should be used. Geeks for Geeks agrees with me.
Geeks for Geeks: Maximum distinct elements after removing k elements
The time complexity uses a variable d, which is the number of distinct elements in the array.
The problem was described ambiguously. It's not retrieving the indices of the k1-st and k2-nd smallest elements and adding up the elements between them. It's adding up the numbers from the k1-st element to the k2-end element in the sorted order.
LeetCode: Reorganize String Grokking: Rearrange String Geeks for Geeks: Rearrange characters in string so that no two adjacent are same
The explanation for this pattern is lacking. I wonder if the author actually understood the algorithm.
If all elements have equal frequencies, then we will go through each element in turn.
LeetCode: Rearrange String k Distance Apart
Why is a max-heap used?
Top K Numbers
Algorithm
Complexity