Pregunta de entrevista de Jane Street

String question. Must have missed an optimisation .