J.P. Morgan interview question

time complexity,space complexity, python lost functions