Tatari interview question

How did you implement the algorithm in the assignment?