Pregunta de entrevista de Apple

Simple Algorithm Question. Also some computer vision questions.