H E B Interview Question

Standard algorithm question, nothing to difficult.