Capgemini interview question

time and space complexity with the examples to justify answer