darwinrlo / public

0 stars 0 forks source link

Top k Elements #32

Open darwinrlo opened 4 years ago

darwinrlo commented 4 years ago

Top K Numbers

Algorithm

Complexity

darwinrlo commented 4 years ago

Kth Smallest Number

darwinrlo commented 4 years ago

LeetCode: Sort Characters By Frequency

Complexity

darwinrlo commented 4 years ago

LeetCode: Kth Largest Element in a Stream

darwinrlo commented 4 years ago

LeetCode: Find K Closest Elements

darwinrlo commented 4 years ago

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.

darwinrlo commented 4 years ago

Grokking: Sum of Elements

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.

darwinrlo commented 4 years ago

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.

darwinrlo commented 4 years ago

LeetCode: Rearrange String k Distance Apart

Why is a max-heap used?