ASAPUtils Logo ASAPUtils
Week 5

Find the Duplicate Number

Find the Duplicate Number by viewing array values as an implicit linked list, with Floyd's two-phase cycle proof, C++ and JavaScript solutions, constant space, constraint recognition, and an interactive index-walk trace.

The problem

An array of n+1 integers contains values only from 1 through n and exactly one value repeats. Return that duplicate without modifying the array and with constant auxiliary space.

nums = [1,3,4,2,2] -> 2

Related Problems