Find Any Duplicate in Range [1, n-1] with O(1) Extra Space

Problem: Find Any Duplicate in an Array (Modifying Input Allowed, O(1) Extra Space)

You are given an integer array nums of length n. Each element is in the range [1, n-1].

It is guaranteed ...

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Standard Input
Execution Result: