Oracle Interview Question

Optimize time and memory complexity for some algorithm