KLM interview question

Data structures implementation, mathematical thinking