FastPrepFind the Duplicate Number
Problems/Find the Duplicate Number

Find the Duplicate Number

SpaceX logoSpaceX● EasyFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a SpaceX onsite interview. The report gives the range of the array and the goal of finding the duplicate. It does not give the function signature, whether the duplicate is unique, examples or limits. Our version is about 88% the same as the reported idea.

Find the Duplicate Number

You are given an integer array nums of length n. It contains every integer from 1 through n - 1 exactly once, except for one value that appears twice.

Return the duplicated value.

Function

findDuplicateNumber(nums: int[]) → int

Examples

Example 1

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

The value 2 is the only number that appears twice.

Example 2

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

The value 3 appears at two positions.

Example 3

nums = [1,1]return = 1

With n = 2, the only valid value is 1, and it appears twice.

Constraints

  • 2 ≤ nums.length ≤ 100,000
  • Every value is between 1 and nums.length - 1, inclusive.
  • Exactly one distinct value appears twice, and every other value appears once.

More SpaceX interview questions

  • Rocket Component CostONSITE INTERVIEW · Seen Aug 2025
  • Starlink Beam PlannerOA · PHONE SCREEN · Seen Nov 2026
  • Timestamped Telemetry Stream DifferencesPHONE SCREEN · Seen Sep 2026
  • Number of IslandsPHONE SCREEN · Seen Aug 2026
  • Number of Islands IIPHONE SCREEN · Seen Aug 2026
  • Button Combination DetectorPHONE SCREEN · Seen Feb 2026
  • Pressure Chamber Linear InterpolationPHONE SCREEN · Seen Jun 2025
  • DNA Sequence MatchOA · Seen Apr 2025
  • Speed to Pressure LookupPHONE SCREEN · Seen Mar 2025
  • Simplified Time-Based Key-Value StorePHONE SCREEN · Seen Nov 2023

Similar questions at other companies

  • List the Key and Value of Every Map EntryNewgen Software · ONSITE INTERVIEW
  • Pizza Price CalculatorMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Cross-Day User Trust ScoresAffirm · PHONE SCREEN · ONSITE INTERVIEWAffirm interview questions
  • Map and Accumulate Learning QueriesPalantir · ONSITE INTERVIEWPalantir interview questions
  • Filter Pins by Excluded IDsPinterest · ONSITE INTERVIEWPinterest interview questions
  • Best Average Student ScoreGoldman Sachs · PHONE SCREEN · ONSITE INTERVIEWGoldman Sachs interview questions
  • Longest Dictionary Word from Nine LettersGoogle · ONSITE INTERVIEWGoogle interview questions
  • Two SumOptimus Information · ONSITE INTERVIEWOptimus Information interview questions
  • Keep the First Key for Each Distinct ValueOneTrust · ONSITE INTERVIEW
  • Two Positions That Add Up to a TargetDocuSign · PHONE SCREEN · ONSITE INTERVIEWDocuSign interview questions

Interview reports that mention this question

  • 2013–2026 SpaceX Full-Time OA / Interviews: 45 Experiences (Part 2 :)
  • SpaceX Software Engineer OA and Interviews: 27 Experiences
  • SpaceX Software Engineer Interviews: 1 Experience

SpaceX interview experiences

  • SpaceX Full-Time Interview Cycle and Delayed Decision
  • SpaceX Experienced Engineer Full-Time Thirteen-Interview Process
  • SpaceX Senior Hardware Engineer Full-Time Interrupted Onsite
All SpaceX interview questionsSee SpaceX hiring insights
Saved
class Solution {
    public int findDuplicateNumber(int[] nums) {
        // Write your code here.
    }

}
Checking account…