Pregunta de entrevista de Oracle

Optimize time and memory complexity for some algorithm