Pregunta de entrevista de CVS Health

Time complexity and space complexity of my code