Pergunta de entrevista da empresa Bloomberg

Time and space complexity of the above functions.