H E B interview question

Standard algorithm question, nothing to difficult.