Pregunta de entrevista de Google

2 algorithm question on screen--easy to medium