Two Sigma interview question

The problems in the coding interview are not difficult for someone with a programming background. The interviewer asked me to evaluate the time-complexity and space-complexity of the algorithm and optimize it.