Domanda di colloquio di Meta

Is there any alternative solution to the coding problem? What about its complexity compared to yours?