Pergunta de entrevista da empresa Amazon

coding question with time complexity analysis