CodePath Interview Question

How did you come up with the solution?