Walmart Interview Question

Code the answer to this problem