Pergunta de entrevista da empresa NVIDIA

Time complexity of some code snippet, how to reduce the time complexity