Jul 8, 2022
Thanks, I haven't analyzed your code in detail, but isn't what you are doing essentially a partial sort which is a O(N + k log k) operation?
I added a partial sort solution in my article update, but it might be interesting to have a close look at how you solved it. Maybe I need a rewrite for myself to clarify in my own head how you did id.