Dsa
Binary Search
Medium
Smallest Missing Positive Integer
Given an unsorted array of positive integers, find the smallest missing positive integer. The solution should be efficient and run in O(n log n) time complexity by leveraging binary search.
Input format:
- The first line contains an integer n (1 ≤ n ≤ 10^6), the number of elements in the array.
- The second line contains n space-separated integers (positive integers, up to 10^9).
Output format:
- Print the smallest missing positive integer.
Example:
Input:
5
3 4 -1 1
Output:
2
Key concepts
binary_searcharraymissing_number
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now