Pergunta de entrevista da empresa GlobalLogic

time complexity, space complexity for java problem