JPMorganChase interview question

time and space complexity of the algorithm