Search
First Missing Integer Interviewbit Solution
Updated: May 29, 2021
Problem: First Missing Integer
Problem Description:
Given an unsorted integer array, find the first missing positive integer.
Example:
Given [1,2,0] return 3,
[3,4,-1,1] return 2,
[-8, -7, -6] returns 1Your algorithm should run in O(n) time and use constant space.
Solution:
Method 1:
Time Complexity: O(N)
Space Complexity: O(N)Method 2:
Time Complexity: O(NlogN)
Space Complexity: O(1)Method 3:
Time Complexity: O(N)
Space Complexity: O(1)


I was reading https://snabbauttagcasinon.com about how they streamline processes to cut waiting times, and that mindset fits this solution perfectly—instead of allocating extra memory, you use the array itself as the lookup table by placing each number in its index spot. The trick of ignoring negatives and values greater than n is what makes the O(n) constant-space approach click for me. It's a nice reminder that constraints often push you toward more elegant solutions.
It looks in the code given above , first approach missed space constraints and second approach missed time constraint. ( As per InterviewBit problem statement)