I went straight for the cyclic sort approach since mutating the array was allowed, which worked fine.
Clarify the constraints and confirm that the array is read-only and that we can modify it if needed. Then, present Floyd's cycle detection algorithm (tortoise and hare) to find a duplicate in O(n) time and O(1) space, explaining how the array indices form a linked list with a cycle. Alternatively, discuss binary search on the value range if the array is read-only, but note it requires O(n log n) time.
Pro tip: Mention that the problem is equivalent to finding the entry point of a cycle in a linked list, and that Floyd's algorithm is optimal. Also, note that if the array is read-only, binary search on the value range is a viable alternative, but it's slower.
Ask if the array can be modified, if it's read-only, and if we need to find any duplicate or all duplicates. Confirm that elements are in [1, n-1] and at least one duplicate exists.
Explain that the array can be viewed as a linked list where each element points to the index equal to its value. Since there's a duplicate, there must be a cycle.
Use two pointers: slow moves one step, fast moves two steps. They will meet inside the cycle. Then, reset one pointer to the start and move both one step at a time to find the cycle entrance, which is the duplicate.
State that the algorithm runs in O(n) time and uses O(1) extra space, meeting the requirements. Mention that the array is not modified.
If the array is read-only, binary search on the value range can be used, but it takes O(n log n) time. Also, mention that sorting would take O(n log n) time and O(1) space if in-place, but modifies the array.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.