CVS Health Interview Question

Time complexity and space complexity of my code