← NVIDIA Interview Insights

NVIDIA·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Apr 2026

Summary

NVIDIA SWE coding round, one problem but it had some real depth to it. The question sounds like a basic duplicate-finding thing until you actually read the constraints.

Questions Asked (1)

Q1

Given an integer array of length n where every element is in the range [1, n-1] and at least one duplicate exists, find any duplicate number using O(1) extra space and better than O(n^2) time.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

I went straight for the cyclic sort approach since mutating the array was allowed, which worked fine.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

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.

1. Clarify constraints and assumptions

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.

2. Identify the cycle detection approach

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.

3. Apply Floyd's tortoise and hare algorithm

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.

4. Analyze time and space complexity

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.

5. Discuss alternative approaches and trade-offs

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.

Key Points to Mention

  • Floyd's cycle detection algorithm (tortoise and hare)
  • Time complexity O(n) and space complexity O(1)
  • The array as a linked list with a cycle due to duplicate
  • Proof that the cycle entrance is a duplicate
  • Alternative: binary search on value range for read-only arrays
  • Trade-offs: modifying array vs. read-only, time vs. space

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.