Spotify interview question

Data structure, Big O notations, optimisation