Walmart Global Tech interview question

Whiteboard code problem and solution