<p>You have a set of integers <code>s</code>, which originally contains all the numbers from <code>1</code> to <code>n</code>. Unfortunately, due to some error, one of the numbers in <code>s</code> got duplicated to another number in the set, which results in <strong>repetition of one</strong> number and <strong>loss of another</strong> number.</p>

<p>You are given an integer array <code>nums</code> representing the data status of this set after the error.</p>

<p>Find the number that occurs twice and the number that is missing and return <em>them in the form of an array</em>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre><strong>Input:</strong> nums = [1,2,2,4]
<strong>Output:</strong> [2,3]
</pre><p><strong class="example">Example 2:</strong></p>
<pre><strong>Input:</strong> nums = [1,1]
<strong>Output:</strong> [1,2]
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>2 &lt;= nums.length &lt;= 10<sup>4</sup></code></li>
	<li><code>1 &lt;= nums[i] &lt;= 10<sup>4</sup></code></li>
</ul>

class Solution {
public:
    vector<int> findErrorNums(vector<int>& nums) {
    int duplicate = -1, missing = -1;
    
    // First pass: Use values as indices and mark visited positions
    for (int num : nums) {
        int index = abs(num) - 1;  // Get the index from the value (convert to 0-based index)
        
        // If the value at this index is already negative, it means this index has been visited, hence it's a duplicate
        if (nums[index] < 0) {
            duplicate = abs(num);
        } else {
            nums[index] = -nums[index];  // Mark as visited by negating the value
        }
    }
    
    // Second pass: Find the missing number
    for (int i = 0; i < nums.size(); ++i) {
        // If the number at index i is positive, it means i + 1 is the missing number
        if (nums[i] > 0) {
            missing = i + 1;
            break;
        }
    }
    
    return {duplicate, missing};
}
};

23900