BMAT Interview Question

Time and space complexity of the solution