When I see this kind of problem, my first thought is to see if it can be decomposed into a couple of simpler problems.
Here I think we can turn it into 'partition' and 'zip', and I think this is the insight that I'd be looking for if I were asking this as an interview question.
I'd then have a conversation about efficiency, and might come up with a composed version closer to what you've shown above, if the interviewer were interested in following that path.
Anyhow, just thought I'd offer another perspective -- good luck. :)
When I see this kind of problem, my first thought is to see if it can be decomposed into a couple of simpler problems.
Here I think we can turn it into 'partition' and 'zip', and I think this is the insight that I'd be looking for if I were asking this as an interview question.
I'd then have a conversation about efficiency, and might come up with a composed version closer to what you've shown above, if the interviewer were interested in following that path.
Anyhow, just thought I'd offer another perspective -- good luck. :)
Thanks. I hadn't heard of a zip before, but it seems pretty common in CS.
You're welcome.