Pregunta de entrevista de Amazon

coding questions, time complexity , approach to the problem