Delete K nodes in a linked list having their data less than the next node's
Do you know Shlemiel The Painter?
He never moves his paint can, and so repeatedly walks all over the town.

What you need to do is take the algorithm for removing one friend, look at how it works when applied k times, and then cut out all the redundant Setup work.



Aside from that, you aren't using any C++ containers or algorithms, nor smart-pointers (std::unique_ptr), new or the like.

Don't assume nothing will go wrong. While it is unlikely with malloc() as long as you stay reasonable, scanf() parses user-input, and users will do everything possible, even if you think it's impossible.

There's more, but that should be a good start.