Scientific Games interview question

Basic way to solve the problem in code