Pregunta de entrevista de Susquehanna International Group

Given a coding question and an inefficient solution, choose a better date structure to optimize it and write the code