CIBC interview question

Coding interview regarding optimization and space complexity.