Staples interview question

Time/Space complexity of the code