FastPrepFind the Duplicate Number Without Modifying the Array
Problems/Find the Duplicate Number Without Modifying the Array

Find the Duplicate Number Without Modifying the Array

Google logoGoogle● MediumINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report gives the setup of n+1 integers with one duplicate, O(1) extra space, and time better than quadratic. It adds follow-ups for several duplicates or a different value range. It does not state the rules on changing the input, a signature, input limits, examples, or the output for a more general case. Our version is about 92% the same as the main reported question.

You are given an integer array nums of length n + 1. Every value is between 1 and n, inclusive, and exactly one distinct value appears more than once.

Return the duplicated value. The duplicated value may occur more than twice.

Do not modify nums. Use O(1) auxiliary space and strictly better than O(n^2) time.

Interview follow-up

Be prepared to explain which guarantees the constant-space algorithm relies on and how the available approaches change if several distinct values may repeat or if values are not restricted to 1 through n. These harder versions are for discussion only. Your function solves the main problem above.

Function

findDuplicate(nums: int[]) → int

Examples

Example 1

nums = [1,3,4,2,2]return = 2

The value 2 appears twice, while every other value appears once.

Example 2

nums = [3,1,3,4,2]return = 3

The duplicated value is 3.

Example 3

nums = [1,1]return = 1

This is the smallest valid array, and 1 is duplicated.

Constraints

  • 1 <= n <= 100000.
  • nums.length == n + 1.
  • 1 <= nums[i] <= n.
  • Exactly one distinct value is duplicated, possibly more than twice.
  • The input array must not be modified.

More Google Onsite Interview questions

  • Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
  • Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
  • Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
  • Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
  • Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Merge Sorted Squares of Two ArraysWhatNot · PHONE SCREEN · ONSITE INTERVIEW
  • Run-Length Encoded Vector Dot ProductMeta · PHONE SCREEN · ONSITE INTERVIEW
  • Search a Row- and Column-Sorted MatrixByteDance · ONSITE INTERVIEW
  • Shortest Window with Required CountsOracle · ONSITE INTERVIEW
  • 3Sum SmallerSalesforce · ONSITE INTERVIEW
  • Sort Ones, Twos, and Threes In PlaceAgoda · PHONE SCREEN · ONSITE INTERVIEW
  • Minimum Station Tracks for a Train ScheduleBNSF Railway · ONSITE INTERVIEW
  • Candy Crush Grid Matching and GravityRoblox · PHONE SCREEN · ONSITE INTERVIEW
  • Longest Binary Window with at Most K OnesLinkedIn · ONSITE INTERVIEW
  • Rotate an Array Right by K StepsQualys · ONSITE INTERVIEW

Interview reports that mention this question

  • Google Intern Prefix Sums and Heaps: 6 Experiences (Part 3 of 8)

Google interview experiences

  • Google interviews · November 2026
  • Google Software Engineer Onsite Questions: 10 Experiences
  • Google OA: What It Tests (2026)
  • Google L4 SWE Phone Screen: 1 Experience
  • Google ML Engineering Manager Onsite: 1 Experience
See Google hiring insights
Saved
class Solution {
    public int findDuplicate(int[] nums) {
      // Write your code here.
    }
}
Checking account…