LC 3510 - Minimum Pair Removal to Sort Array II

Approach This is a raelly interesting problem. same problem with yesterdays daily but need to come up with a much faster method. I was originally thinking that checking a vector to be sorted is O(N), and we can only done in O(N^2), and after reading one solution, I find that we only need to check the neigobers order, and count the number of ordered pairs. In this case, we can check O(1) to update the number of ordered pairs, and this can be done in O(1). ...

January 23, 2026 · 3 min

LC 23 - Merge k Sorted Lists

Approach This is actually quite simple, just take the smallest from all list and connect, and iteratively do this process, and will use a min heap instead for faster min-val query. I also tried a new method for defining the comparator for priority_queue this time. Usually I will use a comparator class and a bool operator(), but I found that there is a more clear way to write this, that is to define the lambda function first, and pass the function to pq’s constructor. ...

January 9, 2026 · 1 min

LC 295 - Find Median from Data Stream

Approach I waw originally thinking that we can insert the number with binary search (or lower_bound), and find median with directly taking the number from index for the vector. This strategy can pass the porlbme, but this is actually an O(N) solution since vector insert can be O(n). I then find out that we can maintain a minheap and maxheap with O(lgN) insertion time, and we only need to rebalance two heaps when their size is different by more than 2. ...

January 9, 2026 · 2 min

LC 3478 - Choose K Elements With Maximum Sum

[translate by ChatGPT] I actually thought of the solution early on, but at first I didn’t notice that the problem requires choosing k elements. I initially thought it only required finding the two largest values. Later I realized that I could implement it using a min heap. This also made me feel that I should review how to use a min heap again. The usage of priority_queue is actually quite simple: just use top() to get the element, and then push() / pop(). ...

March 9, 2025 · 2 min