Domanda di colloquio di CVS Health

Time complexity and space complexity of my code