Citi interview question

How did you implement the solution?