Student Beans interview question

How to solve a coding challenge