Endava interview question

Implementing data structures to solve a question