Domanda di colloquio di Amazon

coding question with time complexity analysis