bp interview question

Algorithm question with complexity analysis