2dbi
Home/HPE/Find the Duplicate Number
HHPE·DSASDE-2Technical Phone Screen

Find the Duplicate Number

Problem

Array of n+1 integers in [1,n]; find the single duplicate without modifying the array and in O(1) space.

Example

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

Constraints

  • n+1 elements

Approach

Floyd's cycle detection on the value-as-pointer graph.

added 6 days ago
LeadersAccount