← All problems

Find the Duplicate Number

Medium arraystwo-pointerscycles LeetCode ↗
Array of n+1 integers in [1, n] with one duplicate. Find it without modifying the array, O(1) space.

Hints (0/3 revealed)

Log in to reveal hints progressively.

Complexity

Time O(n), Space O(1)

Common pitfalls

  • Sorting the array (modifies it)
  • Binary-search-on-count is O(n log n) - acceptable but not the intended trick

Your solution

Log in to save your code and track progress.