https://leetcode.com/problems/remove-element/description/
This was interesting: I made this problem a lot harder by trying to move the "to remove" elements to the end instead of moving the "to keep" elements to the beginning.
I found my idea hard to implement iteratively, and I had to switch to recursion to get it working. After that, I was able to convert my solution to iterative -- but it would've been pretty hard to implement this approach iteratively from the start!
But if we move "to keep" elements to the beginning instead, this problem is really simple iteratively.
- solution1: My tricky recursive solution
- solution2: My tricky iterative solution based on solution1
- solution3: The easy iterative solution