Identify the Duplicated and Missing Set Values

Quick Overview

Identify the Duplicated and Missing Set Values. An original set 1..n lost one value when it was replaced by another existing value.

Identify the Duplicated and Missing Set Values

Company: Amazon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

### Problem An original set 1..n lost one value when it was replaced by another existing value. Given the resulting n-element array nums, return [duplicatedValue,missingValue] in that order. ```cpp class Solution { public: vector<int> findErrorNums(vector<int>& nums); }; ``` ### Examples **Example 1:** ```text nums = [3,1,3,4] Output: [3,2] Explanation: Three appears twice and two is absent. ``` **Example 2:** ```text nums = [2,2] Output: [2,1] Explanation: The replacement removed one. ``` ### Constraints - Array length: 2..10000. Listed numeric value bound: 1..10000; the single-replacement promise specifies the original set 1..n. ### Clarifying Questions Use the promised single replacement and preserve duplicate-before-missing output order. ```hint Read the boundary condition How do the occurrence counts differ from the original set? ``` ### Contract considerations Use the promised single replacement and preserve duplicate-before-missing output order.

Overview: Identify the Duplicated and Missing Set Values. An original set 1..n lost one value when it was replaced by another existing value.

Amazon logo
Amazon
Sep 11, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0

Problem

An original set 1..n lost one value when it was replaced by another existing value. Given the resulting n-element array nums, return [duplicatedValue,missingValue] in that order.

class Solution {
public:
    vector<int> findErrorNums(vector<int>& nums);
};

Examples

Example 1:

nums = [3,1,3,4]
Output: [3,2]
Explanation: Three appears twice and two is absent.

Example 2:

nums = [2,2]
Output: [2,1]
Explanation: The replacement removed one.

Constraints

  • Array length: 2..10000. Listed numeric value bound: 1..10000; the single-replacement promise specifies the original set 1..n.

Clarifying Questions Guidance

Use the promised single replacement and preserve duplicate-before-missing output order.

Contract considerations

Use the promised single replacement and preserve duplicate-before-missing output order.