Walmart interview question

Code the answer to this problem