Domanda di colloquio di Optro

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