Capgemini Interview Question

time and space complexity with the examples to justify answer