EPAM Systems interview question

Why is that solution best solution? Time complexity and space complexity