โ† Zoho questions

Find duplicates in O(n) time

Filed under Zoho

Free read 2 of 3

Check if modifying the input array in-place is permitted to achieve O(1) space.

The question

Given an array of size n containing elements from 0 to n-1, find all duplicate elements in O(n) time and O(1) extra space.

Constraints

  • Array elements are in the range [0, n-1]
  • Time complexity must be O(n)
  • Auxiliary space complexity must be O(1)

Examples

Input
nums = [1, 2, 3, 1, 3]
Output
[1, 3]
Why
1 and 3 appear more than once in the array.

Approach

  1. Check if modifying the input array in-place is permitted to achieve O(1) space.

Tips

  • What they are testing: Test arrays with multiple duplicates, single duplicate, and no duplicates.
  • Common mistake: Modifying the array destructively if modification is not allowed, or failing to handle multiple duplicate counts cleanly.

Related Zoho questions

Collected from public candidate posts and coding forums. Updated Nov 2026.