Find the Duplicate Number
Updated
Problem statement
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[]) → intExamples
Example 1
nums = [1,3,4,2,2]return = 2The value 2 is the only number that appears twice.
Example 2
nums = [3,1,3,4,2]return = 3The value 3 appears at two positions.
Example 3
nums = [1,1]return = 1With n = 2, the only valid value is 1, and it appears twice.
Constraints
2 ≤ nums.length ≤ 100,000- Every value is between
1andnums.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