Pergunta de entrevista da empresa Amazon

coding questions, time complexity , approach to the problem