...

/

Find the Corrupt Pair

Find the Corrupt Pair

Try to solve the Find the Corrupt Pair problem.

Statement

We are given an unsorted array, nums, with nn elements and each element is in the range [1,n][1, n] inclusive. The array originally contained all the elements from 11 to nn but due to a data error, one of the numbers is duplicated, which causes another number missing. Find and return the corrupt pair (missing, duplicated).

Constraints:

  • 2n1032 \leq n \leq 10^3
  • 11 \leq nums[i] n\leq n

Examples

1 / 3

Understand the problem

Let’s take a moment to make sure you’ve correctly understood the problem. The quiz below helps you check if you’re solving the correct problem:

Find the Corrupt Pair

1

Which is the corrupt pair in the array given below?

[4, 1, 3, 4, 5]

A)

2, 3

B)

2, 4

C)

2, 5

D)

2, 6

Question 1 of 30 attempted

Figure it out!

We have a game for you to play. Rearrange the logical building blocks to develop a clearer understanding of how to solve this problem.

Sequence - Vertical
Drag and drop the cards to rearrange them in the correct sequence.

1
2
3
4

Try it yourself

Implement your solution in the following coding playground:

Press + to interact
Java
usercode > FindCorruptPair.java
import java.util.*;
public class FindCorruptPair{
public static int[] findCorruptPair(int[] nums) {
// Replace this placeholder return statement with your code
return new int[]{0, 0};
}
}
Find the Corrupt Pair

Access this course and 1200+ top-rated courses and projects.