O14
Find Missing and Repeated Number
Problem Statement & Objective
You are given an unsorted array of size n containing numbers from 1 to n. One number in this range appears twice, and one number is missing. Find both the repeated number and the missing number.
Function Signature (Python)
find_missing_and_repeated(nums: list[int]) -> list[int]Input & Output Contract
Output Rule:[repeated, missing] array of two integers.
System Constraints
2 <= n <= 10^5
nums contains elements in range 1..nExample Execution Walkthrough
nums = [3, 1, 2, 5, 3]
repeated: 3, missing: 4 -> result [3, 4]Example Test Scenarios (3)
Example 1
Input:
[[3,1,2,5,3]]Expected Output:
[3,4]Example 2: n=2
Input:
[[2,2]]Expected Output:
[2,1]Example 3: Ortada Tekrar
Input:
[[1,2,2,4]]Expected Output:
[2,3]