FastPrepFind Missing and Duplicate Integer
Problems/Find Missing and Duplicate Integer

Find Missing and Duplicate Integer

InMobi logoInMobi● MediumFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: The source includes one example that violates its own exactly-one-missing-and-one-duplicate premise and has no expected output, so that example is omitted. The judged core task follows the stated premise and matches the usable source at about 94%.

You are given an integer array nums of length n. It should contain every integer from 1 through n exactly once, but one value is missing and one other value appears twice.

Return a two-element array [missing, duplicate], with the missing value first and the repeated value second.

Function

findMissingAndDuplicate(nums: int[]) → int[]

Examples

Example 1

nums = [1,2,3,4,5,6,7,8,9,10,10]return = [11,10]

The array has length 11. The value 11 is absent, while 10 appears twice.

Example 2

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

The value 4 is missing from 1 through 5, and 3 is duplicated.

Constraints

  • 2 <= nums.length <= 2 * 10^5
  • 1 <= nums[i] <= nums.length
  • Exactly one value in 1..nums.length is missing.
  • Exactly one different value appears twice, and every other value appears once.

More InMobi problems

  • Validate a Bracket SequenceOA · Seen Oct 2026
  • Validate a Bracket SequenceOA · Seen Oct 2026
  • Count Substrings Matching with One Adjacent SwapOA · Seen Oct 2026
All InMobi interview questionsSee InMobi hiring insights
Saved
public int[] findMissingAndDuplicate(int[] nums) {
    // write your code here
}
Checking account…