Scientific Games Interview Question

Basic way to solve the problem in code