The solution is a while-loop with a couple of if-statements. I would hope an engineer would write code like this many times per day. Whenever they need to marshal a blob from A to B.
> It also can feel just a tad insulting to be drilled on CompSci 101 questions.
I wish I had this problem! In these rare cases, I just say, "Great job! This was to just double-check you could write code. You'd be surprised how often a candidate isn't able to solve this! Let's talk about your career. In what aspects would you like to grow next?"