Pregunta de entrevista de Optro

I was asked to solve a data structures and algorithms problem and explain the optimized approach, complexity, and implementation details.