Grokking Google Coding Interview
Ask Author
Back to course home

0% completed

Vote For New Content
Set Mismatch (easy)
Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Problem Statement

You are given an array nums of size n, originally containing 1 to n integers. Unfortunately, due to some error, one number got duplicated, replacing another number that now goes missing from the sequence.

Identify the duplicated number and the missing number and return them as a pair.

Examples

  • Example 1:

    • Input: nums = [1,3,3,4]
    • Expected Output: [3,2]
    • Justification: Here, 3 appears twice, and 2 is missing from the sequence.
  • Example 2:

    • Input: nums = [2,2,3,5,4]
    • Expected Output: [2,1]
    • Justification: 2 is duplicated, and 1 is missing, making 2 the repeated number and 1 the missing one.
  • Example 3:

    • Input: nums = [1,5,3,2,7,7,6]
    • Expected Output: [7,4]
    • Justification: In this sequence, 7 is the number that appears twice, and 4 is absent, indicating 7 as the duplicate and 4 as the missing number.

Try it yourself

Try solving this question here:

Python3
Python3

. . . .

.....

.....

.....

Like the course? Get enrolled and start learning!

Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible