Bootcamps
Masterclasses
Menu
Courses
Account
Login / Sign Up

Missing And Repeating

Easy Acceptance 24.83% Points 20

Given an unsorted array arr of positive integers. One number a from the set [1, 2,....,n] is missing and one number b occurs twice in the array. Find numbers a and b.

Note: The test cases are generated such that there always exists one missing and one repeating number within the range [1,n].

Examples
Example 1

Example 1

Input: arr[] = [2, 2]

Output: [2, 1]

Explanation: Repeating number is 2 and smallest positive missing number is 1.

Example 2

Example 2

Input: arr[] = [1, 3, 3]

Output: [3, 2]

Explanation: Repeating number is 3 and smallest positive missing number is 2.

Constraints
  • 2 <= arr.size() <= 10^6
  • 1 <= arr[i] <= arr.size()
Hints
  • Expected Time Complexity: O(n)
  • Expected Space Complexity: O(1)
Topics
Array
Companies
Samsung Walmart TCS Infosys
Added 19 Jul 2026 24.83% acceptance
Ln 1, Col 1Sign in to save your code
2 2
2 1