I am an editor for a lousy paper and I found a better algorithm than theirs. Must I share it with them?
I think you are treading on thin ice, ethically speaking. Obviously you, as an editor, have no obligation to help the authors in any specific way, and you are free to tell them about your improvement or not, but rejecting their paper, taking the idea/problem, applying a different method to its resolution, and then publishing this under your own name seems problematic.

As an editor, you are usually expected to treat the papers you are handling as privileged information, and you are specifically expected to not use your knowledge of rejected papers to scoop the authors - which is exactly what you plan to do. Say you reject the paper with comments along the line "important problem, solution is too simplistic". The authors now go back to the drawing board, come up with a solution similar to what you had in mind, and get their paper accepted. If you publish your idea first they obviously can't do this anymore - you have effectively made use of knowledge you learned as an editor to pull the rug from under the people who initially thought of the research project, even if they did not do a great job with the first submission.

I understand that it sucks that if you told them about your idea you would be giving away information that, in different circumstances, may be sufficient for co-authorship. However, I would argue, as a reviewer / editor we sign up for helping the authors "for free" to some extent (that is, without expecting recognition).

If you really don't want to tell the authors about your idea your best hope is that the authors get their work accepted somewhere else. In that case you are free to write your follow-up paper and cite the original paper.