Videocites interview question

Data structures and time complexity question