Molex Interview Question

What is the runtime and space complexity of the solution ?