Pergunta de entrevista da empresa FactSet

Given a list of sorted/sequential integers with one duplicate, find the duplicate.

Resposta da entrevista

Sigiloso

15 de out. de 2010

I got stuck for a little, then realized binary search would work--since you know the sequence and it's sorted, you know what the middle element should be. If the middle element is smaller than you expect, something's duplicated on the left side. Similarly if it's larger, then something's duplicated on the right. Keep going like this and you will eventually find the duplicate.